From 44f869b292f858cf9ad8c893ae30d39fadda1102 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Wed, 2 Dec 2009 00:14:46 +0100 Subject: continued with code cleanup in com.sun.gluegen.cgram and com.sun.gluegen.opengl packages. --- .../com/sun/gluegen/opengl/BuildStaticGLInfo.java | 44 +++++---- .../com/sun/gluegen/opengl/GLConfiguration.java | 104 +++++++++------------ src/java/com/sun/gluegen/opengl/GLEmitter.java | 45 +++++---- .../gluegen/opengl/GLJavaMethodBindingEmitter.java | 8 +- 4 files changed, 92 insertions(+), 109 deletions(-) diff --git a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java index a6c0cfc97..8653b076e 100644 --- a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java +++ b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java @@ -103,10 +103,11 @@ public class BuildStaticGLInfo 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(); + protected Map declarationToExtensionMap = new HashMap(); + // Maps extension names to Set of identifiers (both #defines and // function names) this extension declares - protected Map/**/ extensionToDeclarationMap = new HashMap(); + protected Map> extensionToDeclarationMap = new HashMap>(); protected boolean debug = false; /** @@ -221,28 +222,27 @@ public class BuildStaticGLInfo } public void dump() { - for (Iterator i1 = extensionToDeclarationMap.keySet().iterator(); i1.hasNext(); ) { - String name = (String) i1.next(); - Set decls = (Set) extensionToDeclarationMap.get(name); + for (String name : extensionToDeclarationMap.keySet()) { + Set decls = extensionToDeclarationMap.get(name); System.out.println("<"+name+"> :"); - List l = new ArrayList(); + List l = new ArrayList(); l.addAll(decls); Collections.sort(l); - for (Iterator i2 = l.iterator(); i2.hasNext(); ) { - System.out.println(" <" + (String) i2.next() + ">"); + for (String str : l) { + System.out.println(" <" + str + ">"); } } } public String getExtension(String identifier) { - return (String) declarationToExtensionMap.get(identifier); + return declarationToExtensionMap.get(identifier); } - public Set/**/ getDeclarations(String extension) { - return (Set) extensionToDeclarationMap.get(extension); + public Set getDeclarations(String extension) { + return extensionToDeclarationMap.get(extension); } - public Set/**/ getExtensions() { + public Set getExtensions() { return extensionToDeclarationMap.keySet(); } @@ -298,8 +298,7 @@ public class BuildStaticGLInfo // Compute max capacity int maxCapacity = 0; - for (Iterator iter = declarationToExtensionMap.keySet().iterator(); iter.hasNext(); ) { - String name = (String) iter.next(); + for (String name : declarationToExtensionMap.keySet()) { if (!name.startsWith("GL")) { ++maxCapacity; } @@ -307,18 +306,17 @@ public class BuildStaticGLInfo output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity"); output.println(" String group;"); - ArrayList sets = new ArrayList(extensionToDeclarationMap.keySet()); + ArrayList sets = new ArrayList(extensionToDeclarationMap.keySet()); Collections.sort(sets); - for (Iterator iter = sets.iterator(); iter.hasNext(); ) { - String groupName = (String) iter.next(); - Set funcs = (Set) extensionToDeclarationMap.get(groupName); - List l = new ArrayList(); + for (String groupName : sets) { + Set funcs = extensionToDeclarationMap.get(groupName); + List l = new ArrayList(); l.addAll(funcs); Collections.sort(l); - Iterator funcIter = l.iterator(); + Iterator funcIter = l.iterator(); boolean printedHeader = false; while (funcIter.hasNext()) { - String funcName = (String)funcIter.next(); + String funcName = funcIter.next(); if (!funcName.startsWith("GL")) { if (!printedHeader) { output.println(); @@ -343,9 +341,9 @@ public class BuildStaticGLInfo protected void addAssociation(String identifier, String association) { declarationToExtensionMap.put(identifier, association); - Set/**/ identifiers = (Set) extensionToDeclarationMap.get(association); + Set identifiers = extensionToDeclarationMap.get(association); if (identifiers == null) { - identifiers = new HashSet/**/(); + identifiers = new HashSet(); extensionToDeclarationMap.put(association, identifiers); } identifiers.add(identifier); diff --git a/src/java/com/sun/gluegen/opengl/GLConfiguration.java b/src/java/com/sun/gluegen/opengl/GLConfiguration.java index 9352bcba2..5e7ef7a89 100755 --- a/src/java/com/sun/gluegen/opengl/GLConfiguration.java +++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java @@ -48,14 +48,14 @@ import com.sun.gluegen.runtime.opengl.GLExtensionNames; public class GLConfiguration extends ProcAddressConfiguration { // The following data members support ignoring an entire extension at a time - private List/**/ glHeaders = new ArrayList(); - private Set/**/ ignoredExtensions = new HashSet(); - private Set/**/ extensionsRenamedIntoCore = new HashSet(); + private List glHeaders = new ArrayList(); + private Set ignoredExtensions = new HashSet(); + private Set extensionsRenamedIntoCore = new HashSet(); private BuildStaticGLInfo glInfo; // Maps function names to the kind of buffer object it deals with - private Map/**/ bufferObjectKinds = new HashMap(); + private Map bufferObjectKinds = new HashMap(); private GLEmitter emitter; - private Set/*String*/ dropUniqVendorExtensions = new HashSet(); + private Set dropUniqVendorExtensions = new HashSet(); // 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 @@ -72,44 +72,30 @@ public class GLConfiguration extends ProcAddressConfiguration { } } - protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException { - if (cmd.equalsIgnoreCase("IgnoreExtension")) - { - String sym = readString("IgnoreExtension", tok, filename, lineNo); - ignoredExtensions.add(sym); - } - else if (cmd.equalsIgnoreCase("RenameExtensionIntoCore")) - { - 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(); - } - else if (cmd.equalsIgnoreCase("GLHeader")) - { - String sym = readString("GLHeader", tok, filename, lineNo); - glHeaders.add(sym); - } - else if (cmd.equalsIgnoreCase("BufferObjectKind")) - { - readBufferObjectKind(tok, filename, lineNo); - } - else if (cmd.equalsIgnoreCase("DropUniqVendorExtensions")) - { - String sym = readString("DropUniqVendorExtensions", tok, filename, lineNo); - dropUniqVendorExtensions.add(sym); - } - else - { - super.dispatch(cmd,tok,file,filename,lineNo); - } - } + @Override + protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException { + if (cmd.equalsIgnoreCase("IgnoreExtension")) { + String sym = readString("IgnoreExtension", tok, filename, lineNo); + ignoredExtensions.add(sym); + } else if (cmd.equalsIgnoreCase("RenameExtensionIntoCore")) { + 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(); + } else if (cmd.equalsIgnoreCase("GLHeader")) { + String sym = readString("GLHeader", tok, filename, lineNo); + glHeaders.add(sym); + } else if (cmd.equalsIgnoreCase("BufferObjectKind")) { + readBufferObjectKind(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("DropUniqVendorExtensions")) { + String sym = readString("DropUniqVendorExtensions", tok, filename, lineNo); + dropUniqVendorExtensions.add(sym); + } else { + super.dispatch(cmd, tok, file, filename, lineNo); + } + } protected void readBufferObjectKind(StringTokenizer tok, String filename, int lineNo) { try { @@ -140,12 +126,10 @@ public class GLConfiguration extends ProcAddressConfiguration { /** Overrides javaPrologueForMethod in superclass and automatically generates prologue code for functions associated with buffer objects. */ - public List/**/ javaPrologueForMethod(MethodBinding binding, - boolean forImplementingMethodCall, - boolean eraseBufferAndArrayTypes) { - List/**/ res = super.javaPrologueForMethod(binding, - forImplementingMethodCall, - eraseBufferAndArrayTypes); + @Override + public List javaPrologueForMethod(MethodBinding binding, boolean forImplementingMethodCall, boolean eraseBufferAndArrayTypes) { + + List res = super.javaPrologueForMethod(binding, forImplementingMethodCall, eraseBufferAndArrayTypes); GLEmitter.BufferObjectKind kind = getBufferObjectKind(binding.getName()); if (kind != null) { // Need to generate appropriate prologue based on both buffer @@ -154,7 +138,7 @@ public class GLConfiguration extends ProcAddressConfiguration { // // NOTE we MUST NOT mutate the array returned from the super // call! - ArrayList res2 = new ArrayList(); + ArrayList res2 = new ArrayList(); if (res != null) { res2.addAll(res); } @@ -187,8 +171,8 @@ public class GLConfiguration extends ProcAddressConfiguration { // Must also filter out bogus rangeCheck directives for VBO/PBO // variants if (emitter.isBufferObjectMethodBinding(binding)) { - for (Iterator iter = res.iterator(); iter.hasNext(); ) { - String line = (String) iter.next(); + for (Iterator iter = res.iterator(); iter.hasNext(); ) { + String line = iter.next(); if (line.indexOf("BufferFactory.rangeCheck") >= 0) { iter.remove(); } @@ -199,10 +183,11 @@ public class GLConfiguration extends ProcAddressConfiguration { return res; } + @Override public void dumpIgnores() { System.err.println("GL Ignored extensions: "); - for (Iterator iter = ignoredExtensions.iterator(); iter.hasNext(); ) { - System.err.println("\t"+(String)iter.next()); + for (String str : ignoredExtensions) { + System.err.println("\t"+str); } super.dumpIgnores(); } @@ -231,6 +216,7 @@ public class GLConfiguration extends ProcAddressConfiguration { return false; } + @Override public boolean shouldIgnoreInInterface(String symbol) { return shouldIgnoreInInterface(symbol, true); } @@ -239,6 +225,7 @@ public class GLConfiguration extends ProcAddressConfiguration { return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInInterface(symbol); } + @Override public boolean shouldIgnoreInImpl(String symbol) { return shouldIgnoreInImpl(symbol, true); } @@ -268,8 +255,8 @@ public class GLConfiguration extends ProcAddressConfiguration { /** Returns the kind of buffer object this function deals with, or null if none. */ - public GLEmitter.BufferObjectKind getBufferObjectKind(String name) { - return (GLEmitter.BufferObjectKind) bufferObjectKinds.get(name); + GLEmitter.BufferObjectKind getBufferObjectKind(String name) { + return bufferObjectKinds.get(name); } public boolean isBufferObjectFunction(String name) { @@ -281,8 +268,7 @@ public class GLConfiguration extends ProcAddressConfiguration { public void parseGLHeaders(GlueEmitterControls controls) throws IOException { if (!glHeaders.isEmpty()) { glInfo = new BuildStaticGLInfo(); - for (Iterator iter = glHeaders.iterator(); iter.hasNext(); ) { - String file = (String) iter.next(); + for (String file : glHeaders) { String fullPath = controls.findHeaderFile(file); if (fullPath == null) { throw new IOException("Unable to locate header file \"" + file + "\""); @@ -303,7 +289,7 @@ public class GLConfiguration extends ProcAddressConfiguration { constant definitions and functions renamed into the core namespace; for example, glGenFramebuffersEXT to glGenFramebuffers and GL_FRAMEBUFFER_EXT to GL_FRAMEBUFFER. */ - public Set/**/ getExtensionsRenamedIntoCore() { + public Set getExtensionsRenamedIntoCore() { return extensionsRenamedIntoCore; } } diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java index 4ca2e698b..ff307c432 100644 --- a/src/java/com/sun/gluegen/opengl/GLEmitter.java +++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java @@ -45,20 +45,20 @@ import java.util.*; import com.sun.gluegen.*; import com.sun.gluegen.cgram.types.*; import com.sun.gluegen.procaddress.*; -import com.sun.gluegen.runtime.*; import com.sun.gluegen.runtime.opengl.GLExtensionNames; /** * A subclass of ProcAddressEmitter with special OpenGL-specific * configuration abilities. */ -public class GLEmitter extends ProcAddressEmitter -{ +public class GLEmitter extends ProcAddressEmitter { + // Keeps track of which MethodBindings were created for handling // Buffer Object variants. Used as a Set rather than a Map. - private Map/**/ bufferObjectMethodBindings = new IdentityHashMap(); + private Map bufferObjectMethodBindings = new IdentityHashMap(); static class BufferObjectKind { + private BufferObjectKind() {} static final BufferObjectKind UNPACK_PIXEL = new BufferObjectKind(); @@ -67,8 +67,8 @@ public class GLEmitter extends ProcAddressEmitter static final BufferObjectKind ELEMENT = new BufferObjectKind(); } - public void beginEmission(GlueEmitterControls controls) throws IOException - { + @Override + public void beginEmission(GlueEmitterControls controls) throws IOException { getGLConfig().parseGLHeaders(controls); renameExtensionsIntoCore(); if (getGLConfig().getAutoUnifyExtensions()) { @@ -85,7 +85,7 @@ public class GLEmitter extends ProcAddressEmitter // renaming mechanisms that are built elsewhere. GLConfiguration config = getGLConfig(); - Set extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore(); + Set extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore(); BuildStaticGLInfo glInfo = config.getGLInfo(); if(null==glInfo) { if(extensionsRenamedIntoCore.size()>0) { @@ -93,9 +93,8 @@ public class GLEmitter extends ProcAddressEmitter } return; } - for (Iterator iter = extensionsRenamedIntoCore.iterator(); iter.hasNext(); ) { - String extension = (String) iter.next(); - Set/**/ declarations = glInfo.getDeclarations(extension); + for (String extension : extensionsRenamedIntoCore) { + Set declarations = glInfo.getDeclarations(extension); if (declarations != null) { for (Iterator i2 = declarations.iterator(); i2.hasNext(); ) { String decl = (String) i2.next(); @@ -116,21 +115,21 @@ public class GLEmitter extends ProcAddressEmitter } class ExtensionUnifier implements SymbolFilter { - private List/**/ constants; - private List/**/ functions; + private List constants; + private List functions; - public void filterSymbols(List/**/ constants, - List/**/ functions) { + public void filterSymbols(List constants, + List functions) { this.constants = constants; this.functions = functions; doWork(); } - public List/**/ getConstants() { + public List getConstants() { return constants; } - public List/**/ getFunctions() { + public List getFunctions() { return functions; } @@ -140,8 +139,8 @@ public class GLEmitter extends ProcAddressEmitter return; } // Try to retain a "good" ordering for these symbols - Map/**/ constantMap = new LinkedHashMap(); - Map/**/ functionMap = new LinkedHashMap(); + Map constantMap = new LinkedHashMap(); + Map functionMap = new LinkedHashMap(); for (Iterator iter = constants.iterator(); iter.hasNext(); ) { ConstantDefinition def = (ConstantDefinition) iter.next(); constantMap.put(def.getName(), def); @@ -158,10 +157,10 @@ public class GLEmitter extends ProcAddressEmitter // that doesn't support the core version of these APIs, the runtime // will take care of looking up the extension version of these entry // points. - Set/**/ extensionNames = glInfo.getExtensions(); + Set extensionNames = glInfo.getExtensions(); for (Iterator iter1 = extensionNames.iterator(); iter1.hasNext(); ) { String extension = (String) iter1.next(); - Set/**/ declarations = glInfo.getDeclarations(extension); + Set declarations = glInfo.getDeclarations(extension); boolean isExtension = true; boolean shouldUnify = true; String cause = null; @@ -253,14 +252,14 @@ public class GLEmitter extends ProcAddressEmitter (i.e., mutators for argument names). We also would need to inform the CMethodBindingEmitter that it is overloaded in this case (though we default to true currently). */ - protected List/**/ expandMethodBinding(MethodBinding binding) { - List/**/ bindings = super.expandMethodBinding(binding); + protected List expandMethodBinding(MethodBinding binding) { + List bindings = super.expandMethodBinding(binding); if (!getGLConfig().isBufferObjectFunction(binding.getName())) { return bindings; } - List/**/ newBindings = new ArrayList(); + List newBindings = new ArrayList(); newBindings.addAll(bindings); // Need to expand each one of the generated bindings to take a diff --git a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java index 662e75b51..33f94fb19 100755 --- a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java @@ -40,7 +40,6 @@ package com.sun.gluegen.opengl; import java.io.*; -import java.util.*; import com.sun.gluegen.*; import com.sun.gluegen.cgram.types.*; import com.sun.gluegen.procaddress.*; @@ -83,6 +82,7 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit this(methodToWrap, methodToWrap.glEmitter, methodToWrap.bufferObjectVariant); } + @Override protected String getArgumentName(int i) { String name = super.getArgumentName(i); @@ -104,9 +104,9 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit return name; } - protected class GLCommentEmitter - extends JavaMethodBindingEmitter.DefaultCommentEmitter - { + protected class GLCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter { + + @Override protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) { super.emitBindingCSignature(binding, writer); -- cgit v1.2.3