diff options
Diffstat (limited to 'src/java/com/jogamp')
5 files changed, 115 insertions, 65 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 7969597..63f86e8 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -813,27 +813,32 @@ public class JavaConfiguration { public boolean shouldIgnoreInInterface(final AliasedSymbol symbol) { return shouldIgnoreInInterface_Int(symbol); } - private static boolean oneInSet(final Set<String> ignoreSymbols, final Set<String> symbols) { - if( null != ignoreSymbols && ignoreSymbols.size() > 0 && + public static <K,V> V oneInMap(final Map<K, V> map, final Set<K> symbols) { + if( null != map && map.size() > 0 && null != symbols && symbols.size() > 0 ) { - for(final String sym : symbols) { - if( ignoreSymbols.contains( sym ) ) { - return true; + for(final K sym : symbols) { + final V v = map.get(sym); + if( null != v ) { + return v; } } } - return false; + return null; } - /** private static boolean allInSet(final Set<String> ignoreSymbols, final Set<String> symbols) { - if( null != ignoreSymbols && ignoreSymbols.size() > 0 && - null != symbols && symbols.size() > 0 ) { - return ignoreSymbols.containsAll(symbols); + public static <K> boolean oneInSet(final Set<K> set1, final Set<K> set2) { + if( null != set1 && set1.size() > 0 && + null != set2 && set2.size() > 0 ) { + for(final K sym : set2) { + if( set1.contains( sym ) ) { + return true; + } + } } return false; - } */ - private static boolean onePatternMatch(final Pattern ignoreRegexp, final Set<String> symbols) { - if( null != ignoreRegexp && null != symbols && symbols.size() > 0 ) { - for(final String sym : symbols) { + } + private static boolean onePatternMatch(final Pattern ignoreRegexp, final Set<String> set) { + if( null != ignoreRegexp && null != set && set.size() > 0 ) { + for(final String sym : set) { final Matcher matcher = ignoreRegexp.matcher(sym); if (matcher.matches()) { return true; @@ -948,17 +953,16 @@ public class JavaConfiguration { /** Returns true if this function should be given a body which throws a run-time exception with an "unimplemented" message during glue code generation. */ - public boolean isUnimplemented(final String symbol) { - // Ok, the slow case. We need to check the entire table, in case the table - // contains an regular expression that matches the symbol. - for (final Pattern regexp : unimplemented) { - final Matcher matcher = regexp.matcher(symbol); - if (matcher.matches()) { - return true; + public boolean isUnimplemented(final AliasedSymbol symbol) { + // Ok, the slow case. We need to check the entire table, in case the table + // contains an regular expression that matches the symbol. + for (final Pattern unimplRegexp : unimplemented) { + final Matcher matcher = unimplRegexp.matcher(symbol.getName()); + if ( matcher.matches() || onePatternMatch(unimplRegexp, symbol.getAliasedNames()) ) { + return true; + } } - } - - return false; + return false; } /** diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index a66458b..9665182 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -563,7 +563,7 @@ public class JavaEmitter implements GlueEmitter { // It's possible we may not need a body even if signatureOnly is // set to false; for example, if the routine doesn't take any // arrays or buffers as arguments - final boolean isUnimplemented = cfg.isUnimplemented(binding.getName()); + final boolean isUnimplemented = cfg.isUnimplemented(binding.getCSymbol()); final List<String> prologue = cfg.javaPrologueForMethod(binding, false, false); final List<String> epilogue = cfg.javaEpilogueForMethod(binding, false, false); final boolean needsBody = isUnimplemented || @@ -633,7 +633,7 @@ public class JavaEmitter implements GlueEmitter { cfg.javaPrologueForMethod(binding, false, false) != null || cfg.javaEpilogueForMethod(binding, false, false) != null ; - if ( !cfg.isUnimplemented( binding.getName() ) ) { + if ( !cfg.isUnimplemented( binding.getCSymbol() ) ) { if( !requiresStaticInitialization ) { requiresStaticInitialization = binding.signatureRequiresStaticInitialization(); if( requiresStaticInitialization ) { diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java index 81aa96b..982e16d 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java @@ -85,6 +85,10 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { emitter.getConfiguration() ); + if( needsLocalTypedef && !callThroughProcAddress ) { + throw new IllegalArgumentException("needsLocalTypedef=true, but callThroughProcAddress=false for "+methodToWrap.toString()); + } + if (methodToWrap.getReturnValueCapacityExpression() != null) { setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression()); } diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressConfiguration.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressConfiguration.java index 0c5692b..50334c6 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressConfiguration.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressConfiguration.java @@ -38,7 +38,11 @@ */ package com.jogamp.gluegen.procaddress; +import static java.util.logging.Level.INFO; + import com.jogamp.gluegen.JavaConfiguration; +import com.jogamp.gluegen.cgram.types.AliasedSymbol; + import java.io.*; import java.text.*; import java.util.*; @@ -269,8 +273,15 @@ public class ProcAddressConfiguration extends JavaConfiguration { return tableClassName; } - public boolean skipProcAddressGen(final String name) { - return skipProcAddressGen.contains(name); + public boolean skipProcAddressGen(final AliasedSymbol symbol) { + if ( skipProcAddressGen.contains( symbol.getName() ) || + oneInSet(skipProcAddressGen, symbol.getAliasedNames()) + ) + { + LOG.log(INFO, "Skip ProcAddress: {0}", symbol.getAliasedString()); + return true; + } + return false; } public boolean isForceProcAddressGen4All() { @@ -298,9 +309,25 @@ public class ProcAddressConfiguration extends JavaConfiguration { return procAddressNameConverter.convert(funcName); } - public boolean forceProcAddressGen(final String funcName) { - return forceProcAddressGen4All || forceProcAddressGenSet.contains(funcName); + public boolean forceProcAddressGen(final AliasedSymbol symbol) { + if( forceProcAddressGen4All ) { + if(!forceProcAddressGen4AllOnce) { + forceProcAddressGen4AllOnce = true; + LOG.log(INFO, "Force ALL ProcAddress"); + } + return true; + } + + if ( forceProcAddressGenSet.contains( symbol.getName() ) || + oneInSet(forceProcAddressGenSet, symbol.getAliasedNames()) + ) + { + LOG.log(INFO, "Force ProcAddress: {0}", symbol.getAliasedString()); + return true; + } + return false; } + private static boolean forceProcAddressGen4AllOnce = false; public void addForceProcAddressGen(final String funcName) { forceProcAddressGen.add(funcName); @@ -311,11 +338,15 @@ public class ProcAddressConfiguration extends JavaConfiguration { localProcAddressCallingConventionMap.put(funcName, callingConvention); } - public String getLocalProcAddressCallingConvention(final String funcName) { - if (isLocalProcAddressCallingConvention4All()) { + public String getLocalProcAddressCallingConvention(final AliasedSymbol symbol) { + if ( isLocalProcAddressCallingConvention4All() ) { return getLocalProcAddressCallingConvention4All(); } - return localProcAddressCallingConventionMap.get(funcName); + final String res = localProcAddressCallingConventionMap.get(symbol.getName()); + if( null != res ) { + return res; + } + return oneInMap(localProcAddressCallingConventionMap, symbol.getAliasedNames()); } public boolean isLocalProcAddressCallingConvention4All() { diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java index 1984d09..a7739df 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java @@ -120,11 +120,11 @@ public class ProcAddressEmitter extends JavaEmitter { } protected boolean needsModifiedEmitters(final FunctionSymbol sym) { - if (!needsProcAddressWrapper(sym) || getConfig().isUnimplemented(getAliasedSymName(sym))) { + if ( !callThroughProcAddress(sym) || getConfig().isUnimplemented(sym) ) { return false; + } else { + return true; } - - return true; } private List<? extends FunctionEmitter> generateMethodBindingEmittersImpl(final Set<MethodBinding> methodBindingSet, final FunctionSymbol sym) throws Exception { @@ -138,15 +138,19 @@ public class ProcAddressEmitter extends JavaEmitter { return defaultEmitters; } - // Don't do anything special if this symbol doesn't require - // modifications - if (!needsModifiedEmitters(sym)) { + final boolean callThroughProcAddress = callThroughProcAddress(sym); + final boolean isUnimplemented = getConfig().isUnimplemented(sym); + + // Don't do anything special if this symbol doesn't require modifications + if( !callThroughProcAddress || isUnimplemented ) { + LOG.log(Level.INFO, "genModProcAddrEmitter: SKIP, not needed: callThrough {0}, isUnimplemented {1}: {2}", + callThroughProcAddress, isUnimplemented, sym.getAliasedString()); return defaultEmitters; } final ArrayList<FunctionEmitter> modifiedEmitters = new ArrayList<FunctionEmitter>(defaultEmitters.size()); - if (needsProcAddressWrapper(sym)) { + if ( callThroughProcAddress ) { if (getProcAddressConfig().emitProcAddressTable()) { // emit an entry in the GL proc address table for this method. emitProcAddressTableEntryForString(getAliasedSymName(sym)); @@ -196,7 +200,7 @@ public class ProcAddressEmitter extends JavaEmitter { protected void generateModifiedEmitters(final JavaMethodBindingEmitter baseJavaEmitter, final List<FunctionEmitter> emitters) { // See whether we need a proc address entry for this one - final boolean callThroughProcAddress = needsProcAddressWrapper(baseJavaEmitter.getBinding().getCSymbol()); + final boolean callThroughProcAddress = callThroughProcAddress(baseJavaEmitter.getBinding().getCSymbol()); // If this emitter doesn't have a body (i.e., is a direct native // call with no intervening argument processing), we need to force @@ -245,12 +249,15 @@ public class ProcAddressEmitter extends JavaEmitter { final FunctionSymbol cSymbol = baseCEmitter.getBinding().getCSymbol(); // See whether we need a proc address entry for this one - final boolean callThroughProcAddress = needsProcAddressWrapper(cSymbol); - final boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(cSymbol.getName()); + final boolean needsLocalTypedef = getProcAddressConfig().forceProcAddressGen(cSymbol) || + !hasFunctionPointerTypedef(cSymbol); + final boolean callThroughProcAddress = needsLocalTypedef || callThroughProcAddress(cSymbol); + LOG.log(Level.INFO, "genModProcAddrEmitter: needsTypedef {0}, callThrough {1}: {2}", + needsLocalTypedef, callThroughProcAddress, cSymbol.getAliasedString()); String forcedCallingConvention = null; - if (forceProcAddress) { - forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(cSymbol.getName()); + if (needsLocalTypedef) { + forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(cSymbol); } // Note that we don't care much about the naming of the C argument // variables so to keep things simple we ignore the buffer object @@ -260,7 +267,7 @@ public class ProcAddressEmitter extends JavaEmitter { // extra final argument, which is the address (the OpenGL procedure // address) of the function it needs to call final ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter( - baseCEmitter, callThroughProcAddress, forceProcAddress, forcedCallingConvention, this); + baseCEmitter, callThroughProcAddress, needsLocalTypedef, forcedCallingConvention, this); final MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression(); if (exp != null) { @@ -277,26 +284,30 @@ public class ProcAddressEmitter extends JavaEmitter { return symName; } - protected boolean needsProcAddressWrapper(final FunctionSymbol sym) { - final String symName = getAliasedSymName(sym); - - final ProcAddressConfiguration config = getProcAddressConfig(); - - // We should only generate code to call through a function pointer - // if the symbol has an associated function pointer typedef. - final String funcPointerTypedefName = getFunctionPointerTypedefName(sym); - boolean shouldWrap = typedefDictionary.containsKey(funcPointerTypedefName); - //System.err.println(funcPointerTypedefName + " defined: " + shouldWrap); - - if (config.skipProcAddressGen(symName)) { - shouldWrap = false; - } - - if (config.forceProcAddressGen(symName)) { - shouldWrap = true; + protected boolean callThroughProcAddress(final FunctionSymbol sym) { + final ProcAddressConfiguration cfg = getProcAddressConfig(); + boolean res = false; + int mode = 0; + if (cfg.forceProcAddressGen(sym)) { + res = true; + mode = 1; + } else { + if (cfg.skipProcAddressGen(sym)) { + res = false; + mode = 2; + } else { + res = hasFunctionPointerTypedef(sym); + mode = 3; + } } - - return shouldWrap; + LOG.log(Level.INFO, "callThroughProcAddress: {0} [m {1}]: {2}", res, mode, sym.getAliasedString()); + return res; + } + protected boolean hasFunctionPointerTypedef(final FunctionSymbol sym) { + final String funcPointerTypedefName = getFunctionPointerTypedefName(sym); + final boolean res = typedefDictionary.containsKey(funcPointerTypedefName); + LOG.log(Level.INFO, "hasFunctionPointerTypedef: {0}: {1}", res, sym.getAliasedString()); + return res; } protected void beginProcAddressTable() throws Exception { |