aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/JavaEmitter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-07-10 16:39:36 +0200
committerSven Gothel <[email protected]>2023-07-10 16:39:36 +0200
commit0ea6688e41c31b0e2c8dba73582c935562885b44 (patch)
tree4e4b3c96e99e7552f4cf481df0ab88523048e185 /src/java/com/jogamp/gluegen/JavaEmitter.java
parent63ed5f7676bc46ee03db1a6d27c5ce86fcf6a597 (diff)
GlueGen JavaCallback: Add optional custom 'Callback-UserParamClass` for non-compound `UserParam` types to have more clarity in resulting API
Diffstat (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java')
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 88cff27..576e9bc 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -1474,14 +1474,15 @@ public class JavaEmitter implements GlueEmitter {
}
final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, jcbi0.staticCBMethodSignature,
funcType, jcbi0.cbFuncBinding, jcbi0.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices,
- jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName);
+ jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices,
+ jcbd.userParamClassName, jcbd.customKeyClassName);
cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1);
LOG.log(INFO, "JavaCallbackInfo: Reusing {0} -> {1}", jcbd.setFuncName, jcbi0);
} else {
final StringBuilder cbMethodSignature = new StringBuilder();
javaUnit.emitln(" /** JavaCallback interface: "+jcbd.cbFuncTypeName+" -> "+funcType.toString(jcbd.cbFuncTypeName, false, true)+" */");
javaUnit.emitln(" public static interface "+cbSimpleClazzName+" {");
- final List<MethodBinding> mbs = generateFunctionInterfaceCode(javaUnit, funcSym, jcbd.cbFuncUserParamIdx, cbMethodSignature);
+ final List<MethodBinding> mbs = generateFunctionInterfaceCode(javaUnit, funcSym, jcbd, cbMethodSignature);
javaUnit.emitln(" }");
javaUnit.emitln();
if( 1 != mbs.size() ) {
@@ -1494,7 +1495,8 @@ public class JavaEmitter implements GlueEmitter {
}
final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, cbMethodSignature.toString(),
funcType, cbFuncBinding, jcbd.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices,
- jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName);
+ jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices,
+ jcbd.userParamClassName, jcbd.customKeyClassName);
cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1);
javaCallbackInterfaceMap.put(cbFQClazzName, jcbi1);
LOG.log(INFO, "JavaCallbackInfo: Added {0} -> {1}", jcbd.setFuncName, jcbi1);
@@ -1502,15 +1504,23 @@ public class JavaEmitter implements GlueEmitter {
}
private final Map<String, JavaCallbackInfo> javaCallbackInterfaceMap = new HashMap<String, JavaCallbackInfo>();
- private List<MethodBinding> generateFunctionInterfaceCode(final JavaCodeUnit javaUnit, final FunctionSymbol funcSym, final int userParamIdx, final StringBuilder methodSignature) {
+ private List<MethodBinding> generateFunctionInterfaceCode(final JavaCodeUnit javaUnit, final FunctionSymbol funcSym, final JavaCallbackDef jcbd, final StringBuilder methodSignature) {
// Emit method call and associated native code
MethodBinding mb = bindFunction(funcSym, true /* forInterface */, machDescJava, null, null);
// Replace optional userParam argument 'void*' with Object
+ final int userParamIdx = jcbd.cbFuncUserParamIdx;
if( 0 <= userParamIdx && userParamIdx < mb.getNumArguments() ) {
final JavaType t = mb.getJavaArgumentType(userParamIdx);
if ( t.isCVoidPointerType() ) {
- mb = mb.replaceJavaArgumentType(userParamIdx, JavaType.forObjectClass());
+ final JavaType mappedType;
+ if( null != jcbd.userParamClassName ) {
+ mappedType = JavaType.createForNamedClass( jcbd.userParamClassName );
+ mb = mb.replaceJavaArgumentType(userParamIdx, JavaType.forObjectClass());
+ } else {
+ mappedType = JavaType.forObjectClass();
+ }
+ mb = mb.replaceJavaArgumentType(userParamIdx, mappedType);
}
}
// Produce the method signature
@@ -3124,6 +3134,8 @@ public class JavaEmitter implements GlueEmitter {
if( cArgType.getTargetType().isVoid() ) {
if( jcbi.cbFuncUserParamType.isCompound() ) {
mappedType = JavaType.createForClass(long.class);
+ } else if( null != jcbi.userParamClassName ) {
+ mappedType = JavaType.createForNamedClass( jcbi.userParamClassName );
} else {
mappedType = JavaType.forObjectClass();
}