aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-08-05 07:31:49 -0700
committerSven Gothel <[email protected]>2009-08-05 07:31:49 -0700
commitaac675e3ae8be73d3e498cc8f1062a20839f8482 (patch)
treedbf68c2183499179a28632b2d3dbc491e0f225dd /src/java/com
parentedaf82f5a86cd3e239072608e5299a9553ece32c (diff)
Cleanup for a better OpenGL 3.2 integration,
for subsuming extensions: - Allow RenameExtensionIntoCore generate duplicate names, ie those will not be generated. - Add proper comment showing the extension of the symbol. - Fail if no 'GLHeader' is specified, but we are processing a GL/ProcAddress config - Fail if a GL function is not part of an extension MethodBinding, ConstantDefinition cleanup: - getName() returns the renamed name - getOrigName() returns the original - getAliasedNames() returns the aliased ones MethodBinding: - Change: equals() operates on renamed name - Add: hashCode() function - same criteria as equals() Impact: - All config options etc shall trigger with the renamed name, but ignore, rename etc. - Generated Java impl. uses the renamed base name as well Change: emitDefine() uses the ConstantDefinition Add: JavaConfiguration: dumpRenames() Change JavaConfiguration.shouldIgnoreInInterface/Impl(): - respect the renamed symbol name as well Change JavaEmitter.emitFunctions(): - only emit a generated MethodBinding once, therefor store emitted method bindings in a HashSet Fix BuildStaticGLInfo: - Allow white space at the end of #ifndef and #define - Trim strings - Allow 'const' qualifier in function pattern Fix GLEmitter: - Fail if no 'GLHeader' is specified, but a RenameIntoCore option .. - Don't emit marker defines, marking an extension (ie not part of an extension) Fix GLJavaMethodBindingEmitter: - Fail if a GL function is not part of an extension Fix PCPP: - Pass constant type qualifiers for hex-constants: 'l' 'L' ... Fix ProcAddressEmitter: - Operate on the aliased/renamed name for querying ProcAddress usage and generating code.
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/sun/gluegen/CMethodBindingEmitter.java2
-rw-r--r--src/java/com/sun/gluegen/ConstantDefinition.java28
-rw-r--r--src/java/com/sun/gluegen/DebugEmitter.java4
-rw-r--r--src/java/com/sun/gluegen/GlueEmitter.java2
-rw-r--r--src/java/com/sun/gluegen/GlueGen.java4
-rw-r--r--src/java/com/sun/gluegen/JavaConfiguration.java16
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java46
-rw-r--r--src/java/com/sun/gluegen/JavaMethodBindingEmitter.java6
-rw-r--r--src/java/com/sun/gluegen/MethodBinding.java54
-rwxr-xr-xsrc/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java4
-rwxr-xr-xsrc/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java4
-rw-r--r--src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java40
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLConfiguration.java11
-rw-r--r--src/java/com/sun/gluegen/opengl/GLEmitter.java92
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java19
-rw-r--r--src/java/com/sun/gluegen/pcpp/PCPP.java26
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java8
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java27
18 files changed, 277 insertions, 116 deletions
diff --git a/src/java/com/sun/gluegen/CMethodBindingEmitter.java b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
index 02680d0..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();
}
/**
diff --git a/src/java/com/sun/gluegen/ConstantDefinition.java b/src/java/com/sun/gluegen/ConstantDefinition.java
index e06903b..60f5cef 100644
--- a/src/java/com/sun/gluegen/ConstantDefinition.java
+++ b/src/java/com/sun/gluegen/ConstantDefinition.java
@@ -38,6 +38,8 @@ 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 String enumName;
@@ -46,9 +48,11 @@ public class ConstantDefinition {
public ConstantDefinition(String name,
String value,
String enumName) {
+ this.origName = name;
this.name = name;
this.value = value;
this.enumName = enumName;
+ this.aliasedNames=new HashSet();
}
public boolean equals(ConstantDefinition other) {
@@ -72,7 +76,29 @@ 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. */
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..9221c3a 100644
--- a/src/java/com/sun/gluegen/GlueGen.java
+++ b/src/java/com/sun/gluegen/GlueGen.java
@@ -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 a1fe732..636cef8 100644
--- a/src/java/com/sun/gluegen/JavaConfiguration.java
+++ b/src/java/com/sun/gluegen/JavaConfiguration.java
@@ -598,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 (extendedIntfSymbolsIgnore.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);
}
@@ -625,7 +634,8 @@ public class JavaConfiguration {
}
if (!extendedIntfSymbolsOnly.isEmpty()) {
- if(!extendedIntfSymbolsOnly.contains(symbol)) {
+ if(!extendedIntfSymbolsOnly.contains(symbol) &&
+ !extendedIntfSymbolsOnly.contains(getJavaSymbolRename(symbol))) {
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl !extended: " + symbol);
}
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/BuildStaticGLInfo.java b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java
index 4226f46..f5193dc 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 = 9;
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*)(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 ([EW]?GL[X]?_[A-Za-z0-9_]+)\\s*");
+
+ 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 ([EW]?GL[X]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)\\s*");
+
// 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 923dcf5..4e8c0c3 100755
--- a/src/java/com/sun/gluegen/opengl/GLConfiguration.java
+++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
@@ -202,13 +202,6 @@ public class GLConfiguration extends ProcAddressConfiguration {
super.dumpIgnores();
}
- protected String getExtension(String symbol) {
- if (glInfo != null) {
- return glInfo.getExtension(symbol);
- }
- return null;
- }
-
protected boolean shouldIgnoreExtension(String symbol, boolean criteria) {
if (criteria && glInfo != null) {
String extension = glInfo.getExtension(symbol);
@@ -216,14 +209,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;
}
diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java
index 83e688e..9e32026 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,19 +311,68 @@ public class GLEmitter extends ProcAddressEmitter
return bufferObjectMethodBindings.containsKey(binding);
}
- public void emitDefine(String name, String value, String optionalComment) throws Exception {
- String extensionName = getGLConfig().getExtension(name);
+ 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();
- if(null!=extensionName) {
- newComment.append("Part of <code>"+extensionName+"</code>");
- } else {
- newComment.append("Part of <code>unknown extension</code>");
+ newComment.append("Part of <code>");
+ if(0==addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, def.getAliasedNames())) {
+ // Note: All GL enums 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(" ");
newComment.append(optionalComment);
}
- super.emitDefine(name, value, newComment.toString());
+
+ 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;
}
//----------------------------------------------------------------------
@@ -399,23 +454,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 b952272..5e8bada 100755
--- a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
@@ -109,12 +109,21 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit
{
protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) {
super.emitBindingCSignature(binding, writer);
- String extensionName = glEmitter.getGLConfig().getExtension(binding.getCSymbol().getName());
- if(null!=extensionName) {
- writer.print("<br>Part of <code>"+extensionName+"</code>");
- } else {
- writer.print("<br>Part of <code>unknown extension</code>");
+
+ String symbolRenamed = binding.getName();
+ StringBuffer newComment = new StringBuffer();
+ newComment.append("Part of <code>");
+ if(0==glEmitter.addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, binding.getAliasedNames())) {
+ 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