summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/cgram
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/gluegen/cgram')
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/ArrayType.java7
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/FunctionType.java20
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/PointerType.java12
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/StructLayout.java12
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/Type.java97
5 files changed, 110 insertions, 38 deletions
diff --git a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java
index 678fa10..401944b 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/ArrayType.java
@@ -72,8 +72,7 @@ public class ArrayType extends MemoryLayoutType implements Cloneable {
// 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();
+ computedName = (elementType.getName() + " *").intern();
}
return computedName;
}
@@ -85,14 +84,14 @@ public class ArrayType extends MemoryLayoutType implements Cloneable {
public int getLength() { return length; }
public boolean hasLength() { return length >= 0; }
- /** Return the bottommost element type if this is a multidimensional
- array. */
+ @Override
public Type getBaseElementType() {
ArrayType t = this;
while (t.getElementType().isArray()) {
t = t.getElementType().asArray();
}
return t.getElementType();
+ // return elementType.getBaseElementType();
}
/** Recompute the size of this array if necessary. This needs to be
diff --git a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
index 70fbc64..7672744 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
@@ -126,19 +126,16 @@ public class FunctionType extends Type implements Cloneable {
return toString(null);
}
- public String toString(String functionName) {
+ public String toString(final String functionName) {
return toString(functionName, false);
}
- public String toString(String functionName, boolean emitNativeTag) {
+ public String toString(final String functionName, final boolean emitNativeTag) {
return toString(functionName, null, emitNativeTag, false);
}
- String toString(String functionName, String callingConvention, boolean emitNativeTag, boolean isPointer) {
- StringBuilder res = new StringBuilder();
- if(isConst()) {
- res.append("const ");
- }
+ String toString(final String functionName, final String callingConvention, final boolean emitNativeTag, final boolean isPointer) {
+ final StringBuilder res = new StringBuilder();
res.append(getReturnType());
res.append(" ");
if (isPointer) {
@@ -167,17 +164,11 @@ public class FunctionType extends Type implements Cloneable {
Type t = getArgumentType(i);
if (t.isFunctionPointer()) {
Type targetType = t.asPointer().getTargetType();
- if(targetType.isConst()) {
- res.append("const ");
- }
FunctionType ft = targetType.asFunction();
res.append(ft.toString(getArgumentName(i), callingConvention, false, true));
} else if (t.isArray()) {
res.append(t.asArray().toString(getArgumentName(i)));
} else {
- if(t.isConst()) {
- res.append("const ");
- }
res.append(t);
String argumentName = getArgumentName(i);
if (argumentName != null) {
@@ -190,9 +181,6 @@ public class FunctionType extends Type implements Cloneable {
}
}
res.append(")");
- if (!isPointer) {
- res.append(";");
- }
return res.toString();
}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java
index 330d791..5f19202 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java
@@ -97,8 +97,7 @@ public class PointerType extends Type implements Cloneable {
// Lazy computation of name due to lazy setting of compound type
// names during parsing
if (computedName == null) {
- computedName = targetType.getName(includeCVAttrs) + " *";
- computedName = computedName.intern();
+ computedName = (targetType.getName(includeCVAttrs) + " *").intern();
}
if (!includeCVAttrs) {
return computedName;
@@ -120,12 +119,15 @@ public class PointerType extends Type implements Cloneable {
return targetType;
}
- public Type getLastTargetType() {
+ @Override
+ public Type getBaseElementType() {
+ /**
if(targetType.isPointer()) {
- return ((PointerType)targetType).getLastTargetType();
+ return ((PointerType)targetType).getBaseElementType();
} else {
return targetType;
- }
+ } */
+ return targetType.getBaseElementType();
}
@Override
diff --git a/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java b/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java
index f105f1f..dfcb722 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java
@@ -87,9 +87,6 @@ public class StructLayout {
} else {
curOffset = SizeThunk.add(curOffset, sz);
}
- if( GlueGen.debug() ) {
- System.err.printf("SL.%02d: o %03d, s %03d, t %s: %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), ft, f);
- }
} else if (ft.isCompound()) {
final CompoundType ct = ft.asCompound();
if(!ct.isLayouted()) {
@@ -103,9 +100,6 @@ public class StructLayout {
} else {
curOffset = SizeThunk.add(curOffset, sz);
}
- if( GlueGen.debug() ) {
- System.err.printf("SL.%02d: o %03d, s %03d, t %s{%d}: %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), ft, ct.getNumFields(), f);
- }
} else if (ft.isArray()) {
final ArrayType arrayType = ft.asArray();
if(!arrayType.isLayouted()) {
@@ -122,9 +116,6 @@ public class StructLayout {
curOffset = SizeThunk.align(curOffset, sz);
f.setOffset(curOffset);
curOffset = SizeThunk.add(curOffset, sz);
- if( GlueGen.debug() ) {
- System.err.printf("SL.%02d: o %03d, s %03d, t %s: %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), ft, f);
- }
} else {
// FIXME
String name = t.getName();
@@ -136,6 +127,9 @@ public class StructLayout {
" in type " + name +
") not implemented yet");
}
+ if( GlueGen.debug() ) {
+ System.err.printf("SL.%02d: o %03d, s %03d: %s, %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), f, ft.getDebugString());
+ }
}
if (t.isUnion()) {
t.setSize(maxSize);
diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java
index a403de6..45d610d 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/Type.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java
@@ -52,8 +52,8 @@ public abstract class Type implements Cloneable {
private String name;
private SizeThunk size;
- private int cvAttributes;
- private int typedefedCVAttributes;
+ private final int cvAttributes;
+ private int typedefedCVAttributes;
private boolean hasTypedefName;
protected Type(String name, SizeThunk size, int cvAttributes) {
@@ -75,18 +75,96 @@ public abstract class Type implements Cloneable {
/** 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); }
+ public final 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) {
+ public String getName(boolean includeCVAttrs) {
if (!includeCVAttrs) {
return name;
}
return getCVAttributesString() + name;
}
+ private void append(final StringBuilder sb, final String val, final boolean prepComma) {
+ if( prepComma ) {
+ sb.append(", ");
+ }
+ sb.append(val);
+ }
+ // For debugging
+ public String getDebugString() {
+ final StringBuilder sb = new StringBuilder();
+ boolean prepComma = false;
+ sb.append("CType[");
+ if( null != name ) {
+ append(sb, "'"+name+"'", prepComma); prepComma=true;
+ } else {
+ append(sb, "ANON", prepComma); prepComma=true;
+ }
+ if( hasTypedefName() ) {
+ sb.append(" (typedef)");
+ }
+ append(sb, "size ", prepComma); prepComma=true;
+ if( null != size ) {
+ final long mdSize;
+ {
+ long _mdSize = -1;
+ try {
+ _mdSize = size.computeSize(MachineDescription.StaticConfig.X86_64_UNIX.md);
+ } catch (Exception e) {}
+ mdSize = _mdSize;
+ }
+ sb.append("[fixed ").append(size.hasFixedNativeSize()).append(", lnx64 ").append(mdSize).append("]");
+ } else {
+ sb.append(" ZERO");
+ }
+ append(sb, "[", prepComma); prepComma=false;
+ if( isConst() ) {
+ append(sb, "const ", false);
+ }
+ if( isVolatile() ) {
+ append(sb, "volatile ", false);
+ }
+ if( isPointer() ) {
+ append(sb, "pointer*"+pointerDepth(), prepComma); prepComma=true;
+ }
+ if( isArray() ) {
+ append(sb, "array*"+arrayDimension(), prepComma); prepComma=true;
+ }
+ if( isBit() ) {
+ append(sb, "bit", prepComma); prepComma=true;
+ }
+ if( isCompound() ) {
+ sb.append("struct{").append(asCompound().getNumFields());
+ append(sb, "}", prepComma); prepComma=true;
+ }
+ if( isDouble() ) {
+ append(sb, "double", prepComma); prepComma=true;
+ }
+ if( isEnum() ) {
+ append(sb, "enum", prepComma); prepComma=true;
+ }
+ if( isFloat() ) {
+ append(sb, "float", prepComma); prepComma=true;
+ }
+ if( isFunction() ) {
+ append(sb, "function", prepComma); prepComma=true;
+ }
+ if( isFunctionPointer() ) {
+ append(sb, "funcPointer", prepComma); prepComma=true;
+ }
+ if( isInt() ) {
+ append(sb, "int", prepComma); prepComma=true;
+ }
+ if( isVoid() ) {
+ append(sb, "void", prepComma); prepComma=true;
+ }
+ sb.append("]]");
+ return sb.toString();
+ }
+
/** Set the name of this type; used for handling typedefs. */
public void setName(String name) {
if (name == null) {
@@ -269,6 +347,17 @@ public abstract class Type implements Cloneable {
return 1 + arrayType.getElementType().arrayDimension();
}
+ /**
+ * Helper method to returns the bottom-most element type of this type.
+ * <p>
+ * If this is a multidimensional array or pointer method returns the bottom-most element type,
+ * otherwise this.
+ * </p>
+ */
+ public Type getBaseElementType() {
+ return this;
+ }
+
/** Helper routine for list equality comparison */
static <C> boolean listsEqual(List<C> a, List<C> b) {
return ((a == null && b == null) || (a != null && b != null && a.equals(b)));