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 booleanrelaxedEqSem
-
Constructor Summary
Constructors Modifier Constructor Description protectedType(String name, SizeThunk size, int cvAttributes, ASTLocusTag astLocus)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intarrayDimension()Helper method for determining how many array dimentions this type represents (i.e., "char[][]" returns 2).ArrayTypeasArray()Casts this to an ArrayType or returns null if not an ArrayType.BitTypeasBit()Casts this to a BitType or returns null if not a BitType.CompoundTypeasCompound()Casts this to a CompoundType or returns null if not a CompoundType.DoubleTypeasDouble()Casts this to a DoubleType or returns null if not a DoubleType.EnumTypeasEnum()Casts this to an EnumType or returns null if not an EnumType.FloatTypeasFloat()Casts this to a FloatType or returns null if not a FloatType.FunctionTypeasFunction()Casts this to a FunctionType or returns null if not a FunctionType.IntTypeasInt()Casts this to an IntType or returns null if not an IntType.PointerTypeasPointer()Casts this to a PointerType or returns null if not a PointerType.VoidTypeasVoid()Casts this to a VoidType or returns null if not a VoidType.protected voidclearCache()Typeclone(ASTLocusTag newLoc)Clones this instance using a newASTLocusTag.booleanequals(Object arg)Equality test for Types inclusive its givenname.booleanequalSemantics(TypeComparator.SemanticEqualityOp arg)Semantic equality test for Types exclusive its givenname.protected abstract booleanequalSemanticsImpl(Type t)protected abstract booleanequalsImpl(Type t)TypegetArrayBaseOrPointerTargetType()ASTLocusTaggetASTLocusTag()Returns this instance'sASTLocusTag, if available, otherwise returnsnull.TypegetBaseType()Helper method to returns the bottom-most element type of this type, i.e.StringgetCName()Returns the name of this type.StringgetCName(boolean includeCVAttrs)Returns the name of this type, optionally including const/volatile attributes.intgetCVAttributes()StringgetCVAttributesString()Returns a string indicating the const/volatile attributes of this type.StringgetDebugString()StringgetName()Returns the name of this type.StringgetName(boolean includeCVAttrs)Returns the name of this type, optionally including const/volatile attributes.StringBuildergetSignature(StringBuilder sb)SizeThunkgetSize()SizeThunk which computes size of this type in bytes.longgetSize(MachineDataInfo machDesc)Size of this type in bytes according to the given MachineDataInfo.FunctionTypegetTargetFunction()Returns the targetFunctionTypeif this type isisFunctionPointer().TypegetTargetType()Helper method to returns the target type of this type, in case another type is being referenced, i.e.inthashCode()Hashcode for Types.protected abstract inthashCodeImpl()inthashCodeSemantics()Semantic hashcode for Types exclusive its givenname.protected abstract inthashCodeSemanticsImpl()booleanhasSize()Returns true ifgetSize()is not null, otherwise false.booleanisAnon()booleanisArray()Indicates whether this is an ArrayType.booleanisBaseTypeConst()Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.booleanisBit()Indicates whether this is a BitType.booleanisCompound()Indicates whether this is a CompoundType.booleanisConst()Indicates whether this type is const.booleanisDouble()Indicates whether this is a DoubleType.booleanisEnum()Indicates whether this is an EnumType.booleanisFloat()Indicates whether this is a FloatType.booleanisFunction()Indicates whether this is a FunctionType.booleanisFunctionPointer()Convenience routine indicating whether this Type is a pointer to a function.booleanisInt()Indicates whether this is an IntType.booleanisPointer()Indicates whether this is a PointerType.booleanisPrimitive()Indicates whether this type is a primitive type.booleanisTypedef()Indicates whether this type is a typedef type, i.e.booleanisVoid()Indicates whether this is a VoidType.booleanisVolatile()Indicates whether this type is volatile.TypenewCVVariant(int cvAttributes)Return a variant of this type matching the given const/volatile attributes.intpointerDepth()Helper method for determining how many pointer indirections this type represents (i.e., "void **" returns 2).booleansetTypedefName(String name)Set the typedef name of this type and renders this type a typedef, if givennamehas a length.StringtoString()Returns a string representation of this type.voidvisit(TypeVisitor visitor)Traverse thisTypeand 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.ASTLocusTagProviderReturns this instance'sASTLocusTag, if available, otherwise returnsnull.- Specified by:
getASTLocusTagin 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 givennamehas 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.SemanticEqualityOpSemantic hashcode for Types exclusive its givenname.- Specified by:
hashCodeSemanticsin 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.SemanticEqualityOpSemantic equality test for Types exclusive its givenname.- Specified by:
equalSemanticsin interfaceTypeComparator.SemanticEqualityOp- See Also:
TypeComparator.SemanticEqualityOp.hashCodeSemantics()
-
equalSemanticsImpl
protected abstract boolean equalSemanticsImpl(Type t)
-
visit
public void visit(TypeVisitor visitor)
Traverse thisTypeand 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 functionPointerTypeis 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` functionPointerTypeis returned.- See Also:
getBaseType(),getTargetFunction()
-
getArrayBaseOrPointerTargetType
public Type getArrayBaseOrPointerTargetType()
-
getTargetFunction
public FunctionType getTargetFunction()
Returns the targetFunctionTypeif this type isisFunctionPointer().
-
-