Cleanup a bit

This commit is contained in:
jdf
2010-03-15 19:59:42 +00:00
parent 3e3364f4f0
commit 3a2185333e
2 changed files with 23 additions and 32 deletions
+1 -13
View File
@@ -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
@@ -125,11 +125,10 @@ import antlr.collections.*;
* <P/>
*/
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