aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/JavaEmitter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java')
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java71
1 files changed, 49 insertions, 22 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 8310cda..fb310a9 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -465,9 +465,11 @@ public class JavaEmitter implements GlueEmitter {
final boolean isUnimplemented = cfg.isUnimplemented(cSymbol);
final List<String> prologue = cfg.javaPrologueForMethod(binding, false, false);
final List<String> epilogue = cfg.javaEpilogueForMethod(binding, false, false);
+ final boolean needsJavaCallbackCode = cfg.requiresJavaCallbackCode( binding.getName() );
final boolean needsBody = isUnimplemented ||
binding.needsNIOWrappingOrUnwrapping() ||
binding.signatureUsesJavaPrimitiveArrays() ||
+ needsJavaCallbackCode ||
null != prologue ||
null != epilogue;
@@ -531,6 +533,7 @@ public class JavaEmitter implements GlueEmitter {
final boolean hasPrologueOrEpilogue =
cfg.javaPrologueForMethod(binding, false, false) != null ||
cfg.javaEpilogueForMethod(binding, false, false) != null ;
+ final boolean needsJavaCallbackCode = cfg.requiresJavaCallbackCode( binding.getName() );
if ( !cfg.isUnimplemented( cSymbol ) ) {
// If we already generated a public native entry point for this
@@ -541,7 +544,7 @@ public class JavaEmitter implements GlueEmitter {
// the private native entry point for it along with the version
// taking only NIO buffers
if ( !binding.signatureUsesJavaPrimitiveArrays() &&
- ( binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue )
+ ( binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue || needsJavaCallbackCode )
)
{
final CodeUnit unit = (cfg.allStatic() ? javaUnit() : javaImplUnit());
@@ -588,7 +591,7 @@ public class JavaEmitter implements GlueEmitter {
cfg.implClassName(),
true, // NOTE: we always disambiguate with a suffix now, so this is optional
cfg.allStatic(),
- (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue),
+ (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue || needsJavaCallbackCode),
!cfg.useNIODirectOnly(binding.getName()),
machDescJava, getConfig());
prepCEmitter(binding.getName(), binding.getJavaReturnType(), cEmitter);
@@ -1140,6 +1143,20 @@ public class JavaEmitter implements GlueEmitter {
field + "\" in type \"" + structCTypeName + "\")",
fieldType.getASTLocusTag());
}
+ if( !immutableField && !fieldType.isConst() ) {
+ // Setter
+ generateSetterSignature(javaUnit, MethodAccess.PUBLIC, false, false, fieldName, fieldType, Ownership.Parent, containingJTypeName, CodeGenUtils.capitalizeString(fieldName), null, fieldType.getName(), null, false, false, null, null, null);
+ javaUnit.emitln(" {");
+ javaUnit.emitln(" final ByteBuffer bb = src.getBuffer();");
+ javaUnit.emitln(" final int size = "+fieldName+"_size[mdIdx];");
+ javaUnit.emitln(" final byte[] content = new byte[size];");
+ javaUnit.emitln(" bb.get(content, 0, size);");
+ javaUnit.emitln(" accessor.setBytesAt("+fieldName+"_offset[mdIdx], content);");
+ javaUnit.emitln(" return this;");
+ javaUnit.emitln(" }");
+ javaUnit.emitln();
+ }
+ // Getter
generateGetterSignature(javaUnit, false, false, fieldName, fieldType, Ownership.Parent, fieldType.getName(), CodeGenUtils.capitalizeString(fieldName), null, false, false, null, null);
javaUnit.emitln(" {");
javaUnit.emitln(" return " + fieldType.getName() + ".create( accessor.slice( " +
@@ -1528,11 +1545,11 @@ public class JavaEmitter implements GlueEmitter {
methodSignature.append("(");
for(int i=0; i<mb.getNumArguments(); ++i) {
final JavaType t = mb.getJavaArgumentType(i);
- methodSignature.append(t.getDescriptor());
+ methodSignature.append(t.getDescriptor(cfg));
}
methodSignature.append(")");
final JavaType rt = mb.getJavaReturnType();
- methodSignature.append(rt.getDescriptor());
+ methodSignature.append(rt.getDescriptor(cfg));
}
// JavaTypes representing C pointers in the initial
@@ -3131,8 +3148,7 @@ public class JavaEmitter implements GlueEmitter {
final Type cArgType = sym.getArgumentType(i);
final String cArgName = sym.getArgumentName(i);
JavaType mappedType = typeToJavaType(cArgType, curMachDesc);
- // System.out.println("C arg type -> \"" + cArgType + "\"" );
- // System.out.println(" Java -> \"" + mappedType + "\"" );
+ int mapMode = 0;
if( null != jcbi && jcbi.cbFuncTypeName.equals( cArgType.getName() ) &&
( !jcbi.setFuncProcessed || i == jcbi.setFuncCBParamIdx ) )
@@ -3140,47 +3156,58 @@ public class JavaEmitter implements GlueEmitter {
// Replace JavaCallback type with generated interface name
jcbiSetFuncCBParamIdx=i;
mappedType = JavaType.createForNamedClass( jcbi.cbFQClazzName );
+ mapMode = 10;
} else if( null != jcbi && i == jcbi.setFuncUserParamIdx && cArgType.isPointer() ) {
// Replace userParam argument '<userParamType>*' if 'void*' with Object
if( cArgType.getTargetType().isVoid() ) {
if( jcbi.cbFuncUserParamType.isCompound() ) {
mappedType = JavaType.createForClass(long.class);
+ mapMode = 20;
} else if( null != jcbi.userParamClassName ) {
mappedType = JavaType.createForNamedClass( jcbi.userParamClassName );
+ mapMode = 21;
} else {
mappedType = JavaType.forObjectClass();
+ mapMode = 22;
}
+ } else {
+ // fallthrough intended
}
- } else if ( stringArgIndices != null && stringArgIndices.contains(i) ) {
+ }
+ if ( 0 == mapMode && stringArgIndices != null && stringArgIndices.contains(i) ) {
// Take into account any ArgumentIsString configuration directives that apply
// System.out.println("Forcing conversion of " + binding.getName() + " arg #" + i + " from byte[] to String ");
- if (mappedType.isCVoidPointerType() ||
- mappedType.isCCharPointerType() ||
- mappedType.isCShortPointerType() ||
- mappedType.isNIOPointerBuffer() ||
- (mappedType.isArray() &&
- (mappedType.getJavaClass() == ArrayTypes.byteBufferArrayClass) ||
- (mappedType.getJavaClass() == ArrayTypes.shortBufferArrayClass))) {
+ if ( mappedType.isCVoidPointerType() ||
+ mappedType.isCCharPointerType() ||
+ mappedType.isCShortPointerType() ||
+ mappedType.isNIOPointerBuffer() ||
+ ( mappedType.isArray() &&
+ ( mappedType.getJavaClass() == ArrayTypes.byteBufferArrayClass ) ||
+ ( mappedType.getJavaClass() == ArrayTypes.shortBufferArrayClass ) ) )
+ {
// convert mapped type from:
// void*, byte[], and short[] to String
// ByteBuffer[] and ShortBuffer[] to String[]
final boolean pascalString = cfg.pascalStringLengthIndex(sym, i) >= 0;
if (mappedType.isArray() || mappedType.isNIOPointerBuffer()) {
mappedType = javaStringType(ArrayTypes.stringArrayClass, pascalString);
+ mapMode = 30;
} else {
mappedType = javaStringType(String.class, pascalString);
+ mapMode = 31;
}
- }
- else {
- throw new GlueGenException(
- "Cannot apply ArgumentIsString configuration directive to " +
- "argument " + i + " of \"" + sym + "\": argument type is not " +
- "a \"void*\", \"char *\", \"short *\", \"char**\", or \"short**\" equivalent",
- sym.getASTLocusTag());
+ } else {
+ mapMode = 99;
+ throw new GlueGenException(
+ "Cannot apply ArgumentIsString configuration directive to " +
+ "argument " + i + " of \"" + sym + "\": argument type is not " +
+ "a \"void*\", \"char *\", \"short *\", \"char**\", or \"short**\" equivalent",
+ sym.getASTLocusTag());
}
}
javaArgumentTypes.add(mappedType);
- //System.out.println("During binding of [" + sym + "], added mapping from C type: " + cArgType + " to Java type: " + mappedType);
+ LOG.log(INFO, "BindFunc: {0}: added mapping ({1}) for {2} from C type: {3} to Java type: {4}",
+ sym.getName(), mapMode, cArgName, cArgType, mappedType);
}
if( null != jcbi ) {
jcbi.setFuncProcessed(sym.getType(), jcbiSetFuncCBParamIdx);