diff options
author | Sven Gothel <[email protected]> | 2015-03-07 08:25:36 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-03-07 08:25:36 +0100 |
commit | eca019cdea4017227e951d8a9eb30cb34fca4a07 (patch) | |
tree | 214e4837e6f448873c03c886adb2ccf2af7782ab /src/java/com/jogamp/gluegen/cgram | |
parent | 6a0822b03de2976c5bc37544c50e70094eeb94a7 (diff) |
Bug 1134 - Pass ASTLocationTag to all types, used for GlueGenException
Enhances semantic exception in code generation
by adding the AST location of the type or function declaration.
Diffstat (limited to 'src/java/com/jogamp/gluegen/cgram')
14 files changed, 208 insertions, 105 deletions
diff --git a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java index 281c68d..672bccf 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java @@ -40,6 +40,8 @@ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + /** Represents an array type. This differs from a pointer type in C syntax by the use of "[]" rather than "*". The length may or may not be known; if the length is unknown then a negative number @@ -49,8 +51,13 @@ public class ArrayType extends MemoryLayoutType implements Cloneable { private final Type elementType; private final int length; - public ArrayType(final Type elementType, final SizeThunk sizeInBytes, final int length, final int cvAttributes) { - super(elementType.getName() + " *", sizeInBytes, cvAttributes); + public ArrayType(final Type elementType, final SizeThunk sizeInBytes, final int length, + final int cvAttributes) { + this(elementType, sizeInBytes, length, cvAttributes, null); + } + public ArrayType(final Type elementType, final SizeThunk sizeInBytes, final int length, + final int cvAttributes, final ASTLocusTag astLocus) { + super(elementType.getName() + " *", sizeInBytes, cvAttributes, astLocus); this.elementType = elementType; this.length = length; } @@ -147,6 +154,10 @@ public class ArrayType extends MemoryLayoutType implements Cloneable { @Override Type newCVVariant(final int cvAttributes) { - return new ArrayType(elementType, getSize(), length, 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 87eb8ce..b7488ea 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/BitType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/BitType.java @@ -40,7 +40,7 @@ package com.jogamp.gluegen.cgram.types; -import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp; +import com.jogamp.gluegen.ASTLocusTag; /** Represents a bitfield in a struct. */ @@ -49,8 +49,9 @@ public class BitType extends IntType implements Cloneable { private final int sizeInBits; private final int offset; - public BitType(final IntType underlyingType, final int sizeInBits, final int lsbOffset, final int cvAttributes) { - super(underlyingType.getName(), underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes); + public BitType(final IntType underlyingType, final int sizeInBits, final int lsbOffset, + final int cvAttributes, final ASTLocusTag astLocus) { + super(underlyingType.getName(), underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes, astLocus); this.underlyingType = underlyingType; this.sizeInBits = sizeInBits; this.offset = lsbOffset; @@ -110,6 +111,10 @@ public class BitType extends IntType implements Cloneable { @Override Type newCVVariant(final int cvAttributes) { - return new BitType(underlyingType, sizeInBits, offset, 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 c9c4223..264389b 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java @@ -42,6 +42,8 @@ package com.jogamp.gluegen.cgram.types; import java.util.*; +import com.jogamp.gluegen.ASTLocusTag; + /** Models all compound types, i.e., those containing fields: structs and unions. The boolean type accessors indicate how the type is really defined. */ @@ -59,8 +61,9 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable * @param cvAttributes * @param structName */ - CompoundType(final String name, final SizeThunk size, final int cvAttributes, final String structName) { - super(name, size, cvAttributes); + CompoundType(final String name, final SizeThunk size, final int cvAttributes, + final String structName, final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); this.structName = structName; } @@ -96,15 +99,17 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable * @param cvAttributes * @return */ - public static CompoundType create(final String structName, final SizeThunk size, final CompoundTypeKind kind, final int cvAttributes) + public static CompoundType create(final String structName, final SizeThunk size, + final CompoundTypeKind kind, final int cvAttributes, + final ASTLocusTag astLocus) { final CompoundType res; switch (kind) { case STRUCT: - res = new StructType(null, size, cvAttributes, structName); + res = new StructType(null, size, cvAttributes, structName, astLocus); break; case UNION: - res = new UnionType(null, size, cvAttributes, structName); + res = new UnionType(null, size, cvAttributes, structName, astLocus); break; default: throw new RuntimeException("OO relation "+kind+" / Compount not yet supported"); @@ -165,7 +170,7 @@ public abstract class CompoundType extends MemoryLayoutType implements Cloneable @Override public String getCName(final boolean includeCVAttrs) { - if( hasTypedefName() ) { + if( isTypedef() ) { return getName(includeCVAttrs); } else { return (isStruct() ? "struct " : "union ")+getName(includeCVAttrs); diff --git a/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java b/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java index 1e13701..7bcf767 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java @@ -39,11 +39,13 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + /** Represents a double-word floating-point type (C type "double".) */ public class DoubleType extends PrimitiveType implements Cloneable { - public DoubleType(final String name, final SizeThunk size, final int cvAttributes) { - super(name, size, cvAttributes); + public DoubleType(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); } @Override @@ -73,6 +75,10 @@ public class DoubleType extends PrimitiveType implements Cloneable { @Override Type newCVVariant(final int cvAttributes) { - return new DoubleType(getName(), getSize(), 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 7fa22e4..47691cd 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/EnumType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/EnumType.java @@ -43,13 +43,12 @@ import java.util.ArrayList; import java.util.NoSuchElementException; import com.jogamp.gluegen.ASTLocusTag; -import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider; import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp; /** Describes enumerated types. Enumerations are like ints except that they have a set of named values. */ -public class EnumType extends IntType implements Cloneable, ASTLocusTagProvider { +public class EnumType extends IntType implements Cloneable { private IntType underlyingType; @@ -103,30 +102,23 @@ public class EnumType extends IntType implements Cloneable, ASTLocusTagProvider } private ArrayList<Enum> enums; - private final ASTLocusTag astLocus; public EnumType(final String name) { super(name, SizeThunk.LONG, false, CVAttributes.CONST); this.underlyingType = new IntType(name, SizeThunk.LONG, false, CVAttributes.CONST); - this.astLocus = null; } public EnumType(final String name, final SizeThunk enumSizeInBytes, final ASTLocusTag astLocus) { - super(name, enumSizeInBytes, false, CVAttributes.CONST); - this.underlyingType = new IntType(name, enumSizeInBytes, false, CVAttributes.CONST); - this.astLocus = astLocus; + super(name, enumSizeInBytes, false, CVAttributes.CONST, astLocus); + 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); + super(name, underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes, astLocus); this.underlyingType = underlyingType; - this.astLocus = astLocus; } @Override - public ASTLocusTag getASTLocusTag() { return astLocus; } - - @Override public Object clone() { final EnumType n = (EnumType) super.clone(); if(null!=this.underlyingType) { @@ -255,6 +247,9 @@ public class EnumType extends IntType implements Cloneable, ASTLocusTagProvider 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 0428543..2632409 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/FloatType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/FloatType.java @@ -40,11 +40,13 @@ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + /** Represents a single-word floating-point type (C type "float".) */ public class FloatType extends PrimitiveType implements Cloneable { - public FloatType(final String name, final SizeThunk size, final int cvAttributes) { - super(name, size, cvAttributes); + public FloatType(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); } @Override @@ -72,6 +74,10 @@ public class FloatType extends PrimitiveType implements Cloneable { @Override Type newCVVariant(final int cvAttributes) { - return new FloatType(getName(), getSize(), 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/FunctionType.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java index b0d16e1..7ccc4c0 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java @@ -41,7 +41,7 @@ package com.jogamp.gluegen.cgram.types; import java.util.*; -import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp; +import com.jogamp.gluegen.ASTLocusTag; /** Describes a function type, used to model both function declarations and (via PointerType) function pointers. */ @@ -51,8 +51,13 @@ public class FunctionType extends Type implements Cloneable { private ArrayList<Type> argumentTypes; private ArrayList<String> argumentNames; - public FunctionType(final String name, final SizeThunk size, final Type returnType, final int cvAttributes) { - super(name, size, cvAttributes); + public FunctionType(final String name, final SizeThunk size, final Type returnType, + final int cvAttributes) { + this(name, size, returnType, cvAttributes, null); + } + public FunctionType(final String name, final SizeThunk size, final Type returnType, + final int cvAttributes, final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); this.returnType = returnType; } diff --git a/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java b/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java index fb8c86b..ba46aed 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/MemoryLayoutType.java @@ -27,11 +27,13 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + public abstract class MemoryLayoutType extends Type { private boolean isLayouted; - protected MemoryLayoutType(final String name, final SizeThunk size, final int cvAttributes) { - super(name, size, cvAttributes); + protected MemoryLayoutType(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); isLayouted = false; } diff --git a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java index c6496bb..1528f9f 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java @@ -39,18 +39,20 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + public class PointerType extends Type implements Cloneable { private final Type targetType; - public PointerType(final SizeThunk size, final Type targetType, final int cvAttributes, final String typedefedName) { + public PointerType(final SizeThunk size, final Type targetType, final int cvAttributes) { + this(size, targetType, cvAttributes, null); + } + public PointerType(final SizeThunk size, final Type targetType, final int cvAttributes, final ASTLocusTag astLocus) { // can pass null for the final name parameter because the PointerType's getName() // completely replaces superclass behavior - super(targetType.getName() + " *", size, cvAttributes); + super(targetType.getName() + " *", size, cvAttributes, astLocus); this.targetType = targetType; - if (null != typedefedName) { - setTypedefName(typedefedName); - } } @Override @@ -77,7 +79,7 @@ public class PointerType extends Type implements Cloneable { @Override public boolean hasName() { - if ( hasTypedefName() ) { + if ( isTypedef() ) { return super.hasName(); } else { return targetType.hasName(); @@ -86,7 +88,7 @@ public class PointerType extends Type implements Cloneable { @Override public String getName(final boolean includeCVAttrs) { - if ( hasTypedefName() ) { + if ( isTypedef() ) { return super.getName(includeCVAttrs); } else if (!includeCVAttrs) { return targetType.getName(includeCVAttrs) + " *"; @@ -97,7 +99,7 @@ public class PointerType extends Type implements Cloneable { @Override public String getCName(final boolean includeCVAttrs) { - if ( hasTypedefName() ) { + if ( isTypedef() ) { return super.getCName(includeCVAttrs); } else if (!includeCVAttrs) { return targetType.getCName(includeCVAttrs) + " *"; @@ -134,7 +136,7 @@ public class PointerType extends Type implements Cloneable { @Override public String toString() { - if ( hasTypedefName() ) { + if ( isTypedef() ) { return super.getCName(true); } else { return toStringInt(); @@ -167,6 +169,10 @@ public class PointerType extends Type implements Cloneable { @Override Type newCVVariant(final int cvAttributes) { - return new PointerType(getSize(), targetType, cvAttributes, (hasTypedefName() ? getName() : null)); + 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 8a86337..69e28ab 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java @@ -39,10 +39,12 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + public abstract class PrimitiveType extends Type implements Cloneable { - protected PrimitiveType(final String name, final SizeThunk size, final int cvAttributes) { - super(name, size, cvAttributes); + protected PrimitiveType(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); } @Override diff --git a/src/java/com/jogamp/gluegen/cgram/types/StructType.java b/src/java/com/jogamp/gluegen/cgram/types/StructType.java index 4998484..7f2f865 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/StructType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/StructType.java @@ -27,14 +27,12 @@ */ package com.jogamp.gluegen.cgram.types; -public class StructType extends CompoundType { +import com.jogamp.gluegen.ASTLocusTag; - public StructType(final String name, final SizeThunk size, final int cvAttributes) { - this(name, size, cvAttributes, null); - } +public class StructType extends CompoundType { - StructType(final String name, final SizeThunk size, final int cvAttributes, final String structName) { - super (name, size, cvAttributes, structName); + StructType(final String name, final SizeThunk size, final int cvAttributes, final String structName, final ASTLocusTag astLocus) { + super (name, size, cvAttributes, structName, astLocus); } @Override @@ -44,10 +42,10 @@ public class StructType extends CompoundType { @Override Type newCVVariant(final int cvAttributes) { - final StructType t = new StructType(getName(), getSize(), cvAttributes, getStructName()); + final StructType t = new StructType(getName(), getSize(), cvAttributes, getStructName(), astLocus); t.setFields(getFields()); - if( hasTypedefName() ) { - t.setTypedefName( getName() ); + if( isTypedef() ) { + t.setTypedef(getTypedefCVAttributes()); } return t; } diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java index cd48aa0..9fd51fe 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Type.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java @@ -41,6 +41,8 @@ package com.jogamp.gluegen.cgram.types; import com.jogamp.common.os.MachineDataInfo; +import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider; +import com.jogamp.gluegen.ASTLocusTag; import com.jogamp.gluegen.GlueGen; import com.jogamp.gluegen.TypeConfig; import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp; @@ -49,36 +51,34 @@ 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 { +public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTagProvider { public final boolean relaxedEqSem; private final int cvAttributes; private String name; private SizeThunk size; - private int typedefedCVAttributes; - private boolean hasTypedefName; + private int typedefCVAttributes; + private boolean isTypedef; private boolean hasCachedHash; private int cachedHash; private boolean hasCachedSemanticHash; private int cachedSemanticHash; + final ASTLocusTag astLocus; - protected Type(final String name, final SizeThunk size, final int cvAttributes) { - setName(name); + 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.size = size; - this.typedefedCVAttributes = 0; - this.hasTypedefName = false; - this.hasCachedHash = false; - this.cachedHash = 0; - this.hasCachedSemanticHash = false; - this.cachedSemanticHash = 0; + this.typedefCVAttributes = 0; + this.isTypedef = false; + this.astLocus = astLocus; } protected final void clearCache() { - cachedHash = 0; hasCachedHash = false; + cachedHash = 0; + hasCachedSemanticHash = false; cachedSemanticHash = 0; - hasCachedHash = false; } @Override @@ -90,6 +90,9 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { } } + @Override + public final ASTLocusTag getASTLocusTag() { return astLocus; } + public final boolean isAnonymous() { return null == name; } public boolean hasName() { return null != name; } @@ -139,11 +142,15 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { } // For debugging public String getDebugString() { + return getDebugString(false); + } + // For debugging + public String getDebugString(final boolean withASTLoc) { final StringBuilder sb = new StringBuilder(); boolean prepComma = false; sb.append("CType["); sb.append("(").append(getClass().getSimpleName()).append(") "); - if( hasTypedefName() ) { + if( isTypedef() ) { sb.append("typedef "); } if( null != name ) { @@ -223,34 +230,85 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { if( isVoid() ) { append(sb, "void", prepComma); prepComma=true; } - sb.append("]]"); + sb.append("]"); + if( withASTLoc ) { + sb.append(", loc ").append(astLocus); + } + sb.append("]"); return sb.toString(); } private final int objHash() { return super.hashCode(); } - protected final void setName(final String name) { - if (name == null) { + /** + * Returns {@code true} if given {@code name} is not {@code null} + * and has a length > 0. In this case this instance's names will + * be set to the internalized version. + * <p> + * Otherwise method returns {@code false} + * and this instance's name will be set to {@code null}. + * </p> + * <p> + * Method issues {@link #clearCache()}, to force re-evaluation + * of hashes. + * </p> + */ + protected final boolean setName(final String name) { + clearCache(); + if( null == name || 0 == name.length() ) { this.name = name; + return false; } else { this.name = name.intern(); + return true; } - clearCache(); } - /** Set the name of this type; used for handling typedefs. */ + /** + * 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> + */ public void setTypedefName(final String name) { - setName(name); - // Capture the const/volatile attributes at the time of typedef so - // we don't redundantly repeat them in the CV attributes string - typedefedCVAttributes = cvAttributes; - hasTypedefName = true; + 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; + } + } + final void setTypedef(final int typedefedCVAttributes) { + this.typedefCVAttributes = typedefedCVAttributes; + this.isTypedef = true; + clearCache(); + } + final int getTypedefCVAttributes() { + return typedefCVAttributes; } - /** Indicates whether {@link #setTypedefName(String)} has been called on this type, - indicating that it already has a typedef name. */ - public final boolean hasTypedefName() { - return hasTypedefName; + /** + * Indicates whether this type is a typedef type, + * i.e. declared via {@link #setTypedefName(String)}. + */ + public final boolean isTypedef() { + return isTypedef; } /** SizeThunk which computes size of this type in bytes. */ @@ -312,9 +370,9 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { public boolean isVoid() { return (asVoid() != null); } /** Indicates whether this type is const. */ - public boolean isConst() { return (((cvAttributes & ~typedefedCVAttributes) & CVAttributes.CONST) != 0); } + public boolean isConst() { return (((cvAttributes & ~typedefCVAttributes) & CVAttributes.CONST) != 0); } /** Indicates whether this type is volatile. */ - public boolean isVolatile() { return (((cvAttributes & ~typedefedCVAttributes) & CVAttributes.VOLATILE) != 0); } + public boolean isVolatile() { return (((cvAttributes & ~typedefCVAttributes) & CVAttributes.VOLATILE) != 0); } /** Indicates whether this type is a primitive type. */ public boolean isPrimitive(){ return false; } @@ -330,11 +388,11 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { public final int hashCode() { if( !hasCachedHash ) { // 31 * x == (x << 5) - x - int hash = 31 + ( hasTypedefName ? 1 : 0 ); + int hash = 31 + ( isTypedef ? 1 : 0 ); hash = ((hash << 5) - hash) + ( null != size ? size.hashCode() : 0 ); hash = ((hash << 5) - hash) + cvAttributes; hash = ((hash << 5) - hash) + ( null != name ? name.hashCode() : 0 ); - if( !hasTypedefName ) { + if( !isTypedef ) { hash = ((hash << 5) - hash) + hashCodeImpl(); } cachedHash = hash; @@ -355,7 +413,7 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { return false; } else { final Type t = (Type)arg; - if( hasTypedefName == t.hasTypedefName && + if( isTypedef == t.isTypedef && ( ( null != size && size.equals(t.size) ) || ( null == size && null == t.size ) ) && @@ -363,7 +421,7 @@ public abstract class Type implements Cloneable, SemanticEqualityOp { ( null == name ? null == t.name : name.equals(t.name) ) ) { - if( !hasTypedefName ) { + if( !isTypedef ) { return equalsImpl(t); } else { return true; diff --git a/src/java/com/jogamp/gluegen/cgram/types/UnionType.java b/src/java/com/jogamp/gluegen/cgram/types/UnionType.java index 6ccc4a2..e03d671 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/UnionType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/UnionType.java @@ -27,14 +27,12 @@ */ package com.jogamp.gluegen.cgram.types; -public class UnionType extends CompoundType { +import com.jogamp.gluegen.ASTLocusTag; - public UnionType(final String name, final SizeThunk size, final int cvAttributes) { - this(name, size, cvAttributes, null); - } +public class UnionType extends CompoundType { - UnionType(final String name, final SizeThunk size, final int cvAttributes, final String structName) { - super (name, size, cvAttributes, structName); + UnionType(final String name, final SizeThunk size, final int cvAttributes, final String structName, final ASTLocusTag astLocus) { + super (name, size, cvAttributes, structName, astLocus); } @Override @@ -44,10 +42,10 @@ public class UnionType extends CompoundType { @Override Type newCVVariant(final int cvAttributes) { - final UnionType t = new UnionType(getName(), getSize(), cvAttributes, getStructName()); + final UnionType t = new UnionType(getName(), getSize(), cvAttributes, getStructName(), astLocus); t.setFields(getFields()); - if( hasTypedefName() ) { - t.setTypedefName( getName() ); + if( isTypedef() ) { + t.setTypedef(getTypedefCVAttributes()); } return t; } diff --git a/src/java/com/jogamp/gluegen/cgram/types/VoidType.java b/src/java/com/jogamp/gluegen/cgram/types/VoidType.java index f6adaac..f63bda3 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/VoidType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/VoidType.java @@ -39,14 +39,16 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + public class VoidType extends Type implements Cloneable { - public VoidType(final int cvAttributes) { - this("void", cvAttributes); + public VoidType(final int cvAttributes, final ASTLocusTag astLocus) { + this("void", cvAttributes, astLocus); } - private VoidType(final String name, final int cvAttributes) { - super(name, null, cvAttributes); + private VoidType(final String name, final int cvAttributes, final ASTLocusTag astLocus) { + super(name, null, cvAttributes, astLocus); } @Override @@ -56,7 +58,11 @@ public class VoidType extends Type implements Cloneable { @Override Type newCVVariant(final int cvAttributes) { - return new VoidType(getName(), cvAttributes); + final Type t = new VoidType(getName(), cvAttributes, astLocus); + if( isTypedef() ) { + t.setTypedef(getTypedefCVAttributes()); + } + return t; } @Override |