summaryrefslogtreecommitdiffstats
path: root/src/java/com/sun
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/sun')
-rw-r--r--src/java/com/sun/gluegen/GlueGen.java17
-rw-r--r--src/java/com/sun/gluegen/ant/GlueGenTask.java24
-rw-r--r--src/java/com/sun/gluegen/pcpp/PCPP.java44
3 files changed, 72 insertions, 13 deletions
diff --git a/src/java/com/sun/gluegen/GlueGen.java b/src/java/com/sun/gluegen/GlueGen.java
index aac5319..866f602 100644
--- a/src/java/com/sun/gluegen/GlueGen.java
+++ b/src/java/com/sun/gluegen/GlueGen.java
@@ -84,13 +84,13 @@ public class GlueGen implements GlueEmitterControls {
@SuppressWarnings("unchecked")
- public void run(final Reader reader, final String filename, Class<?> emitterClass, List<String> includePaths, List<String> cfgFiles, String outputRootDir) {
+ public void run(final Reader reader, final String filename, Class<?> emitterClass, List<String> includePaths, List<String> cfgFiles, String outputRootDir, boolean debug) {
try {
final PipedInputStream ppIn = new PipedInputStream();
final PipedOutputStream ppOut = new PipedOutputStream(ppIn);
- preprocessor = new PCPP(includePaths);
+ preprocessor = new PCPP(includePaths, debug);
preprocessor.setOut(ppOut);
new Thread("PCPP") {
@@ -136,9 +136,12 @@ public class GlueGen implements GlueEmitterControls {
// walk that tree
headerParser.translationUnit(parser.getAST());
+ /**
// For debugging: Dump type dictionary and struct dictionary to System.err
- //td.dumpDictionary(err, "All Types");
- //sd.dumpDictionary(err, "All Structs");
+ if(debug) {
+ td.dumpDictionary(err, "All Types");
+ sd.dumpDictionary(err, "All Structs");
+ } */
// At this point we have all of the pieces we need in order to
// generate glue code: the #defines to constants, the set of
@@ -306,6 +309,7 @@ public class GlueGen implements GlueEmitterControls {
String emitterFQN = null;
String outputRootDir = null;
List<String> cfgFiles = new ArrayList<String>();
+ boolean debug = false;
List<String> includePaths = new ArrayList<String>();
for (int i = 0; i < args.length; i++) {
@@ -320,6 +324,8 @@ public class GlueGen implements GlueEmitterControls {
emitterFQN = arg.substring(2);
} else if (arg.startsWith("-C")) {
cfgFiles.add(arg.substring(2));
+ } else if (arg.equals("--debug")) {
+ debug=true;
} else {
usage();
}
@@ -344,7 +350,7 @@ public class GlueGen implements GlueEmitterControls {
try {
Class<?> emitterClass = emitterFQN == null ? null : Class.forName(emitterFQN);
- new GlueGen().run(reader, filename, emitterClass, includePaths, cfgFiles, outputRootDir);
+ new GlueGen().run(reader, filename, emitterClass, includePaths, cfgFiles, outputRootDir, debug);
} catch (ClassNotFoundException ex) {
throw new RuntimeException("specified emitter class was not in the classpath", ex);
}
@@ -367,6 +373,7 @@ public class GlueGen implements GlueEmitterControls {
out.println("declarations) to standard output. Emitter-specific configuration");
out.println("file or files can be specified with -C option; e.g,");
out.println("-Cjava-emitter.cfg.");
+ out.println(" --debug enables debug mode");
exit(1);
}
}
diff --git a/src/java/com/sun/gluegen/ant/GlueGenTask.java b/src/java/com/sun/gluegen/ant/GlueGenTask.java
index af42392..cc66c64 100644
--- a/src/java/com/sun/gluegen/ant/GlueGenTask.java
+++ b/src/java/com/sun/gluegen/ant/GlueGenTask.java
@@ -71,7 +71,8 @@ import org.apache.tools.ant.util.JavaEnvUtils;
includeRefid="[optional FileSet or DirSet for include files]"
literalInclude="[optional hack to get around FileSet / DirSet issues with different drives]"
emitter="[emitter class name]"
- config="[configuration file]" /&gt;
+ config="[configuration file]"
+ debug="[optional boolean]" /&gt;
* </pre>
*
* @author Rob Grzywinski <a href="mailto:[email protected]">[email protected]</a>
@@ -94,6 +95,11 @@ public class GlueGenTask extends Task
// =========================================================================
/**
+ * <p>The optional debug flag.</p>
+ */
+ private boolean debug=false;
+
+ /**
* <p>The optional output root dir.</p>
*/
private String outputRootDir;
@@ -160,6 +166,17 @@ public class GlueGenTask extends Task
// ANT getters and setters
/**
+ * <p>Set the debug flag (optional). This is called by ANT.</p>
+ *
+ * @param outputRootDir the optional output root dir
+ */
+ public void setDebug(boolean debug)
+ {
+ log( ("Setting debug flag: " + debug), Project.MSG_VERBOSE);
+ this.debug=debug;
+ }
+
+ /**
* <p>Set the output root dir (optional). This is called by ANT.</p>
*
* @param outputRootDir the optional output root dir
@@ -418,6 +435,11 @@ public class GlueGenTask extends Task
// NOTE: GlueGen uses concatenated flag / value rather than two
// separate arguments
+ // add the debug flag if enabled
+ if(debug) {
+ gluegenCommandline.createArgument().setValue("--debug");
+ }
+
// add the output root dir
if(null!=outputRootDir && outputRootDir.trim().length()>0) {
gluegenCommandline.createArgument().setValue("-O" + outputRootDir);
diff --git a/src/java/com/sun/gluegen/pcpp/PCPP.java b/src/java/com/sun/gluegen/pcpp/PCPP.java
index 26c4f27..cced7a6 100644
--- a/src/java/com/sun/gluegen/pcpp/PCPP.java
+++ b/src/java/com/sun/gluegen/pcpp/PCPP.java
@@ -67,8 +67,6 @@ 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
evaluate certain very simple definitions (to properly handle
OpenGL's gl.h) but preserve the text of definitions evaluating
@@ -84,9 +82,12 @@ public class PCPP {
private ParseState state;
- public PCPP(List<String> includePaths) {
+ private boolean enableDebugPrint;
+
+ public PCPP(List<String> includePaths, boolean debug) {
this.includePaths = includePaths;
setOut(System.out);
+ enableDebugPrint = debug;
}
public void run(Reader reader, String filename) throws IOException {
@@ -297,6 +298,11 @@ public class PCPP {
return new String(new char[] { c });
}
+ private String nextWordOrString() throws IOException {
+ nextToken();
+ return curTokenAsString();
+ }
+
private String nextWord() throws IOException {
int val = nextToken();
if (val != StreamTokenizer.TT_WORD) {
@@ -386,7 +392,13 @@ public class PCPP {
private void preprocessorDirective() throws IOException {
String w = nextWord();
boolean shouldPrint = true;
- if (w.equals("define")) {
+ if (w.equals("warning")) {
+ handleWarning();
+ shouldPrint = false;
+ } else if (w.equals("error")) {
+ handleError();
+ shouldPrint = false;
+ } else if (w.equals("define")) {
handleDefine();
shouldPrint = false;
} else if (w.equals("undef")) {
@@ -446,6 +458,20 @@ public class PCPP {
}
}
+ private void handleWarning() throws IOException {
+ String msg = nextWordOrString();
+ if (enabled()) {
+ LOG.log(WARNING, "#warning {0} at \"{1}\" line \"{2}\"", new Object[]{msg, filename(), lineNumber()});
+ }
+ }
+
+ private void handleError() throws IOException {
+ String msg = nextWordOrString();
+ if (enabled()) {
+ LOG.log(WARNING, "#error {0} at \"{1}\" line \"{2}\"", new Object[]{msg, filename(), lineNumber()});
+ }
+ }
+
private void handleDefine() throws IOException {
// (workaround for not having a lookahead)
@@ -752,7 +778,7 @@ public class PCPP {
if (!isIf) {
popEnableBit();
}
- pushEnableBit(enabled() && defineEvaluatedToTrue == isIf);
+ pushEnableBit(enabled() && defineEvaluatedToTrue);
//System.out.println("OUT HANDLE_" + (isIf ? "IF" : "ELIF") +" (evaluated to " + defineEvaluatedToTrue + ")");
}
@@ -959,7 +985,7 @@ public class PCPP {
private static int debugPrintIndentLevel = 0;
private void debugPrint(boolean onlyPrintIfEnabled, String msg) {
- if (disableDebugPrint) {
+ if (!enableDebugPrint) {
return;
}
@@ -1033,12 +1059,14 @@ public class PCPP {
System.out.println("Minimal pseudo-C-preprocessor.");
System.out.println("Output goes to standard output. Standard input can be used as input");
System.out.println("by passing '-' as the argument.");
+ System.out.println(" --debug enables debug mode");
System.exit(1);
}
public static void main(String[] args) throws IOException {
Reader reader = null;
String filename = null;
+ boolean debug = false;
if (args.length == 0) {
usage();
@@ -1053,6 +1081,8 @@ public class PCPP {
for (int j = 0; j < paths.length; j++) {
includePaths.add(paths[j]);
}
+ } else if (arg.equals("--debug")) {
+ debug = true;
} else {
usage();
}
@@ -1071,7 +1101,7 @@ public class PCPP {
}
}
- new PCPP(includePaths).run(reader, filename);
+ new PCPP(includePaths, debug).run(reader, filename);
}
}