summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-25 10:16:01 +0200
committerSven Gothel <[email protected]>2014-06-25 10:16:01 +0200
commit9ee44e1a289ecbac024662dd5a2ffc42e8add023 (patch)
tree2946a8bbf78e2fd26d088c35ee24cde3e51648e0 /src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
parent6cb643671578aa912d16dd17e773d92f4667118b (diff)
Bug 1025 - GlueGen: Add accessor for compound fields of type array, pointer and string (code generation)
Enhance compound access as delivered by Bug 1022, to also generate accessors (getter and setter) for array, pointer and string types. Allow configuration of array length either via their internal size (c-header) or config 'ReturnedArrayLength'. 'ReturnedArrayLength' allows specifying a java expression. Canonical field names of compounds are _now_ specified as follows for configuration entries: COMPOUND.FIELD e.g. StructA.fieldB Also allow configuration of pointer fields to be treated as referenced arrays via 'ReturnedArrayLength'. Further, allow specifying 'pointer fields' as String values via 'ReturnsString' configuration. ++++ Implementation details: - handle above described accessor features - enhance JavaDoc for generated accessors - generate native JNI compound and string accessor on demand - encapsule accessor code generation in their own methods - enhance exception messages - enhance type verbosity in debug mode - verbose debug output via GlueGen.debug() Tests: - Features covered by test1.[ch] and Test1p1JavaEmitter and Test1p2ProcAddressEmitter - Validated compilation and unit tests for modules: - joal - jogl (minor config changes req.) - jocl (minor config changes req.)
Diffstat (limited to 'src/java/com/jogamp/gluegen/CMethodBindingEmitter.java')
-rw-r--r--src/java/com/jogamp/gluegen/CMethodBindingEmitter.java37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
index 0e373d0..1c9d043 100644
--- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
@@ -909,7 +909,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
writer.print(CMethodBindingEmitter.cThisArgumentName());
} else {
writer.print("(");
- Type cArgType = binding.getCArgumentType(i);
+ final Type cArgType = binding.getCArgumentType(i);
boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType);
boolean needsArrayOffset = !needsDataCopy && (
javaArgType.isArray() ||
@@ -921,8 +921,8 @@ public class CMethodBindingEmitter extends FunctionEmitter {
// if this is a pointer to an unsigned type, add unsigned to the name to avoid compiler warnings
if(cArgType.isPointer()) {
- Type typeLast = ((PointerType)cArgType).getLastTargetType();
- if(typeLast.isInt() && (((IntType)typeLast).isPrimitiveUnsigned())) {
+ final Type baseType = cArgType.getBaseElementType();
+ if(baseType.isInt() && (((IntType)baseType).isPrimitiveUnsigned())) {
writer.print("unsigned ");
}
}
@@ -955,8 +955,18 @@ public class CMethodBindingEmitter extends FunctionEmitter {
return binding.getNumArguments();
}
- protected void emitBodyCallCFunction(PrintWriter writer) {
+ private boolean isCStructFunctionPointer = false;
+
+ /**
+ * If method originates from a struct, see {@link MethodBinding#hasContainingType()},
+ * it can either purposed to call a native static function (default)
+ * or a struct's function pointer.
+ */
+ protected void setIsCStructFunctionPointer(final boolean v) {
+ isCStructFunctionPointer = v;
+ }
+ protected void emitBodyCallCFunction(PrintWriter writer) {
// Make the call to the actual C function
writer.print(" ");
@@ -967,7 +977,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
if (!cReturnType.isVoid()) {
writer.print("_res = ");
}
- if (binding.hasContainingType()) {
+ if ( isCStructFunctionPointer && binding.hasContainingType() ) {
// Call through function pointer
writer.print(CMethodBindingEmitter.cThisArgumentName() + "->");
}
@@ -1019,8 +1029,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
// See whether capacity has been specified
if (returnValueCapacityExpression != null) {
- writer.print(
- returnValueCapacityExpression.format(argumentNameArray()));
+ writer.print( returnValueCapacityExpression.format( argumentNameArray() ) );
} else {
if (cReturnType.isPointer() &&
cReturnType.asPointer().getTargetType().isCompound()) {
@@ -1030,7 +1039,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
"for function \"" + binding + "\": " +
"Structs to be emitted should have been laid out by this point " +
"(type " + cReturnType.asPointer().getTargetType().getName() + " / " +
- cReturnType.asPointer().getTargetType() + " was not)"
+ cReturnType.asPointer().getTargetType() + " was not) for "+binding
);
}
}
@@ -1073,7 +1082,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
throw new RuntimeException(
"Could not emit native code for function \"" + binding +
- "\": array return values for non-char types not implemented yet");
+ "\": array return values for non-char types not implemented yet, for "+binding);
// FIXME: This is approximately what will be required here
//
@@ -1095,8 +1104,8 @@ public class CMethodBindingEmitter extends FunctionEmitter {
//writer.print(arrayRes);
//writer.println(";");
} else {
- System.err.print("Unhandled return type: "+javaReturnType.getDumpString());
- throw new RuntimeException("Unhandled return type");
+ System.err.print("Unhandled return type: "+javaReturnType.getDebugString());
+ throw new RuntimeException("Unhandled return type: "+javaReturnType.getDebugString()+" for "+binding);
}
}
}
@@ -1474,11 +1483,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
}
protected String byteOffsetArgName(int i) {
- return byteOffsetArgName(binding.getArgumentName(i));
- }
-
- protected String byteOffsetArgName(String s) {
- return s + "_byte_offset";
+ return JavaMethodBindingEmitter.byteOffsetArgName(binding.getArgumentName(i));
}
protected String isNIOArgName(int i) {