| java.lang.Object xtc.type.C
C | public class C (Code) | | Common type operations for the C language.
author: Robert Grimm version: $Revision: 1.30 $ |
Constructor Summary | |
public | C() Create a new instance. |
Method Summary | |
public Type | compose(Type t1, Type t2, boolean pedantic) Compose the specified types. | protected Type | compose(Type t1, Type t2, boolean pedantic, boolean recursive) Compose the specified types.
Parameters: t1 - The first type. Parameters: t2 - The second type. Parameters: pedantic - The flag for pedantic composition. Parameters: recursive - The flag for recursive invocations. | protected Type | composeArrays(ArrayT a1, ArrayT a2) Compose the specified array types (C99 6.2.7).
Parameters: a1 - The first array. Parameters: a2 - The second array. | protected Type | composeFunctions(FunctionT f1, FunctionT f2, boolean pedantic) Compose the specified function types (C99 6.2.7). | public Type | convert(Type t1, Type t2) Perform the usual arithmetic conversions. | public boolean | equal(Type t1, Type t2) Determine whether the specified types are equal to each other.
Calling this method on types t1 and t2
is equivalent to:
C.hasSameQualifiers(t1, t2) && (! C.compose(t1, t2).isError())
Parameters: t1 - The first type. Parameters: t2 - The second type. | public boolean | fits(BigInteger number, Type type) Determine whether the specified number fits the specified integer
type.
Parameters: number - The number. Parameters: type - The integer type. | protected long | getAligned(Type type) Get the specified type's alignment. | public long | getAlignment(Type type) Get the specified type's alignment in bytes.
Parameters: type - The type. | public long | getAlignment(Type type, boolean natural) Get the specified type's alignment in bytes.
Parameters: type - The type. Parameters: natural - The flag for determining the natural alignment. | public Reference | getConstRef(Type type) Get the specified type's constant reference.
Parameters: type - The type. | public long | getSize(Type type) Get the specified type's size in bytes.
Parameters: type - The type. | protected long | getSize(StructT type) Get the specified struct's size in bytes.
Parameters: type - The struct. | public long | getWidth(Type number) Get the specified number's size in bits.
Parameters: number - The number. | public boolean | hasConstRef(Type type) Determine whether this type has a constant reference. | public boolean | hasQualifiers(Type type) Determine whether the specified type has any qualifiers.
Parameters: type - The type. | public boolean | hasQualifiers(Type type, Type template) Determine whether the specified type has at least the qualifiers
of the specified template.
Parameters: type - The type. Parameters: template - The template. | public boolean | hasSameQualifiers(Type type, Type template) Determine whether the specified type has the same qualifiers as
the specified template.
Parameters: type - The type. Parameters: template - The template. | public boolean | hasTrailingArray(Type type) Determine whether the specified type has a trailing array. | public boolean | isArithmetic(Type type) Determine whether the specified type is arithmetic.
Parameters: type - The type. | public boolean | isChar(Type type) Determine whether the specified type is a char.
Parameters: type - The type. | public boolean | isConstant(Type type) Determine whether the specified type is qualified as constant.
Consistent with C99 6.3.2.1, this method checks whether the type
has a
Constants.ATT_CONSTANT attribute and, if it is an
array, struct, or union, whether any member or element of the
type has that attribute.
Parameters: type - The type. | public boolean | isIncomplete(Type type) Determine whether the specified type is incomplete.
Per C99 6.2.5, a type is incomplete if it does not contain
sufficient information for determining its size. | public boolean | isIntegral(Type type) Determine whether the specified type is integral.
Parameters: type - The type. | public boolean | isModifiable(Type type) Determine whether the specified type represents a modifiable
lvalue. | protected boolean | isPacked(Type type) Determine whether the specified type has a GCC packed attribute.
Parameters: type - The type. | public boolean | isReal(Type type) Determine whether the specified type is real.
Parameters: type - The type. | public boolean | isScalar(Type type) Determine whether the specified type is scalar.
Parameters: type - The type. | public boolean | isString(Type type) Determine whether the specified type is a string.
Parameters: type - The type. | public boolean | isVariablyModified(Type type) Determine whether the specified type is variably modified.
Consistent with C99 6.7.5-3, this method checks whether the type
contains a variable length array type.
Parameters: type - The type. | public boolean | isWideChar(Type type) Determine whether the specified type is a wide char.
Parameters: type - The type. | public boolean | isWideString(Type type) Determine whether the specified type is a wide string.
Parameters: type - The type. | public BigInteger | mask(BigInteger number, Type type) Mask the specified number as a value of this integer type.
Parameters: number - The number. Parameters: type - The type. | public Type | pointerize(Type type) Pointerize the specified type. | public Type | promote(Type type) Integer promote the specified type. | public Type | promoteArgument(Type type) Argument promote this type. | public Type | qualify(Type type, Type template) Qualify the specified type with the qualifiers of the specified
template. | public Type | reattribute(Type type, Type template) Reattribute the specified type with the specified template's GCC
attributes.
Parameters: type - The type. Parameters: template - The template. | public String | toDesignation(Type type) Get the specified type's designation.
Parameters: type - The type. | public Type | toRValue(Type type) Convert the specified type to an rvalue. | public Type | typeCharacter(String literal) Type the specified C character literal. | public Type | typeFloat(String literal) Type the specified floating point literal. | public Type | typeInteger(String literal) Type the specified integer literal. |
FACTOR_WIDE | final protected BigInteger FACTOR_WIDE(Code) | | The factor for wide chars.
|
IMPLICIT | final public static IntegerT IMPLICIT(Code) | | The canonical implicit int type. In K&R C, a missing type
specifier is treated as an int. We preserve knowledge about this
lack of type specifier through this type, which has a
Constants.ATT_IMPLICIT attribute.
|
KIND_PTR_DIFF | final protected static NumberT.Kind KIND_PTR_DIFF(Code) | | The integer kind of the pointer difference type.
|
KIND_SIZEOF | final protected static NumberT.Kind KIND_SIZEOF(Code) | | The integer kind of the sizeof type.
|
KIND_WCHAR | final protected static NumberT.Kind KIND_WCHAR(Code) | | The number kind of the wchar_t type.
|
PTR_DIFF | final public static IntegerT PTR_DIFF(Code) | | The canonical pointer difference type.
|
SIZEOF | final public static IntegerT SIZEOF(Code) | | The canonical sizeof type.
|
WCHAR | final public static IntegerT WCHAR(Code) | | The canonical wide char type.
|
C | public C()(Code) | | Create a new instance.
|
compose | public Type compose(Type t1, Type t2, boolean pedantic)(Code) | | Compose the specified types. This method determines whether the
two types are compatible while also constructing a composite type
as specified in C99 6.2.7. If the types are compatible, the
resulting type is wrapped exactly as the first type. If the
types are not compatible, the resulting type is
ErrorT.TYPE .
Note that if both types are derived types, this method
ensures that any referenced types have the same qualifiers.
However, it does not ensure that the two types have the same
qualifiers. As a result, two types t1 and
t2 are compatible if:
C.hasSameQualfiers(t1, t2) && (! C.compose(t1, t2).isError())
Further note that the composed type does not preserve any
annotations or wraped types and thus needs to be annotated with
the two type's qualifiers etc.
See Also: C.equal(Type,Type) Parameters: t1 - The first type. Parameters: t2 - The second type. Parameters: pedantic - The flag for pedantic composition. The composed type. |
compose | protected Type compose(Type t1, Type t2, boolean pedantic, boolean recursive)(Code) | | Compose the specified types.
Parameters: t1 - The first type. Parameters: t2 - The second type. Parameters: pedantic - The flag for pedantic composition. Parameters: recursive - The flag for recursive invocations. The composed type. |
composeArrays | protected Type composeArrays(ArrayT a1, ArrayT a2)(Code) | | Compose the specified array types (C99 6.2.7).
Parameters: a1 - The first array. Parameters: a2 - The second array. The composed type. |
composeFunctions | protected Type composeFunctions(FunctionT f1, FunctionT f2, boolean pedantic)(Code) | | Compose the specified function types (C99 6.2.7). Note that this
method ignores any exceptions, which are not part of the C
language anyway.
Parameters: f1 - The first function. Parameters: f2 - The second function. Parameters: pedantic - The flag for pedantic composition. The composed type. |
convert | public Type convert(Type t1, Type t2)(Code) | | Perform the usual arithmetic conversions. Per C99 6.3.1.8, this
method performs the usual arithmetic conversions for the
specified two types and returns the type of the corresponding
result.
Parameters: t1 - The first type. Parameters: t2 - The second type. The converted type. throws: IllegalArgumentException - Signals that either type isnot arithmetic. |
equal | public boolean equal(Type t1, Type t2)(Code) | | Determine whether the specified types are equal to each other.
Calling this method on types t1 and t2
is equivalent to:
C.hasSameQualifiers(t1, t2) && (! C.compose(t1, t2).isError())
Parameters: t1 - The first type. Parameters: t2 - The second type. true if the types are equal. |
fits | public boolean fits(BigInteger number, Type type)(Code) | | Determine whether the specified number fits the specified integer
type.
Parameters: number - The number. Parameters: type - The integer type. true if the number fits the type. |
getAligned | protected long getAligned(Type type)(Code) | | Get the specified type's alignment. If the specified type has a
GCC aligned attribute, this method returns the corresponding
alignment. Otherwise, it returns -1.
Parameters: type - The type. The alignment or -1 if the type does not have an alignedattribute. |
getAlignment | public long getAlignment(Type type)(Code) | | Get the specified type's alignment in bytes.
Parameters: type - The type. The type's alignment. throws: IllegalArgumentException - Signals that the type does nothave a static alignment. |
getAlignment | public long getAlignment(Type type, boolean natural)(Code) | | Get the specified type's alignment in bytes.
Parameters: type - The type. Parameters: natural - The flag for determining the natural alignment. The type's alignment. throws: IllegalArgumentException - Signals that the type does not have a static alignment. |
getConstRef | public Reference getConstRef(Type type)(Code) | | Get the specified type's constant reference.
Parameters: type - The type. The constant reference. throws: IllegalArgumentException - Signals that the type does nothave a constant reference. |
getSize | public long getSize(Type type)(Code) | | Get the specified type's size in bytes.
Parameters: type - The type. The type's size. throws: IllegalArgumentException - Signals that the type does nothave a static size. |
getSize | protected long getSize(StructT type)(Code) | | Get the specified struct's size in bytes.
Parameters: type - The struct. The struct's size. throws: IllegalArgumentException - Signals that the struct does nothave a static size. |
getWidth | public long getWidth(Type number)(Code) | | Get the specified number's size in bits.
Parameters: number - The number. The size in bits. |
hasConstRef | public boolean hasConstRef(Type type)(Code) | | Determine whether this type has a constant reference. This
method takes the pointer decay of arrays and functions into
account and returns true either if the specified
type has a constant reference or if this type is an array or
function and has a constant reference.
Parameters: type - The type. true if the type has a constant reference. |
hasQualifiers | public boolean hasQualifiers(Type type)(Code) | | Determine whether the specified type has any qualifiers.
Parameters: type - The type. true if the type has any qualifiers. |
hasQualifiers | public boolean hasQualifiers(Type type, Type template)(Code) | | Determine whether the specified type has at least the qualifiers
of the specified template.
Parameters: type - The type. Parameters: template - The template. true if the type has at least the template'squalifiers. |
hasSameQualifiers | public boolean hasSameQualifiers(Type type, Type template)(Code) | | Determine whether the specified type has the same qualifiers as
the specified template.
Parameters: type - The type. Parameters: template - The template. true if the type has the same qualifiersas the template. |
hasTrailingArray | public boolean hasTrailingArray(Type type)(Code) | | Determine whether the specified type has a trailing array. This
method checks whether the specified type is either a struct type
with an incomplete array as its last member or a union containing
such a member.
Parameters: type - The type. true if the type has a trailing array. |
isArithmetic | public boolean isArithmetic(Type type)(Code) | | Determine whether the specified type is arithmetic.
Parameters: type - The type. true if the specified type is arithmetic. |
isChar | public boolean isChar(Type type)(Code) | | Determine whether the specified type is a char.
Parameters: type - The type. true if the type is a char. |
isConstant | public boolean isConstant(Type type)(Code) | | Determine whether the specified type is qualified as constant.
Consistent with C99 6.3.2.1, this method checks whether the type
has a
Constants.ATT_CONSTANT attribute and, if it is an
array, struct, or union, whether any member or element of the
type has that attribute.
Parameters: type - The type. true if the specified type is constantqualified. |
isIncomplete | public boolean isIncomplete(Type type)(Code) | | Determine whether the specified type is incomplete.
Per C99 6.2.5, a type is incomplete if it does not contain
sufficient information for determining its size. However, per
C99 6.7.2.1, a struct type with more than one named member may
have an incomplete type as its last member, while still being
considered complete.
Parameters: type - The type. true if the type is incomplete. |
isIntegral | public boolean isIntegral(Type type)(Code) | | Determine whether the specified type is integral.
Parameters: type - The type. true if the specified type is integral. |
isModifiable | public boolean isModifiable(Type type)(Code) | | Determine whether the specified type represents a modifiable
lvalue. Consistent with C99 6.3.2.1, this method checks that the
type represents an lvalue, is not incomplete, and is not
qualified as constant. For struct and union types, this method
also checks that no member is qualified as constant.
Parameters: type - The type. true if the type represents a modifiablelvalue. |
isPacked | protected boolean isPacked(Type type)(Code) | | Determine whether the specified type has a GCC packed attribute.
Parameters: type - The type. true if the type has a packed attribute. |
isReal | public boolean isReal(Type type)(Code) | | Determine whether the specified type is real.
Parameters: type - The type. true if the specified type is real. |
isScalar | public boolean isScalar(Type type)(Code) | | Determine whether the specified type is scalar.
Parameters: type - The type. true if the specified type is scalar. |
isString | public boolean isString(Type type)(Code) | | Determine whether the specified type is a string.
Parameters: type - The type. true if the type is a string. |
isVariablyModified | public boolean isVariablyModified(Type type)(Code) | | Determine whether the specified type is variably modified.
Consistent with C99 6.7.5-3, this method checks whether the type
contains a variable length array type.
Parameters: type - The type. true if the type is variably modified. |
isWideChar | public boolean isWideChar(Type type)(Code) | | Determine whether the specified type is a wide char.
Parameters: type - The type. true if the type is a wide char. |
isWideString | public boolean isWideString(Type type)(Code) | | Determine whether the specified type is a wide string.
Parameters: type - The type. true if the type is a wide string. |
mask | public BigInteger mask(BigInteger number, Type type)(Code) | | Mask the specified number as a value of this integer type.
Parameters: number - The number. Parameters: type - The type. The number masked as a value of this type. |
pointerize | public Type pointerize(Type type)(Code) | | Pointerize the specified type. This method resolves the type
and, if the type is an array or function, then performs C's
pointer decay (C99 6.3.2.1).
Parameters: type - The type. The pointerized type. |
promote | public Type promote(Type type)(Code) | | Integer promote the specified type. This method resolves the
type and, if the type is integral, then performs C's integer
promotion (C99 6.3.1.1). Additionally, it normalizes implicit
and signed int types to int types.
Parameters: type - The type. The integer promoted type. |
promoteArgument | public Type promoteArgument(Type type)(Code) | | Argument promote this type. This method resolves the type and,
if the type is an integral type or a float, then performs C's
default argument promotions (C99 6.5.2.2).
Parameters: type - The type. The argument promoted type. |
qualify | public Type qualify(Type type, Type template)(Code) | | Qualify the specified type with the qualifiers of the specified
template. If the template has any qualifiers, this method first
Type.annotate annotates the specified type first.
Parameters: type - The type. Parameters: template - The template. The qualified type. |
reattribute | public Type reattribute(Type type, Type template)(Code) | | Reattribute the specified type with the specified template's GCC
attributes.
Parameters: type - The type. Parameters: template - The template. The reattributed type. |
toDesignation | public String toDesignation(Type type)(Code) | | Get the specified type's designation.
Parameters: type - The type. The designation. |
toRValue | public Type toRValue(Type type)(Code) | | Convert the specified type to an rvalue. If the specified type
has a shape, this method returns the resolved type, annotated
with any qualifiers and constant value. Otherwise, it returns
the specified type.
Parameters: type - The type. The type as an rvalue. |
typeCharacter | public Type typeCharacter(String literal)(Code) | | Type the specified C character literal. This method determines
the type for the specified character literal, which may be a wide
character literal, and returns that type. The type is annotated
with the literal's constant value, even if the value does not fit
the type.
Parameters: literal - The literal. The corresponding constant valued type. |
typeFloat | public Type typeFloat(String literal)(Code) | | Type the specified floating point literal. This method returns
the type for the specified C floating point literal wrapped in
the literal's constant value.
Parameters: literal - The literal. The corresponding type. |
typeInteger | public Type typeInteger(String literal)(Code) | | Type the specified integer literal. This method returns the type
for the specified C integer literal wrapped in the literal's
constant value. If the specified literal does not fit any type,
this method returns the largest appropriate type.
Parameters: literal - The literal. The corresponding type and constant value. |
|
|