diff options
Diffstat (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java')
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 6e79b6c..8ed269e 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -66,6 +66,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import jogamp.common.os.MachineDataInfoRuntime; @@ -359,7 +360,8 @@ public class JavaEmitter implements GlueEmitter { @Override public void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, - final Map<Type, Type> canonMap) throws Exception { + final Map<Type, Type> canonMap, + final List<FunctionSymbol> cFunctions) throws Exception { // this.typedefDictionary = typedefDictionary; this.canonMap = canonMap; @@ -371,7 +373,14 @@ public class JavaEmitter implements GlueEmitter { for(final JavaCallbackDef jcbd : javaCallbacks) { final Type funcPtr = typedefDictionary.get(jcbd.cbFuncTypeName); if( null != funcPtr && funcPtr.isFunctionPointer() ) { - generateJavaCallbackCode(jcbd, funcPtr.getTargetFunction()); + final Optional<FunctionSymbol> setter = cFunctions.stream() + .filter(cFunction -> jcbd.setFuncName.equals(cFunction.getName())) + .findFirst(); + if( setter.isPresent() ) { + generateJavaCallbackCode(jcbd, funcPtr.getTargetFunction()); + } else { + LOG.log(WARNING, "JavaCallback '{0}' setter not available", jcbd); + } } else { LOG.log(WARNING, "JavaCallback '{0}' function-pointer type not available", jcbd); } @@ -465,9 +474,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 +542,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 +553,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 +600,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); @@ -1874,11 +1886,22 @@ public class JavaEmitter implements GlueEmitter { if( !_constElemCount ) { // check for const length field if( elemCountExpr.startsWith("get") && elemCountExpr.endsWith("()") ) { - final String lenFieldName = CodeGenUtils.decapitalizeString( elemCountExpr.substring(3, elemCountExpr.length()-2) ); - final Field lenField = structCType.getField(lenFieldName); - if( null != lenField ) { - _constElemCount = lenField.getType().isConst(); + final String baseLenFieldName = elemCountExpr.substring(3, elemCountExpr.length()-2); + String lenFieldName = CodeGenUtils.decapitalizeString( baseLenFieldName ); + Field lenField = structCType.getField(lenFieldName); + if( null == lenField ) { + lenFieldName = baseLenFieldName; + lenField = structCType.getField(lenFieldName); + } + if( null == lenField ) { + throw new GlueGenException("Unable to creating array accessors for field \"" + + fqStructFieldName + "\", because elemCountExpr specify following getter \"" + + elemCountExpr + "\" and host structure doesn't contain following field \"" + + CodeGenUtils.decapitalizeString( baseLenFieldName ) + "\" or \"" + + baseLenFieldName + "\"", + fieldType.getASTLocusTag()); } + _constElemCount = lenField.getType().isConst(); LOG.log(INFO, structCType.getASTLocusTag(), unit.className+": elemCountExpr "+elemCountExpr+", lenFieldName "+lenFieldName+" -> "+lenField.toString()+", isConst "+_constElemCount); } |