mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 19:31:16 +01:00
remove sketchXxxx() overrides, move size() statement to settings, cleanup AST code
This commit is contained in:
@@ -245,25 +245,21 @@ public class JavaBuild {
|
||||
}
|
||||
}
|
||||
|
||||
// // initSketchSize() sets the internal sketchWidth/Height/Renderer vars
|
||||
// // in the preprocessor. Those are used in preproc.write() so that they
|
||||
// // can be turned into sketchXxxx() methods.
|
||||
// // This also returns the size info as an array so that we can figure out
|
||||
// // if this fella is OpenGL, and if so, to add the import. It's messy and
|
||||
// // gross and someday we'll just always include OpenGL.
|
||||
// String[] sizeInfo =
|
||||
// initSketchSize() sets the internal sketchWidth/Height/Renderer vars
|
||||
// in the preprocessor. Those are used in preproc.write() so that they
|
||||
// can be used to add methods (settings() or sketchXxxx())
|
||||
String[] sizeParts =
|
||||
preprocessor.initSketchSize(sketch.getMainProgram(), sizeWarning);
|
||||
// //PdePreprocessor.parseSketchSize(sketch.getMainProgram(), false);
|
||||
// if (sizeInfo != null) {
|
||||
// String sketchRenderer = sizeInfo[3];
|
||||
// if (sketchRenderer != null) {
|
||||
// if (sketchRenderer.equals("P2D") ||
|
||||
// sketchRenderer.equals("P3D") ||
|
||||
// sketchRenderer.equals("OPENGL")) {
|
||||
// bigCode.insert(0, "import processing.opengl.*; ");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//System.out.format("size() is '%s'%n", info[0]);
|
||||
|
||||
// Remove the size() statement (will be added back by writeFooter())
|
||||
if (sizeParts != null) {
|
||||
String sizeStatement = sizeParts[0];
|
||||
if (sizeStatement != null) {
|
||||
int index = bigCode.indexOf(sizeStatement);
|
||||
bigCode.delete(index, index + sizeStatement.length());
|
||||
}
|
||||
}
|
||||
|
||||
PreprocessorResult result;
|
||||
try {
|
||||
@@ -1833,7 +1829,7 @@ public class JavaBuild {
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error in file " + pieces[i]);
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -939,6 +939,15 @@ public class PdePreprocessor {
|
||||
}
|
||||
|
||||
if ((mode == Mode.STATIC) || (mode == Mode.ACTIVE)) {
|
||||
// doesn't remove the oriiginal size() method, but calling size()
|
||||
// again in setup() is harmless.
|
||||
if (!hasMethod("settings") && sizeStatement != null) {
|
||||
out.println(indent + "public void settings() { " + sizeStatement + " }");
|
||||
// out.println(indent + "public void settings() {");
|
||||
// out.println(indent + indent + sizeStatement);
|
||||
// out.println(indent + "}");
|
||||
}
|
||||
/*
|
||||
if (sketchWidth != null && !hasMethod("sketchWidth")) {
|
||||
// Only include if it's a number (a variable will be a problem)
|
||||
if (PApplet.parseInt(sketchWidth, -1) != -1 || sketchWidth.equals("displayWidth")) {
|
||||
@@ -960,6 +969,7 @@ public class PdePreprocessor {
|
||||
if (sketchOutputPath != null && !hasMethod("sketchOutputPath")) {
|
||||
out.println(indent + "public String sketchOutputPath() { return " + sketchOutputPath + "; }");
|
||||
}
|
||||
*/
|
||||
|
||||
if (!hasMethod("main")) {
|
||||
out.println(indent + "static public void main(String[] passedArgs) {");
|
||||
@@ -1036,6 +1046,10 @@ public class PdePreprocessor {
|
||||
// return pkg.startsWith("processing.xml.");
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/**
|
||||
* Find the first CLASS_DEF node in the tree, and return the name of the
|
||||
* class in question.
|
||||
@@ -1049,11 +1063,13 @@ public class PdePreprocessor {
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
public void debugAST(final AST ast, final boolean includeHidden) {
|
||||
System.err.println("------------------");
|
||||
debugAST(ast, includeHidden, 0);
|
||||
}
|
||||
|
||||
|
||||
private void debugAST(final AST ast, final boolean includeHidden,
|
||||
final int indent) {
|
||||
for (int i = 0; i < indent; i++)
|
||||
@@ -1073,23 +1089,24 @@ public class PdePreprocessor {
|
||||
debugAST(kid, includeHidden, indent + 1);
|
||||
}
|
||||
|
||||
|
||||
private String debugHiddenAfter(AST ast) {
|
||||
if (!(ast instanceof antlr.CommonASTWithHiddenTokens))
|
||||
return "";
|
||||
return debugHiddenTokens(((antlr.CommonASTWithHiddenTokens) ast)
|
||||
.getHiddenAfter());
|
||||
return (ast instanceof antlr.CommonASTWithHiddenTokens) ?
|
||||
debugHiddenTokens(((antlr.CommonASTWithHiddenTokens) ast).getHiddenAfter()) : "";
|
||||
}
|
||||
|
||||
private String debugHiddenBefore(AST ast) {
|
||||
if (!(ast instanceof antlr.CommonASTWithHiddenTokens))
|
||||
if (!(ast instanceof antlr.CommonASTWithHiddenTokens)) {
|
||||
return "";
|
||||
antlr.CommonHiddenStreamToken child = null, parent = ((antlr.CommonASTWithHiddenTokens) ast)
|
||||
.getHiddenBefore();
|
||||
}
|
||||
antlr.CommonHiddenStreamToken parent =
|
||||
((antlr.CommonASTWithHiddenTokens) ast).getHiddenBefore();
|
||||
|
||||
if (parent == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
antlr.CommonHiddenStreamToken child = null;
|
||||
do {
|
||||
child = parent;
|
||||
parent = child.getHiddenBefore();
|
||||
@@ -1098,15 +1115,18 @@ public class PdePreprocessor {
|
||||
return debugHiddenTokens(child);
|
||||
}
|
||||
|
||||
|
||||
private String debugHiddenTokens(antlr.CommonHiddenStreamToken t) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (; t != null; t = filter.getHiddenAfter(t)) {
|
||||
if (sb.length() == 0)
|
||||
if (sb.length() == 0) {
|
||||
sb.append("[");
|
||||
}
|
||||
sb.append(t.getText().replace("\n", "\\n"));
|
||||
}
|
||||
if (sb.length() > 0)
|
||||
if (sb.length() > 0) {
|
||||
sb.append("]");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user