Package com.jogamp.gluegen.cgram.types
Class Type
- java.lang.Object
-
- com.jogamp.gluegen.cgram.types.Type
-
- All Implemented Interfaces:
ASTLocusTag.ASTLocusTagProvider
,TypeComparator.SemanticEqualityOp
- Direct Known Subclasses:
FunctionType
,MemoryLayoutType
,PointerType
,PrimitiveType
,VoidType
public abstract class Type extends Object implements TypeComparator.SemanticEqualityOp, ASTLocusTag.ASTLocusTagProvider
Models a C type. Primitive types include int, float, and double. All types have an associated name. Structs and unions are modeled as "compound" types -- composed of fields of primitive or other types.
-
-
Field Summary
Fields Modifier and Type Field Description boolean
relaxedEqSem
-
Constructor Summary
Constructors Modifier Constructor Description protected
Type(String name, SizeThunk size, int cvAttributes, ASTLocusTag astLocus)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
arrayDimension()
Helper method for determining how many array dimentions this type represents (i.e., "char[][]" returns 2).ArrayType
asArray()
Casts this to an ArrayType or returns null if not an ArrayType.BitType
asBit()
Casts this to a BitType or returns null if not a BitType.CompoundType
asCompound()
Casts this to a CompoundType or returns null if not a CompoundType.DoubleType
asDouble()
Casts this to a DoubleType or returns null if not a DoubleType.EnumType
asEnum()
Casts this to an EnumType or returns null if not an EnumType.FloatType
asFloat()
Casts this to a FloatType or returns null if not a FloatType.FunctionType
asFunction()
Casts this to a FunctionType or returns null if not a FunctionType.IntType
asInt()
Casts this to an IntType or returns null if not an IntType.PointerType
asPointer()
Casts this to a PointerType or returns null if not a PointerType.VoidType
asVoid()
Casts this to a VoidType or returns null if not a VoidType.protected void
clearCache()
Type
clone(ASTLocusTag newLoc)
Clones this instance using a newASTLocusTag
.boolean
equals(Object arg)
Equality test for Types inclusive its givenname
.boolean
equalSemantics(TypeComparator.SemanticEqualityOp arg)
Semantic equality test for Types exclusive its givenname
.protected abstract boolean
equalSemanticsImpl(Type t)
protected abstract boolean
equalsImpl(Type t)
Type
getArrayBaseOrPointerTargetType()
ASTLocusTag
getASTLocusTag()
Returns this instance'sASTLocusTag
, if available, otherwise returnsnull
.Type
getBaseType()
Helper method to returns the bottom-most element type of this type, i.e.String
getCName()
Returns the name of this type.String
getCName(boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.int
getCVAttributes()
String
getCVAttributesString()
Returns a string indicating the const/volatile attributes of this type.String
getDebugString()
String
getName()
Returns the name of this type.String
getName(boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.StringBuilder
getSignature(StringBuilder sb)
SizeThunk
getSize()
SizeThunk which computes size of this type in bytes.long
getSize(MachineDataInfo machDesc)
Size of this type in bytes according to the given MachineDataInfo.FunctionType
getTargetFunction()
Returns the targetFunctionType
if this type isisFunctionPointer()
.Type
getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced, i.e.int
hashCode()
Hashcode for Types.protected abstract int
hashCodeImpl()
int
hashCodeSemantics()
Semantic hashcode for Types exclusive its givenname
.protected abstract int
hashCodeSemanticsImpl()
boolean
hasSize()
Returns true ifgetSize()
is not null, otherwise false.boolean
isAnon()
boolean
isArray()
Indicates whether this is an ArrayType.boolean
isBaseTypeConst()
Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.boolean
isBit()
Indicates whether this is a BitType.boolean
isCompound()
Indicates whether this is a CompoundType.boolean
isConst()
Indicates whether this type is const.boolean
isDouble()
Indicates whether this is a DoubleType.boolean
isEnum()
Indicates whether this is an EnumType.boolean
isFloat()
Indicates whether this is a FloatType.boolean
isFunction()
Indicates whether this is a FunctionType.boolean
isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.boolean
isInt()
Indicates whether this is an IntType.boolean
isPointer()
Indicates whether this is a PointerType.boolean
isPrimitive()
Indicates whether this type is a primitive type.boolean
isTypedef()
Indicates whether this type is a typedef type, i.e.boolean
isVoid()
Indicates whether this is a VoidType.boolean
isVolatile()
Indicates whether this type is volatile.Type
newCVVariant(int cvAttributes)
Return a variant of this type matching the given const/volatile attributes.int
pointerDepth()
Helper method for determining how many pointer indirections this type represents (i.e., "void **" returns 2).boolean
setTypedefName(String name)
Set the typedef name of this type and renders this type a typedef, if givenname
has a length.String
toString()
Returns a string representation of this type.void
visit(TypeVisitor visitor)
Traverse thisType
and all of its component types; for example, the return type and argument types of a FunctionType.
-
-
-
Constructor Detail
-
Type
protected Type(String name, SizeThunk size, int cvAttributes, ASTLocusTag astLocus)
-
-
Method Detail
-
clearCache
protected final void clearCache()
-
newCVVariant
public final Type newCVVariant(int cvAttributes)
Return a variant of this type matching the given const/volatile attributes. May return this object if the attributes match.
-
clone
public Type clone(ASTLocusTag newLoc)
Clones this instance using a newASTLocusTag
.
-
getASTLocusTag
public final ASTLocusTag getASTLocusTag()
Description copied from interface:ASTLocusTag.ASTLocusTagProvider
Returns this instance'sASTLocusTag
, if available, otherwise returnsnull
.- Specified by:
getASTLocusTag
in interfaceASTLocusTag.ASTLocusTagProvider
-
isAnon
public boolean isAnon()
-
getCName
public final String getCName()
Returns the name of this type. The returned string is suitable for use as a type specifier for native C. Does not include any const/volatile attributes.
-
getCName
public String getCName(boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes. The returned string is suitable for use as a type specifier for native C.
-
getName
public final String getName()
Returns the name of this type. The returned string is suitable for use as a type specifier for Java. Does not include any const/volatile attributes.
-
getName
public String getName(boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes. The returned string is suitable for use as a type specifier for Java.
-
toString
public String toString()
Returns a string representation of this type. The returned string is suitable for use as a type specifier for native C. It does contain an expanded description of structs/unions, hence may not be suitable for type declarations.
-
getSignature
public final StringBuilder getSignature(StringBuilder sb)
-
getDebugString
public final String getDebugString()
-
setTypedefName
public boolean setTypedefName(String name)
Set the typedef name of this type and renders this type a typedef, if givenname
has a length.Method issues
clearCache()
, to force re-evaluation of hashes.
-
isTypedef
public final boolean isTypedef()
Indicates whether this type is a typedef type, i.e. declared viasetTypedefName(String)
.
-
hasSize
public final boolean hasSize()
Returns true ifgetSize()
is not null, otherwise false.
-
getSize
public final SizeThunk getSize()
SizeThunk which computes size of this type in bytes.
-
getSize
public final long getSize(MachineDataInfo machDesc)
Size of this type in bytes according to the given MachineDataInfo.
-
asBit
public BitType asBit()
Casts this to a BitType or returns null if not a BitType.
-
asInt
public IntType asInt()
Casts this to an IntType or returns null if not an IntType.
-
asEnum
public EnumType asEnum()
Casts this to an EnumType or returns null if not an EnumType.
-
asFloat
public FloatType asFloat()
Casts this to a FloatType or returns null if not a FloatType.
-
asDouble
public DoubleType asDouble()
Casts this to a DoubleType or returns null if not a DoubleType.
-
asPointer
public PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
-
asArray
public ArrayType asArray()
Casts this to an ArrayType or returns null if not an ArrayType.
-
asCompound
public CompoundType asCompound()
Casts this to a CompoundType or returns null if not a CompoundType.
-
asFunction
public FunctionType asFunction()
Casts this to a FunctionType or returns null if not a FunctionType.
-
asVoid
public VoidType asVoid()
Casts this to a VoidType or returns null if not a VoidType.
-
isBit
public final boolean isBit()
Indicates whether this is a BitType.
-
isInt
public final boolean isInt()
Indicates whether this is an IntType.
-
isEnum
public final boolean isEnum()
Indicates whether this is an EnumType.
-
isFloat
public final boolean isFloat()
Indicates whether this is a FloatType.
-
isDouble
public final boolean isDouble()
Indicates whether this is a DoubleType.
-
isPointer
public final boolean isPointer()
Indicates whether this is a PointerType.
-
isArray
public final boolean isArray()
Indicates whether this is an ArrayType.
-
isCompound
public final boolean isCompound()
Indicates whether this is a CompoundType.
-
isFunction
public final boolean isFunction()
Indicates whether this is a FunctionType.
-
isVoid
public final boolean isVoid()
Indicates whether this is a VoidType.
-
isVolatile
public final boolean isVolatile()
Indicates whether this type is volatile.
-
isConst
public final boolean isConst()
Indicates whether this type is const.
-
isPrimitive
public boolean isPrimitive()
Indicates whether this type is a primitive type.
-
isFunctionPointer
public boolean isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.
-
isBaseTypeConst
public final boolean isBaseTypeConst()
Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.Note: Intermediate 'const' qualifier are not considered, e.g. const pointer.
-
hashCodeImpl
protected abstract int hashCodeImpl()
-
equalsImpl
protected abstract boolean equalsImpl(Type t)
-
hashCodeSemantics
public final int hashCodeSemantics()
Description copied from interface:TypeComparator.SemanticEqualityOp
Semantic hashcode for Types exclusive its givenname
.- Specified by:
hashCodeSemantics
in interfaceTypeComparator.SemanticEqualityOp
- See Also:
TypeComparator.SemanticEqualityOp.equalSemantics(SemanticEqualityOp)
-
hashCodeSemanticsImpl
protected abstract int hashCodeSemanticsImpl()
-
equalSemantics
public final boolean equalSemantics(TypeComparator.SemanticEqualityOp arg)
Description copied from interface:TypeComparator.SemanticEqualityOp
Semantic equality test for Types exclusive its givenname
.- Specified by:
equalSemantics
in interfaceTypeComparator.SemanticEqualityOp
- See Also:
TypeComparator.SemanticEqualityOp.hashCodeSemantics()
-
equalSemanticsImpl
protected abstract boolean equalSemanticsImpl(Type t)
-
visit
public void visit(TypeVisitor visitor)
Traverse thisType
and all of its component types; for example, the return type and argument types of a FunctionType.
-
getCVAttributes
public final int getCVAttributes()
-
getCVAttributesString
public final String getCVAttributesString()
Returns a string indicating the const/volatile attributes of this type.
-
pointerDepth
public int pointerDepth()
Helper method for determining how many pointer indirections this type represents (i.e., "void **" returns 2). Returns 0 if this type is not a pointer type.
-
arrayDimension
public int arrayDimension()
Helper method for determining how many array dimentions this type represents (i.e., "char[][]" returns 2). Returns 0 if this type is not an array type.
-
getBaseType
public Type getBaseType()
Helper method to returns the bottom-most element type of this type, i.e. returns `type
` if this-type is `type
*`, `type
**`, `type
[]` or `type
[][]`.If this is a multidimensional array or pointer method returns the bottom-most element type, otherwise this.
In case a
isFunctionPointer()
type is reached, traversing ends and the functionPointerType
is returned.- See Also:
getTargetType()
,getTargetFunction()
-
getTargetType
public Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced, i.e. returns `type
` if this-type is `type
*` or `type
[]` and returns `type
*` if this-type is `type
**` or `type
[][]`.If this is an array or pointer method returns the next target element type, otherwise `this`.
In this is a
isFunctionPointer()
type, `this` functionPointerType
is returned.- See Also:
getBaseType()
,getTargetFunction()
-
getArrayBaseOrPointerTargetType
public Type getArrayBaseOrPointerTargetType()
-
getTargetFunction
public FunctionType getTargetFunction()
Returns the targetFunctionType
if this type isisFunctionPointer()
.
-
-