aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2004-04-21 01:36:13 +0000
committerKenneth Russel <[email protected]>2004-04-21 01:36:13 +0000
commit0f2fa98495ce75434fc011e7ba2976c78edd38d0 (patch)
treeb0c3040900b1c1c9de052b960753ad2eaaa273b9 /src
parent2ee2b7b51e3e82553e7dc17fe1a04e8cec5be8bf (diff)
Fixed Issue 28: All functions that take arrays as parameters should also take buffers
Fixed Issue 36: glSelectBuffer/glFeedbackBuffer need direct buffers git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@112 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
-rw-r--r--src/net/java/games/gluegen/JavaConfiguration.java85
-rw-r--r--src/net/java/games/gluegen/JavaEmitter.java190
-rw-r--r--src/net/java/games/gluegen/JavaType.java141
-rw-r--r--src/net/java/games/gluegen/MethodBinding.java6
4 files changed, 357 insertions, 65 deletions
diff --git a/src/net/java/games/gluegen/JavaConfiguration.java b/src/net/java/games/gluegen/JavaConfiguration.java
index cdf2f091e..f72664a67 100644
--- a/src/net/java/games/gluegen/JavaConfiguration.java
+++ b/src/net/java/games/gluegen/JavaConfiguration.java
@@ -97,6 +97,14 @@ public class JavaConfiguration {
private Set/*<Pattern>*/ ignoreNots = new HashSet();
private Set/*<Pattern>*/ unimplemented = new HashSet();
private Set/*<String>*/ nioOnly = new HashSet();
+ /** See {@link #nioMode} */
+ public static final int NIO_MODE_VOID_ONLY = 1;
+ /** See {@link #nioMode} */
+ public static final int NIO_MODE_ALL_POINTERS = 2;
+ private int nioMode = NIO_MODE_VOID_ONLY;
+ private Set/*<String>*/ noNio = new HashSet();
+ private Set/*<String>*/ forcedNio = new HashSet();
+ private boolean flattenNIOVariants = true;
private Set/*<String>*/ manuallyImplement = new HashSet();
private Map/*<String,List<String>>*/ customJavaCode = new HashMap();
private Map/*<String,List<String>>*/ classJavadoc = new HashMap();
@@ -306,12 +314,46 @@ public class JavaConfiguration {
}
/** Returns true if the given function should only create a java.nio
- variant, and no array variants, for <code>void*</code>
- pointers. */
+ variant, and no array variants, for <code>void*</code> and other
+ C primitive pointers. */
public boolean nioOnly(String functionName) {
return nioOnly.contains(functionName);
}
+ /** Returns true if the user requested that the given function
+ should only create array variants, and no java.nio variant, for
+ <code>void*</code> and other C primitive pointers, overriding
+ the NIO mode default. */
+ public boolean noNio(String functionName) {
+ return noNio.contains(functionName);
+ }
+
+ /** Returns true if the user requested that the given function
+ should create a java.nio variant for the given function's
+ <code>void*</code> and other C primitive pointers, overriding
+ the NIO mode default. */
+ public boolean forcedNio(String functionName) {
+ return forcedNio.contains(functionName);
+ }
+
+ /** Returns the default NIO generation mode for C primitive pointer
+ arguments. NIO_MODE_VOID_ONLY is the default and specifies
+ that only void* arguments will have java.nio variants generated
+ for them. NIO_MODE_ALL_POINTERS specifies that all C
+ primitive arguments will have java.nio variants generated. */
+ public int nioMode() {
+ return nioMode;
+ }
+
+ /** Returns true if, for the plethora of java.nio variants generated
+ for primitive C pointer types, the emitter should flatten the
+ output down to two variants: one taking only Java primitive
+ arrays as arguments, and one taking only java.nio.Buffers as
+ arguments. */
+ public boolean flattenNIOVariants() {
+ return flattenNIOVariants;
+ }
+
/** Returns true if the glue code for the given function will be
manually implemented by the end user. */
public boolean manuallyImplement(String functionName) {
@@ -587,6 +629,14 @@ public class JavaConfiguration {
// because readClassJavadoc changes them.
} else if (cmd.equalsIgnoreCase("NioOnly")) {
nioOnly.add(readString("NioOnly", tok, filename, lineNo));
+ } else if (cmd.equalsIgnoreCase("NoNio")) {
+ noNio.add(readString("NoNio", tok, filename, lineNo));
+ } else if (cmd.equalsIgnoreCase("ForcedNio")) {
+ forcedNio.add(readString("ForcedNio", tok, filename, lineNo));
+ } else if (cmd.equalsIgnoreCase("NioMode")) {
+ readNioMode(tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("FlattenNIOVariants")) {
+ flattenNIOVariants = readBoolean("FlattenNIOVariants", tok, filename, lineNo).booleanValue();
} else if (cmd.equalsIgnoreCase("EmitStruct")) {
forcedStructs.add(readString("EmitStruct", tok, filename, lineNo));
} else if (cmd.equalsIgnoreCase("MirrorExpandedBindingArgs")) {
@@ -799,6 +849,37 @@ public class JavaConfiguration {
}
/**
+ * Sets the default NIO generation mode for C primitive
+ * pointers. Options are VOID_ONLY or ALL_POINTERS. When the mode is
+ * set to VOID_ONLY, java.nio variants of methods are only generated
+ * for C primitive pointers of type <code>void*</code>. All other
+ * pointers are translated by default into Java primitive arrays.
+ * When the mode is set to ALL_POINTERS, C primitive pointers of
+ * other types (i.e., <code>int*</code>) will have java.nio variants
+ * generated for them (i.e., <code>IntBuffer</code> as opposed to
+ * merely <code>int[]</code>). This default mode can be overridden
+ * with the NioOnly and NoNio directives. The default for this mode
+ * is currently VOID_ONLY.
+ */
+ protected void readNioMode(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String mode = tok.nextToken();
+ if (mode.equalsIgnoreCase("VOID_ONLY")) {
+ nioMode = NIO_MODE_VOID_ONLY;
+ } else if (mode.equalsIgnoreCase("ALL_POINTERS")) {
+ nioMode = NIO_MODE_ALL_POINTERS;
+ } else {
+ throw new RuntimeException("Error parsing \"NioMode\" command at line " + lineNo +
+ " in file \"" + filename + "\"; expected VOID_ONLY or ALL_POINTERS");
+ }
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException(
+ "Error parsing \"NioMode\" command at line " + lineNo +
+ " in file \"" + filename + "\"", e);
+ }
+ }
+
+ /**
* When void* arguments in the C function prototypes are encountered, the
* emitter will try to expand the binding and create Java entry points for
* all possible array types. If there are 2 or more void* arguments in the C
diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java
index b1384375e..46d976b23 100644
--- a/src/net/java/games/gluegen/JavaEmitter.java
+++ b/src/net/java/games/gluegen/JavaEmitter.java
@@ -753,9 +753,6 @@ public class JavaEmitter implements GlueEmitter {
return javaType(Void.TYPE);
} else {
if (t.pointerDepth() > 0 || arrayDimension(t) > 0) {
- // FIXME: add option to disable generation of typed pointer ->
- // array conversions so that these will be handled with direct
- // buffers (Should this be done later? in expandMethodBinding?)
Type targetType; // target type
if (t.isPointer()) {
// t is <type>*, we need to get <type>
@@ -765,24 +762,25 @@ public class JavaEmitter implements GlueEmitter {
targetType = t.asArray().getElementType();
}
- // Handle Types of form pointer-to-type or array-of-type, like char*
- // or int[]
+ // Handle Types of form pointer-to-type or array-of-type, like
+ // char* or int[]; these are expanded out into Java primitive
+ // arrays, NIO buffers, or both in expandMethodBinding
if (t.pointerDepth() == 1 || arrayDimension(t) == 1) {
if (targetType.isVoid()) {
return JavaType.createForVoidPointer();
} else if (targetType.isInt()) {
switch (targetType.getSize()) {
- case 1: return javaType(ArrayTypes.byteArrayClass);
- case 2: return javaType(ArrayTypes.shortArrayClass);
- case 4: return javaType(ArrayTypes.intArrayClass);
- case 8: return javaType(ArrayTypes.longArrayClass);
+ case 1: return JavaType.createForCCharPointer();
+ case 2: return JavaType.createForCShortPointer();
+ case 4: return JavaType.createForCInt32Pointer();
+ case 8: return JavaType.createForCInt64Pointer();
default: throw new RuntimeException("Unknown integer array type of size " +
t.getSize() + " and name " + t.getName());
}
} else if (targetType.isFloat()) {
- return javaType(ArrayTypes.floatArrayClass);
+ return JavaType.createForCFloatPointer();
} else if (targetType.isDouble()) {
- return javaType(ArrayTypes.doubleArrayClass);
+ return JavaType.createForCDoublePointer();
} else if (targetType.isCompound()) {
if (t.isArray()) {
throw new RuntimeException("Arrays of compound types not handled yet");
@@ -1207,10 +1205,9 @@ public class JavaEmitter implements GlueEmitter {
// Take into account any ArgumentIsString configuration directives that apply
if (stringArgIndices != null && stringArgIndices.contains(new Integer(i))) {
//System.out.println("Forcing conversion of " + binding.getName() + " arg #" + i + " from byte[] to String ");
- if ((mappedType.isArray() &&
- (mappedType.getJavaClass() == ArrayTypes.byteArrayClass ||
- mappedType.getJavaClass() == ArrayTypes.byteArrayArrayClass)) ||
- (mappedType.isVoidPointerType())) {
+ if (mappedType.isCVoidPointerType() ||
+ mappedType.isCCharPointerType() ||
+ (mappedType.isArray() && mappedType.getJavaClass() == ArrayTypes.byteArrayArrayClass)) {
// convert mapped type from void* and byte[] to String, or byte[][] to String[]
if (mappedType.getJavaClass() == ArrayTypes.byteArrayArrayClass) {
mappedType = javaType(ArrayTypes.stringArrayClass);
@@ -1234,8 +1231,8 @@ public class JavaEmitter implements GlueEmitter {
return binding;
}
- // Expands a MethodBinding containing void pointer types into
- // multiple variants taking double arrays and NIO buffers, subject
+ // Expands a MethodBinding containing C primitive pointer types into
+ // multiple variants taking Java primitive arrays and NIO buffers, subject
// to the per-function "NIO only" rule in the configuration file
private List/*<MethodBinding>*/ expandMethodBinding(MethodBinding binding) {
List result = new ArrayList();
@@ -1246,37 +1243,111 @@ public class JavaEmitter implements GlueEmitter {
boolean shouldRemoveCurrent = false;
for (int j = 0; j < mb.getNumArguments(); j++) {
JavaType t = mb.getJavaArgumentType(j);
- if (t.isVoidPointerType()) {
- // Create variants
+ if (t.isCPrimitivePointerType()) {
+ // Remove original from list
+ shouldRemoveCurrent = true;
MethodBinding variant = null;
- if (!cfg.nioOnly(mb.getCSymbol().getName())) {
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.booleanArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.byteArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.charArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.shortArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.intArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.longArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.floatArrayClass));
- if (! result.contains(variant)) result.add(variant);
- variant = mb.createVoidPointerVariant(j, javaType(ArrayTypes.doubleArrayClass));
- if (! result.contains(variant)) result.add(variant);
+
+ // Non-NIO variants for void* and other C primitive pointer types
+ if (!cfg.nioOnly(mb.getCSymbol().getName())) {
+ if (t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.booleanArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.charArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
+ if (t.isCCharPointerType() || t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.byteArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
+ if (t.isCShortPointerType() || t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.shortArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
+ if (t.isCInt32PointerType() || t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.intArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
+ if (t.isCInt64PointerType() || t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.longArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
+ if (t.isCFloatPointerType() || t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.floatArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
+ if (t.isCDoublePointerType() || t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.doubleArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
}
- variant = mb.createVoidPointerVariant(j, JavaType.forNIOBufferClass());
- if (! result.contains(variant)) result.add(variant);
- // Remove original from list
- shouldRemoveCurrent = true;
+ // NIO variants for void* and other C primitive pointer types
+ if (!cfg.noNio(mb.getCSymbol().getName())) {
+ if (t.isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+ }
+
+ if ((cfg.nioMode() == JavaConfiguration.NIO_MODE_ALL_POINTERS && !cfg.noNio(mb.getCSymbol().getName())) ||
+ (cfg.nioMode() == JavaConfiguration.NIO_MODE_VOID_ONLY && cfg.forcedNio(mb.getCSymbol().getName()))) {
+ if (t.isCCharPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOByteBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+
+ if (t.isCShortPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOShortBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+
+ if (t.isCInt32PointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOIntBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+
+ if (t.isCInt64PointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOLongBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+
+ if (t.isCFloatPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOFloatBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+
+ if (t.isCDoublePointerType()) {
+ variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIODoubleBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ }
+ }
}
}
- if (mb.getJavaReturnType().isVoidPointerType()) {
- MethodBinding variant = mb.createVoidPointerVariant(-1, JavaType.forNIOByteBufferClass());
- if (! result.contains(variant)) result.add(variant);
+ if (mb.getJavaReturnType().isCPrimitivePointerType()) {
+ MethodBinding variant = null;
+ if (mb.getJavaReturnType().isCVoidPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.forNIOByteBufferClass());
+ if (! result.contains(variant)) result.add(variant);
+ } else if (mb.getJavaReturnType().isCCharPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.createForClass(ArrayTypes.byteArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ } else if (mb.getJavaReturnType().isCShortPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.createForClass(ArrayTypes.shortArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ } else if (mb.getJavaReturnType().isCInt32PointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.createForClass(ArrayTypes.intArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ } else if (mb.getJavaReturnType().isCInt64PointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.createForClass(ArrayTypes.longArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ } else if (mb.getJavaReturnType().isCFloatPointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.createForClass(ArrayTypes.floatArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ } else if (mb.getJavaReturnType().isCDoublePointerType()) {
+ variant = mb.createCPrimitivePointerVariant(-1, JavaType.createForClass(ArrayTypes.doubleArrayClass));
+ if (! result.contains(variant)) result.add(variant);
+ }
shouldRemoveCurrent = true;
}
if (shouldRemoveCurrent) {
@@ -1285,6 +1356,39 @@ public class JavaEmitter implements GlueEmitter {
}
++i;
}
+
+ // Honor the flattenNIOVariants directive in the configuration file
+ if (cfg.flattenNIOVariants()) {
+ i = 0;
+ while (i < result.size()) {
+ boolean shouldRemoveCurrent = false;
+ MethodBinding mb = (MethodBinding) result.get(i);
+ for (int j = 0; j < binding.getNumArguments() && !shouldRemoveCurrent; j++) {
+ JavaType t1 = binding.getJavaArgumentType(j);
+ if (t1.isCPrimitivePointerType() && !t1.isCVoidPointerType()) {
+ for (int k = j + 1; k < binding.getNumArguments() && !shouldRemoveCurrent; k++) {
+ JavaType t2 = binding.getJavaArgumentType(k);
+ if (t2.isCPrimitivePointerType() && !t2.isCVoidPointerType()) {
+ // The "NIO-ness" of the converted arguments in the
+ // new binding must match
+ JavaType nt1 = mb.getJavaArgumentType(j);
+ JavaType nt2 = mb.getJavaArgumentType(k);
+ if (nt1.isNIOBuffer() != nt2.isNIOBuffer()) {
+ shouldRemoveCurrent = true;
+ }
+ }
+ }
+ }
+ }
+ if (shouldRemoveCurrent) {
+ result.remove(i);
+ --i;
+ }
+
+ ++i;
+ }
+ }
+
return result;
}
diff --git a/src/net/java/games/gluegen/JavaType.java b/src/net/java/games/gluegen/JavaType.java
index ea771613e..6e9d71c2a 100644
--- a/src/net/java/games/gluegen/JavaType.java
+++ b/src/net/java/games/gluegen/JavaType.java
@@ -49,11 +49,29 @@ import net.java.games.gluegen.cgram.types.*;
* contains some utility methods for creating common types.
*/
public class JavaType {
+ private static final int PTR_C_VOID = 1;
+ private static final int PTR_C_CHAR = 2;
+ private static final int PTR_C_SHORT = 3;
+ private static final int PTR_C_INT32 = 4;
+ private static final int PTR_C_INT64 = 5;
+ private static final int PTR_C_FLOAT = 6;
+ private static final int PTR_C_DOUBLE = 7;
+
private Class clazz; // Primitive types and other types representable as Class objects
private String name; // Types we're generating glue code for (i.e., C structs)
private Type elementType; // Element type if this JavaType represents a C array
+ private int primitivePointerType; // Represents C arrays that
+ // will / can be represented
+ // with NIO buffers (resolved
+ // down to another JavaType
+ // later in processing)
private static JavaType nioBufferType;
private static JavaType nioByteBufferType;
+ private static JavaType nioShortBufferType;
+ private static JavaType nioIntBufferType;
+ private static JavaType nioLongBufferType;
+ private static JavaType nioFloatBufferType;
+ private static JavaType nioDoubleBufferType;
private static JavaType nioByteBufferArrayType;
public boolean equals(Object arg) {
@@ -61,9 +79,13 @@ public class JavaType {
return false;
}
JavaType t = (JavaType) arg;
- return (t.clazz == clazz &&
- ((t.name == name) ||
- ((name != null) && (t.name != null) && (t.name.equals(name)))));
+ return (this == t ||
+ (t.clazz == clazz &&
+ ((name == t.name) ||
+ ((name != null) && (t.name != null) && (name.equals(t.name)))) &&
+ ((elementType == t.elementType) ||
+ (elementType != null) && (t.elementType != null) && (elementType.equals(t.elementType))) &&
+ (primitivePointerType == t.primitivePointerType)));
}
public int hashCode() {
@@ -99,7 +121,31 @@ public class JavaType {
}
public static JavaType createForVoidPointer() {
- return new JavaType();
+ return new JavaType(PTR_C_VOID);
+ }
+
+ public static JavaType createForCCharPointer() {
+ return new JavaType(PTR_C_CHAR);
+ }
+
+ public static JavaType createForCShortPointer() {
+ return new JavaType(PTR_C_SHORT);
+ }
+
+ public static JavaType createForCInt32Pointer() {
+ return new JavaType(PTR_C_INT32);
+ }
+
+ public static JavaType createForCInt64Pointer() {
+ return new JavaType(PTR_C_INT64);
+ }
+
+ public static JavaType createForCFloatPointer() {
+ return new JavaType(PTR_C_FLOAT);
+ }
+
+ public static JavaType createForCDoublePointer() {
+ return new JavaType(PTR_C_DOUBLE);
}
public static JavaType createForJNIEnv() {
@@ -120,6 +166,41 @@ public class JavaType {
return nioByteBufferType;
}
+ public static JavaType forNIOShortBufferClass() {
+ if (nioShortBufferType == null) {
+ nioShortBufferType = createForClass(java.nio.ShortBuffer.class);
+ }
+ return nioShortBufferType;
+ }
+
+ public static JavaType forNIOIntBufferClass() {
+ if (nioIntBufferType == null) {
+ nioIntBufferType = createForClass(java.nio.IntBuffer.class);
+ }
+ return nioIntBufferType;
+ }
+
+ public static JavaType forNIOLongBufferClass() {
+ if (nioLongBufferType == null) {
+ nioLongBufferType = createForClass(java.nio.LongBuffer.class);
+ }
+ return nioLongBufferType;
+ }
+
+ public static JavaType forNIOFloatBufferClass() {
+ if (nioFloatBufferType == null) {
+ nioFloatBufferType = createForClass(java.nio.FloatBuffer.class);
+ }
+ return nioFloatBufferType;
+ }
+
+ public static JavaType forNIODoubleBufferClass() {
+ if (nioDoubleBufferType == null) {
+ nioDoubleBufferType = createForClass(java.nio.DoubleBuffer.class);
+ }
+ return nioDoubleBufferType;
+ }
+
public static JavaType forNIOByteBufferArrayClass() {
if (nioByteBufferArrayType == null) {
ByteBuffer[] tmp = new ByteBuffer[0];
@@ -130,7 +211,7 @@ public class JavaType {
/**
* Returns the Java Class corresponding to this type. Returns null if this
- * object corresponds to a C "void*" type.
+ * object corresponds to a C primitive array type.
*/
public Class getJavaClass() {
return clazz;
@@ -216,8 +297,7 @@ public class JavaType {
}
public boolean isNIOBuffer() {
- return (clazz == java.nio.Buffer.class ||
- clazz == java.nio.ByteBuffer.class);
+ return (clazz != null && java.nio.Buffer.class.isAssignableFrom(clazz));
}
public boolean isNIOByteBuffer() {
@@ -252,8 +332,36 @@ public class JavaType {
return (elementType != null);
}
- public boolean isVoidPointerType() {
- return (clazz == null && name == null && elementType == null);
+ public boolean isCPrimitivePointerType() {
+ return (primitivePointerType != 0);
+ }
+
+ public boolean isCVoidPointerType() {
+ return (primitivePointerType == PTR_C_VOID);
+ }
+
+ public boolean isCCharPointerType() {
+ return (primitivePointerType == PTR_C_CHAR);
+ }
+
+ public boolean isCShortPointerType() {
+ return (primitivePointerType == PTR_C_SHORT);
+ }
+
+ public boolean isCInt32PointerType() {
+ return (primitivePointerType == PTR_C_INT32);
+ }
+
+ public boolean isCInt64PointerType() {
+ return (primitivePointerType == PTR_C_INT64);
+ }
+
+ public boolean isCFloatPointerType() {
+ return (primitivePointerType == PTR_C_FLOAT);
+ }
+
+ public boolean isCDoublePointerType() {
+ return (primitivePointerType == PTR_C_DOUBLE);
}
public boolean isJNIEnv() {
@@ -261,11 +369,12 @@ public class JavaType {
}
public Object clone() {
- JavaType clone = new JavaType();
+ JavaType clone = new JavaType(primitivePointerType);
clone.clazz = this.clazz;
clone.name = this.name;
-
+ clone.elementType = this.elementType;
+
return clone;
}
@@ -295,12 +404,10 @@ public class JavaType {
this.elementType = elementType;
}
- /**
- * Default constructor; the type is initialized to the equivalent of a
- * C-language "void *".
- */
- private JavaType() {
-
+ /** Constructs a type representing a pointer to a C primitive
+ (integer, floating-point, or void pointer) type. */
+ private JavaType(int primitivePointerType) {
+ this.primitivePointerType = primitivePointerType;
}
private String arrayName(Class clazz) {
diff --git a/src/net/java/games/gluegen/MethodBinding.java b/src/net/java/games/gluegen/MethodBinding.java
index af86f0b66..5a88f00f8 100644
--- a/src/net/java/games/gluegen/MethodBinding.java
+++ b/src/net/java/games/gluegen/MethodBinding.java
@@ -142,11 +142,11 @@ public class MethodBinding {
return sym.getName();
}
- /** Replaces the void* argument at slot <i>argumentNumber</i>
+ /** Replaces the C primitive pointer argument at slot <i>argumentNumber</i>
(0..getNumArguments() - 1) with the specified type. If
argumentNumber is less than 0 then replaces the return type. */
- public MethodBinding createVoidPointerVariant(int argumentNumber,
- JavaType newArgType) {
+ public MethodBinding createCPrimitivePointerVariant(int argumentNumber,
+ JavaType newArgType) {
MethodBinding binding = new MethodBinding(sym);
if (argumentNumber < 0) {
binding.setJavaReturnType(newArgType);