summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--J2V.java4
-rw-r--r--boil/library/BoilSimp.java758
-rw-r--r--boil/library/TypeFactory.java (renamed from vaporize/library/TypeFactory.java)2
-rw-r--r--boil/tests/BinaryTree.java (renamed from vaporize/tests/BinaryTree.java)0
-rw-r--r--boil/tests/BinaryTree.opt.vapor (renamed from vaporize/tests/BinaryTree.opt.vapor)0
-rw-r--r--boil/tests/BinaryTree.vapor (renamed from vaporize/tests/BinaryTree.vapor)0
-rw-r--r--boil/tests/BubbleSort.java (renamed from vaporize/tests/BubbleSort.java)0
-rw-r--r--boil/tests/BubbleSort.opt.vapor (renamed from vaporize/tests/BubbleSort.opt.vapor)0
-rw-r--r--boil/tests/BubbleSort.vapor (renamed from vaporize/tests/BubbleSort.vapor)0
-rw-r--r--boil/tests/Factorial.java (renamed from vaporize/tests/Factorial.java)0
-rw-r--r--boil/tests/Factorial.opt.vapor (renamed from vaporize/tests/Factorial.opt.vapor)0
-rw-r--r--boil/tests/Factorial.vapor (renamed from vaporize/tests/Factorial.vapor)0
-rw-r--r--boil/tests/LinearSearch.java (renamed from vaporize/tests/LinearSearch.java)0
-rw-r--r--boil/tests/LinearSearch.opt.vapor (renamed from vaporize/tests/LinearSearch.opt.vapor)0
-rw-r--r--boil/tests/LinearSearch.vapor (renamed from vaporize/tests/LinearSearch.vapor)0
-rw-r--r--boil/tests/LinkedList.java (renamed from vaporize/tests/LinkedList.java)0
-rw-r--r--boil/tests/LinkedList.opt.vapor (renamed from vaporize/tests/LinkedList.opt.vapor)0
-rw-r--r--boil/tests/LinkedList.vapor (renamed from vaporize/tests/LinkedList.vapor)0
-rw-r--r--boil/tests/MoreThan4.java (renamed from vaporize/tests/MoreThan4.java)0
-rw-r--r--boil/tests/MoreThan4.opt.vapor (renamed from vaporize/tests/MoreThan4.opt.vapor)0
-rw-r--r--boil/tests/MoreThan4.vapor (renamed from vaporize/tests/MoreThan4.vapor)0
-rw-r--r--boil/tests/QuickSort.java (renamed from vaporize/tests/QuickSort.java)0
-rw-r--r--boil/tests/QuickSort.opt.vapor (renamed from vaporize/tests/QuickSort.opt.vapor)0
-rw-r--r--boil/tests/QuickSort.vapor (renamed from vaporize/tests/QuickSort.vapor)0
-rw-r--r--boil/tests/ShortCircuit.opt.vapor (renamed from vaporize/tests/ShortCircuit.opt.vapor)0
-rw-r--r--boil/tests/ShortCircuit.vapor (renamed from vaporize/tests/ShortCircuit.vapor)0
-rw-r--r--boil/tests/TreeVisitor.java (renamed from vaporize/tests/TreeVisitor.java)0
-rw-r--r--boil/tests/TreeVisitor.opt.vapor (renamed from vaporize/tests/TreeVisitor.opt.vapor)0
-rw-r--r--boil/tests/TreeVisitor.vapor (renamed from vaporize/tests/TreeVisitor.vapor)0
-rw-r--r--boil/tests/ex1.java (renamed from vaporize/tests_easy/ex1.java)0
-rw-r--r--boil/tests/ex1.vapor (renamed from vaporize/tests_easy/ex1.vapor)0
-rw-r--r--boil/tests/ex2.java (renamed from vaporize/tests_easy/ex2.java)0
-rw-r--r--boil/tests/ex2.vapor (renamed from vaporize/tests_easy/ex2.vapor)0
-rw-r--r--boil/tests/ex29.java (renamed from vaporize/tests_easy/ex29.java)0
-rw-r--r--boil/tests/ex30.java (renamed from vaporize/tests_easy/ex30.java)0
-rw-r--r--boil/tests/ex30.vapor3
-rw-r--r--boil/tests/ex31.java (renamed from vaporize/tests_easy/ex31.java)0
-rw-r--r--boil/tests/ex32.java16
-rw-r--r--boil/tests/ex33.java13
-rw-r--r--typecheck/library/TypeCheckSimp.java2
-rw-r--r--typecheck/tests/IsPositive.java18
-rw-r--r--vaporize/library/VaporizeSimp.java668
42 files changed, 1103 insertions, 381 deletions
diff --git a/J2V.java b/J2V.java
index 6038ffa..70c715f 100644
--- a/J2V.java
+++ b/J2V.java
@@ -5,7 +5,7 @@ import syntaxtree.*;
import java.util.*;
import st.*;
import misc.*;
-import vaporize.library.*;
+import boil.library.*;
public class J2V {
public static void main(String[] args) {
@@ -24,7 +24,7 @@ public class J2V {
root.accept(new SymTableBottomUp<Void>(), symt);
root.accept(new SymTableTopDown<Void>(), symt);
- VaporizeSimp vp = new VaporizeSimp();
+ BoilSimp vp = new BoilSimp();
String program = root.accept(vp, symt);
PrintFilter.print("===================================================", true);
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java
new file mode 100644
index 0000000..b5ea518
--- /dev/null
+++ b/boil/library/BoilSimp.java
@@ -0,0 +1,758 @@
+package boil.library;
+
+import syntaxtree.*;
+import visitor.*;
+import st.*;
+import misc.*;
+import java.util.*;
+
+public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
+
+ TypeFactory tf = new TypeFactory();
+
+ //
+ // Auto class visitors--probably don't need to be overridden.
+ //
+ public String visit(NodeList n, SymbolTable symt) {
+ String mod = "";
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ mod += e.nextElement().accept(this,symt);
+ _count++;
+ }
+ return mod;
+ }
+
+ public String visit(NodeListOptional n, SymbolTable symt) {
+ String mod = "";
+ if ( n.present() ) {
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ mod += e.nextElement().accept(this,symt);
+ _count++;
+ }
+ return mod;
+ }
+ else
+ return "";
+ }
+
+ public String visit(NodeOptional n, SymbolTable symt) {
+ if ( n.present() )
+ return n.node.accept(this,symt);
+ else
+ return "";
+ }
+
+ public String visit(NodeSequence n, SymbolTable symt) {
+ String mod = "";
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ mod += e.nextElement().accept(this,symt);
+ _count++;
+ }
+ return mod;
+ }
+
+ public String visit(NodeToken n, SymbolTable symt) { return ""; }
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public String visit(Goal n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> ( VarDeclaration() )*
+ * f15 -> ( Statement() )*
+ * f16 -> "}"
+ * f17 -> "}"
+ */
+ public String visit(MainClass n, SymbolTable symt) {
+ String id = n.f1.f0.tokenImage;
+
+ symt.setActive(TypeEnum.classname, id);
+ symt.setActive(TypeEnum.method, "main");
+ this.tf.reset();
+ String mod = "";
+ mod += "func Main()\n";
+
+ mod += n.f0.accept(this, symt);
+ n.f1.accept(this, symt); // throw class name away
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+ mod += n.f6.accept(this, symt);
+ mod += n.f7.accept(this, symt);
+ mod += n.f8.accept(this, symt);
+ mod += n.f9.accept(this, symt);
+ mod += n.f10.accept(this, symt);
+ n.f11.accept(this, symt); // throw boiler 'args' variable away
+ mod += n.f12.accept(this, symt);
+ mod += n.f13.accept(this, symt);
+ mod += n.f14.accept(this, symt); // FIXME
+ mod += n.f15.accept(this, symt);
+ mod += n.f16.accept(this, symt);
+ mod += n.f17.accept(this, symt);
+
+ mod += " goto :exit\nerror:\n" +
+ " Error(\"Mem exhausted\")\n goto :exit\n" +
+ "exit:\n ret\n\n";
+
+ symt.removeActive(TypeEnum.method);
+ return mod;
+ }
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public String visit(TypeDeclaration n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public String visit(ClassDeclaration n, SymbolTable symt) {
+ String id = n.f1.f0.tokenImage;
+ symt.setActive(TypeEnum.classname, id);
+ String mod = "";
+
+ mod += n.f0.accept(this, symt);
+ n.f1.accept(this, symt);
+ mod += String.format("const functable_%s\n", id);
+ for (MethodInstance mtd : symt.getClass(id).getMethods()) {
+ mod += String.format(" :%s_%s\n", id, mtd);
+ }
+ mod += "\n";
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+
+ return mod;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public String visit(ClassExtendsDeclaration n, SymbolTable symt) {
+ String id = n.f1.f0.tokenImage;
+ symt.setActive(TypeEnum.classname, id);
+ String mod = "";
+
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+ mod += n.f6.accept(this, symt);
+ mod += n.f7.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public String visit(VarDeclaration n, SymbolTable symt) {
+ String mod = "";
+
+ n.f0.accept(this, symt);
+ String id = n.f1.accept(this, symt);
+ mod += String.format(" %s = HeapAllocZ(32)\n",
+ this.tf.addNewAlias(symt.getType(id))); // FIXME add proper allocation size
+ mod += String.format(" if0 %s goto :error\n",
+ this.tf.retrieveAlias(symt.getType(id)));
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public String visit(MethodDeclaration n, SymbolTable symt) {
+ String id = n.f2.f0.tokenImage;
+ symt.setActive(TypeEnum.method, id);
+ this.tf.reset();
+ String mod = "";
+
+ mod += n.f0.accept(this, symt);
+ n.f1.accept(this, symt);
+ n.f2.accept(this, symt);
+ mod += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this";
+ mod += n.f3.accept(this, symt);
+ String args = n.f4.accept(this, symt);
+ mod += String.format("%s)\n", args);
+ mod += n.f5.accept(this, symt);
+ mod += n.f6.accept(this, symt);
+ mod += n.f7.accept(this, symt);
+ mod += n.f8.accept(this, symt);
+ mod += n.f9.accept(this, symt);
+ n.f10.accept(this, symt); // FIXME
+ mod += n.f11.accept(this, symt);
+ mod += n.f12.accept(this, symt);
+
+ mod += " ret\n\n";
+
+
+ symt.removeActive(TypeEnum.method);
+ return mod;
+ }
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public String visit(FormalParameterList n, SymbolTable symt) {
+ String mod = "";
+ String arg = n.f0.accept(this, symt);
+ if (arg != null)
+ mod += " " + arg;
+ mod += n.f1.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public String visit(FormalParameter n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public String visit(FormalParameterRest n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ String arg = n.f1.accept(this, symt);
+ if (arg != null)
+ mod += " " + arg;
+ return mod;
+ }
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public String visit(Type n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public String visit(ArrayType n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "boolean"
+ */
+ public String visit(BooleanType n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "int"
+ */
+ public String visit(IntegerType n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);;
+ return mod;
+ }
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public String visit(Statement n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public String visit(Block n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public String visit(AssignmentStatement n, SymbolTable symt) {
+ String mod = "";
+
+ String id = n.f0.accept(this, symt);
+ mod += String.format(" [%s] = ", this.tf.retrieveAlias(symt.getType(id)));
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public String visit(ArrayAssignmentStatement n, SymbolTable symt) {
+ String mod = "";
+ n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+ mod += n.f6.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public String visit(IfStatement n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+ mod += n.f6.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public String visit(WhileStatement n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public String visit(PrintStatement n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public String visit(Expression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public String visit(AndExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public String visit(CompareExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public String visit(PlusExpression n, SymbolTable symt) {
+ String mod = "";
+ String oper1 = n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ String oper2 = n.f2.accept(this, symt);
+ TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR);
+
+ mod += String.format(" %s = AddS(%s %s)\n",
+ this.tf.addNewAlias(tp1),
+ oper1,
+ oper2);
+
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public String visit(MinusExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public String visit(TimesExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public String visit(ArrayLookup n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public String visit(ArrayLength n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public String visit(MessageSend n, SymbolTable symt) {
+ String mod = "";
+ String id = n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ String id2 = n.f2.accept(this, symt);
+ TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); // TypeFactory likes to know who it's renting to
+ TypeInstance tp2 = new TypeInstance("tp2", TypeEnum.ERROR);
+
+ TypeInstance cur = symt.getType(id);
+ int mtdIndex = cur.getClassInstance()
+ .getMethods().indexOf(symt.getMethod(id2)) * 4;
+
+ mod += String.format(" %s = [%s+%d]\n",
+ this.tf.addNewAlias(tp1),
+ this.tf.retrieveAlias(cur),
+ 0);
+
+ mod += String.format(" %s = [%s+%d]\n",
+ this.tf.addNewAlias(tp2),
+ this.tf.retrieveAlias(tp1),
+ mtdIndex);
+
+ mod += n.f3.accept(this, symt);
+ mod = n.f4.accept(this, symt);
+ mod += n.f5.accept(this, symt);
+
+ mod += String.format(" call %s(%s)\n",
+ this.tf.retrieveAlias(tp2),
+ this.tf.retrieveAlias(cur));
+
+ return mod;
+ }
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public String visit(ExpressionList n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public String visit(ExpressionRest n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public String visit(PrimaryExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public String visit(IntegerLiteral n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.tokenImage;
+ return mod;
+ }
+
+ /**
+ * f0 -> "true"
+ */
+ public String visit(TrueLiteral n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "false"
+ */
+ public String visit(FalseLiteral n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public String visit(Identifier n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.tokenImage;
+ return mod;
+ }
+
+ /**
+ * f0 -> "this"
+ */
+ public String visit(ThisExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public String visit(ArrayAllocationExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ mod += n.f4.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public String visit(AllocationExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ String cls = n.f1.accept(this, symt);
+ mod += String.format(":functable_%s\n", cls);
+
+ mod += n.f2.accept(this, symt);
+ mod += n.f3.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public String visit(NotExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ return mod;
+ }
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public String visit(BracketExpression n, SymbolTable symt) {
+ String mod = "";
+ mod += n.f0.accept(this, symt);
+ mod += n.f1.accept(this, symt);
+ mod += n.f2.accept(this, symt);
+ return mod;
+ }
+
+}
diff --git a/vaporize/library/TypeFactory.java b/boil/library/TypeFactory.java
index b73862f..8dd910e 100644
--- a/vaporize/library/TypeFactory.java
+++ b/boil/library/TypeFactory.java
@@ -1,4 +1,4 @@
-package vaporize.library;
+package boil.library;
import java.util.HashMap;
import st.TypeInstance;
diff --git a/vaporize/tests/BinaryTree.java b/boil/tests/BinaryTree.java
index 18d1464..18d1464 100644
--- a/vaporize/tests/BinaryTree.java
+++ b/boil/tests/BinaryTree.java
diff --git a/vaporize/tests/BinaryTree.opt.vapor b/boil/tests/BinaryTree.opt.vapor
index ef6ac4e..ef6ac4e 100644
--- a/vaporize/tests/BinaryTree.opt.vapor
+++ b/boil/tests/BinaryTree.opt.vapor
diff --git a/vaporize/tests/BinaryTree.vapor b/boil/tests/BinaryTree.vapor
index 275cfe3..275cfe3 100644
--- a/vaporize/tests/BinaryTree.vapor
+++ b/boil/tests/BinaryTree.vapor
diff --git a/vaporize/tests/BubbleSort.java b/boil/tests/BubbleSort.java
index e5645a9..e5645a9 100644
--- a/vaporize/tests/BubbleSort.java
+++ b/boil/tests/BubbleSort.java
diff --git a/vaporize/tests/BubbleSort.opt.vapor b/boil/tests/BubbleSort.opt.vapor
index a118894..a118894 100644
--- a/vaporize/tests/BubbleSort.opt.vapor
+++ b/boil/tests/BubbleSort.opt.vapor
diff --git a/vaporize/tests/BubbleSort.vapor b/boil/tests/BubbleSort.vapor
index cedba69..cedba69 100644
--- a/vaporize/tests/BubbleSort.vapor
+++ b/boil/tests/BubbleSort.vapor
diff --git a/vaporize/tests/Factorial.java b/boil/tests/Factorial.java
index d938bb6..d938bb6 100644
--- a/vaporize/tests/Factorial.java
+++ b/boil/tests/Factorial.java
diff --git a/vaporize/tests/Factorial.opt.vapor b/boil/tests/Factorial.opt.vapor
index aca17fe..aca17fe 100644
--- a/vaporize/tests/Factorial.opt.vapor
+++ b/boil/tests/Factorial.opt.vapor
diff --git a/vaporize/tests/Factorial.vapor b/boil/tests/Factorial.vapor
index 28e1126..28e1126 100644
--- a/vaporize/tests/Factorial.vapor
+++ b/boil/tests/Factorial.vapor
diff --git a/vaporize/tests/LinearSearch.java b/boil/tests/LinearSearch.java
index daddd94..daddd94 100644
--- a/vaporize/tests/LinearSearch.java
+++ b/boil/tests/LinearSearch.java
diff --git a/vaporize/tests/LinearSearch.opt.vapor b/boil/tests/LinearSearch.opt.vapor
index 302de05..302de05 100644
--- a/vaporize/tests/LinearSearch.opt.vapor
+++ b/boil/tests/LinearSearch.opt.vapor
diff --git a/vaporize/tests/LinearSearch.vapor b/boil/tests/LinearSearch.vapor
index db4884a..db4884a 100644
--- a/vaporize/tests/LinearSearch.vapor
+++ b/boil/tests/LinearSearch.vapor
diff --git a/vaporize/tests/LinkedList.java b/boil/tests/LinkedList.java
index 69adc33..69adc33 100644
--- a/vaporize/tests/LinkedList.java
+++ b/boil/tests/LinkedList.java
diff --git a/vaporize/tests/LinkedList.opt.vapor b/boil/tests/LinkedList.opt.vapor
index aaca62c..aaca62c 100644
--- a/vaporize/tests/LinkedList.opt.vapor
+++ b/boil/tests/LinkedList.opt.vapor
diff --git a/vaporize/tests/LinkedList.vapor b/boil/tests/LinkedList.vapor
index bebdf94..bebdf94 100644
--- a/vaporize/tests/LinkedList.vapor
+++ b/boil/tests/LinkedList.vapor
diff --git a/vaporize/tests/MoreThan4.java b/boil/tests/MoreThan4.java
index 4960f01..4960f01 100644
--- a/vaporize/tests/MoreThan4.java
+++ b/boil/tests/MoreThan4.java
diff --git a/vaporize/tests/MoreThan4.opt.vapor b/boil/tests/MoreThan4.opt.vapor
index a59d1b5..a59d1b5 100644
--- a/vaporize/tests/MoreThan4.opt.vapor
+++ b/boil/tests/MoreThan4.opt.vapor
diff --git a/vaporize/tests/MoreThan4.vapor b/boil/tests/MoreThan4.vapor
index 6067f8e..6067f8e 100644
--- a/vaporize/tests/MoreThan4.vapor
+++ b/boil/tests/MoreThan4.vapor
diff --git a/vaporize/tests/QuickSort.java b/boil/tests/QuickSort.java
index 5893390..5893390 100644
--- a/vaporize/tests/QuickSort.java
+++ b/boil/tests/QuickSort.java
diff --git a/vaporize/tests/QuickSort.opt.vapor b/boil/tests/QuickSort.opt.vapor
index 6e14e5a..6e14e5a 100644
--- a/vaporize/tests/QuickSort.opt.vapor
+++ b/boil/tests/QuickSort.opt.vapor
diff --git a/vaporize/tests/QuickSort.vapor b/boil/tests/QuickSort.vapor
index 3fe3798..3fe3798 100644
--- a/vaporize/tests/QuickSort.vapor
+++ b/boil/tests/QuickSort.vapor
diff --git a/vaporize/tests/ShortCircuit.opt.vapor b/boil/tests/ShortCircuit.opt.vapor
index 8275acd..8275acd 100644
--- a/vaporize/tests/ShortCircuit.opt.vapor
+++ b/boil/tests/ShortCircuit.opt.vapor
diff --git a/vaporize/tests/ShortCircuit.vapor b/boil/tests/ShortCircuit.vapor
index 31cc088..31cc088 100644
--- a/vaporize/tests/ShortCircuit.vapor
+++ b/boil/tests/ShortCircuit.vapor
diff --git a/vaporize/tests/TreeVisitor.java b/boil/tests/TreeVisitor.java
index 8debfe6..8debfe6 100644
--- a/vaporize/tests/TreeVisitor.java
+++ b/boil/tests/TreeVisitor.java
diff --git a/vaporize/tests/TreeVisitor.opt.vapor b/boil/tests/TreeVisitor.opt.vapor
index dfa80a6..dfa80a6 100644
--- a/vaporize/tests/TreeVisitor.opt.vapor
+++ b/boil/tests/TreeVisitor.opt.vapor
diff --git a/vaporize/tests/TreeVisitor.vapor b/boil/tests/TreeVisitor.vapor
index d8aa63b..d8aa63b 100644
--- a/vaporize/tests/TreeVisitor.vapor
+++ b/boil/tests/TreeVisitor.vapor
diff --git a/vaporize/tests_easy/ex1.java b/boil/tests/ex1.java
index 22f0aa0..22f0aa0 100644
--- a/vaporize/tests_easy/ex1.java
+++ b/boil/tests/ex1.java
diff --git a/vaporize/tests_easy/ex1.vapor b/boil/tests/ex1.vapor
index bcfb38c..bcfb38c 100644
--- a/vaporize/tests_easy/ex1.vapor
+++ b/boil/tests/ex1.vapor
diff --git a/vaporize/tests_easy/ex2.java b/boil/tests/ex2.java
index 986ca7d..986ca7d 100644
--- a/vaporize/tests_easy/ex2.java
+++ b/boil/tests/ex2.java
diff --git a/vaporize/tests_easy/ex2.vapor b/boil/tests/ex2.vapor
index 25811b3..25811b3 100644
--- a/vaporize/tests_easy/ex2.vapor
+++ b/boil/tests/ex2.vapor
diff --git a/vaporize/tests_easy/ex29.java b/boil/tests/ex29.java
index 30ea154..30ea154 100644
--- a/vaporize/tests_easy/ex29.java
+++ b/boil/tests/ex29.java
diff --git a/vaporize/tests_easy/ex30.java b/boil/tests/ex30.java
index 4a5064d..4a5064d 100644
--- a/vaporize/tests_easy/ex30.java
+++ b/boil/tests/ex30.java
diff --git a/boil/tests/ex30.vapor b/boil/tests/ex30.vapor
new file mode 100644
index 0000000..200baee
--- /dev/null
+++ b/boil/tests/ex30.vapor
@@ -0,0 +1,3 @@
+func Main()
+
+ ret \ No newline at end of file
diff --git a/vaporize/tests_easy/ex31.java b/boil/tests/ex31.java
index d5a6980..d5a6980 100644
--- a/vaporize/tests_easy/ex31.java
+++ b/boil/tests/ex31.java
diff --git a/boil/tests/ex32.java b/boil/tests/ex32.java
new file mode 100644
index 0000000..5e421c4
--- /dev/null
+++ b/boil/tests/ex32.java
@@ -0,0 +1,16 @@
+class ex31 {
+ public static void main(String[] a) {
+ A a ;
+ a = new A() ;
+ System.out.println(a.bar()) ;
+ }
+}
+
+class A {
+ public int foo() {
+ return 22 ;
+ }
+ public int bar() {
+ return 42 ;
+ }
+}
diff --git a/boil/tests/ex33.java b/boil/tests/ex33.java
new file mode 100644
index 0000000..53e369f
--- /dev/null
+++ b/boil/tests/ex33.java
@@ -0,0 +1,13 @@
+class ex31 {
+ public static void main(String[] a) {
+ A a ;
+ a = new A() ;
+ System.out.println(a.foo(12 + 13)) ;
+ }
+}
+
+class A {
+ public int foo(int a) {
+ return 22 ;
+ }
+}
diff --git a/typecheck/library/TypeCheckSimp.java b/typecheck/library/TypeCheckSimp.java
index 1a77477..2eb5bf1 100644
--- a/typecheck/library/TypeCheckSimp.java
+++ b/typecheck/library/TypeCheckSimp.java
@@ -175,7 +175,7 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> {
n.f8.accept(this, symt);
n.f9.accept(this, symt);
n.f10.accept(this, symt);
- // TypeInstance args = n.f11.accept(this, symt); // FIXME Type in the main class declaration uses an illegal minijava type?
+ // TypeInstance args = n.f11.accept(this, symt);
n.f12.accept(this, symt);
n.f13.accept(this, symt);
TypeInstance var_dec = n.f14.accept(this, symt);
diff --git a/typecheck/tests/IsPositive.java b/typecheck/tests/IsPositive.java
index 087cd3f..09bcf1d 100644
--- a/typecheck/tests/IsPositive.java
+++ b/typecheck/tests/IsPositive.java
@@ -1,12 +1,24 @@
class IsPositive{
public static void main(String[] a){
- System.out.println(new Positive().isPos(10));
+ System.out.println(new Positive().isPositive(10));
}
}
class Positive {
- public bool isPos(int num){
- bool positive ;
+ public boolean isPositive(int num){
+ boolean positive ;
+
+ if (0 < num)
+ positive = true ;
+ else
+ positive = false ;
+ return positive ;
+ }
+}
+
+class Positive2 extends Positive {
+ public boolean isPositive(int num){
+ boolean positive ;
if (0 < num)
positive = true ;
diff --git a/vaporize/library/VaporizeSimp.java b/vaporize/library/VaporizeSimp.java
index a7faf88..6c69ea2 100644
--- a/vaporize/library/VaporizeSimp.java
+++ b/vaporize/library/VaporizeSimp.java
@@ -1,60 +1,58 @@
package vaporize.library;
import syntaxtree.*;
-import visitor.*;
+package visitor;
import st.*;
import misc.*;
import java.util.*;
-public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
-
- TypeFactory tf = new TypeFactory();
+public class VaporizeSimp<R,A> implements GJVisitor<R,A> {
//
// Auto class visitors--probably don't need to be overridden.
//
- public String visit(NodeList n, SymbolTable symt) {
- String mod = "";
+ public R visit(NodeList n, A argu) {
+ R _ret=null;
int _count=0;
for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
- mod += e.nextElement().accept(this,symt);
+ e.nextElement().accept(this,argu);
_count++;
}
- return mod;
+ return _ret;
}
- public String visit(NodeListOptional n, SymbolTable symt) {
- String mod = "";
+ public R visit(NodeListOptional n, A argu) {
if ( n.present() ) {
+ R _ret=null;
int _count=0;
for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
- mod += e.nextElement().accept(this,symt);
+ e.nextElement().accept(this,argu);
_count++;
}
- return mod;
+ return _ret;
}
else
- return "";
+ return null;
}
- public String visit(NodeOptional n, SymbolTable symt) {
+ public R visit(NodeOptional n, A argu) {
if ( n.present() )
- return n.node.accept(this,symt);
+ return n.node.accept(this,argu);
else
- return "";
+ return null;
}
- public String visit(NodeSequence n, SymbolTable symt) {
- String mod = "";
+ public R visit(NodeSequence n, A argu) {
+ R _ret=null;
int _count=0;
for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
- mod += e.nextElement().accept(this,symt);
+ e.nextElement().accept(this,argu);
_count++;
}
- return mod;
+ return _ret;
}
- public String visit(NodeToken n, SymbolTable symt) { return ""; }
+ public R visit(NodeToken n, A argu) { return null; }
//
// User-generated visitor methods below
@@ -65,12 +63,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> ( TypeDeclaration() )*
* f2 -> <EOF>
*/
- public String visit(Goal n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(Goal n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -93,50 +91,37 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f16 -> "}"
* f17 -> "}"
*/
- public String visit(MainClass n, SymbolTable symt) {
- String id = n.f1.f0.tokenImage;
-
- symt.setActive(TypeEnum.classname, id);
- symt.setActive(TypeEnum.method, "main");
- this.tf.reset();
- String mod = "";
- mod += "func Main()\n";
-
- mod += n.f0.accept(this, symt);
- n.f1.accept(this, symt); // throw class name away
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- mod += n.f5.accept(this, symt);
- mod += n.f6.accept(this, symt);
- mod += n.f7.accept(this, symt);
- mod += n.f8.accept(this, symt);
- mod += n.f9.accept(this, symt);
- mod += n.f10.accept(this, symt);
- n.f11.accept(this, symt); // throw boiler 'args' variable away
- mod += n.f12.accept(this, symt);
- mod += n.f13.accept(this, symt);
- mod += n.f14.accept(this, symt); // FIXME
- mod += n.f15.accept(this, symt);
- mod += n.f16.accept(this, symt);
- mod += n.f17.accept(this, symt);
-
- mod += " goto :exit\nerror:\n" +
- " Error(\"Mem exhausted\")\n goto :exit\n" +
- "exit:\n ret\n\n";
-
- symt.removeActive(TypeEnum.method);
- return mod;
+ public R visit(MainClass n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ n.f13.accept(this, argu);
+ n.f14.accept(this, argu);
+ n.f15.accept(this, argu);
+ n.f16.accept(this, argu);
+ n.f17.accept(this, argu);
+ return _ret;
}
/**
* f0 -> ClassDeclaration()
* | ClassExtendsDeclaration()
*/
- public String visit(TypeDeclaration n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(TypeDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
@@ -147,24 +132,15 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f4 -> ( MethodDeclaration() )*
* f5 -> "}"
*/
- public String visit(ClassDeclaration n, SymbolTable symt) {
- String id = n.f1.f0.tokenImage;
- symt.setActive(TypeEnum.classname, id);
- String mod = "";
-
- mod += n.f0.accept(this, symt);
- n.f1.accept(this, symt);
- mod += String.format("const functable_%s\n", id);
- for (MethodInstance mtd : symt.getClass(id).getMethods()) {
- mod += String.format(" :%s_%s\n", id, mtd);
- }
- mod += "\n";
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- mod += n.f5.accept(this, symt);
-
- return mod;
+ public R visit(ClassDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ return _ret;
}
/**
@@ -177,20 +153,17 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f6 -> ( MethodDeclaration() )*
* f7 -> "}"
*/
- public String visit(ClassExtendsDeclaration n, SymbolTable symt) {
- String id = n.f1.f0.tokenImage;
- symt.setActive(TypeEnum.classname, id);
- String mod = "";
-
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- mod += n.f5.accept(this, symt);
- mod += n.f6.accept(this, symt);
- mod += n.f7.accept(this, symt);
- return mod;
+ public R visit(ClassExtendsDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ return _ret;
}
/**
@@ -198,17 +171,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> Identifier()
* f2 -> ";"
*/
- public String visit(VarDeclaration n, SymbolTable symt) {
- String mod = "";
-
- n.f0.accept(this, symt);
- String id = n.f1.accept(this, symt);
- mod += String.format(" %s = HeapAllocZ(32)\n",
- this.tf.addNewAlias(symt.getType(id))); // FIXME add proper allocation size
- mod += String.format(" if0 %s goto :error\n",
- this.tf.retrieveAlias(symt.getType(id)));
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(VarDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -226,70 +194,55 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f11 -> ";"
* f12 -> "}"
*/
- public String visit(MethodDeclaration n, SymbolTable symt) {
- String id = n.f2.f0.tokenImage;
- symt.setActive(TypeEnum.method, id);
- this.tf.reset();
- String mod = "";
-
- mod += n.f0.accept(this, symt);
- n.f1.accept(this, symt);
- n.f2.accept(this, symt);
- mod += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this";
- mod += n.f3.accept(this, symt);
- String args = n.f4.accept(this, symt);
- mod += String.format("%s)\n", args);
- mod += n.f5.accept(this, symt);
- mod += n.f6.accept(this, symt);
- mod += n.f7.accept(this, symt);
- mod += n.f8.accept(this, symt);
- mod += n.f9.accept(this, symt);
- n.f10.accept(this, symt); // FIXME
- mod += n.f11.accept(this, symt);
- mod += n.f12.accept(this, symt);
-
- mod += " ret\n\n";
-
-
- symt.removeActive(TypeEnum.method);
- return mod;
+ public R visit(MethodDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ return _ret;
}
/**
* f0 -> FormalParameter()
* f1 -> ( FormalParameterRest() )*
*/
- public String visit(FormalParameterList n, SymbolTable symt) {
- String mod = "";
- String arg = n.f0.accept(this, symt);
- if (arg != null)
- mod += " " + arg;
- mod += n.f1.accept(this, symt);
- return mod;
+ public R visit(FormalParameterList n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
}
/**
* f0 -> Type()
* f1 -> Identifier()
*/
- public String visit(FormalParameter n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- return mod;
+ public R visit(FormalParameter n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
}
/**
* f0 -> ","
* f1 -> FormalParameter()
*/
- public String visit(FormalParameterRest n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- String arg = n.f1.accept(this, symt);
- if (arg != null)
- mod += " " + arg;
- return mod;
+ public R visit(FormalParameterRest n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
}
/**
@@ -298,10 +251,10 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* | IntegerType()
* | Identifier()
*/
- public String visit(Type n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(Type n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
@@ -309,30 +262,30 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "["
* f2 -> "]"
*/
- public String visit(ArrayType n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(ArrayType n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
* f0 -> "boolean"
*/
- public String visit(BooleanType n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(BooleanType n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
* f0 -> "int"
*/
- public String visit(IntegerType n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);;
- return mod;
+ public R visit(IntegerType n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
@@ -343,10 +296,10 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* | WhileStatement()
* | PrintStatement()
*/
- public String visit(Statement n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(Statement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
@@ -354,12 +307,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> ( Statement() )*
* f2 -> "}"
*/
- public String visit(Block n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(Block n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -368,15 +321,13 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f2 -> Expression()
* f3 -> ";"
*/
- public String visit(AssignmentStatement n, SymbolTable symt) {
- String mod = "";
-
- String id = n.f0.accept(this, symt);
- mod += String.format(" [%s] = ", this.tf.retrieveAlias(symt.getType(id)));
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- return mod;
+ public R visit(AssignmentStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
}
/**
@@ -388,16 +339,16 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f5 -> Expression()
* f6 -> ";"
*/
- public String visit(ArrayAssignmentStatement n, SymbolTable symt) {
- String mod = "";
- n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- mod += n.f5.accept(this, symt);
- mod += n.f6.accept(this, symt);
- return mod;
+ public R visit(ArrayAssignmentStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ return _ret;
}
/**
@@ -409,16 +360,16 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f5 -> "else"
* f6 -> Statement()
*/
- public String visit(IfStatement n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- mod += n.f5.accept(this, symt);
- mod += n.f6.accept(this, symt);
- return mod;
+ public R visit(IfStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ return _ret;
}
/**
@@ -428,14 +379,14 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f3 -> ")"
* f4 -> Statement()
*/
- public String visit(WhileStatement n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- return mod;
+ public R visit(WhileStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
}
/**
@@ -445,14 +396,14 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f3 -> ")"
* f4 -> ";"
*/
- public String visit(PrintStatement n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- return mod;
+ public R visit(PrintStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
}
/**
@@ -466,10 +417,10 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* | MessageSend()
* | PrimaryExpression()
*/
- public String visit(Expression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(Expression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
@@ -477,12 +428,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "&&"
* f2 -> PrimaryExpression()
*/
- public String visit(AndExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(AndExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -490,12 +441,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "<"
* f2 -> PrimaryExpression()
*/
- public String visit(CompareExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(CompareExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -503,19 +454,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "+"
* f2 -> PrimaryExpression()
*/
- public String visit(PlusExpression n, SymbolTable symt) {
- String mod = "";
- String oper1 = n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- String oper2 = n.f2.accept(this, symt);
- TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR);
-
- mod += String.format(" %s = AddS(%s %s)\n",
- this.tf.addNewAlias(tp1),
- oper1,
- oper2);
-
- return mod;
+ public R visit(PlusExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -523,12 +467,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "-"
* f2 -> PrimaryExpression()
*/
- public String visit(MinusExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(MinusExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -536,12 +480,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "*"
* f2 -> PrimaryExpression()
*/
- public String visit(TimesExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(TimesExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -550,13 +494,13 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f2 -> PrimaryExpression()
* f3 -> "]"
*/
- public String visit(ArrayLookup n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- return mod;
+ public R visit(ArrayLookup n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
}
/**
@@ -564,12 +508,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> "."
* f2 -> "length"
*/
- public String visit(ArrayLength n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(ArrayLength n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
/**
@@ -580,59 +524,37 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f4 -> ( ExpressionList() )?
* f5 -> ")"
*/
- public String visit(MessageSend n, SymbolTable symt) {
- String mod = "";
- String id = n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- String id2 = n.f2.accept(this, symt);
- TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); // TypeFactory likes to know who it's renting to
- TypeInstance tp2 = new TypeInstance("tp2", TypeEnum.ERROR);
-
- TypeInstance cur = symt.getType(id);
- int mtdIndex = cur.getClassInstance()
- .getMethods().indexOf(symt.getMethod(id2)) * 4;
-
- mod += String.format(" %s = [%s+%d]\n",
- this.tf.addNewAlias(tp1),
- this.tf.retrieveAlias(cur),
- 0);
-
- mod += String.format(" %s = [%s+%d]\n",
- this.tf.addNewAlias(tp2),
- this.tf.retrieveAlias(tp1),
- mtdIndex);
-
- mod += n.f3.accept(this, symt);
- mod = n.f4.accept(this, symt);
- mod += n.f5.accept(this, symt);
-
- mod += String.format(" call %s(%s)\n",
- this.tf.retrieveAlias(tp2),
- this.tf.retrieveAlias(cur));
-
- return mod;
+ public R visit(MessageSend n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ return _ret;
}
/**
* f0 -> Expression()
* f1 -> ( ExpressionRest() )*
*/
- public String visit(ExpressionList n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- return mod;
+ public R visit(ExpressionList n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
}
/**
* f0 -> ","
* f1 -> Expression()
*/
- public String visit(ExpressionRest n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- return mod;
+ public R visit(ExpressionRest n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
}
/**
@@ -646,55 +568,55 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* | NotExpression()
* | BracketExpression()
*/
- public String visit(PrimaryExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(PrimaryExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
* f0 -> <INTEGER_LITERAL>
*/
- public String visit(IntegerLiteral n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.tokenImage;
- return mod;
+ public R visit(IntegerLiteral n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
* f0 -> "true"
*/
- public String visit(TrueLiteral n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(TrueLiteral n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
* f0 -> "false"
*/
- public String visit(FalseLiteral n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(FalseLiteral n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
* f0 -> <IDENTIFIER>
*/
- public String visit(Identifier n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.tokenImage;
- return mod;
+ public R visit(Identifier n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
* f0 -> "this"
*/
- public String visit(ThisExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- return mod;
+ public R visit(ThisExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
}
/**
@@ -704,14 +626,14 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f3 -> Expression()
* f4 -> "]"
*/
- public String visit(ArrayAllocationExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- mod += n.f4.accept(this, symt);
- return mod;
+ public R visit(ArrayAllocationExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
}
/**
@@ -720,26 +642,24 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f2 -> "("
* f3 -> ")"
*/
- public String visit(AllocationExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- String cls = n.f1.accept(this, symt);
- mod += String.format(":functable_%s\n", cls);
-
- mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
- return mod;
+ public R visit(AllocationExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
}
/**
* f0 -> "!"
* f1 -> Expression()
*/
- public String visit(NotExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- return mod;
+ public R visit(NotExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
}
/**
@@ -747,12 +667,12 @@ public class VaporizeSimp extends GJDepthFirst<String,SymbolTable> {
* f1 -> Expression()
* f2 -> ")"
*/
- public String visit(BracketExpression n, SymbolTable symt) {
- String mod = "";
- mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
- return mod;
+ public R visit(BracketExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
}
}