summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/gluegen/runtime')
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/ArrayType.java135
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/BitType.java92
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/CVAttributes.java48
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/CompoundType.java222
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/CompoundTypeKind.jav41
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/DoubleType.java68
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/EnumType.java189
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/Field.java107
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/FloatType.java67
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/FunctionType.java202
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/IntType.java93
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/MemoryLayoutType.java41
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/PointerType.java159
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/PrimitiveType.java52
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/types/SizeThunk.java226
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/StructLayout.java138
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/StructType.java57
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/Type.java273
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/TypeVisitor.java44
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/UnionType.java57
-rw-r--r--src/java/com/jogamp/gluegen/runtime/types/VoidType.java60
21 files changed, 2371 insertions, 0 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/types/ArrayType.java b/src/java/com/jogamp/gluegen/runtime/types/ArrayType.java
new file mode 100644
index 0000000..ace3ff0
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/ArrayType.java
@@ -0,0 +1,135 @@
+/*
+ * 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.runtime.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 MemoryLayoutType 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 after layouting. */
+ void recomputeSize() {
+ ArrayType arrayElementType = getElementType().asArray();
+ if (arrayElementType != null) {
+ arrayElementType.recomputeSize();
+ }
+ 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/runtime/types/BitType.java b/src/java/com/jogamp/gluegen/runtime/types/BitType.java
new file mode 100644
index 0000000..78290d8
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/BitType.java
@@ -0,0 +1,92 @@
+/*
+ * 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.runtime.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/runtime/types/CVAttributes.java b/src/java/com/jogamp/gluegen/runtime/types/CVAttributes.java
new file mode 100644
index 0000000..f55f817
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/CVAttributes.java
@@ -0,0 +1,48 @@
+/*
+ * 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.runtime.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/runtime/types/CompoundType.java b/src/java/com/jogamp/gluegen/runtime/types/CompoundType.java
new file mode 100644
index 0000000..3e93fcf
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/CompoundType.java
@@ -0,0 +1,222 @@
+/*
+ * 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.runtime.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 abstract class CompoundType extends MemoryLayoutType implements Cloneable {
+ // 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;
+
+ CompoundType(String name, SizeThunk size, int cvAttributes, String structName) {
+ super(name, size, cvAttributes);
+ this.structName = structName;
+ }
+
+ public static CompoundType create(String name, SizeThunk size, CompoundTypeKind kind, int cvAttributes) {
+ switch (kind) {
+ case STRUCT:
+ return new StructType(name, size, cvAttributes);
+ case UNION:
+ return new UnionType(name, size, cvAttributes);
+ default:
+ throw new RuntimeException("OO relation "+kind+" / Compount not yet supported");
+ }
+ }
+
+ 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))) &&
+ 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; }
+
+ ArrayList<Field> getFields() { return fields; }
+ void setFields(ArrayList<Field> fields) { this.fields = fields; }
+
+ /** 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 abstract boolean isStruct();
+ /** Indicates whether this type was declared as a union. */
+ public abstract boolean isUnion();
+
+ @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;
+ }
+ }
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/CompoundTypeKind.jav b/src/java/com/jogamp/gluegen/runtime/types/CompoundTypeKind.jav
new file mode 100644
index 0000000..96a07ae
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/CompoundTypeKind.jav
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2011 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.gluegen.runtime.types;
+
+/** Type-safe enum for discriminating between structs and unions
+ represented as compound types. Used while syntax parsing. */
+public enum CompoundTypeKind {
+ STRUCT(0), UNION(1);
+
+ public final int id;
+
+ CompoundTypeKind(int id){
+ this.id = id;
+ }
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/DoubleType.java b/src/java/com/jogamp/gluegen/runtime/types/DoubleType.java
new file mode 100644
index 0000000..a18e4cc
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/DoubleType.java
@@ -0,0 +1,68 @@
+/*
+ * 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.runtime.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/runtime/types/EnumType.java b/src/java/com/jogamp/gluegen/runtime/types/EnumType.java
new file mode 100644
index 0000000..9bff00e
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/EnumType.java
@@ -0,0 +1,189 @@
+/*
+ * 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.runtime.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/runtime/types/Field.java b/src/java/com/jogamp/gluegen/runtime/types/Field.java
new file mode 100644
index 0000000..0613b5f
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/Field.java
@@ -0,0 +1,107 @@
+/*
+ * 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.runtime.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/runtime/types/FloatType.java b/src/java/com/jogamp/gluegen/runtime/types/FloatType.java
new file mode 100644
index 0000000..4a10210
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/FloatType.java
@@ -0,0 +1,67 @@
+/*
+ * 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.runtime.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/runtime/types/FunctionType.java b/src/java/com/jogamp/gluegen/runtime/types/FunctionType.java
new file mode 100644
index 0000000..bfe0275
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/FunctionType.java
@@ -0,0 +1,202 @@
+/*
+ * 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.runtime.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/runtime/types/IntType.java b/src/java/com/jogamp/gluegen/runtime/types/IntType.java
new file mode 100644
index 0000000..02ab530
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/IntType.java
@@ -0,0 +1,93 @@
+/*
+ * 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.runtime.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/runtime/types/MemoryLayoutType.java b/src/java/com/jogamp/gluegen/runtime/types/MemoryLayoutType.java
new file mode 100644
index 0000000..3473d95
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/MemoryLayoutType.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2011 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.gluegen.runtime.types;
+
+public abstract class MemoryLayoutType extends Type {
+ private boolean isLayouted;
+
+ protected MemoryLayoutType(String name, SizeThunk size, int cvAttributes) {
+ super(name, size, cvAttributes);
+ isLayouted = false;
+ }
+
+ public boolean isLayouted() { return isLayouted; }
+ public void setLayouted() { /* FIXME JAU isLayouted = true; */ }
+
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/PointerType.java b/src/java/com/jogamp/gluegen/runtime/types/PointerType.java
new file mode 100644
index 0000000..e45b9ff
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/PointerType.java
@@ -0,0 +1,159 @@
+/*
+ * 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.runtime.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/runtime/types/PrimitiveType.java b/src/java/com/jogamp/gluegen/runtime/types/PrimitiveType.java
new file mode 100644
index 0000000..b2e6fc0
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/PrimitiveType.java
@@ -0,0 +1,52 @@
+/*
+ * 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.runtime.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/runtime/types/SizeThunk.java b/src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java
new file mode 100755
index 0000000..b9d4eda
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java
@@ -0,0 +1,226 @@
+/*
+ * 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.runtime.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 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 align(final SizeThunk offsetThunk,
+ final SizeThunk alignmentThunk) {
+ return new SizeThunk() {
+ public long computeSize(MachineDescription machDesc) {
+ // x % 2n == x & (2n - 1)
+ // remainder = net_size & ( alignment - 1 )
+ // padding = alignment - remainder ;
+ // aligned_size = net_size + padding ;
+
+ final long size = offsetThunk.computeSize(machDesc);
+ final long alignment = alignmentThunk.computeAlignment(machDesc);
+
+ final long remainder = size & ( alignment - 1 ) ;
+ final long padding = (remainder > 0) ? alignment - remainder : 0;
+ return size + padding;
+ }
+
+ public long computeAlignment(MachineDescription machDesc) {
+ final long thunk1A = offsetThunk.computeAlignment(machDesc);
+ final long thunk2A = alignmentThunk.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 alignment for constants
+ }
+ };
+ }
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/StructLayout.java b/src/java/com/jogamp/gluegen/runtime/types/StructLayout.java
new file mode 100644
index 0000000..95b7585
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/StructLayout.java
@@ -0,0 +1,138 @@
+/*
+ * 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.runtime.types;
+
+/** Encapsulates algorithm for laying out data structures. Note that
+ this ends up embedding code in various places via SizeThunks. If
+ the 32-bit and 64-bit ports on a given platform differ
+ fundamentally in their handling of struct layout then this code
+ will need to be updated and, most likely, two versions of the
+ SizeThunks maintained in various places. */
+
+public class StructLayout {
+ private int baseOffset;
+
+ protected StructLayout(int baseOffset) {
+ this.baseOffset = baseOffset;
+ }
+
+ public void layout(CompoundType t) {
+ /**
+ * - 1) align offset for the new data type,
+ * using the new data type alignment.
+ * Offsets are always upfront.
+ * - 2) add the aligned size of the new data type
+ * - 3) add trailing padding (largest element size)
+ */
+ int n = t.getNumFields();
+ SizeThunk curOffset = SizeThunk.constant(baseOffset);
+ SizeThunk maxSize = SizeThunk.constant(0);
+ for (int i = 0; i < n; i++) {
+ Field f = t.getField(i);
+ Type ft = f.getType();
+ if (ft.isInt() || ft.isFloat() || ft.isDouble() || ft.isPointer()) {
+ final SizeThunk sz = ft.getSize();
+ curOffset = SizeThunk.align(curOffset, sz);
+ f.setOffset(curOffset);
+ if (t.isUnion()) {
+ maxSize = SizeThunk.max(maxSize, sz);
+ } else {
+ curOffset = SizeThunk.add(curOffset, sz);
+ }
+ } else if (ft.isCompound()) {
+ final CompoundType ct = ft.asCompound();
+ if(!ct.isLayouted()) {
+ StructLayout.layout(0, ct);
+ }
+ final SizeThunk sz = ct.getSize();
+ curOffset = SizeThunk.align(curOffset, sz);
+ f.setOffset(curOffset);
+ if (t.isUnion()) {
+ maxSize = SizeThunk.max(maxSize, sz);
+ } else {
+ curOffset = SizeThunk.add(curOffset, sz);
+ }
+ } else if (ft.isArray()) {
+ ArrayType arrayType = ft.asArray();
+ if(!arrayType.isLayouted()) {
+ CompoundType compoundElementType = arrayType.getBaseElementType().asCompound();
+ if (compoundElementType != null) {
+ if(!compoundElementType.isLayouted()) {
+ StructLayout.layout(0, compoundElementType);
+ }
+ arrayType.recomputeSize();
+ }
+ arrayType.setLayouted();
+ }
+ final SizeThunk sz = ft.getSize();
+ curOffset = SizeThunk.align(curOffset, sz);
+ f.setOffset(curOffset);
+ curOffset = SizeThunk.add(curOffset, sz);
+ } else {
+ // FIXME
+ String name = t.getName();
+ if (name == null) {
+ name = t.toString();
+ }
+ throw new RuntimeException("Complicated field types (" + ft +
+ " " + f.getName() +
+ " in type " + name +
+ ") not implemented yet");
+ }
+ }
+ if (t.isUnion()) {
+ t.setSize(maxSize);
+ } else {
+ // trailing struct padding ..
+ curOffset = SizeThunk.align(curOffset, curOffset);
+ t.setSize(curOffset);
+ }
+ t.setLayouted();
+ }
+
+ public static StructLayout create(int baseOffset) {
+ return new StructLayout(baseOffset);
+ }
+
+ public static void layout(int baseOffset, CompoundType t) {
+ create(baseOffset).layout(t);
+ }
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/StructType.java b/src/java/com/jogamp/gluegen/runtime/types/StructType.java
new file mode 100644
index 0000000..2c0a589
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/StructType.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2011 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.gluegen.runtime.types;
+
+public class StructType extends CompoundType {
+
+ public StructType(String name, SizeThunk size, int cvAttributes) {
+ this(name, size, cvAttributes, null);
+ }
+
+ StructType(String name, SizeThunk size, int cvAttributes, String structName) {
+ super (name, size, cvAttributes, structName);
+ }
+
+ @Override
+ public boolean equals(Object arg) {
+ if (arg == null || !(arg instanceof StructType)) {
+ return false;
+ }
+ return super.equals(arg);
+ }
+
+ public final boolean isStruct() { return true; }
+ public final boolean isUnion() { return false; }
+
+ Type newCVVariant(int cvAttributes) {
+ StructType t = new StructType(getName(), getSize(), cvAttributes, getStructName());
+ t.setFields(getFields());
+ return t;
+ }
+
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/Type.java b/src/java/com/jogamp/gluegen/runtime/types/Type.java
new file mode 100644
index 0000000..ebedfcb
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/Type.java
@@ -0,0 +1,273 @@
+/*
+ * 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.runtime.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/runtime/types/TypeVisitor.java b/src/java/com/jogamp/gluegen/runtime/types/TypeVisitor.java
new file mode 100644
index 0000000..0d7f63d
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/TypeVisitor.java
@@ -0,0 +1,44 @@
+/*
+ * 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.runtime.types;
+
+public interface TypeVisitor {
+ public void visitType(Type t);
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/UnionType.java b/src/java/com/jogamp/gluegen/runtime/types/UnionType.java
new file mode 100644
index 0000000..5aee3f1
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/UnionType.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2011 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.gluegen.runtime.types;
+
+public class UnionType extends CompoundType {
+
+ public UnionType(String name, SizeThunk size, int cvAttributes) {
+ this(name, size, cvAttributes, null);
+ }
+
+ UnionType(String name, SizeThunk size, int cvAttributes, String structName) {
+ super (name, size, cvAttributes, structName);
+ }
+
+ @Override
+ public boolean equals(Object arg) {
+ if (arg == null || !(arg instanceof UnionType)) {
+ return false;
+ }
+ return super.equals(arg);
+ }
+
+ public final boolean isStruct() { return false; }
+ public final boolean isUnion() { return true; }
+
+ Type newCVVariant(int cvAttributes) {
+ UnionType t = new UnionType(getName(), getSize(), cvAttributes, getStructName());
+ t.setFields(getFields());
+ return t;
+ }
+
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/types/VoidType.java b/src/java/com/jogamp/gluegen/runtime/types/VoidType.java
new file mode 100644
index 0000000..07b3ec3
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/runtime/types/VoidType.java
@@ -0,0 +1,60 @@
+/*
+ * 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.runtime.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);
+ }
+}