From 7865b355bd52958f4b27e42b500e83c52255ef37 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 9 Nov 2010 02:42:03 +0100 Subject: 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 --- src/java/com/jogamp/gluegen/GlueGen.java | 59 ++++++++++++++++++---- src/java/com/jogamp/gluegen/cgram/GnuCParser.g | 3 ++ src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g | 11 ++++ src/java/com/jogamp/gluegen/cgram/HeaderParser.g | 3 ++ src/java/com/jogamp/gluegen/cgram/StdCParser.g | 11 ++++ src/java/com/jogamp/gluegen/pcpp/PCPP.java | 17 +++++-- 6 files changed, 89 insertions(+), 15 deletions(-) (limited to 'src/java') 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.
- *
+ *

+ *

GlueGen Data Type Mapping

* Gluegen has build-in types (terminal symbols) for:
*
* - * - * - * - * - * - * - * - * - * - *
type java native-x32native-x64type signed
__int32 32bit32bit 32bit integersigned or unsigned
int32_t 32bit32bit 32bit integersigned
uint32_t 32bit32bit 32bit integerunsigned
__int64 64bit64bit 64bit integersigned or unsigned
int64_t 64bit64bit 64bit integersigned
uint64_t 64bit64bit 64bit integerunsigned
ptrdiff_t 64bit32bit 64bit integersigned
size_t 64bit32bit 64bit integerunsigned
+ * type java native-x32native-x64type signed origin + * __int32 32bit32bit 32bit integersigned or unsignedwindows + * int32_t 32bit32bit 32bit integersigned stdint.h + * wchar_t 32bit32bit 32bit integersigned stddef.h + * uint32_t 32bit32bit 32bit integerunsigned stdint.h + * __int64 64bit64bit 64bit integersigned or unsignedwindows + * int64_t 64bit64bit 64bit integersigned stdint.h + * uint64_t 64bit64bit 64bit integerunsigned stdint.h + * ptrdiff_t 64bit32bit 64bit integersigned stddef.h + * intptr_t 64bit32bit 64bit integersigned stdint.h + * size_t 64bit32bit 64bit integerunsigned stddef.h + * uintptr_t 64bit32bit 64bit integerunsigned stdint.h + *

+ *

+ *

GlueGen Platform Header Files

+ * GlueGen provides convenient platform headers,
+ * which can be included in your C header files for native compilation and GlueGen code generation.
+ *
+ * Example:
+ *
+   #include <gluegen_stdint.h>
+   #include <gluegen_stddef.h>
+ 
+   uint64_t test64;
+   size_t size1;
+   ptrdiff_t ptr1;
+ * 
+ *
+ * To compile this file you have to include the following folder to your compilers system includes, ie -I:
+ *
+ *   gluegen/make/stub_includes/platform
+ * 
+ *
+ * To generate code for this file you have to include the following folder to your GlueGen includeRefid element:
+ *
+ *   gluegen/make/stub_includes/gluegen
+ * 

+ *

+ *

GlueGen Pre-Defined Macros

+ * To identity a GlueGen code generation run, GlueGen defines the following macros:
+ *
+     #define __GLUEGEN__ 2
+ * 
+ *

*/ + 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 values = new ArrayList(); + values.add(value); + addDefine(name, false, values); + } + + private void addDefine(String name, boolean nameIsMacro, List 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 params = new ArrayList(); for (int i = 1; i < values.size(); i++) { -- cgit v1.2.3