diff --git a/app/PdeCompilerJavac.java b/app/PdeCompilerJavac.java deleted file mode 100755 index c5f9c4edd..000000000 --- a/app/PdeCompilerJavac.java +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - PdeCompilerJavac - compiler interface to kjc.. someday this will go away - Part of the Processing project - http://processing.org - - Except where noted, code is written by Ben Fry and - Copyright (c) 2001-03 Massachusetts Institute of Technology - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - -/* - - -import java.io.*; - - -// this class is incomplete. it was added in an attempt to support -// mac os 9, but the javac for jdk 1.1 doesn't seem to like the -// file format of the classes produced by jikes, which is revision -// 57 code instead of rev 55. - -// using jikes -target 1.1 doesn't seem to help. the next attempt -// was to use javac from the 1.1 jdk, which i attempted to hack -// into the bagel build scripts, but javac actually crashed (not -// just and exception, but an application crash) whenever used -// (especially if called on long paths/from another directory). - -// there are plenty of ways to address this, but for the time being, -// it's not worth the time so we'll just suspend macos9 support. - -public class PdeCompilerJavac extends PdeCompiler { - - public PdeCompilerJavac(String buildPath, String className, - File includeFolder, PdeEditor editor) { - super(buildPath, className, includeFolder, editor); - } - - public boolean compileJava(PrintStream leechErr) { - - // probably not needed with javac - //System.setErr(leechErr); // redirect stderr to our leech filter - - int argc = 0; - String args[] = new String[4]; - args[argc++] = "-d"; - args[argc++] = buildPath; - args[argc++] = "-nowarn"; - args[argc++] = buildPath + File.separator + className + ".java"; - //System.out.println("args = " + args[0] + " " + args[1]); - - System.out.println("compiling with javac"); - return new sun.tools.javac.Main(leechErr, "javac").compile(args); - - // probably not needed with javac - //System.setErr(PdeEditorConsole.consoleErr); - - //System.err.println("success = " + success); - //return success; - } - - // part of the PdeMessageConsumer interface - // - public void message(String s) { - System.out.println("javac msg: " + s); - - // as in: lib\build\Temporary_5476_6442.java:88: caution:Assignment of an expression to itself [KOPI] - if (s.indexOf("caution") != -1) return; - - // - //System.out.println("leech2: " + new String(b, offset, length)); - //String s = new String(b, offset, length); - //if (s.indexOf(tempFilename) == 0) { - String fullTempFilename = buildPath + File.separator + className + ".java"; - if (s.indexOf(fullTempFilename) == 0) { - String s1 = s.substring(fullTempFilename.length() + 1); - int colon = s1.indexOf(':'); - int lineNumber = Integer.parseInt(s1.substring(0, colon)); - //System.out.println("pde / line number: " + lineNumber); - - //String s2 = s1.substring(colon + 2); - int err = s1.indexOf("error:"); - if (err != -1) { - //err += "error:".length(); - String description = s1.substring(err + "error:".length()); - description = description.trim(); - - // as in: ...error:Constructor setup must be named Temporary_5362_2548 [JL1 8.6] - if(description.indexOf("Constructor setup must be named") != -1) { - description = "Missing function return type, or constructor does not match class name"; - } - //exception = new PdeException(description, lineNumber-2); - exception = new PdeException(description, lineNumber-1); - editor.error(exception); - - } else { - System.err.println("i suck: " + s); - } - - } else { - //System.err.println("don't understand: " + s); - exception = new PdeException(SUPER_BADNESS); - editor.error(exception); - } - } -} - - -*/ \ No newline at end of file diff --git a/app/preproc/.cvsignore b/app/preproc/.cvsignore new file mode 100644 index 000000000..b010c249c --- /dev/null +++ b/app/preproc/.cvsignore @@ -0,0 +1,9 @@ +*Lexer.java +*Recognizer.java +*TokenTypes.java +*TokenTypes.txt +*TreeParser.java +*TreeParserTokenTypes.java +*TreeParserTokenTypes.txt +expanded*.g + diff --git a/app/preproc/ExtendedCommonASTWithHiddenTokens.java b/app/preproc/ExtendedCommonASTWithHiddenTokens.java new file mode 100644 index 000000000..43519e89c --- /dev/null +++ b/app/preproc/ExtendedCommonASTWithHiddenTokens.java @@ -0,0 +1,132 @@ +package antlr; + +/* ANTLR Translator Generator + * Project led by Terence Parr at http://www.jGuru.com + * Software rights: http://www.antlr.org/RIGHTS.html + * + * $Id$ + */ + +import java.io.*; +import antlr.*; +import antlr.collections.*; +import antlr.collections.impl.*; + +/** A CommonAST whose initialization copies hidden token + * information from the Token used to create a node. + */ +public class ExtendedCommonASTWithHiddenTokens + extends CommonASTWithHiddenTokens { + + public ExtendedCommonASTWithHiddenTokens() { + super(); + } + + public ExtendedCommonASTWithHiddenTokens(Token tok) { + super(tok); + } + + public void initialize(AST ast) { + ExtendedCommonASTWithHiddenTokens a = + (ExtendedCommonASTWithHiddenTokens)ast; + super.initialize(a); + hiddenBefore = a.getHiddenBefore(); + hiddenAfter = a.getHiddenAfter(); + } + + public String getHiddenAfterString() { + + CommonHiddenStreamToken t; + StringBuffer hiddenAfterString = new StringBuffer(100); + + for ( t = hiddenAfter ; t != null ; t = t.getHiddenAfter() ) { + hiddenAfterString.append(t.getText()); + } + + return hiddenAfterString.toString(); + } + + public String getHiddenBeforeString() { + + antlr.CommonHiddenStreamToken + child = null, + parent = hiddenBefore; + + // if there aren't any hidden tokens here, quietly return + // + if (parent == null) { + return ""; + } + + // traverse back to the head of the list of tokens before this node + do { + child = parent; + parent = child.getHiddenBefore(); + } while (parent != null); + + // dump that list + + StringBuffer hiddenBeforeString = new StringBuffer(100); + + for ( CommonHiddenStreamToken t = child; t != null ; + t = t.getHiddenAfter() ) { + hiddenBeforeString.append(t.getText()); + } + + return hiddenBeforeString.toString(); + } + + public void xmlSerializeNode(Writer out) + throws IOException { + StringBuffer buf = new StringBuffer(100); + buf.append("<"); + buf.append(getClass().getName() + " "); + + buf.append("hiddenBeforeString=\"" + + encode(getHiddenBeforeString()) + + "\" text=\"" + encode(getText()) + "\" type=\"" + + getType() + "\" hiddenAfterString=\"" + + encode(getHiddenAfterString()) + "\"/>"); + out.write(buf.toString()); + } + + public void xmlSerializeRootOpen(Writer out) + throws IOException { + StringBuffer buf = new StringBuffer(100); + buf.append("<"); + buf.append(getClass().getName() + " "); + buf.append("hiddenBeforeString=\"" + + encode(getHiddenBeforeString()) + + "\" text=\"" + encode(getText()) + "\" type=\"" + + getType() + "\" hiddenAfterString=\"" + + encode(getHiddenAfterString()) + "\">\n"); + out.write(buf.toString()); + } + + public void xmlSerializeRootClose(Writer out) + throws IOException { + out.write("\n"); + } + + public void xmlSerialize(Writer out) throws IOException { + // print out this node and all siblings + for (AST node = this; + node != null; + node = node.getNextSibling()) { + if (node.getFirstChild() == null) { + // print guts (class name, attributes) + ((BaseAST)node).xmlSerializeNode(out); + } + else { + ((BaseAST)node).xmlSerializeRootOpen(out); + + // print children + ((BaseAST)node.getFirstChild()).xmlSerialize(out); + + // print end tag + ((BaseAST)node).xmlSerializeRootClose(out); + } + } + } + +} diff --git a/app/preproc/PdeEmitter.java b/app/preproc/PdeEmitter.java new file mode 100644 index 000000000..57c014f84 --- /dev/null +++ b/app/preproc/PdeEmitter.java @@ -0,0 +1,922 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +package processing.app.preproc; + +import processing.app.*; + + +/* Based on original code copyright (c) 2003 Andy Tripp . + * shipped under GPL with permission. + */ + +import antlr.*; +import antlr.collections.*; +import antlr.collections.impl.*; +import java.io.*; +import java.util.*; + +/** + * PDEEmitter: A class that can take an ANTLR Java AST and produce + * reasonably formatted Java code from it. To use it, create a + * PDEEmitter object, call setOut() if you want to print to something + * other than System.out, and then call print(), passing the + * AST. Typically, the AST node that you pass would be the root of a + * tree - the ROOT_ID node that represents a Java file. + */ + +public class PdeEmitter implements PdeTokenTypes +{ + private PrintStream out = System.out; + private PrintStream debug = System.err; + private static int ALL = -1; + private java.util.Stack stack = new java.util.Stack(); + private static String[] tokenNames; + private final static int ROOT_ID = 0; + static { + setupTokenNames(); + } + + /* + private static Hashtable publicMethods; + private static final String publicMethodList[] = { + "setup", "draw", //"loop", + "mousePressed", "mouseReleased", "mouseClicked", + "mouseEntered", "mouseExited", + "mouseMoved", "mouseDragged", + "keyPressed", "keyReleased", "keyTyped" + }; + + static { + publicMethods = new Hashtable(); + for (int i = 0; i < publicMethodList.length; i++) { + publicMethods.put(publicMethodList[i], new Object()); + } + } + */ + + // Map each AST token type to a String + private static void setupTokenNames() { + tokenNames = new String[200]; + for (int i=0; i