aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g71
-rw-r--r--src/java/com/jogamp/gluegen/CMethodBindingEmitter.java4
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java4
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/AliasedSymbol.java5
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/ArrayType.java21
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/BitType.java37
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/CompoundType.java53
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/DoubleType.java18
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/EnumType.java45
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/FloatType.java18
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java2
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/FunctionType.java40
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/IntType.java67
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java4
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/PointerType.java25
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java4
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/StructType.java20
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/Type.java108
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java6
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/UnionType.java20
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/VoidType.java16
21 files changed, 315 insertions, 273 deletions
diff --git a/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g b/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
index 595d770..0478293 100644
--- a/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
+++ b/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
@@ -411,6 +411,10 @@ options {
// dumpASTTree("XXX", t);
throw new GlueGenException(message, findASTLocusTag(t));
}
+ private void throwGlueGenException(final ASTLocusTag locusTag, final String message) throws GlueGenException {
+ // dumpASTTree("XXX", t);
+ throw new GlueGenException(message, locusTag);
+ }
/**
* Return ASTLocusTag in tree, or null if not found.
@@ -601,32 +605,32 @@ typeSpecifier[int attributes] returns [Type t] {
boolean unsig = ((attributes & UNSIGNED) != 0);
final ASTLocusTag locusTag = findASTLocusTag(typeSpecifier_AST_in);
}
- //
// TYPEDEF
- // UNSIGNED |
- // TOKEN TYPE NAME SIZE | ATTRIBS | LOCUS
- : "void" { t = new VoidType( cvAttrs, locusTag); }
- | "char" { t = new IntType("char" , SizeThunk.INT8, unsig, cvAttrs, false, locusTag); }
- | "short" { t = new IntType("short", SizeThunk.INT16, unsig, cvAttrs, false, locusTag); }
- | "int" { t = new IntType("int" , SizeThunk.INTxx, unsig, cvAttrs, false, locusTag); }
- | "long" { t = new IntType("long" , SizeThunk.LONG, unsig, cvAttrs, false, locusTag); }
- | "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs, locusTag); }
- | "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs, locusTag); }
- | "__int32" { t = new IntType("__int32", SizeThunk.INT32, unsig, cvAttrs, false, locusTag); }
- | "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsig, cvAttrs, false, locusTag); }
- | "int8_t" { t = new IntType("int8_t", SizeThunk.INT8, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "uint8_t" { t = new IntType("uint8_t", SizeThunk.INT8, true, cvAttrs, true, locusTag); } /* TS: always unsigned */
- | "int16_t" { t = new IntType("int16_t", SizeThunk.INT16, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "uint16_t" { t = new IntType("uint16_t", SizeThunk.INT16, true, cvAttrs, true, locusTag); } /* TS: always unsigned */
- | "int32_t" { t = new IntType("int32_t", SizeThunk.INT32, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT32, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT32, true, cvAttrs, true, locusTag); } /* TS: always unsigned */
- | "int64_t" { t = new IntType("int64_t", SizeThunk.INT64, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "uint64_t" { t = new IntType("uint64_t", SizeThunk.INT64, true, cvAttrs, true, locusTag); } /* TS: always unsigned */
- | "ptrdiff_t" { t = new IntType("ptrdiff_t", SizeThunk.POINTER, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "intptr_t" { t = new IntType("intptr_t", SizeThunk.POINTER, false, cvAttrs, true, locusTag); } /* TS: always signed */
- | "size_t" { t = new IntType("size_t", SizeThunk.POINTER, true, cvAttrs, true, locusTag); } /* TS: always unsigned */
- | "uintptr_t" { t = new IntType("uintptr_t", SizeThunk.POINTER, true, cvAttrs, true, locusTag); } /* TS: always unsigned */
+ // | TYPEDEF-UNSIGNED
+ // UNSIGNED | |
+ // TOKEN TYPE NAME SIZE | ATTRIBS | | LOCUS
+ : "void" { t = new VoidType( cvAttrs, locusTag); }
+ | "char" { t = new IntType("char" , SizeThunk.INT8, unsig, cvAttrs, false, false, locusTag); }
+ | "short" { t = new IntType("short", SizeThunk.INT16, unsig, cvAttrs, false, false, locusTag); }
+ | "int" { t = new IntType("int" , SizeThunk.INTxx, unsig, cvAttrs, false, false, locusTag); }
+ | "long" { t = new IntType("long" , SizeThunk.LONG, unsig, cvAttrs, false, false, locusTag); }
+ | "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs, locusTag); }
+ | "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs, locusTag); }
+ | "__int32" { t = new IntType("__int32", SizeThunk.INT32, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "int8_t" { t = new IntType("int8_t", SizeThunk.INT8, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "uint8_t" { t = new IntType("uint8_t", SizeThunk.INT8, unsig, cvAttrs, true, true, locusTag); } /* TD: unsigned */
+ | "int16_t" { t = new IntType("int16_t", SizeThunk.INT16, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "uint16_t" { t = new IntType("uint16_t", SizeThunk.INT16, unsig, cvAttrs, true, true, locusTag); } /* TD: unsigned */
+ | "int32_t" { t = new IntType("int32_t", SizeThunk.INT32, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT32, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT32, unsig, cvAttrs, true, true, locusTag); } /* TS: unsigned */
+ | "int64_t" { t = new IntType("int64_t", SizeThunk.INT64, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "uint64_t" { t = new IntType("uint64_t", SizeThunk.INT64, unsig, cvAttrs, true, true, locusTag); } /* TD: unsigned */
+ | "ptrdiff_t" { t = new IntType("ptrdiff_t", SizeThunk.POINTER, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "intptr_t" { t = new IntType("intptr_t", SizeThunk.POINTER, unsig, cvAttrs, true, false, locusTag); } /* TD: signed */
+ | "size_t" { t = new IntType("size_t", SizeThunk.POINTER, unsig, cvAttrs, true, true, locusTag); } /* TD: unsigned */
+ | "uintptr_t" { t = new IntType("uintptr_t", SizeThunk.POINTER, unsig, cvAttrs, true, true, locusTag); } /* TD: unsigned */
| t = structSpecifier[cvAttrs] ( attributeDecl )*
| t = unionSpecifier [cvAttrs] ( attributeDecl )*
| t = enumSpecifier [cvAttrs]
@@ -645,7 +649,7 @@ typedefName[int cvAttrs] returns [Type t] { t = null; }
{
final Type t0 = lookupInTypedefDictionary(typedefName_AST_in, id.getText());
debugPrint("Adding typedef lookup: [" + id.getText() + "] -> "+getDebugTypeString(t0));
- final Type t1 = t0.getCVVariant(cvAttrs);
+ final Type t1 = t0.newCVVariant(cvAttrs);
debugPrintln(" - cvvar -> "+getDebugTypeString(t1));
t = canonicalize(t1);
debugPrintln(" - canon -> "+getDebugTypeString(t));
@@ -669,12 +673,12 @@ structOrUnionBody[CompoundTypeKind kind, int cvAttrs] returns [CompoundType t] {
// fully declared struct, i.e. not anonymous
t = (CompoundType) canonicalize(lookupInStructDictionary(id.getText(), kind, cvAttrs, locusTag));
} ( addedAny = structDeclarationList[t] )?
- RCURLY { t.setBodyParsed(addedAny); }
+ RCURLY { t.setBodyParsed(); }
| LCURLY {
// anonymous declared struct
t = CompoundType.create(null, null, kind, cvAttrs, locusTag);
} ( structDeclarationList[t] )?
- RCURLY { t.setBodyParsed(false); }
+ RCURLY { t.setBodyParsed(); }
| id2:ID {
// anonymous struct
t = (CompoundType) canonicalize(lookupInStructDictionary(id2.getText(), kind, cvAttrs, locusTag));
@@ -835,6 +839,7 @@ initDeclList[TypeBox tb]
initDecl[TypeBox tb] {
String declName = null;
+ final ASTLocusTag locusTag = findASTLocusTag(initDecl_AST_in);
}
: #( NInitDecl
declName = declarator[tb] {
@@ -857,7 +862,7 @@ initDecl[TypeBox tb] {
debugPrint(" - redefine -> "+getDebugTypeString(t));
} else {
// Use new typedef, using a copy to preserve canonicalized base type
- t = (Type) t.clone();
+ t = t.clone(locusTag);
t.setTypedefName(declName);
debugPrint(" - newdefine -> "+getDebugTypeString(t));
}
@@ -878,16 +883,16 @@ initDecl[TypeBox tb] {
debugPrint(" - alias -> "+getDebugTypeString(t));
} else {
// copy to preserve canonicalized base type
- t = (Type) t.clone();
+ t = t.clone(locusTag);
t.setTypedefName(declName);
debugPrint(" - copy -> "+getDebugTypeString(t));
}
}
final Type dupT = typedefDictionary.get(declName);
if( null != dupT && !dupT.equalSemantics(t) ) {
- throwGlueGenException(initDecl_AST_in,
- String.format("Duplicate typedef w/ incompatible type:%n have '%s',%n this '%s'",
- getTypeString(dupT), getTypeString(t)));
+ throwGlueGenException(locusTag,
+ String.format("Duplicate typedef w/ incompatible type:%n this '%s',%n have '%s',%n previously declared here: %s",
+ getTypeString(t), getTypeString(dupT), dupT.getASTLocusTag()));
}
t = canonicalize(t);
debugPrintln(" - canon -> "+getDebugTypeString(t));
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
index 4599a56..fb617ef 100644
--- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
@@ -1037,7 +1037,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
int mode = 0;
if ( 1 == cReturnType.pointerDepth() && null != cReturnTargetType ) {
if( cReturnTargetType.isCompound() ) {
- if( !cReturnTargetType.isAnonymous() &&
+ if( !cReturnTargetType.isAnon() &&
cReturnTargetType.asCompound().getNumFields() > 0 )
{
// fully declared non-anonymous struct pointer: pass content
@@ -1047,7 +1047,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
"for function \"" + binding + "\": " +
"Structs to be emitted should have been laid out by this point " +
"(type " + cReturnTargetType.getCName() + " / " +
- cReturnTargetType.getDebugString() + " was not) for "+binding,
+ cReturnTargetType.getDebugString() + " was not) for "+binding.getCSymbol(),
binding.getCSymbol().getASTLocusTag()
);
}
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index dfcf92b..ca89b0e 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -1890,7 +1890,7 @@ public class JavaEmitter implements GlueEmitter {
if( isPointer ) {
// Getter Primitive Pointer
final FunctionType ft = new FunctionType(dummyFuncTypeName, SizeThunk.POINTER, fieldType, 0);
- ft.addArgument(containingCType.getCVVariant(containingCType.getCVAttributes() | CVAttributes.CONST),
+ ft.addArgument(containingCType.newCVVariant(containingCType.getCVAttributes() | CVAttributes.CONST),
CMethodBindingEmitter.cThisArgumentName());
ft.addArgument(int32Type, nativeArrayLengthArg);
final FunctionSymbol fs = new FunctionSymbol("get"+capitalFieldName, ft);
@@ -1998,7 +1998,7 @@ public class JavaEmitter implements GlueEmitter {
if( isPointer ) {
// Getter Struct Pointer
final FunctionType ft = new FunctionType(dummyFuncTypeName, SizeThunk.POINTER, fieldType, 0);
- ft.addArgument(containingCType.getCVVariant(containingCType.getCVAttributes() | CVAttributes.CONST),
+ ft.addArgument(containingCType.newCVVariant(containingCType.getCVAttributes() | CVAttributes.CONST),
CMethodBindingEmitter.cThisArgumentName());
ft.addArgument(int32Type, nativeArrayElemOffsetArg);
final FunctionSymbol fs = new FunctionSymbol("get"+capitalFieldName, ft);
diff --git a/src/java/com/jogamp/gluegen/cgram/types/AliasedSymbol.java b/src/java/com/jogamp/gluegen/cgram/types/AliasedSymbol.java
index 679d44d..73c65ef 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/AliasedSymbol.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/AliasedSymbol.java
@@ -107,6 +107,11 @@ public interface AliasedSymbol {
this.aliasedNames=new HashSet<String>();
this.name = origName;
}
+ public AliasedSymbolImpl(final AliasedSymbolImpl o) {
+ this.origName = o.origName;
+ this.aliasedNames = new HashSet<String>(o.aliasedNames);
+ this.name = o.origName;
+ }
@Override
public void rename(final String newName) {
if( null != newName && !name.equals(newName) ) {
diff --git a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java
index cabbcc1..ada34f7 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java
@@ -61,6 +61,16 @@ public class ArrayType extends MemoryLayoutType implements Cloneable {
this.elementType = elementType;
this.length = length;
}
+ private ArrayType(final ArrayType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ elementType = o.elementType;
+ length = o.length;
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new ArrayType(this, cvAttributes, astLocus);
+ }
@Override
protected int hashCodeImpl() {
@@ -91,7 +101,7 @@ public class ArrayType extends MemoryLayoutType implements Cloneable {
}
@Override
- public boolean hasName() { return null != elementType.getName(); }
+ public boolean isAnon() { return elementType.isAnon(); }
@Override
public String getName(final boolean includeCVAttrs) {
@@ -151,13 +161,4 @@ public class ArrayType extends MemoryLayoutType implements Cloneable {
super.visit(arg);
elementType.visit(arg);
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new ArrayType(elementType, getSize(), length, cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/BitType.java b/src/java/com/jogamp/gluegen/cgram/types/BitType.java
index b7488ea..834ff95 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/BitType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/BitType.java
@@ -57,10 +57,23 @@ public class BitType extends IntType implements Cloneable {
this.offset = lsbOffset;
}
+ private BitType(final BitType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ underlyingType = o.underlyingType;
+ sizeInBits = o.sizeInBits;
+ offset = o.offset;
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new BitType(this, cvAttributes, astLocus);
+ }
+
@Override
protected int hashCodeImpl() {
// 31 * x == (x << 5) - x
- int hash = underlyingType.hashCode();
+ int hash = super.hashCodeImpl();
+ hash = ((hash << 5) - hash) + underlyingType.hashCode();
hash = ((hash << 5) - hash) + sizeInBits;
return ((hash << 5) - hash) + offset;
}
@@ -68,7 +81,8 @@ public class BitType extends IntType implements Cloneable {
@Override
protected boolean equalsImpl(final Type arg) {
final BitType t = (BitType) arg;
- return underlyingType.equals(t.underlyingType) &&
+ return super.equalsImpl(arg) &&
+ underlyingType.equals(t.underlyingType) &&
sizeInBits == t.sizeInBits &&
offset == t.offset;
}
@@ -76,7 +90,8 @@ public class BitType extends IntType implements Cloneable {
@Override
protected int hashCodeSemanticsImpl() {
// 31 * x == (x << 5) - x
- int hash = underlyingType.hashCodeSemantics();
+ int hash = super.hashCodeSemanticsImpl();
+ hash = ((hash << 5) - hash) + underlyingType.hashCodeSemantics();
hash = ((hash << 5) - hash) + sizeInBits;
return ((hash << 5) - hash) + offset;
}
@@ -84,9 +99,10 @@ public class BitType extends IntType implements Cloneable {
@Override
protected boolean equalSemanticsImpl(final Type arg) {
final BitType t = (BitType) arg;
- return underlyingType.equalSemantics(t.underlyingType) &&
- sizeInBits == t.sizeInBits &&
- offset == t.offset;
+ return super.equalSemanticsImpl(arg) &&
+ underlyingType.equalSemantics(t.underlyingType) &&
+ sizeInBits == t.sizeInBits &&
+ offset == t.offset;
}
@Override
@@ -108,13 +124,4 @@ public class BitType extends IntType implements Cloneable {
super.visit(arg);
underlyingType.visit(arg);
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new BitType(underlyingType, sizeInBits, offset, cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java b/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java
index dc5becf..56bcdda 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java
@@ -54,18 +54,6 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable
private ArrayList<Field> fields;
private boolean visiting;
private boolean bodyParsed;
- /**
- *
- * @param name
- * @param size
- * @param cvAttributes
- * @param structName
- */
- CompoundType(final String name, final SizeThunk size, final int cvAttributes,
- final String structName, final ASTLocusTag astLocus) {
- super(name, size, cvAttributes, astLocus);
- this.structName = structName;
- }
@Override
public void rename(final String newName) {
@@ -117,13 +105,19 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable
return res;
}
- @Override
- public Object clone() {
- final CompoundType n = (CompoundType) super.clone();
- if(null!=this.fields) {
- n.fields = new ArrayList<Field>(this.fields);
+ CompoundType(final String name, final SizeThunk size, final int cvAttributes,
+ final String structName, final ASTLocusTag astLocus) {
+ super(null == name ? structName : name, size, cvAttributes, astLocus);
+ this.structName = structName;
+ }
+
+ CompoundType(final CompoundType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ this.structName = o.structName;
+ if(null != o.fields) {
+ fields = new ArrayList<Field>(o.fields);
}
- return n;
+ bodyParsed = o.bodyParsed;
}
@Override
@@ -200,30 +194,13 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable
/**
* Indicates to this CompoundType that its body has been parsed and
* that no more {@link #addField} operations will be made.
- * <p>
- * If {@code evalStructTypeName} is {@code true}, {@link #evalStructTypeName()} is performed.
- * </p>
* @throws IllegalStateException If called twice.
*/
- public void setBodyParsed(final boolean evalStructTypeName) throws IllegalStateException {
+ public void setBodyParsed() throws IllegalStateException {
if (bodyParsed) {
throw new IllegalStateException("Body of this CompoundType has been already closed");
}
bodyParsed = true;
- if( evalStructTypeName ) {
- evalStructTypeName();
- }
- }
- public boolean isBodyParsed() { return bodyParsed; }
- /**
- * {@link #getName() name} is set to {@link #getStructName() struct-name},
- * which promotes this instance for emission by its struct-name.
- */
- public Type evalStructTypeName() {
- if( null == getName() ) {
- setName(structName);
- }
- return this;
}
/** Indicates whether this type was declared as a struct. */
@@ -254,12 +231,12 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable
super.visit(arg);
final int n = getNumFields();
for (int i = 0; i < n; i++) {
- final Field f = getField(i);
- f.getType().visit(arg);
+ getField(i).getType().visit(arg);
}
} finally {
visiting = false;
}
+ return;
}
public String getStructString() {
diff --git a/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java b/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java
index 7bcf767..133a322 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java
@@ -48,6 +48,15 @@ public class DoubleType extends PrimitiveType implements Cloneable {
super(name, size, cvAttributes, astLocus);
}
+ private DoubleType(final DoubleType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new DoubleType(this, cvAttributes, astLocus);
+ }
+
@Override
public DoubleType asDouble() {
return this;
@@ -72,13 +81,4 @@ public class DoubleType extends PrimitiveType implements Cloneable {
protected boolean equalSemanticsImpl(final Type t) {
return true;
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new DoubleType(getName(), getSize(), cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/EnumType.java b/src/java/com/jogamp/gluegen/cgram/types/EnumType.java
index 47691cd..f49c2ec 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/EnumType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/EnumType.java
@@ -50,8 +50,6 @@ import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp;
they have a set of named values. */
public class EnumType extends IntType implements Cloneable {
- private IntType underlyingType;
-
private static class Enum implements TypeComparator.SemanticEqualityOp {
final String name;
final long value;
@@ -101,6 +99,7 @@ public class EnumType extends IntType implements Cloneable {
public String toString() { return name+" = "+value; }
}
+ private final IntType underlyingType;
private ArrayList<Enum> enums;
public EnumType(final String name) {
@@ -113,48 +112,48 @@ public class EnumType extends IntType implements Cloneable {
this.underlyingType = new IntType(name, enumSizeInBytes, false, CVAttributes.CONST, astLocus);
}
- protected EnumType(final String name, final IntType underlyingType, final int cvAttributes, final ASTLocusTag astLocus) {
- super(name, underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes, astLocus);
- this.underlyingType = underlyingType;
+ private EnumType(final EnumType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ underlyingType = o.underlyingType;
+ if(null != o.enums) {
+ enums = new ArrayList<Enum>(o.enums);
+ }
}
@Override
- public Object clone() {
- final EnumType n = (EnumType) super.clone();
- if(null!=this.underlyingType) {
- n.underlyingType = (IntType) this.underlyingType.clone();
- }
- if(null!=this.enums) {
- n.enums = new ArrayList<Enum>(this.enums);
- }
- return n;
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new EnumType(this, cvAttributes, astLocus);
}
@Override
protected int hashCodeImpl() {
// 31 * x == (x << 5) - x
- final int hash = underlyingType.hashCode();
+ int hash = super.hashCodeImpl();
+ hash = ((hash << 5) - hash) + underlyingType.hashCode();
return ((hash << 5) - hash) + TypeComparator.listsHashCode(enums);
}
@Override
protected boolean equalsImpl(final Type arg) {
final EnumType t = (EnumType) arg;
- return underlyingType.equals(t.underlyingType) &&
+ return super.equalsImpl(arg) &&
+ underlyingType.equals(t.underlyingType) &&
TypeComparator.listsEqual(enums, t.enums);
}
@Override
protected int hashCodeSemanticsImpl() {
// 31 * x == (x << 5) - x
- final int hash = underlyingType.hashCodeSemantics();
+ int hash = super.hashCodeSemanticsImpl();
+ hash = ((hash << 5) - hash) + underlyingType.hashCodeSemantics();
return ((hash << 5) - hash) + TypeComparator.listsHashCodeSemantics(enums);
}
@Override
protected boolean equalSemanticsImpl(final Type arg) {
final EnumType t = (EnumType) arg;
- return underlyingType.equalSemantics(t.underlyingType) &&
+ return super.equalSemanticsImpl(arg) &&
+ underlyingType.equalSemantics(t.underlyingType) &&
TypeComparator.listsEqualSemantics(enums, t.enums);
}
@@ -242,14 +241,4 @@ public class EnumType extends IntType implements Cloneable {
super.visit(arg);
underlyingType.visit(arg);
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- final EnumType t = new EnumType(getName(), underlyingType, cvAttributes, astLocus);
- t.enums = enums;
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/FloatType.java b/src/java/com/jogamp/gluegen/cgram/types/FloatType.java
index 2632409..2e7a2cf 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/FloatType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/FloatType.java
@@ -49,6 +49,15 @@ public class FloatType extends PrimitiveType implements Cloneable {
super(name, size, cvAttributes, astLocus);
}
+ private FloatType(final FloatType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new FloatType(this, cvAttributes, astLocus);
+ }
+
@Override
public FloatType asFloat() { return this; }
@@ -71,13 +80,4 @@ public class FloatType extends PrimitiveType implements Cloneable {
protected boolean equalSemanticsImpl(final Type t) {
return true;
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new FloatType(getName(), getSize(), cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java
index 2b78e8c..55585fc 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java
@@ -113,7 +113,7 @@ public class FunctionSymbol extends AliasedSymbolImpl implements AliasedSemantic
@Override
public String toString() {
- return getType().toString(getName());
+ return getType().toString(getName(), false);
}
/** Helper routine for emitting native javadoc tags */
diff --git a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
index 7ccc4c0..2b9dec7 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
@@ -61,16 +61,25 @@ public class FunctionType extends Type implements Cloneable {
this.returnType = returnType;
}
- @Override
- public Object clone() {
- final FunctionType n = (FunctionType) super.clone();
- if(null!=this.argumentTypes) {
- n.argumentTypes = new ArrayList<Type>(this.argumentTypes);
+ private FunctionType(final FunctionType o, final ASTLocusTag astLocus) {
+ super(o, o.getCVAttributes(), astLocus);
+ returnType = o.returnType;
+ if(null != o.argumentTypes) {
+ argumentTypes = new ArrayList<Type>(o.argumentTypes);
+ }
+ if(null != o.argumentNames) {
+ argumentNames = new ArrayList<String>(o.argumentNames);
}
- if(null!=this.argumentNames) {
- n.argumentNames = new ArrayList<String>(this.argumentNames);
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ if( newCVVariant ) {
+ // Functions don't have const/volatile attributes
+ return this;
+ } else {
+ return new FunctionType(this, astLocus);
}
- return n;
}
@Override
@@ -146,18 +155,15 @@ public class FunctionType extends Type implements Cloneable {
@Override
public String toString() {
- return toString(null);
- }
-
- public String toString(final String functionName) {
- return toString(functionName, false);
+ return toString(null, false);
}
public String toString(final String functionName, final boolean emitNativeTag) {
return toString(functionName, null, emitNativeTag, false);
}
- String toString(final String functionName, final String callingConvention, final boolean emitNativeTag, final boolean isPointer) {
+ String toString(final String functionName, final String callingConvention,
+ final boolean emitNativeTag, final boolean isPointer) {
final StringBuilder res = new StringBuilder();
res.append(getReturnType().getCName(true));
res.append(" ");
@@ -216,10 +222,4 @@ public class FunctionType extends Type implements Cloneable {
getArgumentType(i).visit(arg);
}
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- // Functions don't have const/volatile attributes
- return this;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/IntType.java b/src/java/com/jogamp/gluegen/cgram/types/IntType.java
index fd2509e..2433fc6 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/IntType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/IntType.java
@@ -44,6 +44,7 @@ import com.jogamp.gluegen.ASTLocusTag;
public class IntType extends PrimitiveType implements Cloneable {
private final boolean unsigned;
+ private boolean typedefUnsigned;
public IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes) {
this(name, size, unsigned, cvAttributes, null);
@@ -54,42 +55,79 @@ public class IntType extends PrimitiveType implements Cloneable {
final ASTLocusTag astLocus) {
super(name, size, cvAttributes, astLocus);
this.unsigned = unsigned;
+ this.typedefUnsigned = false;
}
- /** Only for HeaderParser */
+ /**
+ * Only for HeaderParser!
+ *
+ * @param name the name
+ * @param size the size
+ * @param unsigned true if this instance is unsigned, not the <i>typedef</i>!
+ * @param cvAttributes the cvAttributes for this instance, not for the <i>typedef</i>!
+ * @param isTypedef true if this instance is a <i>typedef</i> variant
+ * @param typedefUnsigned true if the <i>typedef</i> itself is unsigned
+ * @param astLocus the location in source code
+ */
public IntType(final String name, final SizeThunk size,
final boolean unsigned, final int cvAttributes,
- final boolean isTypedef,
+ final boolean isTypedef, final boolean typedefUnsigned,
final ASTLocusTag astLocus) {
super(name, size, cvAttributes, astLocus);
this.unsigned = unsigned;
if( isTypedef ) {
- setTypedef(cvAttributes);
+ // the 'cvAttributes' are intended for this instance, not the 'typedef cvAttributes'!
+ setTypedef(0);
+ this.typedefUnsigned = typedefUnsigned;
+ } else {
+ this.typedefUnsigned = false;
}
}
+ IntType(final IntType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ this.unsigned = o.unsigned;
+ this.typedefUnsigned = o.typedefUnsigned;
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new IntType(this, cvAttributes, astLocus);
+ }
+
@Override
protected int hashCodeImpl() {
// 31 * x == (x << 5) - x
- return 31 + ( unsigned ? 1 : 0 );
+ int hash = 1;
+ hash = ((hash << 5) - hash) + ( unsigned ? 1 : 0 );
+ return ((hash << 5) - hash) + ( typedefUnsigned ? 1 : 0 );
}
@Override
protected boolean equalsImpl(final Type arg) {
final IntType t = (IntType) arg;
- return unsigned == t.unsigned;
+ return unsigned == t.unsigned &&
+ typedefUnsigned == t.typedefUnsigned;
}
@Override
protected int hashCodeSemanticsImpl() {
- return hashCodeImpl();
+ // 31 * x == (x << 5) - x
+ int hash = 1;
+ if( !relaxedEqSem ) {
+ hash = ((hash << 5) - hash) + ( unsigned ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( typedefUnsigned ? 1 : 0 );
+ }
+ return hash;
}
@Override
protected boolean equalSemanticsImpl(final Type arg) {
final IntType t = (IntType) arg;
return relaxedEqSem ||
- unsigned == t.unsigned;
+ ( unsigned == t.unsigned &&
+ typedefUnsigned == t.typedefUnsigned
+ );
}
@Override
@@ -104,7 +142,7 @@ public class IntType extends PrimitiveType implements Cloneable {
@Override
public String getCName(final boolean includeCVAttrs) {
- if ( isTypedef() || !isUnsigned() ) {
+ if ( !unsigned || typedefUnsigned ) {
return super.getCName(includeCVAttrs);
} else {
return "unsigned "+super.getCName(includeCVAttrs);
@@ -113,15 +151,16 @@ public class IntType extends PrimitiveType implements Cloneable {
@Override
public String toString() {
- return getCVAttributesString() + ( isUnsigned() && !isTypedef() ? "unsigned " : "") + getCName();
+ return getCVAttributesString() + ( unsigned && !typedefUnsigned ? "unsigned " : "") + getCName();
}
@Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new IntType(getName(), getSize(), isUnsigned(), cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
+ public boolean setTypedefName(final String name) {
+ if( super.setTypedefName(name) ) {
+ typedefUnsigned = unsigned;
+ return true;
+ } else {
+ return false;
}
- return t;
}
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java b/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java
index ba46aed..8b06a7e 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java
@@ -36,6 +36,10 @@ public abstract class MemoryLayoutType extends Type {
super(name, size, cvAttributes, astLocus);
isLayouted = false;
}
+ MemoryLayoutType(final MemoryLayoutType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ isLayouted = o.isLayouted;
+ }
public boolean isLayouted() { return isLayouted; }
public void setLayouted() {
diff --git a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java
index 76cb4b3..5707b5c 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java
@@ -55,6 +55,16 @@ public class PointerType extends Type implements Cloneable {
this.targetType = targetType;
}
+ private PointerType(final PointerType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ targetType = o.targetType;
+ }
+
+ @Override
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new PointerType(this, cvAttributes, astLocus);
+ }
+
@Override
protected int hashCodeImpl() {
return targetType.hashCode();
@@ -78,11 +88,11 @@ public class PointerType extends Type implements Cloneable {
}
@Override
- public boolean hasName() {
+ public boolean isAnon() {
if ( isTypedef() ) {
- return super.hasName();
+ return super.isAnon();
} else {
- return targetType.hasName();
+ return targetType.isAnon();
}
}
@@ -165,13 +175,4 @@ public class PointerType extends Type implements Cloneable {
super.visit(arg);
targetType.visit(arg);
}
-
- @Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new PointerType(getSize(), targetType, cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getName(), getTypedefCVAttributes());
- }
- return t;
- }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java b/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java
index 69e28ab..76f3ff1 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java
@@ -47,6 +47,10 @@ public abstract class PrimitiveType extends Type implements Cloneable {
super(name, size, cvAttributes, astLocus);
}
+ PrimitiveType(final PrimitiveType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ }
+
@Override
public boolean isPrimitive() {
return true;
diff --git a/src/java/com/jogamp/gluegen/cgram/types/StructType.java b/src/java/com/jogamp/gluegen/cgram/types/StructType.java
index 7f2f865..fa78006 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/StructType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/StructType.java
@@ -35,19 +35,17 @@ public class StructType extends CompoundType {
super (name, size, cvAttributes, structName, astLocus);
}
- @Override
- public final boolean isStruct() { return true; }
- @Override
- public final boolean isUnion() { return false; }
+ private StructType(final StructType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ }
@Override
- Type newCVVariant(final int cvAttributes) {
- final StructType t = new StructType(getName(), getSize(), cvAttributes, getStructName(), astLocus);
- t.setFields(getFields());
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new StructType(this, cvAttributes, astLocus);
}
+ @Override
+ public final boolean isStruct() { return true; }
+ @Override
+ public final boolean isUnion() { return false; }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java
index 04ea3a3..04c46af 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/Type.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java
@@ -51,9 +51,10 @@ import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp;
double. All types have an associated name. Structs and unions are
modeled as "compound" types -- composed of fields of primitive or
other types. */
-public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTagProvider {
+public abstract class Type implements SemanticEqualityOp, ASTLocusTagProvider {
public final boolean relaxedEqSem;
private final int cvAttributes;
+ final ASTLocusTag astLocus;
private String name;
private SizeThunk size;
private int typedefCVAttributes;
@@ -62,16 +63,25 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
private int cachedHash;
private boolean hasCachedSemanticHash;
private int cachedSemanticHash;
- final ASTLocusTag astLocus;
protected Type(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus) {
setName(name); // -> clearCache()
this.relaxedEqSem = TypeConfig.relaxedEqualSemanticsTest();
this.cvAttributes = cvAttributes;
+ this.astLocus = astLocus;
this.size = size;
this.typedefCVAttributes = 0;
this.isTypedef = false;
+ }
+ Type(final Type o, final int cvAttributes, final ASTLocusTag astLocus) {
+ this.relaxedEqSem = o.relaxedEqSem;
+ this.cvAttributes = cvAttributes;
this.astLocus = astLocus;
+ this.name = o.name;
+ this.size = o.size;
+ this.typedefCVAttributes = o.typedefCVAttributes;
+ this.isTypedef = o.isTypedef;
+ clearCache();
}
protected final void clearCache() {
@@ -81,21 +91,40 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
cachedSemanticHash = 0;
}
- @Override
- public Object clone() {
- try {
- return super.clone();
- } catch (final CloneNotSupportedException ex) {
- throw new InternalError();
+ /**
+ * Return a variant of this type matching the given const/volatile
+ * attributes. May return this object if the attributes match.
+ */
+ public final Type newCVVariant(final int cvAttributes) {
+ if (this.cvAttributes == cvAttributes) {
+ return this;
+ } else {
+ return newVariantImpl(true, cvAttributes, astLocus);
}
}
+ /**
+ * Clones this instance using a new {@link ASTLocusTag}.
+ */
+ public Type clone(final ASTLocusTag newLoc) {
+ return newVariantImpl(true, cvAttributes, newLoc);
+ }
+
+ /**
+ * Create a new variant of this type matching the given parameter
+ * <p>
+ * Implementation <i>must</i> use {@link Type}'s copy-ctor: {@link #Type(Type, int, ASTLocusTag)}!
+ * </p>
+ * @param newCVVariant true if new variant is intended to have new <i>cvAttributes</i>
+ * @param cvAttributes the <i>cvAttributes</i> to be used
+ * @param astLocus the {@link ASTLocusTag} to be used
+ */
+ abstract Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus);
+
@Override
public final ASTLocusTag getASTLocusTag() { return astLocus; }
- public final boolean isAnonymous() { return null == name; }
-
- public boolean hasName() { return null != name; }
+ public boolean isAnon() { return null == name; }
/** 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
@@ -143,10 +172,6 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
}
// For debugging
public final String getDebugString() {
- return getDebugString(false);
- }
- // For debugging
- public final String getDebugString(final boolean withASTLoc) {
final StringBuilder sb = new StringBuilder();
boolean prepComma = false;
sb.append("CType[");
@@ -245,9 +270,6 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
}
sb.append("]");
}
- if( withASTLoc ) {
- sb.append(", loc ").append(astLocus);
- }
sb.append("]");
return sb.toString();
}
@@ -267,7 +289,7 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
* of hashes.
* </p>
*/
- protected final boolean setName(final String name) {
+ private final boolean setName(final String name) {
clearCache();
if( null == name || 0 == name.length() ) {
this.name = name;
@@ -286,29 +308,19 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
* of hashes.
* </p>
*/
- public final void setTypedefName(final String name) {
+ public boolean setTypedefName(final String name) {
if( setName(name) ) {
// Capture the const/volatile attributes at the time of typedef so
// we don't redundantly repeat them in the CV attributes string
typedefCVAttributes = cvAttributes;
isTypedef = true;
- }
- }
- /**
- * Set the typedef name of this type and renders this type a typedef,
- * if given {@code name} has a length.
- * <p>
- * Method issues {@link #clearCache()}, to force re-evaluation
- * of hashes.
- * </p>
- */
- final void setTypedef(final String name, final int typedefedCVAttributes) {
- if( setName(name) ) {
- this.typedefCVAttributes = typedefedCVAttributes;
- this.isTypedef = true;
+ return true;
+ } else {
+ return false;
}
}
final void setTypedef(final int typedefedCVAttributes) {
+ this.name = this.name.intern(); // just make sure ..
this.typedefCVAttributes = typedefedCVAttributes;
this.isTypedef = true;
clearCache();
@@ -418,6 +430,7 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
int hash = 31 + ( isTypedef ? 1 : 0 );
hash = ((hash << 5) - hash) + ( null != size ? size.hashCode() : 0 );
hash = ((hash << 5) - hash) + cvAttributes;
+ hash = ((hash << 5) - hash) + typedefCVAttributes;
hash = ((hash << 5) - hash) + ( null != name ? name.hashCode() : 0 );
if( !isTypedef ) {
hash = ((hash << 5) - hash) + hashCodeImpl();
@@ -445,6 +458,7 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
( null == size && null == t.size )
) &&
cvAttributes == t.cvAttributes &&
+ typedefCVAttributes == t.typedefCVAttributes &&
( null == name ? null == t.name : name.equals(t.name) )
)
{
@@ -467,6 +481,7 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
int hash = 31 + ( null != size ? size.hashCodeSemantics() : 0 );
if( !relaxedEqSem ) {
hash = ((hash << 5) - hash) + cvAttributes;
+ hash = ((hash << 5) - hash) + typedefCVAttributes;
}
hash = ((hash << 5) - hash) + hashCodeSemanticsImpl();
cachedSemanticHash = hash;
@@ -488,7 +503,11 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
if( ( ( null != size && size.equalSemantics(t.size) ) ||
( null == size && null == t.size )
) &&
- ( relaxedEqSem || cvAttributes == t.cvAttributes )
+ ( relaxedEqSem ||
+ ( cvAttributes == t.cvAttributes &&
+ typedefCVAttributes == t.typedefCVAttributes
+ )
+ )
)
{
return equalSemanticsImpl(t);
@@ -499,8 +518,10 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
}
protected abstract boolean equalSemanticsImpl(final Type t);
- /** Visit this type and all of the component types of this one; for
- example, the return type and argument types of a FunctionType. */
+ /**
+ * Traverse this {@link Type} and all of its component types; for
+ * example, the return type and argument types of a FunctionType.
+ */
public void visit(final TypeVisitor visitor) {
visitor.visitType(this);
}
@@ -518,19 +539,6 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag
return "";
}
- /** Return a variant of this type matching the given const/volatile
- attributes. May return this object if the attributes match. */
- public final Type getCVVariant(final int cvAttributes) {
- if (this.cvAttributes == cvAttributes) {
- return this;
- }
- return newCVVariant(cvAttributes);
- }
-
- /** Create a new variant of this type matching the given
- const/volatile attributes. */
- abstract Type newCVVariant(int cvAttributes);
-
/** 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. */
diff --git a/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java b/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java
index 89c014b..ed5cfa9 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java
@@ -39,6 +39,12 @@
package com.jogamp.gluegen.cgram.types;
+/**
+ * A visitor for {@link Type}'s visitor model.
+ */
public interface TypeVisitor {
+ /**
+ * Visiting the given {@link Type}.
+ */
public void visitType(Type t);
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/UnionType.java b/src/java/com/jogamp/gluegen/cgram/types/UnionType.java
index e03d671..8c6d9dd 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/UnionType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/UnionType.java
@@ -35,19 +35,17 @@ public class UnionType extends CompoundType {
super (name, size, cvAttributes, structName, astLocus);
}
- @Override
- public final boolean isStruct() { return false; }
- @Override
- public final boolean isUnion() { return true; }
+ private UnionType(final UnionType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ }
@Override
- Type newCVVariant(final int cvAttributes) {
- final UnionType t = new UnionType(getName(), getSize(), cvAttributes, getStructName(), astLocus);
- t.setFields(getFields());
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new UnionType(this, cvAttributes, astLocus);
}
+ @Override
+ public final boolean isStruct() { return false; }
+ @Override
+ public final boolean isUnion() { return true; }
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/VoidType.java b/src/java/com/jogamp/gluegen/cgram/types/VoidType.java
index f63bda3..bf51523 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/VoidType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/VoidType.java
@@ -51,18 +51,18 @@ public class VoidType extends Type implements Cloneable {
super(name, null, cvAttributes, astLocus);
}
+ private VoidType(final VoidType o, final int cvAttributes, final ASTLocusTag astLocus) {
+ super(o, cvAttributes, astLocus);
+ }
+
@Override
- public VoidType asVoid() {
- return this;
+ Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
+ return new VoidType(this, cvAttributes, astLocus);
}
@Override
- Type newCVVariant(final int cvAttributes) {
- final Type t = new VoidType(getName(), cvAttributes, astLocus);
- if( isTypedef() ) {
- t.setTypedef(getTypedefCVAttributes());
- }
- return t;
+ public VoidType asVoid() {
+ return this;
}
@Override