summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-23 04:05:03 +0100
committerSven Gothel <[email protected]>2015-03-23 04:05:03 +0100
commitb755b045fb7e3c8306f24dd645297992ab8db7f9 (patch)
tree4be9dfb52b0e0ed91d5376ef1d770552d3252d1e
parent532b8df474976b474f0cf4eb2d93588ded2ad3fe (diff)
Bug 1149 - Replacing PCPP w/ JCPP, allowing complete macro handling (Part-1: Cleanup / Preparation)
-rw-r--r--make/build-test.xml9
-rwxr-xr-xmake/jogamp-env.xml6
-rw-r--r--src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g7
-rw-r--r--src/java/com/jogamp/common/nio/StructAccessor.java23
-rw-r--r--src/java/com/jogamp/gluegen/ConstantDefinition.java82
-rw-r--r--src/java/com/jogamp/gluegen/GenericCPP.java62
-rw-r--r--src/java/com/jogamp/gluegen/GlueGen.java82
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java72
-rw-r--r--src/java/com/jogamp/gluegen/Logging.java46
-rw-r--r--src/java/com/jogamp/gluegen/pcpp/PCPP.java119
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java5
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg2
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg2
13 files changed, 371 insertions, 146 deletions
diff --git a/make/build-test.xml b/make/build-test.xml
index 624bd61..fe1aaec 100644
--- a/make/build-test.xml
+++ b/make/build-test.xml
@@ -36,6 +36,7 @@
<property name="test.junit.generation.rel" value="${test.junit.rel}/gluegen/test/junit/generation" />
<property name="test.junit.generation.dir" value="${test.base.dir}/${test.junit.generation.rel}" />
+ <property name="tempdir" value="${project.root}/build-temp" />
<property name="build" location="${project.root}/${rootrel.build}" />
<property name="test.dir" value="${gluegen.root}/${rootrel.build}/test"/>
<property name="results" value="${test.dir}/results" />
@@ -50,6 +51,7 @@
<property name="build_t.gen.rootrel" value="${rootrel.build}/test/build/gensrc"/>
+ <mkdir dir="${tempdir}" />
<mkdir dir="${test.dir}"/>
<mkdir dir="${results}"/>
<mkdir dir="${build_t}"/>
@@ -516,6 +518,12 @@ chmod 644 ${results}/* \${line.separator}
</antcall>
</target>
+ <target name="java.generate.copy2temp">
+ <copy todir="${tempdir}">
+ <fileset dir="${build_t}"
+ includes="gensrc/classes/**" />
+ </copy>
+ </target>
<!--
@@ -546,6 +554,7 @@ chmod 644 ${results}/* \${line.separator}
logLevel="WARNING">
<classpath refid="gluegen.classpath" />
</gluegen>
+ <antcall target="java.generate.copy2temp" inheritRefs="true" />
<gluegen src="${test.junit.generation.dir}/test1-gluegen.c"
outputRootDir="${build_t.gen}"
diff --git a/make/jogamp-env.xml b/make/jogamp-env.xml
index 68fa098..c5bb1b0 100755
--- a/make/jogamp-env.xml
+++ b/make/jogamp-env.xml
@@ -236,6 +236,9 @@
<contains string="${target.sourcelevel}" substring="1.6" casesensitive="false" />
<contains string="${target.sourcelevel}" substring="1.7" casesensitive="false" />
<contains string="${target.sourcelevel}" substring="1.8" casesensitive="false" />
+ <contains string="${target.sourcelevel}" substring="1.9" casesensitive="false" />
+ <contains string="${target.sourcelevel}" substring="2.0" casesensitive="false" />
+ <contains string="${target.sourcelevel}" substring="2.1" casesensitive="false" />
</or>
</not>
</condition>
@@ -247,6 +250,9 @@
<contains string="${target.targetlevel}" substring="1.6" casesensitive="false" />
<contains string="${target.targetlevel}" substring="1.7" casesensitive="false" />
<contains string="${target.targetlevel}" substring="1.8" casesensitive="false" />
+ <contains string="${target.targetlevel}" substring="1.9" casesensitive="false" />
+ <contains string="${target.targetlevel}" substring="2.0" casesensitive="false" />
+ <contains string="${target.targetlevel}" substring="2.1" casesensitive="false" />
</or>
</not>
</condition>
diff --git a/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g b/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
index d159ff3..4bcb052 100644
--- a/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
+++ b/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
@@ -689,7 +689,12 @@ structDeclaration[CompoundType containingType] returns [boolean addedAny] {
if (!addedAny) {
if (t != null) {
CompoundType ct = t.asCompound();
- if (ct.isUnion()) {
+ if( null == ct ) {
+ throwGlueGenException(structDeclaration_AST_in,
+ String.format("Anonymous compound, w/ NULL type:%n containing '%s'",
+ getTypeString(containingType)));
+ }
+ if ( ct.isUnion() ) {
// Anonymous union
containingType.addField(new Field(null, t, null));
}
diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java
index af7b6d1..8ae0c29 100644
--- a/src/java/com/jogamp/common/nio/StructAccessor.java
+++ b/src/java/com/jogamp/common/nio/StructAccessor.java
@@ -83,6 +83,16 @@ public class StructAccessor {
bb.put(byteOffset, v);
}
+ /** Retrieves the boolean at the specified byteOffset. */
+ public final boolean getBooleanAt(final int byteOffset) {
+ return (byte)0 != bb.get(byteOffset);
+ }
+
+ /** Puts a boolean at the specified byteOffset. */
+ public final void setBooleanAt(final int byteOffset, final boolean v) {
+ bb.put(byteOffset, v?(byte)1:(byte)0);
+ }
+
/** Retrieves the char at the specified byteOffset. */
public final char getCharAt(final int byteOffset) {
return bb.getChar(byteOffset);
@@ -213,6 +223,19 @@ public class StructAccessor {
return v;
}
+ public final void setBooleansAt(int byteOffset, final boolean[] v) {
+ for (int i = 0; i < v.length; i++) {
+ bb.put(byteOffset++, v[i]?(byte)1:(byte)0);
+ }
+ }
+
+ public final boolean[] getBooleansAt(int byteOffset, final boolean[] v) {
+ for (int i = 0; i < v.length; i++) {
+ v[i] = (byte)0 != bb.get(byteOffset++);
+ }
+ return v;
+ }
+
public final void setCharsAt(int byteOffset, final char[] v) {
for (int i = 0; i < v.length; i++, byteOffset+=2) {
bb.putChar(byteOffset, v[i]);
diff --git a/src/java/com/jogamp/gluegen/ConstantDefinition.java b/src/java/com/jogamp/gluegen/ConstantDefinition.java
index 1ea4233..e88bb9c 100644
--- a/src/java/com/jogamp/gluegen/ConstantDefinition.java
+++ b/src/java/com/jogamp/gluegen/ConstantDefinition.java
@@ -169,4 +169,86 @@ public class ConstantDefinition extends AliasedSymbolImpl implements AliasedSema
return s1.equals(s2);
}
+
+ public static boolean isConstantExpression(final String value) {
+ if( null != value && value.length() > 0 ) {
+ // Single numeric value
+ if ( isNumber(value) ) {
+ return true;
+ }
+ // Find constant expressions like (1 << 3)
+ // if found just pass them through, they will most likely work in java too
+ // expressions containing identifiers are currently ignored (casts too)
+ final String[] values = value.split("[\\s\\(\\)]"); // [ whitespace '(' ')' ]
+ int numberCount = 0;
+ for (final String s : values) {
+ if( s.length() > 0 ) {
+ if( isCPPOperand(s) ) {
+ // OK
+ } else if ( isNumber(s) ) {
+ // OK
+ numberCount++;
+ } else {
+ return false;
+ }
+ }
+ }
+ final boolean res = numberCount > 0;
+ return res;
+ }
+ return false;
+ }
+ public static boolean isNumber(final String s) {
+ if( isHexNumber(s) ) {
+ return true;
+ } else {
+ return isDecimalNumber(s);
+ }
+ }
+ public static boolean isHexNumber(final String s) {
+ return patternHexNumber.matcher(s).matches();
+ }
+ public static java.util.regex.Pattern patternHexNumber =
+ java.util.regex.Pattern.compile("0[xX][0-9a-fA-F]+[lLfFuU]?");
+
+ public static boolean isDecimalNumber(final String s) {
+ try {
+ Float.valueOf(s);
+ } catch (final NumberFormatException e) {
+ // not parsable as a number
+ return false;
+ }
+ return true;
+ }
+
+
+ public static boolean isCPPOperand(final String s) {
+ return patternCPPOperand.matcher(s).matches();
+ }
+ /**
+ * One of: {@code +} {@code -} {@code *} {@code /} {@code |} {@code &} {@code (} {@code )} {@code <<} {@code >>}
+ */
+ public static java.util.regex.Pattern patternCPPOperand =
+ java.util.regex.Pattern.compile("[\\+\\-\\*\\/\\|\\&\\(\\)]|(\\<\\<)|(\\>\\>)");
+
+ public static boolean isIdentifier(final String value) {
+ boolean identifier = false;
+
+ final char[] chars = value.toCharArray();
+
+ for (int i = 0; i < chars.length; i++) {
+ final char c = chars[i];
+ if (i == 0) {
+ if (Character.isJavaIdentifierStart(c)) {
+ identifier = true;
+ }
+ } else {
+ if (!Character.isJavaIdentifierPart(c)) {
+ identifier = false;
+ break;
+ }
+ }
+ }
+ return identifier;
+ }
}
diff --git a/src/java/com/jogamp/gluegen/GenericCPP.java b/src/java/com/jogamp/gluegen/GenericCPP.java
new file mode 100644
index 0000000..85c8e65
--- /dev/null
+++ b/src/java/com/jogamp/gluegen/GenericCPP.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2015 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community OR
+ * CONTRIBUTORS 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.gluegen;
+
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.List;
+
+import org.anarres.cpp.LexerException;
+
+/**
+ * Generic C preprocessor interface for GlueGen
+ */
+public interface GenericCPP {
+
+ public void addDefine(String name, String value) throws LexerException;
+
+ public String findFile(String filename);
+
+ public OutputStream out();
+ public void setOut(OutputStream out);
+
+ public void run(Reader reader, String filename) throws GlueGenException;
+
+ /**
+ * Returns a list of {@link ConstantDefinition}, i.e.
+ * <i>non-function-like</i> and <i>non-empty</i> macros w/ <i>constant-value</i>,
+ * as derived during parsing.
+ * <p>
+ * May return an empty list, in case this preprocessor does not
+ * store {@link ConstantDefinition}s.
+ * </p>
+ */
+ public List<ConstantDefinition> getConstantDefinitions();
+
+
+} \ 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 778ed75..20e1efa 100644
--- a/src/java/com/jogamp/gluegen/GlueGen.java
+++ b/src/java/com/jogamp/gluegen/GlueGen.java
@@ -63,7 +63,7 @@ public class GlueGen implements GlueEmitterControls {
}
private final List<String> forcedStructNames = new ArrayList<String>();
- private PCPP preprocessor;
+ private GenericCPP preprocessor;
// State for SymbolFilters
private List<ConstantDefinition> allConstants;
@@ -100,6 +100,7 @@ public class GlueGen implements GlueEmitterControls {
}
}
+ public static final String __GLUEGEN__ = "__GLUEGEN__";
@SuppressWarnings("unchecked")
public void run(final Reader reader, final String filename, final Class<?> emitterClass, final List<String> includePaths, final List<String> cfgFiles, final String outputRootDir, final boolean copyPCPPOutput2Stderr) {
@@ -136,7 +137,7 @@ public class GlueGen implements GlueEmitterControls {
}
preprocessor = new PCPP(includePaths, debug, copyPCPPOutput2Stderr);
- preprocessor.addDefine("__GLUEGEN__", "2");
+ preprocessor.addDefine(__GLUEGEN__, "2");
preprocessor.setOut(outStream);
preprocessor.run(reader, filename);
@@ -222,6 +223,7 @@ public class GlueGen implements GlueEmitterControls {
final Define def = (Define) elem;
allConstants.add(new ConstantDefinition(def.getName(), def.getValue(), def.getASTLocusTag()));
}
+ allConstants.addAll(preprocessor.getConstantDefinitions());
allFunctions = headerParser.getParsedFunctions();
@@ -248,44 +250,46 @@ public class GlueGen implements GlueEmitterControls {
}
}
- emit.beginDefines();
- final Set<String> emittedDefines = new HashSet<String>(100);
- // emit java equivalent of enum { ... } statements
- final StringBuilder comment = new StringBuilder();
- for (final ConstantDefinition def : allConstants) {
- if (!emittedDefines.contains(def.getName())) {
- emittedDefines.add(def.getName());
- final Set<String> aliases = cfg.getAliasedDocNames(def);
- if (aliases != null && aliases.size() > 0 ) {
- int i=0;
- comment.append("Alias for: <code>");
- for (final String alias : aliases) {
- if(0 < i) {
- comment.append("</code>, <code>");
+ if ( !cfg.structsOnly() ) {
+ emit.beginDefines();
+ final Set<String> emittedDefines = new HashSet<String>(100);
+ // emit java equivalent of enum { ... } statements
+ final StringBuilder comment = new StringBuilder();
+ for (final ConstantDefinition def : allConstants) {
+ if (!emittedDefines.contains(def.getName())) {
+ emittedDefines.add(def.getName());
+ final Set<String> aliases = cfg.getAliasedDocNames(def);
+ if (aliases != null && aliases.size() > 0 ) {
+ int i=0;
+ comment.append("Alias for: <code>");
+ for (final String alias : aliases) {
+ if(0 < i) {
+ comment.append("</code>, <code>");
+ }
+ comment.append(alias);
+ i++;
}
- comment.append(alias);
- i++;
+ comment.append("</code>");
}
- comment.append("</code>");
- }
- if (def.getEnumName() != null) {
- if (comment.length() > 0)
- comment.append("<br>\n");
+ if (def.getEnumName() != null) {
+ if (comment.length() > 0)
+ comment.append("<br>\n");
- comment.append("Defined as part of enum type \"");
- comment.append(def.getEnumName());
- comment.append("\"");
- }
- if (comment.length() > 0) {
- emit.emitDefine(def, comment.toString());
- comment.setLength(0);
- }
- else {
- emit.emitDefine(def, null);
+ comment.append("Defined as part of enum type \"");
+ comment.append(def.getEnumName());
+ comment.append("\"");
+ }
+ if (comment.length() > 0) {
+ emit.emitDefine(def, comment.toString());
+ comment.setLength(0);
+ }
+ else {
+ emit.emitDefine(def, null);
+ }
}
}
+ emit.endDefines();
}
- emit.endDefines();
// Iterate through the functions finding structs that are referenced in
// the function signatures; these will be remembered for later emission
@@ -337,10 +341,12 @@ public class GlueGen implements GlueEmitterControls {
}
emit.endStructs();
- // emit java and C code to interface with the native functions
- emit.beginFunctions(td, sd, headerParser.getCanonMap());
- emit.emitFunctions(allFunctions);
- emit.endFunctions();
+ if ( !cfg.structsOnly() ) {
+ // emit java and C code to interface with the native functions
+ emit.beginFunctions(td, sd, headerParser.getCanonMap());
+ emit.emitFunctions(allFunctions);
+ emit.endFunctions();
+ }
// end emission of glue code
emit.endEmission();
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 0e2efbb..ae4ed2a 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -223,7 +223,7 @@ public class JavaEmitter implements GlueEmitter {
controls.forceStructEmission(structs);
}
- if (!cfg.structsOnly()) {
+ if ( !cfg.structsOnly() ) {
try {
openWriters();
} catch (final Exception e) {
@@ -235,7 +235,7 @@ public class JavaEmitter implements GlueEmitter {
@Override
public void endEmission() {
- if (!cfg.structsOnly()) {
+ if ( !cfg.structsOnly() ) {
emitAllFileFooters();
try {
@@ -248,7 +248,7 @@ public class JavaEmitter implements GlueEmitter {
@Override
public void beginDefines() throws Exception {
- if ((cfg.allStatic() || cfg.emitInterface()) && !cfg.structsOnly()) {
+ if ( ( cfg.allStatic() || cfg.emitInterface() ) && !cfg.structsOnly() ) {
javaWriter().println();
}
}
@@ -301,8 +301,7 @@ public class JavaEmitter implements GlueEmitter {
// "calculates" the result type of a simple expression
// example: (2+3)-(2.0f-3.0) -> Double
// example: (1 << 2) -> Integer
-
- final Scanner scanner = new Scanner(value).useDelimiter("[+-/*/></(/)]");
+ final Scanner scanner = new Scanner(value).useDelimiter(ConstantDefinition.patternCPPOperand);
Object resultType = null;
@@ -430,8 +429,7 @@ public class JavaEmitter implements GlueEmitter {
@Override
public void emitDefine(final ConstantDefinition def, final String optionalComment) throws Exception {
-
- if (cfg.allStatic() || cfg.emitInterface()) {
+ if ( ( cfg.allStatic() || cfg.emitInterface() ) && !cfg.structsOnly() ) {
// TODO: Some defines (e.g., GL_DOUBLE_EXT in gl.h) are defined in terms
// of other defines -- should we emit them as references to the original
// define (not even sure if the lexer supports this)? Right now they're
@@ -457,7 +455,6 @@ public class JavaEmitter implements GlueEmitter {
value = value.substring(0, value.length()-1);
}
}
-
javaWriter().println(" public static final " + type + " " + name + " = " + value + suffix + ";");
}
}
@@ -476,46 +473,47 @@ public class JavaEmitter implements GlueEmitter {
this.canonMap = canonMap;
this.requiresStaticInitialization = false; // reset
- if ((cfg.allStatic() || cfg.emitInterface()) && !cfg.structsOnly()) {
+ if ( ( cfg.allStatic() || cfg.emitInterface() ) && !cfg.structsOnly() ) {
javaWriter().println();
}
}
@Override
public Iterator<FunctionSymbol> emitFunctions(final List<FunctionSymbol> funcsToBind) throws Exception {
- // Bind all the C funcs to Java methods
- final ArrayList<FunctionEmitter> methodBindingEmitters = new ArrayList<FunctionEmitter>(2*funcsToBind.size());
- {
- int i=0;
- for (final FunctionSymbol cFunc : funcsToBind) {
- // Check to see whether this function should be ignored
- if ( !cfg.shouldIgnoreInImpl(cFunc) ) {
- methodBindingEmitters.addAll(generateMethodBindingEmitters(cFunc));
- LOG.log(INFO, cFunc.getASTLocusTag(), "Non-Ignored Impl[{0}]: {1}", i++, cFunc);
- }
+ if ( !cfg.structsOnly() ) {
+ // Bind all the C funcs to Java methods
+ final ArrayList<FunctionEmitter> methodBindingEmitters = new ArrayList<FunctionEmitter>(2*funcsToBind.size());
+ {
+ int i=0;
+ for (final FunctionSymbol cFunc : funcsToBind) {
+ // Check to see whether this function should be ignored
+ if ( !cfg.shouldIgnoreInImpl(cFunc) ) {
+ methodBindingEmitters.addAll(generateMethodBindingEmitters(cFunc));
+ LOG.log(INFO, cFunc.getASTLocusTag(), "Non-Ignored Impl[{0}]: {1}", i++, cFunc);
+ }
+ }
}
- }
- // Emit all the methods
- {
- int i=0;
- for (final FunctionEmitter emitter : methodBindingEmitters) {
- try {
- final FunctionSymbol cFunc = emitter.getCSymbol();
- if ( !emitter.isInterface() || !cfg.shouldIgnoreInInterface(cFunc) ) {
- emitter.emit();
- emitter.getDefaultOutput().println(); // put newline after method body
- LOG.log(INFO, cFunc.getASTLocusTag(), "Non-Ignored Intf[{0}]: {1}", i++, cFunc);
+ // Emit all the methods
+ {
+ int i=0;
+ for (final FunctionEmitter emitter : methodBindingEmitters) {
+ try {
+ final FunctionSymbol cFunc = emitter.getCSymbol();
+ if ( !emitter.isInterface() || !cfg.shouldIgnoreInInterface(cFunc) ) {
+ emitter.emit();
+ emitter.getDefaultOutput().println(); // put newline after method body
+ LOG.log(INFO, cFunc.getASTLocusTag(), "Non-Ignored Intf[{0}]: {1}", i++, cFunc);
+ }
+ } catch (final Exception e) {
+ throw new GlueGenException(
+ "Error while emitting binding for \"" + emitter.getCSymbol().getAliasedString() + "\"",
+ emitter.getCSymbol().getASTLocusTag(), e);
+ }
}
- } catch (final Exception e) {
- throw new GlueGenException(
- "Error while emitting binding for \"" + emitter.getCSymbol().getAliasedString() + "\"",
- emitter.getCSymbol().getASTLocusTag(), e);
- }
}
}
-
// Return the list of FunctionSymbols that we generated gluecode for
return funcsToBind.iterator();
}
@@ -869,7 +867,7 @@ public class JavaEmitter implements GlueEmitter {
@Override
public void endFunctions() throws Exception {
- if (!cfg.structsOnly()) {
+ if ( !cfg.structsOnly() ) {
if (cfg.allStatic() || cfg.emitInterface()) {
emitCustomJavaCode(javaWriter(), cfg.className());
}
diff --git a/src/java/com/jogamp/gluegen/Logging.java b/src/java/com/jogamp/gluegen/Logging.java
index 7000406..ddefca4 100644
--- a/src/java/com/jogamp/gluegen/Logging.java
+++ b/src/java/com/jogamp/gluegen/Logging.java
@@ -54,6 +54,15 @@ public class Logging {
*/
public static interface LoggerIf {
/**
+ * See {@link Logger#info(String)}
+ */
+ void info(final String msg);
+ /**
+ * See {@link Logger#info(String)}
+ */
+ void info(final ASTLocusTag loc, final String msg);
+
+ /**
* See {@link Logger#warning(String)}
*/
void warning(final String msg);
@@ -63,6 +72,15 @@ public class Logging {
void warning(final ASTLocusTag loc, final String msg);
/**
+ * Calls {@link #log(Level, String)} w/ {@link Level#FINE}.
+ */
+ void debug(final String msg);
+ /**
+ * Calls {@link #log(Level, ASTLocusTag, String)} w/ {@link Level#FINE}.
+ */
+ void debug(final ASTLocusTag loc, final String msg);
+
+ /**
* See {@link Logger#log(Level, String)}
*/
void log(final Level level, final String msg);
@@ -126,6 +144,20 @@ public class Logging {
": obj 0x"+Integer.toHexString(impl.hashCode()));
}
@Override
+ public void info(final String msg) {
+ impl.info(msg);
+ }
+ @Override
+ public void info(final ASTLocusTag loc, final String msg) {
+ handler.plf.setASTLocusTag(loc);
+ try {
+ impl.info(msg);
+ } finally {
+ handler.plf.setASTLocusTag(null);
+ }
+ }
+
+ @Override
public void warning(final String msg) {
impl.warning(msg);
}
@@ -140,6 +172,15 @@ public class Logging {
}
@Override
+ public void debug(final String msg) {
+ log(Level.FINE, msg);
+ }
+ @Override
+ public void debug(final ASTLocusTag loc, final String msg) {
+ log(Level.FINE, loc, msg);
+ }
+
+ @Override
public void log(final Level level, final String msg) {
impl.log(level, msg);
}
@@ -296,6 +337,11 @@ public class Logging {
return rootPackageLogger;
}
/** Returns the demanded logger, while aligning its log-level to the root logger's level. */
+ public static synchronized LoggerIf getLogger(final Class<?> clazz) {
+ return getLogger(clazz.getPackage().getName(), clazz.getSimpleName());
+ }
+
+ /** Returns the demanded logger, while aligning its log-level to the root logger's level. */
public static synchronized LoggerIf getLogger(final String packageName, final String simpleClassName) {
final String fqnClassName = packageName+"."+simpleClassName;
LoggerIf res = loggers.get(fqnClassName);
diff --git a/src/java/com/jogamp/gluegen/pcpp/PCPP.java b/src/java/com/jogamp/gluegen/pcpp/PCPP.java
index d660764..a06b8ee 100644
--- a/src/java/com/jogamp/gluegen/pcpp/PCPP.java
+++ b/src/java/com/jogamp/gluegen/pcpp/PCPP.java
@@ -56,8 +56,11 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.logging.Level;
import com.jogamp.gluegen.ASTLocusTag;
+import com.jogamp.gluegen.ConstantDefinition;
+import com.jogamp.gluegen.GenericCPP;
import com.jogamp.gluegen.GlueGenException;
import com.jogamp.gluegen.Logging;
import com.jogamp.gluegen.Logging.LoggerIf;
@@ -68,7 +71,7 @@ import static java.util.logging.Level.*;
#define statements defining constants so they can be observed by a
glue code generator. */
-public class PCPP {
+public class PCPP implements GenericCPP {
private final LoggerIf LOG;
@@ -98,7 +101,8 @@ public class PCPP {
enableCopyOutput2Stderr = copyOutput2Stderr;
}
- public void run(final Reader reader, final String filename) throws IOException {
+ @Override
+ public void run(final Reader reader, final String filename) throws GlueGenException {
StreamTokenizer tok = null;
BufferedReader bufReader = null;
if (reader instanceof BufferedReader) {
@@ -114,13 +118,29 @@ public class PCPP {
final ParseState oldState = state;
state = curState;
lineDirective();
- parse();
+ try {
+ parse();
+ } catch (final Exception e) {
+ final StringBuilder buf = new StringBuilder("Preprocessor failed");
+ LOG.log(Level.SEVERE, buf.toString(), e);
+ if( e instanceof GlueGenException ) {
+ throw (GlueGenException)e;
+ } else {
+ throw new GlueGenException("Preprocessor failed",
+ new ASTLocusTag(filename(), lineNumber(), -1, null), e);
+ }
+ }
state = oldState;
if (state != null) {
lineDirective();
}
}
+ @Override
+ public List<ConstantDefinition> getConstantDefinitions() {
+ return new ArrayList<ConstantDefinition>(); // NOP
+ }
+
private void initTokenizer(final StreamTokenizer tok) {
tok.resetSyntax();
tok.wordChars('a', 'z');
@@ -137,6 +157,7 @@ public class PCPP {
tok.slashStarComments(true);
}
+ @Override
public String findFile(final String filename) {
final String sep = File.separator;
for (final String inclPath : includePaths) {
@@ -149,10 +170,12 @@ public class PCPP {
return null;
}
+ @Override
public OutputStream out() {
return out;
}
+ @Override
public void setOut(final OutputStream out) {
this.out = out;
writer = new PrintWriter(out);
@@ -381,7 +404,7 @@ public class PCPP {
}
}
- if(isIdentifier(value)) {
+ if(ConstantDefinition.isIdentifier(value)) {
newS +=" ";
}
@@ -528,6 +551,7 @@ public class PCPP {
addDefine(name, macroDefinition, values);
}
+ @Override
public void addDefine(final String name, final String value) {
final List<String> values = new ArrayList<String>();
values.add(value);
@@ -560,7 +584,7 @@ public class PCPP {
// See whether the value is a constant
final String value = values.get(0);
- if (isConstant(value)) {
+ if (ConstantDefinition.isNumber(value)) {
// Value is numeric constant like "#define FOO 5".
// Put it in the #define map
final String oldDef = defineMap.put(name, value);
@@ -629,7 +653,7 @@ public class PCPP {
boolean containsIdentifier = false;
for (final String value : values) {
- if(isIdentifier(value)) {
+ if(ConstantDefinition.isIdentifier(value)) {
containsIdentifier = true;
break;
}
@@ -693,68 +717,6 @@ public class PCPP {
//System.err.println("OUT HANDLE_DEFINE: " + name);
}
- private boolean isIdentifier(final String value) {
-
- boolean identifier = false;
-
- final char[] chars = value.toCharArray();
-
- for (int i = 0; i < chars.length; i++) {
- final char c = chars[i];
- if (i == 0) {
- if (Character.isJavaIdentifierStart(c)) {
- identifier = true;
- }
- } else {
- if (!Character.isJavaIdentifierPart(c)) {
- identifier = false;
- break;
- }
- }
- }
- return identifier;
- }
-
- private boolean isConstant(final String s) {
- if (s.startsWith("0x") || s.startsWith("0X")) {
- return checkHex(s);
- } else {
- return checkDecimal(s);
- }
- }
-
- private boolean checkHex(final String s) {
- char c='\0';
- int i;
- for (i = 2; i < s.length(); i++) {
- c = s.charAt(i);
- if (!((c >= '0' && c <= '9') ||
- (c >= 'a' && c <= 'f') ||
- (c >= 'A' && c <= 'F'))) {
- break;
- }
- }
- if(i==s.length()) {
- return true;
- } else if(i==s.length()-1) {
- // Const qualifier ..
- return c == 'l' || c == 'L' ||
- c == 'f' || c == 'F' ||
- c == 'u' || c == 'U' ;
- }
- return false;
- }
-
- private boolean checkDecimal(final String s) {
- try {
- Float.valueOf(s);
- } catch (final NumberFormatException e) {
- // not parsable as a number
- return false;
- }
- return true;
- }
-
private String resolveDefine(final String word, final boolean returnNullIfNotFound) {
String lastWord = defineMap.get(word);
if (lastWord == null) {
@@ -932,6 +894,27 @@ public class PCPP {
ifValue = false;
}
break;
+ case '*':
+ {
+ // NOTE: we don't handle expressions like this properly
+ final boolean rhs = handleIfRecursive(false);
+ ifValue = false;
+ }
+ break;
+ case '+':
+ {
+ // NOTE: we don't handle expressions like this properly
+ final boolean rhs = handleIfRecursive(false);
+ ifValue = false;
+ }
+ break;
+ case '-':
+ {
+ // NOTE: we don't handle expressions like this properly
+ final boolean rhs = handleIfRecursive(false);
+ ifValue = false;
+ }
+ break;
case '=':
{
// NOTE: we don't handle expressions like this properly
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 75ef808..6e56a49 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -65,11 +65,12 @@ public class BaseClass extends SingletonJunitCase {
Assert.assertNotNull(ifName+" does not exist", clazzIf);
Assert.assertNotNull(implName+" does not exist", clazzImpl);
- Assert.assertEquals(1, clazzIf.getDeclaredField("CONSTANT_ONE").get(null));
+ Assert.assertNotNull(clazzImpl.getDeclaredMethod("nopTest"));
final Object obj = clazzImpl.newInstance();
Assert.assertTrue("Not of type "+ifName, clazzIf.isAssignableFrom(obj.getClass()));
- Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.generation.Bindingtest1", (obj instanceof com.jogamp.gluegen.test.junit.generation.Bindingtest1));
+ Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.generation.Bindingtest1",
+ (obj instanceof com.jogamp.gluegen.test.junit.generation.Bindingtest1));
}
/**
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg
index 6ef171b..b8582a8 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg
@@ -6,6 +6,8 @@ NativeOutputDir native
Extends Bindingtest1p1 Bindingtest1
+ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/com/jogamp/gluegen/test/junit/generation/Bindingtest1.java
+
Include test1-common.cfg
Import com.jogamp.gluegen.test.junit.generation.Bindingtest1
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg
index 708bd26..eb9fdcf 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg
@@ -6,6 +6,8 @@ NativeOutputDir native
Extends Bindingtest1p2 Bindingtest1
+ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/com/jogamp/gluegen/test/junit/generation/Bindingtest1.java
+
# Use a ProcAddressTable so we dynamically look up the routines
EmitProcAddressTable true
ProcAddressTableClassName Bindingtest1p2ProcAddressTable