diff options
author | Michael Bien <[email protected]> | 2009-08-08 21:46:55 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-08-08 21:46:55 +0200 |
commit | 889b9574958b04988ab3acbabab109745fbc379a (patch) | |
tree | 5f3485268de0f59f113c9d524561fc49b50ad75f /src/java | |
parent | a07c223b8dbde8f81886b7b2bf602e26ab9531b3 (diff) | |
parent | 5f8e46324f245c99080d2c340cd4fb2ec9c4fa8d (diff) |
Merge branch 'master' of ssh://[email protected]/gluegen~gluegen-git
Diffstat (limited to 'src/java')
23 files changed, 468 insertions, 164 deletions
diff --git a/src/java/com/sun/gluegen/CMethodBindingEmitter.java b/src/java/com/sun/gluegen/CMethodBindingEmitter.java index 2085477..af632c3 100644 --- a/src/java/com/sun/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/CMethodBindingEmitter.java @@ -155,7 +155,7 @@ public class CMethodBindingEmitter extends FunctionEmitter public final MethodBinding getBinding() { return binding; } public String getName() { - return binding.getRenamedMethodName(); + return binding.getName(); } /** @@ -691,11 +691,12 @@ public class CMethodBindingEmitter extends FunctionEmitter "Could not copy data for type \"" + cArgType + "\"; currently only pointer types supported."); } - PointerType cArgElementType = cArgPtrType.getTargetType().asPointer(); + PointerType cArgElementType = cArgPtrType.getTargetType().asPointer(); emitMalloc( writer, convName+"_copy", cArgElementType.getName(), + isConstPtrPtr(cArgPtrType), arrayLenName, "Could not allocate buffer for copying data in argument \\\""+binding.getArgumentName(i)+"\\\""); @@ -757,6 +758,7 @@ public class CMethodBindingEmitter extends FunctionEmitter writer, convName+"_copy[_copyIndex]", cArgElementType.getTargetType().getName(), // assumes cArgPtrType is ptr-to-ptr-to-primitive !! + isConstPtrPtr(cArgPtrType), "(*env)->GetArrayLength(env, _tmpObj)", "Could not allocate buffer during copying of data in argument \\\""+binding.getArgumentName(i)+"\\\""); // FIXME: copy the data (use matched Get/ReleasePrimitiveArrayCritical() calls) @@ -982,6 +984,9 @@ public class CMethodBindingEmitter extends FunctionEmitter } else { writer.print("("); Type cArgType = binding.getCSymbol().getArgumentType(i); + if (isConstPtrPtr(cArgType)) { + writer.print("const "); + } writer.print(cArgType.getName()); writer.print(") "); if (binding.getCArgumentType(i).isPointer() && binding.getJavaArgumentType(i).isPrimitive()) { @@ -1277,12 +1282,16 @@ public class CMethodBindingEmitter extends FunctionEmitter private void emitMalloc(PrintWriter writer, String targetVarName, String elementTypeString, + boolean elementTypeIsConst, String numElementsExpression, String mallocFailureErrorString) { writer.print(" "); writer.print(targetVarName); writer.print(" = ("); + if(elementTypeIsConst) { + writer.print("const "); + } writer.print(elementTypeString); writer.print(" *) malloc("); writer.print(numElementsExpression); @@ -1467,9 +1476,22 @@ public class CMethodBindingEmitter extends FunctionEmitter // incoming data has been properly laid out in memory to match the C // memory model if (javaType.isStringArray()) { - writer.print(" const char **"); + String cElementTypeName = "char *"; + PointerType cPtrType = cType.asPointer(); + if (cPtrType != null) { + cElementTypeName = cPtrType.getTargetType().asPointer().getName(); + } + if (isConstPtrPtr(cType)) { + writer.print(" const "+cElementTypeName+" *"); + } else { + writer.print(" "+cElementTypeName+" *"); + } } else { - writer.print(" " + ptrTypeString); + if (isConstPtrPtr(cType)) { + writer.print(" const " + ptrTypeString); + } else { + writer.print(" " + ptrTypeString); + } } writer.print(" "); writer.print(cVariableName); diff --git a/src/java/com/sun/gluegen/ConstantDefinition.java b/src/java/com/sun/gluegen/ConstantDefinition.java index e06903b..44ce8e0 100644 --- a/src/java/com/sun/gluegen/ConstantDefinition.java +++ b/src/java/com/sun/gluegen/ConstantDefinition.java @@ -38,17 +38,24 @@ import java.util.*; /** Represents the definition of a constant which was provided either via a #define statement or through an enum definition. */ public class ConstantDefinition { + private String origName; + private HashSet aliasedNames; private String name; private String value; + private boolean isEnum; private String enumName; private Set/*<String>*/ aliases; public ConstantDefinition(String name, String value, + boolean isEnum, String enumName) { + this.origName = name; this.name = name; this.value = value; + this.isEnum = isEnum; this.enumName = enumName; + this.aliasedNames=new HashSet(); } public boolean equals(ConstantDefinition other) { @@ -72,12 +79,36 @@ public class ConstantDefinition { return name.hashCode(); } - public String getName() { return name; } + /** Supports renaming in Java binding. */ + public void rename(String name) { + if(null!=name) { + this.name = name; + aliasedNames.add(origName); + } + } + + public void addAliasedName(String name) { + aliasedNames.add(name); + } + public Collection getAliasedNames() { + return aliasedNames; + } + + public String getOrigName() { + return origName; + } + + public String getName() { + return name; + } + public String getValue() { return value; } /** Returns null if this definition was not part of an enumeration, or if the enum was anonymous. */ public String getEnumName() { return enumName; } + public boolean isEnum() { return isEnum; } + public Set/*<String>*/ getAliases() { return aliases; } diff --git a/src/java/com/sun/gluegen/DebugEmitter.java b/src/java/com/sun/gluegen/DebugEmitter.java index 40d6c2d..34586a1 100644 --- a/src/java/com/sun/gluegen/DebugEmitter.java +++ b/src/java/com/sun/gluegen/DebugEmitter.java @@ -58,7 +58,9 @@ public class DebugEmitter implements GlueEmitter { System.out.println("----- END EMISSION OF GLUE CODE -----"); } public void beginDefines() {} - public void emitDefine(String name, String value, String optionalComment) { + public void emitDefine(ConstantDefinition def, String optionalComment) { + String name = def.getName(); + String value = def.getValue(); System.out.println("#define " + name + " " + value + (optionalComment != null ? ("// " + optionalComment) : "")); } diff --git a/src/java/com/sun/gluegen/GlueEmitter.java b/src/java/com/sun/gluegen/GlueEmitter.java index e21bc87..2738411 100644 --- a/src/java/com/sun/gluegen/GlueEmitter.java +++ b/src/java/com/sun/gluegen/GlueEmitter.java @@ -88,7 +88,7 @@ public interface GlueEmitter { * emit that string as a comment providing extra information about the * define. */ - public void emitDefine(String name, String value, String optionalComment) throws Exception; + public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception; public void endDefines() throws Exception; public void beginFunctions(TypeDictionary typedefDictionary, diff --git a/src/java/com/sun/gluegen/GlueGen.java b/src/java/com/sun/gluegen/GlueGen.java index 5d61fdb..3804795 100644 --- a/src/java/com/sun/gluegen/GlueGen.java +++ b/src/java/com/sun/gluegen/GlueGen.java @@ -227,12 +227,12 @@ public class GlueGen implements GlueEmitterControls { for (int i = 0; i < enumeration.getNumEnumerates(); ++i) { String enumElementName = enumeration.getEnumName(i); String value = String.valueOf(enumeration.getEnumValue(i)); - constants.add(new ConstantDefinition(enumElementName, value, enumName)); + constants.add(new ConstantDefinition(enumElementName, value, true, enumName)); } } for (Iterator iter = lexer.getDefines().iterator(); iter.hasNext(); ) { Define def = (Define) iter.next(); - constants.add(new ConstantDefinition(def.getName(), def.getValue(), null)); + constants.add(new ConstantDefinition(def.getName(), def.getValue(), false, null)); } functions = headerParser.getParsedFunctions(); @@ -266,9 +266,7 @@ public class GlueGen implements GlueEmitterControls { comment += "<br>\n" + enumName; } } - emit.emitDefine(def.getName(), - def.getValue(), - comment); + emit.emitDefine(def, comment); } } emit.endDefines(); diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java index 5693150..636cef8 100644 --- a/src/java/com/sun/gluegen/JavaConfiguration.java +++ b/src/java/com/sun/gluegen/JavaConfiguration.java @@ -117,8 +117,8 @@ public class JavaConfiguration { * converted to String args; value is List of Integer argument indices */ private Map/*<String,List<Integer>>*/ argumentsAreString = new HashMap(); - private Set/*<String>*/ extendedIntfSymbols = new HashSet(); - private boolean extendedIntfSymbolsOnly=false; + private Set/*<String>*/ extendedIntfSymbolsIgnore = new HashSet(); + private Set/*<String>*/ extendedIntfSymbolsOnly = new HashSet(); private Set/*<Pattern>*/ ignores = new HashSet(); private Map/*<String,Pattern>*/ ignoreMap = new HashMap(); private Set/*<Pattern>*/ ignoreNots = new HashSet(); @@ -577,10 +577,6 @@ public class JavaConfiguration { return (String) parentClass.get(className); } - public boolean extendedIntfSymbolsOnly() { - return extendedIntfSymbolsOnly; - } - public static final boolean DEBUG_IGNORES = false; public static boolean dumpedIgnores = false; @@ -593,7 +589,7 @@ public class JavaConfiguration { public void dumpIgnores() { System.err.println("Extended Intf: "); - for (Iterator iter = extendedIntfSymbols.iterator(); iter.hasNext(); ) { + for (Iterator iter = extendedIntfSymbolsIgnore.iterator(); iter.hasNext(); ) { System.err.println("\t"+(String)iter.next()); } System.err.println("Ignores (All): "); @@ -602,14 +598,23 @@ public class JavaConfiguration { } } + public void dumpRenames() { + System.err.println("Symbol Renames: "); + for (Iterator iter = javaSymbolRenames.keySet().iterator(); iter.hasNext(); ) { + String key = (String)iter.next(); + System.err.println("\t"+key+" -> "+javaSymbolRenames.get(key)); + } + } + /** Returns true if this #define, function, struct, or field within a struct should be ignored during glue code generation. */ public boolean shouldIgnoreInInterface(String symbol) { if(DEBUG_IGNORES) { dumpIgnoresOnce(); } - // Simple case; the entire symbol is in the interface ignore table. - if (extendedIntfSymbols.contains(symbol)) { + // Simple case; the entire symbol (orig or renamed) is in the interface ignore table + if (extendedIntfSymbolsIgnore.contains(symbol) || + extendedIntfSymbolsIgnore.contains(getJavaSymbolRename(symbol))) { if(DEBUG_IGNORES) { System.err.println("Ignore Intf: "+symbol); } @@ -628,8 +633,9 @@ public class JavaConfiguration { dumpIgnoresOnce(); } - if (extendedIntfSymbolsOnly) { - if(!extendedIntfSymbols.contains(symbol)) { + if (!extendedIntfSymbolsOnly.isEmpty()) { + if(!extendedIntfSymbolsOnly.contains(symbol) && + !extendedIntfSymbolsOnly.contains(getJavaSymbolRename(symbol))) { if(DEBUG_IGNORES) { System.err.println("Ignore Impl !extended: " + symbol); } @@ -849,11 +855,10 @@ public class JavaConfiguration { // because ReturnedArrayLength changes them. } else if (cmd.equalsIgnoreCase("ArgumentIsString")) { readArgumentIsString(tok, filename, lineNo); - } else if (cmd.equalsIgnoreCase("ExtendedInterfaceSymbols")) { - readExtendedInterfaceSymbols(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("ExtendedInterfaceSymbolsIgnore")) { + readExtendedInterfaceSymbols(tok, filename, lineNo, false); } else if (cmd.equalsIgnoreCase("ExtendedInterfaceSymbolsOnly")) { - extendedIntfSymbolsOnly=true; - readExtendedInterfaceSymbols(tok, filename, lineNo); + readExtendedInterfaceSymbols(tok, filename, lineNo, true); } else if (cmd.equalsIgnoreCase("Ignore")) { readIgnore(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("Unignore")) { @@ -1056,7 +1061,7 @@ public class JavaConfiguration { } } - protected void readExtendedInterfaceSymbols(StringTokenizer tok, String filename, int lineNo) { + protected void readExtendedInterfaceSymbols(StringTokenizer tok, String filename, int lineNo, boolean onlyList) { File javaFile; BufferedReader javaReader; try { @@ -1080,8 +1085,13 @@ public class JavaConfiguration { return; } - extendedIntfSymbols.addAll(parser.getParsedEnumNames()); - extendedIntfSymbols.addAll(parser.getParsedFunctionNames()); + if(onlyList) { + extendedIntfSymbolsOnly.addAll(parser.getParsedEnumNames()); + extendedIntfSymbolsOnly.addAll(parser.getParsedFunctionNames()); + } else { + extendedIntfSymbolsIgnore.addAll(parser.getParsedEnumNames()); + extendedIntfSymbolsIgnore.addAll(parser.getParsedFunctionNames()); + } } protected void readIgnore(StringTokenizer tok, String filename, int lineNo) { diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 603881c..1667ed6 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -126,11 +126,7 @@ public class JavaEmitter implements GlueEmitter { for (Iterator iter = constants.iterator(); iter.hasNext(); ) { ConstantDefinition def = (ConstantDefinition) iter.next(); String rename = cfg.getJavaSymbolRename(def.getName()); - if (rename != null) { - ConstantDefinition newDef = new ConstantDefinition(rename, def.getValue(), def.getEnumName()); - newDef.addAlias(def.getName()); - def = newDef; - } + def.rename(cfg.getJavaSymbolRename(def.getName())); newConstants.add(def); } constants = newConstants; @@ -301,7 +297,7 @@ public class JavaEmitter implements GlueEmitter { "\" cannot be assigned to a int, long, float, or double"); } - public void emitDefine(String name, String value, String optionalComment) throws Exception + public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception { if (cfg.allStatic() || cfg.emitInterface()) { // TODO: Some defines (e.g., GL_DOUBLE_EXT in gl.h) are defined in terms @@ -313,6 +309,8 @@ public class JavaEmitter implements GlueEmitter { // currently only emits only numeric defines -- if it handled #define'd // objects it would make a bigger difference. + String name = def.getName(); + String value = def.getValue(); if (!cfg.shouldIgnoreInInterface(name)) { String type = getJavaType(name, value); if (optionalComment != null && optionalComment.length() != 0) { @@ -377,6 +375,7 @@ public class JavaEmitter implements GlueEmitter { }); // Bind all the C funcs to Java methods + HashSet/*<MethodBinding>*/ methodBindingSet = new HashSet(); ArrayList/*<FunctionEmitter>*/ methodBindingEmitters = new ArrayList(2*funcsToBind.size()); for (Iterator iter = funcsToBind.iterator(); iter.hasNext(); ) { FunctionSymbol cFunc = (FunctionSymbol) iter.next(); @@ -385,7 +384,7 @@ public class JavaEmitter implements GlueEmitter { continue; // don't generate bindings for this symbol } - List allBindings = generateMethodBindingEmitters(cFunc); + List allBindings = generateMethodBindingEmitters(methodBindingSet, cFunc); methodBindingEmitters.addAll(allBindings); } @@ -669,14 +668,14 @@ public class JavaEmitter implements GlueEmitter { * Generate all appropriate Java bindings for the specified C function * symbols. */ - protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { + protected List generateMethodBindingEmitters(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception { ArrayList/*<FunctionEmitter>*/ allEmitters = new ArrayList(); try { // Get Java binding for the function MethodBinding mb = bindFunction(sym, null, null, machDesc64); - + // JavaTypes representing C pointers in the initial // MethodBinding have not been lowered yet to concrete types List bindings = expandMethodBinding(mb); @@ -684,6 +683,11 @@ public class JavaEmitter implements GlueEmitter { for (Iterator iter = bindings.iterator(); iter.hasNext(); ) { MethodBinding binding = (MethodBinding) iter.next(); + if(!methodBindingSet.add(binding)) { + // skip .. already exisiting binding .. + continue; + } + if (cfg.allStatic() && binding.hasContainingType()) { // This should not currently happen since structs are emitted using a different mechanism throw new IllegalArgumentException("Cannot create binding in AllStatic mode because method has containing type: \"" + @@ -1146,6 +1150,28 @@ public class JavaEmitter implements GlueEmitter { } public void endStructs() throws Exception {} + public static int addStrings2Buffer(StringBuffer buf, String sep, String first, Collection col) { + int num = 0; + if(null==buf) buf=new StringBuffer(); + + Iterator iter=col.iterator(); + if(null!=first) { + buf.append(first); + if( iter.hasNext() ) { + buf.append(sep); + } + num++; + } + while( iter.hasNext() ) { + buf.append((String)iter.next()); + if( iter.hasNext() ) { + buf.append(sep); + } + num++; + } + return num; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -1643,7 +1669,7 @@ public class JavaEmitter implements GlueEmitter { MethodBinding binding = new MethodBinding(sym, containingType, containingCType); - binding.setRenamedMethodName(cfg.getJavaSymbolRename(sym.getName())); + binding.renameMethodName(cfg.getJavaSymbolRename(sym.getName())); if (cfg.returnsString(binding.getName())) { PointerType prt = sym.getReturnType().asPointer(); diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java index 9fa232d..558c184 100644 --- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -157,7 +157,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter public boolean isForIndirectBufferAndArrayImplementation() { return forIndirectBufferAndArrayImplementation; } public String getName() { - return binding.getRenamedMethodName(); + return binding.getName(); } protected String getArgumentName(int i) { @@ -370,9 +370,9 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected String getImplMethodName(boolean direct) { if (direct) { - return binding.getRenamedMethodName() + "0"; + return binding.getName() + "0"; } else { - return binding.getRenamedMethodName() + "1"; + return binding.getName() + "1"; } } diff --git a/src/java/com/sun/gluegen/MethodBinding.java b/src/java/com/sun/gluegen/MethodBinding.java index 5431874..228f581 100644 --- a/src/java/com/sun/gluegen/MethodBinding.java +++ b/src/java/com/sun/gluegen/MethodBinding.java @@ -51,6 +51,7 @@ public class MethodBinding { private FunctionSymbol sym; private String renamedMethodName; + private HashSet aliasedNames; private JavaType javaReturnType; private List javaArgumentTypes; private boolean computedSignatureProperties; @@ -76,6 +77,8 @@ public class MethodBinding { this.sym = bindingToCopy.sym; this.renamedMethodName = bindingToCopy.renamedMethodName; + this.aliasedNames=new HashSet(); + this.aliasedNames.addAll(bindingToCopy.aliasedNames); this.containingType = bindingToCopy.containingType; this.containingCType = bindingToCopy.containingCType; this.javaReturnType = bindingToCopy.javaReturnType; @@ -96,6 +99,7 @@ public class MethodBinding { /** Constructor for calling a C function. */ public MethodBinding(FunctionSymbol sym) { this.sym = sym; + this.aliasedNames=new HashSet(); } /** Constructor for calling a function pointer contained in a @@ -104,6 +108,7 @@ public class MethodBinding { this.sym = sym; this.containingType = containingType; this.containingCType = containingCType; + this.aliasedNames=new HashSet(); } public void setJavaReturnType(JavaType type) { @@ -156,11 +161,11 @@ public class MethodBinding { return "arg" + i; } - public String getName() { + public String getOrigName() { return sym.getName(); } - public String getRenamedMethodName() { + public String getName() { // Defaults to same as C symbol unless renamed if (renamedMethodName != null) { return renamedMethodName; @@ -169,8 +174,19 @@ public class MethodBinding { } /** Supports renaming C function in Java binding. */ - public void setRenamedMethodName(String name) { - renamedMethodName = name; + public void renameMethodName(String name) { + if(null!=name) { + renamedMethodName = name; + aliasedNames.add(sym.getName()); + } + } + + public void addAliasedName(String name) { + aliasedNames.add(name); + } + + public Collection getAliasedNames() { + return aliasedNames; } /** Creates a new MethodBinding replacing the specified Java @@ -451,9 +467,10 @@ public class MethodBinding { } MethodBinding other = (MethodBinding)obj; - if (!(sym.equals(other.sym))) { return false; } + if ( !getName().equals(other.getName()) || + !sym.getType().equals(other.sym.getType()) ) { return false; } if (!(javaReturnType.equals(other.getJavaReturnType()))) { return false; } - if (containingType != null && + if (containingCType != null && other.getContainingCType() != null && (!(containingCType.equals(other.getContainingCType())))) { return false; @@ -473,14 +490,35 @@ public class MethodBinding { return true; } - // FIXME!! Implement hashCode() to match equals(Object) + public int hashCode() { + StringBuffer buf = new StringBuffer(200); + buf.append(getName()); + buf.append(sym.getType().getName(true)); + buf.append(getJavaReturnType().getName()); + if (containingCType != null) { + buf.append(containingCType.getName(true)); + } + + for (int i = 0; i < getNumArguments(); i++) { + JavaType type = getJavaArgumentType(i); + if (type.isVoid()) { + // Make sure this is the only param to the method; if it isn't, + // there's something wrong with our parsing of the headers. + assert(getNumArguments() == 1); + continue; + } + + buf.append(type.getName()); + } + return buf.toString().hashCode(); + } /** Returns the signature of this binding. */ public String toString() { StringBuffer buf = new StringBuffer(200); buf.append(getJavaReturnType().getName()); buf.append(" "); - buf.append(getRenamedMethodName()); + buf.append(getName()); buf.append("("); boolean needComma = false; for (int i = 0; i < getNumArguments(); i++) { diff --git a/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java b/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java index 4fe81af..314a9bb 100755 --- a/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java +++ b/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java @@ -50,9 +50,9 @@ import com.sun.gluegen.procaddress.*; /** Emitter producing NativeSignature attributes. */ public class NativeSignatureEmitter extends GLEmitter { - protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { + protected List generateMethodBindingEmitters(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception { // Allow superclass to do most of the work for us - List res = super.generateMethodBindingEmitters(sym); + List res = super.generateMethodBindingEmitters(methodBindingSet, sym); // Filter out all non-JavaMethodBindingEmitters for (Iterator iter = res.iterator(); iter.hasNext(); ) { diff --git a/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java index 12a6c0e..63d95fe 100755 --- a/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java @@ -474,9 +474,9 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding protected String getImplMethodName(boolean direct) { String name = null; if (direct) { - name = binding.getRenamedMethodName() + "$0"; + name = binding.getName() + "$0"; } else { - name = binding.getRenamedMethodName() + "$1"; + name = binding.getName() + "$1"; } if (bufferObjectVariant) { return name + "BufObj"; diff --git a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java index 89176f5..b52047b 100644 --- a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java +++ b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java @@ -330,15 +330,29 @@ public class BuildComposablePipeline PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file))); + List baseInterfaces = Arrays.asList(baseInterfaceClass.getInterfaces()); HashSet clazzList = new HashSet(); clazzList.add(baseInterfaceClass); - clazzList.addAll(Arrays.asList(baseInterfaceClass.getInterfaces())); + clazzList.addAll(baseInterfaces); + int ifNamesNumber = clazzList.size(); - String[] ifNames = new String[clazzList.size()]; + // keep original order .. + clazzList.clear(); + String[] ifNames = new String[ifNamesNumber]; { int i=0; - for (Iterator iter=clazzList.iterator(); iter.hasNext(); ) { - ifNames[i++] = new String(((Class)iter.next()).getName()); + + for (Iterator iter=baseInterfaces.iterator(); iter.hasNext(); ) { + Class ifClass = (Class)iter.next(); + if(!clazzList.contains(ifClass)) { + ifNames[i++] = new String(ifClass.getName()); + clazzList.add(ifClass); + } + } + + if(null!=baseInterfaceClass && !clazzList.contains(baseInterfaceClass)) { + ifNames[i++] = new String(baseInterfaceClass.getName()); + clazzList.add(baseInterfaceClass); } } @@ -619,6 +633,7 @@ public class BuildComposablePipeline emitGLIsMethod(output, "GLES2"); emitGLIsMethod(output, "GL2ES1"); emitGLIsMethod(output, "GL2ES2"); + emitGLIsMethod(output, "GL2GL3"); output.println(" public boolean isGLES() {"); output.println(" return isGLES2() || isGLES1();"); output.println(" }"); @@ -648,6 +663,7 @@ public class BuildComposablePipeline emitGLGetMethod(output, "GLES2"); emitGLGetMethod(output, "GL2ES1"); emitGLGetMethod(output, "GL2ES2"); + emitGLGetMethod(output, "GL2GL3"); output.println(" public GLProfile getGLProfile() {"); output.println(" return "+getDownstreamObjectName()+".getGLProfile();"); output.println(" }"); @@ -744,9 +760,9 @@ public class BuildComposablePipeline output.println(" * "); output.println("<PRE>"); if(null!=prologNameOpt) { - output.println(" drawable.setGL( new "+className+"( drawable.getGL().getGL2ES2(), new "+prologNameOpt+"( drawable.getGL().getGL2ES2() ) ) );"); + output.println(" GL gl = drawable.setGL( new "+className+"( drawable.getGL().getGL2ES2(), new "+prologNameOpt+"( drawable.getGL().getGL2ES2() ) ) );"); } else { - output.println(" drawable.setGL( new "+className+"( drawable.getGL().getGL2ES2() ) );"); + output.println(" GL gl = drawable.setGL( new "+className+"( drawable.getGL().getGL2ES2() ) );"); } output.println("</PRE>"); output.println("*/"); @@ -896,7 +912,7 @@ public class BuildComposablePipeline output.println(" Sample code which installs this pipeline: </P>"); output.println(); output.println("<PRE>"); - output.println(" drawable.setGL(new DebugGL(drawable.getGL()));"); + output.println(" GL gl = drawable.setGL(new DebugGL(drawable.getGL()));"); output.println("</PRE>"); output.println("*/"); } @@ -1034,7 +1050,7 @@ public class BuildComposablePipeline output.println(" before and after each OpenGL method call. Sample code which installs this pipeline: </P>"); output.println(); output.println("<PRE>"); - output.println(" drawable.setGL(new TraceGL(drawable.getGL(), System.err));"); + output.println(" GL gl = drawable.setGL(new TraceGL(drawable.getGL(), System.err));"); output.println("</PRE>"); output.println("*/"); } @@ -1055,7 +1071,7 @@ public class BuildComposablePipeline output.println("printIndent();"); } - output.print(" println("); + output.print(" print("); printFunctionCallString(output, m); output.println(");"); } @@ -1093,10 +1109,10 @@ public class BuildComposablePipeline } else if(params[i].equals(int.class)) { output.print("+\"<"+params[i].getName()+"> 0x\"+Integer.toHexString(arg"+i+").toUpperCase()"); } else { - output.print("+\"<"+params[i].getName()+">\"+arg"+i); + output.print("+\"<"+params[i].getName()+"> \"+arg"+i); } if ( i < params.length-1) { - output.print("+\",\""); + output.print("+\", \""); } } output.print("+\")\""); diff --git a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java index 4226f46..a6c0cfc 100644 --- a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java +++ b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java @@ -91,17 +91,23 @@ import java.util.regex.*; public class BuildStaticGLInfo { // Handles function pointer + protected static int funcIdentifierGroup = 10; protected static Pattern funcPattern = - Pattern.compile("^(GLAPI|GL_API|GL_APICALL|EGLAPI|extern)?(\\s*)(\\w+)(\\*)?(\\s+)(GLAPIENTRY|GL_APIENTRY|APIENTRY|EGLAPIENTRY|WINAPI)?(\\s*)([ew]?gl\\w+)\\s?(\\(.*)"); + Pattern.compile("^(GLAPI|GL_API|GL_APICALL|EGLAPI|extern)?(\\s*)((unsigned|const)\\s+)?(\\w+)(\\s*\\*)?(\\s+)(GLAPIENTRY|GL_APIENTRY|APIENTRY|EGLAPIENTRY|WINAPI)?(\\s*)([ew]?gl\\w+)\\s?(\\(.*)"); + protected static Pattern associationPattern = - Pattern.compile("\\#ifndef ([EW]?GL[X]?_[A-Za-z0-9_]+)"); + Pattern.compile("\\#ifndef ([CEW]?GL[XU]?_[A-Za-z0-9_]+)(.*)"); + + protected static int defineIdentifierGroup = 1; protected static Pattern definePattern = - Pattern.compile("\\#define ([EW]?GL[X]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)"); + Pattern.compile("\\#define ([CEW]?GL[XU]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)(.*)"); + // Maps function / #define names to the names of the extensions they're declared in protected Map declarationToExtensionMap = new HashMap(); // Maps extension names to Set of identifiers (both #defines and // function names) this extension declares protected Map/*<String, Set<String>*/ extensionToDeclarationMap = new HashMap(); + protected boolean debug = false; /** * The first argument is the package to which the StaticGLInfo class @@ -113,6 +119,7 @@ public class BuildStaticGLInfo { if (args.length > 0 && args[0].equals("-test")) { BuildStaticGLInfo builder = new BuildStaticGLInfo(); + builder.setDebug(true); String[] newArgs = new String[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); builder.parse(newArgs); @@ -157,6 +164,9 @@ public class BuildStaticGLInfo } } + public void setDebug(boolean v) { + debug = v; + } /** Parses the supplied C header files and adds the function associations contained therein to the internal map. */ @@ -173,14 +183,20 @@ public class BuildStaticGLInfo String line, activeAssociation = null; Matcher m = null; while ((line = reader.readLine()) != null) { + int type = 0; // 1-define, 2-function // see if we're inside a #ifndef GL_XXX block and matching a function if (activeAssociation != null) { String identifier = null; if ((m = funcPattern.matcher(line)).matches()) { - identifier = m.group(8); + identifier = m.group(funcIdentifierGroup).trim(); + type =2; } else if ((m = definePattern.matcher(line)).matches()) { - identifier = m.group(1); + identifier = m.group(defineIdentifierGroup).trim(); + type =1; } else if (line.startsWith("#endif")) { + if(debug) { + System.err.println("END ASSOCIATION BLOCK: <" + activeAssociation + ">"); + } activeAssociation = null; } if ((identifier != null) && @@ -188,13 +204,17 @@ public class BuildStaticGLInfo // Handles #ifndef GL_... #define GL_... !identifier.equals(activeAssociation)) { addAssociation(identifier, activeAssociation); - // System.err.println(" ADDING ASSOCIATION: " + identifier + " " + activeAssociation); + if(debug) { + System.err.println(" ADDING ASSOCIATION: <" + identifier + "> <" + activeAssociation + "> ; type "+type); + } } } else if ((m = associationPattern.matcher(line)).matches()) { // found a new #ifndef GL_XXX block - activeAssociation = m.group(1); + activeAssociation = m.group(1).trim(); - // System.err.println("FOUND NEW ASSOCIATION BLOCK: " + activeAssociation); + if(debug) { + System.err.println("BEGIN ASSOCIATION BLOCK: <" + activeAssociation + ">"); + } } } reader.close(); @@ -204,12 +224,12 @@ public class BuildStaticGLInfo for (Iterator i1 = extensionToDeclarationMap.keySet().iterator(); i1.hasNext(); ) { String name = (String) i1.next(); Set decls = (Set) extensionToDeclarationMap.get(name); - System.out.println(name + ":"); + System.out.println("<"+name+"> :"); List l = new ArrayList(); l.addAll(decls); Collections.sort(l); for (Iterator i2 = l.iterator(); i2.hasNext(); ) { - System.out.println(" " + (String) i2.next()); + System.out.println(" <" + (String) i2.next() + ">"); } } } diff --git a/src/java/com/sun/gluegen/opengl/GLConfiguration.java b/src/java/com/sun/gluegen/opengl/GLConfiguration.java index 3013848..9352bcb 100755 --- a/src/java/com/sun/gluegen/opengl/GLConfiguration.java +++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java @@ -59,7 +59,8 @@ public class GLConfiguration extends ProcAddressConfiguration { // This directive is off by default but can help automatically // indicate which extensions have been folded into the core OpenGL // namespace, and if not, then why not - private boolean autoUnifyExtensions; + private boolean autoUnifyExtensions=false; + private boolean allowNonGLExtensions=false; public GLConfiguration(GLEmitter emitter) { super(); @@ -82,6 +83,10 @@ public class GLConfiguration extends ProcAddressConfiguration { String sym = readString("RenameExtensionIntoCore", tok, filename, lineNo); extensionsRenamedIntoCore.add(sym); } + else if (cmd.equalsIgnoreCase("AllowNonGLExtensions")) + { + allowNonGLExtensions = readBoolean("AllowNonGLExtensions", tok, filename, lineNo).booleanValue(); + } else if (cmd.equalsIgnoreCase("AutoUnifyExtensions")) { autoUnifyExtensions = readBoolean("AutoUnifyExtensions", tok, filename, lineNo).booleanValue(); @@ -209,14 +214,14 @@ public class GLConfiguration extends ProcAddressConfiguration { ignoredExtensions.contains(extension)) { return true; } - boolean isGLFunc = GLExtensionNames.isGLFunction(symbol); boolean isGLEnum = GLExtensionNames.isGLEnumeration(symbol); + boolean isGLFunc = GLExtensionNames.isGLFunction(symbol); if(isGLFunc || isGLEnum) { if(GLExtensionNames.isExtensionVEN(symbol, isGLFunc)) { String extSuffix = GLExtensionNames.getExtensionSuffix(symbol, isGLFunc); if( getDropUniqVendorExtensions(extSuffix) ) { if(DEBUG_IGNORES) { - System.err.println("Ignore UniqVendorEXT: "+symbol); + System.err.println("Ignore UniqVendorEXT: "+symbol+", vendor "+extSuffix); } return true; } @@ -249,6 +254,13 @@ public class GLConfiguration extends ProcAddressConfiguration { return autoUnifyExtensions; } + /** If true, accept all non encapsulated defines and functions, + * as it is mandatory for GL declarations. */ + public boolean getAllowNonGLExtensions() { + return allowNonGLExtensions; + } + + /** shall the non unified (uniq) vendor extensions be dropped ? */ public boolean getDropUniqVendorExtensions(String extName) { return dropUniqVendorExtensions.contains(extName); diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java index fff9d7e..4ca2e69 100644 --- a/src/java/com/sun/gluegen/opengl/GLEmitter.java +++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java @@ -85,9 +85,15 @@ public class GLEmitter extends ProcAddressEmitter // renaming mechanisms that are built elsewhere. GLConfiguration config = getGLConfig(); + Set extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore(); BuildStaticGLInfo glInfo = config.getGLInfo(); - for (Iterator iter = config.getExtensionsRenamedIntoCore().iterator(); - iter.hasNext(); ) { + if(null==glInfo) { + if(extensionsRenamedIntoCore.size()>0) { + throw new RuntimeException("ExtensionRenamedIntoCore (num: "+extensionsRenamedIntoCore.size()+"), but no GLHeader"); + } + return; + } + for (Iterator iter = extensionsRenamedIntoCore.iterator(); iter.hasNext(); ) { String extension = (String) iter.next(); Set/*<String>*/ declarations = glInfo.getDeclarations(extension); if (declarations != null) { @@ -305,6 +311,83 @@ public class GLEmitter extends ProcAddressEmitter return bufferObjectMethodBindings.containsKey(binding); } + public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if(null==glInfo) { + throw new Exception("No GLInfo for: "+def); + } + String symbolRenamed = def.getName(); + StringBuffer newComment = new StringBuffer(); + newComment.append("Part of <code>"); + if(0==addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, def.getAliasedNames())) { + if(def.isEnum()) { + String enumName = def.getEnumName(); + if(null!=enumName) { + newComment.append(enumName); + } else { + newComment.append("CORE ENUM"); + } + } else { + if(getGLConfig().getAllowNonGLExtensions()) { + newComment.append("CORE DEF"); + } else { + // Note: All GL defines must be contained within an extension marker ! + // #ifndef GL_EXT_lala + // #define GL_EXT_lala 1 + // ... + // #endif + if(JavaConfiguration.DEBUG_IGNORES) { + StringBuffer sb = new StringBuffer(); + JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, def.getAliasedNames()); + System.err.println("Dropping marker: "+sb.toString()); + } + return; + } + } + } + newComment.append("</code>"); + + if(null!=optionalComment) { + newComment.append("<br>"); + newComment.append(optionalComment); + } + + super.emitDefine(def, newComment.toString()); + } + + public int addExtensionsOfSymbols2Buffer(StringBuffer buf, String sep, String first, Collection col) { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if(null==glInfo) { + throw new RuntimeException("No GLInfo for: "+first); + } + int num = 0; + if(null==buf) buf=new StringBuffer(); + String extensionName; + + Iterator iter=col.iterator(); + if(null!=first) { + extensionName = glInfo.getExtension(first); + if(null!=extensionName) { + buf.append(extensionName); + if( iter.hasNext() ) { + buf.append(sep); + } + num++; + } + } + while( iter.hasNext() ) { + extensionName = glInfo.getExtension((String)iter.next()); + if(null!=extensionName) { + buf.append(extensionName); + if( iter.hasNext() ) { + buf.append(sep); + } + num++; + } + } + return num; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -319,10 +402,9 @@ public class GLEmitter extends ProcAddressEmitter for (Iterator iter = superEmitters.iterator(); iter.hasNext(); ) { JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) iter.next(); if (emitter instanceof ProcAddressJavaMethodBindingEmitter) { - emitters.add(new GLJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) emitter, this, bufferObjectVariant)); - } else { - emitters.add(emitter); + emitter = new GLJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) emitter, this, bufferObjectVariant); } + emitters.add(emitter); } } @@ -385,23 +467,4 @@ public class GLEmitter extends ProcAddressEmitter w.flush(); w.close(); } - - protected void emitProcAddressTableEntryForSymbol(FunctionSymbol cFunc) - { - emitProcAddressTableEntryForString(cFunc.getName()); - } - - protected void emitProcAddressTableEntryForString(String str) - { - // Deal gracefully with forced proc address generation in the face - // of having the function pointer typedef in the header file too - if (emittedTableEntries.contains(str)) - return; - emittedTableEntries.add(str); - tableWriter.print(" public long "); - tableWriter.print(PROCADDRESS_VAR_PREFIX); - tableWriter.print(str); - tableWriter.println(";"); - } - } diff --git a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java index c6a0309..662e75b 100755 --- a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java @@ -52,6 +52,7 @@ import com.sun.gluegen.procaddress.*; public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmitter { protected boolean bufferObjectVariant; protected GLEmitter glEmitter; + protected CommentEmitter glCommentEmitter = new GLCommentEmitter(); public GLJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, boolean callThroughProcAddress, @@ -66,6 +67,7 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit emitter); this.bufferObjectVariant = bufferObjectVariant; this.glEmitter=emitter; + setCommentEmitter(glCommentEmitter); } public GLJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap, @@ -74,6 +76,7 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit super(methodToWrap); this.bufferObjectVariant = bufferObjectVariant; this.glEmitter=emitter; + setCommentEmitter(glCommentEmitter); } public GLJavaMethodBindingEmitter(GLJavaMethodBindingEmitter methodToWrap) { @@ -100,4 +103,31 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit return name; } + + protected class GLCommentEmitter + extends JavaMethodBindingEmitter.DefaultCommentEmitter + { + protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) { + super.emitBindingCSignature(binding, writer); + + String symbolRenamed = binding.getName(); + StringBuffer newComment = new StringBuffer(); + newComment.append("<br>Part of <code>"); + if(0==glEmitter.addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, binding.getAliasedNames())) { + if(glEmitter.getGLConfig().getAllowNonGLExtensions()) { + newComment.append("CORE FUNC"); + } else { + StringBuffer sb = new StringBuffer(); + JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, binding.getAliasedNames()); + RuntimeException ex = new RuntimeException("Couldn't find extension to: "+binding+" ; "+sb.toString()); + ex.printStackTrace(); + glEmitter.getGLConfig().getGLInfo().dump(); + // glEmitter.getGLConfig().dumpRenames(); + throw ex; + } + } + newComment.append("</code>"); + writer.print(newComment.toString()); + } + } } diff --git a/src/java/com/sun/gluegen/pcpp/PCPP.java b/src/java/com/sun/gluegen/pcpp/PCPP.java index 4523032..7303c04 100644 --- a/src/java/com/sun/gluegen/pcpp/PCPP.java +++ b/src/java/com/sun/gluegen/pcpp/PCPP.java @@ -436,8 +436,10 @@ public class PCPP { System.err.println("WARNING: \"" + name + "\" redefined from \"" + oldDef + "\" to \"" + value + "\""); } + debugPrint(true, "#define " + name + " ["+oldDef+" ] -> "+value + " CONST"); //System.out.println("//---DEFINED: " + name + " to \"" + value + "\""); } else { + debugPrint(true, "#define " + name + " -> "+value + " SYMB"); // Value is a symbolic constant like "#define FOO BAR". // Try to look up the symbol's value String newValue = resolveDefine(value, true); @@ -501,15 +503,25 @@ public class PCPP { } private boolean checkHex(String s) { - for (int i = 2; i < s.length(); i++) { - char c = s.charAt(i); + char c='\0'; + int i; + for (i = 2; i < s.length(); i++) { + c = s.charAt(i); if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - return false; + break; } } - return true; + if(i==s.length()) { + return true; + } else if(i==s.length()-1) { + // Const qualifier .. + return c == 'l' || c == 'L' || + c == 'f' || c == 'F' || + c == 'u' || c == 'U' ; + } + return false; } private boolean checkDecimal(String s) { @@ -553,7 +565,7 @@ public class PCPP { String symbolName = nextWord(); debugPrint(true, (isIfdef ? "#ifdef " : "#ifndef ") + symbolName); boolean symbolIsDefined = defineMap.get(symbolName) != null; - //debugPrint(true, "HANDLE_IFDEF: ifdef(" + symbolName + ") = " + symbolIsDefined ); + debugPrint(true, (isIfdef ? "#ifdef " : "#ifndef ") + symbolName + "(defined: "+symbolIsDefined+")"); pushEnableBit(enabled() && symbolIsDefined == isIfdef); } @@ -808,7 +820,7 @@ public class PCPP { private void pushEnableBit(boolean enabled) { enabledBits.add(new Boolean(enabled)); ++debugPrintIndentLevel; - //debugPrint(false, "PUSH_ENABLED, NOW: " + enabled()); + debugPrint(false, "PUSH_ENABLED, NOW: " + enabled()); } private void popEnableBit() { @@ -818,7 +830,7 @@ public class PCPP { } enabledBits.remove(enabledBits.size() - 1); --debugPrintIndentLevel; - //debugPrint(false, "POP_ENABLED, NOW: " + enabled()); + debugPrint(false, "POP_ENABLED, NOW: " + enabled()); } private boolean enabled() { diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java index b7aadc9..54263a5 100755 --- a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java @@ -66,14 +66,6 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { return super.getName(); } } - - public String getRenamedMethodName() { - if (callThroughProcAddress) { - return ProcAddressEmitter.WRAP_PREFIX + super.getRenamedMethodName(); - } else { - return super.getRenamedMethodName(); - } - } }, methodToWrap.getDefaultOutput(), methodToWrap.getJavaPackageName(), diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java index 8f849ac..871dc5e 100755 --- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java +++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java @@ -102,23 +102,21 @@ public class ProcAddressEmitter extends JavaEmitter return new ProcAddressConfiguration(); } - protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception - { - return generateMethodBindingEmittersImpl(sym); + protected List generateMethodBindingEmitters(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception { + return generateMethodBindingEmittersImpl(methodBindingSet, sym); } protected boolean needsModifiedEmitters(FunctionSymbol sym) { if (!needsProcAddressWrapper(sym) || - getConfig().isUnimplemented(sym.getName())) { + getConfig().isUnimplemented(getAliasedSymName(sym))) { return false; } return true; } - private List generateMethodBindingEmittersImpl(FunctionSymbol sym) throws Exception - { - List defaultEmitters = super.generateMethodBindingEmitters(sym); + private List generateMethodBindingEmittersImpl(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception { + List defaultEmitters = super.generateMethodBindingEmitters(methodBindingSet, sym); // if the superclass didn't generate any bindings for the symbol, let's // honor that (for example, the superclass might have caught an Ignore @@ -140,7 +138,7 @@ public class ProcAddressEmitter extends JavaEmitter if (needsProcAddressWrapper(sym)) { if (getProcAddressConfig().emitProcAddressTable()) { // emit an entry in the GL proc address table for this method. - emitProcAddressTableEntryForSymbol(sym); + emitProcAddressTableEntryForString(getAliasedSymName(sym)); } } @@ -254,9 +252,15 @@ public class ProcAddressEmitter extends JavaEmitter emitters.add(res); } + private String getAliasedSymName(FunctionSymbol sym) { + String symName = getConfig().getJavaSymbolRename(sym.getName()); + if(null==symName) symName=sym.getName(); + return symName; + } + protected boolean needsProcAddressWrapper(FunctionSymbol sym) { - String symName = sym.getName(); + String symName = getAliasedSymName(sym); ProcAddressConfiguration config = getProcAddressConfig(); @@ -378,11 +382,6 @@ public class ProcAddressEmitter extends JavaEmitter w.close(); } - protected void emitProcAddressTableEntryForSymbol(FunctionSymbol cFunc) - { - emitProcAddressTableEntryForString(cFunc.getName()); - } - protected void emitProcAddressTableEntryForString(String str) { // Deal gracefully with forced proc address generation in the face diff --git a/src/java/com/sun/gluegen/runtime/CPU.java b/src/java/com/sun/gluegen/runtime/CPU.java index 0456e9f..ee6c9f5 100755 --- a/src/java/com/sun/gluegen/runtime/CPU.java +++ b/src/java/com/sun/gluegen/runtime/CPU.java @@ -38,6 +38,7 @@ */ package com.sun.gluegen.runtime; +import java.security.*; /** Provides information to autogenerated struct accessors about what kind of data model (32- or 64-bit) is being used by the currently @@ -47,39 +48,67 @@ public class CPU { private static boolean is32Bit; static { - // We don't seem to need an AccessController.doPrivileged() block - // here as these system properties are visible even to unsigned - // applets - // Note: this code is replicated in StructLayout.java - String os = System.getProperty("os.name").toLowerCase(); - String cpu = System.getProperty("os.arch").toLowerCase(); - if ((os.startsWith("windows") && cpu.equals("x86")) || - (os.startsWith("windows") && cpu.equals("arm")) || - (os.startsWith("linux") && cpu.equals("i386")) || - (os.startsWith("linux") && cpu.equals("x86")) || - (os.startsWith("mac os") && cpu.equals("ppc")) || - (os.startsWith("mac os") && cpu.equals("i386")) || - (os.startsWith("darwin") && cpu.equals("ppc")) || - (os.startsWith("darwin") && cpu.equals("i386")) || - (os.startsWith("sunos") && cpu.equals("sparc")) || - (os.startsWith("sunos") && cpu.equals("x86")) || - (os.startsWith("freebsd") && cpu.equals("i386")) || - (os.startsWith("hp-ux") && cpu.equals("pa_risc2.0"))) { - is32Bit = true; - } else if ((os.startsWith("windows") && cpu.equals("amd64")) || - (os.startsWith("linux") && cpu.equals("amd64")) || - (os.startsWith("linux") && cpu.equals("x86_64")) || - (os.startsWith("linux") && cpu.equals("ia64")) || - (os.startsWith("mac os") && cpu.equals("x86_64")) || - (os.startsWith("darwin") && cpu.equals("x86_64")) || - (os.startsWith("sunos") && cpu.equals("sparcv9")) || - (os.startsWith("sunos") && cpu.equals("amd64"))) { - } else { - throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os + "/" + cpu + ")"); + NativeLibrary.ensureNativeLibLoaded(); + + boolean done=false; + + // Try to use Sun's sun.arch.data.model first .. + int bits = getPointerSizeInBits(); + if ( 32 == bits || 64 == bits ) { + is32Bit = ( 32 == bits ); + done = true ; + } + + if(!done) { + // We don't seem to need an AccessController.doPrivileged() block + // here as these system properties are visible even to unsigned + // applets + // Note: this code is replicated in StructLayout.java + String os = System.getProperty("os.name").toLowerCase(); + String cpu = System.getProperty("os.arch").toLowerCase(); + + if(!done) { + if ((os.startsWith("windows") && cpu.equals("x86")) || + (os.startsWith("windows") && cpu.equals("arm")) || + (os.startsWith("linux") && cpu.equals("i386")) || + (os.startsWith("linux") && cpu.equals("x86")) || + (os.startsWith("mac os") && cpu.equals("ppc")) || + (os.startsWith("mac os") && cpu.equals("i386")) || + (os.startsWith("darwin") && cpu.equals("ppc")) || + (os.startsWith("darwin") && cpu.equals("i386")) || + (os.startsWith("sunos") && cpu.equals("sparc")) || + (os.startsWith("sunos") && cpu.equals("x86")) || + (os.startsWith("freebsd") && cpu.equals("i386")) || + (os.startsWith("hp-ux") && cpu.equals("pa_risc2.0"))) { + is32Bit = true; + done = true; + } + } + + if(!done) { + if ((os.startsWith("windows") && cpu.equals("amd64")) || + (os.startsWith("linux") && cpu.equals("amd64")) || + (os.startsWith("linux") && cpu.equals("x86_64")) || + (os.startsWith("linux") && cpu.equals("ia64")) || + (os.startsWith("mac os") && cpu.equals("x86_64")) || + (os.startsWith("darwin") && cpu.equals("x86_64")) || + (os.startsWith("sunos") && cpu.equals("sparcv9")) || + (os.startsWith("sunos") && cpu.equals("amd64"))) { + is32Bit = false; + done = true; + } + } + + if(!done) { + throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os + "/" + cpu + ")"); + } } } public static boolean is32Bit() { return is32Bit; } + + public static native int getPointerSizeInBits(); + } diff --git a/src/java/com/sun/gluegen/runtime/NativeLibrary.java b/src/java/com/sun/gluegen/runtime/NativeLibrary.java index 22063a5..c4c9f25 100755 --- a/src/java/com/sun/gluegen/runtime/NativeLibrary.java +++ b/src/java/com/sun/gluegen/runtime/NativeLibrary.java @@ -412,7 +412,7 @@ public class NativeLibrary { } private static volatile boolean loadedDynLinkNativeLib; - private static void ensureNativeLibLoaded() { + static void ensureNativeLibLoaded() { if (!loadedDynLinkNativeLib) { synchronized (NativeLibrary.class) { if (!loadedDynLinkNativeLib) { diff --git a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java index 1c180bd..ba77eed 100644 --- a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java +++ b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java @@ -8,9 +8,11 @@ public class TestPointerBufferEndian { public static void main (String[] args) { boolean direct = args.length>0 && args[0].equals("-direct"); boolean ok = true; + int bitsPtr = CPU.getPointerSizeInBits(); + String bitsProp = System.getProperty("sun.arch.data.model"); String os = System.getProperty("os.name"); String cpu = System.getProperty("os.arch"); - System.out.println("OS: <"+os+"> CPU: <"+cpu+">"); + System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); System.out.println("CPU is: "+ (CPU.is32Bit()?"32":"64") + " bit"); System.out.println("Buffer is in: "+ (BufferFactory.isLittleEndian()?"little":"big") + " endian"); PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(3); diff --git a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java index 4f05256..dc53a10 100644 --- a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java +++ b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java @@ -7,9 +7,11 @@ import java.nio.*; public class TestStructAccessorEndian { public static void main (String args[]) { boolean ok = true; + int bitsPtr = CPU.getPointerSizeInBits(); + String bitsProp = System.getProperty("sun.arch.data.model"); String os = System.getProperty("os.name"); String cpu = System.getProperty("os.arch"); - System.out.println("OS: <"+os+"> CPU: <"+cpu+">"); + System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); System.out.println("CPU is: "+ (CPU.is32Bit()?"32":"64") + " bit"); System.out.println("Buffer is in: "+ (BufferFactory.isLittleEndian()?"little":"big") + " endian"); ByteBuffer tst = BufferFactory.newDirectByteBuffer(BufferFactory.SIZEOF_LONG * 3); |