summaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-03-31 23:32:39 +0200
committerSven Gothel <[email protected]>2010-03-31 23:32:39 +0200
commite37c383c4a09432fff009e81d572c8a92b42eef6 (patch)
tree9ebb8bacc940a3460be1639ad771f8e5d98ad012 /src/java/com
parent73829c38665c57052bf703ae58a2bd1dc7dc4625 (diff)
parent22262166e07de99ae0d4557e4f87e3bd1c5cd6dd (diff)
Merged with latest of mbien
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/jogamp/common/nio/AbstractBuffer.java (renamed from src/java/com/jogamp/gluegen/runtime/AbstractBuffer.java)10
-rw-r--r--src/java/com/jogamp/common/nio/AbstractLongBuffer.java (renamed from src/java/com/jogamp/gluegen/runtime/AbstractLongBuffer.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/nio/Buffers.java (renamed from src/java/com/jogamp/gluegen/runtime/Buffers.java)3
-rw-r--r--src/java/com/jogamp/common/nio/Int64Buffer.java (renamed from src/java/com/jogamp/gluegen/runtime/Int64Buffer.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java (renamed from src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/nio/Int64BufferSE.java (renamed from src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java)2
-rw-r--r--src/java/com/jogamp/common/nio/NativeBuffer.java54
-rw-r--r--src/java/com/jogamp/common/nio/PointerBuffer.java (renamed from src/java/com/jogamp/gluegen/runtime/PointerBuffer.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java (renamed from src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/nio/PointerBufferSE.java (renamed from src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java)3
-rw-r--r--src/java/com/jogamp/common/nio/StructAccessor.java (renamed from src/java/com/jogamp/gluegen/runtime/StructAccessor.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/os/DynamicLinker.java (renamed from src/java/com/jogamp/gluegen/runtime/DynamicLinker.java)2
-rwxr-xr-xsrc/java/com/jogamp/common/os/DynamicLookupHelper.java (renamed from src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java)2
-rwxr-xr-xsrc/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java (renamed from src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java)6
-rwxr-xr-xsrc/java/com/jogamp/common/os/NativeLibrary.java (renamed from src/java/com/jogamp/gluegen/runtime/NativeLibrary.java)5
-rw-r--r--src/java/com/jogamp/common/os/Platform.java (renamed from src/java/com/jogamp/gluegen/runtime/Platform.java)3
-rwxr-xr-xsrc/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java (renamed from src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java)6
-rwxr-xr-xsrc/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java (renamed from src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java)6
-rw-r--r--src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java1
-rw-r--r--src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java1
-rw-r--r--src/java/com/sun/gluegen/CMethodBindingEmitter.java17
-rw-r--r--src/java/com/sun/gluegen/GlueGen.java4
-rw-r--r--src/java/com/sun/gluegen/JavaConfiguration.java102
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java78
-rw-r--r--src/java/com/sun/gluegen/JavaType.java12
-rw-r--r--src/java/com/sun/gluegen/Logging.java85
-rwxr-xr-xsrc/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java246
-rwxr-xr-xsrc/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java8
-rw-r--r--src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java1942
-rw-r--r--src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java419
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLConfiguration.java419
-rw-r--r--src/java/com/sun/gluegen/opengl/GLEmitter.java756
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java146
-rw-r--r--src/java/com/sun/gluegen/pcpp/PCPP.java112
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java279
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java456
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java636
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java185
38 files changed, 3041 insertions, 2983 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/AbstractBuffer.java b/src/java/com/jogamp/common/nio/AbstractBuffer.java
index 34e39ba..d76574b 100644
--- a/src/java/com/jogamp/gluegen/runtime/AbstractBuffer.java
+++ b/src/java/com/jogamp/common/nio/AbstractBuffer.java
@@ -28,7 +28,9 @@
/*
* Created on Saturday, March 27 2010 11:55
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+
+import com.jogamp.common.os.*;
import java.nio.ByteBuffer;
import java.nio.Buffer;
@@ -38,7 +40,7 @@ import java.util.HashMap;
* @author Michael Bien
* @author Sven Gothel
*/
-public abstract class AbstractBuffer {
+public abstract class AbstractBuffer implements NativeBuffer {
protected final ByteBuffer bb;
protected int capacity;
@@ -67,7 +69,7 @@ public abstract class AbstractBuffer {
return position;
}
- public final AbstractBuffer position(int newPos) {
+ public final NativeBuffer position(int newPos) {
if (0 > newPos || newPos >= capacity) {
throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " +
"My capacity is "+capacity()+".");
@@ -84,7 +86,7 @@ public abstract class AbstractBuffer {
return position < capacity;
}
- public final AbstractBuffer rewind() {
+ public final NativeBuffer rewind() {
position = 0;
return this;
}
diff --git a/src/java/com/jogamp/gluegen/runtime/AbstractLongBuffer.java b/src/java/com/jogamp/common/nio/AbstractLongBuffer.java
index 63c2b5f..ad90ffc 100644
--- a/src/java/com/jogamp/gluegen/runtime/AbstractLongBuffer.java
+++ b/src/java/com/jogamp/common/nio/AbstractLongBuffer.java
@@ -28,8 +28,9 @@
/*
* Created on Saturday, March 27 2010 11:55
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.*;
import java.nio.ByteBuffer;
import java.nio.Buffer;
import java.util.HashMap;
diff --git a/src/java/com/jogamp/gluegen/runtime/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java
index 49f6e8b..e3bea17 100755
--- a/src/java/com/jogamp/gluegen/runtime/Buffers.java
+++ b/src/java/com/jogamp/common/nio/Buffers.java
@@ -36,8 +36,9 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.Platform;
import java.nio.*;
/**
diff --git a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java b/src/java/com/jogamp/common/nio/Int64Buffer.java
index 4535bdb..6f0b7a3 100644
--- a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java
+++ b/src/java/com/jogamp/common/nio/Int64Buffer.java
@@ -25,8 +25,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.*;
import java.nio.ByteBuffer;
/**
diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java b/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java
index 93863cf..9621677 100755
--- a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java
+++ b/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java
@@ -33,8 +33,9 @@
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.Platform;
import java.nio.*;
/**
diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java b/src/java/com/jogamp/common/nio/Int64BufferSE.java
index a874133..fc262fd 100755
--- a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java
+++ b/src/java/com/jogamp/common/nio/Int64BufferSE.java
@@ -33,7 +33,7 @@
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
import java.nio.*;
diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java
new file mode 100644
index 0000000..99a5cbc
--- /dev/null
+++ b/src/java/com/jogamp/common/nio/NativeBuffer.java
@@ -0,0 +1,54 @@
+/*
+ * Created on Tuesday, March 30 2010 18:22
+ */
+package com.jogamp.common.nio;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Hardware independent container for various kinds of buffers.
+ *
+ * @author Michael Bien
+ * @author Sven Gothel
+ */
+public interface NativeBuffer/*<B extends NativeBuffer>*/ {
+
+ public int limit();
+
+ public int capacity();
+
+ public int position();
+
+ public NativeBuffer position(int newPos);
+
+ public int remaining();
+
+ public boolean hasRemaining();
+
+ public NativeBuffer rewind();
+
+ public boolean hasArray();
+
+ public int arrayOffset();
+
+ public ByteBuffer getBuffer();
+
+ public boolean isDirect();
+
+/*
+ public long[] array();
+
+ public B rewind();
+
+ public B put(int index, long value);
+
+ public B put(long value);
+
+ public B put(B src);
+
+ public long get();
+
+ public long get(int idx);
+*/
+
+}
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/common/nio/PointerBuffer.java
index cfc53a8..26d2e7b 100644
--- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
+++ b/src/java/com/jogamp/common/nio/PointerBuffer.java
@@ -28,8 +28,9 @@
/*
* Created on Saturday, March 27 2010 11:55
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.*;
import java.nio.ByteBuffer;
import java.nio.Buffer;
import java.util.HashMap;
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java b/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java
index a660e1f..6e2c7d9 100755
--- a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java
+++ b/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java
@@ -33,8 +33,9 @@
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.Platform;
import java.nio.*;
/**
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java b/src/java/com/jogamp/common/nio/PointerBufferSE.java
index 9943ec1..11dc629 100755
--- a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java
+++ b/src/java/com/jogamp/common/nio/PointerBufferSE.java
@@ -33,8 +33,9 @@
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.Platform;
import java.nio.*;
/**
diff --git a/src/java/com/jogamp/gluegen/runtime/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java
index 6f3ad7d..117e8de 100644
--- a/src/java/com/jogamp/gluegen/runtime/StructAccessor.java
+++ b/src/java/com/jogamp/common/nio/StructAccessor.java
@@ -36,8 +36,9 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.nio;
+import com.jogamp.common.os.Platform;
import java.nio.*;
/**
diff --git a/src/java/com/jogamp/gluegen/runtime/DynamicLinker.java b/src/java/com/jogamp/common/os/DynamicLinker.java
index f3cfcfd..ef5d5dc 100755
--- a/src/java/com/jogamp/gluegen/runtime/DynamicLinker.java
+++ b/src/java/com/jogamp/common/os/DynamicLinker.java
@@ -37,7 +37,7 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
/** Provides an abstract interface to the OS's low-level dynamic
linking functionality. */
diff --git a/src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java b/src/java/com/jogamp/common/os/DynamicLookupHelper.java
index bc29732..a4f74a4 100755
--- a/src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java
+++ b/src/java/com/jogamp/common/os/DynamicLookupHelper.java
@@ -37,7 +37,7 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
/** Interface callers may use to use the ProcAddressHelper's {@link
ProcAddressHelper#resetProcAddressTable resetProcAddressTable}
diff --git a/src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java
index 8abbd4e..531bc5c 100755
--- a/src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java
+++ b/src/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java
@@ -1,11 +1,9 @@
/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:27:00 PDT 2006 ----! */
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
-import com.jogamp.gluegen.runtime.*;
-public class MacOSXDynamicLinkerImpl implements DynamicLinker
-{
+public class MacOSXDynamicLinkerImpl implements DynamicLinker {
public static final int RTLD_LAZY = 0x1;
public static final int RTLD_NOW = 0x2;
diff --git a/src/java/com/jogamp/gluegen/runtime/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java
index 7de75a3..2de8bc9 100755
--- a/src/java/com/jogamp/gluegen/runtime/NativeLibrary.java
+++ b/src/java/com/jogamp/common/os/NativeLibrary.java
@@ -37,8 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
+import com.jogamp.gluegen.runtime.NativeLibLoader;
import java.io.*;
import java.lang.reflect.*;
import java.security.*;
@@ -412,7 +413,7 @@ public class NativeLibrary implements DynamicLookupHelper {
}
private static volatile boolean loadedDynLinkNativeLib;
- static void ensureNativeLibLoaded() {
+ public static void ensureNativeLibLoaded() {
if (!loadedDynLinkNativeLib) {
synchronized (NativeLibrary.class) {
if (!loadedDynLinkNativeLib) {
diff --git a/src/java/com/jogamp/gluegen/runtime/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index a621279..169af13 100644
--- a/src/java/com/jogamp/gluegen/runtime/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -28,8 +28,9 @@
/*
* Created on Sunday, March 28 2010 14:43
*/
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
+import com.jogamp.common.nio.Buffers;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
diff --git a/src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java
index 018f31b..02bc828 100755
--- a/src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java
+++ b/src/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java
@@ -1,11 +1,9 @@
/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:26:59 PDT 2006 ----! */
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
-import com.jogamp.gluegen.runtime.*;
-public class UnixDynamicLinkerImpl implements DynamicLinker
-{
+public class UnixDynamicLinkerImpl implements DynamicLinker {
public static final int RTLD_LAZY = 0x00001;
public static final int RTLD_NOW = 0x00002;
diff --git a/src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java
index 87b9a37..f5a3312 100755
--- a/src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java
+++ b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java
@@ -1,11 +1,9 @@
/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Tue May 27 02:37:55 PDT 2008 ----! */
-package com.jogamp.gluegen.runtime;
+package com.jogamp.common.os;
-import com.jogamp.gluegen.runtime.*;
-public class WindowsDynamicLinkerImpl implements DynamicLinker
-{
+public class WindowsDynamicLinkerImpl implements DynamicLinker {
/** Interface to C language function: <br> <code> BOOL FreeLibrary(HANDLE hLibModule); </code> */
diff --git a/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java b/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java
index 1b7f9d6..787eab5 100644
--- a/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java
+++ b/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java
@@ -39,6 +39,7 @@
package com.jogamp.gluegen.runtime;
+import com.jogamp.common.os.DynamicLookupHelper;
import java.security.*;
// Debugging only
diff --git a/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java b/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java
index 7470c46..2031d9e 100644
--- a/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java
+++ b/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java
@@ -36,6 +36,7 @@
package com.jogamp.gluegen.runtime.opengl;
+import com.jogamp.common.os.DynamicLookupHelper;
import com.jogamp.gluegen.runtime.*;
// Debugging only
diff --git a/src/java/com/sun/gluegen/CMethodBindingEmitter.java b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
index 022df39..ef5d0e9 100644
--- a/src/java/com/sun/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
@@ -44,12 +44,15 @@ import java.io.*;
import java.text.MessageFormat;
import com.sun.gluegen.cgram.types.*;
+import java.util.logging.Logger;
+
+import static java.util.logging.Level.*;
/** Emits the C-side component of the Java<->C JNI binding. */
-public class CMethodBindingEmitter extends FunctionEmitter
-{
- protected static final CommentEmitter defaultCommentEmitter =
- new DefaultCommentEmitter();
+public class CMethodBindingEmitter extends FunctionEmitter {
+
+ protected static final Logger LOG = Logger.getLogger(CMethodBindingEmitter.class.getPackage().getName());
+ protected static final CommentEmitter defaultCommentEmitter = new DefaultCommentEmitter();
protected static final String arrayResLength = "_array_res_length";
protected static final String arrayRes = "_array_res";
@@ -1006,13 +1009,13 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
}
writer.print("sizeof(" + cReturnType.getName() + ")");
- System.err.println(
- "WARNING: No capacity specified for java.nio.Buffer return " +
+ LOG.warning(
+ "No capacity specified for java.nio.Buffer return " +
"value for function \"" + binding + "\";" +
" assuming size of equivalent C return type (sizeof(" + cReturnType.getName() + ")): " + binding);
/**
throw new RuntimeException(
- "WARNING: No capacity specified for java.nio.Buffer return " +
+ "No capacity specified for java.nio.Buffer return " +
"value for function \"" + binding + "\";" +
" C return type is " + cReturnType.getName() + ": " + binding); */
}
diff --git a/src/java/com/sun/gluegen/GlueGen.java b/src/java/com/sun/gluegen/GlueGen.java
index 8d2144a..aac5319 100644
--- a/src/java/com/sun/gluegen/GlueGen.java
+++ b/src/java/com/sun/gluegen/GlueGen.java
@@ -51,6 +51,10 @@ import static java.lang.System.*;
/** Glue code generator for C functions and data structures. */
public class GlueGen implements GlueEmitterControls {
+ static{
+ Logging.init();
+ }
+
private List<String> forcedStructNames = new ArrayList<String>();
private PCPP preprocessor;
diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java
index e0a0eb6..7a1e45e 100644
--- a/src/java/com/sun/gluegen/JavaConfiguration.java
+++ b/src/java/com/sun/gluegen/JavaConfiguration.java
@@ -39,6 +39,8 @@
package com.sun.gluegen;
+import com.sun.gluegen.JavaEmitter.EmissionStyle;
+import com.sun.gluegen.JavaEmitter.MethodAccess;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
@@ -47,6 +49,11 @@ import java.util.regex.*;
import com.sun.gluegen.jgram.*;
import com.sun.gluegen.cgram.types.*;
+import java.util.logging.Logger;
+
+import static java.util.logging.Level.*;
+import static com.sun.gluegen.JavaEmitter.MethodAccess.*;
+import static com.sun.gluegen.JavaEmitter.EmissionStyle.*;
/** Parses and provides access to the contents of .cfg files for the
JavaEmitter. */
@@ -58,6 +65,8 @@ public class JavaConfiguration {
private String implPackageName;
private String className;
private String implClassName;
+
+ protected static final Logger LOG = Logger.getLogger(JavaConfiguration.class.getPackage().getName());
/**
* Root directory for the hierarchy of generated java classes. Default is
@@ -95,7 +104,7 @@ public class JavaConfiguration {
* (InterfaceAndImpl), only the interface (InterfaceOnly), or only
* the implementation (ImplOnly).
*/
- private int emissionStyle = JavaEmitter.ALL_STATIC;
+ private EmissionStyle emissionStyle = AllStatic;
/**
* List of imports to emit at the head of the output files.
@@ -115,7 +124,8 @@ public class JavaConfiguration {
*/
private String runtimeExceptionType = "RuntimeException";
private String unsupportedExceptionType = "UnsupportedOperationException";
- private Map<String, Integer> accessControl = new HashMap<String, Integer>();
+
+ private Map<String, MethodAccess> accessControl = new HashMap<String, MethodAccess>();
private Map<String, TypeInfo> typeInfoMap = new HashMap<String, TypeInfo>();
private Set<String> returnsString = new HashSet<String>();
private Map<String, String> returnedArrayLengths = new HashMap<String, String>();
@@ -207,16 +217,15 @@ public class JavaConfiguration {
if (nestedReads == 0) {
if (allStatic() && implClassName != null) {
- throw new IllegalStateException(
- "Error in configuration file \"" + filename + "\": Cannot use " +
+ throw new IllegalStateException("Error in configuration file \"" + filename + "\": Cannot use " +
"directive \"ImplJavaClass\" in conjunction with " +
"\"Style AllStatic\"");
}
- if (className == null && (emissionStyle() != JavaEmitter.IMPL_ONLY)) {
+ if (className == null && (emissionStyle() != ImplOnly)) {
// throw new RuntimeException("Output class name was not specified in configuration file \"" + filename + "\"");
}
- if (packageName == null && (emissionStyle() != JavaEmitter.IMPL_ONLY)) {
+ if (packageName == null && (emissionStyle() != ImplOnly)) {
throw new RuntimeException("Output package name was not specified in configuration file \"" + filename + "\"");
}
@@ -293,18 +302,18 @@ public class JavaConfiguration {
}
/** Returns the code emission style (constants in JavaEmitter) parsed from the configuration file. */
- public int emissionStyle() {
+ public EmissionStyle emissionStyle() {
return emissionStyle;
}
/** Returns the access control for the emitted Java method. Returns one of JavaEmitter.ACC_PUBLIC, JavaEmitter.ACC_PROTECTED, JavaEmitter.ACC_PRIVATE, or JavaEmitter.ACC_PACKAGE_PRIVATE. */
- public int accessControl(String methodName) {
- Integer ret = accessControl.get(methodName);
+ public MethodAccess accessControl(String methodName) {
+ MethodAccess ret = accessControl.get(methodName);
if (ret != null) {
- return ret.intValue();
+ return ret;
}
// Default access control is public
- return JavaEmitter.ACC_PUBLIC;
+ return PUBLIC;
}
/** Returns the package in which the generated glue code expects to
@@ -715,7 +724,7 @@ public class JavaConfiguration {
if (!matcher.matches()) {
// Special case as this is most often likely to be the case.
// Unignores are not used very often.
- if(unignores.size() == 0) {
+ if(unignores.isEmpty()) {
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl unignores==0: "+symbol);
}
@@ -793,20 +802,17 @@ public class JavaConfiguration {
/** Returns true if the emission style is AllStatic. */
public boolean allStatic() {
- return (emissionStyle == JavaEmitter.ALL_STATIC);
+ return emissionStyle == AllStatic;
}
/** Returns true if an interface should be emitted during glue code generation. */
public boolean emitInterface() {
- return (emissionStyle() == JavaEmitter.INTERFACE_AND_IMPL ||
- emissionStyle() == JavaEmitter.INTERFACE_ONLY);
+ return emissionStyle() == InterfaceAndImpl || emissionStyle() == InterfaceOnly;
}
/** Returns true if an implementing class should be emitted during glue code generation. */
public boolean emitImpl() {
- return (emissionStyle() == JavaEmitter.ALL_STATIC ||
- emissionStyle() == JavaEmitter.INTERFACE_AND_IMPL ||
- emissionStyle() == JavaEmitter.IMPL_ONLY);
+ return emissionStyle() == AllStatic || emissionStyle() == InterfaceAndImpl || emissionStyle() == ImplOnly;
}
/** Returns a list of Strings which should be emitted as a prologue
@@ -863,19 +869,11 @@ public class JavaConfiguration {
} else if (cmd.equalsIgnoreCase("TagNativeBinding")) {
tagNativeBinding = readBoolean("TagNativeBinding", tok, filename, lineNo).booleanValue();
} else if (cmd.equalsIgnoreCase("Style")) {
- String style = readString("Style", tok, filename, lineNo);
- if (style.equalsIgnoreCase("AllStatic")) {
- emissionStyle = JavaEmitter.ALL_STATIC;
- } else if (style.equalsIgnoreCase("InterfaceAndImpl")) {
- emissionStyle = JavaEmitter.INTERFACE_AND_IMPL;
- } else if (style.equalsIgnoreCase("InterfaceOnly")) {
- emissionStyle = JavaEmitter.INTERFACE_ONLY;
- } else if (style.equalsIgnoreCase("ImplOnly")) {
- emissionStyle = JavaEmitter.IMPL_ONLY;
- } else {
- System.err.println("WARNING: Error parsing \"style\" command at line " + lineNo +
- " in file \"" + filename + "\"");
- }
+ try{
+ emissionStyle = EmissionStyle.valueOf(readString("Style", tok, filename, lineNo));
+ }catch(IllegalArgumentException ex) {
+ LOG.log(WARNING, "Error parsing \"style\" command at line {0} in file \"{1}\"", new Object[]{lineNo, filename});
+ }
} else if (cmd.equalsIgnoreCase("AccessControl")) {
readAccessControl(tok, filename, lineNo);
} else if (cmd.equalsIgnoreCase("Import")) {
@@ -1025,31 +1023,17 @@ public class JavaConfiguration {
throw new RuntimeException("Only primitive types are supported here");
}
- protected void readAccessControl(StringTokenizer tok, String filename, int lineNo) {
- try {
- String methodName = tok.nextToken();
- String style = tok.nextToken();
- int acc = 0;
- if (style.equalsIgnoreCase("PUBLIC")) {
- acc = JavaEmitter.ACC_PUBLIC;
- } else if (style.equalsIgnoreCase("PROTECTED")) {
- acc = JavaEmitter.ACC_PROTECTED;
- } else if (style.equalsIgnoreCase("PRIVATE")) {
- 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 + "\"");
- }
- accessControl.put(methodName, new Integer(acc));
- } catch (Exception e) {
- throw new RuntimeException("Error parsing \"AccessControl\" command at line " + lineNo +
- " in file \"" + filename + "\"", e);
+ protected void readAccessControl(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String methodName = tok.nextToken();
+ String style = tok.nextToken();
+ MethodAccess access = MethodAccess.valueOf(style.toUpperCase());
+ accessControl.put(methodName, access);
+ } catch (Exception e) {
+ throw new RuntimeException("Error parsing \"AccessControl\" command at line " + lineNo
+ + " in file \"" + filename + "\"", e);
+ }
}
- }
protected void readOpaque(StringTokenizer tok, String filename, int lineNo) {
try {
@@ -1104,8 +1088,7 @@ public class JavaConfiguration {
javaFile = new File(tok.nextToken());
javaReader = new BufferedReader(new FileReader(javaFile));
} catch (FileNotFoundException e) {
- e.printStackTrace();
- return;
+ throw new RuntimeException(e);
}
JavaLexer lexer = new JavaLexer(javaReader);
@@ -1117,8 +1100,7 @@ public class JavaConfiguration {
try {
parser.compilationUnit();
} catch (Exception e) {
- e.printStackTrace();
- return;
+ throw new RuntimeException(e);
}
if(onlyList) {
@@ -1386,7 +1368,7 @@ public class JavaConfiguration {
protected void doIncludeAs(StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
try {
- StringBuffer linePrefix = new StringBuffer(128);
+ StringBuilder linePrefix = new StringBuilder(128);
while (tok.countTokens() > 1)
{
linePrefix.append(tok.nextToken());
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index 25aeb16..fc8ab34 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -39,11 +39,17 @@
package com.sun.gluegen;
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.common.os.DynamicLookupHelper;
import java.io.*;
import java.util.*;
import java.text.MessageFormat;
import com.sun.gluegen.cgram.types.*;
+import java.util.logging.Logger;
+
+import static java.util.logging.Level.*;
+import static com.sun.gluegen.JavaEmitter.MethodAccess.*;
// PROBLEMS:
// - what if something returns 'const int *'? Could we
@@ -69,19 +75,12 @@ public class JavaEmitter implements GlueEmitter {
* (InterfaceAndImpl), only the interface (InterfaceOnly), or only
* the implementation (ImplOnly).
*/
- public static final int ALL_STATIC = 1;
- public static final int INTERFACE_AND_IMPL = 2;
- public static final int INTERFACE_ONLY = 3;
- public static final int IMPL_ONLY = 4;
+ public enum EmissionStyle {AllStatic, InterfaceAndImpl, InterfaceOnly, ImplOnly};
/**
* Access control for emitted Java methods.
*/
- public static final int ACC_PUBLIC = 1;
- 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;
+ public enum MethodAccess {PUBLIC, PROTECTED, PRIVATE, PACKAGE_PRIVATE, PUBLIC_ABSTRACT}
private PrintWriter javaWriter; // Emits either interface or, in AllStatic mode, everything
private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class
@@ -89,6 +88,8 @@ public class JavaEmitter implements GlueEmitter {
private MachineDescription machDesc32;
private MachineDescription machDesc64;
+ protected final static Logger LOG = Logger.getLogger(JavaEmitter.class.getPackage().getName());
+
public void readConfigurationFile(String filename) throws Exception {
cfg = createConfig();
cfg.read(filename);
@@ -406,16 +407,10 @@ public class JavaEmitter implements GlueEmitter {
ArrayList<FunctionSymbol> funcsToBind = new ArrayList<FunctionSymbol>(funcsToBindSet);
// sort functions to make them easier to find in native code
- Collections.sort(
- funcsToBind,
- new Comparator<FunctionSymbol>() {
- public int compare(FunctionSymbol o1, FunctionSymbol o2) {
- return o1.getName().compareTo(o2.getName());
- }
- @Override
- public boolean equals(Object obj) {
- return obj.getClass() == this.getClass();
- }
+ Collections.sort(funcsToBind, new Comparator<FunctionSymbol>() {
+ public int compare(FunctionSymbol o1, FunctionSymbol o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
});
// Bind all the C funcs to Java methods
@@ -480,9 +475,9 @@ public class JavaEmitter implements GlueEmitter {
return;
}
- int accessControl = cfg.accessControl(binding.getName());
+ MethodAccess accessControl = cfg.accessControl(binding.getName());
// We should not emit anything except public APIs into interfaces
- if (signatureOnly && (accessControl != ACC_PUBLIC)) {
+ if (signatureOnly && (accessControl != PUBLIC)) {
return;
}
@@ -514,9 +509,9 @@ public class JavaEmitter implements GlueEmitter {
signatureOnly,
cfg);
switch (accessControl) {
- case ACC_PUBLIC: emitter.addModifier(JavaMethodBindingEmitter.PUBLIC); break;
- case ACC_PROTECTED: emitter.addModifier(JavaMethodBindingEmitter.PROTECTED); break;
- case ACC_PRIVATE: emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); break;
+ case PUBLIC: emitter.addModifier(JavaMethodBindingEmitter.PUBLIC); break;
+ case PROTECTED: emitter.addModifier(JavaMethodBindingEmitter.PROTECTED); break;
+ case PRIVATE: emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); break;
default: break; // package-private adds no modifiers
}
if (cfg.allStatic()) {
@@ -654,7 +649,7 @@ public class JavaEmitter implements GlueEmitter {
* Generate all appropriate Java bindings for the specified C function
* symbols.
*/
- protected List<FunctionEmitter> generateMethodBindingEmitters(HashSet<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception {
+ protected List<? extends FunctionEmitter> generateMethodBindingEmitters(Set<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception {
ArrayList<FunctionEmitter> allEmitters = new ArrayList<FunctionEmitter>();
@@ -787,8 +782,8 @@ public class JavaEmitter implements GlueEmitter {
}
if (name == null) {
- System.err.println("WARNING: skipping emission of unnamed struct \"" + structType + "\"");
- return;
+ LOG.log(WARNING, "skipping emission of unnamed struct \"{0}\"", structType);
+ return;
}
if (cfg.shouldIgnoreInInterface(name)) {
@@ -851,7 +846,6 @@ public class JavaEmitter implements GlueEmitter {
String structClassPkg = cfg.packageForStruct(name);
PrintWriter writer = null;
- PrintWriter cWriter = null;
try {
writer = openFile(
cfg.javaOutputDir() + File.separator +
@@ -863,9 +857,9 @@ public class JavaEmitter implements GlueEmitter {
if (cfg.nativeOutputUsesJavaHierarchy()) {
nRoot += File.separator + CodeGenUtils.packageAsPath(cfg.packageName());
}
- cWriter = openFile(nRoot + File.separator + containingTypeName + "_JNI.c");
- CodeGenUtils.emitAutogeneratedWarning(cWriter, this);
- emitCHeader(cWriter, containingTypeName);
+ PrintWriter newCWriter = openFile(nRoot + File.separator + containingTypeName + "_JNI.c");
+ CodeGenUtils.emitAutogeneratedWarning(newCWriter, this);
+ emitCHeader(newCWriter, containingTypeName);
}
} catch(Exception e) {
throw new RuntimeException("Unable to open files for emission of struct class", e);
@@ -877,6 +871,8 @@ public class JavaEmitter implements GlueEmitter {
writer.println("import java.nio.*;");
writer.println();
writer.println("import " + cfg.gluegenRuntimePackage() + ".*;");
+ writer.println("import " + DynamicLookupHelper.class.getPackage().getName() + ".*;");
+ writer.println("import " + Buffers.class.getPackage().getName() + ".*;");
writer.println();
List<String> imports = cfg.imports();
for (String str : imports) {
@@ -1095,7 +1091,6 @@ public class JavaEmitter implements GlueEmitter {
} catch (Exception e) {
System.err.println("Error occurred while creating accessor for field \"" +
field.getName() + "\" in type \"" + name + "\"");
- e.printStackTrace();
throw(e);
}
if (externalJavaType.isPrimitive()) {
@@ -1152,8 +1147,7 @@ public class JavaEmitter implements GlueEmitter {
}
} else {
// FIXME
- System.err.println("WARNING: Complicated fields (field \"" + field + "\" of type \"" + name +
- "\") not implemented yet");
+ LOG.log(WARNING, "Complicated fields (field \"{0}\" of type \"{1}\") not implemented yet", new Object[]{field, name});
// throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t +
// "\") not implemented yet");
}
@@ -1173,9 +1167,11 @@ public class JavaEmitter implements GlueEmitter {
}
public void endStructs() throws Exception {}
- public static int addStrings2Buffer(StringBuffer buf, String sep, String first, Collection<String> col) {
+ public static int addStrings2Buffer(StringBuilder buf, String sep, String first, Collection<String> col) {
int num = 0;
- if(null==buf) buf = new StringBuffer();
+ if(null==buf) {
+ buf = new StringBuilder();
+ }
Iterator<String> iter = col.iterator();
if(null!=first) {
@@ -1240,7 +1236,7 @@ public class JavaEmitter implements GlueEmitter {
// t is<type>**, targetType is <type>*, we need to get <type>
Type bottomType = targetType.asPointer().getTargetType();
- System.out.println("INFO: Opaque Type: "+t+", targetType: "+targetType+", bottomType: "+bottomType+" is ptr-ptr");
+ LOG.log(INFO, "Opaque Type: {0}, targetType: {1}, bottomType: {2} is ptr-ptr", new Object[]{t, targetType, bottomType});
}
}
}
@@ -1333,7 +1329,7 @@ public class JavaEmitter implements GlueEmitter {
} else {
// t is<type>[][], targetType is <type>[], we need to get <type>
bottomType = targetType.asArray().getElementType();
- System.out.println("WARNING: typeToJavaType(ptr-ptr): "+t+", targetType: "+targetType+", bottomType: "+bottomType+" -> Unhandled!");
+ LOG.log(WARNING, "typeToJavaType(ptr-ptr): {0}, targetType: {1}, bottomType: {2} -> Unhandled!", new Object[]{t, targetType, bottomType});
}
// Warning: The below code is not backed up by an implementation,
@@ -1569,7 +1565,7 @@ public class JavaEmitter implements GlueEmitter {
*/
protected void emitCustomJavaCode(PrintWriter writer, String className) throws Exception {
List<String> code = cfg.customJavaCodeForClass(className);
- if (code.size() == 0)
+ if (code.isEmpty())
return;
writer.println();
@@ -1608,7 +1604,7 @@ public class JavaEmitter implements GlueEmitter {
};
String[] accessModifiers = null;
- if(cfg.accessControl(cfg.className())==ACC_PUBLIC_ABSTRACT) {
+ if(cfg.accessControl(cfg.className()) == PUBLIC_ABSTRACT) {
accessModifiers = new String[] { "public", "abstract" };
} else {
accessModifiers = new String[] { "public" };
@@ -1651,7 +1647,7 @@ public class JavaEmitter implements GlueEmitter {
}
String[] accessModifiers = null;
- if(cfg.accessControl(cfg.implClassName())==ACC_PUBLIC_ABSTRACT) {
+ if(cfg.accessControl(cfg.implClassName()) == PUBLIC_ABSTRACT) {
accessModifiers = new String[] { "public", "abstract" };
} else {
accessModifiers = new String[] { "public" };
diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java
index 23f48b2..c3cce38 100644
--- a/src/java/com/sun/gluegen/JavaType.java
+++ b/src/java/com/sun/gluegen/JavaType.java
@@ -197,13 +197,13 @@ public class JavaType {
public static JavaType forNIOInt64BufferClass() {
if(nioInt64BufferType == null)
- nioInt64BufferType = createForClass(com.jogamp.gluegen.runtime.Int64Buffer.class);
+ nioInt64BufferType = createForClass(com.jogamp.common.nio.Int64Buffer.class);
return nioInt64BufferType;
}
public static JavaType forNIOPointerBufferClass() {
if(nioPointerBufferType == null)
- nioPointerBufferType = createForClass(com.jogamp.gluegen.runtime.PointerBuffer.class);
+ nioPointerBufferType = createForClass(com.jogamp.common.nio.PointerBuffer.class);
return nioPointerBufferType;
}
@@ -340,8 +340,8 @@ public class JavaType {
public boolean isNIOBuffer() {
return clazz != null && ( (java.nio.Buffer.class).isAssignableFrom(clazz) ||
- (com.jogamp.gluegen.runtime.PointerBuffer.class).isAssignableFrom(clazz) ||
- (com.jogamp.gluegen.runtime.Int64Buffer.class).isAssignableFrom(clazz) ) ;
+ (com.jogamp.common.nio.PointerBuffer.class).isAssignableFrom(clazz) ||
+ (com.jogamp.common.nio.Int64Buffer.class).isAssignableFrom(clazz) ) ;
}
public boolean isNIOByteBuffer() {
@@ -362,11 +362,11 @@ public class JavaType {
}
public boolean isNIOInt64Buffer() {
- return (clazz == com.jogamp.gluegen.runtime.Int64Buffer.class);
+ return (clazz == com.jogamp.common.nio.Int64Buffer.class);
}
public boolean isNIOPointerBuffer() {
- return (clazz == com.jogamp.gluegen.runtime.PointerBuffer.class);
+ return (clazz == com.jogamp.common.nio.PointerBuffer.class);
}
public boolean isString() {
diff --git a/src/java/com/sun/gluegen/Logging.java b/src/java/com/sun/gluegen/Logging.java
new file mode 100644
index 0000000..b38118c
--- /dev/null
+++ b/src/java/com/sun/gluegen/Logging.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2010, Michael Bien
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions 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 JogAmp nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Created on Wednesday, March 31 2010 13:30
+ */
+package com.sun.gluegen;
+
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class Logging {
+
+ static void init() {
+
+ String pakage = Logging.class.getPackage().getName();
+ String property = System.getProperty(pakage+".level");
+ Level level;
+ if(property != null) {
+ level = Level.parse(property);
+ }else{
+ level = Level.WARNING;
+ }
+
+ ConsoleHandler handler = new ConsoleHandler() {
+ @Override
+ public java.util.logging.Formatter getFormatter() {
+ return new PlainLogFormatter();
+ }
+ };
+ handler.setFormatter(new PlainLogFormatter());
+ handler.setLevel(level);
+
+ Logger rootPackageLogger = Logger.getLogger(pakage);
+ rootPackageLogger.setUseParentHandlers(false);
+ rootPackageLogger.setLevel(level);
+ rootPackageLogger.addHandler(handler);
+ }
+
+ /**
+ * This log formatter needs usually one line per log record.
+ * @author Michael Bien
+ */
+ private static class PlainLogFormatter extends Formatter {
+
+ //@Override
+ public String format(LogRecord record) {
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("[").append(record.getLevel()).append(' ').append(record.getSourceClassName()).append("]: ");
+ sb.append(formatMessage(record)).append("\n");
+ return sb.toString();
+ }
+ }
+}
diff --git a/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java b/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java
index 314a9bb..f20495b 100755
--- a/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java
+++ b/src/java/com/sun/gluegen/nativesig/NativeSignatureEmitter.java
@@ -36,7 +36,6 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.nativesig;
import java.io.*;
@@ -47,142 +46,141 @@ import com.sun.gluegen.cgram.types.*;
import com.sun.gluegen.opengl.*;
import com.sun.gluegen.procaddress.*;
-/** Emitter producing NativeSignature attributes. */
-
+/**
+ * Emitter producing NativeSignature attributes.
+ */
public class NativeSignatureEmitter extends GLEmitter {
- protected List generateMethodBindingEmitters(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception {
- // Allow superclass to do most of the work for us
- List res = super.generateMethodBindingEmitters(methodBindingSet, sym);
-
- // Filter out all non-JavaMethodBindingEmitters
- for (Iterator iter = res.iterator(); iter.hasNext(); ) {
- FunctionEmitter emitter = (FunctionEmitter) iter.next();
- if (!(emitter instanceof JavaMethodBindingEmitter)) {
- iter.remove();
- }
- }
- if (res.isEmpty()) {
- return res;
- }
+ @Override
+ protected List<? extends FunctionEmitter> generateMethodBindingEmitters(Set<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception {
- PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter());
+ // Allow superclass to do most of the work for us
+ List<? extends FunctionEmitter> res = super.generateMethodBindingEmitters(methodBindingSet, sym);
- List processed = new ArrayList();
+ // Filter out all non-JavaMethodBindingEmitters
+ for (Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) {
+ FunctionEmitter emitter = iter.next();
+ if (!(emitter instanceof JavaMethodBindingEmitter)) {
+ iter.remove();
+ }
+ }
- // First, filter out all emitters going to the "other" (public) writer
- for (Iterator iter = res.iterator(); iter.hasNext(); ) {
- FunctionEmitter emitter = (FunctionEmitter) iter.next();
- if (emitter.getDefaultOutput() != writer) {
- processed.add(emitter);
- iter.remove();
- }
- }
+ if (res.isEmpty()) {
+ return res;
+ }
+
+ PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter());
+
+ List<FunctionEmitter> processed = new ArrayList<FunctionEmitter>();
- // Now process all of the remaining emitters sorted by MethodBinding
- while (!res.isEmpty()) {
- List emittersForBinding = new ArrayList();
- JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) res.remove(0);
- emittersForBinding.add(emitter);
- MethodBinding binding = emitter.getBinding();
- for (Iterator iter = res.iterator(); iter.hasNext(); ) {
- JavaMethodBindingEmitter emitter2 = (JavaMethodBindingEmitter) iter.next();
- if (emitter2.getBinding() == binding) {
- emittersForBinding.add(emitter2);
- iter.remove();
+ // First, filter out all emitters going to the "other" (public) writer
+ for (Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) {
+ FunctionEmitter emitter = iter.next();
+ if (emitter.getDefaultOutput() != writer) {
+ processed.add(emitter);
+ iter.remove();
+ }
}
- }
- generateNativeSignatureEmitters(binding, emittersForBinding);
- processed.addAll(emittersForBinding);
- }
- return processed;
- }
+ // Now process all of the remaining emitters sorted by MethodBinding
+ while (!res.isEmpty()) {
+ List<JavaMethodBindingEmitter> emittersForBinding = new ArrayList<JavaMethodBindingEmitter>();
+ JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) res.remove(0);
+ emittersForBinding.add(emitter);
+ MethodBinding binding = emitter.getBinding();
+ for (Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) {
+ JavaMethodBindingEmitter emitter2 = (JavaMethodBindingEmitter) iter.next();
+ if (emitter2.getBinding() == binding) {
+ emittersForBinding.add(emitter2);
+ iter.remove();
+ }
+ }
+ generateNativeSignatureEmitters(binding, emittersForBinding);
+ processed.addAll(emittersForBinding);
+ }
- protected void generateNativeSignatureEmitters(MethodBinding binding,
- List allEmitters) {
- if (allEmitters.isEmpty()) {
- return;
+ return processed;
}
- PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter());
-
- // Give ourselves the chance to interpose on the generation of all code to keep things simple
- List newEmitters = new ArrayList();
- for (Iterator iter = allEmitters.iterator(); iter.hasNext(); ) {
- JavaMethodBindingEmitter javaEmitter = (JavaMethodBindingEmitter) iter.next();
- NativeSignatureJavaMethodBindingEmitter newEmitter = null;
- if (javaEmitter instanceof GLJavaMethodBindingEmitter) {
- newEmitter = new NativeSignatureJavaMethodBindingEmitter((GLJavaMethodBindingEmitter) javaEmitter);
- } else if (javaEmitter instanceof ProcAddressJavaMethodBindingEmitter) {
- newEmitter = new NativeSignatureJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) javaEmitter);
- } else {
- newEmitter = new NativeSignatureJavaMethodBindingEmitter(javaEmitter, this);
- }
- newEmitters.add(newEmitter);
- }
- allEmitters.clear();
- allEmitters.addAll(newEmitters);
-
- // Detect whether we need to produce more or modify some of these emitters.
- // Note that at this point we are assuming that generatePublicEmitters has
- // been called with signatureOnly both true and false.
- if (signatureContainsStrings(binding) &&
- !haveEmitterWithBody(allEmitters)) {
- // This basically handles glGetString but also any similar methods
- NativeSignatureJavaMethodBindingEmitter javaEmitter = findEmitterWithWriter(allEmitters, writer);
-
- // First, we need to clone this emitter to produce the native
- // entry point
- NativeSignatureJavaMethodBindingEmitter emitter =
- new NativeSignatureJavaMethodBindingEmitter(javaEmitter);
- emitter.removeModifier(JavaMethodBindingEmitter.PUBLIC);
- emitter.addModifier(JavaMethodBindingEmitter.PRIVATE);
- emitter.setForImplementingMethodCall(true);
- // Note: this is chosen so we don't have to change the logic in
- // emitReturnVariableSetupAndCall which decides which variant
- // (direct / indirect) to call
- emitter.setForDirectBufferImplementation(true);
- allEmitters.add(emitter);
-
- // Now make the original emitter non-native and cause it to emit a body
- javaEmitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
- javaEmitter.setEmitBody(true);
- }
- }
-
- protected boolean signatureContainsStrings(MethodBinding binding) {
- for (int i = 0; i < binding.getNumArguments(); i++) {
- JavaType type = binding.getJavaArgumentType(i);
- if (type.isString() || type.isStringArray()) {
- return true;
- }
+ protected void generateNativeSignatureEmitters(MethodBinding binding, List<JavaMethodBindingEmitter> allEmitters) {
+
+ if (allEmitters.isEmpty()) {
+ return;
+ }
+
+ PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter());
+
+ // Give ourselves the chance to interpose on the generation of all code to keep things simple
+ List<JavaMethodBindingEmitter> newEmitters = new ArrayList<JavaMethodBindingEmitter>();
+ for (JavaMethodBindingEmitter javaEmitter : allEmitters) {
+ NativeSignatureJavaMethodBindingEmitter newEmitter = null;
+ if (javaEmitter instanceof GLJavaMethodBindingEmitter) {
+ newEmitter = new NativeSignatureJavaMethodBindingEmitter((GLJavaMethodBindingEmitter) javaEmitter);
+ } else if (javaEmitter instanceof ProcAddressJavaMethodBindingEmitter) {
+ newEmitter = new NativeSignatureJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) javaEmitter);
+ } else {
+ newEmitter = new NativeSignatureJavaMethodBindingEmitter(javaEmitter, this);
+ }
+ newEmitters.add(newEmitter);
+ }
+ allEmitters.clear();
+ allEmitters.addAll(newEmitters);
+
+ // Detect whether we need to produce more or modify some of these emitters.
+ // Note that at this point we are assuming that generatePublicEmitters has
+ // been called with signatureOnly both true and false.
+ if (signatureContainsStrings(binding) && !haveEmitterWithBody(allEmitters)) {
+ // This basically handles glGetString but also any similar methods
+ NativeSignatureJavaMethodBindingEmitter javaEmitter = findEmitterWithWriter(allEmitters, writer);
+
+ // First, we need to clone this emitter to produce the native
+ // entry point
+ NativeSignatureJavaMethodBindingEmitter emitter = new NativeSignatureJavaMethodBindingEmitter(javaEmitter);
+ emitter.removeModifier(JavaMethodBindingEmitter.PUBLIC);
+ emitter.addModifier(JavaMethodBindingEmitter.PRIVATE);
+ emitter.setForImplementingMethodCall(true);
+ // Note: this is chosen so we don't have to change the logic in
+ // emitReturnVariableSetupAndCall which decides which variant
+ // (direct / indirect) to call
+ emitter.setForDirectBufferImplementation(true);
+ allEmitters.add(emitter);
+
+ // Now make the original emitter non-native and cause it to emit a body
+ javaEmitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
+ javaEmitter.setEmitBody(true);
+ }
}
- JavaType retType = binding.getJavaReturnType();
- if (retType.isString() || retType.isStringArray()) {
- return true;
+
+ protected boolean signatureContainsStrings(MethodBinding binding) {
+ for (int i = 0; i < binding.getNumArguments(); i++) {
+ JavaType type = binding.getJavaArgumentType(i);
+ if (type.isString() || type.isStringArray()) {
+ return true;
+ }
+ }
+ JavaType retType = binding.getJavaReturnType();
+ if (retType.isString() || retType.isStringArray()) {
+ return true;
+ }
+ return false;
}
- return false;
- }
-
- protected boolean haveEmitterWithBody(List allEmitters) {
- for (Iterator iter = allEmitters.iterator(); iter.hasNext(); ) {
- JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) iter.next();
- if (!emitter.signatureOnly()) {
- return true;
- }
+
+ protected boolean haveEmitterWithBody(List<JavaMethodBindingEmitter> allEmitters) {
+ for (JavaMethodBindingEmitter emitter : allEmitters) {
+ if (!emitter.signatureOnly()) {
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
-
- protected NativeSignatureJavaMethodBindingEmitter findEmitterWithWriter(List allEmitters, PrintWriter writer) {
- for (Iterator iter = allEmitters.iterator(); iter.hasNext(); ) {
- NativeSignatureJavaMethodBindingEmitter emitter =
- (NativeSignatureJavaMethodBindingEmitter) iter.next();
- if (emitter.getDefaultOutput() == writer) {
- return emitter;
- }
+
+ protected NativeSignatureJavaMethodBindingEmitter findEmitterWithWriter(List<JavaMethodBindingEmitter> allEmitters, PrintWriter writer) {
+ for (JavaMethodBindingEmitter jemitter : allEmitters) {
+ NativeSignatureJavaMethodBindingEmitter emitter = (NativeSignatureJavaMethodBindingEmitter)jemitter;
+ if (emitter.getDefaultOutput() == writer) {
+ return emitter;
+ }
+ }
+ throw new RuntimeException("Unexpectedly failed to find an emitter with the given writer");
}
- throw new RuntimeException("Unexpectedly failed to find an emitter with the given writer");
- }
}
diff --git a/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java
index b4dc130..379eccf 100755
--- a/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/nativesig/NativeSignatureJavaMethodBindingEmitter.java
@@ -40,16 +40,14 @@
package com.sun.gluegen.nativesig;
import java.io.*;
-import java.util.*;
-import java.text.MessageFormat;
import com.sun.gluegen.*;
import com.sun.gluegen.cgram.types.*;
-import com.sun.gluegen.cgram.*;
import com.sun.gluegen.opengl.*;
import com.sun.gluegen.procaddress.*;
public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBindingEmitter {
+
public NativeSignatureJavaMethodBindingEmitter(GLJavaMethodBindingEmitter methodToWrap) {
super(methodToWrap);
}
@@ -58,11 +56,11 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding
super(methodToWrap, false);
}
- public NativeSignatureJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap,
- NativeSignatureEmitter emitter) {
+ public NativeSignatureJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, NativeSignatureEmitter emitter) {
super(methodToWrap, false, null, false, false, emitter);
}
+ @Override
protected void emitSignature(PrintWriter writer) {
writer.print(getBaseIndentString());
emitNativeSignatureAnnotation(writer);
diff --git a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
index cbc0d89..9750c13 100644
--- a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
+++ b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
@@ -36,7 +36,6 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.opengl;
import com.sun.gluegen.*;
@@ -44,1079 +43,1042 @@ import com.sun.gluegen.*;
import java.lang.reflect.*;
import java.io.*;
import java.util.*;
-import java.util.regex.*;
-
-public class BuildComposablePipeline
-{
- public static final int GEN_DEBUG = 1 << 0 ; // default
- public static final int GEN_TRACE = 1 << 1 ; // default
- public static final int GEN_CUSTOM = 1 << 2 ;
- public static final int GEN_PROLOG_XOR_DOWNSTREAM = 1 << 3 ;
-
- int mode;
- private String outputDir;
- private String outputPackage;
- private String outputName;
- private Class classToComposeAround;
- private Class classPrologOpt;
- private Class classDownstream;
- private String basePackage;
- private String baseName; // does not include package!
- private String downstreamPackage;
- private String downstreamName; // does not include package!
-
- // Only desktop OpenGL has immediate mode glBegin / glEnd
- private boolean hasImmediateMode;
-
- // Desktop OpenGL and GLES1 have GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW errors
- private boolean hasStackOverflow;
-
- public static Class getClass(String name) {
- Class clazz=null;
- try {
- clazz = Class.forName(name);
- } catch (Exception e) {
- throw new RuntimeException(
- "Could not find class \"" + name + "\"", e);
- }
- return clazz;
- }
-
- public static Method getMethod(Class clazz, Method m) {
- Method res = null;
- try {
- res = clazz.getMethod(m.getName(), m.getParameterTypes());
- } catch (Exception e) { }
- return res;
- }
-
- public static void main(String[] args)
- {
- String classToComposeAroundName = args[0];
- Class classPrologOpt, classDownstream;
- Class classToComposeAround = getClass(classToComposeAroundName);
-
- String outputDir = args[1];
- String outputPackage, outputName;
+
+public class BuildComposablePipeline {
+
+ public static final int GEN_DEBUG = 1 << 0; // default
+ public static final int GEN_TRACE = 1 << 1; // default
+ public static final int GEN_CUSTOM = 1 << 2;
+ public static final int GEN_PROLOG_XOR_DOWNSTREAM = 1 << 3;
int mode;
+ private String outputDir;
+ private String outputPackage;
+ private String outputName;
+ private Class<?> classToComposeAround;
+ private Class<?> classPrologOpt;
+ private Class<?> classDownstream;
+ // Only desktop OpenGL has immediate mode glBegin / glEnd
+ private boolean hasImmediateMode;
+ // Desktop OpenGL and GLES1 have GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW errors
+ private boolean hasStackOverflow;
+
+ public static Class<?> getClass(String name) {
+ Class<?> clazz = null;
+ try {
+ clazz = Class.forName(name);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Could not find class \"" + name + "\"", e);
+ }
+ return clazz;
+ }
- if(args.length>2) {
- String outputClazzName = args[2];
- outputPackage = getPackageName(outputClazzName);
- outputName = getBaseClassName(outputClazzName);
- classPrologOpt = getClass(args[3]);
- classDownstream = getClass(args[4]);
- mode = GEN_CUSTOM;
- if(args.length>5) {
- if(args[5].equals("prolog_xor_downstream")) {
- mode |= GEN_PROLOG_XOR_DOWNSTREAM;
+ public static Method getMethod(Class<?> clazz, Method m) {
+ Method res = null;
+ try {
+ res = clazz.getMethod(m.getName(), m.getParameterTypes());
+ } catch (Exception e) {
+ }
+ return res;
+ }
+
+ public static void main(String[] args) {
+ String classToComposeAroundName = args[0];
+ Class<?> classPrologOpt, classDownstream;
+ Class<?> classToComposeAround = getClass(classToComposeAroundName);
+
+ String outputDir = args[1];
+ String outputPackage, outputName;
+ int mode;
+
+ if (args.length > 2) {
+ String outputClazzName = args[2];
+ outputPackage = getPackageName(outputClazzName);
+ outputName = getBaseClassName(outputClazzName);
+ classPrologOpt = getClass(args[3]);
+ classDownstream = getClass(args[4]);
+ mode = GEN_CUSTOM;
+ if (args.length > 5) {
+ if (args[5].equals("prolog_xor_downstream")) {
+ mode |= GEN_PROLOG_XOR_DOWNSTREAM;
+ }
}
+ } else {
+ outputPackage = getPackageName(classToComposeAroundName);
+ outputName = null; // TBD ..
+ classPrologOpt = null;
+ classDownstream = classToComposeAround;
+ mode = GEN_DEBUG | GEN_TRACE;
}
- } else {
- outputPackage = getPackageName(classToComposeAroundName);
- outputName = null; // TBD ..
- classPrologOpt = null;
- classDownstream = classToComposeAround;
- mode = GEN_DEBUG | GEN_TRACE;
- }
- BuildComposablePipeline composer =
- new BuildComposablePipeline(mode, outputDir, outputPackage, outputName, classToComposeAround, classPrologOpt, classDownstream);
+ BuildComposablePipeline composer =
+ new BuildComposablePipeline(mode, outputDir, outputPackage, outputName, classToComposeAround, classPrologOpt, classDownstream);
- try
- {
- composer.emit();
- }
- catch (IOException e)
- {
- throw new RuntimeException(
- "Error generating composable pipeline source files", e);
- }
- }
-
- protected BuildComposablePipeline(int mode, String outputDir, String outputPackage, String outputName,
- Class classToComposeAround, Class classPrologOpt, Class classDownstream)
- {
- this.mode=mode;
- this.outputDir=outputDir;
- this.outputPackage=outputPackage;
- this.outputName=outputName;
- this.classToComposeAround=classToComposeAround;
- this.classPrologOpt=classPrologOpt;
- this.classDownstream=classDownstream;
-
- if (! classToComposeAround.isInterface())
- {
- throw new IllegalArgumentException(
- classToComposeAround.getName() + " is not an interface class");
- }
-
- try {
- hasImmediateMode =
- (classToComposeAround.getMethod("glBegin", new Class[] { Integer.TYPE }) != null);
- } catch (Exception e) {
+ try {
+ composer.emit();
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Error generating composable pipeline source files", e);
+ }
}
- try {
- hasStackOverflow =
- (classToComposeAround.getField("GL_STACK_OVERFLOW") != null);
- } catch (Exception e) {
- }
- }
-
- /**
- * Emit the java source code for the classes that comprise the composable
- * pipeline.
- */
- public void emit() throws IOException
- {
- List/*<Method>*/ publicMethodsRaw = new ArrayList();
- publicMethodsRaw.addAll(Arrays.asList(classToComposeAround.getMethods()));
- Set/*<Method>*/ publicMethodsPlain = new HashSet();
- for (Iterator iter=publicMethodsRaw.iterator(); iter.hasNext(); ) {
- Method method = (Method) iter.next();
- // Don't hook methods which aren't real GL methods,
- // such as the synthetic "isGL2ES2" "getGL2ES2"
- String name = method.getName();
- boolean runHooks = name.startsWith("gl");
- if (!name.startsWith("getGL") && !name.startsWith("isGL") && !name.equals("toString")) {
- publicMethodsPlain.add(new PlainMethod(method, runHooks));
+ protected BuildComposablePipeline(int mode, String outputDir, String outputPackage, String outputName,
+ Class<?> classToComposeAround, Class<?> classPrologOpt, Class<?> classDownstream) {
+ this.mode = mode;
+ this.outputDir = outputDir;
+ this.outputPackage = outputPackage;
+ this.outputName = outputName;
+ this.classToComposeAround = classToComposeAround;
+ this.classPrologOpt = classPrologOpt;
+ this.classDownstream = classDownstream;
+
+ if (!classToComposeAround.isInterface()) {
+ throw new IllegalArgumentException(
+ classToComposeAround.getName() + " is not an interface class");
+ }
+
+ try {
+ hasImmediateMode =
+ (classToComposeAround.getMethod("glBegin", new Class<?>[]{Integer.TYPE}) != null);
+ } catch (Exception e) {
}
- }
- if(0!=(mode&GEN_DEBUG)) {
- (new DebugPipeline(outputDir, outputPackage, classToComposeAround, classDownstream)).emit(publicMethodsPlain.iterator());
+ try {
+ hasStackOverflow =
+ (classToComposeAround.getField("GL_STACK_OVERFLOW") != null);
+ } catch (Exception e) {
+ }
}
- if(0!=(mode&GEN_TRACE)) {
- (new TracePipeline(outputDir, outputPackage, classToComposeAround, classDownstream)).emit(publicMethodsPlain.iterator());
+
+ /**
+ * Emit the java source code for the classes that comprise the composable
+ * pipeline.
+ */
+ public void emit() throws IOException {
+
+ List<Method> publicMethodsRaw = Arrays.asList(classToComposeAround.getMethods());
+
+ Set<PlainMethod> publicMethodsPlain = new HashSet<PlainMethod>();
+ for (Iterator<Method> iter = publicMethodsRaw.iterator(); iter.hasNext();) {
+ Method method = iter.next();
+ // Don't hook methods which aren't real GL methods,
+ // such as the synthetic "isGL2ES2" "getGL2ES2"
+ String name = method.getName();
+ boolean runHooks = name.startsWith("gl");
+ if (!name.startsWith("getGL") && !name.startsWith("isGL") && !name.equals("toString")) {
+ publicMethodsPlain.add(new PlainMethod(method, runHooks));
+ }
+ }
+
+ if (0 != (mode & GEN_DEBUG)) {
+ (new DebugPipeline(outputDir, outputPackage, classToComposeAround, classDownstream)).emit(publicMethodsPlain.iterator());
+ }
+ if (0 != (mode & GEN_TRACE)) {
+ (new TracePipeline(outputDir, outputPackage, classToComposeAround, classDownstream)).emit(publicMethodsPlain.iterator());
+ }
+ if (0 != (mode & GEN_CUSTOM)) {
+ (new CustomPipeline(mode, outputDir, outputPackage, outputName, classToComposeAround, classPrologOpt, classDownstream)).emit(publicMethodsPlain.iterator());
+ }
}
- if(0!=(mode&GEN_CUSTOM)) {
- (new CustomPipeline(mode, outputDir, outputPackage, outputName, classToComposeAround, classPrologOpt, classDownstream)).emit(publicMethodsPlain.iterator());
+
+ public static String getPackageName(String clazzName) {
+ int lastDot = clazzName.lastIndexOf('.');
+ if (lastDot == -1) {
+ // no package, class is at root level
+ return null;
+ }
+ return clazzName.substring(0, lastDot);
}
- }
-
- public static String getPackageName(String clazzName) {
- int lastDot = clazzName.lastIndexOf('.');
- if (lastDot == -1)
- {
- // no package, class is at root level
- return null;
- }
- return clazzName.substring(0, lastDot);
- }
-
- public static String getBaseClassName(String clazzName) {
- int lastDot = clazzName.lastIndexOf('.');
- if (lastDot == -1)
- {
- // no package, class is at root level
- return clazzName;
- }
- return clazzName.substring(lastDot+1);
- }
-
- //-------------------------------------------------------
-
- protected class PlainMethod
- {
- Method m;
- boolean runHooks;
-
- public PlainMethod(Method m, boolean runHooks) {
- this.m=m;
- this.runHooks = runHooks;
+
+ public static String getBaseClassName(String clazzName) {
+ int lastDot = clazzName.lastIndexOf('.');
+ if (lastDot == -1) {
+ // no package, class is at root level
+ return clazzName;
+ }
+ return clazzName.substring(lastDot + 1);
}
- public Method getWrappedMethod() { return m; }
+ //-------------------------------------------------------
+ protected class PlainMethod {
- public boolean runHooks() { return runHooks; }
+ Method m;
+ boolean runHooks;
- public boolean equals(Object obj) {
- if(obj instanceof PlainMethod) {
- PlainMethod b = (PlainMethod)obj;
- boolean res =
- m.getName().equals(b.m.getName()) &&
- m.getModifiers() == b.m.getModifiers() &&
- m.getReturnType().equals(b.m.getReturnType()) &&
- Arrays.equals( m.getParameterTypes() , b.m.getParameterTypes() ) ;
- return res;
+ PlainMethod(Method m, boolean runHooks) {
+ this.m = m;
+ this.runHooks = runHooks;
}
- return false;
- }
- public int hashCode() {
- int hash = m.getName().hashCode() ^ m.getModifiers() ^ m.getReturnType().hashCode();
- Class[] args = m.getParameterTypes();
- for(int i=0; i<args.length; i++) {
- hash ^= args[i].hashCode();
+ public Method getWrappedMethod() {
+ return m;
}
- return hash;
- }
- public String toString() {
- Class[] args = m.getParameterTypes();
- StringBuffer argsString = new StringBuffer();
- argsString.append("(");
- for (int i = 0; i < args.length; i++) {
- if (i > 0)
- argsString.append(", ");
- argsString.append(args[i].getName());
- }
- argsString.append(")");
- return m.toString() +
- "\n\tname: " + m.getName() +
- "\n\tmods: " + m.getModifiers() +
- "\n\tretu: " + m.getReturnType() +
- "\n\targs[" + args.length + "]: "+argsString.toString();
+ public boolean runHooks() {
+ return runHooks;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof PlainMethod) {
+ PlainMethod b = (PlainMethod) obj;
+ boolean res =
+ m.getName().equals(b.m.getName())
+ && m.getModifiers() == b.m.getModifiers()
+ && m.getReturnType().equals(b.m.getReturnType())
+ && Arrays.equals(m.getParameterTypes(), b.m.getParameterTypes());
+ return res;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = m.getName().hashCode() ^ m.getModifiers() ^ m.getReturnType().hashCode();
+ Class<?>[] args = m.getParameterTypes();
+ for (int i = 0; i < args.length; i++) {
+ hash ^= args[i].hashCode();
+ }
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ Class<?>[] args = m.getParameterTypes();
+ StringBuilder argsString = new StringBuilder();
+ argsString.append("(");
+ for (int i = 0; i < args.length; i++) {
+ if (i > 0) {
+ argsString.append(", ");
+ }
+ argsString.append(args[i].getName());
+ }
+ argsString.append(")");
+ return m.toString()
+ + "\n\tname: " + m.getName()
+ + "\n\tmods: " + m.getModifiers()
+ + "\n\tretu: " + m.getReturnType()
+ + "\n\targs[" + args.length + "]: " + argsString.toString();
+ }
}
- }
-
- /**
- * Emits a Java source file that represents one element of the composable
- * pipeline.
- */
- protected abstract class PipelineEmitter
- {
- private File file;
- protected String basePackage;
- protected String baseName; // does not include package!
- protected String downstreamPackage;
- protected String downstreamName; // does not include package!
- protected String prologPackageOpt=null;
- protected String prologNameOpt=null; // does not include package!
-
- protected String outputDir;
- protected String outputPackage;
- protected Class baseInterfaceClass;
- protected Class prologClassOpt=null;
- protected Class downstreamClass;
/**
- * @param outputDir the directory into which the pipeline classes will be
- * generated.
- * @param baseInterfaceClassName the full class name (including package,
- * e.g. "java.lang.String") of the interface that the pipeline wraps
- * @exception IllegalArgumentException if classToComposeAround is not an
- * interface.
+ * Emits a Java source file that represents one element of the composable
+ * pipeline.
*/
- public PipelineEmitter(String outputDir, String outputPackage, Class baseInterfaceClass, Class prologClassOpt, Class downstreamClass)
- {
- this.outputDir=outputDir;
- this.outputPackage=outputPackage;
- this.baseInterfaceClass=baseInterfaceClass;
- this.prologClassOpt=prologClassOpt;
- this.downstreamClass=downstreamClass;
-
- basePackage = getPackageName(baseInterfaceClass.getName());
- baseName = getBaseClassName(baseInterfaceClass.getName());
- downstreamPackage = getPackageName(downstreamClass.getName());
- downstreamName = getBaseClassName(downstreamClass.getName());
- if(null!=prologClassOpt) {
- prologPackageOpt = getPackageName(prologClassOpt.getName());
- prologNameOpt = getBaseClassName(prologClassOpt.getName());
- }
- }
+ protected abstract class PipelineEmitter {
+
+ private File file;
+ protected String basePackage;
+ protected String baseName; // does not include package!
+ protected String downstreamPackage;
+ protected String downstreamName; // does not include package!
+ protected String prologPackageOpt = null;
+ protected String prologNameOpt = null; // does not include package!
+ protected String outputDir;
+ protected String outputPackage;
+ protected Class<?> baseInterfaceClass;
+ protected Class<?> prologClassOpt = null;
+ protected Class<?> downstreamClass;
+
+ /**
+ * @param outputDir the directory into which the pipeline classes will be
+ * generated.
+ * @param baseInterfaceClassName the full class name (including package,
+ * e.g. "java.lang.String") of the interface that the pipeline wraps
+ * @exception IllegalArgumentException if classToComposeAround is not an
+ * interface.
+ */
+ PipelineEmitter(String outputDir, String outputPackage, Class<?> baseInterfaceClass, Class<?> prologClassOpt, Class<?> downstreamClass) {
+ this.outputDir = outputDir;
+ this.outputPackage = outputPackage;
+ this.baseInterfaceClass = baseInterfaceClass;
+ this.prologClassOpt = prologClassOpt;
+ this.downstreamClass = downstreamClass;
+
+ basePackage = getPackageName(baseInterfaceClass.getName());
+ baseName = getBaseClassName(baseInterfaceClass.getName());
+ downstreamPackage = getPackageName(downstreamClass.getName());
+ downstreamName = getBaseClassName(downstreamClass.getName());
+ if (null != prologClassOpt) {
+ prologPackageOpt = getPackageName(prologClassOpt.getName());
+ prologNameOpt = getBaseClassName(prologClassOpt.getName());
+ }
+ }
+
+ public void emit(Iterator<PlainMethod> methodsToWrap) throws IOException {
+ String outputClassName = getOutputName();
+ this.file = new File(outputDir + File.separatorChar + outputClassName + ".java");
+ String parentDir = file.getParent();
+ if (parentDir != null) {
+ File pDirFile = new File(parentDir);
+ pDirFile.mkdirs();
+ }
- public void emit(Iterator/*<Method>*/ methodsToWrap) throws IOException
- {
- String outputClassName = getOutputName();
- this.file = new File(outputDir + File.separatorChar + outputClassName + ".java");
- String parentDir = file.getParent();
- if (parentDir != null)
- {
- File pDirFile = new File(parentDir);
- pDirFile.mkdirs();
- }
-
- PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file)));
-
- List baseInterfaces = Arrays.asList(baseInterfaceClass.getInterfaces());
- HashSet clazzList = new HashSet();
- clazzList.add(baseInterfaceClass);
- clazzList.addAll(baseInterfaces);
- int ifNamesNumber = clazzList.size();
-
- // keep original order ..
- clazzList.clear();
- String[] ifNames = new String[ifNamesNumber];
- {
- int i=0;
-
- 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);
+ PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+
+ List<Class<?>> baseInterfaces = Arrays.asList(baseInterfaceClass.getInterfaces());
+ HashSet<Class<?>> clazzList = new HashSet<Class<?>>();
+ clazzList.add(baseInterfaceClass);
+ clazzList.addAll(baseInterfaces);
+ int ifNamesNumber = clazzList.size();
+
+ // keep original order ..
+ clazzList.clear();
+ String[] ifNames = new String[ifNamesNumber];
+ {
+ int i = 0;
+
+ for (Iterator<Class<?>> iter = baseInterfaces.iterator(); iter.hasNext();) {
+ Class<?> ifClass = iter.next();
+ if (!clazzList.contains(ifClass)) {
+ ifNames[i++] = ifClass.getName();
+ clazzList.add(ifClass);
+ }
}
- }
-
- if(null!=baseInterfaceClass && !clazzList.contains(baseInterfaceClass)) {
- ifNames[i++] = new String(baseInterfaceClass.getName());
- clazzList.add(baseInterfaceClass);
- }
- }
-
- clazzList.add(downstreamClass);
- if(null!=prologClassOpt) {
- clazzList.add(prologClassOpt);
- }
-
- String[] importNames = new String[clazzList.size()+2];
- {
- int i=0;
- importNames[i++] = new String("java.io.*");
- importNames[i++] = new String("javax.media.opengl.*");
- for (Iterator iter=clazzList.iterator(); iter.hasNext(); ) {
- importNames[i++] = new String(((Class)iter.next()).getName());
- }
- }
-
- CodeGenUtils.emitJavaHeaders(output,
- outputPackage,
- outputClassName,
- "com.jogamp.gluegen.runtime", // FIXME: should make configurable
- true,
- importNames,
- new String[] { "public" },
- ifNames,
- null,
- new CodeGenUtils.EmissionCallback() {
- public void emit(PrintWriter w) { emitClassDocComment(w); }
- }
- );
-
- preMethodEmissionHook(output);
-
- constructorHook(output);
-
- emitGLIsMethods(output);
- emitGLGetMethods(output);
-
- while (methodsToWrap.hasNext())
- {
- PlainMethod pm = (PlainMethod)methodsToWrap.next();
- Method m = pm.getWrappedMethod();
- emitMethodDocComment(output, m);
- emitSignature(output, m);
- emitBody(output, m, pm.runHooks());
- }
-
- postMethodEmissionHook(output);
-
- output.println();
- output.print(" private " + downstreamName + " " + getDownstreamObjectName() + ";");
-
- // end the class
- output.println();
- output.print("} // end class ");
- output.println(outputClassName);
-
- output.flush();
- output.close();
-
- System.out.println("wrote to file: "+file); // JAU
- }
- /** Get the name of the object through which API calls should be routed. */
- protected String getDownstreamObjectName()
- {
- return "downstream" + downstreamName;
- }
-
- /** Get the name of the object which shall be called as a prolog. */
- protected String getPrologObjectNameOpt()
- {
- if(null!=prologNameOpt) {
- return "prolog" + prologNameOpt;
- }
- return null;
- }
-
- protected void emitMethodDocComment(PrintWriter output, Method m)
- {
- }
-
- protected void emitSignature(PrintWriter output, Method m)
- {
- output.print(" public ");
- output.print(' ');
- output.print(JavaType.createForClass(m.getReturnType()).getName());
- output.print(' ');
- output.print(m.getName());
- output.print('(');
- output.print(getArgListAsString(m, true, true));
- output.println(")");
- }
-
- protected void emitBody(PrintWriter output, Method m, boolean runHooks)
- {
- output.println(" {");
- output.print(" ");
- Class retType = m.getReturnType();
-
- boolean callPreDownstreamHook = runHooks && hasPreDownstreamCallHook(m);
- boolean callPostDownstreamHook = runHooks && hasPostDownstreamCallHook(m);
- boolean callDownstream = (null!=getMethod(downstreamClass, m)) &&
- !( 0!=(GEN_PROLOG_XOR_DOWNSTREAM&getMode()) && callPreDownstreamHook ) ;
- boolean hasResult = (retType != Void.TYPE);
-
- if(!callDownstream) {
- if(!emptyDownstreamAllowed()) {
- throw new RuntimeException("Method "+m+" has no downstream ("+downstreamName+")");
- }
- }
-
- if(!callPreDownstreamHook && !callPostDownstreamHook && !callDownstream) {
- if(!emptyMethodAllowed()) {
- throw new RuntimeException("Method "+m+" is empty, no downstream ("+downstreamName+") nor prolog ("+prologNameOpt+").");
- } else {
- output.print(" if(DEBUG) { System.out.println(\"WARNING: No prolog, no downstream, empty: \"+");
- printFunctionCallString(output, m);
- output.println("); } ");
+ if (null != baseInterfaceClass && !clazzList.contains(baseInterfaceClass)) {
+ ifNames[i++] = baseInterfaceClass.getName();
+ clazzList.add(baseInterfaceClass);
+ }
+ }
+
+ clazzList.add(downstreamClass);
+ if (null != prologClassOpt) {
+ clazzList.add(prologClassOpt);
+ }
+
+ String[] importNames = new String[clazzList.size() + 2];
+ {
+ int i = 0;
+ importNames[i++] = "java.io.*";
+ importNames[i++] = "javax.media.opengl.*";
+ for (Iterator<Class<?>> iter = clazzList.iterator(); iter.hasNext();) {
+ importNames[i++] = iter.next().getName();
+ }
+ }
+
+ CodeGenUtils.emitJavaHeaders(output,
+ outputPackage,
+ outputClassName,
+ "com.jogamp.gluegen.runtime", // FIXME: should make configurable
+ true,
+ importNames,
+ new String[]{"public"},
+ ifNames,
+ null,
+ new CodeGenUtils.EmissionCallback() {
+ public void emit(PrintWriter w) {
+ emitClassDocComment(w);
+ }
+ });
+
+ preMethodEmissionHook(output);
+
+ constructorHook(output);
+
+ emitGLIsMethods(output);
+ emitGLGetMethods(output);
+
+ while (methodsToWrap.hasNext()) {
+ PlainMethod pm = methodsToWrap.next();
+ Method m = pm.getWrappedMethod();
+ emitMethodDocComment(output, m);
+ emitSignature(output, m);
+ emitBody(output, m, pm.runHooks());
+ }
+
+ postMethodEmissionHook(output);
+
+ output.println();
+ output.print(" private " + downstreamName + " " + getDownstreamObjectName() + ";");
+
+ // end the class
+ output.println();
+ output.print("} // end class ");
+ output.println(outputClassName);
+
+ output.flush();
+ output.close();
+
+ System.out.println("wrote to file: " + file); // JAU
}
- }
- if (callPreDownstreamHook) {
- if(hasResult && !callDownstream) {
- if(callPostDownstreamHook) {
- output.print(" "+JavaType.createForClass(retType).getName());
- output.print(" _res = ");
- } else {
- output.print(" return ");
+ /** Get the name of the object through which API calls should be routed. */
+ protected String getDownstreamObjectName() {
+ return "downstream" + downstreamName;
+ }
+
+ /** Get the name of the object which shall be called as a prolog. */
+ protected String getPrologObjectNameOpt() {
+ if (null != prologNameOpt) {
+ return "prolog" + prologNameOpt;
}
- }
- preDownstreamCallHook(output, m);
- }
-
- if(callDownstream) {
- if (hasResult) {
- if(callPostDownstreamHook) {
- output.print(" "+JavaType.createForClass(retType).getName());
- output.print(" _res = ");
- } else {
- output.print(" return ");
+ return null;
+ }
+
+ protected void emitMethodDocComment(PrintWriter output, Method m) {
+ }
+
+ protected void emitSignature(PrintWriter output, Method m) {
+ output.print(" public ");
+ output.print(' ');
+ output.print(JavaType.createForClass(m.getReturnType()).getName());
+ output.print(' ');
+ output.print(m.getName());
+ output.print('(');
+ output.print(getArgListAsString(m, true, true));
+ output.println(")");
+ }
+
+ protected void emitBody(PrintWriter output, Method m, boolean runHooks) {
+ output.println(" {");
+ output.print(" ");
+ Class<?> retType = m.getReturnType();
+
+ boolean callPreDownstreamHook = runHooks && hasPreDownstreamCallHook(m);
+ boolean callPostDownstreamHook = runHooks && hasPostDownstreamCallHook(m);
+ boolean callDownstream = (null != getMethod(downstreamClass, m))
+ && !(0 != (GEN_PROLOG_XOR_DOWNSTREAM & getMode()) && callPreDownstreamHook);
+ boolean hasResult = (retType != Void.TYPE);
+
+ if (!callDownstream) {
+ if (!emptyDownstreamAllowed()) {
+ throw new RuntimeException("Method " + m + " has no downstream (" + downstreamName + ")");
+ }
}
- }
- output.print(getDownstreamObjectName());
- output.print('.');
- output.print(m.getName());
- output.print('(');
- output.print(getArgListAsString(m, false, true));
- output.println(");");
- }
-
- if (callPostDownstreamHook) {
- postDownstreamCallHook(output, m);
- }
-
- if (hasResult && callDownstream && callPostDownstreamHook) {
- output.println(" return _res;");
- }
- output.println(" }");
- }
+ if (!callPreDownstreamHook && !callPostDownstreamHook && !callDownstream) {
+ if (!emptyMethodAllowed()) {
+ throw new RuntimeException("Method " + m + " is empty, no downstream (" + downstreamName + ") nor prolog (" + prologNameOpt + ").");
+ } else {
+ output.print(" if(DEBUG) { System.out.println(\"WARNING: No prolog, no downstream, empty: \"+");
+ printFunctionCallString(output, m);
+ output.println("); } ");
+ }
+ }
- protected String getArgListAsString(Method m, boolean includeArgTypes, boolean includeArgNames)
- {
- StringBuffer buf = new StringBuffer(256);
- if (!includeArgNames && !includeArgTypes)
- {
- throw new IllegalArgumentException(
- "Cannot generate arglist without both arg types and arg names");
- }
-
- Class[] argTypes = m.getParameterTypes();
- for (int i = 0; i < argTypes.length; ++i)
- {
- if (includeArgTypes)
- {
- buf.append(JavaType.createForClass(argTypes[i]).getName());
- buf.append(' ');
- }
-
- if (includeArgNames)
- {
- buf.append("arg");
- buf.append(i);
- }
- if (i < argTypes.length-1) { buf.append(','); }
- }
-
- return buf.toString();
- }
-
- /** The name of the class around which this pipeline is being
- * composed. E.g., if this pipeline was constructed with
- * "java.util.Set" as the baseInterfaceClassName, then this method will
- * return "Set".
- */
- protected String getBaseInterfaceName()
- {
- return baseName;
- }
-
- /** Get the output name for this pipeline class. */
- protected abstract String getOutputName();
+ if (callPreDownstreamHook) {
+ if (hasResult && !callDownstream) {
+ if (callPostDownstreamHook) {
+ output.print(" " + JavaType.createForClass(retType).getName());
+ output.print(" _res = ");
+ } else {
+ output.print(" return ");
+ }
+ }
+ preDownstreamCallHook(output, m);
+ }
- /**
- * Called after the class headers have been generated, but before any
- * method wrappers have been generated.
- */
- protected void preMethodEmissionHook(PrintWriter output) {
- output.println(" public static final boolean DEBUG = com.jogamp.opengl.impl.Debug.debug(\""+getOutputName()+"\");");
- }
+ if (callDownstream) {
+ if (hasResult) {
+ if (callPostDownstreamHook) {
+ output.print(" " + JavaType.createForClass(retType).getName());
+ output.print(" _res = ");
+ } else {
+ output.print(" return ");
+ }
+ }
+ output.print(getDownstreamObjectName());
+ output.print('.');
+ output.print(m.getName());
+ output.print('(');
+ output.print(getArgListAsString(m, false, true));
+ output.println(");");
+ }
- /**
- * Emits the constructor for the pipeline; called after the preMethodEmissionHook.
- */
- protected abstract void constructorHook(PrintWriter output);
+ if (callPostDownstreamHook) {
+ postDownstreamCallHook(output, m);
+ }
- /**
- * Called after the method wrappers have been generated, but before the
- * closing parenthesis of the class is emitted.
- */
- protected void postMethodEmissionHook(PrintWriter output) {
- output.println( " public String toString() {");
- output.println( " StringBuffer sb = new StringBuffer();");
- output.println( " sb.append(\""+getOutputName()+" [ implementing "+baseInterfaceClass.getName()+",\\n\\t\");");
- if(null!=prologClassOpt) {
- output.println( " sb.append(\" prolog: \"+"+getPrologObjectNameOpt()+".toString()+\",\\n\\t\");");
- }
- output.println( " sb.append(\" downstream: \"+"+getDownstreamObjectName()+".toString()+\"\\n\\t]\");");
- output.println( " return sb.toString();");
- output.println( " }");
- }
+ if (hasResult && callDownstream && callPostDownstreamHook) {
+ output.println(" return _res;");
+ }
+ output.println(" }");
- /**
- * Called before the pipeline routes the call to the downstream object.
- */
- protected abstract void preDownstreamCallHook(PrintWriter output, Method m);
- protected abstract boolean hasPreDownstreamCallHook(Method m);
+ }
- /**
- * Called after the pipeline has routed the call to the downstream object,
- * but before the calling function exits or returns a value.
- */
- protected abstract void postDownstreamCallHook(PrintWriter output, Method m);
+ protected String getArgListAsString(Method m, boolean includeArgTypes, boolean includeArgNames) {
+ StringBuilder buf = new StringBuilder(256);
+ if (!includeArgNames && !includeArgTypes) {
+ throw new IllegalArgumentException(
+ "Cannot generate arglist without both arg types and arg names");
+ }
- protected abstract boolean hasPostDownstreamCallHook(Method m);
+ Class<?>[] argTypes = m.getParameterTypes();
+ for (int i = 0; i < argTypes.length; ++i) {
+ if (includeArgTypes) {
+ buf.append(JavaType.createForClass(argTypes[i]).getName());
+ buf.append(' ');
+ }
- protected abstract int getMode();
- protected abstract boolean emptyMethodAllowed();
- protected abstract boolean emptyDownstreamAllowed();
+ if (includeArgNames) {
+ buf.append("arg");
+ buf.append(i);
+ }
+ if (i < argTypes.length - 1) {
+ buf.append(',');
+ }
+ }
- /** Emit a Javadoc comment for this pipeline class. */
- protected abstract void emitClassDocComment(PrintWriter output);
+ return buf.toString();
+ }
- /**
- * Emits one of the isGL* methods.
- */
- protected void emitGLIsMethod(PrintWriter output, String type) {
- output.println(" public boolean is" + type + "() {");
- Class clazz = BuildComposablePipeline.getClass("javax.media.opengl." + type);
- if (clazz.isAssignableFrom(baseInterfaceClass)) {
- output.println(" return true;");
- } else {
- output.println(" return false;");
- }
- output.println(" }");
- }
+ /** The name of the class around which this pipeline is being
+ * composed. E.g., if this pipeline was constructed with
+ * "java.util.Set" as the baseInterfaceClassName, then this method will
+ * return "Set".
+ */
+ protected String getBaseInterfaceName() {
+ return baseName;
+ }
- /**
- * Emits all of the isGL* methods.
- */
- protected void emitGLIsMethods(PrintWriter output) {
- emitGLIsMethod(output, "GL");
- emitGLIsMethod(output, "GL3bc");
- emitGLIsMethod(output, "GL3");
- emitGLIsMethod(output, "GL2");
- emitGLIsMethod(output, "GLES1");
- emitGLIsMethod(output, "GLES2");
- emitGLIsMethod(output, "GL2ES1");
- emitGLIsMethod(output, "GL2ES2");
- emitGLIsMethod(output, "GL2GL3");
- output.println(" public boolean isGLES() {");
- output.println(" return isGLES2() || isGLES1();");
- output.println(" }");
- }
- /**
- * Emits one of the getGL* methods.
- */
- protected void emitGLGetMethod(PrintWriter output, String type) {
- output.println(" public javax.media.opengl." + type + " get" + type + "() {");
- Class clazz = BuildComposablePipeline.getClass("javax.media.opengl." + type);
- if (clazz.isAssignableFrom(baseInterfaceClass)) {
- output.println(" return this;");
- } else {
- output.println(" throw new GLException(\"Not a " + type + " implementation\");");
- }
- output.println(" }");
- }
+ /** Get the output name for this pipeline class. */
+ protected abstract String getOutputName();
- /**
- * Emits all of the getGL* methods.
- */
- protected void emitGLGetMethods(PrintWriter output) {
- emitGLGetMethod(output, "GL");
- emitGLGetMethod(output, "GL3bc");
- emitGLGetMethod(output, "GL3");
- emitGLGetMethod(output, "GL2");
- emitGLGetMethod(output, "GLES1");
- emitGLGetMethod(output, "GLES2");
- emitGLGetMethod(output, "GL2ES1");
- emitGLGetMethod(output, "GL2ES2");
- emitGLGetMethod(output, "GL2GL3");
- output.println(" public GLProfile getGLProfile() {");
- output.println(" return "+getDownstreamObjectName()+".getGLProfile();");
- output.println(" }");
- }
- } // end class PipelineEmitter
+ /**
+ * Called after the class headers have been generated, but before any
+ * method wrappers have been generated.
+ */
+ protected void preMethodEmissionHook(PrintWriter output) {
+ output.println(" public static final boolean DEBUG = com.jogamp.opengl.impl.Debug.debug(\"" + getOutputName() + "\");");
+ }
- //-------------------------------------------------------
+ /**
+ * Emits the constructor for the pipeline; called after the preMethodEmissionHook.
+ */
+ protected abstract void constructorHook(PrintWriter output);
+
+ /**
+ * Called after the method wrappers have been generated, but before the
+ * closing parenthesis of the class is emitted.
+ */
+ protected void postMethodEmissionHook(PrintWriter output) {
+ output.println(" public String toString() {");
+ output.println(" StringBuffer sb = new StringBuffer();");
+ output.println(" sb.append(\"" + getOutputName() + " [ implementing " + baseInterfaceClass.getName() + ",\\n\\t\");");
+ if (null != prologClassOpt) {
+ output.println(" sb.append(\" prolog: \"+" + getPrologObjectNameOpt() + ".toString()+\",\\n\\t\");");
+ }
+ output.println(" sb.append(\" downstream: \"+" + getDownstreamObjectName() + ".toString()+\"\\n\\t]\");");
+ output.println(" return sb.toString();");
+ output.println(" }");
+ }
- protected class CustomPipeline extends PipelineEmitter
- {
- String className;
- int mode;
+ /**
+ * Called before the pipeline routes the call to the downstream object.
+ */
+ protected abstract void preDownstreamCallHook(PrintWriter output, Method m);
- public CustomPipeline(int mode, String outputDir, String outputPackage, String outputName, Class baseInterfaceClass, Class prologClassOpt, Class downstreamClass)
- {
- super(outputDir, outputPackage, baseInterfaceClass, prologClassOpt, downstreamClass);
- className = outputName;
- this.mode = mode;
- }
+ protected abstract boolean hasPreDownstreamCallHook(Method m);
- protected String getOutputName()
- {
- return className;
- }
+ /**
+ * Called after the pipeline has routed the call to the downstream object,
+ * but before the calling function exits or returns a value.
+ */
+ protected abstract void postDownstreamCallHook(PrintWriter output, Method m);
- protected int getMode() { return mode; }
+ protected abstract boolean hasPostDownstreamCallHook(Method m);
- protected boolean emptyMethodAllowed() {
- return true;
- }
- protected boolean emptyDownstreamAllowed() {
- return true;
- }
+ protected abstract int getMode();
- protected void preMethodEmissionHook(PrintWriter output)
- {
- super.preMethodEmissionHook(output);
- }
+ protected abstract boolean emptyMethodAllowed();
- protected void constructorHook(PrintWriter output) {
- output.print( " public " + getOutputName() + "(" );
- output.print( downstreamName + " " + getDownstreamObjectName() );
- if(null!=prologNameOpt) {
- output.println( ", " + prologNameOpt + " " + getPrologObjectNameOpt() + ")");
- } else {
- output.println(")");
- }
- output.println(" {");
- output.println(" if (" + getDownstreamObjectName() + " == null) {");
- output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
- output.println(" }");
- output.print( " this." + getDownstreamObjectName());
- output.println(" = " + getDownstreamObjectName() + ";");
- if(null!=prologNameOpt) {
- output.print( " this." + getPrologObjectNameOpt());
- output.println(" = " + getPrologObjectNameOpt() + ";");
- }
- output.println(" }");
- output.println();
- }
+ protected abstract boolean emptyDownstreamAllowed();
- protected void postMethodEmissionHook(PrintWriter output)
- {
- super.postMethodEmissionHook(output);
- if(null!=prologNameOpt) {
- output.print(" private " + prologNameOpt + " " + getPrologObjectNameOpt() + ";");
- }
- }
+ /** Emit a Javadoc comment for this pipeline class. */
+ protected abstract void emitClassDocComment(PrintWriter output);
- protected void emitClassDocComment(PrintWriter output)
- {
- output.println("/**");
- output.println(" * Composable pipeline {@link "+outputPackage+"."+outputName+"}, implementing the interface");
- output.println(" * {@link "+baseInterfaceClass.getName()+"}");
- output.println(" * <p>");
- output.println(" * Each method follows the call graph <ul>");
- if(null!=prologClassOpt) {
- output.println(" * <li> call <em>prolog</em> {@link "+prologClassOpt.getName()+"} if available");
- }
- output.println(" * <li> call <em>downstream</em> {@link "+downstreamClass.getName()+"} if available");
- if(null!=prologClassOpt && 0!=(GEN_PROLOG_XOR_DOWNSTREAM&getMode())) {
- output.println(" * <strong>and</strong> if no call to {@link "+prologClassOpt.getName()+"} is made");
- }
- output.println(" * </ul><p>");
- output.println(" * ");
- output.println(" * <ul>");
- output.println(" * <li> <em>Interface</em> {@link "+baseInterfaceClass.getName()+"}");
- if(null!=prologClassOpt) {
- output.println(" * <li> <em>Prolog</em> {@link "+prologClassOpt.getName()+"}");
- }
- output.println(" * <li> <em>Downstream</em> {@link "+downstreamClass.getName()+"}");
- output.println(" * </ul><p>");
- output.println(" * Sample code which installs this pipeline: </P>");
- output.println(" * ");
- output.println("<PRE>");
- if(null!=prologNameOpt) {
- output.println(" GL gl = drawable.setGL( new "+className+"( drawable.getGL().getGL2ES2(), new "+prologNameOpt+"( drawable.getGL().getGL2ES2() ) ) );");
- } else {
- output.println(" GL gl = drawable.setGL( new "+className+"( drawable.getGL().getGL2ES2() ) );");
- }
- output.println("</PRE>");
- output.println("*/");
- }
-
- protected boolean hasPreDownstreamCallHook(Method m) {
- return null!=getMethod(prologClassOpt, m);
- }
+ /**
+ * Emits one of the isGL* methods.
+ */
+ protected void emitGLIsMethod(PrintWriter output, String type) {
+ output.println(" public boolean is" + type + "() {");
+ Class<?> clazz = BuildComposablePipeline.getClass("javax.media.opengl." + type);
+ if (clazz.isAssignableFrom(baseInterfaceClass)) {
+ output.println(" return true;");
+ } else {
+ output.println(" return false;");
+ }
+ output.println(" }");
+ }
- protected void preDownstreamCallHook(PrintWriter output, Method m)
- {
- if(null!=prologNameOpt) {
- output.print(getPrologObjectNameOpt());
- output.print('.');
- output.print(m.getName());
- output.print('(');
- output.print(getArgListAsString(m, false, true));
- output.println(");");
- }
- }
+ /**
+ * Emits all of the isGL* methods.
+ */
+ protected void emitGLIsMethods(PrintWriter output) {
+ emitGLIsMethod(output, "GL");
+ emitGLIsMethod(output, "GL3bc");
+ emitGLIsMethod(output, "GL3");
+ emitGLIsMethod(output, "GL2");
+ emitGLIsMethod(output, "GLES1");
+ emitGLIsMethod(output, "GLES2");
+ emitGLIsMethod(output, "GL2ES1");
+ emitGLIsMethod(output, "GL2ES2");
+ emitGLIsMethod(output, "GL2GL3");
+ output.println(" public boolean isGLES() {");
+ output.println(" return isGLES2() || isGLES1();");
+ output.println(" }");
+ }
- protected boolean hasPostDownstreamCallHook(Method m) {
- return false;
- }
+ /**
+ * Emits one of the getGL* methods.
+ */
+ protected void emitGLGetMethod(PrintWriter output, String type) {
+ output.println(" public javax.media.opengl." + type + " get" + type + "() {");
+ Class<?> clazz = BuildComposablePipeline.getClass("javax.media.opengl." + type);
+ if (clazz.isAssignableFrom(baseInterfaceClass)) {
+ output.println(" return this;");
+ } else {
+ output.println(" throw new GLException(\"Not a " + type + " implementation\");");
+ }
+ output.println(" }");
+ }
- protected void postDownstreamCallHook(PrintWriter output, Method m)
- {
- }
+ /**
+ * Emits all of the getGL* methods.
+ */
+ protected void emitGLGetMethods(PrintWriter output) {
+ emitGLGetMethod(output, "GL");
+ emitGLGetMethod(output, "GL3bc");
+ emitGLGetMethod(output, "GL3");
+ emitGLGetMethod(output, "GL2");
+ emitGLGetMethod(output, "GLES1");
+ emitGLGetMethod(output, "GLES2");
+ emitGLGetMethod(output, "GL2ES1");
+ emitGLGetMethod(output, "GL2ES2");
+ emitGLGetMethod(output, "GL2GL3");
+ output.println(" public GLProfile getGLProfile() {");
+ output.println(" return " + getDownstreamObjectName() + ".getGLProfile();");
+ output.println(" }");
+ }
+ } // end class PipelineEmitter
- } // end class CustomPipeline
+ //-------------------------------------------------------
+ protected class CustomPipeline extends PipelineEmitter {
- protected class DebugPipeline extends PipelineEmitter
- {
- String className;
- public DebugPipeline(String outputDir, String outputPackage, Class baseInterfaceClass, Class downstreamClass)
- {
- super(outputDir, outputPackage, baseInterfaceClass, null, downstreamClass);
- className = "Debug" + getBaseInterfaceName();
- }
+ String className;
+ int mode;
- protected String getOutputName()
- {
- return className;
- }
+ CustomPipeline(int mode, String outputDir, String outputPackage, String outputName, Class<?> baseInterfaceClass, Class<?> prologClassOpt, Class<?> downstreamClass) {
+ super(outputDir, outputPackage, baseInterfaceClass, prologClassOpt, downstreamClass);
+ className = outputName;
+ this.mode = mode;
+ }
- protected int getMode() { return 0; }
+ protected String getOutputName() {
+ return className;
+ }
- protected boolean emptyMethodAllowed() {
- return false;
- }
- protected boolean emptyDownstreamAllowed() {
- return false;
- }
+ protected int getMode() {
+ return mode;
+ }
- protected void preMethodEmissionHook(PrintWriter output)
- {
- super.preMethodEmissionHook(output);
- }
+ protected boolean emptyMethodAllowed() {
+ return true;
+ }
- protected void constructorHook(PrintWriter output) {
- output.print( " public " + getOutputName() + "(" );
- output.println( downstreamName + " " + getDownstreamObjectName() + ")");
- output.println(" {");
- output.println(" if (" + getDownstreamObjectName() + " == null) {");
- output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
- output.println(" }");
- output.print( " this." + getDownstreamObjectName());
- output.println(" = " + getDownstreamObjectName() + ";");
- if(null!=prologNameOpt) {
- output.print( " this." + getPrologObjectNameOpt());
- output.println(" = " + getPrologObjectNameOpt() + ";");
- }
- output.println(" // Fetch GLContext object for better error checking (if possible)");
- output.println(" _context = " + getDownstreamObjectName() + ".getContext();");
- output.println(" }");
- output.println();
- }
+ protected boolean emptyDownstreamAllowed() {
+ return true;
+ }
- protected void postMethodEmissionHook(PrintWriter output)
- {
- super.postMethodEmissionHook(output);
- output.println(" private void checkGLGetError(String caller)");
- output.println(" {");
- if (hasImmediateMode) {
- output.println(" if (insideBeginEndPair) {");
- output.println(" return;");
- output.println(" }");
- output.println();
- }
- output.println(" // Debug code to make sure the pipeline is working; leave commented out unless testing this class");
- output.println(" //System.err.println(\"Checking for GL errors " +
- "after call to \" + caller);");
- output.println();
- output.println(" int err = " +
- getDownstreamObjectName() +
- ".glGetError();");
- output.println(" if (err == GL_NO_ERROR) { return; }");
- output.println();
- output.println(" StringBuffer buf = new StringBuffer(Thread.currentThread()+");
- output.println(" \" glGetError() returned the following error codes " +
- "after a call to \" + caller + \": \");");
- output.println();
- output.println(" // Loop repeatedly to allow for distributed GL implementations,");
- output.println(" // as detailed in the glGetError() specification");
- output.println(" int recursionDepth = 10;");
- output.println(" do {");
- output.println(" switch (err) {");
- output.println(" case GL_INVALID_ENUM: buf.append(\"GL_INVALID_ENUM \"); break;");
- output.println(" case GL_INVALID_VALUE: buf.append(\"GL_INVALID_VALUE \"); break;");
- output.println(" case GL_INVALID_OPERATION: buf.append(\"GL_INVALID_OPERATION \"); break;");
- if (hasStackOverflow) {
- output.println(" case GL_STACK_OVERFLOW: buf.append(\"GL_STACK_OVERFLOW \"); break;");
- output.println(" case GL_STACK_UNDERFLOW: buf.append(\"GL_STACK_UNDERFLOW \"); break;");
- }
- output.println(" case GL_OUT_OF_MEMORY: buf.append(\"GL_OUT_OF_MEMORY \"); break;");
- output.println(" case GL_NO_ERROR: throw new InternalError(\"Should not be treating GL_NO_ERROR as error\");");
- output.println(" default: buf.append(\"Unknown glGetError() return value: \");");
- output.println(" }");
- output.println(" buf.append(\"( \" + err + \" 0x\"+Integer.toHexString(err).toUpperCase() + \"), \");");
- output.println(" } while ((--recursionDepth >= 0) && (err = " +
- getDownstreamObjectName() +
- ".glGetError()) != GL_NO_ERROR);");
- output.println(" throw new GLException(buf.toString());");
- output.println(" }");
- if (hasImmediateMode) {
- output.println(" /** True if the pipeline is inside a glBegin/glEnd pair.*/");
- output.println(" private boolean insideBeginEndPair = false;");
- output.println();
- }
- output.println(" private void checkContext() {");
- output.println(" GLContext currentContext = GLContext.getCurrent();");
- output.println(" if (currentContext == null) {");
- output.println(" throw new GLException(\"No OpenGL context is current on this thread\");");
- output.println(" }");
- output.println(" if ((_context != null) && (_context != currentContext)) {");
- output.println(" throw new GLException(\"This GL object is being incorrectly used with a different GLContext than that which created it\");");
- output.println(" }");
- output.println(" }");
- output.println(" private GLContext _context;");
- }
+ @Override
+ protected void preMethodEmissionHook(PrintWriter output) {
+ super.preMethodEmissionHook(output);
+ }
- protected void emitClassDocComment(PrintWriter output)
- {
- output.println("/** <P> Composable pipeline which wraps an underlying {@link GL} implementation,");
- output.println(" providing error checking after each OpenGL method call. If an error occurs,");
- output.println(" causes a {@link GLException} to be thrown at exactly the point of failure.");
- output.println(" Sample code which installs this pipeline: </P>");
- output.println();
- output.println("<PRE>");
- output.println(" GL gl = drawable.setGL(new DebugGL(drawable.getGL()));");
- output.println("</PRE>");
- output.println("*/");
- }
-
- protected boolean hasPreDownstreamCallHook(Method m) {
- return true;
- }
+ protected void constructorHook(PrintWriter output) {
+ output.print(" public " + getOutputName() + "(");
+ output.print(downstreamName + " " + getDownstreamObjectName());
+ if (null != prologNameOpt) {
+ output.println(", " + prologNameOpt + " " + getPrologObjectNameOpt() + ")");
+ } else {
+ output.println(")");
+ }
+ output.println(" {");
+ output.println(" if (" + getDownstreamObjectName() + " == null) {");
+ output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
+ output.println(" }");
+ output.print(" this." + getDownstreamObjectName());
+ output.println(" = " + getDownstreamObjectName() + ";");
+ if (null != prologNameOpt) {
+ output.print(" this." + getPrologObjectNameOpt());
+ output.println(" = " + getPrologObjectNameOpt() + ";");
+ }
+ output.println(" }");
+ output.println();
+ }
- protected void preDownstreamCallHook(PrintWriter output, Method m)
- {
- output.println(" checkContext();");
- }
+ @Override
+ protected void postMethodEmissionHook(PrintWriter output) {
+ super.postMethodEmissionHook(output);
+ if (null != prologNameOpt) {
+ output.print(" private " + prologNameOpt + " " + getPrologObjectNameOpt() + ";");
+ }
+ }
- protected boolean hasPostDownstreamCallHook(Method m) {
- return true;
- }
+ protected void emitClassDocComment(PrintWriter output) {
+ output.println("/**");
+ output.println(" * Composable pipeline {@link " + outputPackage + "." + outputName + "}, implementing the interface");
+ output.println(" * {@link " + baseInterfaceClass.getName() + "}");
+ output.println(" * <p>");
+ output.println(" * Each method follows the call graph <ul>");
+ if (null != prologClassOpt) {
+ output.println(" * <li> call <em>prolog</em> {@link " + prologClassOpt.getName() + "} if available");
+ }
+ output.println(" * <li> call <em>downstream</em> {@link " + downstreamClass.getName() + "} if available");
+ if (null != prologClassOpt && 0 != (GEN_PROLOG_XOR_DOWNSTREAM & getMode())) {
+ output.println(" * <strong>and</strong> if no call to {@link " + prologClassOpt.getName() + "} is made");
+ }
+ output.println(" * </ul><p>");
+ output.println(" * ");
+ output.println(" * <ul>");
+ output.println(" * <li> <em>Interface</em> {@link " + baseInterfaceClass.getName() + "}");
+ if (null != prologClassOpt) {
+ output.println(" * <li> <em>Prolog</em> {@link " + prologClassOpt.getName() + "}");
+ }
+ output.println(" * <li> <em>Downstream</em> {@link " + downstreamClass.getName() + "}");
+ output.println(" * </ul><p>");
+ output.println(" * Sample code which installs this pipeline: </P>");
+ output.println(" * ");
+ output.println("<PRE>");
+ if (null != prologNameOpt) {
+ output.println(" GL gl = drawable.setGL( new " + className + "( drawable.getGL().getGL2ES2(), new " + prologNameOpt + "( drawable.getGL().getGL2ES2() ) ) );");
+ } else {
+ output.println(" GL gl = drawable.setGL( new " + className + "( drawable.getGL().getGL2ES2() ) );");
+ }
+ output.println("</PRE>");
+ output.println("*/");
+ }
- protected void postDownstreamCallHook(PrintWriter output, Method m)
- {
- if (m.getName().equals("glBegin"))
- {
- output.println(" insideBeginEndPair = true;");
- output.println(" // NOTE: can't check glGetError(); it's not allowed inside glBegin/glEnd pair");
- }
- else
- {
- if (m.getName().equals("glEnd"))
- {
- output.println(" insideBeginEndPair = false;");
- }
-
- output.println(" String txt = new String(\""+ m.getName() + "(\" +");
- Class[] params = m.getParameterTypes() ;
- for(int i=0; params!=null && i<params.length; i++) {
- if(params[i].equals(int.class)) {
- output.println(" \"<"+params[i].getName()+"> 0x\"+Integer.toHexString(arg"+i+").toUpperCase() +");
- } else {
- output.println(" \"<"+params[i].getName()+">\" +");
- }
- if(i<params.length-1) {
- output.println(" \", \" +");
- }
- }
- output.println(" \")\");");
- // calls to glGetError() are only allowed outside of glBegin/glEnd pairs
- output.println(" checkGLGetError( txt );");
- }
- }
+ protected boolean hasPreDownstreamCallHook(Method m) {
+ return null != getMethod(prologClassOpt, m);
+ }
- } // end class DebugPipeline
+ protected void preDownstreamCallHook(PrintWriter output, Method m) {
+ if (null != prologNameOpt) {
+ output.print(getPrologObjectNameOpt());
+ output.print('.');
+ output.print(m.getName());
+ output.print('(');
+ output.print(getArgListAsString(m, false, true));
+ output.println(");");
+ }
+ }
- //-------------------------------------------------------
+ protected boolean hasPostDownstreamCallHook(Method m) {
+ return false;
+ }
- protected class TracePipeline extends PipelineEmitter
- {
- String className;
- public TracePipeline(String outputDir, String outputPackage, Class baseInterfaceClass, Class downstreamClass)
- {
- super(outputDir, outputPackage, baseInterfaceClass, null, downstreamClass);
- className = "Trace" + getBaseInterfaceName();
- }
+ protected void postDownstreamCallHook(PrintWriter output, Method m) {
+ }
+ } // end class CustomPipeline
- protected String getOutputName()
- {
- return className;
- }
+ protected class DebugPipeline extends PipelineEmitter {
- protected int getMode() { return 0; }
+ String className;
- protected boolean emptyMethodAllowed() {
- return false;
- }
- protected boolean emptyDownstreamAllowed() {
- return false;
- }
+ DebugPipeline(String outputDir, String outputPackage, Class<?> baseInterfaceClass, Class<?> downstreamClass) {
+ super(outputDir, outputPackage, baseInterfaceClass, null, downstreamClass);
+ className = "Debug" + getBaseInterfaceName();
+ }
- protected void preMethodEmissionHook(PrintWriter output)
- {
- super.preMethodEmissionHook(output);
- }
+ protected String getOutputName() {
+ return className;
+ }
- protected void constructorHook(PrintWriter output) {
- output.print( " public " + getOutputName() + "(" );
- output.println( downstreamName + " " + getDownstreamObjectName() + ", PrintStream " + getOutputStreamName() + ")");
- output.println(" {");
- output.println(" if (" + getDownstreamObjectName() + " == null) {");
- output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
- output.println(" }");
- output.print( " this." + getDownstreamObjectName());
- output.println(" = " + getDownstreamObjectName() + ";");
- output.print( " this." + getOutputStreamName());
- output.println(" = " + getOutputStreamName() + ";");
- output.println(" }");
- output.println();
- }
+ protected int getMode() {
+ return 0;
+ }
- protected void postMethodEmissionHook(PrintWriter output)
- {
- super.postMethodEmissionHook(output);
- output.println("private PrintStream " + getOutputStreamName() + ";");
- output.println("private int indent = 0;");
- output.println("protected String dumpArray(Object obj)");
- output.println("{");
- output.println(" if (obj == null) return \"[null]\";");
- output.println(" StringBuffer sb = new StringBuffer(\"[\");");
- output.println(" int len = java.lang.reflect.Array.getLength(obj);");
- output.println(" int count = Math.min(len,16);");
- output.println(" for ( int i =0; i < count; i++ ) {");
- output.println(" sb.append(java.lang.reflect.Array.get(obj,i));");
- output.println(" if (i < count-1)");
- output.println(" sb.append(',');");
- output.println(" }");
- output.println(" if ( len > 16 )");
- output.println(" sb.append(\"...\").append(len);");
- output.println(" sb.append(']');");
- output.println(" return sb.toString();");
- output.println("}");
- output.println("protected void print(String str)");
- output.println("{");
- output.println(" "+getOutputStreamName()+".print(str);");
- output.println("}");
- output.println("protected void println(String str)");
- output.println("{");
- output.println(" "+getOutputStreamName()+".println(str);");
- output.println("}");
- output.println("protected void printIndent()");
- output.println("{");
- output.println(" for( int i =0; i < indent; i++) {"+getOutputStreamName()+".print(' ');}");
- output.println("}");
- }
- protected void emitClassDocComment(PrintWriter output)
- {
- output.println("/** <P> Composable pipeline which wraps an underlying {@link GL} implementation,");
- output.println(" providing tracing information to a user-specified {@link java.io.PrintStream}");
- output.println(" before and after each OpenGL method call. Sample code which installs this pipeline: </P>");
- output.println();
- output.println("<PRE>");
- output.println(" GL gl = drawable.setGL(new TraceGL(drawable.getGL(), System.err));");
- output.println("</PRE>");
- output.println("*/");
- }
-
- protected boolean hasPreDownstreamCallHook(Method m) {
- return true;
- }
+ protected boolean emptyMethodAllowed() {
+ return false;
+ }
- protected void preDownstreamCallHook(PrintWriter output, Method m)
- {
- if ( m.getName().equals("glEnd") || m.getName().equals("glEndList"))
- {
- output.println("indent-=2;");
- output.println(" printIndent();");
- }
- else
- {
- output.println("printIndent();");
- }
-
- output.print(" print(");
- printFunctionCallString(output, m);
- output.println(");");
- }
+ protected boolean emptyDownstreamAllowed() {
+ return false;
+ }
- protected boolean hasPostDownstreamCallHook(Method m) {
- return true;
- }
+ @Override
+ protected void preMethodEmissionHook(PrintWriter output) {
+ super.preMethodEmissionHook(output);
+ }
- protected void postDownstreamCallHook(PrintWriter output, Method m)
- {
- Class ret = m.getReturnType();
- if ( ret != Void.TYPE )
- {
- output.println(" println(\" = \"+_res);");
- }
- else
- {
- output.println(" println(\"\");");
- }
- }
+ protected void constructorHook(PrintWriter output) {
+ output.print(" public " + getOutputName() + "(");
+ output.println(downstreamName + " " + getDownstreamObjectName() + ")");
+ output.println(" {");
+ output.println(" if (" + getDownstreamObjectName() + " == null) {");
+ output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
+ output.println(" }");
+ output.print(" this." + getDownstreamObjectName());
+ output.println(" = " + getDownstreamObjectName() + ";");
+ if (null != prologNameOpt) {
+ output.print(" this." + getPrologObjectNameOpt());
+ output.println(" = " + getPrologObjectNameOpt() + ";");
+ }
+ output.println(" // Fetch GLContext object for better error checking (if possible)");
+ output.println(" _context = " + getDownstreamObjectName() + ".getContext();");
+ output.println(" }");
+ output.println();
+ }
- private String getOutputStreamName() {
- return "stream";
- }
+ @Override
+ protected void postMethodEmissionHook(PrintWriter output) {
+ super.postMethodEmissionHook(output);
+ output.println(" private void checkGLGetError(String caller)");
+ output.println(" {");
+ if (hasImmediateMode) {
+ output.println(" if (insideBeginEndPair) {");
+ output.println(" return;");
+ output.println(" }");
+ output.println();
+ }
+ output.println(" // Debug code to make sure the pipeline is working; leave commented out unless testing this class");
+ output.println(" //System.err.println(\"Checking for GL errors "
+ + "after call to \" + caller);");
+ output.println();
+ output.println(" int err = "
+ + getDownstreamObjectName()
+ + ".glGetError();");
+ output.println(" if (err == GL_NO_ERROR) { return; }");
+ output.println();
+ output.println(" StringBuffer buf = new StringBuffer(Thread.currentThread()+");
+ output.println(" \" glGetError() returned the following error codes after a call to \" + caller + \": \");");
+ output.println();
+ output.println(" // Loop repeatedly to allow for distributed GL implementations,");
+ output.println(" // as detailed in the glGetError() specification");
+ output.println(" int recursionDepth = 10;");
+ output.println(" do {");
+ output.println(" switch (err) {");
+ output.println(" case GL_INVALID_ENUM: buf.append(\"GL_INVALID_ENUM \"); break;");
+ output.println(" case GL_INVALID_VALUE: buf.append(\"GL_INVALID_VALUE \"); break;");
+ output.println(" case GL_INVALID_OPERATION: buf.append(\"GL_INVALID_OPERATION \"); break;");
+ if (hasStackOverflow) {
+ output.println(" case GL_STACK_OVERFLOW: buf.append(\"GL_STACK_OVERFLOW \"); break;");
+ output.println(" case GL_STACK_UNDERFLOW: buf.append(\"GL_STACK_UNDERFLOW \"); break;");
+ }
+ output.println(" case GL_OUT_OF_MEMORY: buf.append(\"GL_OUT_OF_MEMORY \"); break;");
+ output.println(" case GL_NO_ERROR: throw new InternalError(\"Should not be treating GL_NO_ERROR as error\");");
+ output.println(" default: buf.append(\"Unknown glGetError() return value: \");");
+ output.println(" }");
+ output.println(" buf.append(\"( \" + err + \" 0x\"+Integer.toHexString(err).toUpperCase() + \"), \");");
+ output.println(" } while ((--recursionDepth >= 0) && (err = "
+ + getDownstreamObjectName()
+ + ".glGetError()) != GL_NO_ERROR);");
+ output.println(" throw new GLException(buf.toString());");
+ output.println(" }");
+ if (hasImmediateMode) {
+ output.println(" /** True if the pipeline is inside a glBegin/glEnd pair.*/");
+ output.println(" private boolean insideBeginEndPair = false;");
+ output.println();
+ }
+ output.println(" private void checkContext() {");
+ output.println(" GLContext currentContext = GLContext.getCurrent();");
+ output.println(" if (currentContext == null) {");
+ output.println(" throw new GLException(\"No OpenGL context is current on this thread\");");
+ output.println(" }");
+ output.println(" if ((_context != null) && (_context != currentContext)) {");
+ output.println(" throw new GLException(\"This GL object is being incorrectly used with a different GLContext than that which created it\");");
+ output.println(" }");
+ output.println(" }");
+ output.println(" private GLContext _context;");
+ }
- } // end class TracePipeline
-
- public static final void printFunctionCallString(PrintWriter output, Method m) {
- Class[] params = m.getParameterTypes();
- output.print(" \"" + m.getName() + "(\"");
- for ( int i =0; i < params.length; i++ )
- {
- if ( params[i].isArray() ) {
- output.print("+\"<"+params[i].getName()+">\"");
- } 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);
+ protected void emitClassDocComment(PrintWriter output) {
+ output.println("/** <P> Composable pipeline which wraps an underlying {@link GL} implementation,");
+ output.println(" providing error checking after each OpenGL method call. If an error occurs,");
+ output.println(" causes a {@link GLException} to be thrown at exactly the point of failure.");
+ output.println(" Sample code which installs this pipeline: </P>");
+ output.println();
+ output.println("<PRE>");
+ output.println(" GL gl = drawable.setGL(new DebugGL(drawable.getGL()));");
+ output.println("</PRE>");
+ output.println("*/");
+ }
+
+ protected boolean hasPreDownstreamCallHook(Method m) {
+ return true;
+ }
+
+ protected void preDownstreamCallHook(PrintWriter output, Method m) {
+ output.println(" checkContext();");
+ }
+
+ protected boolean hasPostDownstreamCallHook(Method m) {
+ return true;
+ }
+
+ protected void postDownstreamCallHook(PrintWriter output, Method m) {
+ if (m.getName().equals("glBegin")) {
+ output.println(" insideBeginEndPair = true;");
+ output.println(" // NOTE: can't check glGetError(); it's not allowed inside glBegin/glEnd pair");
+ } else {
+ if (m.getName().equals("glEnd")) {
+ output.println(" insideBeginEndPair = false;");
+ }
+
+ output.println(" String txt = new String(\"" + m.getName() + "(\" +");
+ Class<?>[] params = m.getParameterTypes();
+ for (int i = 0; params != null && i < params.length; i++) {
+ if (params[i].equals(int.class)) {
+ output.println(" \"<" + params[i].getName() + "> 0x\"+Integer.toHexString(arg" + i + ").toUpperCase() +");
+ } else {
+ output.println(" \"<" + params[i].getName() + ">\" +");
+ }
+ if (i < params.length - 1) {
+ output.println(" \", \" +");
+ }
+ }
+ output.println(" \")\");");
+ // calls to glGetError() are only allowed outside of glBegin/glEnd pairs
+ output.println(" checkGLGetError( txt );");
+ }
+ }
+ } // end class DebugPipeline
+
+ //-------------------------------------------------------
+ protected class TracePipeline extends PipelineEmitter {
+
+ String className;
+
+ TracePipeline(String outputDir, String outputPackage, Class<?> baseInterfaceClass, Class<?> downstreamClass) {
+ super(outputDir, outputPackage, baseInterfaceClass, null, downstreamClass);
+ className = "Trace" + getBaseInterfaceName();
+ }
+
+ protected String getOutputName() {
+ return className;
+ }
+
+ protected int getMode() {
+ return 0;
}
- if ( i < params.length-1) {
- output.print("+\", \"");
+
+ protected boolean emptyMethodAllowed() {
+ return false;
}
- }
- output.print("+\")\"");
- }
+
+ protected boolean emptyDownstreamAllowed() {
+ return false;
+ }
+
+ @Override
+ protected void preMethodEmissionHook(PrintWriter output) {
+ super.preMethodEmissionHook(output);
+ }
+
+ protected void constructorHook(PrintWriter output) {
+ output.print(" public " + getOutputName() + "(");
+ output.println(downstreamName + " " + getDownstreamObjectName() + ", PrintStream " + getOutputStreamName() + ")");
+ output.println(" {");
+ output.println(" if (" + getDownstreamObjectName() + " == null) {");
+ output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
+ output.println(" }");
+ output.print(" this." + getDownstreamObjectName());
+ output.println(" = " + getDownstreamObjectName() + ";");
+ output.print(" this." + getOutputStreamName());
+ output.println(" = " + getOutputStreamName() + ";");
+ output.println(" }");
+ output.println();
+ }
+
+ @Override
+ protected void postMethodEmissionHook(PrintWriter output) {
+ super.postMethodEmissionHook(output);
+ output.println("private PrintStream " + getOutputStreamName() + ";");
+ output.println("private int indent = 0;");
+ output.println("protected String dumpArray(Object obj)");
+ output.println("{");
+ output.println(" if (obj == null) return \"[null]\";");
+ output.println(" StringBuffer sb = new StringBuffer(\"[\");");
+ output.println(" int len = java.lang.reflect.Array.getLength(obj);");
+ output.println(" int count = Math.min(len,16);");
+ output.println(" for ( int i =0; i < count; i++ ) {");
+ output.println(" sb.append(java.lang.reflect.Array.get(obj,i));");
+ output.println(" if (i < count-1)");
+ output.println(" sb.append(',');");
+ output.println(" }");
+ output.println(" if ( len > 16 )");
+ output.println(" sb.append(\"...\").append(len);");
+ output.println(" sb.append(']');");
+ output.println(" return sb.toString();");
+ output.println("}");
+ output.println("protected void print(String str)");
+ output.println("{");
+ output.println(" " + getOutputStreamName() + ".print(str);");
+ output.println("}");
+ output.println("protected void println(String str)");
+ output.println("{");
+ output.println(" " + getOutputStreamName() + ".println(str);");
+ output.println("}");
+ output.println("protected void printIndent()");
+ output.println("{");
+ output.println(" for( int i =0; i < indent; i++) {" + getOutputStreamName() + ".print(' ');}");
+ output.println("}");
+ }
+
+ protected void emitClassDocComment(PrintWriter output) {
+ output.println("/** <P> Composable pipeline which wraps an underlying {@link GL} implementation,");
+ output.println(" providing tracing information to a user-specified {@link java.io.PrintStream}");
+ output.println(" before and after each OpenGL method call. Sample code which installs this pipeline: </P>");
+ output.println();
+ output.println("<PRE>");
+ output.println(" GL gl = drawable.setGL(new TraceGL(drawable.getGL(), System.err));");
+ output.println("</PRE>");
+ output.println("*/");
+ }
+
+ protected boolean hasPreDownstreamCallHook(Method m) {
+ return true;
+ }
+
+ protected void preDownstreamCallHook(PrintWriter output, Method m) {
+ if (m.getName().equals("glEnd") || m.getName().equals("glEndList")) {
+ output.println("indent-=2;");
+ output.println(" printIndent();");
+ } else {
+ output.println("printIndent();");
+ }
+
+ output.print(" print(");
+ printFunctionCallString(output, m);
+ output.println(");");
+ }
+
+ protected boolean hasPostDownstreamCallHook(Method m) {
+ return true;
+ }
+
+ protected void postDownstreamCallHook(PrintWriter output, Method m) {
+ Class<?> ret = m.getReturnType();
+ if (ret != Void.TYPE) {
+ output.println(" println(\" = \"+_res);");
+ } else {
+ output.println(" println(\"\");");
+ }
+ }
+
+ private String getOutputStreamName() {
+ return "stream";
+ }
+ } // end class TracePipeline
+
+ public static final void printFunctionCallString(PrintWriter output, Method m) {
+ Class<?>[] params = m.getParameterTypes();
+ output.print(" \"" + m.getName() + "(\"");
+ for (int i = 0; i < params.length; i++) {
+ if (params[i].isArray()) {
+ output.print("+\"<" + params[i].getName() + ">\"");
+ } 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);
+ }
+ if (i < params.length - 1) {
+ 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 f7a7fe0..2be5519 100644
--- a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java
+++ b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java
@@ -88,8 +88,8 @@ import java.util.regex.*;
* with the symbol
* <code> GL_ARB_texture_compression </code>.
* */
-public class BuildStaticGLInfo
-{
+public class BuildStaticGLInfo {
+
// Handles function pointer
protected static int funcIdentifierGroup = 10;
protected static Pattern funcPattern =
@@ -110,242 +110,237 @@ public class BuildStaticGLInfo
protected Map<String, Set<String>> extensionToDeclarationMap = new HashMap<String, Set<String>>();
protected boolean debug = false;
- /**
- * The first argument is the package to which the StaticGLInfo class
- * belongs, the second is the path to the directory in which that package's
- * classes reside, and the remaining arguments are paths to the C header
- * files that should be parsed
- */
- public static void main(String[] args) throws IOException
- {
- 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);
- builder.dump();
- System.exit(0);
- }
+ /**
+ * The first argument is the package to which the StaticGLInfo class
+ * belongs, the second is the path to the directory in which that package's
+ * classes reside, and the remaining arguments are paths to the C header
+ * files that should be parsed
+ */
+ public static void main(String[] args) throws IOException {
+ 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);
+ builder.dump();
+ System.exit(0);
+ }
- String packageName = args[0];
- String packageDir = args[1];
+ String packageName = args[0];
+ String packageDir = args[1];
- String[] cHeaderFilePaths = new String[args.length-2];
- System.arraycopy(args, 2, cHeaderFilePaths, 0, cHeaderFilePaths.length);
-
- BuildStaticGLInfo builder = new BuildStaticGLInfo();
- try {
- builder.parse(cHeaderFilePaths);
+ String[] cHeaderFilePaths = new String[args.length - 2];
+ System.arraycopy(args, 2, cHeaderFilePaths, 0, cHeaderFilePaths.length);
- File file = new File(packageDir + File.separatorChar + "StaticGLInfo.java");
- String parentDir = file.getParent();
- if (parentDir != null) {
- File pDirFile = new File(parentDir);
- pDirFile.mkdirs();
- }
+ BuildStaticGLInfo builder = new BuildStaticGLInfo();
+ try {
+ builder.parse(cHeaderFilePaths);
- PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
- builder.emitJavaCode(writer, packageName);
+ File file = new File(packageDir + File.separatorChar + "StaticGLInfo.java");
+ String parentDir = file.getParent();
+ if (parentDir != null) {
+ File pDirFile = new File(parentDir);
+ pDirFile.mkdirs();
+ }
- writer.flush();
- writer.close();
- }
- catch (Exception e)
- {
- StringBuffer buf = new StringBuffer("{ ");
- for (int i = 0; i < cHeaderFilePaths.length; ++i)
- {
- buf.append(cHeaderFilePaths[i]);
- buf.append(" ");
- }
- buf.append('}');
- throw new RuntimeException(
- "Error building StaticGLInfo.java from " + buf.toString(), e);
+ PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+ builder.emitJavaCode(writer, packageName);
+
+ writer.flush();
+ writer.close();
+ } catch (Exception e) {
+ StringBuilder buf = new StringBuilder("{ ");
+ for (int i = 0; i < cHeaderFilePaths.length; ++i) {
+ buf.append(cHeaderFilePaths[i]);
+ buf.append(" ");
+ }
+ buf.append('}');
+ throw new RuntimeException(
+ "Error building StaticGLInfo.java from " + buf.toString(), e);
+ }
}
- }
- public void setDebug(boolean v) {
- debug = v;
- }
-
- /** Parses the supplied C header files and adds the function
- associations contained therein to the internal map. */
- public void parse(String[] cHeaderFilePaths) throws IOException {
- for (int i = 0; i < cHeaderFilePaths.length; i++) {
- parse(cHeaderFilePaths[i]);
+ public void setDebug(boolean v) {
+ debug = v;
}
- }
- /** Parses the supplied C header file and adds the function
- associations contained therein to the internal map. */
- public void parse(String cHeaderFilePath) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(cHeaderFilePath));
- 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(funcIdentifierGroup).trim();
- type =2;
- } else if ((m = definePattern.matcher(line)).matches()) {
- identifier = m.group(defineIdentifierGroup).trim();
- type =1;
- } else if (line.startsWith("#endif")) {
- if(debug) {
- System.err.println("END ASSOCIATION BLOCK: <" + activeAssociation + ">");
- }
- activeAssociation = null;
+ /** Parses the supplied C header files and adds the function
+ associations contained therein to the internal map. */
+ public void parse(String[] cHeaderFilePaths) throws IOException {
+ for (int i = 0; i < cHeaderFilePaths.length; i++) {
+ parse(cHeaderFilePaths[i]);
}
- if ((identifier != null) &&
- (activeAssociation != null) &&
- // Handles #ifndef GL_... #define GL_...
- !identifier.equals(activeAssociation)) {
- addAssociation(identifier, activeAssociation);
- if(debug) {
- System.err.println(" ADDING ASSOCIATION: <" + identifier + "> <" + activeAssociation + "> ; type "+type);
- }
+ }
+
+ /** Parses the supplied C header file and adds the function
+ associations contained therein to the internal map. */
+ public void parse(String cHeaderFilePath) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(cHeaderFilePath));
+ 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(funcIdentifierGroup).trim();
+ type = 2;
+ } else if ((m = definePattern.matcher(line)).matches()) {
+ 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)
+ && (activeAssociation != null)
+ && // Handles #ifndef GL_... #define GL_...
+ !identifier.equals(activeAssociation)) {
+ addAssociation(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).trim();
+
+ if (debug) {
+ System.err.println("BEGIN ASSOCIATION BLOCK: <" + activeAssociation + ">");
+ }
+ }
}
- } else if ((m = associationPattern.matcher(line)).matches()) {
- // found a new #ifndef GL_XXX block
- activeAssociation = m.group(1).trim();
-
- if(debug) {
- System.err.println("BEGIN ASSOCIATION BLOCK: <" + activeAssociation + ">");
+ reader.close();
+ }
+
+ public void dump() {
+ for (String name : extensionToDeclarationMap.keySet()) {
+ Set<String> decls = extensionToDeclarationMap.get(name);
+ System.out.println("<" + name + "> :");
+ List<String> l = new ArrayList<String>();
+ l.addAll(decls);
+ Collections.sort(l);
+ for (String str : l) {
+ System.out.println(" <" + str + ">");
+ }
}
- }
}
- reader.close();
- }
- public void dump() {
- for (String name : extensionToDeclarationMap.keySet()) {
- Set<String> decls = extensionToDeclarationMap.get(name);
- System.out.println("<"+name+"> :");
- List<String> l = new ArrayList<String>();
- l.addAll(decls);
- Collections.sort(l);
- for (String str : l) {
- System.out.println(" <" + str + ">");
- }
+ public String getExtension(String identifier) {
+ return declarationToExtensionMap.get(identifier);
}
- }
- public String getExtension(String identifier) {
- return declarationToExtensionMap.get(identifier);
- }
-
- public Set<String> getDeclarations(String extension) {
- return extensionToDeclarationMap.get(extension);
- }
+ public Set<String> getDeclarations(String extension) {
+ return extensionToDeclarationMap.get(extension);
+ }
- public Set<String> getExtensions() {
- return extensionToDeclarationMap.keySet();
- }
+ public Set<String> getExtensions() {
+ return extensionToDeclarationMap.keySet();
+ }
- public void emitJavaCode(PrintWriter output, String packageName) {
- output.println("package " + packageName + ";");
- output.println();
- output.println("import java.util.*;");
- output.println();
- output.println("public final class StaticGLInfo");
- output.println("{");
+ public void emitJavaCode(PrintWriter output, String packageName) {
+ output.println("package " + packageName + ";");
+ output.println();
+ output.println("import java.util.*;");
+ output.println();
+ output.println("public final class StaticGLInfo");
+ output.println("{");
- output.println(" // maps function names to the extension string or OpenGL");
- output.println(" // specification version string to which they correspond.");
- output.println(" private static HashMap funcToAssocMap;");
- output.println();
+ output.println(" // maps function names to the extension string or OpenGL");
+ output.println(" // specification version string to which they correspond.");
+ output.println(" private static HashMap funcToAssocMap;");
+ output.println();
- output.println(" /**");
- output.println(" * Returns the OpenGL extension string or GL_VERSION string with which the");
- output.println(" * given function is associated. <P>");
- output.println(" *");
- output.println(" * If the");
- output.println(" * function is part of the OpenGL core, the returned value will be");
- output.println(" * GL_VERSION_XXX where XXX represents the OpenGL version of which the");
- output.println(" * function is a member (XXX will be of the form \"A\" or \"A_B\" or \"A_B_C\";");
- output.println(" * e.g., GL_VERSION_1_2_1 for OpenGL version 1.2.1).");
- output.println(" *");
- output.println(" * If the function is an extension function, the returned value will the");
- output.println(" * OpenGL extension string for the extension to which the function");
- output.println(" * corresponds. For example, if glLoadTransposeMatrixfARB is the argument,");
- output.println(" * GL_ARB_transpose_matrix will be the value returned.");
- output.println(" * Please see http://oss.sgi.com/projects/ogl-sample/registry/index.html for");
- output.println(" * a list of extension names and the functions they expose.");
- output.println(" *");
- output.println(" * If the function specified is not part of any known OpenGL core version or");
- output.println(" * extension, then NULL will be returned.");
- output.println(" */");
- output.println(" public static String getFunctionAssociation(String glFunctionName)");
- output.println(" {");
- output.println(" String mappedName = null;");
- output.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutationNumber(glFunctionName);");
- output.println(" for(int i = 0; null==mappedName && i < funcNamePermNum; i++) {");
- output.println(" String tmp = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutation(glFunctionName, i);");
- output.println(" try {");
- output.println(" mappedName = (String)funcToAssocMap.get(tmp);");
- output.println(" } catch (Exception e) { }");
- output.println(" }");
- output.println(" return mappedName;");
- output.println(" }");
- output.println();
+ output.println(" /**");
+ output.println(" * Returns the OpenGL extension string or GL_VERSION string with which the");
+ output.println(" * given function is associated. <P>");
+ output.println(" *");
+ output.println(" * If the");
+ output.println(" * function is part of the OpenGL core, the returned value will be");
+ output.println(" * GL_VERSION_XXX where XXX represents the OpenGL version of which the");
+ output.println(" * function is a member (XXX will be of the form \"A\" or \"A_B\" or \"A_B_C\";");
+ output.println(" * e.g., GL_VERSION_1_2_1 for OpenGL version 1.2.1).");
+ output.println(" *");
+ output.println(" * If the function is an extension function, the returned value will the");
+ output.println(" * OpenGL extension string for the extension to which the function");
+ output.println(" * corresponds. For example, if glLoadTransposeMatrixfARB is the argument,");
+ output.println(" * GL_ARB_transpose_matrix will be the value returned.");
+ output.println(" * Please see http://oss.sgi.com/projects/ogl-sample/registry/index.html for");
+ output.println(" * a list of extension names and the functions they expose.");
+ output.println(" *");
+ output.println(" * If the function specified is not part of any known OpenGL core version or");
+ output.println(" * extension, then NULL will be returned.");
+ output.println(" */");
+ output.println(" public static String getFunctionAssociation(String glFunctionName)");
+ output.println(" {");
+ output.println(" String mappedName = null;");
+ output.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutationNumber(glFunctionName);");
+ output.println(" for(int i = 0; null==mappedName && i < funcNamePermNum; i++) {");
+ output.println(" String tmp = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutation(glFunctionName, i);");
+ output.println(" try {");
+ output.println(" mappedName = (String)funcToAssocMap.get(tmp);");
+ output.println(" } catch (Exception e) { }");
+ output.println(" }");
+ output.println(" return mappedName;");
+ output.println(" }");
+ output.println();
- output.println(" static");
- output.println(" {");
+ output.println(" static");
+ output.println(" {");
- // Compute max capacity
- int maxCapacity = 0;
- for (String name : declarationToExtensionMap.keySet()) {
- if (!name.startsWith("GL")) {
- ++maxCapacity;
- }
- }
+ // Compute max capacity
+ int maxCapacity = 0;
+ for (String name : declarationToExtensionMap.keySet()) {
+ if (!name.startsWith("GL")) {
+ ++maxCapacity;
+ }
+ }
- output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity");
- output.println(" String group;");
- ArrayList<String> sets = new ArrayList<String>(extensionToDeclarationMap.keySet());
- Collections.sort(sets);
- for (String groupName : sets) {
- Set<String> funcs = extensionToDeclarationMap.get(groupName);
- List<String> l = new ArrayList<String>();
- l.addAll(funcs);
- Collections.sort(l);
- Iterator<String> funcIter = l.iterator();
- boolean printedHeader = false;
- while (funcIter.hasNext()) {
- String funcName = funcIter.next();
- if (!funcName.startsWith("GL")) {
- if (!printedHeader) {
- output.println();
- output.println(" //----------------------------------------------------------------");
- output.println(" // " + groupName);
- output.println(" //----------------------------------------------------------------");
- output.println(" group = \"" + groupName + "\";");
- printedHeader = true;
- }
+ output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity");
+ output.println(" String group;");
+ ArrayList<String> sets = new ArrayList<String>(extensionToDeclarationMap.keySet());
+ Collections.sort(sets);
+ for (String groupName : sets) {
+ Set<String> funcs = extensionToDeclarationMap.get(groupName);
+ List<String> l = new ArrayList<String>();
+ l.addAll(funcs);
+ Collections.sort(l);
+ Iterator<String> funcIter = l.iterator();
+ boolean printedHeader = false;
+ while (funcIter.hasNext()) {
+ String funcName = funcIter.next();
+ if (!funcName.startsWith("GL")) {
+ if (!printedHeader) {
+ output.println();
+ output.println(" //----------------------------------------------------------------");
+ output.println(" // " + groupName);
+ output.println(" //----------------------------------------------------------------");
+ output.println(" group = \"" + groupName + "\";");
+ printedHeader = true;
+ }
- output.println(" funcToAssocMap.put(\"" + funcName + "\", group);");
+ output.println(" funcToAssocMap.put(\"" + funcName + "\", group);");
+ }
+ }
}
- }
+ output.println(" }");
+ output.println("} // end class StaticGLInfo");
}
- output.println(" }");
- output.println("} // end class StaticGLInfo");
- }
- //----------------------------------------------------------------------
- // Internals only below this point
- //
-
- protected void addAssociation(String identifier, String association) {
- declarationToExtensionMap.put(identifier, association);
- Set<String> identifiers = extensionToDeclarationMap.get(association);
- if (identifiers == null) {
- identifiers = new HashSet<String>();
- extensionToDeclarationMap.put(association, identifiers);
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+ protected void addAssociation(String identifier, String association) {
+ declarationToExtensionMap.put(identifier, association);
+ Set<String> identifiers = extensionToDeclarationMap.get(association);
+ if (identifiers == null) {
+ identifiers = new HashSet<String>();
+ extensionToDeclarationMap.put(association, identifiers);
+ }
+ identifiers.add(identifier);
}
- identifiers.add(identifier);
- }
}
diff --git a/src/java/com/sun/gluegen/opengl/GLConfiguration.java b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
index 6d08a10..d712e90 100755
--- a/src/java/com/sun/gluegen/opengl/GLConfiguration.java
+++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
@@ -36,7 +36,6 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.opengl;
import java.io.*;
@@ -47,30 +46,33 @@ import com.sun.gluegen.procaddress.*;
import com.jogamp.gluegen.runtime.opengl.GLExtensionNames;
public class GLConfiguration extends ProcAddressConfiguration {
- // The following data members support ignoring an entire extension at a time
- private List<String> glHeaders = new ArrayList<String>();
- private Set<String> ignoredExtensions = new HashSet<String>();
- private Set<String> extensionsRenamedIntoCore = new HashSet<String>();
- private BuildStaticGLInfo glInfo;
- // Maps function names to the kind of buffer object it deals with
- private Map<String,GLEmitter.BufferObjectKind> bufferObjectKinds = new HashMap<String,GLEmitter.BufferObjectKind>();
- private GLEmitter emitter;
- private Set<String> dropUniqVendorExtensions = new HashSet<String>();
- // 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=false;
- private boolean allowNonGLExtensions=false;
-
- public GLConfiguration(GLEmitter emitter) {
- super();
- this.emitter = emitter;
- try {
- setProcAddressNameExpr("PFN $UPPERCASE({0}) PROC");
- } catch (NoSuchElementException e) {
- throw new RuntimeException("Error configuring ProcAddressNameExpr", e);
+
+ // The following data members support ignoring an entire extension at a time
+ private List<String> glHeaders = new ArrayList<String>();
+ private Set<String> ignoredExtensions = new HashSet<String>();
+ private Set<String> extensionsRenamedIntoCore = new HashSet<String>();
+ private BuildStaticGLInfo glInfo;
+
+ // Maps function names to the kind of buffer object it deals with
+ private Map<String, GLEmitter.BufferObjectKind> bufferObjectKinds = new HashMap<String, GLEmitter.BufferObjectKind>();
+ private GLEmitter emitter;
+ private Set<String> dropUniqVendorExtensions = new HashSet<String>();
+
+ // 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 = false;
+ private boolean allowNonGLExtensions = false;
+
+ public GLConfiguration(GLEmitter emitter) {
+ super();
+ this.emitter = emitter;
+ try {
+ setProcAddressNameExpr("PFN $UPPERCASE({0}) PROC");
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error configuring ProcAddressNameExpr", e);
+ }
}
- }
@Override
protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
@@ -97,199 +99,198 @@ public class GLConfiguration extends ProcAddressConfiguration {
}
}
- protected void readBufferObjectKind(StringTokenizer tok, String filename, int lineNo) {
- try {
- String kindString = tok.nextToken();
- GLEmitter.BufferObjectKind kind = null;
- String target = tok.nextToken();
- if (kindString.equalsIgnoreCase("UnpackPixel")) {
- kind = GLEmitter.BufferObjectKind.UNPACK_PIXEL;
- } else if (kindString.equalsIgnoreCase("PackPixel")) {
- kind = GLEmitter.BufferObjectKind.PACK_PIXEL;
- } else if (kindString.equalsIgnoreCase("Array")) {
- kind = GLEmitter.BufferObjectKind.ARRAY;
- } else if (kindString.equalsIgnoreCase("Element")) {
- kind = GLEmitter.BufferObjectKind.ELEMENT;
- } else {
- throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo +
- " in file \"" + filename + "\": illegal BufferObjectKind \"" +
- kindString + "\", expected one of UnpackPixel, PackPixel, Array, or Element");
- }
-
- bufferObjectKinds.put(target, kind);
- } catch (NoSuchElementException e) {
- throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo +
- " in file \"" + filename + "\"", e);
- }
- }
-
- /** Overrides javaPrologueForMethod in superclass and
- automatically generates prologue code for functions associated
- with buffer objects. */
- @Override
- public List<String> javaPrologueForMethod(MethodBinding binding, boolean forImplementingMethodCall, boolean eraseBufferAndArrayTypes) {
-
- List<String> res = super.javaPrologueForMethod(binding, forImplementingMethodCall, eraseBufferAndArrayTypes);
- GLEmitter.BufferObjectKind kind = getBufferObjectKind(binding.getName());
- if (kind != null) {
- // Need to generate appropriate prologue based on both buffer
- // object kind and whether this variant of the MethodBinding
- // is the one accepting a "long" as argument
- //
- // NOTE we MUST NOT mutate the array returned from the super
- // call!
- ArrayList<String> res2 = new ArrayList<String>();
- if (res != null) {
- res2.addAll(res);
- }
- res = res2;
-
- String prologue = "check";
-
- if (kind == GLEmitter.BufferObjectKind.UNPACK_PIXEL) {
- prologue = prologue + "UnpackPBO";
- } else if (kind == GLEmitter.BufferObjectKind.PACK_PIXEL) {
- prologue = prologue + "PackPBO";
- } else if (kind == GLEmitter.BufferObjectKind.ARRAY) {
- prologue = prologue + "ArrayVBO";
- } else if (kind == GLEmitter.BufferObjectKind.ELEMENT) {
- prologue = prologue + "ElementVBO";
- } else {
- throw new RuntimeException("Unknown BufferObjectKind " + kind);
- }
-
- if (emitter.isBufferObjectMethodBinding(binding)) {
- prologue = prologue + "Enabled";
- } else {
- prologue = prologue + "Disabled";
- }
-
- prologue = prologue + "(true);";
-
- res.add(0, prologue);
-
- // Must also filter out bogus rangeCheck directives for VBO/PBO
- // variants
- if (emitter.isBufferObjectMethodBinding(binding)) {
- for (Iterator<String> iter = res.iterator(); iter.hasNext(); ) {
- String line = iter.next();
- if (line.indexOf("Buffers.rangeCheck") >= 0) {
- iter.remove();
- }
+ protected void readBufferObjectKind(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String kindString = tok.nextToken();
+ GLEmitter.BufferObjectKind kind = null;
+ String target = tok.nextToken();
+ if (kindString.equalsIgnoreCase("UnpackPixel")) {
+ kind = GLEmitter.BufferObjectKind.UNPACK_PIXEL;
+ } else if (kindString.equalsIgnoreCase("PackPixel")) {
+ kind = GLEmitter.BufferObjectKind.PACK_PIXEL;
+ } else if (kindString.equalsIgnoreCase("Array")) {
+ kind = GLEmitter.BufferObjectKind.ARRAY;
+ } else if (kindString.equalsIgnoreCase("Element")) {
+ kind = GLEmitter.BufferObjectKind.ELEMENT;
+ } else {
+ throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo
+ + " in file \"" + filename + "\": illegal BufferObjectKind \""
+ + kindString + "\", expected one of UnpackPixel, PackPixel, Array, or Element");
+ }
+
+ bufferObjectKinds.put(target, kind);
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo
+ + " in file \"" + filename + "\"", e);
}
- }
}
- return res;
- }
+ /** Overrides javaPrologueForMethod in superclass and
+ automatically generates prologue code for functions associated
+ with buffer objects. */
+ @Override
+ public List<String> javaPrologueForMethod(MethodBinding binding, boolean forImplementingMethodCall, boolean eraseBufferAndArrayTypes) {
+
+ List<String> res = super.javaPrologueForMethod(binding, forImplementingMethodCall, eraseBufferAndArrayTypes);
+ GLEmitter.BufferObjectKind kind = getBufferObjectKind(binding.getName());
+ if (kind != null) {
+ // Need to generate appropriate prologue based on both buffer
+ // object kind and whether this variant of the MethodBinding
+ // is the one accepting a "long" as argument
+ //
+ // NOTE we MUST NOT mutate the array returned from the super
+ // call!
+ ArrayList<String> res2 = new ArrayList<String>();
+ if (res != null) {
+ res2.addAll(res);
+ }
+ res = res2;
+
+ String prologue = "check";
+
+ if (kind == GLEmitter.BufferObjectKind.UNPACK_PIXEL) {
+ prologue = prologue + "UnpackPBO";
+ } else if (kind == GLEmitter.BufferObjectKind.PACK_PIXEL) {
+ prologue = prologue + "PackPBO";
+ } else if (kind == GLEmitter.BufferObjectKind.ARRAY) {
+ prologue = prologue + "ArrayVBO";
+ } else if (kind == GLEmitter.BufferObjectKind.ELEMENT) {
+ prologue = prologue + "ElementVBO";
+ } else {
+ throw new RuntimeException("Unknown BufferObjectKind " + kind);
+ }
+
+ if (emitter.isBufferObjectMethodBinding(binding)) {
+ prologue = prologue + "Enabled";
+ } else {
+ prologue = prologue + "Disabled";
+ }
+
+ prologue = prologue + "(true);";
- @Override
- public void dumpIgnores() {
- System.err.println("GL Ignored extensions: ");
- for (String str : ignoredExtensions) {
- System.err.println("\t"+str);
+ res.add(0, prologue);
+
+ // Must also filter out bogus rangeCheck directives for VBO/PBO
+ // variants
+ if (emitter.isBufferObjectMethodBinding(binding)) {
+ for (Iterator<String> iter = res.iterator(); iter.hasNext();) {
+ String line = iter.next();
+ if (line.indexOf("Buffers.rangeCheck") >= 0) {
+ iter.remove();
+ }
+ }
+ }
+ }
+
+ return res;
+ }
+
+ @Override
+ public void dumpIgnores() {
+ System.err.println("GL Ignored extensions: ");
+ for (String str : ignoredExtensions) {
+ System.err.println("\t" + str);
+ }
+ super.dumpIgnores();
}
- super.dumpIgnores();
- }
-
- protected boolean shouldIgnoreExtension(String symbol, boolean criteria) {
- if (criteria && glInfo != null) {
- String extension = glInfo.getExtension(symbol);
- if (extension != null &&
- ignoredExtensions.contains(extension)) {
- return true;
- }
- 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+", vendor "+extSuffix);
+
+ protected boolean shouldIgnoreExtension(String symbol, boolean criteria) {
+ if (criteria && glInfo != null) {
+ String extension = glInfo.getExtension(symbol);
+ if (extension != null
+ && ignoredExtensions.contains(extension)) {
+ return true;
+ }
+ 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 + ", vendor " + extSuffix);
+ }
+ return true;
+ }
+ }
}
- return true;
- }
}
- }
+ return false;
+ }
+
+ @Override
+ public boolean shouldIgnoreInInterface(String symbol) {
+ return shouldIgnoreInInterface(symbol, true);
+ }
+
+ public boolean shouldIgnoreInInterface(String symbol, boolean checkEXT) {
+ return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInInterface(symbol);
+ }
+
+ @Override
+ public boolean shouldIgnoreInImpl(String symbol) {
+ return shouldIgnoreInImpl(symbol, true);
+ }
+
+ public boolean shouldIgnoreInImpl(String symbol, boolean checkEXT) {
+ return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInImpl(symbol);
+ }
+
+ /** Should we automatically ignore extensions that have already been
+ fully subsumed into the OpenGL core namespace, and if they have
+ not been, indicate which definition is not already in the core? */
+ public boolean getAutoUnifyExtensions() {
+ return autoUnifyExtensions;
+ }
+
+ /** If true, accept all non encapsulated defines and functions,
+ * as it is mandatory for GL declarations. */
+ public boolean getAllowNonGLExtensions() {
+ return allowNonGLExtensions;
}
- return false;
- }
-
- @Override
- public boolean shouldIgnoreInInterface(String symbol) {
- return shouldIgnoreInInterface(symbol, true);
- }
-
- public boolean shouldIgnoreInInterface(String symbol, boolean checkEXT) {
- return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInInterface(symbol);
- }
-
- @Override
- public boolean shouldIgnoreInImpl(String symbol) {
- return shouldIgnoreInImpl(symbol, true);
- }
-
- public boolean shouldIgnoreInImpl(String symbol, boolean checkEXT) {
- return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInImpl(symbol);
- }
-
- /** Should we automatically ignore extensions that have already been
- fully subsumed into the OpenGL core namespace, and if they have
- not been, indicate which definition is not already in the core? */
- public boolean getAutoUnifyExtensions() {
- 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);
- }
-
- /** Returns the kind of buffer object this function deals with, or
- null if none. */
- GLEmitter.BufferObjectKind getBufferObjectKind(String name) {
- return bufferObjectKinds.get(name);
- }
-
- public boolean isBufferObjectFunction(String name) {
- return (getBufferObjectKind(name) != null);
- }
-
- /** Parses any GL headers specified in the configuration file for
- the purpose of being able to ignore an extension at a time. */
- public void parseGLHeaders(GlueEmitterControls controls) throws IOException {
- if (!glHeaders.isEmpty()) {
- glInfo = new BuildStaticGLInfo();
- for (String file : glHeaders) {
- String fullPath = controls.findHeaderFile(file);
- if (fullPath == null) {
- throw new IOException("Unable to locate header file \"" + file + "\"");
+
+ /** shall the non unified (uniq) vendor extensions be dropped ? */
+ public boolean getDropUniqVendorExtensions(String extName) {
+ return dropUniqVendorExtensions.contains(extName);
+ }
+
+ /** Returns the kind of buffer object this function deals with, or
+ null if none. */
+ GLEmitter.BufferObjectKind getBufferObjectKind(String name) {
+ return bufferObjectKinds.get(name);
+ }
+
+ public boolean isBufferObjectFunction(String name) {
+ return (getBufferObjectKind(name) != null);
+ }
+
+ /** Parses any GL headers specified in the configuration file for
+ the purpose of being able to ignore an extension at a time. */
+ public void parseGLHeaders(GlueEmitterControls controls) throws IOException {
+ if (!glHeaders.isEmpty()) {
+ glInfo = new BuildStaticGLInfo();
+ for (String file : glHeaders) {
+ String fullPath = controls.findHeaderFile(file);
+ if (fullPath == null) {
+ throw new IOException("Unable to locate header file \"" + file + "\"");
+ }
+ glInfo.parse(fullPath);
+ }
}
- glInfo.parse(fullPath);
- }
}
- }
-
- /** Returns the information about the association between #defines,
- function symbols and the OpenGL extensions they are defined
- in. */
- public BuildStaticGLInfo getGLInfo() {
- return glInfo;
- }
-
- /** Returns the OpenGL extensions that should have all of their
- constant definitions and functions renamed into the core
- namespace; for example, glGenFramebuffersEXT to
- glGenFramebuffers and GL_FRAMEBUFFER_EXT to GL_FRAMEBUFFER. */
- public Set<String> getExtensionsRenamedIntoCore() {
- return extensionsRenamedIntoCore;
- }
+
+ /** Returns the information about the association between #defines,
+ function symbols and the OpenGL extensions they are defined
+ in. */
+ public BuildStaticGLInfo getGLInfo() {
+ return glInfo;
+ }
+
+ /** Returns the OpenGL extensions that should have all of their
+ constant definitions and functions renamed into the core
+ namespace; for example, glGenFramebuffersEXT to
+ glGenFramebuffers and GL_FRAMEBUFFER_EXT to GL_FRAMEBUFFER. */
+ public Set<String> getExtensionsRenamedIntoCore() {
+ return extensionsRenamedIntoCore;
+ }
}
diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java
index e9ae750..006287e 100644
--- a/src/java/com/sun/gluegen/opengl/GLEmitter.java
+++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java
@@ -36,11 +36,9 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.opengl;
import java.io.*;
-import java.text.MessageFormat;
import java.util.*;
import com.sun.gluegen.*;
import com.sun.gluegen.cgram.types.*;
@@ -53,417 +51,405 @@ import com.jogamp.gluegen.runtime.opengl.GLExtensionNames;
*/
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<MethodBinding, MethodBinding> bufferObjectMethodBindings = new IdentityHashMap<MethodBinding, MethodBinding>();
-
- static class BufferObjectKind {
-
- private BufferObjectKind() {}
-
- static final BufferObjectKind UNPACK_PIXEL = new BufferObjectKind();
- static final BufferObjectKind PACK_PIXEL = new BufferObjectKind();
- static final BufferObjectKind ARRAY = new BufferObjectKind();
- static final BufferObjectKind ELEMENT = new BufferObjectKind();
- }
-
- @Override
- public void beginEmission(GlueEmitterControls controls) throws IOException {
- getGLConfig().parseGLHeaders(controls);
- renameExtensionsIntoCore();
- if (getGLConfig().getAutoUnifyExtensions()) {
- unifyExtensions(controls);
- }
- super.beginEmission(controls);
- }
-
- protected void renameExtensionsIntoCore() {
- // This method handles renaming of entire extensions into the
- // OpenGL core namespace. For example, it is used to move certain
- // OpenGL ES (OES) extensions into the core namespace which are
- // already in the core namespace in desktop OpenGL. It builds upon
- // renaming mechanisms that are built elsewhere.
-
- GLConfiguration config = getGLConfig();
- Set<String> extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore();
- BuildStaticGLInfo glInfo = config.getGLInfo();
- if(null==glInfo) {
- if(extensionsRenamedIntoCore.size()>0) {
- throw new RuntimeException("ExtensionRenamedIntoCore (num: "+extensionsRenamedIntoCore.size()+"), but no GLHeader");
+ // Keeps track of which MethodBindings were created for handling
+ // Buffer Object variants. Used as a Set rather than a Map.
+ private Map<MethodBinding, MethodBinding> bufferObjectMethodBindings = new IdentityHashMap<MethodBinding, MethodBinding>();
+
+ enum BufferObjectKind { UNPACK_PIXEL, PACK_PIXEL, ARRAY, ELEMENT}
+
+ @Override
+ public void beginEmission(GlueEmitterControls controls) throws IOException {
+ getGLConfig().parseGLHeaders(controls);
+ renameExtensionsIntoCore();
+ if (getGLConfig().getAutoUnifyExtensions()) {
+ unifyExtensions(controls);
}
- return;
+ super.beginEmission(controls);
}
- for (String extension : extensionsRenamedIntoCore) {
- Set<String> declarations = glInfo.getDeclarations(extension);
- if (declarations != null) {
- for (Iterator i2 = declarations.iterator(); i2.hasNext(); ) {
- String decl = (String) i2.next();
- boolean isGLFunction = GLExtensionNames.isGLFunction(decl);
- boolean isGLEnumeration = false;
- if (!isGLFunction) {
- isGLEnumeration = GLExtensionNames.isGLEnumeration(decl);
- }
- if (isGLFunction || isGLEnumeration) {
- String renamed = GLExtensionNames.normalize(decl, isGLFunction);
- if(!renamed.equals(decl)) {
- config.addJavaSymbolRename(decl, renamed);
+
+ protected void renameExtensionsIntoCore() {
+ // This method handles renaming of entire extensions into the
+ // OpenGL core namespace. For example, it is used to move certain
+ // OpenGL ES (OES) extensions into the core namespace which are
+ // already in the core namespace in desktop OpenGL. It builds upon
+ // renaming mechanisms that are built elsewhere.
+
+ GLConfiguration config = getGLConfig();
+ Set<String> extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore();
+ BuildStaticGLInfo glInfo = config.getGLInfo();
+ if (null == glInfo) {
+ if (extensionsRenamedIntoCore.size() > 0) {
+ throw new RuntimeException("ExtensionRenamedIntoCore (num: " + extensionsRenamedIntoCore.size() + "), but no GLHeader");
+ }
+ return;
+ }
+ for (String extension : extensionsRenamedIntoCore) {
+ Set<String> declarations = glInfo.getDeclarations(extension);
+ if (declarations != null) {
+ for (Iterator<String> iterator = declarations.iterator(); iterator.hasNext();) {
+ String decl = iterator.next();
+ boolean isGLFunction = GLExtensionNames.isGLFunction(decl);
+ boolean isGLEnumeration = false;
+ if (!isGLFunction) {
+ isGLEnumeration = GLExtensionNames.isGLEnumeration(decl);
+ }
+ if (isGLFunction || isGLEnumeration) {
+ String renamed = GLExtensionNames.normalize(decl, isGLFunction);
+ if (!renamed.equals(decl)) {
+ config.addJavaSymbolRename(decl, renamed);
+ }
+ }
+ }
}
- }
}
- }
- }
- }
-
- class ExtensionUnifier implements SymbolFilter {
- private List<ConstantDefinition> constants;
- private List<FunctionSymbol> functions;
-
- public void filterSymbols(List<ConstantDefinition> constants,
- List<FunctionSymbol> functions) {
- this.constants = constants;
- this.functions = functions;
- doWork();
- }
-
- public List<ConstantDefinition> getConstants() {
- return constants;
- }
-
- public List<FunctionSymbol> getFunctions() {
- return functions;
- }
-
- private void doWork() {
- BuildStaticGLInfo glInfo = getGLConfig().getGLInfo();
- if (glInfo == null) {
- return;
- }
- // Try to retain a "good" ordering for these symbols
- Map<String, ConstantDefinition> constantMap = new LinkedHashMap();
- Map<String, FunctionSymbol> functionMap = new LinkedHashMap();
- for (Iterator iter = constants.iterator(); iter.hasNext(); ) {
- ConstantDefinition def = (ConstantDefinition) iter.next();
- constantMap.put(def.getName(), def);
- }
- for (Iterator iter = functions.iterator(); iter.hasNext(); ) {
- FunctionSymbol sym = (FunctionSymbol) iter.next();
- functionMap.put(sym.getName(), sym);
- }
- // Go through all of the declared extensions.
- // For each extension, look at its #define and function symbols.
- // If we find all of the extension's symbols in the core API under
- // non-ARB (or whatever is the suffix) names, then remove this extension
- // from the public API. If it turns out that we are running on hardware
- // 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<String> extensionNames = glInfo.getExtensions();
- for (Iterator iter1 = extensionNames.iterator(); iter1.hasNext(); ) {
- String extension = (String) iter1.next();
- Set<String> declarations = glInfo.getDeclarations(extension);
- boolean isExtension = true;
- boolean shouldUnify = true;
- String cause = null;
- for (Iterator iter2 = declarations.iterator(); iter2.hasNext(); ) {
- String decl = (String) iter2.next();
- boolean isFunc = !decl.startsWith("GL_");
- if (!GLExtensionNames.isExtension(decl, isFunc)) {
- isExtension = false;
- break;
- }
- // See whether we're emitting glue code for this
- // entry point or definition at all
- if (isFunc) {
- if (!functionMap.containsKey(decl)) {
- isExtension = false;
- break;
- }
- } else {
- if (!constantMap.containsKey(decl)) {
- isExtension = false;
- break;
- }
- }
- cause = decl;
- String unifiedName = GLExtensionNames.normalize(decl, isFunc);
- // NOTE that we look up the unified name in the
- // BuildStaticGLInfo's notion of the APIs -- since
- // we might not be emitting glue code for the
- // headers that actually contain the core entry
- // point. Think of the case where we are parsing the
- // GLES2 gl2.h, which contains certain desktop
- // OpenGL extensions that have been moved into the
- // core, but later generating the implementing glue
- // code (not the interface) for the desktop gl.h /
- // glext.h.
- shouldUnify = (glInfo.getExtension(unifiedName) != null);
- // if (isFunc) {
- // shouldUnify = functionMap.containsKey(unifiedName);
- // } else {
- // shouldUnify = constantMap.containsKey(unifiedName);
- // }
- if (!shouldUnify) {
- break;
- }
- }
- if (isExtension) {
- if (shouldUnify) {
- for (Iterator iter2 = declarations.iterator(); iter2.hasNext(); ) {
- String decl = (String) iter2.next();
- boolean isFunc = !decl.startsWith("GL_");
- if (isFunc) {
- functionMap.remove(decl);
- } else {
- constantMap.remove(decl);
- }
- }
- System.err.println("INFO: unified extension " + extension + " into core API");
- } else {
- System.err.println("INFO: didn't unify extension " + extension + " into core API because of " + cause);
- }
- }
- }
- constants = new ArrayList();
- for (Iterator iter = constantMap.keySet().iterator(); iter.hasNext(); ) {
- constants.add(constantMap.get(iter.next()));
- }
- functions = new ArrayList();
- for (Iterator iter = functionMap.keySet().iterator(); iter.hasNext(); ) {
- functions.add(functionMap.get(iter.next()));
- }
- }
- }
-
- private void unifyExtensions(GlueEmitterControls controls) {
- controls.runSymbolFilter(new ExtensionUnifier());
- }
-
- protected JavaConfiguration createConfig() {
- return new GLConfiguration(this);
- }
-
- /** In order to implement Buffer Object variants of certain
- functions we generate another MethodBinding which maps the void*
- argument to a Java long. The generation of emitters then takes
- place as usual. We do however need to keep track of the modified
- MethodBinding object so that we can also modify the emitters
- later to inform them that their argument has changed. We might
- want to push this functionality down into the MethodBinding
- (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<MethodBinding> expandMethodBinding(MethodBinding binding) {
- List<MethodBinding> bindings = super.expandMethodBinding(binding);
-
- if (!getGLConfig().isBufferObjectFunction(binding.getName())) {
- return bindings;
}
- List<MethodBinding> newBindings = new ArrayList();
- newBindings.addAll(bindings);
-
- // Need to expand each one of the generated bindings to take a
- // Java long instead of a Buffer for each void* argument
- for (Iterator iter = bindings.iterator(); iter.hasNext(); ) {
- MethodBinding cur = (MethodBinding) iter.next();
-
- // Some of these routines (glBitmap) take strongly-typed
- // primitive pointers as arguments which are expanded into
- // non-void* arguments
- // This test (rather than !signatureUsesNIO) is used to catch
- // more unexpected situations
- if (cur.signatureUsesJavaPrimitiveArrays()) {
- continue;
- }
-
- MethodBinding result = cur;
- for (int i = 0; i < cur.getNumArguments(); i++) {
- if (cur.getJavaArgumentType(i).isNIOBuffer()) {
- result = result.replaceJavaArgumentType(i, JavaType.createForClass(Long.TYPE));
+ class ExtensionUnifier implements SymbolFilter {
+
+ private List<ConstantDefinition> constants;
+ private List<FunctionSymbol> functions;
+
+ public void filterSymbols(List<ConstantDefinition> constants,
+ List<FunctionSymbol> functions) {
+ this.constants = constants;
+ this.functions = functions;
+ doWork();
}
- }
- if (result == cur) {
- throw new RuntimeException("Error: didn't find any void* arguments for BufferObject function " +
- binding.getName());
- }
+ public List<ConstantDefinition> getConstants() {
+ return constants;
+ }
- newBindings.add(result);
- // Now need to flag this MethodBinding so that we generate the
- // correct flags in the emitters later
- bufferObjectMethodBindings.put(result, result);
+ public List<FunctionSymbol> getFunctions() {
+ return functions;
+ }
+
+ private void doWork() {
+ BuildStaticGLInfo glInfo = getGLConfig().getGLInfo();
+ if (glInfo == null) {
+ return;
+ }
+ // Try to retain a "good" ordering for these symbols
+ Map<String, ConstantDefinition> constantMap = new LinkedHashMap<String, ConstantDefinition>();
+ for (ConstantDefinition def : constants) {
+ constantMap.put(def.getName(), def);
+ }
+ Map<String, FunctionSymbol> functionMap = new LinkedHashMap<String, FunctionSymbol>();
+ for (FunctionSymbol sym : functions) {
+ functionMap.put(sym.getName(), sym);
+ }
+
+ // Go through all of the declared extensions.
+ // For each extension, look at its #define and function symbols.
+ // If we find all of the extension's symbols in the core API under
+ // non-ARB (or whatever is the suffix) names, then remove this extension
+ // from the public API. If it turns out that we are running on hardware
+ // 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<String> extensionNames = glInfo.getExtensions();
+
+ for (String extension : extensionNames) {
+ Set<String> declarations = glInfo.getDeclarations(extension);
+ boolean isExtension = true;
+ boolean shouldUnify = true;
+ String cause = null;
+ for (String decl : declarations) {
+ boolean isFunc = !decl.startsWith("GL_");
+ if (!GLExtensionNames.isExtension(decl, isFunc)) {
+ isExtension = false;
+ break;
+ }
+ // See whether we're emitting glue code for this
+ // entry point or definition at all
+ if (isFunc) {
+ if (!functionMap.containsKey(decl)) {
+ isExtension = false;
+ break;
+ }
+ } else {
+ if (!constantMap.containsKey(decl)) {
+ isExtension = false;
+ break;
+ }
+ }
+ cause = decl;
+ String unifiedName = GLExtensionNames.normalize(decl, isFunc);
+ // NOTE that we look up the unified name in the
+ // BuildStaticGLInfo's notion of the APIs -- since
+ // we might not be emitting glue code for the
+ // headers that actually contain the core entry
+ // point. Think of the case where we are parsing the
+ // GLES2 gl2.h, which contains certain desktop
+ // OpenGL extensions that have been moved into the
+ // core, but later generating the implementing glue
+ // code (not the interface) for the desktop gl.h /
+ // glext.h.
+ shouldUnify = (glInfo.getExtension(unifiedName) != null);
+ // if (isFunc) {
+ // shouldUnify = functionMap.containsKey(unifiedName);
+ // } else {
+ // shouldUnify = constantMap.containsKey(unifiedName);
+ // }
+ if (!shouldUnify) {
+ break;
+ }
+ }
+ if (isExtension) {
+ if (shouldUnify) {
+ for (String decl : declarations) {
+ boolean isFunc = !decl.startsWith("GL_");
+ if (isFunc) {
+ functionMap.remove(decl);
+ } else {
+ constantMap.remove(decl);
+ }
+ }
+ System.err.println("INFO: unified extension " + extension + " into core API");
+ } else {
+ System.err.println("INFO: didn't unify extension " + extension + " into core API because of " + cause);
+ }
+ }
+ }
+ constants = new ArrayList<ConstantDefinition>(constantMap.values());
+ functions = new ArrayList<FunctionSymbol>(functionMap.values());
+ }
}
- return newBindings;
- }
+ private void unifyExtensions(GlueEmitterControls controls) {
+ controls.runSymbolFilter(new ExtensionUnifier());
+ }
- protected boolean needsModifiedEmitters(FunctionSymbol sym) {
- if ((!needsProcAddressWrapper(sym) && !needsBufferObjectVariant(sym)) ||
- getConfig().isUnimplemented(sym.getName())) {
- return false;
+ @Override
+ protected JavaConfiguration createConfig() {
+ return new GLConfiguration(this);
}
- return true;
- }
-
- public boolean isBufferObjectMethodBinding(MethodBinding binding) {
- 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;
- }
+ /** In order to implement Buffer Object variants of certain
+ functions we generate another MethodBinding which maps the void*
+ argument to a Java long. The generation of emitters then takes
+ place as usual. We do however need to keep track of the modified
+ MethodBinding object so that we can also modify the emitters
+ later to inform them that their argument has changed. We might
+ want to push this functionality down into the MethodBinding
+ (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). */
+ @Override
+ protected List<MethodBinding> expandMethodBinding(MethodBinding binding) {
+ List<MethodBinding> bindings = super.expandMethodBinding(binding);
+
+ if (!getGLConfig().isBufferObjectFunction(binding.getName())) {
+ return bindings;
}
- }
- newComment.append("</code>");
- if(null!=optionalComment) {
- newComment.append("<br>");
- newComment.append(optionalComment);
- }
+ List<MethodBinding> newBindings = new ArrayList<MethodBinding>(bindings);
- super.emitDefine(def, newComment.toString());
- }
+ // Need to expand each one of the generated bindings to take a
+ // Java long instead of a Buffer for each void* argument
- 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);
+ for (MethodBinding cur : bindings) {
+
+ // Some of these routines (glBitmap) take strongly-typed
+ // primitive pointers as arguments which are expanded into
+ // non-void* arguments
+ // This test (rather than !signatureUsesNIO) is used to catch
+ // more unexpected situations
+ if (cur.signatureUsesJavaPrimitiveArrays()) {
+ continue;
+ }
+
+ MethodBinding result = cur;
+ for (int i = 0; i < cur.getNumArguments(); i++) {
+ if (cur.getJavaArgumentType(i).isNIOBuffer()) {
+ result = result.replaceJavaArgumentType(i, JavaType.createForClass(Long.TYPE));
+ }
}
- num++;
+
+ if (result == cur) {
+ throw new RuntimeException("Error: didn't find any void* arguments for BufferObject function "
+ + binding.getName());
+ }
+
+ newBindings.add(result);
+ // Now need to flag this MethodBinding so that we generate the
+ // correct flags in the emitters later
+ bufferObjectMethodBindings.put(result, result);
}
+
+ return newBindings;
+ }
+
+ @Override
+ protected boolean needsModifiedEmitters(FunctionSymbol sym) {
+ if ((!needsProcAddressWrapper(sym) && !needsBufferObjectVariant(sym))
+ || getConfig().isUnimplemented(sym.getName())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean isBufferObjectMethodBinding(MethodBinding binding) {
+ return bufferObjectMethodBindings.containsKey(binding);
}
- while( iter.hasNext() ) {
- extensionName = glInfo.getExtension((String)iter.next());
- if(null!=extensionName) {
- buf.append(extensionName);
- if( iter.hasNext() ) {
- buf.append(sep);
+
+ @Override
+ 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();
+ StringBuilder newComment = new StringBuilder();
+ 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) {
+ StringBuilder sb = new StringBuilder();
+ JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, def.getAliasedNames());
+ System.err.println("Dropping marker: " + sb.toString());
+ }
+ return;
+ }
}
- num++;
}
+ newComment.append("</code>");
+
+ if (null != optionalComment) {
+ newComment.append("<br>");
+ newComment.append(optionalComment);
+ }
+
+ super.emitDefine(def, newComment.toString());
}
- return num;
- }
- //----------------------------------------------------------------------
- // Internals only below this point
- //
+ public int addExtensionsOfSymbols2Buffer(StringBuilder buf, String sep, String first, Collection<String> col) {
+ BuildStaticGLInfo glInfo = getGLConfig().getGLInfo();
+ if (null == glInfo) {
+ throw new RuntimeException("No GLInfo for: " + first);
+ }
+ int num = 0;
+ if (null == buf) {
+ buf = new StringBuilder();
+ }
+ String extensionName;
+
+ Iterator<String> 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(iter.next());
+ if (null != extensionName) {
+ buf.append(extensionName);
+ if (iter.hasNext()) {
+ buf.append(sep);
+ }
+ num++;
+ }
+ }
+ return num;
+ }
- protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List emitters) {
- List superEmitters = new ArrayList();
- super.generateModifiedEmitters(baseJavaEmitter, superEmitters);
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+ @Override
+ protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List<FunctionEmitter> emitters) {
+ List<FunctionEmitter> superEmitters = new ArrayList<FunctionEmitter>();
+ super.generateModifiedEmitters(baseJavaEmitter, superEmitters);
- // See whether this is one of the Buffer Object variants
- boolean bufferObjectVariant = bufferObjectMethodBindings.containsKey(baseJavaEmitter.getBinding());
+ // See whether this is one of the Buffer Object variants
+ boolean bufferObjectVariant = bufferObjectMethodBindings.containsKey(baseJavaEmitter.getBinding());
- for (Iterator iter = superEmitters.iterator(); iter.hasNext(); ) {
- JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) iter.next();
- if (emitter instanceof ProcAddressJavaMethodBindingEmitter) {
- emitter = new GLJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) emitter, this, bufferObjectVariant);
+ for (FunctionEmitter emitter : superEmitters) {
+ if (emitter instanceof ProcAddressJavaMethodBindingEmitter) {
+ emitter = new GLJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) emitter, this, bufferObjectVariant);
+ }
+ emitters.add(emitter);
}
- emitters.add(emitter);
}
- }
-
- protected boolean needsBufferObjectVariant(FunctionSymbol sym) {
- return getGLConfig().isBufferObjectFunction(sym.getName());
- }
-
- protected GLConfiguration getGLConfig() {
- return (GLConfiguration) getConfig();
- }
-
- protected void endProcAddressTable() throws Exception
- {
- PrintWriter w = tableWriter;
-
- w.println(" /**");
- w.println(" * This is a convenience method to get (by name) the native function");
- w.println(" * pointer for a given function. It lets you avoid having to");
- w.println(" * manually compute the &quot;" + PROCADDRESS_VAR_PREFIX + " + ");
- w.println(" * &lt;functionName&gt;&quot; member variable name and look it up via");
- w.println(" * reflection; it also will throw an exception if you try to get the");
- w.println(" * address of an unknown function, or one that is statically linked");
- w.println(" * and therefore does not have a function pointer in this table.");
- w.println(" *");
- w.println(" * @throws RuntimeException if the function pointer was not found in");
- w.println(" * this table, either because the function was unknown or because");
- w.println(" * it was statically linked.");
- w.println(" */");
- w.println(" public long getAddressFor(String functionNameUsr) {");
- w.println(" String functionNameBase = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLExtensionNames.normalizeARB(functionNameUsr, true), true);");
- w.println(" String addressFieldNameBase = " + getProcAddressConfig().gluegenRuntimePackage() + ".ProcAddressHelper.PROCADDRESS_VAR_PREFIX + functionNameBase;");
- w.println(" java.lang.reflect.Field addressField = null;");
- w.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutationNumber(functionNameBase);");
- w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {");
- w.println(" String addressFieldName = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutation(addressFieldNameBase, i);");
- w.println(" try {");
- w.println(" addressField = getClass().getField(addressFieldName);");
- w.println(" } catch (Exception e) { }");
- w.println(" }");
- w.println("");
- w.println(" if(null==addressField) {");
- w.println(" // The user is calling a bogus function or one which is not");
- w.println(" // runtime linked");
- w.println(" throw new RuntimeException(");
- w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +");
- w.println(" \"\\\"; it's either statically linked or address field is not a known \" +");
- w.println(" \"function\");");
- w.println(" } ");
- w.println(" try {");
- w.println(" return addressField.getLong(this);");
- w.println(" } catch (Exception e) {");
- w.println(" throw new RuntimeException(");
- w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +");
- w.println(" \"\\\"; it's either statically linked or is not a known \" +");
- w.println(" \"function\", e);");
- w.println(" }");
- w.println(" }");
-
- w.println("} // end of class " + tableClassName);
- w.flush();
- w.close();
- }
+
+ protected boolean needsBufferObjectVariant(FunctionSymbol sym) {
+ return getGLConfig().isBufferObjectFunction(sym.getName());
+ }
+
+ protected GLConfiguration getGLConfig() {
+ return (GLConfiguration) getConfig();
+ }
+
+ @Override
+ protected void endProcAddressTable() throws Exception {
+ PrintWriter w = tableWriter;
+
+ w.println(" /**");
+ w.println(" * This is a convenience method to get (by name) the native function");
+ w.println(" * pointer for a given function. It lets you avoid having to");
+ w.println(" * manually compute the &quot;" + PROCADDRESS_VAR_PREFIX + " + ");
+ w.println(" * &lt;functionName&gt;&quot; member variable name and look it up via");
+ w.println(" * reflection; it also will throw an exception if you try to get the");
+ w.println(" * address of an unknown function, or one that is statically linked");
+ w.println(" * and therefore does not have a function pointer in this table.");
+ w.println(" *");
+ w.println(" * @throws RuntimeException if the function pointer was not found in");
+ w.println(" * this table, either because the function was unknown or because");
+ w.println(" * it was statically linked.");
+ w.println(" */");
+ w.println(" public long getAddressFor(String functionNameUsr) {");
+ w.println(" String functionNameBase = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLExtensionNames.normalizeARB(functionNameUsr, true), true);");
+ w.println(" String addressFieldNameBase = " + getProcAddressConfig().gluegenRuntimePackage() + ".ProcAddressHelper.PROCADDRESS_VAR_PREFIX + functionNameBase;");
+ w.println(" java.lang.reflect.Field addressField = null;");
+ w.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutationNumber(functionNameBase);");
+ w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {");
+ w.println(" String addressFieldName = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutation(addressFieldNameBase, i);");
+ w.println(" try {");
+ w.println(" addressField = getClass().getField(addressFieldName);");
+ w.println(" } catch (Exception e) { }");
+ w.println(" }");
+ w.println("");
+ w.println(" if(null==addressField) {");
+ w.println(" // The user is calling a bogus function or one which is not");
+ w.println(" // runtime linked");
+ w.println(" throw new RuntimeException(");
+ w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +");
+ w.println(" \"\\\"; it's either statically linked or address field is not a known \" +");
+ w.println(" \"function\");");
+ w.println(" } ");
+ w.println(" try {");
+ w.println(" return addressField.getLong(this);");
+ w.println(" } catch (Exception e) {");
+ w.println(" throw new RuntimeException(");
+ w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +");
+ w.println(" \"\\\"; it's either statically linked or is not a known \" +");
+ w.println(" \"function\", e);");
+ w.println(" }");
+ w.println(" }");
+
+ w.println("} // end of class " + tableClassName);
+ w.flush();
+ w.close();
+ }
}
diff --git a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
index 33f94fb..51182c1 100755
--- a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
@@ -36,7 +36,6 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.opengl;
import java.io.*;
@@ -45,89 +44,80 @@ import com.sun.gluegen.cgram.types.*;
import com.sun.gluegen.procaddress.*;
/** A specialization of the proc address emitter which knows how to
- change argument names to take into account Vertex Buffer Object /
- Pixel Buffer Object variants. */
-
+change argument names to take into account Vertex Buffer Object /
+Pixel Buffer Object variants. */
public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmitter {
- protected boolean bufferObjectVariant;
- protected GLEmitter glEmitter;
- protected CommentEmitter glCommentEmitter = new GLCommentEmitter();
-
- public GLJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap,
- boolean callThroughProcAddress,
- String getProcAddressTableExpr,
- boolean changeNameAndArguments,
- boolean bufferObjectVariant,
- GLEmitter emitter) {
- super(methodToWrap,
- callThroughProcAddress,
- getProcAddressTableExpr,
- changeNameAndArguments,
- emitter);
- this.bufferObjectVariant = bufferObjectVariant;
- this.glEmitter=emitter;
- setCommentEmitter(glCommentEmitter);
- }
-
- public GLJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap,
- GLEmitter emitter,
- boolean bufferObjectVariant) {
- super(methodToWrap);
- this.bufferObjectVariant = bufferObjectVariant;
- this.glEmitter=emitter;
- setCommentEmitter(glCommentEmitter);
- }
-
- public GLJavaMethodBindingEmitter(GLJavaMethodBindingEmitter methodToWrap) {
- this(methodToWrap, methodToWrap.glEmitter, methodToWrap.bufferObjectVariant);
- }
-
- @Override
- protected String getArgumentName(int i) {
- String name = super.getArgumentName(i);
-
- if (!bufferObjectVariant) {
- return name;
+
+ protected boolean bufferObjectVariant;
+ protected GLEmitter glEmitter;
+ protected CommentEmitter glCommentEmitter = new GLCommentEmitter();
+
+ public GLJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, boolean callThroughProcAddress,
+ String getProcAddressTableExpr, boolean changeNameAndArguments, boolean bufferObjectVariant, GLEmitter emitter) {
+
+ super(methodToWrap, callThroughProcAddress, getProcAddressTableExpr, changeNameAndArguments, emitter);
+ this.bufferObjectVariant = bufferObjectVariant;
+ this.glEmitter = emitter;
+ setCommentEmitter(glCommentEmitter);
}
- // Emitters for VBO/PBO-related routines change the outgoing
- // argument name for the buffer
- if (binding.getJavaArgumentType(i).isLong()) {
- Type cType = binding.getCArgumentType(i);
- if (cType.isPointer() &&
- (cType.asPointer().getTargetType().isVoid() ||
- cType.asPointer().getTargetType().isPrimitive())) {
- return name + "_buffer_offset";
- }
+ public GLJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap, GLEmitter emitter, boolean bufferObjectVariant) {
+ super(methodToWrap);
+ this.bufferObjectVariant = bufferObjectVariant;
+ this.glEmitter = emitter;
+ setCommentEmitter(glCommentEmitter);
}
- return name;
- }
+ public GLJavaMethodBindingEmitter(GLJavaMethodBindingEmitter methodToWrap) {
+ this(methodToWrap, methodToWrap.glEmitter, methodToWrap.bufferObjectVariant);
+ }
- protected class GLCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter {
-
@Override
- 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());
+ protected String getArgumentName(int i) {
+ String name = super.getArgumentName(i);
+
+ if (!bufferObjectVariant) {
+ return name;
+ }
+
+ // Emitters for VBO/PBO-related routines change the outgoing
+ // argument name for the buffer
+ if (binding.getJavaArgumentType(i).isLong()) {
+ Type cType = binding.getCArgumentType(i);
+ Type targetType = cType.asPointer().getTargetType();
+ if (cType.isPointer() && (targetType.isVoid() || targetType.isPrimitive())) {
+ return name + "_buffer_offset";
+ }
+ }
+
+ return name;
+ }
+
+ protected class GLCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter {
+
+ @Override
+ protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) {
+
+ super.emitBindingCSignature(binding, writer);
+
+ String symbolRenamed = binding.getName();
+ StringBuilder newComment = new StringBuilder();
+
+ newComment.append("<br>Part of <code>");
+ if (0 == glEmitter.addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, binding.getAliasedNames())) {
+ if (glEmitter.getGLConfig().getAllowNonGLExtensions()) {
+ newComment.append("CORE FUNC");
+ } else {
+ StringBuilder sb = new StringBuilder();
+ JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, binding.getAliasedNames());
+ RuntimeException ex = new RuntimeException("Couldn't find extension to: " + binding + " ; " + sb.toString());
+ 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 386ad8c..26c4f27 100644
--- a/src/java/com/sun/gluegen/pcpp/PCPP.java
+++ b/src/java/com/sun/gluegen/pcpp/PCPP.java
@@ -56,6 +56,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.logging.Logger;
+import static java.util.logging.Level.*;
/** A minimal pseudo-C-preprocessor designed in particular to preserve
#define statements defining constants so they can be observed by a
@@ -63,6 +65,8 @@ import java.util.Set;
public class PCPP {
+ private static final Logger LOG = Logger.getLogger(PCPP.class.getPackage().getName());
+
private static final boolean disableDebugPrint = true;
/** Map containing the results of #define statements. We must
@@ -207,7 +211,7 @@ public class PCPP {
private final List<String> values;
private final List<String> params;
- public Macro(List<String> params, List<String> values) {
+ Macro(List<String> params, List<String> values) {
this.values = values;
this.params = params;
}
@@ -431,15 +435,15 @@ public class PCPP {
if (enabled()) {
String oldDef = defineMap.remove(name);
if (oldDef == null) {
- System.err.println("WARNING: ignoring redundant \"#undef " +
- name + "\", at \"" + filename() + "\" line " + lineNumber() +
- ": \"" + name + "\" was not previously defined");
+ LOG.log(WARNING, "ignoring redundant \"#undef {0}\", at \"{1}\" line {2}: \"{3}\" was not previously defined",
+ new Object[]{name, filename(), lineNumber(), name});
} else {
// System.err.println("UNDEFINED: '" + name + "' (line " + lineNumber() + " file " + filename() + ")");
}
nonConstantDefines.remove(name);
+ } else {
+ LOG.log(WARNING, "FAILED TO UNDEFINE: ''{0}'' (line {1} file {2})", new Object[]{name, lineNumber(), filename()});
}
- else System.err.println("FAILED TO UNDEFINE: '" + name + "' (line " + lineNumber() + " file " + filename() + ")");
}
private void handleDefine() throws IOException {
@@ -489,8 +493,7 @@ public class PCPP {
String value = "";
String oldDef = defineMap.put(name, value);
if (oldDef != null && !oldDef.equals(value)) {
- System.err.println("WARNING: \"" + name + "\" redefined from \"" +
- oldDef + "\" to \"\"");
+ LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"\"", new Object[]{name, oldDef});
}
// We don't want to emit the define, because it would serve no purpose
// and cause GlueGen errors (confuse the GnuCParser)
@@ -505,8 +508,7 @@ public class PCPP {
// Put it in the #define map
String oldDef = defineMap.put(name, value);
if (oldDef != null && !oldDef.equals(value)) {
- System.err.println("WARNING: \"" + name + "\" redefined from \"" +
- oldDef + "\" to \"" + value + "\"");
+ LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", new Object[]{name, oldDef, value});
}
debugPrint(true, "#define " + name + " ["+oldDef+" ] -> "+value + " CONST");
//System.out.println("//---DEFINED: " + name + " to \"" + value + "\"");
@@ -551,8 +553,7 @@ public class PCPP {
Macro macro = new Macro(params, values);
Macro oldDef = macroMap.put(name, macro);
if (oldDef != null) {
- System.err.println("WARNING: \"" + name + "\" redefined from \"" +
- oldDef + "\" to \"" + macro + "\"");
+ LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", new Object[]{name, oldDef, macro});
}
emitDefine = false;
@@ -602,8 +603,7 @@ public class PCPP {
String oldDef = defineMap.put(name, value);
if (oldDef != null && !oldDef.equals(value)) {
- System.err.println("WARNING: \"" + name + "\" redefined from \"" +
- oldDef + "\" to \"" + value + "\"");
+ LOG.log(WARNING, "\"{0}\" redefined from \"{1}\" to \"{2}\"", new Object[]{name, oldDef, value});
}
debugPrint(true, "#define " + name + " ["+oldDef+" ] -> "+value + " CONST");
// System.out.println("#define " + name +" "+value + " CONST EXPRESSION");
@@ -919,12 +919,12 @@ public class PCPP {
} else if (t == '<') {
// Components of path name are coming in as separate tokens;
// concatenate them
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
while ((t = nextToken()) != '>' && (t != StreamTokenizer.TT_EOF)) {
buf.append(curTokenAsString());
}
if (t == StreamTokenizer.TT_EOF) {
- System.err.println("WARNING: unexpected EOF while processing #include directive");
+ LOG.warning("unexpected EOF while processing #include directive");
}
filename = buf.toString();
}
@@ -937,7 +937,7 @@ public class PCPP {
String fullname = findFile(filename);
//System.out.println("ACTIVE BLOCK, LOADING " + filename);
if (fullname == null) {
- System.err.println("WARNING: unable to find #include file \"" + filename + "\"");
+ LOG.log(WARNING, "unable to find #include file \"{0}\"", filename);
return;
}
// Process this file in-line
@@ -957,18 +957,18 @@ public class PCPP {
private List<Boolean> enabledBits = new ArrayList<Boolean>();
private static int debugPrintIndentLevel = 0;
- private void debugPrint(boolean onlyPrintIfEnabled, String msg) {
+
+ private void debugPrint(boolean onlyPrintIfEnabled, String msg) {
if (disableDebugPrint) {
return;
}
- if (!onlyPrintIfEnabled || (onlyPrintIfEnabled && enabled()))
- {
- for (int i = debugPrintIndentLevel; --i >0; ) {
- System.out.print(" ");
- }
- System.out.println(msg + " (line " + lineNumber() + " file " + filename() + ")");
+ if (!onlyPrintIfEnabled || (onlyPrintIfEnabled && enabled())) {
+ for (int i = debugPrintIndentLevel; --i > 0;) {
+ System.out.print(" ");
}
+ System.out.println(msg + " (line " + lineNumber() + " file " + filename() + ")");
+ }
}
private void pushEnableBit(boolean enabled) {
@@ -978,8 +978,8 @@ public class PCPP {
}
private void popEnableBit() {
- if (enabledBits.size() == 0) {
- System.err.println("WARNING: mismatched #ifdef/endif pairs");
+ if (enabledBits.isEmpty()) {
+ LOG.warning("mismatched #ifdef/endif pairs");
return;
}
enabledBits.remove(enabledBits.size() - 1);
@@ -988,7 +988,7 @@ public class PCPP {
}
private boolean enabled() {
- return (enabledBits.size() == 0 || enabledBits.get(enabledBits.size() - 1));
+ return (enabledBits.isEmpty() || enabledBits.get(enabledBits.size() - 1));
}
private void print(String s) {
@@ -1036,46 +1036,42 @@ public class PCPP {
System.exit(1);
}
- public static void main(String[] args) {
- try {
- Reader reader = null;
- String filename = null;
+ public static void main(String[] args) throws IOException {
+ Reader reader = null;
+ String filename = null;
- if (args.length == 0) {
- usage();
- }
+ if (args.length == 0) {
+ usage();
+ }
- List<String> includePaths = new ArrayList<String>();
- for (int i = 0; i < args.length; i++) {
- if (i < args.length - 1) {
- String arg = args[i];
- if (arg.startsWith("-I")) {
- String[] paths = arg.substring(2).split(System.getProperty("path.separator"));
- for (int j = 0; j < paths.length; j++) {
- includePaths.add(paths[j]);
- }
- } else {
- usage();
+ List<String> includePaths = new ArrayList<String>();
+ for (int i = 0; i < args.length; i++) {
+ if (i < args.length - 1) {
+ String arg = args[i];
+ if (arg.startsWith("-I")) {
+ String[] paths = arg.substring(2).split(System.getProperty("path.separator"));
+ for (int j = 0; j < paths.length; j++) {
+ includePaths.add(paths[j]);
}
} else {
- String arg = args[i];
- if (arg.equals("-")) {
- reader = new InputStreamReader(System.in);
- filename = "standard input";
- } else {
- if (arg.startsWith("-")) {
- usage();
- }
- filename = arg;
- reader = new BufferedReader(new FileReader(filename));
+ usage();
+ }
+ } else {
+ String arg = args[i];
+ if (arg.equals("-")) {
+ reader = new InputStreamReader(System.in);
+ filename = "standard input";
+ } else {
+ if (arg.startsWith("-")) {
+ usage();
}
+ filename = arg;
+ reader = new BufferedReader(new FileReader(filename));
}
}
-
- new PCPP(includePaths).run(reader, filename);
- } catch (IOException e) {
- e.printStackTrace();
}
+
+ new PCPP(includePaths).run(reader, filename);
}
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
index b7fac1b..a951c42 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
@@ -40,165 +40,170 @@
package com.sun.gluegen.procaddress;
import java.io.*;
-import java.util.*;
import com.sun.gluegen.*;
import com.sun.gluegen.cgram.types.*;
public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
+
private boolean callThroughProcAddress;
private boolean needsLocalTypedef;
+
private String localTypedefCallingConvention;
- private static String procAddressJavaTypeName =
- JavaType.createForClass(Long.TYPE).jniTypeName();
+
+ private static final String procAddressJavaTypeName = JavaType.createForClass(Long.TYPE).jniTypeName();
private ProcAddressEmitter emitter;
- public ProcAddressCMethodBindingEmitter(CMethodBindingEmitter methodToWrap,
- final boolean callThroughProcAddress,
- boolean needsLocalTypedef,
- String localTypedefCallingConvention,
- ProcAddressEmitter emitter) {
- super(
- new MethodBinding(methodToWrap.getBinding()) {
- public String getName() {
- if (callThroughProcAddress) {
- return ProcAddressEmitter.WRAP_PREFIX + super.getName();
- } else {
- return super.getName();
- }
+ public ProcAddressCMethodBindingEmitter(CMethodBindingEmitter methodToWrap, final boolean callThroughProcAddress,
+ boolean needsLocalTypedef, String localTypedefCallingConvention, ProcAddressEmitter emitter) {
+
+ super(
+ new MethodBinding(methodToWrap.getBinding()) {
+ @Override
+ public String getName() {
+ if (callThroughProcAddress) {
+ return ProcAddressEmitter.WRAP_PREFIX + super.getName();
+ } else {
+ return super.getName();
+ }
+ }
+ },
+ methodToWrap.getDefaultOutput(),
+ methodToWrap.getJavaPackageName(),
+ methodToWrap.getJavaClassName(),
+ methodToWrap.getIsOverloadedBinding(),
+ methodToWrap.getIsJavaMethodStatic(),
+ true,
+ methodToWrap.forIndirectBufferAndArrayImplementation(),
+ methodToWrap.getMachineDescription()
+ );
+
+ if (methodToWrap.getReturnValueCapacityExpression() != null) {
+ setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression());
}
- },
- methodToWrap.getDefaultOutput(),
- methodToWrap.getJavaPackageName(),
- methodToWrap.getJavaClassName(),
- methodToWrap.getIsOverloadedBinding(),
- methodToWrap.getIsJavaMethodStatic(),
- true,
- methodToWrap.forIndirectBufferAndArrayImplementation(),
- methodToWrap.getMachineDescription()
- );
-
- if (methodToWrap.getReturnValueCapacityExpression() != null) {
- setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression());
- }
- if (methodToWrap.getReturnValueLengthExpression() != null) {
- setReturnValueLengthExpression(methodToWrap.getReturnValueLengthExpression());
+ if (methodToWrap.getReturnValueLengthExpression() != null) {
+ setReturnValueLengthExpression(methodToWrap.getReturnValueLengthExpression());
+ }
+ setTemporaryCVariableDeclarations(methodToWrap.getTemporaryCVariableDeclarations());
+ setTemporaryCVariableAssignments(methodToWrap.getTemporaryCVariableAssignments());
+
+ setCommentEmitter(defaultCommentEmitter);
+
+ this.callThroughProcAddress = callThroughProcAddress;
+ this.needsLocalTypedef = needsLocalTypedef;
+ this.localTypedefCallingConvention = localTypedefCallingConvention;
+ this.emitter = emitter;
}
- setTemporaryCVariableDeclarations(methodToWrap.getTemporaryCVariableDeclarations());
- setTemporaryCVariableAssignments (methodToWrap.getTemporaryCVariableAssignments ());
-
- setCommentEmitter(defaultCommentEmitter);
- this.callThroughProcAddress = callThroughProcAddress;
- this.needsLocalTypedef = needsLocalTypedef;
- this.localTypedefCallingConvention = localTypedefCallingConvention;
- this.emitter = emitter;
- }
-
- protected int emitArguments(PrintWriter writer) {
- int numEmitted = super.emitArguments(writer);
- if (callThroughProcAddress) {
- if (numEmitted > 0)
- {
- writer.print(", ");
+
+ @Override
+ protected int emitArguments(PrintWriter writer) {
+ int numEmitted = super.emitArguments(writer);
+ if (callThroughProcAddress) {
+ if (numEmitted > 0) {
+ writer.print(", ");
+ }
+ writer.print(procAddressJavaTypeName);
+ writer.print(" procAddress");
+ ++numEmitted;
}
- writer.print(procAddressJavaTypeName);
- writer.print(" procAddress");
- ++numEmitted;
+
+ return numEmitted;
}
- return numEmitted;
- }
-
- protected void emitBodyVariableDeclarations(PrintWriter writer) {
- if (callThroughProcAddress) {
- // create variable for the function pointer with the right type, and set
- // it to the value of the passed-in proc address
- FunctionSymbol cSym = getBinding().getCSymbol();
- String funcPointerTypedefName =
- emitter.getFunctionPointerTypedefName(cSym);
-
- if (needsLocalTypedef) {
- // We (probably) didn't get a typedef for this function
- // pointer type in the header file; the user requested that we
- // forcibly generate one. Here we force the emission of one.
- PointerType funcPtrType = new PointerType(null, cSym.getType(), 0);
- // Just for safety, emit this name slightly differently than
- // the mangling would otherwise produce
- funcPointerTypedefName = "_local_" + funcPointerTypedefName;
-
- writer.print(" typedef ");
- writer.print(funcPtrType.toString(funcPointerTypedefName, localTypedefCallingConvention));
- writer.println(";");
- }
-
- writer.print(" ");
- writer.print(funcPointerTypedefName);
- writer.print(" ptr_");
- writer.print(cSym.getName());
- writer.println(";");
+ @Override
+ protected void emitBodyVariableDeclarations(PrintWriter writer) {
+ if (callThroughProcAddress) {
+ // create variable for the function pointer with the right type, and set
+ // it to the value of the passed-in proc address
+ FunctionSymbol cSym = getBinding().getCSymbol();
+ String funcPointerTypedefName =
+ emitter.getFunctionPointerTypedefName(cSym);
+
+ if (needsLocalTypedef) {
+ // We (probably) didn't get a typedef for this function
+ // pointer type in the header file; the user requested that we
+ // forcibly generate one. Here we force the emission of one.
+ PointerType funcPtrType = new PointerType(null, cSym.getType(), 0);
+ // Just for safety, emit this name slightly differently than
+ // the mangling would otherwise produce
+ funcPointerTypedefName = "_local_" + funcPointerTypedefName;
+
+ writer.print(" typedef ");
+ writer.print(funcPtrType.toString(funcPointerTypedefName, localTypedefCallingConvention));
+ writer.println(";");
+ }
+
+ writer.print(" ");
+ writer.print(funcPointerTypedefName);
+ writer.print(" ptr_");
+ writer.print(cSym.getName());
+ writer.println(";");
+ }
+
+ super.emitBodyVariableDeclarations(writer);
}
- super.emitBodyVariableDeclarations(writer);
- }
+ @Override
+ protected void emitBodyVariablePreCallSetup(PrintWriter writer) {
+ super.emitBodyVariablePreCallSetup(writer);
- protected void emitBodyVariablePreCallSetup(PrintWriter writer) {
- super.emitBodyVariablePreCallSetup(writer);
+ if (callThroughProcAddress) {
+ // set the function pointer to the value of the passed-in procAddress
+ FunctionSymbol cSym = getBinding().getCSymbol();
+ String funcPointerTypedefName = emitter.getFunctionPointerTypedefName(cSym);
+ if (needsLocalTypedef) {
+ funcPointerTypedefName = "_local_" + funcPointerTypedefName;
+ }
- if (callThroughProcAddress) {
- // set the function pointer to the value of the passed-in procAddress
- FunctionSymbol cSym = getBinding().getCSymbol();
- String funcPointerTypedefName = emitter.getFunctionPointerTypedefName(cSym);
- if (needsLocalTypedef) {
- funcPointerTypedefName = "_local_" + funcPointerTypedefName;
- }
+ String ptrVarName = "ptr_" + cSym.getName();
- String ptrVarName = "ptr_" + cSym.getName();
-
- writer.print(" ");
- writer.print(ptrVarName);
- writer.print(" = (");
- writer.print(funcPointerTypedefName);
- writer.println(") (intptr_t) procAddress;");
+ writer.print(" ");
+ writer.print(ptrVarName);
+ writer.print(" = (");
+ writer.print(funcPointerTypedefName);
+ writer.println(") (intptr_t) procAddress;");
- writer.println(" assert(" + ptrVarName + " != NULL);");
+ writer.println(" assert(" + ptrVarName + " != NULL);");
+ }
}
- }
-
- protected void emitBodyCallCFunction(PrintWriter writer) {
- if (!callThroughProcAddress) {
- super.emitBodyCallCFunction(writer);
- } else {
- // Make the call to the actual C function
- writer.print(" ");
-
- // WARNING: this code assumes that the return type has already been
- // typedef-resolved.
- Type cReturnType = binding.getCReturnType();
-
- if (!cReturnType.isVoid()) {
- writer.print("_res = ");
- }
- MethodBinding binding = getBinding();
- if (binding.hasContainingType()) {
- // FIXME: this can and should be handled and unified with the
- // associated code in the CMethodBindingEmitter
- throw new IllegalStateException("Cannot call through function pointer because binding has containing type: " + binding);
- }
-
- // call throught the run-time function pointer
- writer.print("(* ptr_");
- writer.print(binding.getCSymbol().getName());
- writer.print(") ");
- writer.print("(");
- emitBodyPassCArguments(writer);
- writer.println(");");
+
+ @Override
+ protected void emitBodyCallCFunction(PrintWriter writer) {
+ if (!callThroughProcAddress) {
+ super.emitBodyCallCFunction(writer);
+ } else {
+ // Make the call to the actual C function
+ writer.print(" ");
+
+ // WARNING: this code assumes that the return type has already been
+ // typedef-resolved.
+ Type cReturnType = binding.getCReturnType();
+
+ if (!cReturnType.isVoid()) {
+ writer.print("_res = ");
+ }
+ MethodBinding mBinding = getBinding();
+ if (mBinding.hasContainingType()) {
+ // FIXME: this can and should be handled and unified with the
+ // associated code in the CMethodBindingEmitter
+ throw new IllegalStateException("Cannot call through function pointer because binding has containing type: " + mBinding);
+ }
+
+ // call throught the run-time function pointer
+ writer.print("(* ptr_");
+ writer.print(mBinding.getCSymbol().getName());
+ writer.print(") ");
+ writer.print("(");
+ emitBodyPassCArguments(writer);
+ writer.println(");");
+ }
}
- }
- protected String jniMangle(MethodBinding binding) {
- StringBuffer buf = new StringBuffer(super.jniMangle(binding));
- if (callThroughProcAddress) {
- jniMangle(Long.TYPE, buf, false); // to account for the additional _addr_ parameter
+ @Override
+ protected String jniMangle(MethodBinding binding) {
+ StringBuffer buf = new StringBuffer(super.jniMangle(binding));
+ if (callThroughProcAddress) {
+ jniMangle(Long.TYPE, buf, false); // to account for the additional _addr_ parameter
+ }
+ return buf.toString();
}
- return buf.toString();
- }
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java b/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
index 9409a1e..993f917 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
@@ -36,7 +36,6 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.procaddress;
import java.io.*;
@@ -45,262 +44,279 @@ import java.util.*;
import com.sun.gluegen.*;
-public class ProcAddressConfiguration extends JavaConfiguration
-{
- private boolean emitProcAddressTable = false;
- private String tableClassPackage;
- private String tableClassName = "ProcAddressTable";
- private Set/*<String>*/ skipProcAddressGen = new HashSet();
- private List/*<String>*/ forceProcAddressGen = new ArrayList();
- private Set/*<String>*/ forceProcAddressGenSet = new HashSet();
- private boolean forceProcAddressGen4All=false;
- private String getProcAddressTableExpr;
- private ConvNode procAddressNameConverter;
- // This is needed only on Windows. Ideally we would modify the
- // HeaderParser and PCPP to automatically pick up the calling
- // convention from the headers
- private Map/*<String,String>*/ localProcAddressCallingConventionMap = new HashMap();
- private String localProcAddressCallingConvention4All=null;
-
- protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
- if (cmd.equalsIgnoreCase("EmitProcAddressTable"))
- {
- emitProcAddressTable =
- readBoolean("EmitProcAddressTable", tok, filename, lineNo).booleanValue();
- }
- else if (cmd.equalsIgnoreCase("ProcAddressTablePackage"))
- {
- tableClassPackage = readString("ProcAddressTablePackage", tok, filename, lineNo);
- }
- else if (cmd.equalsIgnoreCase("ProcAddressTableClassName"))
- {
- tableClassName = readString("ProcAddressTableClassName", tok, filename, lineNo);
- }
- else if (cmd.equalsIgnoreCase("SkipProcAddressGen"))
- {
- String sym = readString("SkipProcAddressGen", tok, filename, lineNo);
- skipProcAddressGen.add(sym);
- }
- else if (cmd.equalsIgnoreCase("ForceProcAddressGen"))
- {
- String funcName = readString("ForceProcAddressGen", tok, filename, lineNo);
- if(funcName.equals("__ALL__")) {
- forceProcAddressGen4All=true;
+public class ProcAddressConfiguration extends JavaConfiguration {
+
+ private boolean emitProcAddressTable = false;
+ private boolean forceProcAddressGen4All = false;
+
+ private String tableClassPackage;
+ private String tableClassName = "ProcAddressTable";
+ private String getProcAddressTableExpr;
+ private String localProcAddressCallingConvention4All = null;
+
+ private ConvNode procAddressNameConverter;
+ private final Set<String> skipProcAddressGen = new HashSet<String>();
+ private final List<String> forceProcAddressGen = new ArrayList<String>();
+ private final Set<String> forceProcAddressGenSet = new HashSet<String>();
+
+ // This is needed only on Windows. Ideally we would modify the
+ // HeaderParser and PCPP to automatically pick up the calling
+ // convention from the headers
+ private Map<String, String> localProcAddressCallingConventionMap = new HashMap<String, String>();
+
+ @Override
+ protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
+ if (cmd.equalsIgnoreCase("EmitProcAddressTable")) {
+ emitProcAddressTable = readBoolean("EmitProcAddressTable", tok, filename, lineNo).booleanValue();
+ } else if (cmd.equalsIgnoreCase("ProcAddressTablePackage")) {
+ tableClassPackage = readString("ProcAddressTablePackage", tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("ProcAddressTableClassName")) {
+ tableClassName = readString("ProcAddressTableClassName", tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("SkipProcAddressGen")) {
+ String sym = readString("SkipProcAddressGen", tok, filename, lineNo);
+ skipProcAddressGen.add(sym);
+ } else if (cmd.equalsIgnoreCase("ForceProcAddressGen")) {
+ String funcName = readString("ForceProcAddressGen", tok, filename, lineNo);
+ if (funcName.equals("__ALL__")) {
+ forceProcAddressGen4All = true;
+ } else {
+ addForceProcAddressGen(funcName);
+ }
+ } else if (cmd.equalsIgnoreCase("GetProcAddressTableExpr")) {
+ getProcAddressTableExpr = readGetProcAddressTableExpr(tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("ProcAddressNameExpr")) {
+ readProcAddressNameExpr(tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("LocalProcAddressCallingConvention")) {
+ readLocalProcAddressCallingConvention(tok, filename, lineNo);
} else {
- addForceProcAddressGen( funcName );
+ super.dispatch(cmd, tok, file, filename, lineNo);
}
- }
- else if (cmd.equalsIgnoreCase("GetProcAddressTableExpr"))
- {
- getProcAddressTableExpr = readGetProcAddressTableExpr(tok, filename, lineNo);
- }
- else if (cmd.equalsIgnoreCase("ProcAddressNameExpr"))
- {
- readProcAddressNameExpr(tok, filename, lineNo);
- }
- else if (cmd.equalsIgnoreCase("LocalProcAddressCallingConvention"))
- {
- readLocalProcAddressCallingConvention(tok, filename, lineNo);
- }
- else
- {
- super.dispatch(cmd,tok,file,filename,lineNo);
- }
- }
-
- protected String readGetProcAddressTableExpr(StringTokenizer tok, String filename, int lineNo) {
- try {
- String restOfLine = tok.nextToken("\n\r\f");
- return restOfLine.trim();
- } catch (NoSuchElementException e) {
- throw new RuntimeException("Error parsing \"GetProcAddressTableExpr\" command at line " + lineNo +
- " in file \"" + filename + "\"", e);
}
- }
-
- protected void setProcAddressNameExpr(String expr) {
- // Parse this into something allowing us to map from a function
- // name to the typedef'ed function pointer name
- List/*<String>*/ tokens = new ArrayList/*<String>*/();
- StringTokenizer tok1 = new StringTokenizer(expr);
- while (tok1.hasMoreTokens()) {
- String sstr = tok1.nextToken();
- StringTokenizer tok2 = new StringTokenizer(sstr, "$()", true);
- while (tok2.hasMoreTokens()) {
- tokens.add(tok2.nextToken());
- }
+
+ protected String readGetProcAddressTableExpr(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String restOfLine = tok.nextToken("\n\r\f");
+ return restOfLine.trim();
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"GetProcAddressTableExpr\" command at line " + lineNo
+ + " in file \"" + filename + "\"", e);
+ }
}
- // Now that the string is flattened out, convert it to nodes
- procAddressNameConverter = makeConverter(tokens.iterator());
- if (procAddressNameConverter == null) {
- throw new NoSuchElementException("Error creating converter from string");
+ protected void setProcAddressNameExpr(String expr) {
+ // Parse this into something allowing us to map from a function
+ // name to the typedef'ed function pointer name
+ List<String> tokens = new ArrayList<String>();
+ StringTokenizer tok1 = new StringTokenizer(expr);
+ while (tok1.hasMoreTokens()) {
+ String sstr = tok1.nextToken();
+ StringTokenizer tok2 = new StringTokenizer(sstr, "$()", true);
+ while (tok2.hasMoreTokens()) {
+ tokens.add(tok2.nextToken());
+ }
+ }
+
+ // Now that the string is flattened out, convert it to nodes
+ procAddressNameConverter = makeConverter(tokens.iterator());
+ if (procAddressNameConverter == null) {
+ throw new NoSuchElementException("Error creating converter from string");
+ }
}
- }
-
- protected void readProcAddressNameExpr(StringTokenizer tok, String filename, int lineNo) {
- try {
- String restOfLine = tok.nextToken("\n\r\f");
- restOfLine = restOfLine.trim();
- setProcAddressNameExpr(restOfLine);
- } catch (NoSuchElementException e) {
- throw new RuntimeException("Error parsing \"ProcAddressNameExpr\" command at line " + lineNo +
- " in file \"" + filename + "\"", e);
+
+ protected void readProcAddressNameExpr(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String restOfLine = tok.nextToken("\n\r\f");
+ restOfLine = restOfLine.trim();
+ setProcAddressNameExpr(restOfLine);
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"ProcAddressNameExpr\" command at line " + lineNo
+ + " in file \"" + filename + "\"", e);
+ }
}
- }
-
- protected void readLocalProcAddressCallingConvention(StringTokenizer tok, String filename, int lineNo) throws IOException {
- try {
- String functionName = tok.nextToken();
- String callingConvention = tok.nextToken();
- if(functionName.equals("__ALL__")) {
- localProcAddressCallingConvention4All=callingConvention;
- } else {
- localProcAddressCallingConventionMap.put(functionName, callingConvention);
- }
- } catch (NoSuchElementException e) {
- throw new RuntimeException("Error parsing \"LocalProcAddressCallingConvention\" command at line " + lineNo +
- " in file \"" + filename + "\"", e);
+
+ protected void readLocalProcAddressCallingConvention(StringTokenizer tok, String filename, int lineNo) throws IOException {
+ try {
+ String functionName = tok.nextToken();
+ String callingConvention = tok.nextToken();
+ if (functionName.equals("__ALL__")) {
+ localProcAddressCallingConvention4All = callingConvention;
+ } else {
+ localProcAddressCallingConventionMap.put(functionName, callingConvention);
+ }
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"LocalProcAddressCallingConvention\" command at line " + lineNo
+ + " in file \"" + filename + "\"", e);
+ }
}
- }
-
- private static ConvNode makeConverter(Iterator/*<String>*/ iter) {
- List/*<ConvNode>*/ result = new ArrayList/*<ConvNode>*/();
- while (iter.hasNext()) {
- String str = (String) iter.next();
- if (str.equals("$")) {
- String command = (String) iter.next();
- String openParen = (String) iter.next();
- if (!openParen.equals("(")) {
- throw new NoSuchElementException("Expected \"(\"");
+
+ private static ConvNode makeConverter(Iterator<String> iter) {
+ List<ConvNode> result = new ArrayList<ConvNode>();
+
+ while (iter.hasNext()) {
+ String str = iter.next();
+ if (str.equals("$")) {
+ String command = iter.next();
+ String openParen = iter.next();
+ if (!openParen.equals("(")) {
+ throw new NoSuchElementException("Expected \"(\"");
+ }
+ boolean uppercase = false;
+ if (command.equalsIgnoreCase("UPPERCASE")) {
+ uppercase = true;
+ } else if (!command.equalsIgnoreCase("LOWERCASE")) {
+ throw new NoSuchElementException("Unknown ProcAddressNameExpr command \"" + command + "\"");
+ }
+ result.add(new CaseNode(uppercase, makeConverter(iter)));
+ } else if (str.equals(")")) {
+ // Fall through and return
+ } else if (str.indexOf('{') >= 0) {
+ result.add(new FormatNode(str));
+ } else {
+ result.add(new ConstStringNode(str));
+ }
}
- boolean uppercase = false;
- if (command.equalsIgnoreCase("UPPERCASE")) {
- uppercase = true;
- } else if (!command.equalsIgnoreCase("LOWERCASE")) {
- throw new NoSuchElementException("Unknown ProcAddressNameExpr command \"" + command + "\"");
+ if (result.isEmpty()) {
+ return null;
+ } else if (result.size() == 1) {
+ return result.get(0);
+ } else {
+ return new ConcatNode(result);
}
- result.add(new CaseNode(uppercase, makeConverter(iter)));
- } else if (str.equals(")")) {
- // Fall through and return
- } else if (str.indexOf('{') >= 0) {
- result.add(new FormatNode(str));
- } else {
- result.add(new ConstStringNode(str));
- }
}
- if (result.size() == 0) {
- return null;
- } else if (result.size() == 1) {
- return (ConvNode) result.get(0);
- } else {
- return new ConcatNode(result);
+
+ /** Helper class for converting a function name to the typedef'ed
+ function pointer name */
+ static abstract class ConvNode {
+ abstract String convert(String funcName);
}
- }
- /** Helper class for converting a function name to the typedef'ed
- function pointer name */
- static abstract class ConvNode {
- abstract String convert(String funcName);
- }
+ static class FormatNode extends ConvNode {
+
+ private MessageFormat msgFmt;
- static class FormatNode extends ConvNode {
- private MessageFormat msgFmt;
+ FormatNode(String fmt) {
+ msgFmt = new MessageFormat(fmt);
+ }
- FormatNode(String fmt) {
- msgFmt = new MessageFormat(fmt);
+ String convert(String funcName) {
+ StringBuffer buf = new StringBuffer();
+ msgFmt.format(new Object[]{funcName}, buf, null);
+ return buf.toString();
+ }
}
- String convert(String funcName) {
- StringBuffer buf = new StringBuffer();
- msgFmt.format(new Object[] { funcName }, buf, null);
- return buf.toString();
+ static class ConstStringNode extends ConvNode {
+
+ private String str;
+
+ ConstStringNode(String str) {
+ this.str = str;
+ }
+
+ String convert(String funcName) {
+ return str;
+ }
}
- }
- static class ConstStringNode extends ConvNode {
- private String str;
+ static class ConcatNode extends ConvNode {
- ConstStringNode(String str) {
- this.str = str;
+ private List<ConvNode> children;
+
+ ConcatNode(List<ConvNode> children) {
+ this.children = children;
+ }
+
+ String convert(String funcName) {
+ StringBuilder res = new StringBuilder();
+ for (ConvNode node : children) {
+ res.append(node.convert(funcName));
+ }
+ return res.toString();
+ }
}
- String convert(String funcName) {
- return str;
+ static class CaseNode extends ConvNode {
+
+ private boolean upperCase;
+ private ConvNode child;
+
+ CaseNode(boolean upperCase, ConvNode child) {
+ this.upperCase = upperCase;
+ this.child = child;
+ }
+
+ public String convert(String funcName) {
+ if (upperCase) {
+ return child.convert(funcName).toUpperCase();
+ } else {
+ return child.convert(funcName).toLowerCase();
+ }
+ }
}
- }
- static class ConcatNode extends ConvNode {
- private List/*<ConvNode>*/ children;
+ public boolean emitProcAddressTable() {
+ return emitProcAddressTable;
+ }
- ConcatNode(List/*<ConvNode>*/ children) {
- this.children = children;
+ public String tableClassPackage() {
+ return tableClassPackage;
}
- String convert(String funcName) {
- StringBuffer res = new StringBuffer();
- for (Iterator iter = children.iterator(); iter.hasNext(); ) {
- ConvNode node = (ConvNode) iter.next();
- res.append(node.convert(funcName));
- }
- return res.toString();
+ public String tableClassName() {
+ return tableClassName;
}
- }
- static class CaseNode extends ConvNode {
- private boolean upperCase;
- private ConvNode child;
+ public boolean skipProcAddressGen(String name) {
+ return skipProcAddressGen.contains(name);
+ }
- CaseNode(boolean upperCase, ConvNode child) {
- this.upperCase = upperCase;
- this.child = child;
+ public boolean isForceProcAddressGen4All() {
+ return forceProcAddressGen4All;
}
- public String convert(String funcName) {
- if (upperCase) {
- return child.convert(funcName).toUpperCase();
- } else {
- return child.convert(funcName).toLowerCase();
- }
+ public List<String> getForceProcAddressGen() {
+ return forceProcAddressGen;
}
- }
-
- public boolean emitProcAddressTable() { return emitProcAddressTable; }
- public String tableClassPackage() { return tableClassPackage; }
- public String tableClassName() { return tableClassName; }
- public boolean skipProcAddressGen (String name) { return skipProcAddressGen.contains(name); }
- public boolean isForceProcAddressGen4All() { return forceProcAddressGen4All; }
- public List getForceProcAddressGen() { return forceProcAddressGen; }
- public String getProcAddressTableExpr() {
- if (getProcAddressTableExpr == null) {
- throw new RuntimeException("GetProcAddressTableExpr was not defined in .cfg file");
+
+ public String getProcAddressTableExpr() {
+ if (getProcAddressTableExpr == null) {
+ throw new RuntimeException("GetProcAddressTableExpr was not defined in .cfg file");
+ }
+ return getProcAddressTableExpr;
}
- return getProcAddressTableExpr;
- }
- public String convertToFunctionPointerName(String funcName) {
- if (procAddressNameConverter == null) {
- throw new RuntimeException("ProcAddressNameExpr was not defined in .cfg file");
+
+ public String convertToFunctionPointerName(String funcName) {
+ if (procAddressNameConverter == null) {
+ throw new RuntimeException("ProcAddressNameExpr was not defined in .cfg file");
+ }
+ return procAddressNameConverter.convert(funcName);
}
- return procAddressNameConverter.convert(funcName);
- }
- public boolean forceProcAddressGen(String funcName) {
- return forceProcAddressGen4All || forceProcAddressGenSet.contains(funcName);
- }
+ public boolean forceProcAddressGen(String funcName) {
+ return forceProcAddressGen4All || forceProcAddressGenSet.contains(funcName);
+ }
- public void addForceProcAddressGen(String funcName) {
+ public void addForceProcAddressGen(String funcName) {
forceProcAddressGen.add(funcName);
forceProcAddressGenSet.add(funcName);
- }
-
- public void addLocalProcAddressCallingConvention(String funcName, String callingConvention) {
- localProcAddressCallingConventionMap.put(funcName, callingConvention);
- }
-
- public String getLocalProcAddressCallingConvention(String funcName) {
- if(isLocalProcAddressCallingConvention4All()) return getLocalProcAddressCallingConvention4All();
- return (String) localProcAddressCallingConventionMap.get(funcName);
- }
- public boolean isLocalProcAddressCallingConvention4All() { return localProcAddressCallingConvention4All!=null; }
- public String getLocalProcAddressCallingConvention4All() { return localProcAddressCallingConvention4All; }
+ }
+
+ public void addLocalProcAddressCallingConvention(String funcName, String callingConvention) {
+ localProcAddressCallingConventionMap.put(funcName, callingConvention);
+ }
+
+ public String getLocalProcAddressCallingConvention(String funcName) {
+ if (isLocalProcAddressCallingConvention4All()) {
+ return getLocalProcAddressCallingConvention4All();
+ }
+ return localProcAddressCallingConventionMap.get(funcName);
+ }
+
+ public boolean isLocalProcAddressCallingConvention4All() {
+ return localProcAddressCallingConvention4All != null;
+ }
+
+ public String getLocalProcAddressCallingConvention4All() {
+ return localProcAddressCallingConvention4All;
+ }
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
index 98ff860..c49e239 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
@@ -36,7 +36,6 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.procaddress;
import java.io.*;
@@ -51,351 +50,334 @@ import com.jogamp.gluegen.runtime.*;
* and Java code to allow dynamic lookups of the C entry points
* associated with the Java methods.
*/
-
-public class ProcAddressEmitter extends JavaEmitter
-{
- public static final String PROCADDRESS_VAR_PREFIX = ProcAddressHelper.PROCADDRESS_VAR_PREFIX;
- protected static final String WRAP_PREFIX = "dispatch_";
- private TypeDictionary typedefDictionary;
- protected PrintWriter tableWriter;
- protected Set emittedTableEntries;
- protected String tableClassPackage;
- protected String tableClassName;
-
- public void beginFunctions(TypeDictionary typedefDictionary,
- TypeDictionary structDictionary,
- Map canonMap) throws Exception
- {
- this.typedefDictionary = typedefDictionary;
-
- if (getProcAddressConfig().emitProcAddressTable())
- {
- beginProcAddressTable();
+public class ProcAddressEmitter extends JavaEmitter {
+
+ public static final String PROCADDRESS_VAR_PREFIX = ProcAddressHelper.PROCADDRESS_VAR_PREFIX;
+ protected static final String WRAP_PREFIX = "dispatch_";
+ private TypeDictionary typedefDictionary;
+ protected PrintWriter tableWriter;
+ protected Set<String> emittedTableEntries;
+ protected String tableClassPackage;
+ protected String tableClassName;
+
+ @Override
+ public void beginFunctions(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) throws Exception {
+ this.typedefDictionary = typedefDictionary;
+
+ if (getProcAddressConfig().emitProcAddressTable()) {
+ beginProcAddressTable();
+ }
+ super.beginFunctions(typedefDictionary, structDictionary, canonMap);
}
- super.beginFunctions(typedefDictionary, structDictionary, canonMap);
- }
-
- public void endFunctions() throws Exception
- {
- if (getProcAddressConfig().emitProcAddressTable())
- {
- endProcAddressTable();
+
+ @Override
+ public void endFunctions() throws Exception {
+ if (getProcAddressConfig().emitProcAddressTable()) {
+ endProcAddressTable();
+ }
+ super.endFunctions();
}
- super.endFunctions();
- }
-
- public void beginStructs(TypeDictionary typedefDictionary,
- TypeDictionary structDictionary,
- Map canonMap) throws Exception {
- super.beginStructs(typedefDictionary, structDictionary, canonMap);
- }
-
- public String runtimeExceptionType() {
- return getConfig().runtimeExceptionType();
- }
-
- public String unsupportedExceptionType() {
- return getConfig().unsupportedExceptionType();
- }
-
- protected JavaConfiguration createConfig() {
- return new ProcAddressConfiguration();
- }
-
- protected List generateMethodBindingEmitters(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception {
- return generateMethodBindingEmittersImpl(methodBindingSet, sym);
- }
-
- protected boolean needsModifiedEmitters(FunctionSymbol sym) {
- if (!needsProcAddressWrapper(sym) ||
- getConfig().isUnimplemented(getAliasedSymName(sym))) {
- return false;
+
+ @Override
+ public void beginStructs(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) throws Exception {
+ super.beginStructs(typedefDictionary, structDictionary, canonMap);
}
- return true;
- }
+ public String runtimeExceptionType() {
+ return getConfig().runtimeExceptionType();
+ }
- private List generateMethodBindingEmittersImpl(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception {
- List defaultEmitters = super.generateMethodBindingEmitters(methodBindingSet, sym);
+ public String unsupportedExceptionType() {
+ return getConfig().unsupportedExceptionType();
+ }
- // 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.isEmpty())
- {
- return defaultEmitters;
+ @Override
+ protected JavaConfiguration createConfig() {
+ return new ProcAddressConfiguration();
}
-
- // Don't do anything special if this symbol doesn't require
- // modifications
- if (!needsModifiedEmitters(sym))
- {
- return defaultEmitters;
+
+ @Override
+ protected List<? extends FunctionEmitter> generateMethodBindingEmitters(Set<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception {
+ return generateMethodBindingEmittersImpl(methodBindingSet, sym);
}
- ArrayList modifiedEmitters = new ArrayList(defaultEmitters.size());
+ protected boolean needsModifiedEmitters(FunctionSymbol sym) {
+ if (!needsProcAddressWrapper(sym)
+ || getConfig().isUnimplemented(getAliasedSymName(sym))) {
+ return false;
+ }
- if (needsProcAddressWrapper(sym)) {
- if (getProcAddressConfig().emitProcAddressTable()) {
- // emit an entry in the GL proc address table for this method.
- emitProcAddressTableEntryForString(getAliasedSymName(sym));
- }
+ return true;
}
-
- for (Iterator iter = defaultEmitters.iterator(); iter.hasNext(); )
- {
- FunctionEmitter emitter = (FunctionEmitter) iter.next();
- if (emitter instanceof JavaMethodBindingEmitter)
- {
- generateModifiedEmitters((JavaMethodBindingEmitter) emitter, modifiedEmitters);
- }
- else if (emitter instanceof CMethodBindingEmitter)
- {
- generateModifiedEmitters((CMethodBindingEmitter) emitter, modifiedEmitters);
- }
- else
- {
- throw new RuntimeException("Unexpected emitter type: " +
- emitter.getClass().getName());
- }
- }
-
- return modifiedEmitters;
- }
-
- /**
- * Returns the name of the typedef for a pointer to the function
- * represented by the argument as defined by the ProcAddressNameExpr
- * in the .cfg file. For example, in the OpenGL headers, if the
- * argument is the function "glFuncName", the value returned will be
- * "PFNGLFUNCNAMEPROC". This returns a valid string regardless of
- * whether or not the typedef is actually defined.
- */
- protected String getFunctionPointerTypedefName(FunctionSymbol sym) {
- return getProcAddressConfig().convertToFunctionPointerName(sym.getName());
- }
-
- //----------------------------------------------------------------------
- // Internals only below this point
- //
-
- protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List emitters) {
- if (getConfig().manuallyImplement(baseJavaEmitter.getName())) {
- // User will provide Java-side implementation of this routine;
- // pass through any emitters which will produce signatures for
- // it unmodified
- emitters.add(baseJavaEmitter);
- return;
+
+ private List<? extends FunctionEmitter> generateMethodBindingEmittersImpl(Set<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception {
+ List<? extends FunctionEmitter> 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
+ // direction that matched the symbol's name).
+ if (defaultEmitters.isEmpty()) {
+ return defaultEmitters;
+ }
+
+ // Don't do anything special if this symbol doesn't require
+ // modifications
+ if (!needsModifiedEmitters(sym)) {
+ return defaultEmitters;
+ }
+
+ ArrayList<FunctionEmitter> modifiedEmitters = new ArrayList<FunctionEmitter>(defaultEmitters.size());
+
+ if (needsProcAddressWrapper(sym)) {
+ if (getProcAddressConfig().emitProcAddressTable()) {
+ // emit an entry in the GL proc address table for this method.
+ emitProcAddressTableEntryForString(getAliasedSymName(sym));
+ }
+ }
+ for (FunctionEmitter emitter : defaultEmitters) {
+ if (emitter instanceof JavaMethodBindingEmitter) {
+ generateModifiedEmitters((JavaMethodBindingEmitter)emitter, modifiedEmitters);
+ } else if (emitter instanceof CMethodBindingEmitter) {
+ generateModifiedEmitters((CMethodBindingEmitter) emitter, modifiedEmitters);
+ } else {
+ throw new RuntimeException("Unexpected emitter type: " + emitter.getClass().getName());
+ }
+ }
+
+ return modifiedEmitters;
}
-
- // See whether we need a proc address entry for this one
- boolean callThroughProcAddress = needsProcAddressWrapper(baseJavaEmitter.getBinding().getCSymbol());
-
- ProcAddressJavaMethodBindingEmitter emitter =
- new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
- callThroughProcAddress,
- getProcAddressConfig().getProcAddressTableExpr(),
- baseJavaEmitter.isForImplementingMethodCall(),
- this);
- emitters.add(emitter);
-
- // If this emitter doesn't have a body (i.e., is a direct native
- // call with no intervening argument processing), we need to force
- // it to emit a body, and produce another one to act as the entry
- // point
- // FIXME: the negative test against the PRIVATE modifier is a
- // nasty hack to prevent the ProcAddressJavaMethodBindingEmitter
- // from incorrectly introducing method bodies to the private
- // native implementing methods; want this to work at least for
- // public and package-private methods
- if (baseJavaEmitter.signatureOnly() &&
- !baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.PRIVATE) &&
- baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.NATIVE) &&
- callThroughProcAddress) {
- emitter.setEmitBody(true);
- emitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
- emitter = new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
- callThroughProcAddress,
- getProcAddressConfig().getProcAddressTableExpr(),
- true,
- this);
- emitter.setForImplementingMethodCall(true);
- emitters.add(emitter);
+
+ /**
+ * Returns the name of the typedef for a pointer to the function
+ * represented by the argument as defined by the ProcAddressNameExpr
+ * in the .cfg file. For example, in the OpenGL headers, if the
+ * argument is the function "glFuncName", the value returned will be
+ * "PFNGLFUNCNAMEPROC". This returns a valid string regardless of
+ * whether or not the typedef is actually defined.
+ */
+ protected String getFunctionPointerTypedefName(FunctionSymbol sym) {
+ return getProcAddressConfig().convertToFunctionPointerName(sym.getName());
}
- }
-
- protected void generateModifiedEmitters(CMethodBindingEmitter baseCEmitter, List emitters)
- {
- // See whether we need a proc address entry for this one
- boolean callThroughProcAddress = needsProcAddressWrapper(baseCEmitter.getBinding().getCSymbol());
- boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(baseCEmitter.getBinding().getCSymbol().getName());
- String forcedCallingConvention = null;
- if (forceProcAddress) {
- forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(baseCEmitter.getBinding().getCSymbol().getName());
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List<FunctionEmitter> emitters) {
+ if (getConfig().manuallyImplement(baseJavaEmitter.getName())) {
+ // User will provide Java-side implementation of this routine;
+ // pass through any emitters which will produce signatures for
+ // it unmodified
+ emitters.add(baseJavaEmitter);
+ return;
+ }
+
+ // See whether we need a proc address entry for this one
+ boolean callThroughProcAddress = needsProcAddressWrapper(baseJavaEmitter.getBinding().getCSymbol());
+
+ ProcAddressJavaMethodBindingEmitter emitter =
+ new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
+ callThroughProcAddress,
+ getProcAddressConfig().getProcAddressTableExpr(),
+ baseJavaEmitter.isForImplementingMethodCall(),
+ this);
+ emitters.add(emitter);
+
+ // If this emitter doesn't have a body (i.e., is a direct native
+ // call with no intervening argument processing), we need to force
+ // it to emit a body, and produce another one to act as the entry
+ // point
+ // FIXME: the negative test against the PRIVATE modifier is a
+ // nasty hack to prevent the ProcAddressJavaMethodBindingEmitter
+ // from incorrectly introducing method bodies to the private
+ // native implementing methods; want this to work at least for
+ // public and package-private methods
+ if (baseJavaEmitter.signatureOnly()
+ && !baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.PRIVATE)
+ && baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.NATIVE)
+ && callThroughProcAddress) {
+ emitter.setEmitBody(true);
+ emitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
+ emitter = new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
+ callThroughProcAddress,
+ getProcAddressConfig().getProcAddressTableExpr(),
+ true,
+ this);
+ emitter.setForImplementingMethodCall(true);
+ emitters.add(emitter);
+ }
}
- // Note that we don't care much about the naming of the C argument
- // variables so to keep things simple we ignore the buffer object
- // property for the binding
-
- // The C-side JNI binding for this particular function will have an
- // extra final argument, which is the address (the OpenGL procedure
- // address) of the function it needs to call
- ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter(baseCEmitter,
- callThroughProcAddress,
- forceProcAddress,
- forcedCallingConvention,
- this);
- MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression();
- if (exp != null) {
- res.setReturnValueCapacityExpression(exp);
+
+ protected void generateModifiedEmitters(CMethodBindingEmitter baseCEmitter, List<FunctionEmitter> emitters) {
+ // See whether we need a proc address entry for this one
+ boolean callThroughProcAddress = needsProcAddressWrapper(baseCEmitter.getBinding().getCSymbol());
+ boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(baseCEmitter.getBinding().getCSymbol().getName());
+ String forcedCallingConvention = null;
+ if (forceProcAddress) {
+ forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(baseCEmitter.getBinding().getCSymbol().getName());
+ }
+ // Note that we don't care much about the naming of the C argument
+ // variables so to keep things simple we ignore the buffer object
+ // property for the binding
+
+ // The C-side JNI binding for this particular function will have an
+ // extra final argument, which is the address (the OpenGL procedure
+ // address) of the function it needs to call
+ ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter(baseCEmitter,
+ callThroughProcAddress,
+ forceProcAddress,
+ forcedCallingConvention,
+ this);
+ MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression();
+ if (exp != null) {
+ res.setReturnValueCapacityExpression(exp);
+ }
+ emitters.add(res);
}
- 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 = getAliasedSymName(sym);
-
- ProcAddressConfiguration config = getProcAddressConfig();
-
- // We should only generate code to call through a function pointer
- // if the symbol has an associated function pointer typedef.
- String funcPointerTypedefName = getFunctionPointerTypedefName(sym);
- boolean shouldWrap = typedefDictionary.containsKey(funcPointerTypedefName);
- //System.err.println(funcPointerTypedefName + " defined: " + shouldWrap);
-
- if (config.skipProcAddressGen(symName)) {
- shouldWrap = false;
+
+ private String getAliasedSymName(FunctionSymbol sym) {
+ String symName = getConfig().getJavaSymbolRename(sym.getName());
+ if (null == symName) {
+ symName = sym.getName();
+ }
+ return symName;
}
-
- if (config.forceProcAddressGen(symName)) {
- shouldWrap = true;
+
+ protected boolean needsProcAddressWrapper(FunctionSymbol sym) {
+ String symName = getAliasedSymName(sym);
+
+ ProcAddressConfiguration config = getProcAddressConfig();
+
+ // We should only generate code to call through a function pointer
+ // if the symbol has an associated function pointer typedef.
+ String funcPointerTypedefName = getFunctionPointerTypedefName(sym);
+ boolean shouldWrap = typedefDictionary.containsKey(funcPointerTypedefName);
+ //System.err.println(funcPointerTypedefName + " defined: " + shouldWrap);
+
+ if (config.skipProcAddressGen(symName)) {
+ shouldWrap = false;
+ }
+
+ if (config.forceProcAddressGen(symName)) {
+ shouldWrap = true;
+ }
+
+ if (shouldWrap) {
+ // Hoist argument names from function pointer if not supplied in prototype
+ Type funcPointerType = typedefDictionary.get(funcPointerTypedefName);
+ if (funcPointerType != null) {
+ FunctionType typedef = funcPointerType.asPointer().getTargetType().asFunction();
+ FunctionType fun = sym.getType();
+ int numarg = typedef.getNumArguments();
+ for (int i = 0; i < numarg; i++) {
+ if (fun.getArgumentName(i) == null) {
+ fun.setArgumentName(i, typedef.getArgumentName(i));
+ }
+ }
+ }
+ }
+
+ return shouldWrap;
}
-
- if (shouldWrap)
- {
- // Hoist argument names from function pointer if not supplied in prototype
- Type funcPointerType = typedefDictionary.get(funcPointerTypedefName);
- if (funcPointerType != null) {
- FunctionType typedef = funcPointerType.asPointer().getTargetType().asFunction();
- FunctionType fun = sym.getType();
- int numarg = typedef.getNumArguments();
- for (int i =0; i < numarg; i++) {
- if (fun.getArgumentName(i) == null)
- fun.setArgumentName(i,typedef.getArgumentName(i));
- }
- }
+
+ protected void beginProcAddressTable() throws Exception {
+ tableClassPackage = getProcAddressConfig().tableClassPackage();
+ tableClassName = getProcAddressConfig().tableClassName();
+
+ // Table defaults to going into the impl directory unless otherwise overridden
+ String implPackageName = tableClassPackage;
+ if (implPackageName == null) {
+ implPackageName = getImplPackageName();
+ }
+ String jImplRoot =
+ getJavaOutputDir() + File.separator
+ + CodeGenUtils.packageAsPath(implPackageName);
+
+ tableWriter = openFile(jImplRoot + File.separator + tableClassName + ".java");
+ emittedTableEntries = new HashSet<String>();
+
+ CodeGenUtils.emitAutogeneratedWarning(tableWriter, this);
+
+ tableWriter.println("package " + implPackageName + ";");
+ tableWriter.println();
+ for (String imporT : getConfig().imports()) {
+ tableWriter.println("import " + imporT + ";");
+ }
+ tableWriter.println();
+
+ tableWriter.println("/**");
+ tableWriter.println(" * This table is a cache of pointers to the dynamically-linkable C");
+ tableWriter.println(" * functions this autogenerated Java binding has exposed. Some");
+ tableWriter.println(" * libraries such as OpenGL, OpenAL and others define function pointer");
+ tableWriter.println(" * signatures rather than statically linkable entry points for the");
+ tableWriter.println(" * purposes of being able to query at run-time whether a particular");
+ tableWriter.println(" * extension is available. This table acts as a cache of these");
+ tableWriter.println(" * function pointers. Each function pointer is typically looked up at");
+ tableWriter.println(" * run-time by a platform-dependent mechanism such as dlsym(),");
+ tableWriter.println(" * wgl/glXGetProcAddress(), or alGetProcAddress(). The associated");
+ tableWriter.println(" * autogenerated Java and C code accesses the fields in this table to");
+ tableWriter.println(" * call the various functions. If the field containing the function");
+ 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 + " implements com.jogamp.gluegen.runtime.ProcAddressTable");
+ tableWriter.println("{");
+
+ for (String string : getProcAddressConfig().getForceProcAddressGen()) {
+ emitProcAddressTableEntryForString(string);
+ }
}
-
- return shouldWrap;
- }
-
- protected void beginProcAddressTable() throws Exception
- {
- tableClassPackage = getProcAddressConfig().tableClassPackage();
- tableClassName = getProcAddressConfig().tableClassName();
-
- // Table defaults to going into the impl directory unless otherwise overridden
- String implPackageName = tableClassPackage;
- if (implPackageName == null) {
- implPackageName = getImplPackageName();
+
+ protected void endProcAddressTable() throws Exception {
+ PrintWriter w = tableWriter;
+
+ w.println(" /**");
+ w.println(" * This is a convenience method to get (by name) the native function");
+ w.println(" * pointer for a given function. It lets you avoid having to");
+ w.println(" * manually compute the &quot;" + PROCADDRESS_VAR_PREFIX + " + ");
+ w.println(" * &lt;functionName&gt;&quot; member variable name and look it up via");
+ w.println(" * reflection; it also will throw an exception if you try to get the");
+ w.println(" * address of an unknown function, or one that is statically linked");
+ w.println(" * and therefore does not have a function pointer in this table.");
+ w.println(" *");
+ w.println(" * @throws RuntimeException if the function pointer was not found in");
+ w.println(" * this table, either because the function was unknown or because");
+ w.println(" * it was statically linked.");
+ w.println(" */");
+ w.println(" public long getAddressFor(String functionName) {");
+ w.println(" String addressFieldName = " + getProcAddressConfig().gluegenRuntimePackage() + ".ProcAddressHelper.PROCADDRESS_VAR_PREFIX + functionName;");
+ w.println(" try { ");
+ w.println(" java.lang.reflect.Field addressField = getClass().getField(addressFieldName);");
+ w.println(" return addressField.getLong(this);");
+ w.println(" } catch (Exception e) {");
+ w.println(" // The user is calling a bogus function or one which is not");
+ w.println(" // runtime linked");
+ w.println(" throw new RuntimeException(");
+ w.println(" \"WARNING: Address query failed for \\\"\" + functionName +");
+ w.println(" \"\\\"; it's either statically linked or is not a known \" +");
+ w.println(" \"function\", e);");
+ w.println(" } ");
+ w.println(" }");
+
+ w.println("} // end of class " + tableClassName);
+ w.flush();
+ w.close();
}
- String jImplRoot =
- getJavaOutputDir() + File.separator +
- CodeGenUtils.packageAsPath(implPackageName);
-
- tableWriter = openFile(jImplRoot + File.separator + tableClassName + ".java");
- emittedTableEntries = new HashSet();
-
- CodeGenUtils.emitAutogeneratedWarning(tableWriter, this);
-
- tableWriter.println("package " + implPackageName + ";");
- tableWriter.println();
- for (Iterator iter = getConfig().imports().iterator(); iter.hasNext(); ) {
- tableWriter.println("import " + ((String) iter.next()) + ";");
+
+ 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(";");
}
- tableWriter.println();
-
- tableWriter.println("/**");
- tableWriter.println(" * This table is a cache of pointers to the dynamically-linkable C");
- tableWriter.println(" * functions this autogenerated Java binding has exposed. Some");
- tableWriter.println(" * libraries such as OpenGL, OpenAL and others define function pointer");
- tableWriter.println(" * signatures rather than statically linkable entry points for the");
- tableWriter.println(" * purposes of being able to query at run-time whether a particular");
- tableWriter.println(" * extension is available. This table acts as a cache of these");
- tableWriter.println(" * function pointers. Each function pointer is typically looked up at");
- tableWriter.println(" * run-time by a platform-dependent mechanism such as dlsym(),");
- tableWriter.println(" * wgl/glXGetProcAddress(), or alGetProcAddress(). The associated");
- tableWriter.println(" * autogenerated Java and C code accesses the fields in this table to");
- tableWriter.println(" * call the various functions. If the field containing the function");
- 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 + " implements com.jogamp.gluegen.runtime.ProcAddressTable");
- tableWriter.println("{");
-
- for (Iterator iter = getProcAddressConfig().getForceProcAddressGen().iterator(); iter.hasNext(); ) {
- emitProcAddressTableEntryForString((String) iter.next());
+
+ protected ProcAddressConfiguration getProcAddressConfig() {
+ return (ProcAddressConfiguration) getConfig();
}
- }
-
- protected void endProcAddressTable() throws Exception
- {
- PrintWriter w = tableWriter;
-
- w.println(" /**");
- w.println(" * This is a convenience method to get (by name) the native function");
- w.println(" * pointer for a given function. It lets you avoid having to");
- w.println(" * manually compute the &quot;" + PROCADDRESS_VAR_PREFIX + " + ");
- w.println(" * &lt;functionName&gt;&quot; member variable name and look it up via");
- w.println(" * reflection; it also will throw an exception if you try to get the");
- w.println(" * address of an unknown function, or one that is statically linked");
- w.println(" * and therefore does not have a function pointer in this table.");
- w.println(" *");
- w.println(" * @throws RuntimeException if the function pointer was not found in");
- w.println(" * this table, either because the function was unknown or because");
- w.println(" * it was statically linked.");
- w.println(" */");
- w.println(" public long getAddressFor(String functionName) {");
- w.println(" String addressFieldName = " + getProcAddressConfig().gluegenRuntimePackage() + ".ProcAddressHelper.PROCADDRESS_VAR_PREFIX + functionName;");
- w.println(" try { ");
- w.println(" java.lang.reflect.Field addressField = getClass().getField(addressFieldName);");
- w.println(" return addressField.getLong(this);");
- w.println(" } catch (Exception e) {");
- w.println(" // The user is calling a bogus function or one which is not");
- w.println(" // runtime linked");
- w.println(" throw new RuntimeException(");
- w.println(" \"WARNING: Address query failed for \\\"\" + functionName +");
- w.println(" \"\\\"; it's either statically linked or is not a known \" +");
- w.println(" \"function\", e);");
- w.println(" } ");
- w.println(" }");
-
- w.println("} // end of class " + tableClassName);
- w.flush();
- w.close();
- }
-
- 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(";");
- }
-
- protected ProcAddressConfiguration getProcAddressConfig() {
- return (ProcAddressConfiguration) getConfig();
- }
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java
index 2dda752..5a30ee5 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java
@@ -36,118 +36,115 @@
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-
package com.sun.gluegen.procaddress;
import java.io.*;
-import java.util.*;
import com.sun.gluegen.*;
-import com.sun.gluegen.cgram.types.*;
/** A specialization of JavaMethodBindingEmitter with knowledge of how
- to call through a function pointer. */
-
+to call through a function pointer. */
public class ProcAddressJavaMethodBindingEmitter extends JavaMethodBindingEmitter {
- private final CommentEmitter commentEmitterForWrappedMethod =
- new WrappedMethodCommentEmitter();
-
- protected boolean callThroughProcAddress;
- protected String getProcAddressTableExpr;
- protected boolean changeNameAndArguments;
- protected ProcAddressEmitter emitter;
-
- public ProcAddressJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap,
- boolean callThroughProcAddress,
- String getProcAddressTableExpr,
- boolean changeNameAndArguments,
- ProcAddressEmitter emitter) {
- super(methodToWrap);
- this.callThroughProcAddress = callThroughProcAddress;
- this.getProcAddressTableExpr = getProcAddressTableExpr;
- this.changeNameAndArguments = changeNameAndArguments;
- this.emitter = emitter;
- if (callThroughProcAddress) {
- setCommentEmitter(new WrappedMethodCommentEmitter());
+
+ protected boolean callThroughProcAddress;
+ protected boolean changeNameAndArguments;
+
+ protected String getProcAddressTableExpr;
+ protected ProcAddressEmitter emitter;
+
+ public ProcAddressJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, boolean callThroughProcAddress,
+ String getProcAddressTableExpr, boolean changeNameAndArguments, ProcAddressEmitter emitter) {
+
+ super(methodToWrap);
+
+ this.callThroughProcAddress = callThroughProcAddress;
+ this.getProcAddressTableExpr = getProcAddressTableExpr;
+ this.changeNameAndArguments = changeNameAndArguments;
+ this.emitter = emitter;
+
+ if (callThroughProcAddress) {
+ setCommentEmitter(new WrappedMethodCommentEmitter());
+ }
+
+ if (methodToWrap.getBinding().hasContainingType()) {
+ throw new IllegalArgumentException(
+ "Cannot create proc. address wrapper; method has containing type: \""
+ + methodToWrap.getBinding() + "\"");
+ }
}
- if (methodToWrap.getBinding().hasContainingType())
- {
- throw new IllegalArgumentException(
- "Cannot create proc. address wrapper; method has containing type: \"" +
- methodToWrap.getBinding() + "\"");
+ public ProcAddressJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap) {
+ this(methodToWrap, methodToWrap.callThroughProcAddress, methodToWrap.getProcAddressTableExpr,
+ methodToWrap.changeNameAndArguments, methodToWrap.emitter);
}
- }
-
- public ProcAddressJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap) {
- this(methodToWrap,
- methodToWrap.callThroughProcAddress,
- methodToWrap.getProcAddressTableExpr,
- methodToWrap.changeNameAndArguments,
- methodToWrap.emitter);
- }
-
- public String getName() {
- String res = super.getName();
- if (changeNameAndArguments) {
- return ProcAddressEmitter.WRAP_PREFIX + res;
+
+ @Override
+ public String getName() {
+ String res = super.getName();
+ if (changeNameAndArguments) {
+ return ProcAddressEmitter.WRAP_PREFIX + res;
+ }
+ return res;
}
- return res;
- }
-
- protected int emitArguments(PrintWriter writer) {
- int numEmitted = super.emitArguments(writer);
- if (callThroughProcAddress) {
- if (changeNameAndArguments) {
- if (numEmitted > 0) {
- writer.print(", ");
+
+ @Override
+ protected int emitArguments(PrintWriter writer) {
+ int numEmitted = super.emitArguments(writer);
+ if (callThroughProcAddress) {
+ if (changeNameAndArguments) {
+ if (numEmitted > 0) {
+ writer.print(", ");
+ }
+
+ writer.print("long procAddress");
+ ++numEmitted;
+ }
}
- writer.print("long procAddress");
- ++numEmitted;
- }
+ return numEmitted;
}
-
- return numEmitted;
- }
-
- protected String getImplMethodName() {
- String name = super.getImplMethodName();
- if (callThroughProcAddress) {
- return ProcAddressEmitter.WRAP_PREFIX + name;
+
+ @Override
+ protected String getImplMethodName() {
+ String name = super.getImplMethodName();
+ if (callThroughProcAddress) {
+ return ProcAddressEmitter.WRAP_PREFIX + name;
+ }
+ return name;
}
- return name;
- }
-
- protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) {
- super.emitPreCallSetup(binding, writer);
-
- if (callThroughProcAddress) {
- String procAddressVariable =
- ProcAddressEmitter.PROCADDRESS_VAR_PREFIX + binding.getName();
- writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";");
- writer.println(" if (__addr_ == 0) {");
- writer.println(" throw new " + emitter.unsupportedExceptionType() + "(\"Method \\\"" + binding.getName() + "\\\" not available\");");
- writer.println(" }");
+
+ @Override
+ protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) {
+ super.emitPreCallSetup(binding, writer);
+
+ if (callThroughProcAddress) {
+ String procAddressVariable = ProcAddressEmitter.PROCADDRESS_VAR_PREFIX + binding.getName();
+ writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";");
+ writer.println(" if (__addr_ == 0) {");
+ writer.println(" throw new " + emitter.unsupportedExceptionType() + "(\"Method \\\"" + binding.getName() + "\\\" not available\");");
+ writer.println(" }");
+ }
}
- }
-
- protected int emitCallArguments(MethodBinding binding, PrintWriter writer) {
- int numEmitted = super.emitCallArguments(binding, writer);
- if (callThroughProcAddress) {
- if (numEmitted > 0) {
- writer.print(", ");
- }
- writer.print("__addr_");
- ++numEmitted;
+
+ @Override
+ protected int emitCallArguments(MethodBinding binding, PrintWriter writer) {
+ int numEmitted = super.emitCallArguments(binding, writer);
+ if (callThroughProcAddress) {
+ if (numEmitted > 0) {
+ writer.print(", ");
+ }
+ writer.print("__addr_");
+ ++numEmitted;
+ }
+
+ return numEmitted;
}
- return numEmitted;
- }
+ /** This class emits the comment for the wrapper method */
+ public class WrappedMethodCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter {
- /** This class emits the comment for the wrapper method */
- public class WrappedMethodCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter {
- protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) {
- writer.print("Entry point (through function pointer) to C language function: <br> ");
+ @Override
+ protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) {
+ writer.print("Entry point (through function pointer) to C language function: <br> ");
+ }
}
- }
}