diff options
-rw-r--r-- | src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | 7 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/GlueGen.java | 7 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaConfiguration.java | 106 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 75 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/Logging.java | 179 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/ant/GlueGenTask.java | 23 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/pcpp/PCPP.java | 20 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java | 2 |
8 files changed, 263 insertions, 156 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index 1b1f2fa..47b2811 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -44,10 +44,9 @@ import java.io.*; import java.text.MessageFormat; import com.jogamp.common.os.MachineDataInfo; +import com.jogamp.gluegen.Logging.LoggerIf; import com.jogamp.gluegen.cgram.types.*; -import java.util.logging.Logger; - /** Emits the C-side component of the Java<->C JNI binding. */ public class CMethodBindingEmitter extends FunctionEmitter { @@ -57,7 +56,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { protected static final String arrayRes = "_array_res"; protected static final String arrayIdx = "_array_idx"; - protected final Logger LOG; + protected final LoggerIf LOG; protected MethodBinding binding; @@ -129,7 +128,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { final JavaConfiguration configuration) { super(output, false, configuration); - LOG = Logging.getLogger(CMethodBindingEmitter.class.getPackage().getName()); + LOG = Logging.getLogger(CMethodBindingEmitter.class.getPackage().getName(), CMethodBindingEmitter.class.getSimpleName()); assert(binding != null); assert(javaClassName != null); diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index 1e879c7..2833154 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -71,6 +71,8 @@ public class GlueGen implements GlueEmitterControls { private static boolean debug = false; + private static Level logLevel = null; + public static boolean debug() { return debug; } @Override @@ -103,6 +105,8 @@ public class GlueGen implements GlueEmitterControls { try { if(debug) { Logging.getLogger().setLevel(Level.ALL); + } else if( null != logLevel ) { + Logging.getLogger().setLevel(logLevel); } final GlueEmitter emit; if (emitterClass == null) { @@ -377,6 +381,9 @@ public class GlueGen implements GlueEmitterControls { emitterFQN = arg.substring(2); } else if (arg.startsWith("-C")) { cfgFiles.add(arg.substring(2)); + } else if (arg.equals("--logLevel")) { + i++; + logLevel = Level.parse(args[i]); } else if (arg.equals("--debug")) { debug=true; } else if (arg.equals("--dumpCPP")) { diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 5eadf94..7969597 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -42,6 +42,7 @@ package com.jogamp.gluegen; import com.jogamp.gluegen.JavaEmitter.EmissionStyle; import com.jogamp.gluegen.JavaEmitter.MethodAccess; +import com.jogamp.gluegen.Logging.LoggerIf; import java.io.*; import java.lang.reflect.Array; @@ -51,8 +52,6 @@ import java.util.regex.*; import com.jogamp.gluegen.jgram.*; import com.jogamp.gluegen.cgram.types.*; -import java.util.logging.Logger; - import static java.util.logging.Level.*; import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*; import static com.jogamp.gluegen.JavaEmitter.EmissionStyle.*; @@ -61,17 +60,13 @@ import static com.jogamp.gluegen.JavaEmitter.EmissionStyle.*; JavaEmitter. */ public class JavaConfiguration { - - public static final boolean DEBUG_IGNORES = GlueGen.debug() || false; - public static final boolean DEBUG_RENAMES = GlueGen.debug() || false; - private int nestedReads; private String packageName; private String implPackageName; private String className; private String implClassName; - protected final Logger LOG; + protected final LoggerIf LOG; public static String NEWLINE = System.getProperty("line.separator"); @@ -186,7 +181,7 @@ public class JavaConfiguration { private final Map<String, List<String>> javaEpilogues = new HashMap<String, List<String>>(); public JavaConfiguration() { - LOG = Logging.getLogger(JavaConfiguration.class.getPackage().getName()); + LOG = Logging.getLogger(JavaConfiguration.class.getPackage().getName(), JavaConfiguration.class.getSimpleName()); } /** Reads the configuration file. @@ -728,48 +723,48 @@ public class JavaConfiguration { return parentClass.get(className); } - public void dumpIgnoresOnce() { - if(!dumpedIgnores) { - dumpedIgnores = true; - dumpIgnores(); + public void logIgnoresOnce() { + if(!loggedIgnores) { + loggedIgnores = true; + logIgnores(); } } - private static boolean dumpedIgnores = false; + private static boolean loggedIgnores = false; - public void dumpIgnores() { - System.err.println("Extended Intf: "); + public void logIgnores() { + LOG.log(INFO, "Extended Intf: {0}", extendedIntfSymbolsIgnore.size()); for (final String str : extendedIntfSymbolsIgnore) { - System.err.println("\t"+str); + LOG.log(INFO, "\t{0}", str); } - System.err.println("Extended Impl: "); + LOG.log(INFO, "Extended Impl: {0}", extendedImplSymbolsIgnore.size()); for (final String str : extendedImplSymbolsIgnore) { - System.err.println("\t"+str); + LOG.log(INFO, "\t{0}", str); } - System.err.println("Ignores (All): "); + LOG.log(INFO, "Ignores (All): {0}", ignores.size()); for (final Pattern pattern : ignores) { - System.err.println("\t"+pattern); + LOG.log(INFO, "\t{0}", pattern); } } - public void dumpRenamesOnce() { - if(!dumpedRenames) { - dumpedRenames = true; - dumpRenames(); + public void logRenamesOnce() { + if(!loggedRenames) { + loggedRenames = true; + logRenames(); } } - private static boolean dumpedRenames = false; + private static boolean loggedRenames = false; - public void dumpRenames() { - System.err.println("Symbol Renames: "); + public void logRenames() { + LOG.log(INFO, "Symbol Renames: {0}", javaSymbolRenames.size()); for (final String key : javaSymbolRenames.keySet()) { - System.err.println("\t"+key+" -> "+javaSymbolRenames.get(key)); + LOG.log(INFO, "\t{0} -> {1}", key, javaSymbolRenames.get(key)); } - System.err.println("Symbol Aliasing (through renaming): "); + LOG.log(INFO, "Symbol Aliasing (through renaming): {0}", javaSymbolRenames.size()); for(final String newName : javaSymbolRenames.values()) { final Set<String> origNames = javaRenamedSymbols.get(newName); if(null!=origNames) { - System.err.println("\t"+newName+" <- "+origNames); + LOG.log(INFO, "\t{0} <- {1}", newName, origNames); } } } @@ -848,8 +843,8 @@ public class JavaConfiguration { return false; } protected final boolean shouldIgnoreInInterface_Int(final AliasedSymbol symbol) { - if(DEBUG_IGNORES) { - dumpIgnoresOnce(); + if( GlueGen.debug() ) { + logIgnoresOnce(); } final String name = symbol.getName(); final Set<String> aliases = symbol.getAliasedNames(); @@ -859,18 +854,14 @@ public class JavaConfiguration { oneInSet(extendedIntfSymbolsIgnore, aliases) ) { - if(DEBUG_IGNORES) { - System.err.println("Ignore Intf ignore (one): "+symbol.getAliasedString()); - } + LOG.log(INFO, "Ignore Intf ignore (one): {0}", symbol.getAliasedString()); return true; } // Simple case-2; the entire symbol (orig and renamed) is _not_ in the not-empty interface only table if ( !extendedIntfSymbolsOnly.isEmpty() && !extendedIntfSymbolsOnly.contains( name ) && !oneInSet(extendedIntfSymbolsOnly, aliases) ) { - if(DEBUG_IGNORES) { - System.err.println("Ignore Intf !extended (all): " + symbol.getAliasedString()); - } + LOG.log(INFO, "Ignore Intf !extended (all): {0}", symbol.getAliasedString()); return true; } return shouldIgnoreInImpl_Int(symbol); @@ -901,18 +892,14 @@ public class JavaConfiguration { oneInSet(extendedImplSymbolsIgnore, aliases) ) { - if(DEBUG_IGNORES) { - System.err.println("Ignore Impl ignore (one): "+symbol.getAliasedString()); - } + LOG.log(INFO, "Ignore Impl ignore (one): {0}", symbol.getAliasedString()); return true; } // Simple case-2; the entire symbol (orig and renamed) is _not_ in the not-empty interface only table if ( !extendedImplSymbolsOnly.isEmpty() && !extendedImplSymbolsOnly.contains( name ) && !oneInSet(extendedImplSymbolsOnly, aliases) ) { - if(DEBUG_IGNORES) { - System.err.println("Ignore Impl !extended (all): " + symbol.getAliasedString()); - } + LOG.log(INFO, "Ignore Impl !extended (all): {0}", symbol.getAliasedString()); return true; } @@ -921,9 +908,7 @@ public class JavaConfiguration { for (final Pattern ignoreRegexp : ignores) { final Matcher matcher = ignoreRegexp.matcher(name); if ( matcher.matches() || onePatternMatch(ignoreRegexp, aliases) ) { - if(DEBUG_IGNORES) { - System.err.println("Ignore Impl RegEx: "+symbol.getAliasedString()); - } + LOG.log(INFO, "Ignore Impl RegEx: {0}", symbol.getAliasedString()); return true; } } @@ -938,9 +923,7 @@ public class JavaConfiguration { // Special case as this is most often likely to be the case. // Unignores are not used very often. if(unignores.isEmpty()) { - if(DEBUG_IGNORES) { - System.err.println("Ignore Impl unignores==0: "+symbol.getAliasedString()+" -> "+name); - } + LOG.log(INFO, "Ignore Impl unignores==0: {0} -> {1}", symbol.getAliasedString(), name); return true; } boolean unignoreFound = false; @@ -952,11 +935,10 @@ public class JavaConfiguration { } } - if (!unignoreFound) - if(DEBUG_IGNORES) { - System.err.println("Ignore Impl !unignore: "+symbol.getAliasedString()+" -> "+name); - } - return true; + if (!unignoreFound) { + LOG.log(INFO, "Ignore Impl !unignore: {0} -> {1}", symbol.getAliasedString(), name); + return true; + } } } } @@ -1010,8 +992,8 @@ public class JavaConfiguration { function under the hood. Returns null if this symbol has not been explicitly renamed. */ public String getJavaSymbolRename(final String origName) { - if(DEBUG_RENAMES) { - dumpRenamesOnce(); + if( LOG.isLoggable(INFO) ) { + logRenamesOnce(); } return javaSymbolRenames.get(origName); } @@ -1023,18 +1005,12 @@ public class JavaConfiguration { /** Programmatically adds a rename directive for the given symbol. */ public void addJavaSymbolRename(final String origName, final String newName) { - if(DEBUG_RENAMES) { - System.err.print("\tRename "+origName+" -> "+newName); - } + LOG.log(INFO, "\tRename {0} -> {1}", origName, newName); final String prevValue = javaSymbolRenames.put(origName, newName); if(null != prevValue && !prevValue.equals(newName)) { throw new RuntimeException("Rename-Override Attampt: "+origName+" -> "+newName+ ", but "+origName+" -> "+prevValue+" already exist. Run in 'debug' mode to analyze!"); } - if(DEBUG_RENAMES) { - System.err.println(); - } - Set<String> origNames = javaRenamedSymbols.get(newName); if(null == origNames) { origNames = new HashSet<String>(); @@ -1118,7 +1094,7 @@ public class JavaConfiguration { try{ emissionStyle = EmissionStyle.valueOf(readString("Style", tok, filename, lineNo)); }catch(final IllegalArgumentException ex) { - LOG.log(WARNING, "Error parsing \"style\" command at line {0} in file \"{1}\"", new Object[]{lineNo, filename}); + LOG.log(WARNING, "Error parsing \"style\" command at line {0} in file \"{1}\"", lineNo, filename); } } else if (cmd.equalsIgnoreCase("AccessControl")) { readAccessControl(tok, filename, lineNo); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 17d51ab..a66458b 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -48,11 +48,12 @@ import java.io.*; import java.util.*; import java.text.MessageFormat; +import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider; +import com.jogamp.gluegen.Logging.LoggerIf; import com.jogamp.gluegen.cgram.types.*; import com.jogamp.gluegen.cgram.types.TypeComparator.AliasedSemanticSymbol; import java.nio.Buffer; -import java.util.logging.Logger; import jogamp.common.os.MachineDataInfoRuntime; import static java.util.logging.Level.*; @@ -103,10 +104,10 @@ public class JavaEmitter implements GlueEmitter { private final MachineDataInfo machDescJava = MachineDataInfo.StaticConfig.LP64_UNIX.md; private final MachineDataInfo.StaticConfig[] machDescTargetConfigs = MachineDataInfo.StaticConfig.values(); - protected final Logger LOG; + protected final LoggerIf LOG; public JavaEmitter() { - LOG = Logging.getLogger(JavaEmitter.class.getPackage().getName()); + LOG = Logging.getLogger(JavaEmitter.class.getPackage().getName(), JavaEmitter.class.getSimpleName()); } @Override @@ -477,10 +478,7 @@ public class JavaEmitter implements GlueEmitter { // Check to see whether this function should be ignored if ( !cfg.shouldIgnoreInImpl(cFunc) ) { methodBindingEmitters.addAll(generateMethodBindingEmitters(methodBindingSet, cFunc)); - if( GlueGen.debug() ) { - System.err.println("Non-Ignored Impl["+i+"]: "+cFunc.getAliasedString()); - i++; - } + LOG.log(INFO, "Non-Ignored Impl[{0}]: {1}", i++, cFunc.getAliasedString()); } } @@ -495,10 +493,7 @@ public class JavaEmitter implements GlueEmitter { if ( !emitter.isInterface() || !cfg.shouldIgnoreInInterface(cFunc) ) { emitter.emit(); emitter.getDefaultOutput().println(); // put newline after method body - if( GlueGen.debug() ) { - System.err.println("Non-Ignored Intf["+i+"]: "+cFunc.getAliasedString()); - i++; - } + LOG.log(INFO, "Non-Ignored Intf[{0}]: {1}", i++, cFunc.getAliasedString()); } } catch (final Exception e) { throw new RuntimeException( @@ -887,46 +882,46 @@ public class JavaEmitter implements GlueEmitter { if ( null == structCTypeName ) { final String structName = structCType.getStructName(); if ( null != structName && cfg.shouldIgnoreInInterface(structName) ) { - LOG.log(INFO, "skipping emission of unnamed ignored struct \"{0}\": {1}", new Object[] { structName, structCType.getDebugString() }); + LOG.log(INFO, "skipping emission of unnamed ignored struct \"{0}\": {1}", structName, structCType.getDebugString()); return; } else { final String d1 = null != typedefed ? typedefed.getDebugString() : null; - LOG.log(INFO, "skipping emission of unnamed struct {0}, typedef {1} ", new Object[] { structCType.getDebugString(), d1 }); + LOG.log(INFO, "skipping emission of unnamed struct {0}, typedef {1} ", structCType.getDebugString(), d1); return; } } if ( cfg.shouldIgnoreInInterface(structCTypeName) ) { - LOG.log(INFO, "skipping emission of ignored \"{0}\": {1}", new Object[] { structCTypeName, structCType.getDebugString() }); + LOG.log(INFO, "skipping emission of ignored \"{0}\": {1}", structCTypeName, structCType.getDebugString()); return; } if( null != typedefed && isOpaque(typedefed) ) { - LOG.log(INFO, "skipping emission of opaque typedef {0}, c-struct {1}", new Object[] { typedefed.getDebugString(), structCType.getDebugString() }); + LOG.log(INFO, "skipping emission of opaque typedef {0}, c-struct {1}", typedefed.getDebugString(), structCType.getDebugString()); return; } final Type containingCType = canonicalize(new PointerType(SizeThunk.POINTER, structCType, 0, typedefedName)); final JavaType containingJType = typeToJavaType(containingCType, null); if( containingJType.isOpaqued() ) { - LOG.log(INFO, "skipping emission of opaque {0}, {1}", new Object[] { containingJType.getDebugString(), structCType.getDebugString() }); + LOG.log(INFO, "skipping emission of opaque {0}, {1}", containingJType.getDebugString(), structCType.getDebugString()); return; } if( !containingJType.isCompoundTypeWrapper() ) { - LOG.log(WARNING, "skipping emission of non-compound {0}, {1}", new Object[] { containingJType.getDebugString(), structCType.getDebugString() }); + LOG.log(WARNING, "skipping emission of non-compound {0}, {1}", containingJType.getDebugString(), structCType.getDebugString()); return; } final String containingJTypeName = containingJType.getName(); - LOG.log(INFO, "perform emission of \"{0}\" -> \"{1}\": {2}", new Object[] { structCTypeName, containingJTypeName, structCType.getDebugString()}); + LOG.log(INFO, "perform emission of \"{0}\" -> \"{1}\": {2}", structCTypeName, containingJTypeName, structCType.getDebugString()); if( GlueGen.debug() ) { if( null != typedefed ) { LOG.log(INFO, " typedefed {0}", typedefed.getDebugString()); } else { - LOG.log(INFO, " typedefed NULL"); + LOG.log(INFO, " typedefed {0}", (Object)null); } LOG.log(INFO, " containingCType {0}", containingCType.getDebugString()); LOG.log(INFO, " containingJType {0}", containingJType.getDebugString()); } if( 0 == structCType.getNumFields() ) { - LOG.log(INFO, "emission of \"{0}\" with zero fields {1}", new Object[] { containingJTypeName, structCType.getDebugString() }); + LOG.log(INFO, "emission of \"{0}\" with zero fields {1}", containingJTypeName, structCType.getDebugString()); } this.requiresStaticInitialization = false; // reset @@ -1182,8 +1177,8 @@ public class JavaEmitter implements GlueEmitter { try { javaType = typeToJavaType(fieldType, machDescJava); } catch (final Exception e) { - System.err.println("Error occurred while creating accessor for field \"" + - field.getName() + "\", "+fieldType.getDebugString()); + LOG.log(SEVERE, "Error occurred while creating accessor for field \"{0}\", {1}", + field.getName(), fieldType.getDebugString()); throw(e); } if (javaType.isPrimitive()) { @@ -1199,9 +1194,9 @@ public class JavaEmitter implements GlueEmitter { final String capFieldName = capitalizeString(fieldName); final String sizeDenominator = fieldType.isPointer() ? "pointer" : javaTypeName ; - if(GlueGen.debug()) { - System.err.println("Java.StructEmitter.Primitive: "+field.getName()+", "+fieldType.getDebugString()+", "+javaTypeName+", "+ - ", fixedSize "+fieldTypeNativeSizeFixed+", opaque "+isOpaque(fieldType)+", sizeDenominator "+sizeDenominator); + if( LOG.isLoggable(FINE) ) { + LOG.log(FINE, "Java.StructEmitter.Primitive: "+field.getName()+", "+fieldType.getDebugString()+", "+javaTypeName+", "+ + ", fixedSize "+fieldTypeNativeSizeFixed+", opaque "+isOpaque(fieldType)+", sizeDenominator "+sizeDenominator); } if( !fieldType.isConst() ) { @@ -1543,14 +1538,14 @@ public class JavaEmitter implements GlueEmitter { final String cfgVal = cfg.returnedArrayLength(returnSizeLookupName); if( null != cfgVal ) { if( hasFixedTypeLen[0] ) { - System.err.println("WARNING: struct array field '"+returnSizeLookupName+"' of '"+type+"' length '"+Arrays.toString(length)+"' overwritten by cfg-expression: "+cfgVal); + LOG.log(WARNING, "struct array field '"+returnSizeLookupName+"' of '"+type+"' length '"+Arrays.toString(length)+"' overwritten by cfg-expression: "+cfgVal); } return cfgVal; } if( hasFixedTypeLen[0] ) { return lengthExpr.toString(); } else { - System.err.println("WARNING: struct array field '"+returnSizeLookupName+"' length '"+Arrays.toString(length)+"' without fixed- nor configured-size: "+type.getDebugString()); + LOG.log(WARNING, "struct array field '"+returnSizeLookupName+"' length '"+Arrays.toString(length)+"' without fixed- nor configured-size: "+type.getDebugString()); return null; } } @@ -1659,7 +1654,7 @@ public class JavaEmitter implements GlueEmitter { javaWriter.println(); final String msg = "SKIP ptr-ptr (depth "+pointerType.pointerDepth()+"): "+returnSizeLookupName +": "+fieldType; javaWriter.println(" // "+msg); - System.err.println("WARNING: "+msg); + LOG.log(WARNING, msg); return; } } @@ -1682,7 +1677,7 @@ public class JavaEmitter implements GlueEmitter { javaWriter.println(); final String msg = "SKIP primitive w/ platform dependent sized type in struct: "+returnSizeLookupName+": "+fieldType.getDebugString(); javaWriter.println(" // "+msg); - System.err.println("WARNING: "+msg); + LOG.log(WARNING, msg); return; } } @@ -1708,7 +1703,7 @@ public class JavaEmitter implements GlueEmitter { javaWriter.println(); final String msg = "SKIP unsized array in struct: "+returnSizeLookupName+": "+fieldType.getDebugString(); javaWriter.println(" // "+msg); - System.err.println("WARNING: "+msg); + LOG.log(WARNING, msg); return; } boolean _hasSingleElement=false; @@ -1744,7 +1739,7 @@ public class JavaEmitter implements GlueEmitter { // Setter Primitive Pointer final String msg = "SKIP setter for primitive-pointer type in struct: "+returnSizeLookupName+": "+fieldType.getDebugString(); javaWriter.println(" // "+msg); - System.err.println("INFO: "+msg); + LOG.log(INFO, msg); } else { // Setter Primitive Array if( hasSingleElement ) { @@ -1781,7 +1776,7 @@ public class JavaEmitter implements GlueEmitter { // Setter Struct Pointer final String msg = "SKIP setter for complex-pointer type in struct: "+returnSizeLookupName+": "+fieldType.getDebugString(); javaWriter.println(" // "+msg); - System.err.println("INFO: "+msg); + LOG.log(INFO, msg); } else { // Setter Struct Array if( hasSingleElement ) { @@ -2022,9 +2017,7 @@ public class JavaEmitter implements GlueEmitter { private JavaType typeToJavaType(final Type cType, final MachineDataInfo curMachDesc) { final JavaType jt = typeToJavaTypeImpl(cType, curMachDesc); - if( GlueGen.debug() ) { - System.err.println("typeToJavaType: "+cType.getDebugString()+" -> "+jt.getDebugString()); - } + LOG.log(FINE, "typeToJavaType: {0} -> {1}", cType.getDebugString(), jt.getDebugString()); return jt; } private boolean isJNIEnvPointer(final Type cType) { @@ -2061,7 +2054,8 @@ public class JavaEmitter implements GlueEmitter { if( GlueGen.debug() ) { // t is<type>**, targetType is <type>*, we need to get <type> final Type bottomType = targetType.asPointer().getTargetType(); - LOG.log(INFO, "Opaque Type: {0}, targetType: {1}, bottomType: {2} is ptr-ptr", new Object[]{cType.getDebugString(), targetType, bottomType}); + LOG.log(INFO, "Opaque Type: {0}, targetType: {1}, bottomType: {2} is ptr-ptr", + cType.getDebugString(), targetType, bottomType); } } } @@ -2154,19 +2148,22 @@ public class JavaEmitter implements GlueEmitter { // t is<type>**, targetType is <type>*, we need to get <type> bottomType = targetType.asPointer().getTargetType(); if( GlueGen.debug() ) { - LOG.log(INFO, "typeToJavaType(ptr-ptr): {0}, targetType: {1}, bottomType: {2}", new Object[]{cType.getDebugString(), targetType, bottomType}); + LOG.log(INFO, "typeToJavaType(ptr-ptr): {0}, targetType: {1}, bottomType: {2}", + cType.getDebugString(), targetType, bottomType); } return JavaType.forNIOPointerBufferClass(); } else if(targetType.isArray()) { // t is<type>[][], targetType is <type>[], we need to get <type> bottomType = targetType.asArray().getBaseElementType(); if( GlueGen.debug() ) { - LOG.log(INFO, "typeToJavaType(ptr-ptr.array): {0}, targetType: {1}, bottomType: {2}", new Object[]{cType.getDebugString(), targetType, bottomType}); + LOG.log(INFO, "typeToJavaType(ptr-ptr.array): {0}, targetType: {1}, bottomType: {2}", + cType.getDebugString(), targetType, bottomType); } } else { bottomType = targetType; if( GlueGen.debug() ) { - LOG.log(INFO, "typeToJavaType(ptr-ptr.primitive): {0}, targetType: {1}, bottomType: {2}", new Object[]{cType.getDebugString(), targetType, bottomType}); + LOG.log(INFO, "typeToJavaType(ptr-ptr.primitive): {0}, targetType: {1}, bottomType: {2}", + cType.getDebugString(), targetType, bottomType); } } diff --git a/src/java/com/jogamp/gluegen/Logging.java b/src/java/com/jogamp/gluegen/Logging.java index 77856f4..59cb441 100644 --- a/src/java/com/jogamp/gluegen/Logging.java +++ b/src/java/com/jogamp/gluegen/Logging.java @@ -31,6 +31,8 @@ */ package com.jogamp.gluegen; +import java.util.HashMap; +import java.util.Map; import java.util.logging.ConsoleHandler; import java.util.logging.Formatter; import java.util.logging.Handler; @@ -45,10 +47,134 @@ import com.jogamp.common.util.PropertyAccess; * @author Michael Bien, et.al. */ public class Logging { + /** + * An interface for {@link Logger}. + */ + public static interface LoggerIf { + /** + * See {@link Logger#warning(String)} + */ + void warning(String msg); + /** + * See {@link Logger#log(Level, String, Object[])} + */ + void log(final Level level, final String msg, final Object ... params); + /** + * See {@link Logger#log(Level, String, Object)} + */ + void log(final Level level, final String msg, final Object param); + /** + * See {@link Logger#log(Level, String)} + */ + void log(final Level level, final String msg); + /** + * See {@link Logger#setLevel(Level)} + */ + void setLevel(final Level newLevel) throws SecurityException; + /** + * See {@link Logger#getLevel()} + */ + Level getLevel(); + /** + * See {@link Logger#isLoggable(Level)} + */ + boolean isLoggable(Level level); + /** + * See {@link Logger#getName()} + */ + String getName(); + /** + * See {@link Logger#getHandlers()} + */ + Handler[] getHandlers(); + /** + * See {@link LogRecord#getSourceClassName()} + */ + String getSourceClassName(); + } + /* pp */ static class FQNLogger implements LoggerIf { + public final Logger impl; + public final PlainLogConsoleHandler handler; + /* pp */ FQNLogger(final String fqnClassName, final String simpleClassName, final Level level) { + this.impl = Logger.getLogger(fqnClassName); + this.handler = new PlainLogConsoleHandler(new PlainLogFormatter(simpleClassName), level); + this.impl.setUseParentHandlers(false); + this.impl.setLevel(level); + this.impl.addHandler(this.handler); + this.impl.log(Level.INFO, "Logging.new: "+impl.getName()+": level "+level+ + ": obj 0x"+Integer.toHexString(impl.hashCode())); + } + @Override + public void warning(final String msg) { + impl.warning(msg); + } + @Override + public void log(final Level level, final String msg, final Object ... params) { + impl.log(level, msg, params); + } + @Override + public void log(final Level level, final String msg, final Object param) { + impl.log(level, msg, param); + } + @Override + public void log(final Level level, final String msg) { + impl.log(level, msg); + } + @Override + public void setLevel(final Level newLevel) throws SecurityException { + impl.setLevel(newLevel); + } + @Override + public Level getLevel() { + return impl.getLevel(); + } + @Override + public boolean isLoggable(final Level level) { + return impl.isLoggable(level); + } + @Override + public String getName() { + return impl.getName(); + } + @Override + public synchronized Handler[] getHandlers() { + return impl.getHandlers(); + } + @Override + public String getSourceClassName() { + return handler.plf.simpleClassName; + } + } + static class PlainLogFormatter extends Formatter { + final String simpleClassName; + PlainLogFormatter(final String simpleClassName) { + this.simpleClassName = simpleClassName; + } + @Override + public String format(final LogRecord record) { + final StringBuilder sb = new StringBuilder(128); + sb.append("[").append(record.getLevel()).append(' ').append(simpleClassName).append("]: "); + sb.append(formatMessage(record)).append("\n"); + return sb.toString(); + } + } + static class PlainLogConsoleHandler extends ConsoleHandler { + final PlainLogFormatter plf; + PlainLogConsoleHandler(final PlainLogFormatter plf, final Level level) { + this.plf = plf; + setFormatter(plf); + setLevel(level); + } + @Override + public java.util.logging.Formatter getFormatter() { + return plf; + } + } - final static Logger rootPackageLogger; - + private final static Map<String, LoggerIf> loggers; + private final static FQNLogger rootPackageLogger; static { + loggers = new HashMap<String, LoggerIf>(); final String packageName = Logging.class.getPackage().getName(); final String property = PropertyAccess.getProperty(packageName+".level", true); Level level; @@ -57,37 +183,31 @@ public class Logging { } else { level = Level.WARNING; } - - final ConsoleHandler handler = new ConsoleHandler() { - @Override - public java.util.logging.Formatter getFormatter() { - return new PlainLogFormatter(); - } - }; - handler.setFormatter(new PlainLogFormatter()); - handler.setLevel(level); - - rootPackageLogger = Logger.getLogger(packageName); - rootPackageLogger.setUseParentHandlers(false); - rootPackageLogger.setLevel(level); - rootPackageLogger.addHandler(handler); + final String simpleClassName = Logging.class.getSimpleName(); + final String fqnClassName = packageName+"."+simpleClassName; + rootPackageLogger = new FQNLogger(fqnClassName, simpleClassName, level); + loggers.put(fqnClassName, rootPackageLogger); } /** provokes static initialization */ static void init() { } /** Returns the <i>root package logger</i>. */ - public static Logger getLogger() { + public static LoggerIf getLogger() { return rootPackageLogger; } /** Returns the demanded logger, while aligning its log-level to the root logger's level. */ - public static synchronized Logger getLogger(final String name) { - final Logger l = Logger.getLogger(name); - alignLevel(l); - return l; + public static synchronized LoggerIf getLogger(final String packageName, final String simpleClassName) { + final String fqnClassName = packageName+"."+simpleClassName; + LoggerIf res = loggers.get(fqnClassName); + if( null == res ) { + res = new FQNLogger(fqnClassName, simpleClassName, rootPackageLogger.getLevel()); + loggers.put(fqnClassName, res); + } + return res; } /** Align log-level of given logger to the root logger's level. */ - public static void alignLevel(final Logger l) { + public static void alignLevel(final LoggerIf l) { final Level level = rootPackageLogger.getLevel(); l.setLevel(level); final Handler[] hs = l.getHandlers(); @@ -95,19 +215,4 @@ public class Logging { h.setLevel(level); } } - - /** - * This log formatter needs usually one line per log record. - * @author Michael Bien - */ - private static class PlainLogFormatter extends Formatter { - - @Override - public String format(final LogRecord record) { - final StringBuilder sb = new StringBuilder(128); - sb.append("[").append(record.getLevel()).append(' ').append(record.getSourceClassName()).append("]: "); - sb.append(formatMessage(record)).append("\n"); - return sb.toString(); - } - } } diff --git a/src/java/com/jogamp/gluegen/ant/GlueGenTask.java b/src/java/com/jogamp/gluegen/ant/GlueGenTask.java index dd57365..2b11d3f 100644 --- a/src/java/com/jogamp/gluegen/ant/GlueGenTask.java +++ b/src/java/com/jogamp/gluegen/ant/GlueGenTask.java @@ -73,7 +73,8 @@ import org.apache.tools.ant.util.JavaEnvUtils; emitter="[emitter class name]" config="[configuration file]" dumpCPP="[optional boolean]" - debug="[optional boolean]" /> + debug="[optional boolean]" + logLevel="[optional string]" /> * </pre> * * @author Rob Grzywinski <a href="mailto:[email protected]">[email protected]</a> @@ -101,6 +102,11 @@ public class GlueGenTask extends Task private boolean debug=false; /** + * <p>The optional logLevel.</p> + */ + private String logLevel = null; + + /** * <p>The optional dumpCPP flag.</p> */ private boolean dumpCPP=false; @@ -182,6 +188,15 @@ public class GlueGenTask extends Task } /** + * <p>Set the logLevel (optional). This is called by ANT.</p> + */ + public void setLogLevel(final String logLevel) + { + log( ("Setting logLevel: " + logLevel), Project.MSG_VERBOSE); + this.logLevel=logLevel; + } + + /** * <p>Set the dumpCPP flag (optional). This is called by ANT.</p> */ public void setDumpCPP(final boolean dumpCPP) @@ -456,6 +471,12 @@ public void setIncludeRefid(final Reference reference) { gluegenCommandline.createArgument().setValue("--debug"); } + // add the logLevel if enabled + if(null != logLevel) { + gluegenCommandline.createArgument().setValue("--logLevel"); + gluegenCommandline.createArgument().setValue(logLevel); + } + // add the debug flag if enabled if(dumpCPP) { gluegenCommandline.createArgument().setValue("--dumpCPP"); diff --git a/src/java/com/jogamp/gluegen/pcpp/PCPP.java b/src/java/com/jogamp/gluegen/pcpp/PCPP.java index 72b46a1..1ef0cd6 100644 --- a/src/java/com/jogamp/gluegen/pcpp/PCPP.java +++ b/src/java/com/jogamp/gluegen/pcpp/PCPP.java @@ -56,9 +56,9 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Logger; import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; import static java.util.logging.Level.*; @@ -68,7 +68,7 @@ import static java.util.logging.Level.*; public class PCPP { - private final Logger LOG; + private final LoggerIf LOG; /** Map containing the results of #define statements. We must evaluate certain very simple definitions (to properly handle @@ -89,7 +89,7 @@ public class PCPP { private final boolean enableCopyOutput2Stderr; public PCPP(final List<String> includePaths, final boolean debug, final boolean copyOutput2Stderr) { - LOG = Logging.getLogger(PCPP.class.getPackage().getName()); + LOG = Logging.getLogger(PCPP.class.getPackage().getName(), PCPP.class.getSimpleName()); this.includePaths = includePaths; setOut(System.out); enableDebugPrint = debug; @@ -464,20 +464,20 @@ public class PCPP { final String oldDef = defineMap.remove(name); if (oldDef == null) { LOG.log(WARNING, "ignoring redundant \"#undef {0}\", at \"{1}\" line {2}: \"{3}\" was not previously defined", - new Object[]{name, filename(), lineNumber(), name}); + name, filename(), lineNumber(), name); } else { // System.err.println("UNDEFINED: '" + name + "' (line " + lineNumber() + " file " + filename() + ")"); } nonConstantDefines.remove(name); } else { - LOG.log(WARNING, "FAILED TO UNDEFINE: ''{0}'' (line {1} file {2})", new Object[]{name, lineNumber(), filename()}); + LOG.log(INFO, "DISABLED UNDEFINE: ''{0}'' (line {1} file {2})", name, lineNumber(), filename()); } } private void handleWarning() throws IOException { final String msg = nextWordOrString(); if (enabled()) { - LOG.log(WARNING, "#warning {0} at \"{1}\" line \"{2}\"", new Object[]{msg, filename(), lineNumber()}); + LOG.log(WARNING, "#warning {0} at \"{1}\" line \"{2}\"", msg, filename(), lineNumber()); } } @@ -545,7 +545,7 @@ public class PCPP { final String value = ""; final String oldDef = defineMap.put(name, value); if (oldDef != null && !oldDef.equals(value)) { - LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"\"", new Object[]{name, oldDef}); + LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"\"", name, oldDef); } // We don't want to emit the define, because it would serve no purpose // and cause GlueGen errors (confuse the GnuCParser) @@ -560,7 +560,7 @@ public class PCPP { // Put it in the #define map final String oldDef = defineMap.put(name, value); if (oldDef != null && !oldDef.equals(value)) { - LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", new Object[]{name, oldDef, value}); + LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", name, oldDef, value); } debugPrint(true, "DEFINE " + name + " ["+oldDef+" ] -> "+value + " CONST"); //System.err.println("//---DEFINED: " + name + " to \"" + value + "\""); @@ -610,7 +610,7 @@ public class PCPP { final Macro macro = new Macro(params, values); final Macro oldDef = macroMap.put(name, macro); if (oldDef != null) { - LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", new Object[]{name, oldDef, macro}); + LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", name, oldDef, macro); } emitDefine = false; @@ -661,7 +661,7 @@ public class PCPP { final String oldDef = defineMap.put(name, value); if (oldDef != null && !oldDef.equals(value)) { - LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", new Object[]{name, oldDef, value}); + LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", name, oldDef, value); } debugPrint(true, "DEFINE " + name + " ["+oldDef+" ] -> "+value + " CONST"); // System.err.println("#define " + name +" "+value + " CONST EXPRESSION"); diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java index 4145cc4..1984d09 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java @@ -47,6 +47,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.Level; import com.jogamp.gluegen.CMethodBindingEmitter; import com.jogamp.gluegen.CodeGenUtils; @@ -133,6 +134,7 @@ public class ProcAddressEmitter extends JavaEmitter { // honor that (for example, the superclass might have caught an Ignore // direction that matched the symbol's name). if (defaultEmitters.isEmpty()) { + LOG.log(Level.INFO, "genModProcAddrEmitter: SKIP, empty binding set: {0}", sym.getAliasedString()); return defaultEmitters; } |