diff options
author | Sven Gothel <[email protected]> | 2008-06-21 02:03:17 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-06-21 02:03:17 +0000 |
commit | b6e5af8524f57c1064c30b48b08371c0026d57e5 (patch) | |
tree | f785f8b30fe52f921eddc5775d198bdff7aff256 /src/java | |
parent | 52ac2b969574ae92930cc9d285f3b14aa388df38 (diff) |
OpenGL Composable Pipeline:
- Using GL.getContext() interface directly
- Adding javax.media.opengl.* to imports
ProcAddressEmitter, ProcAddressTable
- Generated class implements gluegen runtime's ProcAddressTable,
to allow generic access to 'getAddressFor(String functionName)'
JavaConfiguration, JavaEmitter
- NEW: ParentClass <ThisClass> <ParentClass>,
to allow the implementing classes to extend a user spec one
- NEW: AccessControl type 'PUBLIC_ABSTRACT",
to allow a generated impl. class to be abstract.
JavaType.getDescriptor()
- Throw a meaningfull exception in case of an unknown type,
ie a used type/struct, which could not be generated.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/branches/JOGL_2_SANDBOX@84 a78bb65f-1512-4460-ba86-f6dc96a7bf27
Diffstat (limited to 'src/java')
6 files changed, 92 insertions, 11 deletions
diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java index a452183..3ce8ecb 100644 --- a/src/java/com/sun/gluegen/JavaConfiguration.java +++ b/src/java/com/sun/gluegen/JavaConfiguration.java @@ -127,6 +127,7 @@ public class JavaConfiguration { private Map/*<String, List<String>>*/ temporaryCVariableAssignments = new HashMap(); private Map/*<String,List<String>>*/ extendedInterfaces = new HashMap(); private Map/*<String,List<String>>*/ implementedInterfaces = new HashMap(); + private Map/*<String,String>*/ parentClass = new HashMap(); private Map/*<String,String>*/ javaTypeRenames = new HashMap(); private Map/*<String,String>*/ javaMethodRenames = new HashMap(); private Map/*<String,List<String>>*/ javaPrologues = new HashMap(); @@ -538,6 +539,13 @@ public class JavaConfiguration { return res; } + /** Returns a List of Strings indicating the interfaces the passed + class should declare it implements. May return null or a list + of zero length if there are none. */ + public String extendedParentClass(String className) { + return (String) parentClass.get(className); + } + /** Returns true if this #define, function, struct, or field within a struct should be ignored during glue code generation. */ public boolean shouldIgnore(String symbol) { @@ -791,6 +799,8 @@ public class JavaConfiguration { readExtend(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("Implements")) { readImplements(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("ParentClass")) { + readParentClass(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("RenameJavaType")) { readRenameJavaType(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("RenameJavaMethod")) { @@ -863,6 +873,8 @@ public class JavaConfiguration { acc = JavaEmitter.ACC_PRIVATE; } else if (style.equalsIgnoreCase("PACKAGE_PRIVATE")) { acc = JavaEmitter.ACC_PACKAGE_PRIVATE; + } else if (style.equalsIgnoreCase("PUBLIC_ABSTRACT")) { + acc = JavaEmitter.ACC_PUBLIC_ABSTRACT; } else { throw new RuntimeException("Error parsing \"AccessControl\" command at line " + lineNo + " in file \"" + filename + "\""); @@ -1213,6 +1225,16 @@ public class JavaConfiguration { } } + protected void readParentClass(StringTokenizer tok, String filename, int lineNo) { + try { + String className = tok.nextToken(); + parentClass.put(className, tok.nextToken()); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"ParentClass\" command at line " + lineNo + + " in file \"" + filename + "\": missing expected parameter", e); + } + } + protected void readRenameJavaType(StringTokenizer tok, String filename, int lineNo) { try { String fromName = tok.nextToken(); diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index ef5c36d..15dff34 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -80,6 +80,7 @@ public class JavaEmitter implements GlueEmitter { public static final int ACC_PROTECTED = 2; public static final int ACC_PRIVATE = 3; public static final int ACC_PACKAGE_PRIVATE = 4; + public static final int ACC_PUBLIC_ABSTRACT = 5; private PrintWriter javaWriter; // Emits either interface or, in AllStatic mode, everything private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class @@ -1394,6 +1395,13 @@ public class JavaEmitter implements GlueEmitter { } }; + String[] accessModifiers = null; + if(cfg.accessControl(cfg.className())==ACC_PUBLIC_ABSTRACT) { + accessModifiers = new String[] { "public", "abstract" }; + } else { + accessModifiers = new String[] { "public" }; + } + CodeGenUtils.emitJavaHeaders( javaWriter, cfg.packageName(), @@ -1401,9 +1409,9 @@ public class JavaEmitter implements GlueEmitter { cfg.gluegenRuntimePackage(), cfg.allStatic() ? true : false, (String[]) cfg.imports().toArray(new String[] {}), - new String[] { "public" }, + accessModifiers, interfaces, - null, + cfg.extendedParentClass(cfg.className()), docEmitter); } @@ -1431,6 +1439,13 @@ public class JavaEmitter implements GlueEmitter { interfaces[userSpecifiedInterfaces.size()] = cfg.className(); } + String[] accessModifiers = null; + if(cfg.accessControl(cfg.implClassName())==ACC_PUBLIC_ABSTRACT) { + accessModifiers = new String[] { "public", "abstract" }; + } else { + accessModifiers = new String[] { "public" }; + } + CodeGenUtils.emitJavaHeaders( javaImplWriter, cfg.implPackageName(), @@ -1438,9 +1453,9 @@ public class JavaEmitter implements GlueEmitter { cfg.gluegenRuntimePackage(), true, (String[]) cfg.imports().toArray(new String[] {}), - new String[] { "public" }, + accessModifiers, interfaces, - null, + cfg.extendedParentClass(cfg.implClassName()), docEmitter); } diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java index b520888..800c16f 100644 --- a/src/java/com/sun/gluegen/JavaType.java +++ b/src/java/com/sun/gluegen/JavaType.java @@ -249,6 +249,9 @@ public class JavaType { return descriptor(clazz); } if (elementType != null) { + if(elementType.getName()==null) { + throw new RuntimeException("elementType.name is null: "+getDumpString()); + } return "[" + descriptor(elementType.getName()); } return descriptor(name); @@ -472,8 +475,11 @@ public class JavaType { // // For debugging + public String getDumpString() { + return "[clazz = " + clazz + " , name = " + name + " , elementType = " + elementType + " , primitivePointerType = " + primitivePointerType + "]"; + } public void dump() { - System.err.println("[clazz = " + clazz + " , name = " + name + " , elementType = " + elementType + " , primitivePointerType = " + primitivePointerType + "]"); + System.err.println(getDumpString()); } /** diff --git a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java index 818f0ce..cc9175b 100644 --- a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java +++ b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java @@ -179,7 +179,7 @@ public class BuildComposablePipeline pipelineClassName, "com.sun.gluegen.runtime", // FIXME: should make configurable true, - new String[] { "java.io.*" }, + new String[] { "java.io.*", "javax.media.opengl.*" }, new String[] { "public" }, new String[] { baseName }, null, @@ -327,10 +327,7 @@ public class BuildComposablePipeline output.print( " this." + getDownstreamObjectName()); output.println(" = " + getDownstreamObjectName() + ";"); output.println(" // Fetch GLContext object for better error checking (if possible)"); - output.println(" // FIXME: should probably put this method in GL rather than GLImpl"); - output.println(" if (" + getDownstreamObjectName() + " instanceof com.sun.opengl.impl.GLImpl) {"); - output.println(" _context = ((com.sun.opengl.impl.GLImpl) " + getDownstreamObjectName() + ").getContext();"); - output.println(" }"); + output.println(" _context = " + getDownstreamObjectName() + ".getContext();"); output.println(" }"); output.println(); } diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java index 45e0bf4..bb81961 100755 --- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java +++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java @@ -324,7 +324,7 @@ public class ProcAddressEmitter extends JavaEmitter tableWriter.println(" * pointer is 0, the function is considered to be unavailable and can"); tableWriter.println(" * not be called."); tableWriter.println(" */"); - tableWriter.println("public class " + tableClassName); + tableWriter.println("public class " + tableClassName + " implements com.sun.gluegen.runtime.ProcAddressTable"); tableWriter.println("{"); for (Iterator iter = getProcAddressConfig().getForceProcAddressGen().iterator(); iter.hasNext(); ) { diff --git a/src/java/com/sun/gluegen/runtime/ProcAddressTable.java b/src/java/com/sun/gluegen/runtime/ProcAddressTable.java new file mode 100644 index 0000000..4271a8c --- /dev/null +++ b/src/java/com/sun/gluegen/runtime/ProcAddressTable.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.sun.gluegen.runtime; + +public interface ProcAddressTable { + public long getAddressFor(String functionName); +} |