summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-09 02:42:03 +0100
committerSven Gothel <[email protected]>2010-11-09 02:42:03 +0100
commit7865b355bd52958f4b27e42b500e83c52255ef37 (patch)
treecdd887ede9b43f1a3d18527cf9eaabc9627946da /src
parent08a74fb5d45f29f4d77a2713d1ebca4343519eb0 (diff)
Gluegen: Types (stddef/stdint), Header and Predefined Macro Change
Read API doc ad GlueGen.java New predefined types: wchar_t, intptr_t, uintptr_t New reusable headers for gluegen usage: make/stub_includes/gluegen for native usage: make/stub_includes/platform New predefined macro #define __GLUEGEN__ 2
Diffstat (limited to 'src')
-rw-r--r--src/java/com/jogamp/gluegen/GlueGen.java59
-rw-r--r--src/java/com/jogamp/gluegen/cgram/GnuCParser.g3
-rw-r--r--src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g11
-rw-r--r--src/java/com/jogamp/gluegen/cgram/HeaderParser.g3
-rw-r--r--src/java/com/jogamp/gluegen/cgram/StdCParser.g11
-rw-r--r--src/java/com/jogamp/gluegen/pcpp/PCPP.java17
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h11
7 files changed, 99 insertions, 16 deletions
diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java
index f24d0b2..e88538e 100644
--- a/src/java/com/jogamp/gluegen/GlueGen.java
+++ b/src/java/com/jogamp/gluegen/GlueGen.java
@@ -51,21 +51,57 @@ import static java.lang.System.*;
/**
* Glue code generator for C functions and data structures.<br>
- * <br>
+ * <p>
+ * <h4>GlueGen Data Type Mapping</h4>
* Gluegen has build-in types (terminal symbols) for:<br>
* <br>
* <table border="1">
- * <tr><th>type</th> <th>java</th> <th>native-x32</th><th>native-x64</th><th>type</th> <th>signed</th></tr>
- * <tr><th>__int32</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed or unsigned</th></tr>
- * <tr><th>int32_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed</th></tr>
- * <tr><th>uint32_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>unsigned</th></tr>
- * <tr><th>__int64</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>signed or unsigned</th></tr>
- * <tr><th>int64_t</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>signed</th></tr>
- * <tr><th>uint64_t</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th></tr>
- * <tr><th>ptrdiff_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>signed</th></tr>
- * <tr><th>size_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th></tr>
- * </table>
+ * <tr><th>type</th> <th>java</th> <th>native-x32</th><th>native-x64</th><th>type</th> <th>signed</th> <th>origin</th</tr>
+ * <tr><th>__int32</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed or unsigned</th><th>windows</th></tr>
+ * <tr><th>int32_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr>
+ * <tr><th>wchar_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed</th> <th>stddef.h</th></tr>
+ * <tr><th>uint32_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr>
+ * <tr><th>__int64</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>signed or unsigned</th><th>windows</th></tr>
+ * <tr><th>int64_t</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr>
+ * <tr><th>uint64_t</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr>
+ * <tr><th>ptrdiff_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>signed</th> <th>stddef.h</th></tr>
+ * <tr><th>intptr_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr>
+ * <tr><th>size_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th> <th>stddef.h</th></tr>
+ * <tr><th>uintptr_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr>
+ * </table></p>
+ * <p>
+ * <h4>GlueGen Platform Header Files</h4>
+ * GlueGen provides convenient platform headers,<br>
+ * which can be included in your C header files for native compilation and GlueGen code generation.<br>
+ * <br>
+ * Example:<br>
+ * <pre>
+ #include &lt;gluegen_stdint.h&gt;
+ #include &lt;gluegen_stddef.h&gt;
+
+ uint64_t test64;
+ size_t size1;
+ ptrdiff_t ptr1;
+ * </pre>
+ * <br>
+ * To compile this file you have to include the following folder to your compilers system includes, ie <code>-I</code>:<br>
+ * <pre>
+ * gluegen/make/stub_includes/platform
+ * </pre>
+ * <br>
+ * To generate code for this file you have to include the following folder to your GlueGen <code>includeRefid</code> element:<br>
+ * <pre>
+ * gluegen/make/stub_includes/gluegen
+ * </pre></p>
+ * <p>
+ * <h4>GlueGen Pre-Defined Macros</h4>
+ * To identity a GlueGen code generation run, GlueGen defines the following macros:<br>
+ * <pre>
+ #define __GLUEGEN__ 2
+ * </pre>
+ * </p>
*/
+
public class GlueGen implements GlueEmitterControls {
static{
@@ -117,6 +153,7 @@ public class GlueGen implements GlueEmitterControls {
}
preprocessor = new PCPP(includePaths, debug, copyPCPPOutput2Stderr);
+ preprocessor.addDefine("__GLUEGEN__", "2");
preprocessor.setOut(outStream);
preprocessor.run(reader, filename);
diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g b/src/java/com/jogamp/gluegen/cgram/GnuCParser.g
index f795702..58d3171 100644
--- a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/GnuCParser.g
@@ -315,12 +315,15 @@ typeSpecifier [int specCount] returns [int retSpecCount]
| "unsigned"
| "__int32"
| "int32_t"
+ | "wchar_t"
| "uint32_t"
| "__int64"
| "int64_t"
| "uint64_t"
| "ptrdiff_t"
+ | "intptr_t"
| "size_t"
+ | "uintptr_t"
| structOrUnionSpecifier ( options{warnWhenFollowAmbig=false;}: attributeDecl )*
| enumSpecifier
| { specCount==0 }? typedefName
diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g b/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g
index 82792f3..1beeb7d 100644
--- a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g
@@ -183,6 +183,17 @@ typeSpecifier
| "double"
| "signed"
| "unsigned"
+ | "__int32"
+ | "int32_t"
+ | "wchar_t"
+ | "uint32_t"
+ | "__int64"
+ | "int64_t"
+ | "uint64_t"
+ | "ptrdiff_t"
+ | "intptr_t"
+ | "size_t"
+ | "uintptr_t"
| structSpecifier ( attributeDecl )*
| unionSpecifier ( attributeDecl )*
| enumSpecifier
diff --git a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g
index fa6455f..acb6dde 100644
--- a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g
@@ -506,12 +506,15 @@ typeSpecifier[int attributes] returns [Type t] {
| "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs); }
| "__int32" { t = new IntType("__int32", SizeThunk.INT, unsigned, cvAttrs); }
| "int32_t" { t = new IntType("int32_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ }
+ | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ }
| "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT, true, cvAttrs); /* TS: always unsigned */ }
| "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsigned, cvAttrs); }
| "int64_t" { t = new IntType("int64_t", SizeThunk.INT64, false, cvAttrs); /* TS: always signed */ }
| "uint64_t" { t = new IntType("uint64_t", SizeThunk.INT64, true, cvAttrs); /* TS: always unsigned */ }
| "ptrdiff_t" { t = new IntType("ptrdiff_t", SizeThunk.POINTER, false, cvAttrs); /* TS: always signed */ }
+ | "intptr_t" { t = new IntType("intptr_t", SizeThunk.POINTER, false, cvAttrs); /* TS: always signed */ }
| "size_t" { t = new IntType("size_t", SizeThunk.POINTER, true, cvAttrs); /* TS: always unsigned */ }
+ | "uintptr_t" { t = new IntType("uintptr_t", SizeThunk.POINTER, true, cvAttrs); /* TS: always unsigned */ }
| t = structSpecifier[cvAttrs] ( attributeDecl )*
| t = unionSpecifier [cvAttrs] ( attributeDecl )*
| t = enumSpecifier [cvAttrs]
diff --git a/src/java/com/jogamp/gluegen/cgram/StdCParser.g b/src/java/com/jogamp/gluegen/cgram/StdCParser.g
index 015c3e0..231e371 100644
--- a/src/java/com/jogamp/gluegen/cgram/StdCParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/StdCParser.g
@@ -265,6 +265,17 @@ typeSpecifier [int specCount] returns [int retSpecCount]
| "double"
| "signed"
| "unsigned"
+ | "__int32"
+ | "int32_t"
+ | "wchar_t"
+ | "uint32_t"
+ | "__int64"
+ | "int64_t"
+ | "uint64_t"
+ | "ptrdiff_t"
+ | "intptr_t"
+ | "size_t"
+ | "uintptr_t"
| structOrUnionSpecifier
| enumSpecifier
| { specCount == 0 }? typedefName
diff --git a/src/java/com/jogamp/gluegen/pcpp/PCPP.java b/src/java/com/jogamp/gluegen/pcpp/PCPP.java
index f34a707..45a92df 100644
--- a/src/java/com/jogamp/gluegen/pcpp/PCPP.java
+++ b/src/java/com/jogamp/gluegen/pcpp/PCPP.java
@@ -517,6 +517,16 @@ public class PCPP {
while (nextToken(true) != StreamTokenizer.TT_EOL) {
values.add(curTokenAsString());
}
+ addDefine(name, macroDefinition, values);
+ }
+
+ public void addDefine(String name, String value) {
+ List<String> values = new ArrayList<String>();
+ values.add(value);
+ addDefine(name, false, values);
+ }
+
+ private void addDefine(String name, boolean nameIsMacro, List<String> values) {
// if we're not within an active block of code (like inside an "#ifdef
// FOO" where FOO isn't defined), then don't actually alter the definition
// map.
@@ -561,8 +571,8 @@ public class PCPP {
// TO DO: Is this correct? Why not output the symbol unchanged?
// I think that it's a good thing to see that some symbols are
// defined in terms of others. -chris
- macroDefinition = newValue.contains("(");
- if(macroDefinition) {
+ boolean valueIsMacro = newValue.contains("(");
+ if(valueIsMacro) {
// parser can't dig this currently
emitDefine = false;
} else {
@@ -576,8 +586,7 @@ public class PCPP {
}
}
- } else if (macroDefinition) {
-
+ } else if (nameIsMacro) {
// list parameters
List<String> params = new ArrayList<String>();
for (int i = 1; i < values.size(); i++) {
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
index 6cdb025..bd526e6 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -23,7 +23,8 @@
#define CONSTANT_ONE 1
#define ARRAY_SIZE 8
-#include "gluegenint.h"
+#include <gluegen_stdint.h>
+#include <gluegen_stddef.h>
typedef uint64_t foo;
@@ -98,4 +99,12 @@ MYAPI MYAPIConfig * MYAPIENTRY typeTestAnonPointer(const MYAPIConfig * a);
#define HUGE_VALF_3 ((int) 1e53)
#define DOUBLE_DEFINE_BRACKETS_3 HUGE_VALF_3
+size_t unsigned_size_t_1;
+ptrdiff_t a_signed_pointer_t_1;
+
+#ifdef __GLUEGEN__
+ #warning "Hello GlueGen"
+#else
+ #warning "Hello Native Compiler"
+#endif