41package com.jogamp.gluegen.cgram.types;
43import com.jogamp.common.os.MachineDataInfo;
44import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider;
45import com.jogamp.gluegen.ASTLocusTag;
46import com.jogamp.gluegen.GlueGen;
47import com.jogamp.gluegen.TypeConfig;
48import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp;
56 private final int cvAttributes;
60 private int typedefCVAttributes;
61 private boolean isTypedef;
62 private boolean hasCachedHash;
63 private int cachedHash;
64 private boolean hasCachedSemanticHash;
65 private int cachedSemanticHash;
69 this.relaxedEqSem =
TypeConfig.relaxedEqualSemanticsTest();
70 this.cvAttributes = cvAttributes;
71 this.astLocus = astLocus;
73 this.typedefCVAttributes = 0;
74 this.isTypedef =
false;
78 this.cvAttributes = cvAttributes;
79 this.astLocus = astLocus;
82 this.typedefCVAttributes = o.typedefCVAttributes;
83 this.isTypedef = o.isTypedef;
88 hasCachedHash =
false;
90 hasCachedSemanticHash =
false;
91 cachedSemanticHash = 0;
99 if (this.cvAttributes == cvAttributes) {
102 return newVariantImpl(
true, cvAttributes, astLocus);
110 return newVariantImpl(
true, cvAttributes, newLoc);
127 public boolean isAnon() {
return null == name; }
137 public String
getCName(
final boolean includeCVAttrs) {
return getName(includeCVAttrs); }
147 public String
getName(
final boolean includeCVAttrs) {
148 if (!includeCVAttrs) {
166 private static StringBuilder append(
final StringBuilder sb,
final String val,
final boolean prepComma) {
175 sb =
new StringBuilder();
177 boolean prepComma =
false;
178 sb.append(
"(").append(getClass().getSimpleName()).append(
") ");
180 sb.append(
"typedef ");
183 sb.append(
"'").append(name).append(
"'");
190 sb.append(ft.
toString(
null ,
null ,
false,
true));
193 if(
null != targetType &&
this != targetType ) {
200 sb.append(
", o=0x"+Integer.toHexString(objHash()));
210 }
catch (
final Exception e) {}
213 sb.append(
"[fixed ").append(size.
hasFixedNativeSize()).append(
", lnx64 ").append(mdSize).append(
"]");
218 append(sb,
"const[", prepComma); prepComma=
false;
220 if( isConstTypedef() ) {
221 append(sb,
"typedef", prepComma); prepComma=
true;
224 append(sb,
"native", prepComma); prepComma=
true;
227 append(sb,
"true]", prepComma);
229 append(sb,
"false]", prepComma);
233 append(sb,
"is[", prepComma); prepComma=
false;
236 append(sb,
"volatile ", prepComma); prepComma=
true;
239 append(sb,
"primitive", prepComma); prepComma=
true;
242 append(sb,
"pointer*"+
pointerDepth(), prepComma); prepComma=
true;
248 append(sb,
"bit", prepComma); prepComma=
true;
251 append(sb,
"struct{", prepComma).append(
asCompound().getStructName()).append(
": ").append(
asCompound().getNumFields());
252 append(sb,
"}", prepComma); prepComma=
true;
255 append(sb,
"double", prepComma); prepComma=
true;
264 append(sb,
"float", prepComma); prepComma=
true;
267 append(sb,
"function", prepComma); prepComma=
true;
270 append(sb,
"funcPointer", prepComma); prepComma=
true;
273 append(sb,
"int", prepComma); prepComma=
true;
276 append(sb,
"void", prepComma); prepComma=
true;
279 append(sb,
"]",
false); prepComma=
true;
286 final StringBuilder sb =
new StringBuilder();
290 return sb.toString();
292 private final int objHash() {
return super.hashCode(); }
308 private final boolean setName(
final String name) {
310 if(
null == name || 0 == name.length() ) {
314 this.name = name.intern();
328 if( setName(name) ) {
331 typedefCVAttributes = cvAttributes;
338 final void setTypedef(
final int typedefedCVAttributes) {
339 this.name = this.name.intern();
340 this.typedefCVAttributes = typedefedCVAttributes;
341 this.isTypedef =
true;
344 final int getTypedefCVAttributes() {
345 return typedefCVAttributes;
357 public final boolean hasSize() {
return null != size; }
365 throw new RuntimeException(
"No size set for type \"" +
getName() +
"\"");
370 final void setSize(
final SizeThunk size) {
422 private final boolean isConstTypedef() {
return 0 != ( typedefCVAttributes & CVAttributes.CONST ); }
423 private final boolean isConstRaw() {
return 0 != ( cvAttributes & CVAttributes.CONST ); }
447 if( !hasCachedHash ) {
449 int hash = 31 + ( isTypedef ? 1 : 0 );
450 hash = ((hash << 5) - hash) + (
null != size ? size.
hashCode() : 0 );
451 hash = ((hash << 5) - hash) + cvAttributes;
452 hash = ((hash << 5) - hash) + typedefCVAttributes;
453 hash = ((hash << 5) - hash) + (
null != name ? name.hashCode() : 0 );
458 hasCachedHash =
true;
468 public final boolean equals(
final Object arg) {
471 }
else if ( !getClass().isInstance(arg) ) {
475 if( isTypedef == t.isTypedef &&
476 ( (
null != size && size.
equals(t.size) ) ||
477 (
null == size &&
null == t.size )
479 cvAttributes == t.cvAttributes &&
480 typedefCVAttributes == t.typedefCVAttributes &&
481 (
null == name ?
null == t.name : name.equals(t.name) )
498 if( !hasCachedSemanticHash ) {
502 hash = ((hash << 5) - hash) + cvAttributes;
503 hash = ((hash << 5) - hash) + typedefCVAttributes;
506 cachedSemanticHash = hash;
507 hasCachedSemanticHash =
true;
509 return cachedSemanticHash;
517 }
else if ( !(arg instanceof
Type) ||
518 !getClass().isInstance(arg) ) {
523 (
null == size &&
null == t.size )
526 ( cvAttributes == t.cvAttributes &&
527 typedefCVAttributes == t.typedefCVAttributes
556 if (
isConst())
return "const ";
Machine data description for alignment and size onle, see com.jogamp.gluegen.
Glue code generator for C functions and data structures.
Static Type config helper binding JavaConfiguration#relaxedEqualSemanticsTest() system wide.
Represents an array type.
Represents a bitfield in a struct.
Models all compound types, i.e., those containing fields: structs and unions.
Represents a double-word floating-point type (C type "double".)
Describes enumerated types.
int getNumEnumerates()
Number of enumerates defined in this enum.
StringBuilder appendEnums(final StringBuilder sb, final boolean cr)
Represents a single-word floating-point type (C type "float".)
Describes a function type, used to model both function declarations and (via PointerType) function po...
String toString()
Returns a string representation of this type.
Provides a level of indirection between the definition of a type's size and the absolute value of thi...
final boolean equals(final Object arg)
final boolean hasFixedNativeSize()
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
abstract long computeSize(MachineDataInfo machDesc)
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
final String getCName()
Returns the name of this type.
final boolean isArray()
Indicates whether this is an ArrayType.
final String getCVAttributesString()
Returns a string indicating the const/volatile attributes of this type.
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
final boolean isInt()
Indicates whether this is an IntType.
IntType asInt()
Casts this to an IntType or returns null if not an IntType.
Type(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus)
BitType asBit()
Casts this to a BitType or returns null if not a BitType.
final StringBuilder getSignature(StringBuilder sb)
abstract boolean equalSemanticsImpl(final Type t)
final int hashCode()
Hashcode for Types.
final boolean isVoid()
Indicates whether this is a VoidType.
Type clone(final ASTLocusTag newLoc)
Clones this instance using a new ASTLocusTag.
abstract int hashCodeImpl()
final boolean isBaseTypeConst()
Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.
final ASTLocusTag getASTLocusTag()
Returns this instance's ASTLocusTag, if available, otherwise returns null.
abstract boolean equalsImpl(final Type t)
Type getArrayBaseOrPointerTargetType()
Return getBaseType() if isArray() or returns getTargetType() otherwise.
final boolean isConst()
Indicates whether this type is const.
Type getBaseType()
Helper method to returns the bottom-most element type of this type, i.e.
VoidType asVoid()
Casts this to a VoidType or returns null if not a VoidType.
int arrayDimension()
Helper method for determining how many array dimentions this type represents (i.e....
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.
boolean isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.
final boolean isVolatile()
Indicates whether this type is volatile.
String getCName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
final boolean isFloat()
Indicates whether this is a FloatType.
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
final String getName()
Returns the name of this type.
boolean setTypedefName(final String name)
Set the typedef name of this type and renders this type a typedef, if given name has a length.
int pointerDepth()
Helper method for determining how many pointer indirections this type represents (i....
String toString()
Returns a string representation of this type.
FunctionType getTargetFunction()
Returns the target FunctionType if this type is isFunctionPointer().
final boolean isFunction()
Indicates whether this is a FunctionType.
abstract int hashCodeSemanticsImpl()
Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
final boolean hasSize()
Returns true if getSize() is not null, otherwise false.
boolean isPrimitive()
Indicates whether this type is a primitive type.
void visit(final TypeVisitor visitor)
Traverse this Type and all of its component types; for example, the return type and argument types of...
final boolean equals(final Object arg)
Equality test for Types inclusive its given name.
FloatType asFloat()
Casts this to a FloatType or returns null if not a FloatType.
final boolean relaxedEqSem
final SizeThunk getSize()
SizeThunk which computes size of this type in bytes.
final boolean isDouble()
Indicates whether this is a DoubleType.
FunctionType asFunction()
Casts this to a FunctionType or returns null if not a FunctionType.
final boolean isEnum()
Indicates whether this is an EnumType.
final Type newCVVariant(final int cvAttributes)
Return a variant of this type matching the given const/volatile attributes.
final String getDebugString()
ArrayType asArray()
Casts this to an ArrayType or returns null if not an ArrayType.
final boolean isPointer()
Indicates whether this is a PointerType.
String getName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
CompoundType asCompound()
Casts this to a CompoundType or returns null if not a CompoundType.
final int getCVAttributes()
final boolean isBit()
Indicates whether this is a BitType.
final long getSize(final MachineDataInfo machDesc)
Size of this type in bytes according to the given MachineDataInfo.
final boolean isTypedef()
Indicates whether this type is a typedef type, i.e.
final boolean isCompound()
Indicates whether this is a CompoundType.
Static enumeration of MachineDataInfo instances used for high performance data size and alignment loo...
Interface tag for ASTLocusTag provider.
Enumeration for const/volatile attributes.
static final int VOLATILE
Supports semantic equality and hash functions for types.
A visitor for Type's visitor model.
void visitType(Type t)
Visiting the given Type.