diff options
author | Kenneth Russel <[email protected]> | 2005-02-02 00:23:09 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-02-02 00:23:09 +0000 |
commit | 944a1c9ff172c5187f8d489b9f687417bb6af953 (patch) | |
tree | 32d5e96e0f923b9ac8a598b92cbfa5a2b44b1891 /src/net/java | |
parent | df6b1b78a80fbf95e6c6e8c946bc899b75312153 (diff) |
Merged in changes from Blackbird branch: refactoring and rewriting of
portions of GlueGen for more flexibility. Also fixed source-level
problems associated with making GLCapabilities' clone() not throw
CloneNotSupportedException.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@202 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java')
-rw-r--r-- | src/net/java/games/gluegen/FunctionEmitter.java | 9 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaEmitter.java | 24 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaMethodBindingEmitter.java | 25 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java | 16 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaType.java | 4 | ||||
-rw-r--r-- | src/net/java/games/gluegen/MethodBinding.java | 130 | ||||
-rw-r--r-- | src/net/java/games/gluegen/opengl/GLEmitter.java | 37 | ||||
-rw-r--r-- | src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java | 1 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/GLContext.java | 6 |
9 files changed, 172 insertions, 80 deletions
diff --git a/src/net/java/games/gluegen/FunctionEmitter.java b/src/net/java/games/gluegen/FunctionEmitter.java index 097d8d0be..9acde1211 100644 --- a/src/net/java/games/gluegen/FunctionEmitter.java +++ b/src/net/java/games/gluegen/FunctionEmitter.java @@ -59,6 +59,15 @@ public abstract class FunctionEmitter this.defaultOutput = defaultOutput; } + /** + * Makes this FunctionEmitter a copy of the passed one. + */ + public FunctionEmitter(FunctionEmitter arg) { + modifiers = (HashSet) arg.modifiers.clone(); + commentEmitter = arg.commentEmitter; + defaultOutput = arg.defaultOutput; + } + public PrintWriter getDefaultOutput() { return defaultOutput; } public void addModifiers(Iterator/*<EmissionModifier>*/ mi) diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java index 00887c333..318c2ad73 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/net/java/games/gluegen/JavaEmitter.java @@ -264,10 +264,8 @@ public class JavaEmitter implements GlueEmitter { continue; // don't generate bindings for this symbol } - Iterator allBindings = generateMethodBindingEmitters(cFunc); - while (allBindings.hasNext()) { - methodBindingEmitters.add(allBindings.next()); - } + List allBindings = generateMethodBindingEmitters(cFunc); + methodBindingEmitters.addAll(allBindings); } // Emit all the methods @@ -305,7 +303,7 @@ public class JavaEmitter implements GlueEmitter { * Generate all appropriate Java bindings for the specified C function * symbols. */ - protected Iterator generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { + protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { ArrayList/*<FunctionEmitter>*/ allEmitters = new ArrayList(1); @@ -375,7 +373,7 @@ public class JavaEmitter implements GlueEmitter { if (cfg.allStatic()) { entryPoint.addModifier(JavaMethodBindingEmitter.STATIC); } - if (!isUnimplemented && !binding.needsBody()) { + if (!isUnimplemented && !bindingNeedsBody(binding)) { entryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); } entryPoint.setReturnedArrayLengthExpression(cfg.returnedArrayLength(binding.getName())); @@ -395,8 +393,8 @@ public class JavaEmitter implements GlueEmitter { // If the user has stated that the function will be // manually implemented, then don't auto-generate a function body. if (!cfg.manuallyImplement(sym.getName()) && !isUnimplemented) { - if (binding.needsBody()) { - // Generate the method which calls the underlying function + if (bindingNeedsBody(binding)) { + // Generate the method which calls the underlying C function // after unboxing has occurred PrintWriter output = cfg.allStatic() ? javaWriter() : javaImplWriter(); JavaMethodBindingEmitter wrappedEntryPoint = @@ -422,7 +420,7 @@ public class JavaEmitter implements GlueEmitter { "Error while generating bindings for \"" + sym + "\"", e); } - return allEmitters.iterator(); + return allEmitters; } @@ -571,7 +569,7 @@ public class JavaEmitter implements GlueEmitter { JavaMethodBindingEmitter entryPoint = new JavaMethodBindingImplEmitter(binding, writer, cfg.runtimeExceptionType()); entryPoint.addModifier(JavaMethodBindingEmitter.PUBLIC); - if (!binding.needsBody() && !binding.hasContainingType()) { + if (!bindingNeedsBody(binding) && !binding.hasContainingType()) { entryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); } entryPoint.emit(); @@ -676,6 +674,12 @@ public class JavaEmitter implements GlueEmitter { // Internals only below this point // + protected boolean bindingNeedsBody(MethodBinding binding) { + // We need to perform NIO checks and conversions and array length + // checks + return binding.signatureUsesNIO() || binding.signatureUsesCArrays(); + } + private CMethodBindingEmitter makeCEmitter(MethodBinding binding, boolean overloaded, boolean doingImplRoutine, diff --git a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java index 131faae0d..e5b83a26c 100644 --- a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java +++ b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java @@ -66,7 +66,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter private String runtimeExceptionType; private MethodBinding binding; - private boolean forNIOBufferBaseRoutine; + private boolean forImplementingMethodCall; // A non-null value indicates that rather than returning a compound // type accessor we are returning an array of such accessors; this @@ -80,18 +80,26 @@ public class JavaMethodBindingEmitter extends FunctionEmitter this(binding, output, runtimeExceptionType, false); } - public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType, boolean forNIOBufferBaseRoutine) + public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType, boolean forImplementingMethodCall) { super(output); this.binding = binding; - this.forNIOBufferBaseRoutine = forNIOBufferBaseRoutine; + this.forImplementingMethodCall = forImplementingMethodCall; this.runtimeExceptionType = runtimeExceptionType; setCommentEmitter(defaultInterfaceCommentEmitter); } + public JavaMethodBindingEmitter(JavaMethodBindingEmitter arg) { + super(arg); + runtimeExceptionType = arg.runtimeExceptionType; + binding = arg.binding; + forImplementingMethodCall = arg.forImplementingMethodCall; + returnedArrayLengthExpression = arg.returnedArrayLengthExpression; + } + public final MethodBinding getBinding() { return binding; } - public final boolean isForNIOBufferBaseRoutine() { return forNIOBufferBaseRoutine; } + public boolean isForImplementingMethodCall() { return forImplementingMethodCall; } public String getName() { return binding.getName(); @@ -130,9 +138,10 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected void emitName(PrintWriter writer) { - writer.print(binding.getName()); - if (forNIOBufferBaseRoutine) { - writer.print("0"); + if (forImplementingMethodCall) { + writer.print(getImplMethodName()); + } else { + writer.print(getName()); } } @@ -141,7 +150,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter boolean needComma = false; int numEmitted = 0; - if (forNIOBufferBaseRoutine && binding.hasContainingType()) { + if (forImplementingMethodCall && binding.hasContainingType()) { // Always emit outgoing "this" argument writer.print("java.nio.Buffer "); writer.print(javaThisArgumentName()); diff --git a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java index 2701bc2ec..dc3dfa629 100644 --- a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java +++ b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java @@ -65,6 +65,13 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter this.isUnimplemented = isUnimplemented; } + public JavaMethodBindingImplEmitter(JavaMethodBindingEmitter arg) { + super(arg); + if (arg instanceof JavaMethodBindingImplEmitter) { + this.isUnimplemented = ((JavaMethodBindingImplEmitter) arg).isUnimplemented; + } + } + protected void emitBody(PrintWriter writer) { MethodBinding binding = getBinding(); @@ -84,8 +91,15 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter } } + protected boolean isUnimplemented() { + return isUnimplemented; + } + protected boolean needsBody() { - return isUnimplemented || getBinding().needsBody() || getBinding().hasContainingType(); + return (isUnimplemented || + getBinding().signatureUsesNIO() || + getBinding().signatureUsesCArrays() || + getBinding().hasContainingType()); } protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { diff --git a/src/net/java/games/gluegen/JavaType.java b/src/net/java/games/gluegen/JavaType.java index 2d41a543d..b879187ef 100644 --- a/src/net/java/games/gluegen/JavaType.java +++ b/src/net/java/games/gluegen/JavaType.java @@ -325,6 +325,10 @@ public class JavaType { return ((clazz != null) && !isArray() && clazz.isPrimitive() && (clazz != Void.TYPE)); } + public boolean isPrimitiveArray() { + return (isArray() && (clazz.getComponentType().isPrimitive())); + } + public boolean isVoid() { return (clazz == Void.TYPE); } diff --git a/src/net/java/games/gluegen/MethodBinding.java b/src/net/java/games/gluegen/MethodBinding.java index fd2b7b7bc..b7117185d 100644 --- a/src/net/java/games/gluegen/MethodBinding.java +++ b/src/net/java/games/gluegen/MethodBinding.java @@ -52,8 +52,10 @@ public class MethodBinding { private FunctionSymbol sym; private JavaType javaReturnType; private List javaArgumentTypes; - private boolean computedNeedsBody; - private boolean needsBody; + private boolean computedSignatureProperties; + private boolean signatureUsesNIO; + private boolean signatureUsesCArrays; + private boolean signatureUsesPrimitiveArrays; private JavaType containingType; private Type containingCType; private int thisPointerIndex = -1; @@ -66,13 +68,15 @@ public class MethodBinding { public MethodBinding(MethodBinding bindingToCopy) { this.sym = bindingToCopy.sym; - this.containingType = bindingToCopy.containingType; - this.containingCType = bindingToCopy.containingCType; - this.javaReturnType = bindingToCopy.javaReturnType; - this.javaArgumentTypes = (List)((ArrayList)bindingToCopy.javaArgumentTypes).clone(); - this.computedNeedsBody = bindingToCopy.computedNeedsBody; - this.needsBody = bindingToCopy.needsBody; - this.thisPointerIndex = bindingToCopy.thisPointerIndex; + this.containingType = bindingToCopy.containingType; + this.containingCType = bindingToCopy.containingCType; + this.javaReturnType = bindingToCopy.javaReturnType; + this.javaArgumentTypes = (List)((ArrayList)bindingToCopy.javaArgumentTypes).clone(); + this.computedSignatureProperties = bindingToCopy.computedSignatureProperties; + this.signatureUsesNIO = bindingToCopy.signatureUsesNIO; + this.signatureUsesCArrays = bindingToCopy.signatureUsesCArrays; + this.signatureUsesPrimitiveArrays = bindingToCopy.signatureUsesPrimitiveArrays; + this.thisPointerIndex = bindingToCopy.thisPointerIndex; } /** Constructor for calling a C function. */ @@ -90,7 +94,7 @@ public class MethodBinding { public void setJavaReturnType(JavaType type) { javaReturnType = type; - computedNeedsBody = false; + computedSignatureProperties = false; } public void addJavaArgumentType(JavaType type) { @@ -98,7 +102,7 @@ public class MethodBinding { javaArgumentTypes = new ArrayList(); } javaArgumentTypes.add(type); - computedNeedsBody = false; + computedSignatureProperties = false; } public JavaType getJavaReturnType() { @@ -162,46 +166,86 @@ public class MethodBinding { } return binding; } + + /** + * Returns true if the return type or any of the outgoing arguments + * in the method's signature require conversion or checking due to + * the use of New I/O. + */ + public boolean signatureUsesNIO() { + computeSignatureProperties(); + return signatureUsesNIO; + } + + /** + * Returns true if any of the outgoing arguments in the method's + * signature represent fixed-length C arrays which require length + * checking during the call. + */ + public boolean signatureUsesCArrays() { + computeSignatureProperties(); + return signatureUsesCArrays; + } + + /** + * Returns true if any of the outgoing arguments in the method's + * signature represent primitive arrays which require a + * GetPrimitiveArrayCritical or similar operation during the call. + */ + public boolean signatureUsesPrimitiveArrays() { + computeSignatureProperties(); + return signatureUsesPrimitiveArrays; + } + /** - * Returns true if this method needs a special implementation to wrap and/or - * set the byte order of its arguments or return type (i.e., needs special - * pre-processing of the data passed to the native function, or - * post-processing of the data returned from the native function). <P> - * - * Returns false if this binding can be implemented via a one-to-one - * correspondence between a Java method and its native implementation. + * Computes summary information about the method's C and Java + * signatures. */ - public boolean needsBody() { - if (!computedNeedsBody) { - if (javaReturnType.isCompoundTypeWrapper() || - javaReturnType.isNIOByteBuffer() || - javaReturnType.isArrayOfCompoundTypeWrappers()) { - // Needs wrapping and/or setting of byte order (neither of - // which can be done easily from native code) - needsBody = true; - } else { - for (int i = 0; i < getNumArguments(); i++) { - JavaType javaArgType = getJavaArgumentType(i); - Type cArgType = getCArgumentType(i); - if (javaArgType.isCompoundTypeWrapper() || - javaArgType.isNIOBuffer() || - cArgType.isArray() || - javaArgType.isNIOBufferArray()) { - // Needs unwrapping of accessors, checking of array - // lengths, or checking of direct buffer property - needsBody = true; - break; - } - } + protected void computeSignatureProperties() { + if (computedSignatureProperties) + return; + + signatureUsesNIO = false; + signatureUsesCArrays = false; + signatureUsesPrimitiveArrays = false; + + if (javaReturnType.isCompoundTypeWrapper() || + javaReturnType.isNIOByteBuffer() || + javaReturnType.isArrayOfCompoundTypeWrappers()) { + // Needs wrapping and/or setting of byte order (neither of + // which can be done easily from native code) + signatureUsesNIO = true; + } + + for (int i = 0; i < getNumArguments(); i++) { + JavaType javaArgType = getJavaArgumentType(i); + Type cArgType = getCArgumentType(i); + if (javaArgType.isCompoundTypeWrapper() || + javaArgType.isNIOBuffer() || + javaArgType.isNIOBufferArray()) { + // Needs unwrapping of accessors or checking of direct + // buffer property + signatureUsesNIO = true; + } + + if (cArgType.isArray()) { + // Needs checking of array lengths + signatureUsesCArrays = true; + } + + if (javaArgType.isPrimitiveArray()) { + // Needs getPrimitiveArrayCritical or similar construct + // depending on native code calling convention + signatureUsesPrimitiveArrays = true; } - computedNeedsBody = true; } - return needsBody; + computedSignatureProperties = true; } + public MethodBinding createNIOBufferVariant() { - if (!needsBody()) { + if (!signatureUsesNIO()) { return this; } MethodBinding binding = new MethodBinding(sym, containingType, containingCType); diff --git a/src/net/java/games/gluegen/opengl/GLEmitter.java b/src/net/java/games/gluegen/opengl/GLEmitter.java index 861e85bb7..b63d6e8b4 100644 --- a/src/net/java/games/gluegen/opengl/GLEmitter.java +++ b/src/net/java/games/gluegen/opengl/GLEmitter.java @@ -93,14 +93,27 @@ public class GLEmitter extends JavaEmitter return new GLConfiguration(); } - protected Iterator generateMethodBindingEmitters(FunctionSymbol sym) throws Exception + protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { - Iterator defaultEmitters = super.generateMethodBindingEmitters(sym); + return generateMethodBindingEmittersImpl(sym); + } + + protected List generateMethodBindingEmitters(FunctionSymbol sym, boolean skipProcessing) throws Exception { + if (skipProcessing) { + return super.generateMethodBindingEmitters(sym); + } else { + return generateMethodBindingEmittersImpl(sym); + } + } + + private List generateMethodBindingEmittersImpl(FunctionSymbol sym) throws Exception + { + List defaultEmitters = super.generateMethodBindingEmitters(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 // direction that matched the symbol's name). - if (!defaultEmitters.hasNext()) + if (defaultEmitters.isEmpty()) { return defaultEmitters; } @@ -121,9 +134,9 @@ public class GLEmitter extends JavaEmitter emitGLProcAddressTableEntryForSymbol(sym); } - while (defaultEmitters.hasNext()) + for (Iterator iter = defaultEmitters.iterator(); iter.hasNext(); ) { - FunctionEmitter emitter = (FunctionEmitter)defaultEmitters.next(); + FunctionEmitter emitter = (FunctionEmitter) iter.next(); if (emitter instanceof JavaMethodBindingEmitter) { JavaMethodBindingEmitter newEmitter = @@ -144,7 +157,7 @@ public class GLEmitter extends JavaEmitter } } - return modifiedEmitters.iterator(); + return modifiedEmitters; } /** @@ -168,7 +181,7 @@ public class GLEmitter extends JavaEmitter // Internals only below this point // - private JavaMethodBindingEmitter generateModifiedEmitter(JavaMethodBindingEmitter baseJavaEmitter) + protected JavaMethodBindingEmitter generateModifiedEmitter(JavaMethodBindingEmitter baseJavaEmitter) { if (!(baseJavaEmitter instanceof JavaMethodBindingImplEmitter)) { // We only want to wrap the native entry point in the implementation @@ -178,7 +191,7 @@ public class GLEmitter extends JavaEmitter // it needs argument conversion or similar, filter that out since we will // be providing such an emitter ourselves. Otherwise return the emitter // unmodified. - if (baseJavaEmitter.isForNIOBufferBaseRoutine()) + if (baseJavaEmitter.isForImplementingMethodCall()) return null; return baseJavaEmitter; } @@ -189,7 +202,7 @@ public class GLEmitter extends JavaEmitter return new JavaGLPAWrapperEmitter(baseJavaEmitter, getGLConfig().getProcAddressTableExpr()); } - private CMethodBindingEmitter generateModifiedEmitter(CMethodBindingEmitter baseCEmitter) + protected CMethodBindingEmitter generateModifiedEmitter(CMethodBindingEmitter baseCEmitter) { // The C-side JNI binding for this particular function will have an // extra final argument, which is the address (the OpenGL procedure @@ -202,7 +215,7 @@ public class GLEmitter extends JavaEmitter return res; } - private boolean needsProcAddressWrapper(FunctionSymbol sym) + protected boolean needsProcAddressWrapper(FunctionSymbol sym) { String symName = sym.getName(); @@ -316,7 +329,7 @@ public class GLEmitter extends JavaEmitter w.close(); } - private void emitGLProcAddressTableEntryForSymbol(FunctionSymbol cFunc) + protected void emitGLProcAddressTableEntryForSymbol(FunctionSymbol cFunc) { tableWriter.print(" public long "); tableWriter.print(PROCADDRESS_VAR_PREFIX); @@ -325,7 +338,7 @@ public class GLEmitter extends JavaEmitter ++numProcAddressEntries; } - private GLConfiguration getGLConfig() { + protected GLConfiguration getGLConfig() { return (GLConfiguration) getConfig(); } diff --git a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java index 4fb50ea21..1bb06b791 100644 --- a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java +++ b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java @@ -151,7 +151,6 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { super.emitPreCallSetup(binding, writer); - JavaType returnType = binding.getJavaReturnType(); MethodBinding wrappedBinding = emitterBeingWrapped.getBinding(); String procAddressVariable = diff --git a/src/net/java/games/jogl/impl/GLContext.java b/src/net/java/games/jogl/impl/GLContext.java index 4fd00dcd5..cc5d465d6 100644 --- a/src/net/java/games/jogl/impl/GLContext.java +++ b/src/net/java/games/jogl/impl/GLContext.java @@ -145,11 +145,7 @@ public abstract class GLContext { GLCapabilitiesChooser chooser, GLContext shareWith) { this.component = component; - try { - this.capabilities = (GLCapabilities) capabilities.clone(); - } catch (CloneNotSupportedException e) { - throw new GLException(e); - } + this.capabilities = (GLCapabilities) capabilities.clone(); this.chooser = chooser; setGL(createGL()); functionAvailability = new FunctionAvailabilityCache(this); |