diff options
Diffstat (limited to 'src/java/com')
4 files changed, 86 insertions, 92 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index 114f091..23c2b95 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -444,7 +444,6 @@ public class CMethodBindingEmitter extends FunctionEmitter { Type cReturnType = binding.getCReturnType(); JavaType javaReturnType = binding.getJavaReturnType(); - String capitalizedComponentType = null; if (!cReturnType.isVoid()) { writer.print(" "); // Note we must respect const/volatile for return argument @@ -472,8 +471,6 @@ public class CMethodBindingEmitter extends FunctionEmitter { } String javaTypeName = componentType.getName(); - capitalizedComponentType = - "" + Character.toUpperCase(javaTypeName.charAt(0)) + javaTypeName.substring(1); String javaArrayTypeName = "j" + javaTypeName + "Array"; writer.print(" "); writer.print(javaArrayTypeName); @@ -567,22 +564,6 @@ public class CMethodBindingEmitter extends FunctionEmitter { null); } - for (int i = 0; i < binding.getNumArguments(); i++) { - JavaType type = binding.getJavaArgumentType(i); - if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { - continue; - } - - if (type.isCompoundTypeWrapper() || - (type.isNIOBuffer() && !forIndirectBufferAndArrayImplementation)) { - String javaArgName = binding.getArgumentName(i); - emitPointerConversion(writer, binding, type, - binding.getCArgumentType(i), javaArgName, - pointerConversionArgumentName(javaArgName), - byteOffsetArgName(i)); - } - } - // Convert all arrays to pointers, and get UTF-8 versions of jstring args for (int i = 0; i < binding.getNumArguments(); i++) { JavaType javaArgType = binding.getJavaArgumentType(i); @@ -592,9 +573,15 @@ public class CMethodBindingEmitter extends FunctionEmitter { } String javaArgName = binding.getArgumentName(i); - if (javaArgType.isArray() || - (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation) || - javaArgType.isArrayOfCompoundTypeWrappers()) { + if (javaArgType.isCompoundTypeWrapper() || + (javaArgType.isNIOBuffer() && !forIndirectBufferAndArrayImplementation ) ) { + emitPointerConversion(writer, binding, javaArgType, + binding.getCArgumentType(i), javaArgName, + pointerConversionArgumentName(javaArgName), + byteOffsetArgName(i)); + } else if (javaArgType.isArray() || + javaArgType.isArrayOfCompoundTypeWrappers() || + ( javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation ) ) { boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType); writer.println(" if ( NULL != " + javaArgName + " ) {"); @@ -786,7 +773,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { String convName = pointerConversionArgumentName(javaArgName); if (!needsDataCopy) { - writer.println(" if ( NULL != " + javaArgName + " && JNI_FALSE == " + isNIOArgName(i) + " ) {"); + writer.println(" if ( JNI_FALSE == " + isNIOArgName(i) + " && NULL != " + javaArgName + " ) {"); // Release array final String modeFlag = isConstPtr(cArgType) || isConstPtrPtr(cArgType) ? "JNI_ABORT" : "0" ; @@ -1052,7 +1039,6 @@ public class CMethodBindingEmitter extends FunctionEmitter { } else { pointerType = retType.asArray().getElementType(); } - Type baseType = pointerType.asPointer().getTargetType(); writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx + ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], sizeof(" + pointerType.getName() + ")));"); writer.println(" }"); diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 87d8978..d1cb46a 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -147,10 +147,10 @@ public class JavaConfiguration { private Set<Pattern> ignoreNots = new HashSet<Pattern>(); private Set<Pattern> unignores = new HashSet<Pattern>(); private Set<Pattern> unimplemented = new HashSet<Pattern>(); - private boolean forceNioOnly4All = false; - private Set<String> nioOnly = new HashSet<String>(); - private boolean forceNioDirectOnly4All = false; - private Set<String> nioDirectOnly = new HashSet<String>(); + private boolean forceUseNIOOnly4All = false; + private Set<String> useNIOOnly = new HashSet<String>(); + private boolean forceUseNIODirectOnly4All = false; + private Set<String> useNIODirectOnly = new HashSet<String>(); private Set<String> manuallyImplement = new HashSet<String>(); private Map<String, List<String>> customJavaCode = new HashMap<String, List<String>>(); private Map<String, List<String>> classJavadoc = new HashMap<String, List<String>>(); @@ -502,25 +502,28 @@ public class JavaConfiguration { return argumentsAreString.get(functionName); } - public boolean isForceNioOnly4All() { return forceNioOnly4All; } + public boolean isForceUsingNIOOnly4All() { return forceUseNIOOnly4All; } - public void addNioOnly(String fname ) { - nioOnly.add(fname); + public void addUseNIOOnly(String fname ) { + useNIOOnly.add(fname); } - public boolean nioOnly(String functionName) { - return forceNioOnly4All || nioOnly.contains(functionName); + /** Returns true if the given function should only create a java.nio + variant, and no array variants, for <code>void*</code> and other + C primitive pointers. NIO only still allows usage of array backed not direct Buffers. */ + public boolean useNIOOnly(String functionName) { + return useNIODirectOnly(functionName) || forceUseNIOOnly4All || useNIOOnly.contains(functionName); } - public boolean isForceNioDirectOnly4All() { return forceNioDirectOnly4All; } - - public void addNioDirectOnly(String fname ) { - nioDirectOnly.add(fname); + public void addUseNIODirectOnly(String fname ) { + useNIODirectOnly.add(fname); } /** Returns true if the given function should only create a java.nio variant, and no array variants, for <code>void*</code> and other - C primitive pointers. */ - public boolean nioDirectOnly(String functionName) { - return forceNioDirectOnly4All || nioDirectOnly.contains(functionName); + C primitive pointers. NIO direct only does only allow direct Buffers. + Implies useNIOOnly ! + */ + public boolean useNIODirectOnly(String functionName) { + return forceUseNIODirectOnly4All || useNIODirectOnly.contains(functionName); } /** Returns true if the glue code for the given function will be @@ -961,19 +964,19 @@ public class JavaConfiguration { readClassJavadoc(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop // because readClassJavadoc changes them. - } else if (cmd.equalsIgnoreCase("NioOnly")) { - String funcName = readString("NioOnly", tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("NIOOnly")) { + String funcName = readString("NIOOnly", tok, filename, lineNo); if(funcName.equals("__ALL__")) { - forceNioOnly4All=true; + forceUseNIOOnly4All=true; } else { - addNioOnly( funcName ); + addUseNIOOnly( funcName ); } - } else if (cmd.equalsIgnoreCase("NioDirectOnly")) { - String funcName = readString("NioDirectOnly", tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("NIODirectOnly")) { + String funcName = readString("NIODirectOnly", tok, filename, lineNo); if(funcName.equals("__ALL__")) { - forceNioDirectOnly4All=true; + forceUseNIODirectOnly4All=true; } else { - addNioDirectOnly( funcName ); + addUseNIODirectOnly( funcName ); } } else if (cmd.equalsIgnoreCase("EmitStruct")) { forcedStructs.add(readString("EmitStruct", tok, filename, lineNo)); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 7ab3aca..99a5796 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -72,7 +72,6 @@ public class JavaEmitter implements GlueEmitter { private StructLayout layout; private TypeDictionary typedefDictionary; - private TypeDictionary structDictionary; private Map<Type, Type> canonMap; protected JavaConfiguration cfg; @@ -196,12 +195,12 @@ public class JavaEmitter implements GlueEmitter { parseValue = value; } //System.err.println("parsing " + value + " as long w/ radix " + radix); - long longVal = Long.parseLong(parseValue, radix); + Long.parseLong(parseValue, radix); return radix; } catch (NumberFormatException e) { try { // see if it's a double or float - double dVal = Double.parseDouble(value); + Double.parseDouble(value); return 10; } catch (NumberFormatException e2) { throw new RuntimeException( @@ -376,7 +375,6 @@ public class JavaEmitter implements GlueEmitter { Map<Type, Type> canonMap) throws Exception { this.typedefDictionary = typedefDictionary; - this.structDictionary = structDictionary; this.canonMap = canonMap; if ((cfg.allStatic() || cfg.emitInterface()) && !cfg.structsOnly()) { @@ -498,7 +496,8 @@ public class JavaEmitter implements GlueEmitter { !signatureOnly && needsBody, cfg.tagNativeBinding(), false, - cfg.nioDirectOnly(binding.getName()), + cfg.useNIOOnly(binding.getName()), + cfg.useNIODirectOnly(binding.getName()), false, false, false, @@ -564,7 +563,8 @@ public class JavaEmitter implements GlueEmitter { false, cfg.tagNativeBinding(), true, - cfg.nioDirectOnly(binding.getName()), + cfg.useNIOOnly(binding.getName()), + cfg.useNIODirectOnly(binding.getName()), true, true, false, @@ -599,7 +599,7 @@ public class JavaEmitter implements GlueEmitter { true, // NOTE: we always disambiguate with a suffix now, so this is optional cfg.allStatic(), (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue), - !cfg.nioDirectOnly(binding.getName()), + !cfg.useNIODirectOnly(binding.getName()), machDescJava); prepCEmitter(binding, cEmitter); allEmitters.add(cEmitter); @@ -751,7 +751,6 @@ public class JavaEmitter implements GlueEmitter { TypeDictionary structDictionary, Map<Type, Type> canonMap) throws Exception { this.typedefDictionary = typedefDictionary; - this.structDictionary = structDictionary; this.canonMap = canonMap; } @@ -964,6 +963,7 @@ public class JavaEmitter implements GlueEmitter { cfg.tagNativeBinding(), false, true, // FIXME: should unify this with the general emission code + true, // FIXME: should unify this with the general emission code false, false, // FIXME: should unify this with the general emission code false, // FIXME: should unify this with the general emission code @@ -983,6 +983,7 @@ public class JavaEmitter implements GlueEmitter { cfg.tagNativeBinding(), true, true, // FIXME: should unify this with the general emission code + true, // FIXME: should unify this with the general emission code true, true, // FIXME: should unify this with the general emission code false, // FIXME: should unify this with the general emission code @@ -1560,8 +1561,8 @@ public class JavaEmitter implements GlueEmitter { CodeGenUtils.EmissionCallback docEmitter = new CodeGenUtils.EmissionCallback() { public void emit(PrintWriter w) { - for (Iterator iter = intfDocs.iterator(); iter.hasNext(); ) { - w.println((String) iter.next()); + for (Iterator<String> iter = intfDocs.iterator(); iter.hasNext(); ) { + w.println(iter.next()); } } }; @@ -1590,8 +1591,8 @@ public class JavaEmitter implements GlueEmitter { CodeGenUtils.EmissionCallback docEmitter = new CodeGenUtils.EmissionCallback() { public void emit(PrintWriter w) { - for (Iterator iter = implDocs.iterator(); iter.hasNext(); ) { - w.println((String) iter.next()); + for (Iterator<String> iter = implDocs.iterator(); iter.hasNext(); ) { + w.println(iter.next()); } } }; @@ -1867,7 +1868,7 @@ public class JavaEmitter implements GlueEmitter { // FIXME: should add new configuration flag for this if (canProduceArrayVariant[0] && (binding.signatureUsesCPrimitivePointers() || binding.signatureUsesCArrays()) && - !cfg.nioDirectOnly(binding.getName()) && !cfg.nioOnly(binding.getName())) { + !cfg.useNIOOnly(binding.getName()) ) { result.add(lowerMethodBindingPointerTypes(binding, true, null)); } } else { @@ -1877,10 +1878,6 @@ public class JavaEmitter implements GlueEmitter { return result; } - private String resultName() { - return "_res"; - } - private Type canonicalize(Type t) { Type res = canonMap.get(t); if (res != null) { diff --git a/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java index f7b1466..bd99486 100644 --- a/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java @@ -72,7 +72,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { protected boolean emitBody; protected boolean eraseBufferAndArrayTypes; - protected boolean directNIOOnly; + protected boolean useNIOOnly; + protected boolean useNIODirectOnly; protected boolean forImplementingMethodCall; protected boolean forDirectBufferImplementation; protected boolean forIndirectBufferAndArrayImplementation; @@ -106,7 +107,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { boolean emitBody, boolean tagNativeBinding, boolean eraseBufferAndArrayTypes, - boolean directNIOOnly, + boolean useNIOOnly, + boolean useNIODirectOnly, boolean forImplementingMethodCall, boolean forDirectBufferImplementation, boolean forIndirectBufferAndArrayImplementation, @@ -120,7 +122,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { this.emitBody = emitBody; this.tagNativeBinding = tagNativeBinding; this.eraseBufferAndArrayTypes = eraseBufferAndArrayTypes; - this.directNIOOnly = directNIOOnly; + this.useNIOOnly = useNIOOnly; + this.useNIODirectOnly = useNIODirectOnly; this.forImplementingMethodCall = forImplementingMethodCall; this.forDirectBufferImplementation = forDirectBufferImplementation; this.forIndirectBufferAndArrayImplementation = forIndirectBufferAndArrayImplementation; @@ -141,7 +144,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { emitBody = arg.emitBody; tagNativeBinding = arg.tagNativeBinding; eraseBufferAndArrayTypes = arg.eraseBufferAndArrayTypes; - directNIOOnly = arg.directNIOOnly; + useNIOOnly = arg.useNIOOnly; + useNIODirectOnly = arg.useNIODirectOnly; forImplementingMethodCall = arg.forImplementingMethodCall; forDirectBufferImplementation = arg.forDirectBufferImplementation; forIndirectBufferAndArrayImplementation = arg.forIndirectBufferAndArrayImplementation; @@ -352,7 +356,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { if (forDirectBufferImplementation || forIndirectBufferAndArrayImplementation) { if (type.isNIOBuffer()) { writer.print(", int " + byteOffsetArgName(i)); - if(!directNIOOnly) { + if(!useNIODirectOnly) { writer.print(", boolean " + isNIOArgName(i)); } } else if (type.isNIOBufferArray()) { @@ -362,8 +366,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { // Add offset argument after each primitive array if (type.isPrimitiveArray()) { - if(directNIOOnly) { - throw new RuntimeException("NIODirectOnly "+binding+" is set, but "+getArgumentName(i)+" is a primitive array"); + if(useNIOOnly) { + throw new RuntimeException("NIO[Direct]Only "+binding+" is set, but "+getArgumentName(i)+" is a primitive array"); } writer.print(", int " + offsetArgName(i)); } @@ -373,7 +377,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { protected String getImplMethodName() { - return binding.getName() + ( directNIOOnly ? "0" : "1" ); + return binding.getName() + ( useNIODirectOnly ? "0" : "1" ); } protected String byteOffsetArgName(int i) { @@ -456,19 +460,18 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { } else { JavaType javaType = binding.getJavaArgumentType(i); if (javaType.isNIOBuffer()) { - if (directNIOOnly) { + if (useNIODirectOnly) { writer.println(" if (!Buffers.isDirect(" + getArgumentName(i) + "))"); writer.println(" throw new " + getRuntimeExceptionType() + "(\"Argument \\\"" + - getArgumentName(i) + "\\\" was not a direct buffer\");"); + getArgumentName(i) + "\\\" is not a direct buffer\");"); } else { - writer.print(" boolean " + isNIOArgName(i) + " = "); - writer.println(getArgumentName(i) + " != null && Buffers.isDirect(" + getArgumentName(i) + ");"); + writer.println(" final boolean " + isNIOArgName(i) + " = Buffers.isDirect(" + getArgumentName(i) + ");"); } } else if (javaType.isNIOBufferArray()) { // All buffers passed down in an array of NIO buffers must be direct String argName = getArgumentName(i); String arrayName = byteOffsetArrayArgName(i); - writer.println(" int[] " + arrayName + " = new int[" + argName + ".length];"); + writer.println(" final int[] " + arrayName + " = new int[" + argName + ".length];"); // Check direct buffer properties of all buffers within writer.println(" if (" + argName + " != null) {"); writer.println(" for (int _ctr = 0; _ctr < " + argName + ".length; _ctr++) {"); @@ -504,7 +507,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { if (javaType.isArrayOfCompoundTypeWrappers()) { String argName = getArgumentName(i); String tempArrayName = argName + COMPOUND_ARRAY_SUFFIX; - writer.println(" ByteBuffer[] " + tempArrayName + " = new ByteBuffer[" + argName + ".length];"); + writer.println(" final ByteBuffer[] " + tempArrayName + " = new ByteBuffer[" + argName + ".length];"); writer.println(" for (int _ctr = 0; _ctr < + " + argName + ".length; _ctr++) {"); writer.println(" " + javaType.getName() + " _tmp = " + argName + "[_ctr];"); writer.println(" " + tempArrayName + "[_ctr] = ((_tmp == null) ? null : _tmp.getBuffer());"); @@ -530,13 +533,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { if (!returnType.isVoid()) { if (returnType.isCompoundTypeWrapper() || returnType.isNIOBuffer()) { - writer.println("ByteBuffer _res;"); + writer.println("final ByteBuffer _res;"); needsResultAssignment = true; } else if (returnType.isArrayOfCompoundTypeWrappers()) { - writer.println("ByteBuffer[] _res;"); + writer.println("final ByteBuffer[] _res;"); needsResultAssignment = true; } else if (((epilogue != null) && (epilogue.size() > 0)) || binding.signatureUsesArraysOfCompoundTypeWrappers()) { + writer.print("final "); emitReturnType(writer); writer.println(" _res;"); needsResultAssignment = true; @@ -597,14 +601,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { if (type.isNIOBuffer()) { if(type.isNIOPointerBuffer()) { - if (directNIOOnly) { + if (useNIODirectOnly) { writer.print( getArgumentName(i)+ " != null ? " + getArgumentName(i) + ".getBuffer() : null"); } else { writer.print( isNIOArgName(i) + " ? ( " + getArgumentName(i)+ " != null ? " + getArgumentName(i) + ".getBuffer() : null )"); writer.print( " : Buffers.getArray(" + getArgumentName(i) + ")" ); } } else { - if (directNIOOnly) { + if (useNIODirectOnly) { writer.print( getArgumentName(i) ); } else { writer.print( isNIOArgName(i) + " ? " + getArgumentName(i) + " : Buffers.getArray(" + getArgumentName(i) + ")" ); @@ -623,7 +627,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { } if (type.isNIOBuffer()) { - if (directNIOOnly) { + if (useNIODirectOnly) { writer.print( ", Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")"); } else { writer.print( ", " + isNIOArgName(i) + " ? Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")"); @@ -653,12 +657,12 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { } if (type.isNIOBuffer()) { - if (!directNIOOnly) { + if (!useNIODirectOnly) { writer.print( ", " + isNIOArgName(i) ); } } else if (type.isPrimitiveArray()) { - if (directNIOOnly) { - throw new RuntimeException("NIODirectOnly "+binding+" is set, but "+getArgumentName(i)+" is a primitive array"); + if (useNIOOnly) { + throw new RuntimeException("NIO[Direct]Only "+binding+" is set, but "+getArgumentName(i)+" is a primitive array"); } writer.print( ", false"); } @@ -715,14 +719,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { throw new RuntimeException("ReturnedArrayLength directive currently only supported for pointers to compound types " + "(error occurred while generating Java glue code for " + getName() + ")"); } - writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[" + expr + "];"); + writer.println(" final " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[" + expr + "];"); writer.println(" for (int _count = 0; _count < " + expr + "; _count++) {"); // Create temporary ByteBuffer slice // FIXME: probably need Type.getAlignedSize() for arrays of // compound types (rounding up to machine-dependent alignment) writer.println(" _res.position(_count * " + getReturnTypeString(true) + ".size());"); writer.println(" _res.limit ((1 + _count) * " + getReturnTypeString(true) + ".size());"); - writer.println(" ByteBuffer _tmp = _res.slice();"); + writer.println(" final ByteBuffer _tmp = _res.slice();"); writer.println(" Buffers.nativeOrder(_tmp);"); writer.println(" _res.position(0);"); writer.println(" _res.limit(_res.capacity());"); @@ -756,7 +760,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { } } else if (returnType.isArrayOfCompoundTypeWrappers()) { writer.println(" if (_res == null) return null;"); - writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];"); + writer.println(" final " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];"); writer.println(" for (int _count = 0; _count < _res.length; _count++) {"); writer.println(" _retarray[_count] = " + getReturnTypeString(true) + ".create(_res[_count]);"); writer.println(" }"); @@ -838,13 +842,17 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { writer.print(enumType.getEnumName(j)); } writer.println("</code>"); - } else if (directNIOOnly && javaType.isNIOBuffer()) { + } else if (javaType.isNIOBuffer()) { writer.println(); writer.print(emitter.getBaseIndentString()); writer.print(" "); writer.print("@param "); writer.print(getArgumentName(i)); - writer.print(" a direct {@link " + javaType.getName() + "}"); + if (useNIODirectOnly) { + writer.print(" a direct only {@link " + javaType.getName() + "}"); + } else { + writer.print(" a direct or array-backed {@link " + javaType.getName() + "}"); + } } } } |