aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-24 03:44:24 +0100
committerSven Gothel <[email protected]>2015-03-24 03:44:24 +0100
commit88d51db39f3b00df1462eb0a18c1825ae1e86485 (patch)
tree6ba949ff85c1ff48cedfd866eb0622cafc583f40 /src
parentb755b045fb7e3c8306f24dd645297992ab8db7f9 (diff)
Bug 1149 - Replacing PCPP w/ JCPP, allowing complete macro handling (Part-2: JCPP submodule, build, test and doc)
Diffstat (limited to 'src')
-rw-r--r--src/java/com/jogamp/common/util/IOUtil.java10
-rw-r--r--src/java/com/jogamp/gluegen/GenericCPP.java5
-rw-r--r--src/java/com/jogamp/gluegen/GlueGen.java5
-rw-r--r--src/java/com/jogamp/gluegen/pcpp/PCPP.java2
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java27
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h7
6 files changed, 51 insertions, 5 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java
index c773b21..88542c4 100644
--- a/src/java/com/jogamp/common/util/IOUtil.java
+++ b/src/java/com/jogamp/common/util/IOUtil.java
@@ -39,6 +39,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.io.Reader;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.net.URISyntaxException;
@@ -188,6 +189,15 @@ public class IOUtil {
return numBytes;
}
+ public static StringBuilder appendCharStream(final StringBuilder sb, final Reader r) throws IOException {
+ final char[] cbuf = new char[1024];
+ int count;
+ while( 0 < ( count = r.read(cbuf) ) ) {
+ sb.append(cbuf, 0, count);
+ }
+ return sb;
+ }
+
/**
* Copy the specified input stream to a byte array, which is being returned.
*/
diff --git a/src/java/com/jogamp/gluegen/GenericCPP.java b/src/java/com/jogamp/gluegen/GenericCPP.java
index 85c8e65..db414d9 100644
--- a/src/java/com/jogamp/gluegen/GenericCPP.java
+++ b/src/java/com/jogamp/gluegen/GenericCPP.java
@@ -31,7 +31,7 @@ import java.io.OutputStream;
import java.io.Reader;
import java.util.List;
-import org.anarres.cpp.LexerException;
+import com.jogamp.gluegen.jcpp.LexerException;
/**
* Generic C preprocessor interface for GlueGen
@@ -55,8 +55,9 @@ public interface GenericCPP {
* May return an empty list, in case this preprocessor does not
* store {@link ConstantDefinition}s.
* </p>
+ * @throws GlueGenException
*/
- public List<ConstantDefinition> getConstantDefinitions();
+ public List<ConstantDefinition> getConstantDefinitions() throws GlueGenException;
} \ No newline at end of file
diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java
index 20e1efa..4153518 100644
--- a/src/java/com/jogamp/gluegen/GlueGen.java
+++ b/src/java/com/jogamp/gluegen/GlueGen.java
@@ -49,7 +49,7 @@ import antlr.*;
import com.jogamp.gluegen.cgram.*;
import com.jogamp.gluegen.cgram.types.*;
-import com.jogamp.gluegen.pcpp.*;
+import com.jogamp.gluegen.jcpp.JCPP;
import static java.lang.System.*;
@@ -136,7 +136,8 @@ public class GlueGen implements GlueEmitterControls {
out.deleteOnExit();
}
- preprocessor = new PCPP(includePaths, debug, copyPCPPOutput2Stderr);
+ // preprocessor = new PCPP(includePaths, debug, copyPCPPOutput2Stderr);
+ preprocessor = new JCPP(includePaths, debug, copyPCPPOutput2Stderr);
preprocessor.addDefine(__GLUEGEN__, "2");
preprocessor.setOut(outStream);
diff --git a/src/java/com/jogamp/gluegen/pcpp/PCPP.java b/src/java/com/jogamp/gluegen/pcpp/PCPP.java
index a06b8ee..c766634 100644
--- a/src/java/com/jogamp/gluegen/pcpp/PCPP.java
+++ b/src/java/com/jogamp/gluegen/pcpp/PCPP.java
@@ -137,7 +137,7 @@ public class PCPP implements GenericCPP {
}
@Override
- public List<ConstantDefinition> getConstantDefinitions() {
+ public List<ConstantDefinition> getConstantDefinitions() throws GlueGenException {
return new ArrayList<ConstantDefinition>(); // NOP
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
index 6e56a49..32ec496 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -96,6 +96,33 @@ public class BaseClass extends SingletonJunitCase {
AnonBlob ab = null;
PointerBuffer pb=null;
+ // Test constants values: binding and value!
+ {
+ // Plain vanilla CPP constants
+ Assert.assertEquals( 1, Bindingtest1.CONSTANT_ONE);
+ Assert.assertEquals( 8, Bindingtest1.ARRAY_SIZE);
+ Assert.assertEquals(1234, Bindingtest1.DEFINE_01);
+
+ // Enums
+ Assert.assertEquals( 1, Bindingtest1.LI);
+ Assert.assertEquals( 3, Bindingtest1.LO);
+ Assert.assertEquals( 2, Bindingtest1.LU);
+ Assert.assertEquals( 1, Bindingtest1.MI);
+ Assert.assertEquals( 3, Bindingtest1.MO);
+ Assert.assertEquals( 2, Bindingtest1.MU);
+ Assert.assertEquals( 0, Bindingtest1.ZERO);
+ Assert.assertEquals( 1, Bindingtest1.ONE);
+ Assert.assertEquals( 2, Bindingtest1.TWO);
+ Assert.assertEquals( 3, Bindingtest1.THREE);
+
+ // CPP Macro Expansion!
+ Assert.assertEquals( 1, Bindingtest1.NUMBER_ONE);
+ Assert.assertEquals( 2, Bindingtest1.NUMBER_TWO);
+ Assert.assertEquals( 4, Bindingtest1.NUMBER_FOUR);
+ Assert.assertEquals( 8, Bindingtest1.NUMBER_EIGHT);
+ Assert.assertEquals( 9, Bindingtest1.NUMBER_NINE);
+ Assert.assertEquals( 10, Bindingtest1.NUMBER_TEN);
+ }
{
l = binding.testXID(l);
l = binding.testXID_2(l);
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 6e826c5..fa876c6 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -50,6 +50,13 @@ typedef void * AnonBuffer; // Non Opaque
// #define DEFINE_02 ( (int ) 3 ) // Duplicate w/ same value ERROR (PCPP redefine)
// #define DEFINE_02 ( (int) 3 ) // Duplicate w/ diff value ERROR (PCPP redefine, then GlueGen)
+#define NUMBER_ONE CONSTANT_ONE
+#define NUMBER_TWO ( NUMBER_ONE + NUMBER_ONE )
+#define NUMBER_FOUR ( NUMBER_ONE << NUMBER_TWO )
+#define NUMBER_EIGHT ( NUMBER_TWO * NUMBER_TWO + ( NUMBER_ONE << NUMBER_TWO ) )
+#define NUMBER_NINE ( 2 * 2 + ( 1 << 2 ) + 1 )
+#define NUMBER_TEN ( NUMBER_EIGHT | NUMBER_TWO )
+
enum Lala { LI=1, LU, LO };
// enum Lala { LI=1, LU, LO }; // Duplicate w/ same value (ignored, ERROR in native compilation)
// enum Lala { LI=1, LU=3, LO }; // Duplicate w/ diff value ERROR