From bbe2b65e129e04755669396c0340c71e2c6fa09c Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 17 May 2015 10:51:52 -0400 Subject: [PATCH] remove sketchXxxx() overrides, move size() statement to settings, cleanup AST code --- core/todo.txt | 2 +- java/src/processing/mode/java/JavaBuild.java | 34 ++++++++--------- .../mode/java/preproc/PdePreprocessor.java | 38 ++++++++++++++----- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/core/todo.txt b/core/todo.txt index 5a3a10ccd..35c2fe023 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -129,7 +129,7 @@ _ args[] should be null if none passed (otherwise args == null checks are weird) full screen -_ Fullscreen window on second monitor without using present mode +_ Full screen window on second monitor without using present mode _ https://github.com/processing/processing/issues/3271 _ "run sketches on display" not working in 3.0a7 _ https://github.com/processing/processing/issues/3264 diff --git a/java/src/processing/mode/java/JavaBuild.java b/java/src/processing/mode/java/JavaBuild.java index fb49d3827..87027321d 100644 --- a/java/src/processing/mode/java/JavaBuild.java +++ b/java/src/processing/mode/java/JavaBuild.java @@ -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(); diff --git a/java/src/processing/mode/java/preproc/PdePreprocessor.java b/java/src/processing/mode/java/preproc/PdePreprocessor.java index f759dae3d..882ea0142 100644 --- a/java/src/processing/mode/java/preproc/PdePreprocessor.java +++ b/java/src/processing/mode/java/preproc/PdePreprocessor.java @@ -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(); } } \ No newline at end of file