diff options
author | Travis Bryson <[email protected]> | 2005-02-28 23:38:51 +0000 |
---|---|---|
committer | Travis Bryson <[email protected]> | 2005-02-28 23:38:51 +0000 |
commit | c35019b5256ca33fb642d54608101ab7292f3c60 (patch) | |
tree | 000d0e2c0937fd9d3893cf5c2007eb6efc69eae7 /src/net/java/games | |
parent | b41b720c4366d4e2cdc1ba146123b87da966d724 (diff) |
Add PrimitiveArrayExpansion mode option to grammar, Implement PrimitiveArrayExpansion mode in gluegen, Add VoidPointerExpansion mode option to grammar, Implement VoidPointerExpansion mode in gluegen, change grammar file appropriately, Add a couple of Apple NIOOnly options, omission was previously a bug
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@250 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games')
-rw-r--r-- | src/net/java/games/gluegen/JavaConfiguration.java | 158 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaEmitter.java | 62 |
2 files changed, 210 insertions, 10 deletions
diff --git a/src/net/java/games/gluegen/JavaConfiguration.java b/src/net/java/games/gluegen/JavaConfiguration.java index f72664a67..73aebb5a8 100644 --- a/src/net/java/games/gluegen/JavaConfiguration.java +++ b/src/net/java/games/gluegen/JavaConfiguration.java @@ -49,6 +49,29 @@ import net.java.games.gluegen.cgram.types.*; JavaEmitter. */ public class JavaConfiguration { + + /* possible PrimitiveArrayExpansionMode states */ + private int ALL_POINTERS = 1; + private int NON_VOID_ONLY = 2; + private int NO_POINTERS = 3; + + /* Default primitive array expansion mode is ALL_POINTERS, meaning all C + pointers, including void pointers, will have Java primitive array + expansions */ + private int primitiveArrayExpansionMode = ALL_POINTERS; + + /* Determines which primitive array types void * C signatures are + expanded into (assuming PrimitiveArrayExpansionMode = ALL_POINTERS). */ + private boolean voidPointerExpansionToBoolean = true; + private boolean voidPointerExpansionToChar = true; + private boolean voidPointerExpansionToByte = true; + private boolean voidPointerExpansionToShort = true; + private boolean voidPointerExpansionToInt = true; + private boolean voidPointerExpansionToLong = true; + private boolean voidPointerExpansionToFloat = true; + private boolean voidPointerExpansionToDouble = true; + + private int nestedReads; private String packageName; private String implPackageName; @@ -230,6 +253,30 @@ public class JavaConfiguration { /** Returns the list of imports that should be emitted at the top of each .java file. */ public List/*<String>*/ imports() { return imports; } + + /* Return Primitive Array Expansion Mode state */ + public boolean isPrimArrayExpModeAllPtrs() { + return (primitiveArrayExpansionMode == ALL_POINTERS); + } + public boolean isPrimArrayExpModeNonVoidPtrs() { + return (primitiveArrayExpansionMode == NON_VOID_ONLY); + } + public boolean isPrimArrayExpModeNoPtrs() { + return (primitiveArrayExpansionMode == NO_POINTERS); + } + + + /** Returns VoidPointerExpansion values */ + public boolean voidPointerExpansionToBoolean() { return voidPointerExpansionToBoolean; } + public boolean voidPointerExpansionToChar() { return voidPointerExpansionToChar; } + public boolean voidPointerExpansionToByte() { return voidPointerExpansionToByte; } + public boolean voidPointerExpansionToShort() { return voidPointerExpansionToShort; } + public boolean voidPointerExpansionToInt() { return voidPointerExpansionToInt; } + public boolean voidPointerExpansionToLong() { return voidPointerExpansionToLong; } + public boolean voidPointerExpansionToFloat() { return voidPointerExpansionToFloat; } + public boolean voidPointerExpansionToDouble() { return voidPointerExpansionToDouble; } + + /** If this type should be considered opaque, returns the TypeInfo describing the replacement type. Returns null if this type should not be considered opaque. */ @@ -637,6 +684,10 @@ public class JavaConfiguration { readNioMode(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("FlattenNIOVariants")) { flattenNIOVariants = readBoolean("FlattenNIOVariants", tok, filename, lineNo).booleanValue(); + } else if (cmd.equalsIgnoreCase("PrimitiveArrayExpansionMode")) { + readPrimitiveExpMode(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("VoidPointerExpansion")) { + readVoidPointerExpansionSet(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("EmitStruct")) { forcedStructs.add(readString("EmitStruct", tok, filename, lineNo)); } else if (cmd.equalsIgnoreCase("MirrorExpandedBindingArgs")) { @@ -879,6 +930,113 @@ public class JavaConfiguration { } } + + /** + * Sets the Primitive Array Expansion Mode. Options are ALL_POINTERS (default), + * NON_VOID_ONLY, and NO_POINTERS. ALL_POINTERS means that all Primitive array + * C pointers (float*, int*, void*, etc.) get expanded into non-NIO buffer + * targets. The setting has no bearing on whether NIO buffer targets happen. + * So float * goes to float[], int* goes to int[], and void* gets expanded to + * (by default) double[], float[], long[], int[], short[], byte[], char[], and + * boolean[]. NON_VOID_ONLY means that all Primitive array pointers except + * for void * get expanded, and NO_POINTERS means that no C Primitive array + * pointers get expanded. + * For void * expansion the default is all 8 primitive types as listed above. + * However, the types can be restricted by use of the VoidPointerExpansion + * attribute defined elsewhere in this file. + */ + + protected void readPrimitiveExpMode(StringTokenizer tok, String filename, int lineNo) { + try { + String mode = tok.nextToken(); + if (mode.equalsIgnoreCase("ALL_POINTERS")) { + primitiveArrayExpansionMode = ALL_POINTERS; + } else if (mode.equalsIgnoreCase("NON_VOID_ONLY")) { + primitiveArrayExpansionMode = NON_VOID_ONLY; + } else if (mode.equalsIgnoreCase("NO_POINTERS")) { + primitiveArrayExpansionMode = NO_POINTERS; + } else { + throw new RuntimeException("Error parsing \"PrimitiveArrayExpansionMode\" command at line " + lineNo + + " in file \"" + filename + + "\"; expected NO_POINTERS, NON_VOID_ONLY or ALL_POINTERS"); + } + } catch (NoSuchElementException e) { + throw new RuntimeException( + "Error parsing \"PrimitiveArrayExpansionMode\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + + + + /** + * readVoidPointerExpansionSet: + * Parses VoidPointerExpansion arguments. Expecting subset of boolean, char, byte, + * short, int, long,float, double. Example grammar file syntax: + * VoidPointerExpansion short int float byte double + * If PrimitiveArrayExpansionMode is set to NON_VOID_ONLY or NO_POINTERS, then + * the VoidPointerExpansion attribute has no effect, since in that case void + * pointers are not expanded. + */ + + protected void readVoidPointerExpansionSet(StringTokenizer tok, String filename, int lineNo) { + int number_passes=0; + boolean finished = false; + + voidPointerExpansionToBoolean = false; + voidPointerExpansionToChar = false; + voidPointerExpansionToByte = false; + voidPointerExpansionToShort = false; + voidPointerExpansionToInt = false; + voidPointerExpansionToLong = false; + voidPointerExpansionToFloat = false; + voidPointerExpansionToDouble = false; + + while(!finished) { + try { + String mode = tok.nextToken(); + if (mode.equalsIgnoreCase("float")) { + voidPointerExpansionToFloat = true; + number_passes++; + } else if (mode.equalsIgnoreCase("int")) { + voidPointerExpansionToInt = true; + number_passes++; + } else if (mode.equalsIgnoreCase("byte")) { + voidPointerExpansionToByte = true; + number_passes++; + } else if (mode.equalsIgnoreCase("short")) { + voidPointerExpansionToShort = true; + number_passes++; + } else if (mode.equalsIgnoreCase("boolean")) { + voidPointerExpansionToBoolean = true; + number_passes++; + } else if (mode.equalsIgnoreCase("char")) { + voidPointerExpansionToChar = true; + number_passes++; + } else if (mode.equalsIgnoreCase("long")) { + voidPointerExpansionToLong = true; + number_passes++; + } else if (mode.equalsIgnoreCase("double")) { + voidPointerExpansionToDouble = true; + number_passes++; + } else { + throw new RuntimeException("Error parsing \"VoidPointerExpansion\" command at line " + lineNo + + " in file \"" + filename + + "\"; expected some combination of boolean, char, byte, short, int, long, float, double"); + } + } catch (NoSuchElementException e) { + if(number_passes == 0) { + throw new RuntimeException( + "Error parsing \"VoidPointerExpansion\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + finished = true; + } + } + } + + + /** * When void* arguments in the C function prototypes are encountered, the * emitter will try to expand the binding and create Java entry points for diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java index 318c2ad73..f635c2d44 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/net/java/games/gluegen/JavaEmitter.java @@ -1255,41 +1255,75 @@ public class JavaEmitter implements GlueEmitter { shouldRemoveCurrent = true; MethodBinding variant = null; - // Non-NIO variants for void* and other C primitive pointer types - if (!cfg.nioOnly(mb.getCSymbol().getName())) { - if (t.isCVoidPointerType()) { + // Non-NIO variants for non-void C primitive pointer types + if (!cfg.nioOnly(mb.getCSymbol().getName()) && !t.isCVoidPointerType() + && !cfg.isPrimArrayExpModeNoPtrs()) { + if (t.isCCharPointerType()) { + variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.byteArrayClass)); + if (! result.contains(variant)) result.add(variant); + } + if (t.isCShortPointerType()) { + variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.shortArrayClass)); + if (! result.contains(variant)) result.add(variant); + } + if (t.isCInt32PointerType()) { + variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.intArrayClass)); + if (! result.contains(variant)) result.add(variant); + } + if (t.isCInt64PointerType()) { + variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.longArrayClass)); + if (! result.contains(variant)) result.add(variant); + } + if (t.isCFloatPointerType()) { + variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.floatArrayClass)); + if (! result.contains(variant)) result.add(variant); + } + if (t.isCDoublePointerType()) { + variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.doubleArrayClass)); + if (! result.contains(variant)) result.add(variant); + } + } + + + // Non-NIO variants for void* C primitive pointer type + if (!cfg.nioOnly(mb.getCSymbol().getName()) && t.isCVoidPointerType() + && cfg.isPrimArrayExpModeAllPtrs()) { + if (cfg.voidPointerExpansionToBoolean()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.booleanArrayClass)); if (! result.contains(variant)) result.add(variant); + } + if (cfg.voidPointerExpansionToChar()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.charArrayClass)); if (! result.contains(variant)) result.add(variant); } - if (t.isCCharPointerType() || t.isCVoidPointerType()) { + if (cfg.voidPointerExpansionToByte()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.byteArrayClass)); if (! result.contains(variant)) result.add(variant); } - if (t.isCShortPointerType() || t.isCVoidPointerType()) { + if (cfg.voidPointerExpansionToShort()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.shortArrayClass)); if (! result.contains(variant)) result.add(variant); } - if (t.isCInt32PointerType() || t.isCVoidPointerType()) { + if (cfg.voidPointerExpansionToInt()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.intArrayClass)); if (! result.contains(variant)) result.add(variant); } - if (t.isCInt64PointerType() || t.isCVoidPointerType()) { + if (cfg.voidPointerExpansionToLong()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.longArrayClass)); if (! result.contains(variant)) result.add(variant); } - if (t.isCFloatPointerType() || t.isCVoidPointerType()) { + if (cfg.voidPointerExpansionToFloat()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.floatArrayClass)); if (! result.contains(variant)) result.add(variant); } - if (t.isCDoublePointerType() || t.isCVoidPointerType()) { + if (cfg.voidPointerExpansionToDouble()) { variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.doubleArrayClass)); if (! result.contains(variant)) result.add(variant); } } - // NIO variants for void* and other C primitive pointer types + + // NIO variant for void* C primitive pointer type if (!cfg.noNio(mb.getCSymbol().getName())) { if (t.isCVoidPointerType()) { variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOBufferClass()); @@ -1297,6 +1331,7 @@ public class JavaEmitter implements GlueEmitter { } } + // NIO variants for non-void* C primitive pointer types 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()) { @@ -1331,6 +1366,7 @@ public class JavaEmitter implements GlueEmitter { } } } + if (mb.getJavaReturnType().isCPrimitivePointerType()) { MethodBinding variant = null; if (mb.getJavaReturnType().isCVoidPointerType()) { @@ -1365,6 +1401,12 @@ public class JavaEmitter implements GlueEmitter { } // Honor the flattenNIOVariants directive in the configuration file + // FlattenNIOVariants <boolean> + // true: If there are multiple arguments in a method signature that map + // to NIO buffer, do not pair an NIO buffer argument with a primitive + // array argument + // false: Allow cross-pairing of nio and primitive array arguments in a + // single method signature. if (cfg.flattenNIOVariants()) { i = 0; while (i < result.size()) { |