From 3a2185333e0ea81494a02b2e006dbb8513113507 Mon Sep 17 00:00:00 2001 From: jdf Date: Mon, 15 Mar 2010 19:59:42 +0000 Subject: [PATCH] Cleanup a bit --- app/src/processing/app/Sketch.java | 14 +------ .../app/preproc/PdePreprocessor.java | 41 ++++++++++--------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 4feb3effa..19f296569 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1245,7 +1245,7 @@ public class Sketch { bigCount += sc.getLineCount(); } } - + // Note that the headerOffset isn't applied until compile and run, because // it only applies to the code after it's been written to the .java file. int headerOffset = 0; @@ -1267,25 +1267,13 @@ public class Sketch { String primaryClassName = null; try { - // if (i != 0) preproc will fail if a pde file is not - // java mode, since that's required final String className = preprocessor.write(); - if (className == null) { throw new RunnerException("Could not find main class"); - // this situation might be perfectly fine, - // (i.e. if the file is empty) - //System.out.println("No class found in " + code[i].name); - //System.out.println("(any code in that file will be ignored)"); - //System.out.println(); - -// } else { -// code[0].setPreprocName(className + ".java"); } // store this for the compiler and the runtime primaryClassName = className; - } catch (antlr.RecognitionException re) { // re also returns a column that we're not bothering with for now diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index f4e9ee158..0fd725a6b 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -125,11 +125,10 @@ import antlr.collections.*; *

*/ public class PdePreprocessor { - + // used for calling the ASTFactory to get the root node private static final int ROOT_ID = 0; - // these ones have the .* at the end, since a class name might be at the end // instead of .* which would make trouble other classes using this can lop // off the . and anything after it to produce a package name consistently. @@ -149,28 +148,31 @@ public class PdePreprocessor { // starts as sketch name, ends as main class name private String name; - private TokenStreamCopyingHiddenTokenFilter filter; private boolean foundMain; + public void setFoundMain(boolean foundMain) { this.foundMain = foundMain; } + public boolean getFoundMain() { return foundMain; } - + private String advClassName = ""; + public void setAdvClassName(final String advClassName) { this.advClassName = advClassName; } - + private ProgramType programType; + public void setProgramType(final ProgramType programType) { // System.err.println("Setting program type to " + programType); this.programType = programType; } - + public PdePreprocessor() { char[] indentChars = new char[Preferences.getInteger("editor.tabs.size")]; Arrays.fill(indentChars, ' '); @@ -180,11 +182,11 @@ public class PdePreprocessor { CommonHiddenStreamToken getHiddenAfter(final CommonHiddenStreamToken t) { return filter.getHiddenAfter(t); } - + CommonHiddenStreamToken getInitialHiddenToken() { return filter.getInitialHiddenToken(); } - + public int writePrefix(String program, String buildPath, String sketchName, String codeFolderPackages[]) throws FileNotFoundException { @@ -386,21 +388,22 @@ public class PdePreprocessor { if (name == null) return null; - // output the code - PdeEmitter emitter = new PdeEmitter(this, stream); writeDeclaration(stream, name); - emitter.print(rootNode); - - // debugAST(rootNode, true); - // final ByteArrayOutputStream buf = new ByteArrayOutputStream(); - // final PrintStream bufout = new PrintStream(buf); - // emitter.setOut(bufout); - // emitter.print(rootNode); - // System.err.println(new String(buf.toByteArray())); - + new PdeEmitter(this, stream).print(rootNode); writeFooter(stream, name); stream.close(); + + if (false) { + final ByteArrayOutputStream buf = new ByteArrayOutputStream(); + final PrintStream bufout = new PrintStream(buf); + writeDeclaration(bufout, name); + new PdeEmitter(this, bufout).print(rootNode); + writeFooter(bufout, name); + debugAST(rootNode, true); + System.err.println(new String(buf.toByteArray())); + } + // if desired, serialize the parse tree to an XML file. can // be viewed usefully with Mozilla or IE