diff options
Diffstat (limited to 'src/java/com/jogamp/gluegen/cgram')
20 files changed, 8 insertions, 2117 deletions
diff --git a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g index 8c2ad26..6a78e91 100644 --- a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g +++ b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g @@ -46,6 +46,7 @@ header { import antlr.CommonAST; import com.jogamp.gluegen.cgram.types.*; + import com.jogamp.gluegen.runtime.types.*; } class HeaderParser extends GnuCTreeParser; @@ -130,7 +131,7 @@ options { int cvAttrs) { CompoundType t = (CompoundType) structDictionary.get(typeName); if (t == null) { - t = new CompoundType(null, null, kind, cvAttrs); + t = CompoundType.create(null, null, kind, cvAttrs); t.setStructName(typeName); structDictionary.put(typeName, t); } @@ -297,8 +298,6 @@ options { private void handleArrayExpr(TypeBox tb, AST t) { if (t != null) { try { - // FIXME: this doesn't take into account struct alignment, which may be necessary - // See also FIXMEs in ArrayType.java int len = parseIntConstExpr(t); tb.setType(canonicalize(new ArrayType(tb.type(), SizeThunk.mul(SizeThunk.constant(len), tb.type().getSize()), len, 0))); return; @@ -556,7 +555,7 @@ structOrUnionBody[CompoundTypeKind kind, int cvAttrs] returns [CompoundType t] { t = (CompoundType) canonicalize(lookupInStructDictionary(id.getText(), kind, cvAttrs)); } ( structDeclarationList[t] )? RCURLY { t.setBodyParsed(); } - | LCURLY { t = new CompoundType(null, null, kind, cvAttrs); } + | LCURLY { t = CompoundType.create(null, null, kind, cvAttrs); } ( structDeclarationList[t] )? RCURLY { t.setBodyParsed(); } | id2:ID { t = (CompoundType) canonicalize(lookupInStructDictionary(id2.getText(), kind, cvAttrs)); } diff --git a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java deleted file mode 100644 index 675efb5..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -/** 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 - should be passed in to the constructor. */ - -public class ArrayType extends Type implements Cloneable { - private Type elementType; - private int length; - private String computedName; - - public ArrayType(Type elementType, SizeThunk sizeInBytes, int length, int cvAttributes) { - super(elementType.getName() + " *", sizeInBytes, cvAttributes); - this.elementType = elementType; - this.length = length; - } - - @Override - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || (!(arg instanceof ArrayType))) { - return false; - } - ArrayType t = (ArrayType) arg; - return (super.equals(arg) && elementType.equals(t.elementType) && (length == t.length)); - } - - @Override - public String getName(boolean includeCVAttrs) { - // Lazy computation of name due to lazy setting of compound type - // names during parsing - // Note: don't think cvAttributes can be set for array types (unlike pointer types) - if (computedName == null) { - computedName = elementType.getName() + " *"; - computedName = computedName.intern(); - } - return computedName; - } - - @Override - public ArrayType asArray() { return this; } - - public Type getElementType() { return elementType; } - public int getLength() { return length; } - public boolean hasLength() { return length >= 0; } - - /** Return the bottommost element type if this is a multidimensional - array. */ - public Type getBaseElementType() { - ArrayType t = this; - while (t.getElementType().isArray()) { - t = t.getElementType().asArray(); - } - return t.getElementType(); - } - - /** Recompute the size of this array if necessary. This needs to be - done when the base element type is a compound type. */ - public void recomputeSize() { - ArrayType arrayElementType = getElementType().asArray(); - if (arrayElementType != null) { - arrayElementType.recomputeSize(); - } - // FIXME: this doesn't take into account struct alignment, which may be necessary - // See also FIXME below and in HeaderParser.g - super.setSize(SizeThunk.mul(SizeThunk.constant(getLength()), elementType.getSize())); - } - - @Override - public String toString() { - return toString(null); - } - - public String toString(String variableName) { - StringBuffer buf = new StringBuffer(); - buf.append(elementType.getName()); - if (variableName != null) { - buf.append(" "); - buf.append(variableName); - } - buf.append("["); - buf.append(length); - buf.append("]"); - return buf.toString(); - } - - @Override - public void visit(TypeVisitor arg) { - super.visit(arg); - elementType.visit(arg); - } - - Type newCVVariant(int cvAttributes) { - return new ArrayType(elementType, getSize(), length, cvAttributes); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/BitType.java b/src/java/com/jogamp/gluegen/cgram/types/BitType.java deleted file mode 100644 index a7a1f55..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/BitType.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -/** Represents a bitfield in a struct. */ - -public class BitType extends IntType implements Cloneable { - private IntType underlyingType; - private int sizeInBits; - private int offset; - - public BitType(IntType underlyingType, int sizeInBits, int lsbOffset, int cvAttributes) { - super(underlyingType.getName(), underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes); - this.underlyingType = underlyingType; - this.sizeInBits = sizeInBits; - this.offset = lsbOffset; - } - - @Override - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || (!(arg instanceof BitType))) { - return false; - } - BitType t = (BitType) arg; - return (super.equals(arg) && underlyingType.equals(t.underlyingType) && - (sizeInBits == t.sizeInBits) && (offset == t.offset)); - } - - @Override - public BitType asBit() { return this; } - - /** Size in bits of this type. */ - public int getSizeInBits() { - return sizeInBits; - } - - /** Offset from the least-significant bit (LSB) of the LSB of this - type */ - public int getOffset() { - return offset; - } - - @Override - public void visit(TypeVisitor arg) { - super.visit(arg); - underlyingType.visit(arg); - } - - @Override - Type newCVVariant(int cvAttributes) { - return new BitType(underlyingType, sizeInBits, offset, cvAttributes); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/CVAttributes.java b/src/java/com/jogamp/gluegen/cgram/types/CVAttributes.java deleted file mode 100644 index 34b703e..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/CVAttributes.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -/** Enumeration for const/volatile attributes. These are passed in to - the constructor of the type. */ - -public interface CVAttributes { - public static final int CONST = 0x01; - public static final int VOLATILE = 0x02; -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java b/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java deleted file mode 100644 index 9e9ead7..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/CompoundType.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -import java.util.*; - -/** Models all compound types, i.e., those containing fields: structs - and unions. The boolean type accessors indicate how the type is - really defined. */ - -public class CompoundType extends Type implements Cloneable { - private CompoundTypeKind kind; - // The name "foo" in the construct "struct foo { ... }"; - private String structName; - private ArrayList<Field> fields; - private boolean visiting; - private boolean bodyParsed; - private boolean computedHashcode; - private int hashcode; - - public CompoundType(String name, SizeThunk size, CompoundTypeKind kind, int cvAttributes) { - this(name, size, kind, cvAttributes, null); - } - - private CompoundType(String name, SizeThunk size, CompoundTypeKind kind, int cvAttributes, String structName) { - super(name, size, cvAttributes); - assert kind != null; - this.kind = kind; - this.structName = structName; - } - - public Object clone() { - CompoundType n = (CompoundType) super.clone(); - if(null!=this.fields) { - n.fields = (ArrayList) this.fields.clone(); - } - return n; - } - - @Override - public int hashCode() { - if (computedHashcode) { - return hashcode; - } - - if (structName != null) { - hashcode = structName.hashCode(); - } else if (getName() != null) { - hashcode = getName().hashCode(); - } else { - hashcode = 0; - } - - computedHashcode = true; - return hashcode; - } - - @Override - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || !(arg instanceof CompoundType)) { - return false; - } - CompoundType t = (CompoundType) arg; - return super.equals(arg) && - ((structName == null ? t.structName == null : structName.equals(t.structName)) || - (structName != null && structName.equals(t.structName))) && - kind == t.kind && listsEqual(fields, t.fields); - } - - /** Returns the struct name of this CompoundType, i.e. the "foo" in - the construct "struct foo { ... };". */ - public String getStructName() { - return structName; - } - - /** Sets the struct name of this CompoundType, i.e. the "foo" in the - construct "struct foo { ... };". */ - public void setStructName(String structName) { - this.structName = structName; - } - - @Override - public void setSize(SizeThunk size) { - super.setSize(size); - } - - @Override - public CompoundType asCompound() { return this; } - - /** Returns the number of fields in this type. */ - public int getNumFields() { - return ((fields == null) ? 0 : fields.size()); - } - - /** Returns the <i>i</i>th field of this type. */ - public Field getField(int i) { - return fields.get(i); - } - - /** Adds a field to this type. */ - public void addField(Field f) { - if (bodyParsed) { - throw new RuntimeException("Body of this CompoundType has already been parsed; should not be adding more fields"); - } - if (fields == null) { - fields = new ArrayList<Field>(); - } - fields.add(f); - } - - /** Indicates to this CompoundType that its body has been parsed and - that no more {@link #addField} operations will be made. */ - public void setBodyParsed() { - bodyParsed = true; - } - - /** Indicates whether this type was declared as a struct. */ - public boolean isStruct() { return (kind == CompoundTypeKind.STRUCT); } - /** Indicates whether this type was declared as a union. */ - public boolean isUnion() { return (kind == CompoundTypeKind.UNION); } - - @Override - public String toString() { - String cvAttributesString = getCVAttributesString(); - if (getName() != null) { - return cvAttributesString + getName(); - } else if (getStructName() != null) { - return cvAttributesString + "struct " + getStructName(); - } else { - return cvAttributesString + getStructString(); - } - } - - @Override - public void visit(TypeVisitor arg) { - if (visiting) { - return; - } - try { - visiting = true; - super.visit(arg); - int n = getNumFields(); - for (int i = 0; i < n; i++) { - Field f = getField(i); - f.getType().visit(arg); - } - } finally { - visiting = false; - } - } - - public String getStructString() { - if (visiting) { - if (getName() != null) { - return getName(); - } - return "struct {/*Recursive type reference*/}"; - } - - try { - visiting = true; - String kind = (isStruct() ? "struct {" : "union {"); - StringBuffer res = new StringBuffer(); - res.append(kind); - int n = getNumFields(); - for (int i = 0; i < n; i++) { - res.append(" "); - res.append(getField(i)); - } - res.append(" }"); - return res.toString(); - } finally { - visiting = false; - } - } - - Type newCVVariant(int cvAttributes) { - CompoundType t = new CompoundType(getName(), getSize(), kind, cvAttributes, structName); - t.fields = fields; - return t; - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/CompoundTypeKind.java b/src/java/com/jogamp/gluegen/cgram/types/CompoundTypeKind.java deleted file mode 100644 index b07611c..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/CompoundTypeKind.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -/** Type-safe enum for discriminating between structs and unions, - which are both represented as compound types. */ - -public class CompoundTypeKind { - public static final CompoundTypeKind STRUCT = new CompoundTypeKind(); - public static final CompoundTypeKind UNION = new CompoundTypeKind(); - - private CompoundTypeKind() {} -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java b/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java deleted file mode 100644 index 280485a..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/DoubleType.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -/** Represents a double-word floating-point type (C type "double".) */ -public class DoubleType extends PrimitiveType implements Cloneable { - - public DoubleType(String name, SizeThunk size, int cvAttributes) { - super(name, size, cvAttributes); - } - - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof DoubleType))) { - return false; - } - return super.equals(arg); - } - - @Override - public DoubleType asDouble() { - return this; - } - - Type newCVVariant(int cvAttributes) { - return new DoubleType(getName(), getSize(), cvAttributes); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/EnumType.java b/src/java/com/jogamp/gluegen/cgram/types/EnumType.java deleted file mode 100644 index 7967ba0..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/EnumType.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -import java.util.ArrayList; -import java.util.NoSuchElementException; - - -/** Describes enumerated types. Enumerations are like ints except that -they have a set of named values. */ -public class EnumType extends IntType implements Cloneable { - - private IntType underlyingType; - - private static class Enum { - - String name; - long value; - - Enum(String name, long value) { - this.name = name; - this.value = value; - } - - String getName() { - return name; - } - - long getValue() { - return value; - } - } - - private ArrayList<Enum> enums; - - public EnumType(String name) { - super(name, SizeThunk.LONG, false, CVAttributes.CONST); - this.underlyingType = new IntType(name, SizeThunk.LONG, false, CVAttributes.CONST); - } - - public EnumType(String name, SizeThunk enumSizeInBytes) { - super(name, enumSizeInBytes, false, CVAttributes.CONST); - this.underlyingType = new IntType(name, enumSizeInBytes, false, CVAttributes.CONST); - } - - protected EnumType(String name, IntType underlyingType, int cvAttributes) { - super(name, underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes); - this.underlyingType = underlyingType; - } - - public Object clone() { - EnumType n = (EnumType) super.clone(); - if(null!=this.underlyingType) { - n.underlyingType = (IntType) this.underlyingType.clone(); - } - if(null!=this.enums) { - n.enums = (ArrayList) this.enums.clone(); - } - return n; - } - - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof EnumType))) { - return false; - } - EnumType t = (EnumType) arg; - return (super.equals(arg) - && underlyingType.equals(t.underlyingType) - && listsEqual(enums, t.enums)); - } - - @Override - public EnumType asEnum() { - return this; - } - - public void addEnum(String name, long val) { - if (enums == null) { - enums = new ArrayList<Enum>(); - } - enums.add(new Enum(name, val)); - } - - /** Number of enumerates defined in this enum. */ - public int getNumEnumerates() { - return enums.size(); - } - - /** Fetch <i>i</i>th (0..getNumEnumerates() - 1) name */ - public String getEnumName(int i) { - return (enums.get(i)).getName(); - } - - /** Fetch <i>i</i>th (0..getNumEnumerates() - 1) value */ - public long getEnumValue(int i) { - return (enums.get(i)).getValue(); - } - - /** Fetch the value of the enumerate with the given name. */ - public long getEnumValue(String name) { - for (int i = 0; i < enums.size(); ++i) { - Enum n = (enums.get(i)); - if (n.getName().equals(name)) { - return n.getValue(); - } - } - throw new NoSuchElementException( - "No enumerate named \"" + name + "\" in EnumType \"" - + getName() + "\""); - } - - /** Does this enum type contain an enumerate with the given name? */ - public boolean containsEnumerate(String name) { - for (int i = 0; i < enums.size(); ++i) { - if ((enums.get(i)).getName().equals(name)) { - return true; - } - } - return false; - } - - /** Remove the enumerate with the given name. Returns true if it was found - * and removed; false if it was not found. - */ - public boolean removeEnumerate(String name) { - for (int i = 0; i < enums.size(); ++i) { - Enum e = enums.get(i); - if (e.getName().equals(name)) { - enums.remove(e); - return true; - } - } - return false; - } - - @Override - public void visit(TypeVisitor arg) { - super.visit(arg); - underlyingType.visit(arg); - } - - @Override - Type newCVVariant(int cvAttributes) { - EnumType t = new EnumType(getName(), underlyingType, cvAttributes); - t.enums = enums; - return t; - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/Field.java b/src/java/com/jogamp/gluegen/cgram/types/Field.java deleted file mode 100644 index 891bb27..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/Field.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -import com.jogamp.common.os.MachineDescription; - -/** Represents a field in a struct or union. */ - -public class Field { - private String name; - private Type type; - private SizeThunk offset; - - public Field(String name, Type type, SizeThunk offset) { - this.name = name; - this.type = type; - this.offset = offset; - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public boolean equals(Object arg) { - if (arg == null || (!(arg instanceof Field))) { - return false; - } - - Field f = (Field) arg; - // Note: don't know how to examine offset any more since it's - // implemented in terms of code and they're not canonicalized - return (((name != null && name.equals(f.name)) || - (name == null && f.name == null)) && - type.equals(f.type)); - } - - /** Name of this field in the containing data structure. */ - public String getName() { return name; } - - /** Type of this field. */ - public Type getType() { return type; } - - /** SizeThunk computing offset, in bytes, of this field in the containing data structure. */ - public SizeThunk getOffset() { return offset; } - - /** Offset, in bytes, of this field in the containing data structure - given the specified MachineDescription. */ - public long getOffset(MachineDescription machDesc) { return offset.computeSize(machDesc); } - - /** Sets the offset of this field in the containing data structure. */ - public void setOffset(SizeThunk offset) { this.offset = offset; } - - @Override - public String toString() { - if (!getType().isFunctionPointer()) { - if (getName() == null && - getType().asCompound() != null && - getType().asCompound().isUnion()) { - return "" + getType() + ";"; - } - return "" + getType() + " " + getName() + ";"; - } else { - FunctionType ft = getType().asPointer().getTargetType().asFunction(); - // FIXME: pick up calling convention? - return ft.toString(getName(), null, false, true) + ";"; - } - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/FloatType.java b/src/java/com/jogamp/gluegen/cgram/types/FloatType.java deleted file mode 100644 index 7766b8c..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/FloatType.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -/** Represents a single-word floating-point type (C type "float".) */ - -public class FloatType extends PrimitiveType implements Cloneable { - public FloatType(String name, SizeThunk size, int cvAttributes) { - super(name, size, cvAttributes); - } - - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof FloatType))) { - return false; - } - return super.equals(arg); - } - - @Override - public FloatType asFloat() { return this; } - - Type newCVVariant(int cvAttributes) { - return new FloatType(getName(), getSize(), cvAttributes); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java index 545a6e8..2bfc859 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java +++ b/src/java/com/jogamp/gluegen/cgram/types/FunctionSymbol.java @@ -38,6 +38,9 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.runtime.types.FunctionType; +import com.jogamp.gluegen.runtime.types.Type; + /** Describes a function symbol, which includes the name and type. Since we are currently only concerned with processing functions this is the only symbol type, though plausibly more diff --git a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java deleted file mode 100644 index cb430db..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -import java.util.*; - -/** Describes a function type, used to model both function -declarations and (via PointerType) function pointers. */ -public class FunctionType extends Type implements Cloneable { - - private Type returnType; - private ArrayList<Type> argumentTypes; - private ArrayList<String> argumentNames; - - public FunctionType(String name, SizeThunk size, Type returnType, int cvAttributes) { - super(name, size, cvAttributes); - this.returnType = returnType; - } - - public Object clone() { - FunctionType n = (FunctionType) super.clone(); - if(null!=this.argumentTypes) { - n.argumentTypes = (ArrayList) this.argumentTypes.clone(); - } - if(null!=this.argumentNames) { - n.argumentNames = (ArrayList) this.argumentNames.clone(); - } - return n; - } - - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof FunctionType))) { - return false; - } - FunctionType t = (FunctionType) arg; - return (super.equals(arg) - && returnType.equals(t.returnType) - && listsEqual(argumentTypes, t.argumentTypes)); - } - - @Override - public FunctionType asFunction() { - return this; - } - - /** Returns the return type of this function. */ - public Type getReturnType() { - return returnType; - } - - public int getNumArguments() { - return ((argumentTypes == null) ? 0 : argumentTypes.size()); - } - - /** Returns the name of the <i>i</i>th argument. May return null if - no argument names were available during parsing. */ - public String getArgumentName(int i) { - return argumentNames.get(i); - } - - /** Returns the type of the <i>i</i>th argument. */ - public Type getArgumentType(int i) { - return argumentTypes.get(i); - } - - /** - * Add an argument's name and type. Use null for unknown argument names. - */ - public void addArgument(Type argumentType, String argumentName) { - if (argumentTypes == null) { - argumentTypes = new ArrayList<Type>(); - argumentNames = new ArrayList<String>(); - } - argumentTypes.add(argumentType); - argumentNames.add(argumentName); - } - - public void setArgumentName(int i, String name) { - argumentNames.set(i, name); - } - - @Override - public String toString() { - return toString(null); - } - - public String toString(String functionName) { - return toString(functionName, false); - } - - public String toString(String functionName, boolean emitNativeTag) { - return toString(functionName, null, emitNativeTag, false); - } - - String toString(String functionName, String callingConvention, boolean emitNativeTag, boolean isPointer) { - StringBuffer res = new StringBuffer(); - res.append(getReturnType()); - res.append(" "); - if (isPointer) { - res.append("("); - if (callingConvention != null) { - res.append(callingConvention); - } - res.append("*"); - } - if (functionName != null) { - if (emitNativeTag) { - // Emit @native tag for javadoc purposes - res.append("{@native "); - } - res.append(functionName); - if (emitNativeTag) { - res.append("}"); - } - } - if (isPointer) { - res.append(")"); - } - res.append("("); - int n = getNumArguments(); - for (int i = 0; i < n; i++) { - Type t = getArgumentType(i); - if (t.isFunctionPointer()) { - FunctionType ft = t.asPointer().getTargetType().asFunction(); - res.append(ft.toString(getArgumentName(i), callingConvention, false, true)); - } else if (t.isArray()) { - res.append(t.asArray().toString(getArgumentName(i))); - } else { - res.append(t); - String argumentName = getArgumentName(i); - if (argumentName != null) { - res.append(" "); - res.append(argumentName); - } - } - if (i < n - 1) { - res.append(", "); - } - } - res.append(")"); - if (!isPointer) { - res.append(";"); - } - return res.toString(); - } - - @Override - public void visit(TypeVisitor arg) { - super.visit(arg); - returnType.visit(arg); - int n = getNumArguments(); - for (int i = 0; i < n; i++) { - getArgumentType(i).visit(arg); - } - } - - Type newCVVariant(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 deleted file mode 100644 index b85c7fc..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/IntType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -public class IntType extends PrimitiveType implements Cloneable { - - private boolean unsigned; - private boolean typedefedUnsigned; - - public IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes) { - this(name, size, unsigned, cvAttributes, false); - } - - public IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes, boolean typedefedUnsigned) { - super(name, size, cvAttributes); - this.unsigned = unsigned; - this.typedefedUnsigned = typedefedUnsigned; - } - - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof IntType))) { - return false; - } - IntType t = (IntType) arg; - return (super.equals(arg) && (unsigned == t.unsigned)); - } - - @Override - public void setName(String name) { - super.setName(name); - typedefedUnsigned = unsigned; - } - - @Override - public IntType asInt() { - return this; - } - - /** Indicates whether this type is unsigned */ - public boolean isUnsigned() { - return unsigned; - } - - @Override - public String toString() { - return getCVAttributesString() + ((isUnsigned() & (!typedefedUnsigned)) ? "unsigned " : "") + getName(); - } - - Type newCVVariant(int cvAttributes) { - return new IntType(getName(), getSize(), isUnsigned(), cvAttributes, typedefedUnsigned); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java deleted file mode 100644 index 4666e48..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -public class PointerType extends Type implements Cloneable { - - private Type targetType; - private String computedName; - private boolean hasTypedefedName; - - public PointerType(SizeThunk size, Type targetType, int cvAttributes) { - // can pass null for the final name parameter because the PointerType's getName() - // completely replaces superclass behavior - this(size, targetType, cvAttributes, false, null); - } - - private PointerType(SizeThunk size, Type targetType, int cvAttributes, boolean hasTypedefedName, String typedefedName) { - super(targetType.getName() + " *", size, cvAttributes); - this.hasTypedefedName = false; - this.targetType = targetType; - if (hasTypedefedName) { - setName(typedefedName); - } - } - - @Override - public int hashCode() { - return targetType.hashCode(); - } - - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof PointerType))) { - return false; - } - PointerType t = (PointerType) arg; - // Note we ignore the name of this type (which might be a typedef - // name) for comparison purposes because this is what allows - // e.g. a newly-fabricated type "PIXELFORMATDESCRIPTOR *" to be - // canonicalized to e.g. "LPPIXELFORMATDESCRIPTOR" - return ((getSize() == t.getSize()) - && (getCVAttributes() == t.getCVAttributes()) - && targetType.equals(t.targetType)); - } - - @Override - public void setName(String name) { - super.setName(name); - hasTypedefedName = true; - } - - @Override - public String getName(boolean includeCVAttrs) { - if (hasTypedefedName) { - return super.getName(includeCVAttrs); - } else { - // Lazy computation of name due to lazy setting of compound type - // names during parsing - if (computedName == null) { - computedName = targetType.getName(includeCVAttrs) + " *"; - computedName = computedName.intern(); - } - if (!includeCVAttrs) { - return computedName; - } - return targetType.getName(includeCVAttrs) + " * " + getCVAttributesString(); - } - } - - public boolean hasTypedefedName() { - return hasTypedefedName; - } - - @Override - public PointerType asPointer() { - return this; - } - - public Type getTargetType() { - return targetType; - } - - @Override - public boolean isFunctionPointer() { - return targetType.isFunction(); - } - - @Override - public String toString() { - if (hasTypedefedName) { - return super.getName(true); - } else { - if (!targetType.isFunction()) { - return targetType.toString() + " * " + getCVAttributesString(); - } - return toString(null, null); // this is a pointer to an unnamed function - } - } - - /** For use only when printing function pointers. Calling convention - string (i.e., "__stdcall") is optional and is generally only - needed on Windows. */ - public String toString(String functionName, String callingConvention) { - if (!targetType.isFunction()) { - throw new RuntimeException("<Internal error or misuse> This method is only for use when printing function pointers"); - } - return ((FunctionType) targetType).toString(functionName, callingConvention, false, true); - } - - @Override - public void visit(TypeVisitor arg) { - super.visit(arg); - targetType.visit(arg); - } - - Type newCVVariant(int cvAttributes) { - return new PointerType(getSize(), targetType, cvAttributes, hasTypedefedName, (hasTypedefedName ? getName() : null)); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java b/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java deleted file mode 100644 index 1eea9a4..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/PrimitiveType.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -public abstract class PrimitiveType extends Type implements Cloneable { - - protected PrimitiveType(String name, SizeThunk size, int cvAttributes) { - super(name, size, cvAttributes); - } - - @Override - public boolean isPrimitive() { - return true; - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java deleted file mode 100755 index d71445d..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -import com.jogamp.common.os.MachineDescription; - -/** Provides a level of indirection between the definition of a type's - size and the absolute value of this size. Necessary when - generating glue code for two different CPU architectures (e.g., - 32-bit and 64-bit) from the same internal representation of the - various types involved. */ - -public abstract class SizeThunk implements Cloneable { - // Private constructor because there are only a few of these - private SizeThunk() {} - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - public abstract long computeSize(MachineDescription machDesc); - public abstract long computeAlignment(MachineDescription machDesc); - - public static final SizeThunk INT8 = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.int8SizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.int8AlignmentInBytes(); - } - }; - - public static final SizeThunk INT16 = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.int16SizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.int16AlignmentInBytes(); - } - }; - - public static final SizeThunk INT32 = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.int32SizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.int32AlignmentInBytes(); - } - }; - - public static final SizeThunk INTxx = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.intSizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.intAlignmentInBytes(); - } - }; - - public static final SizeThunk LONG = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.longSizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.longAlignmentInBytes(); - } - }; - - public static final SizeThunk INT64 = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.int64SizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.int64AlignmentInBytes(); - } - }; - - public static final SizeThunk FLOAT = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.floatSizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.floatAlignmentInBytes(); - } - }; - - public static final SizeThunk DOUBLE = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.doubleSizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.doubleAlignmentInBytes(); - } - }; - - public static final SizeThunk POINTER = new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return machDesc.pointerSizeInBytes(); - } - public long computeAlignment(MachineDescription machDesc) { - return machDesc.pointerAlignmentInBytes(); - } - }; - - // Factory methods for performing certain limited kinds of - // arithmetic on these values - public static SizeThunk add(final SizeThunk thunk1, - final SizeThunk thunk2) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return thunk1.computeSize(machDesc) + thunk2.computeSize(machDesc); - } - public long computeAlignment(MachineDescription machDesc) { - final long thunk1A = thunk1.computeAlignment(machDesc); - final long thunk2A = thunk2.computeAlignment(machDesc); - return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; - } - }; - } - - public static SizeThunk sub(final SizeThunk thunk1, - final SizeThunk thunk2) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return thunk1.computeSize(machDesc) - thunk2.computeSize(machDesc); - } - public long computeAlignment(MachineDescription machDesc) { - // FIXME - final long thunk1A = thunk1.computeAlignment(machDesc); - final long thunk2A = thunk2.computeAlignment(machDesc); - return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; - } - }; - } - - public static SizeThunk mul(final SizeThunk thunk1, - final SizeThunk thunk2) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return thunk1.computeSize(machDesc) * thunk2.computeSize(machDesc); - } - public long computeAlignment(MachineDescription machDesc) { - final long thunk1A = thunk1.computeAlignment(machDesc); - final long thunk2A = thunk2.computeAlignment(machDesc); - return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; - } - }; - } - - public static SizeThunk mod(final SizeThunk thunk1, - final SizeThunk thunk2) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return thunk1.computeSize(machDesc) % thunk2.computeSize(machDesc); - } - public long computeAlignment(MachineDescription machDesc) { - // FIXME - final long thunk1A = thunk1.computeAlignment(machDesc); - final long thunk2A = thunk2.computeAlignment(machDesc); - return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; - } - }; - } - - public static SizeThunk roundUp(final SizeThunk thunk1, - final SizeThunk thunk2) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - final long sz1 = thunk1.computeSize(machDesc); - final long sz2 = thunk2.computeSize(machDesc); - final long rem = (sz1 % sz2); - if (rem == 0) { - return sz1; - } - return sz1 + (sz2 - rem); - } - public long computeAlignment(MachineDescription machDesc) { - final long thunk1A = thunk1.computeAlignment(machDesc); - final long thunk2A = thunk2.computeAlignment(machDesc); - return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; - } - }; - } - - public static SizeThunk max(final SizeThunk thunk1, - final SizeThunk thunk2) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return Math.max(thunk1.computeSize(machDesc), thunk2.computeSize(machDesc)); - } - public long computeAlignment(MachineDescription machDesc) { - final long thunk1A = thunk1.computeAlignment(machDesc); - final long thunk2A = thunk2.computeAlignment(machDesc); - return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; - } - }; - } - - public static SizeThunk constant(final int constant) { - return new SizeThunk() { - public long computeSize(MachineDescription machDesc) { - return constant; - } - public long computeAlignment(MachineDescription machDesc) { - return 1; // no real alignment for constants - } - }; - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java deleted file mode 100644 index 27aff92..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/Type.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -import java.util.List; - -import com.jogamp.common.os.MachineDescription; - -/** 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. */ -public abstract class Type implements Cloneable { - - private String name; - private SizeThunk size; - private int cvAttributes; - private int typedefedCVAttributes; - private boolean hasTypedefName; - - protected Type(String name, SizeThunk size, int cvAttributes) { - setName(name); - this.size = size; - this.cvAttributes = cvAttributes; - hasTypedefName = false; - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - /** Returns the name of this type. The returned string is suitable - for use as a type specifier. Does not include any const/volatile - attributes. */ - public String getName() { return getName(false); } - - /** Returns the name of this type, optionally including - const/volatile attributes. The returned string is suitable for - use as a type specifier. */ - public String getName(boolean includeCVAttrs) { - if (!includeCVAttrs) { - return name; - } - return getCVAttributesString() + name; - } - - /** Set the name of this type; used for handling typedefs. */ - public void setName(String name) { - if (name == null) { - this.name = name; - } else { - this.name = name.intern(); - } - // 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; - } - - /** SizeThunk which computes size of this type in bytes. */ - public SizeThunk getSize() { return size; } - /** Size of this type in bytes according to the given MachineDescription. */ - public long getSize(MachineDescription machDesc) { - SizeThunk thunk = getSize(); - if (thunk == null) { - throw new RuntimeException("No size set for type \"" + getName() + "\""); - } - return thunk.computeSize(machDesc); - } - /** Set the size of this type; only available for CompoundTypes. */ - void setSize(SizeThunk size) { this.size = size; } - - /** Casts this to a BitType or returns null if not a BitType. */ - public BitType asBit() { return null; } - /** Casts this to an IntType or returns null if not an IntType. */ - public IntType asInt() { return null; } - /** Casts this to an EnumType or returns null if not an EnumType. */ - public EnumType asEnum() { return null; } - /** Casts this to a FloatType or returns null if not a FloatType. */ - public FloatType asFloat() { return null; } - /** Casts this to a DoubleType or returns null if not a DoubleType. */ - public DoubleType asDouble() { return null; } - /** Casts this to a PointerType or returns null if not a PointerType. */ - public PointerType asPointer() { return null; } - /** Casts this to an ArrayType or returns null if not an ArrayType. */ - public ArrayType asArray() { return null; } - /** Casts this to a CompoundType or returns null if not a CompoundType. */ - public CompoundType asCompound() { return null; } - /** Casts this to a FunctionType or returns null if not a FunctionType. */ - public FunctionType asFunction() { return null; } - /** Casts this to a VoidType or returns null if not a VoidType. */ - public VoidType asVoid() { return null; } - - /** Indicates whether this is a BitType. */ - public boolean isBit() { return (asBit() != null); } - /** Indicates whether this is an IntType. */ - public boolean isInt() { return (asInt() != null); } - /** Indicates whether this is an EnumType. */ - public boolean isEnum() { return (asEnum() != null); } - /** Indicates whether this is a FloatType. */ - public boolean isFloat() { return (asFloat() != null); } - /** Indicates whether this is a DoubleType. */ - public boolean isDouble() { return (asDouble() != null); } - /** Indicates whether this is a PointerType. */ - public boolean isPointer() { return (asPointer() != null); } - /** Indicates whether this is an ArrayType. */ - public boolean isArray() { return (asArray() != null); } - /** Indicates whether this is a CompoundType. */ - public boolean isCompound() { return (asCompound() != null); } - /** Indicates whether this is a FunctionType. */ - public boolean isFunction() { return (asFunction() != null); } - /** Indicates whether this is a VoidType. */ - public boolean isVoid() { return (asVoid() != null); } - - /** Indicates whether this type is const. */ - public boolean isConst() { return (((cvAttributes & ~typedefedCVAttributes) & CVAttributes.CONST) != 0); } - /** Indicates whether this type is volatile. */ - public boolean isVolatile() { return (((cvAttributes & ~typedefedCVAttributes) & CVAttributes.VOLATILE) != 0); } - - /** Indicates whether this type is a primitive type. */ - public boolean isPrimitive(){ return false; } - - /** Convenience routine indicating whether this Type is a pointer to - a function. */ - public boolean isFunctionPointer() { - return (isPointer() && asPointer().getTargetType().isFunction()); - } - - /** Hashcode for Types. */ - @Override - public int hashCode() { - if (name == null) { - return 0; - } - - if (cvAttributes != 0) { - String nameWithAttribs = name + cvAttributes; - return nameWithAttribs.hashCode(); - } - return name.hashCode(); - } - - /** - * Equality test for Types. - */ - @Override - public boolean equals(Object arg) { - if (arg == this) { - return true; - } - if (arg == null || (!(arg instanceof Type))) { - return false; - } - Type t = (Type) arg; - return (((name == null ? t.name == null : name.equals(t.name)) || (name != null && name.equals(name))) && - (size == t.size) && (cvAttributes == t.cvAttributes)); - } - - /** Returns a string representation of this type. This string is not - necessarily suitable for use as a type specifier; for example, - it will contain an expanded description of structs/unions. */ - @Override - public String toString() { - return getName(true); - } - - /** Visit this type and all of the component types of this one; for - example, the return type and argument types of a FunctionType. */ - public void visit(TypeVisitor visitor) { - visitor.visitType(this); - } - - public final int getCVAttributes() { - return cvAttributes; - } - - /** Returns a string indicating the const/volatile attributes of - this type. */ - public final String getCVAttributesString() { - if (isConst() && isVolatile()) return "const volatile "; - if (isConst()) return "const "; - if (isVolatile()) return "volatile "; - 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(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); - - /** Indicates whether setName() has been called on this type, - indicating that it already has a typedef name. */ - public boolean hasTypedefName() { - return hasTypedefName; - } - - /** 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. */ - public int pointerDepth() { - PointerType pt = asPointer(); - if (pt == null) { - return 0; - } - return 1 + pt.getTargetType().pointerDepth(); - } - - /** 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. */ - public int arrayDimension() { - ArrayType arrayType = asArray(); - if (arrayType == null) { - return 0; - } - return 1 + arrayType.getElementType().arrayDimension(); - } - - /** Helper routine for list equality comparison */ - static boolean listsEqual(List a, List b) { - return ((a == null && b == null) || (a != null && b != null && a.equals(b))); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/TypeDictionary.java b/src/java/com/jogamp/gluegen/cgram/types/TypeDictionary.java index 3bc4d87..2e2caba 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/TypeDictionary.java +++ b/src/java/com/jogamp/gluegen/cgram/types/TypeDictionary.java @@ -41,6 +41,8 @@ package com.jogamp.gluegen.cgram.types; import java.util.*; +import com.jogamp.gluegen.runtime.types.Type; + /** Utility class for recording names of typedefs and structs. */ public class TypeDictionary { diff --git a/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java b/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java deleted file mode 100644 index 0889681..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/TypeVisitor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -public interface TypeVisitor { - public void visitType(Type t); -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/VoidType.java b/src/java/com/jogamp/gluegen/cgram/types/VoidType.java deleted file mode 100644 index fa098e7..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/VoidType.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.cgram.types; - -public class VoidType extends Type implements Cloneable { - - public VoidType(int cvAttributes) { - this("void", cvAttributes); - } - - private VoidType(String name, int cvAttributes) { - super(name, null, cvAttributes); - } - - @Override - public VoidType asVoid() { - return this; - } - - Type newCVVariant(int cvAttributes) { - return new VoidType(getName(), cvAttributes); - } -} |