diff --git a/src/edu/berkeley/cs/tedd/BshTest.java b/src/edu/berkeley/cs/tedd/BshTest.java deleted file mode 100644 index fc5b0f4..0000000 --- a/src/edu/berkeley/cs/tedd/BshTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.berkeley.cs.tedd; -import bsh.EvalError; -import bsh.Interpreter; - -import java.util.Date; - -/** - * Created by IntelliJ IDEA. - * User: ksen - * Date: 7/5/11 - * Time: 3:53 PM - * To change this template use File | Settings | File Templates. - */ -public class BshTest { - public static void main(String[] args) throws EvalError { - - Interpreter i = new Interpreter(); // Construct an interpreter - i.set("foo", 5); // Set variables - i.set("date", new Date() ); - - Date date = (Date)i.get("date"); // retrieve a variable - - i.eval("bar = foo*10"); - System.out.println( i.get("bar") ); - - - } - -} diff --git a/src/edu/berkeley/cs/tedd/core/CallStack.java b/src/edu/berkeley/cs/tedd/core/CallStack.java deleted file mode 100644 index 34ec9a2..0000000 --- a/src/edu/berkeley/cs/tedd/core/CallStack.java +++ /dev/null @@ -1,122 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import bsh.NameSpace; -import bsh.Primitive; -import bsh.UtilEvalError; - -import java.util.Stack; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class CallStack { - StmtNode currentStmt; - private Function currentFunction; - private Stack functionStack; - private Stack stmtStack; - private Stack nameSpaceStack; - - public CallStack() { - currentStmt = new NonCondStmtNode("** Begin **"); - currentFunction = null; - functionStack = new Stack(); - stmtStack = new Stack(); - nameSpaceStack = new Stack(); - } - - public void reset(NameSpace nameSpace) { - nameSpaceStack.clear(); - stmtStack.clear(); - functionStack.clear(); - - currentStmt = new NonCondStmtNode("** Begin **"); - currentFunction = null; - nameSpaceStack.push(nameSpace); - - } - - public void push(Function fun, NameSpace oldNameSpace) { - functionStack.push(currentFunction); - currentFunction = fun; - stmtStack.push(currentStmt); - currentStmt = currentFunction.getRoot(); - - if (!fun.isInline()) { - NameSpace newNameSpace = new NameSpace(oldNameSpace,fun.getFunctionName()); - nameSpaceStack.push(newNameSpace); - } - - } - - public boolean pop() throws UtilEvalError { - if(!currentFunction.isInline()) { - nameSpaceStack.pop(); - } - if (stmtStack.peek() instanceof InvokeAssignStmtNode) { - Object returnVal; - returnVal = (currentStmt.lastValue==null)? Primitive.NULL:currentStmt.lastValue; - nameSpaceStack.peek().setVariable(((InvokeAssignStmtNode)stmtStack.peek()).lhs,returnVal,true); - } - boolean flag = currentFunction.isInline() && currentFunction.getFunctionName().equals(functionStack.peek().getFunctionName()); - currentFunction = functionStack.pop(); - currentStmt = stmtStack.pop(); - return flag; - - } - - public int size() { - return functionStack.size(); - } - - public String getPrompt() { - StringBuilder sb = new StringBuilder("%"); - for (Function fun:functionStack) { - if (fun!=null) { - String fName = fun.getFunctionName(); - sb.append(fName); - sb.append(":"); - } - } - if (currentFunction !=null) - sb.append(currentFunction.getSig()); - sb.append("%"); - return sb.toString(); - } - - public boolean isEmpty() { - return functionStack.isEmpty(); - } - - public NameSpace getNameSpace() { - return nameSpaceStack.peek(); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/CodingEngine.java b/src/edu/berkeley/cs/tedd/core/CodingEngine.java deleted file mode 100644 index ffcf4cb..0000000 --- a/src/edu/berkeley/cs/tedd/core/CodingEngine.java +++ /dev/null @@ -1,444 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import bsh.*; - -import java.io.*; -import java.util.*; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class CodingEngine implements Serializable { - private static final String globalFunctionNameVarName = "__tedd_functionName"; - private static final String globalArgumentsVarName = "__tedd_arguments"; - - public static String formatFixedWidth(long value, int width) { - String ret = value+""; - if (ret.length() functions; - Map mocks; - - private LinkedHashMap> tests; - private Interpreter currentInterpreter = null; - private String currentClass; - - private CallStack callStack; - private Console console; - - private LinkedHashSet watchList; - private Trace trace; - private boolean isTesting; - - private void commonInit() { - console = new Console(); - trace = new Trace(console); - callStack = new CallStack(); - currentInterpreter = null; - } - - public CodingEngine() { - functions = new HashMap(); - mocks = new HashMap(); - tests = new LinkedHashMap>(); - watchList = new LinkedHashSet(); - - commonInit(); - } - - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - out.writeObject(functions); - out.writeObject(mocks); - out.writeObject(tests); - out.writeObject(watchList); - } - - - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - functions = (HashMap) in.readObject(); - mocks = (HashMap) in.readObject(); - tests = (LinkedHashMap>) in.readObject(); - watchList = (LinkedHashSet) in.readObject(); - commonInit(); - } - - - - private void reset() throws EvalError { - trace.clear(); - currentInterpreter = createInterpreter(); - callStack.reset(currentInterpreter.getNameSpace()); - } - - private Interpreter createInterpreter() throws EvalError { - Interpreter ret = new Interpreter(); - ret.setStrictJava(true); - ret.eval("String " + globalFunctionNameVarName + " = null;"); - ret.eval("Object[] " + globalArgumentsVarName + " = null;"); - ret.eval("void invoke(String methodName, Object[] arguments) { global."+globalFunctionNameVarName+" = methodName; global."+globalArgumentsVarName+" = arguments; }"); - - return ret; - } - - private boolean handleFunctionCall() throws EvalError, TeddError, UtilEvalError { - String functionName = (String) currentInterpreter.get(globalFunctionNameVarName); - if (functionName==null) return false; - Function fun = functions.get(functionName); - if (fun==null) { - throw new TeddError("Function "+functionName+" is not declared."); - } - - callStack.push(fun,currentInterpreter.getNameSpace()); - - Object[] arguments = (Object[]) currentInterpreter.get(globalArgumentsVarName); - fun.setArguments(currentInterpreter,callStack.getNameSpace(),arguments); - currentInterpreter.eval("global.__tedd_functionName = null;"); - - - return true; - } - - private void handleFunctionReturn() throws EvalError, UtilEvalError { - if (callStack.currentStmt.isReturn()) { - boolean flag; - do { - flag = callStack.pop(); - if (callStack.isEmpty()) { - isTesting = false; - return; - } - } while(flag); - } - } - - public void declareFunction(String sig) throws TeddError { - Function ret = new Function(sig); - if(functions.containsKey(ret.getFunctionName())) { - throw new TeddError("Function "+sig+" already declared."); - } else { - functions.put(ret.getFunctionName(), ret); - System.out.println("Function "+sig+" declared."); - } - } - - public void unDeclareFunction(String sig) throws TeddError { - Function ret = new Function(sig); - if(functions.containsKey(ret.getFunctionName())) { - functions.remove(ret.getFunctionName()); - System.out.println("Function "+sig+" un-declared."); - } else { - throw new TeddError("Function " + sig + " is not declared."); - } - } - - private ArrayList getMocks(String sig) { - ArrayList ret; - ret = tests.get(sig); - if (ret==null) { - ret = new ArrayList(); - tests.put(sig,ret); - } - return ret; - } - - public void editFunction(String sig) throws TeddError, EvalError, UtilEvalError { - reset(); - isTesting = true; - currentInterpreter.eval(sig, callStack.getNameSpace()); - if (!handleFunctionCall()) { - throw new TeddError(sig + " must be declared."); - } else { - ArrayList mocks = getMocks(sig); - trace.setCurrentTest(sig,mocks); - trace.updateNext(callStack.size(), callStack.currentStmt); - } - } - - public void print() { - trace.print(callStack.size()); - printNext(); - } - - public void printNext() { - trace.printNext(callStack.size(),callStack.currentStmt); - } - - - public void setMock(String mockName) throws TeddError { - if (mockName!=null) { - Function ret = new Function("void "+mockName+"();"); - if(!mocks.containsKey(ret.getFunctionName())) { - mocks.put(ret.getFunctionName(), ret); - System.out.println("Mock "+mockName+" declared."); - } - } - trace.setMock(mockName); - trace.updateNext(callStack.size(), callStack.currentStmt); - } - - public void step() throws EvalError, TeddError, UtilEvalError { - if (isTesting) { - String mockName; - if ((mockName = trace.getMock())!=null) { - Function fun = mocks.get(mockName); - if (fun==null) { - throw new TeddError("Mock "+mockName+" is not found."); - } - callStack.currentStmt = fun.getRoot(); - System.out.println(trace.add(callStack.size(), new NonCondStmtNode("mock "+mockName))); - trace.updateNext(callStack.size(), callStack.currentStmt); - //System.out.println("Doing mock "+mockName); - } else if (callStack.currentStmt.nextStmt() != null) { - callStack.currentStmt = callStack.currentStmt.forward(currentInterpreter, callStack.getNameSpace()); - System.out.println(trace.add(callStack.size(), callStack.currentStmt)); - handleFunctionCall(); - handleFunctionReturn(); - trace.updateNext(callStack.size(), callStack.currentStmt); - } else { - throw new TeddError("No more statement to execute."); - } - } else { - throw new TeddError("Not in the middle of a test. use !test test-name to create a test."); - } - } - - private boolean isForwardPossible() { - return trace.getMock()!=null || callStack.currentStmt.nextStmt()!=null; - } - - public void next() throws EvalError, TeddError, UtilEvalError { - int depth = callStack.size(); - step(); - while (callStack.size()>depth && isForwardPossible()) { - step(); - } - } - - public void Continue() throws EvalError, TeddError, UtilEvalError { - while(isForwardPossible()) { - step(); - } - } - - public void rerun(int n) throws EvalError, TeddError, UtilEvalError { - editFunction(trace.getCurrentTest()); - if (n==-1) Continue(); - for(int i=0; i incomplete = new LinkedList(); - List failed = new LinkedList(); - List passed = new LinkedList(); - for(String test:tests.keySet()) { - System.out.println("*********************************"); - System.out.println("Testing "+test); - try { - editFunction(test); - Continue(); - if (isTesting) { - System.err.println("******** Test incomplete:\""+test+"\" ***********"); - incomplete.add(test); - } else { - System.out.println("******** Test passed ***********"); - passed.add(test); - } - } catch(EvalError ee) { - System.err.println("******** Test failed:\""+test+"\" ***********"); - System.err.println(ee); - ee.printStackTrace(); - failed.add(test); - } catch (TeddError te) { - System.err.println("I should not be here"); - System.err.println(te); - te.printStackTrace(); - System.exit(-1); - } catch (UtilEvalError utilEvalError) { - System.err.println("******** Test failed:\""+test+"\" ***********"); - System.err.println(utilEvalError); - utilEvalError.printStackTrace(); - failed.add(test); - } - - } - System.out.println("passed = " + passed); - System.out.println("incomplete = " + incomplete); - System.out.println("failed = " + failed); - } - - - public String getPrompt() { - return callStack.getPrompt(); - } - - public void list() { - System.out.println("******** Functions Declared *********"); - for(String fname:functions.keySet()) { - Function foo = functions.get(fname); - System.out.println(foo.getSig()); - } - System.out.println("*************************************"); - } - - - public void generate(String cname) throws IOException { - PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(cname+".java"))); - out.println("// auto generated class"); - out.println(); - out.print("public class "); - out.print(cname); - out.println(" {"); - for(String fname:functions.keySet()) { - functions.get(fname).generate(out,this); - out.println(); - } - - out.print(Function.tab); - out.println("public static void main(String args[]) {"); - for(String test:tests.keySet()) { - out.print(Function.tab); - out.print(Function.tab); - out.println(test); - } - out.print(Function.tab); - out.println("}"); - out.println("}"); - out.close(); - } - - public void dump(String filename) throws IOException { - ObjectOutputStream out; - out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename+".tedd"))); - out.writeObject(this); - out.close(); - } - - public void save() throws IOException, TeddError { - if (currentClass == null) { - throw new TeddError("Current class name is not set. Use saveas command."); - } else { - dump(currentClass); - generate(currentClass); - System.out.println("Saved."); - } - } - - public void saveas(String cname) throws IOException, TeddError { - if ((new File(cname+".java")).exists()) { - throw new TeddError(cname+".java already exists. Pick a different class name"); - } else { - currentClass = cname; - dump(currentClass); - generate(currentClass); - System.out.println("Saved."); - } - } - - public void setCurrentClass(String currentClass) { - this.currentClass = currentClass; - } - -} diff --git a/src/edu/berkeley/cs/tedd/core/Command.java b/src/edu/berkeley/cs/tedd/core/Command.java deleted file mode 100644 index 37d0f92..0000000 --- a/src/edu/berkeley/cs/tedd/core/Command.java +++ /dev/null @@ -1,46 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) - -public @interface Command { - public String value(); -} diff --git a/src/edu/berkeley/cs/tedd/core/Commands.java b/src/edu/berkeley/cs/tedd/core/Commands.java deleted file mode 100644 index 51b0acc..0000000 --- a/src/edu/berkeley/cs/tedd/core/Commands.java +++ /dev/null @@ -1,291 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import bsh.EvalError; -import bsh.UtilEvalError; -import jline.ConsoleReader; - -import java.io.*; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -public class Commands { - - private CodingEngine ce; - - @Command(": Execute next statement. Step over any declared function call in the statement.") - public void next(String arg) throws EvalError, TeddError, UtilEvalError { - ce.next(); - ce.changeWatchList(); - } - - @Command(": Execute next statement. Step into any declared function call in the statement.") - public void step(String arg) throws EvalError, TeddError, UtilEvalError { - ce.step(); - ce.changeWatchList(); - } - - @Command(": Rollback execution to the previous statement.") - public void previous(String arg) throws EvalError, TeddError, UtilEvalError { - ce.previous(); - ce.changeWatchList(); - } - - @Command(": Execute all the remaining statements.") - public void cont(String arg) throws EvalError, TeddError, UtilEvalError { - ce.Continue(); - ce.changeWatchList(); - } - -// @Command(": Restart the execution and execute all the statements.") -// public void rerun() throws EvalError, TeddError, UtilEvalError { -// rerun("-1"); -// } -// - @Command("n: Restart the execution and execute n statements. Example \"rerun 0\"") - public void rerun(String arg) throws EvalError, TeddError, UtilEvalError { - if (arg.length()==0) arg = "-1"; - int n = 0; - try { - n = Integer.parseInt(arg); - } catch (NumberFormatException e) { - n = 0; - } - ce.rerun(n); - ce.changeWatchList(); - } - - @Command("sig: Declare a new function to be defined. Example \"declare int foo(String bar, int v)\"") - public void declare(String sig) throws TeddError { - ce.declareFunction(sig); - } - - @Command("function-name: Undeclare the function function-name. Example \"undeclare foo\"") - public void undeclare(String fname) throws TeddError { - ce.unDeclareFunction(fname); - } - - @Command(": list all declared function names.") - public void list(String fname) { - ce.list(); - } - - @Command(": Remove next statement.") - public void remove(String arg) throws TeddError { - ce.remove(); - } - - @Command("statement: Insert and execute the next statement.") - public void insert(String arg) throws EvalError, TeddError, UtilEvalError { - ce.insert(arg); - ce.step(); - ce.changeWatchList(); - } - - @Command("statement: Replace the next statement.") - public void replace (String arg) throws TeddError { - ce.replace(arg); - } - - public void add(String arg) throws TeddError, EvalError, UtilEvalError { - ce.add(arg); - ce.step(); - ce.changeWatchList(); - } - - @Command("statement: Execute the statement, but do not add or insert the statement in the current function.") - public void execute(String arg) throws EvalError { - ce.execute(arg); - } - - - @Command(": print the statements executed so far in the current test.") - public void print(String arg) { - ce.print(); - } - - @Command("test-name: Declare and start executing the test function \"void test-name()\".") - public void test(String arg) throws EvalError, TeddError, UtilEvalError { - if (arg.length()==0) { - throw new TeddError("test-name is not provided."); - } else { - try { - ce.declareFunction("void "+arg+"();"); - } catch (TeddError te) { - System.out.println(te); - } - ce.editFunction(arg+"();"); - } - } - - @Command(": Test all tests declared so far.") - public void all(String arg) throws EvalError, TeddError { - ce.testAll(); - } - - @Command("expression: Print the value of the expression after every command.") - public void watch(String arg) { - ce.watch(arg); - } - - @Command(": Save the current program.") - public void save(String arg) throws IOException, TeddError { - ce.save(); - } - - @Command("file-name: Save the current program in the file-name.") - public void saveas(String arg) throws IOException, TeddError { - ce.saveas(arg); - } - - @Command("file-name: Open the file \"file-name\" as the current program.") - public void open(String arg) throws IOException, ClassNotFoundException { - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(arg+".tedd"))); - ce = (CodingEngine) in.readObject(); - ce.setCurrentClass(arg); - System.out.println("Loaded class "+arg); - } - - @Command("mock-name: Create and execute the mock mock-name.") - public void mock(String arg) throws TeddError, EvalError, UtilEvalError { - if (arg.length()==0) { - ce.setMock(null); - } else { - ce.setMock(arg); - ce.step(); - } - } - - - @Command(": print usage of this tool.") - public void usage(String arg) { - System.out.println("Usage:"); - System.out.println("\tstatement: add the statement as the next statement and execute."); - for (Method m : getClass().getMethods()) { - if (m.isAnnotationPresent(Command.class)) { - try { - Command annot = m.getAnnotation(Command.class); - if (annot != null) { - System.out.println("\t!"+m.getName()+" "+annot.value()); - } - } catch (Throwable ex) { - System.err.println(ex); - ex.printStackTrace(); - } - } - } - - } - - public void processCommand() throws IOException { - ConsoleReader br = new ConsoleReader(); - String line; - ce = new CodingEngine(); - - System.out.println(ce.getPrompt()); - while((line = br.readLine())!=null) { - String command, rest = ""; - if (line.startsWith("!")) { - line = line.substring(1); - int idx = line.indexOf(' '); - if (idx==-1) { - command = line.trim(); - } else { - command = line.substring(0,idx).trim(); - rest = line.substring(idx).trim(); - } - } else { - command = null; - rest = line.trim(); - } - try { - if (command==null) { - if (rest.length()>0) - add(rest); - } else { - boolean isFound = false; - for (Method m : getClass().getMethods()) { - if (m.isAnnotationPresent(Command.class)) { - if (m.getName().startsWith(command)) { - Object[] args = new Object[1]; - args[0] = rest; - isFound = true; - try { - m.invoke(this,args); - } catch (IllegalAccessException e) { - System.err.println("-----------------------------------"); - System.err.println(e); - e.printStackTrace(); - } catch (InvocationTargetException e) { - throw e.getTargetException(); - } - - break; - } - } - } - if (!isFound) { - System.out.println("Command not found: !"+line); - } - } - } catch (TeddError te) { - System.err.println(te); - } catch (Throwable e) { - System.err.println("-----------------------------------"); - System.err.println(e); - e.printStackTrace(); - } - ce.executeWatchList(); - System.out.println(ce.getPrompt()); - - } - - System.out.println("Goodbye!"); - - List hist = br.getHistory().getHistoryList(); - for(Object command:hist){ - System.out.println(command); - } - } - - - public static void main(String[] args) throws IOException { - Commands cmds = new Commands(); - System.out.println("type !usage to print usage of this tool."); - cmds.processCommand(); - System.exit(0); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/CondStmtNode.java b/src/edu/berkeley/cs/tedd/core/CondStmtNode.java deleted file mode 100644 index 15005ea..0000000 --- a/src/edu/berkeley/cs/tedd/core/CondStmtNode.java +++ /dev/null @@ -1,103 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import bsh.EvalError; -import bsh.Interpreter; -import bsh.NameSpace; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Serializable; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class CondStmtNode extends StmtNode { - StmtNode falseNextStmt; - StmtNode trueNextStmt; - //private boolean lastOutcome; - - - - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - out.writeObject(getStmt()); - out.writeObject(falseNextStmt); - out.writeObject(trueNextStmt); - } - - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - lastValue = true; - setStmt((String) in.readObject()); - falseNextStmt = (StmtNode)in.readObject(); - if (falseNextStmt !=null) falseNextStmt.setParent(this); - trueNextStmt = (StmtNode)in.readObject(); - if (trueNextStmt !=null) trueNextStmt.setParent(this); - } - - protected CondStmtNode(String stmt) { - super(stmt); - lastValue = true; - } - - @Override - public StmtNode nextStmt() { - return ((Boolean)lastValue)?trueNextStmt:falseNextStmt; - } - - @Override - protected void setNextStmt(StmtNode child) { - if ((Boolean)lastValue) - trueNextStmt = child; - else - falseNextStmt = child; - if(child!=null) { - child.setParent(this); - } - } - - @Override - public String toString() { - return ((Boolean)lastValue)?"since "+getStmt():"since !("+getStmt()+")"; - } - - @Override - public void printStmt(PrintWriter out, Function fun) { - int idx; - idx = getStmt().lastIndexOf(';'); - String ret = getStmt(); - if (idx >=0) { - ret = getStmt().substring(0, idx); - } - out.print(ret); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/Console.java b/src/edu/berkeley/cs/tedd/core/Console.java deleted file mode 100644 index 3b492dd..0000000 --- a/src/edu/berkeley/cs/tedd/core/Console.java +++ /dev/null @@ -1,126 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -import java.awt.*; -import java.io.*; -import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.text.Document; - -public class Console extends JFrame { - private JTextArea textArea = new JTextArea(); - private JTextArea watchArea1 = new JTextArea(); - private JTextArea watchArea2 = new JTextArea(); - private int rest; - - public Console(){ - rest = 0; - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - textArea.setEditable(false); - textArea.setRows(32); - textArea.setColumns(50); - getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); - watchArea1.setEditable(false); - watchArea1.setRows(5); - watchArea1.setColumns(25); - watchArea1.setBorder(BorderFactory.createTitledBorder("Previous Watch List")); - watchArea2.setEditable(false); - watchArea2.setRows(5); - watchArea2.setColumns(25); - watchArea2.setBorder(BorderFactory.createTitledBorder("Current Watch List")); - - - FlowLayout layout = new FlowLayout(); - JPanel south = new JPanel(layout); - getContentPane().add(south, BorderLayout.SOUTH); - - south.add(new JScrollPane(watchArea1)); - south.add(new JScrollPane(watchArea2)); - - pack(); - setVisible(true); - } - - public void addText(StatementTextWithDepth line) { - addText(line.toString()); - } - - public void clear() { - textArea.setText(""); - rest = 0; - } - - public void removeTail() { - int end = textArea.getDocument().getLength(); - if (rest <= end) { - textArea.replaceRange("",rest,end); - } - } - - public void addTail(StatementTextWithDepth line) { - addTail(line.toString()); - } - - public void addText(String s) { - textArea.append(s); - textArea.append("\n"); - rest = textArea.getDocument().getLength(); - textArea.setCaretPosition(rest); - } - - public void addTail(String s) { - textArea.append(s); - textArea.append("\n"); - textArea.setCaretPosition(textArea.getDocument().getLength()); - } - - public void changeWatch() { - try { - Document doc = watchArea2.getDocument(); - watchArea1.setText(doc.getText(0,doc.getLength())); - watchArea2.setText(""); - } catch(Exception e) { - System.err.println(e); - e.printStackTrace(); - } - } - - public void clearWatch() { - watchArea2.setText(""); - } - - public void addWatchText(String s) { - watchArea2.append(s+"\n"); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/Function.java b/src/edu/berkeley/cs/tedd/core/Function.java deleted file mode 100644 index ddc6092..0000000 --- a/src/edu/berkeley/cs/tedd/core/Function.java +++ /dev/null @@ -1,218 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import bsh.EvalError; -import bsh.Interpreter; -import bsh.NameSpace; -import bsh.UtilEvalError; - -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.PrintWriter; -import java.io.Serializable; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class Function implements Serializable { - private NonCondStmtNode root; - private String functionName; - private String returnType; - private List argumentTypes; - private List argumentNames; - private String sig; - private boolean isInline; - private boolean isInsideGeneration; - - - public Function(String sig) throws TeddError { - this.sig = sig; - this.isInsideGeneration = false; - Pattern p = Pattern.compile("(\\w+)\\s+(@)?(\\w+)\\s*\\(([^\\)]*)\\).*"); - Matcher m = p.matcher(sig); - m.find(); - returnType = m.group(1); - String modifier = m.group(2); - this.isInline = modifier!=null && modifier.trim().equals("@"); - if (isInline && !returnType.equals("void")) - throw new TeddError("Return type of an inline function must be void."); - functionName = m.group(3); - String arguments = m.group(4); - String args[] = arguments.split("\\,"); - argumentTypes = new LinkedList(); - argumentNames = new LinkedList(); - - for(String arg: args){ - arg = arg.trim(); - int idx = arg.lastIndexOf(' '); - if (idx != -1){ - String type = arg.substring(0,idx); - String name = arg.substring(idx+1); - argumentTypes.add(type); - argumentNames.add(name); - } - } - - root = new NonCondStmtNode("** begin **"); - //System.out.println("Declared "+this); - } - - public String getSig() { - return sig; - } - - public String getFunctionName() { - return functionName; - } - - public static void main(String[] args) throws TeddError { - System.out.println((new Function(" void food() ;"))); - } - - @Override - public String toString() { - return isInline()+":"+returnType+":"+functionName+":"+ argumentTypes +":"+ argumentNames; - } - - public NonCondStmtNode getRoot() { - return root; - } - - public void setArguments(Interpreter currentInterpreter, NameSpace newNameSpace, Object[] arguments) throws UtilEvalError, EvalError { - int i = 0; - Iterator typeIter = argumentTypes.iterator(); - Iterator nameIter = argumentNames.iterator(); - while(typeIter.hasNext()) { - currentInterpreter.eval(typeIter.next()+" "+nameIter.next()+";",newNameSpace); - } - for (String argument: argumentNames) { - newNameSpace.setVariable(argument,arguments[i],true); - i++; - } - } - - - final public static String tab = " "; - - private void generate(PrintWriter out, String prefix, StmtNode stmt, CodingEngine ce) { - if (stmt == null) return; - if (stmt instanceof InlineInvokeStmtNode) { - InlineInvokeStmtNode is = (InlineInvokeStmtNode) stmt; - String[] components = is.getComponents(); - Function callee = ce.functions.get(components[0]); - for (int i=0; i0) { - out.print(", "); - } - out.print(argumentTypes.get(i)); - out.print(' '); - out.print(argumentNames.get(i)); - } - out.println(") {"); - generate(out,tab+tab,root.nextStmt(), ce); - out.print(tab); - out.println("}"); - - } - -// private NonCondStmtNode root; -// private String functionName; -// private String returnType; -// private List argumentTypes; -// private List argumentNames; -// private String sig; -// private boolean isInline; - - public boolean isInline() { - return isInline; - } -} diff --git a/src/edu/berkeley/cs/tedd/core/InlineInvokeStmtNode.java b/src/edu/berkeley/cs/tedd/core/InlineInvokeStmtNode.java deleted file mode 100644 index f0b065b..0000000 --- a/src/edu/berkeley/cs/tedd/core/InlineInvokeStmtNode.java +++ /dev/null @@ -1,79 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.LinkedList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class InlineInvokeStmtNode extends NonCondStmtNode { - protected InlineInvokeStmtNode(String stmt) { - super(stmt); - setStmt(stmt.substring(1).trim()); - } - - @Override - public String toString() { - return "@"+getStmt(); - } - - public String[] getComponents() { - LinkedList ret = new LinkedList(); - Pattern p = Pattern.compile("(\\w+)\\s*\\(([^\\)]*)\\).*"); - Matcher m = p.matcher(getStmt()); - m.find(); - String fname = m.group(1); - ret.add(fname); - String arguments = m.group(2); - String args[] = arguments.split("\\,"); - for(String arg: args){ - arg = arg.trim(); - ret.add(arg); - } - String[] rets = new String[ret.size()]; - int i = 0; - for(String s:ret) { - rets[i] = s; - i++; - } - return rets; - } - - @Override - public void printStmt(PrintWriter out, Function fun) { - out.print(getStmt()); - } - -} diff --git a/src/edu/berkeley/cs/tedd/core/InvokeAssignStmtNode.java b/src/edu/berkeley/cs/tedd/core/InvokeAssignStmtNode.java deleted file mode 100644 index b411f1a..0000000 --- a/src/edu/berkeley/cs/tedd/core/InvokeAssignStmtNode.java +++ /dev/null @@ -1,74 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class InvokeAssignStmtNode extends NonCondStmtNode { - String lhs; - - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - out.writeObject(getStmt()); - out.writeObject(lhs); - out.writeObject(nextStmt); - } - - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - setStmt((String) in.readObject()); - lhs = (String) in.readObject(); - nextStmt = (StmtNode)in.readObject(); - if (nextStmt !=null) nextStmt.setParent(this); - } - - protected InvokeAssignStmtNode(String stmt) { - super(stmt); - int idx = stmt.indexOf('='); - setStmt(stmt.substring(idx+1).trim()); - lhs = stmt.substring(0,idx).trim(); - } - - @Override - public String toString() { - return lhs +" = "+getStmt(); - } - - @Override - public void printStmt(PrintWriter out, Function fun) { - out.print(lhs); - out.print(" = "); - out.print(getStmt()); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/NonCondStmtNode.java b/src/edu/berkeley/cs/tedd/core/NonCondStmtNode.java deleted file mode 100644 index 52fc635..0000000 --- a/src/edu/berkeley/cs/tedd/core/NonCondStmtNode.java +++ /dev/null @@ -1,85 +0,0 @@ -package edu.berkeley.cs.tedd.core; - - -import bsh.EvalError; -import bsh.Interpreter; -import bsh.NameSpace; - -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -public class NonCondStmtNode extends StmtNode { - StmtNode nextStmt; - - - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - out.writeObject(getStmt()); - out.writeObject(nextStmt); - } - - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - setStmt((String) in.readObject()); - nextStmt = (StmtNode)in.readObject(); - if (nextStmt !=null) nextStmt.setParent(this); - } - - - protected NonCondStmtNode(String stmt) { - super(stmt); - } - - @Override - protected void setNextStmt(StmtNode child) { - nextStmt = child; - if(child!=null) { - child.setParent(this); - } - } - - @Override - public StmtNode nextStmt() { - return nextStmt; - } - - - @Override - public String toString() { - return getStmt(); - } - -} diff --git a/src/edu/berkeley/cs/tedd/core/StatementTextWithDepth.java b/src/edu/berkeley/cs/tedd/core/StatementTextWithDepth.java deleted file mode 100644 index a7e8116..0000000 --- a/src/edu/berkeley/cs/tedd/core/StatementTextWithDepth.java +++ /dev/null @@ -1,61 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class StatementTextWithDepth { - private int depth; - private int index; - private String stmt; - - public StatementTextWithDepth(int depth, int index, String stmt) { - this.depth = depth; - this.index = index; - this.stmt = stmt; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(CodingEngine.formatFixedWidth(index, 6)); - sb.append(": "); - for(int i=0; i - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public abstract class StmtNode implements Serializable { - private String stmt; - StmtNode parent; - Object lastValue; - - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - } - - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - } - - - public static StmtNode createNode(String stmt) { - StmtNode ret = null; - if (stmt.startsWith("since ")) { - stmt = stmt.substring(6).trim(); - ret = new CondStmtNode(stmt); - } else if (stmt.matches("\\s*\\w+\\s*=\\s*\\w+\\s*\\(.*")){ - return new InvokeAssignStmtNode(stmt); - } else if (stmt.matches("\\s*@\\w+\\s*\\(.*")){ - return new InlineInvokeStmtNode(stmt); - } else { - ret = new NonCondStmtNode(stmt); - } - return ret; - } - - protected StmtNode(String stmt) { - setStmt(stmt); - } - - public void setStmt(String stmt) { - if (!stmt.endsWith(";")) { - stmt = stmt+";"; - } - this.stmt = stmt; - } - - public String getStmt() { - return stmt; - } - - public void setParent(StmtNode parent) { - this.parent = parent; - } - - abstract public StmtNode nextStmt(); - - abstract protected void setNextStmt(StmtNode child); - - private StmtNode step(Interpreter intp, NameSpace ns) throws EvalError { - lastValue = intp.eval(getStmt(),ns); - return nextStmt(); - } - - final public StmtNode forward(Interpreter intp, NameSpace ns) throws EvalError, TeddError { - StmtNode ret = nextStmt(); - if (ret==null) { - throw new TeddError("No more statement to execute."); - } - ret.step(intp, ns); - return ret; - } - - final public StmtNode insert(String stmt) { - StmtNode ret = createNode(stmt); - ret.setNextStmt(nextStmt()); - setNextStmt(ret); - return ret; - } - - final public StmtNode remove() throws TeddError { - StmtNode ret = nextStmt(); - if (ret != null) { - setNextStmt(ret.nextStmt()); - } else { - throw new TeddError("There is no next statement. Nothing is removed."); - } - return ret; - } - - final public StmtNode replace(String stmt) throws TeddError { - remove(); - return insert(stmt); -// StmtNode ret = nextStmt(); -// if (stmt.startsWith("since ")) { -// if (ret instanceof CondStmtNode) { -// stmt = stmt.substring(6).trim(); -// ret.setStmt(stmt); -// } else { -// throw new TeddError("Cannot replace a regular statement with a \"since\" statement."); -// } -// } else { -// if (ret instanceof NonCondStmtNode) { -// ret.setStmt(stmt); -// } else { -// throw new TeddError("Cannot replace a \"since\" statement with a regular statement."); -// } -// } -// return ret; - } - - public void printStmt(PrintWriter out, Function fun) { - if (isReturn() && fun.isInline()) - out.print("break "+fun.getFunctionName()+";"); - else { - String ret = getStmt().replace("Assert.check", "assert "); - out.print(ret); - } - } - - final public boolean isReturn() { - return getStmt().matches("return\\W.*"); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/TeddError.java b/src/edu/berkeley/cs/tedd/core/TeddError.java deleted file mode 100644 index 96586d2..0000000 --- a/src/edu/berkeley/cs/tedd/core/TeddError.java +++ /dev/null @@ -1,39 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class TeddError extends Exception { - public TeddError(String s) { - super(s); - } -} diff --git a/src/edu/berkeley/cs/tedd/core/Trace.java b/src/edu/berkeley/cs/tedd/core/Trace.java deleted file mode 100644 index cf7f406..0000000 --- a/src/edu/berkeley/cs/tedd/core/Trace.java +++ /dev/null @@ -1,146 +0,0 @@ -package edu.berkeley.cs.tedd.core; - -import javax.swing.text.Document; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * Copyright (c) 2006-2011, - * Koushik Sen - * All rights reserved. - *

- * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - *

- * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - *

- * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - *

- * 3. The names of the contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public class Trace { - private List statementHistory; - private String currentTest; - private Console console; - private ArrayList mocks; - - public Trace(Console console) { - statementHistory = new LinkedList(); - this.console = console; - } - - public void clear() { - statementHistory.clear(); - if (console != null) - console.clear(); - } - - public boolean isEmpty() { - return statementHistory.isEmpty(); - } - - public StatementTextWithDepth add(int depth, StmtNode currentStmt ) { - StatementTextWithDepth ret = new StatementTextWithDepth(depth, - statementHistory.size()+1,currentStmt.toString()); - if (console != null) { - console.removeTail(); - console.addText(ret); - } - statementHistory.add(ret); - - return ret; - } - - private StatementTextWithDepth getNextStmt(int depth, StmtNode currentStmt) { - StatementTextWithDepth ret2; - String stmt; - - String mock = getMock(); - if(mock!=null) { - stmt = "mock "+mock; - } else { - StmtNode tmp = currentStmt.nextStmt(); - if (tmp!=null) { - stmt = tmp.toString(); - } else { - if (depth == 0) - stmt = "** end of execution **"; - else - stmt = "no statement"; - } - } - - ret2 = new StatementTextWithDepth(depth, statementHistory.size()+1,stmt); - return ret2; - } - - public void updateNext(int depth, StmtNode currentStmt) { - if (console != null) { - console.removeTail(); - console.addTail("------------------------------------------->\n"); - console.addTail(getNextStmt(depth,currentStmt)); - } - } - - public void setCurrentTest(String sig, ArrayList mocks) { - this.currentTest = sig; - this.mocks = mocks; - if (console != null) { - StatementTextWithDepth ret = new StatementTextWithDepth(0,0,sig); - console.addText(ret); - } - } - - public String getCurrentTest() { - return currentTest; - } - - public void print(int depth) { - System.out.println(new StatementTextWithDepth(0,0,currentTest)); - for(StatementTextWithDepth stmt:statementHistory) { - if (depth >= stmt.getDepth()) - System.out.println(stmt); - } - } - - public void printNext(int depth, StmtNode currentStmt) { - System.out.println("------------------------------------------->"); - System.out.println(getNextStmt(depth,currentStmt).toString()); - } - - public void setMock(String mockName) { - int n = statementHistory.size(); - mocks.set(n,mockName); - } - - public String getMock() { - int n = statementHistory.size(); - if (mocks.size()<=n) { - mocks.add(null); - } - return mocks.get(n); - } - - public int size() { - return statementHistory.size(); - } -}