diff options
Diffstat (limited to 'typecheck/library')
-rw-r--r-- | typecheck/library/TypeCheckSimp.java | 681 |
1 files changed, 341 insertions, 340 deletions
diff --git a/typecheck/library/TypeCheckSimp.java b/typecheck/library/TypeCheckSimp.java index 59ee69b..b3a9ca3 100644 --- a/typecheck/library/TypeCheckSimp.java +++ b/typecheck/library/TypeCheckSimp.java @@ -10,11 +10,11 @@ import java.util.*; * Provides default methods which visit each node in the tree in depth-first * order. Your visitors may extend this class. */ -public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,AbstractInstance>> { +public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { private int offset; - private void printNode(Node n, HashMap<String,AbstractInstance> argu, boolean enter, TypeEnum consensus) { + private void printNode(Node n, SymbolTable symt, boolean enter, TypeEnum consensus) { for (int i=0; i < this.offset; ++i) PrintFilter.print(".", false); if (enter) @@ -31,36 +31,36 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst PrintFilter.print("", true); } - public TypeInstance visit(NodeList n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(NodeList n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret = new TypeInstance(null, TypeEnum.CHECK); int _count=0; for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { - TypeInstance node = e.nextElement().accept(this,argu); - e.nextElement().accept(this,argu); - if (node.get_type() == TypeEnum.ERROR) + TypeInstance node = e.nextElement().accept(this,symt); + e.nextElement().accept(this,symt); + if (node.getType() == TypeEnum.ERROR) ret = node; _count++; } - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } - public TypeInstance visit(NodeListOptional n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(NodeListOptional n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret; if ( n.present() ) { ret = new TypeInstance(null, TypeEnum.CHECK); int _count=0; for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { - TypeInstance node = e.nextElement().accept(this,argu); - if (node.get_type() == TypeEnum.ERROR) + TypeInstance node = e.nextElement().accept(this,symt); + if (node.getType() == TypeEnum.ERROR) ret = node; _count++; } @@ -68,47 +68,47 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst else ret = new TypeInstance(null, TypeEnum.CHECK); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } // FIXME - public TypeInstance visit(NodeOptional n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(NodeOptional n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret; if ( n.present() ) - ret = n.node.accept(this,argu); + ret = n.node.accept(this,symt); else ret = new TypeInstance(null, TypeEnum.CHECK); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } - public TypeInstance visit(NodeSequence n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(NodeSequence n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret = new TypeInstance(null, TypeEnum.CHECK); int _count=0; for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { - TypeInstance node = e.nextElement().accept(this,argu); - if (node.get_type() == TypeEnum.ERROR) + TypeInstance node = e.nextElement().accept(this,symt); + if (node.getType() == TypeEnum.ERROR) ret = node; _count++; } - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } - public TypeInstance visit(NodeToken n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(NodeToken n, SymbolTable symt) { // A fixed string token. '⌣' for (int i=0; i < this.offset; ++i) PrintFilter.print(".", false); @@ -127,15 +127,15 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> ( TypeDeclaration() )* * f2 -> <EOF> */ - public TypeInstance visit(Goal n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(Goal n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -160,30 +160,30 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f16 -> "}" * f17 -> "}" */ - public TypeInstance visit(MainClass n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(MainClass n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - TypeInstance name = 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); - // TypeInstance args = n.f11.accept(this, argu); // FIXME Type in the main class declaration uses an illegal minijava type? - n.f12.accept(this, argu); - n.f13.accept(this, argu); - TypeInstance var_dec = n.f14.accept(this, argu); - TypeInstance stmt = n.f15.accept(this, argu); - n.f16.accept(this, argu); - n.f17.accept(this, argu); - - this.printNode(n, argu, false, stmt.get_type()); + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + TypeInstance name = n.f1.accept(this, symt); + n.f2.accept(this, symt); + n.f3.accept(this, symt); + n.f4.accept(this, symt); + n.f5.accept(this, symt); + n.f6.accept(this, symt); + n.f7.accept(this, symt); + 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? + n.f12.accept(this, symt); + n.f13.accept(this, symt); + TypeInstance var_dec = n.f14.accept(this, symt); + TypeInstance stmt = n.f15.accept(this, symt); + n.f16.accept(this, symt); + n.f17.accept(this, symt); + + this.printNode(n, symt, false, stmt.getType()); --this.offset; return stmt; } @@ -192,13 +192,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> ClassDeclaration() * | ClassExtendsDeclaration() */ - public TypeInstance visit(TypeDeclaration n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(TypeDeclaration n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -211,23 +211,23 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f4 -> ( MethodDeclaration() )* * f5 -> "}" */ - public TypeInstance visit(ClassDeclaration n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ClassDeclaration n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - TypeInstance id = n.f1.accept(this, argu); - n.f2.accept(this, argu); - TypeInstance vars = n.f3.accept(this, argu); - TypeInstance mehs = n.f4.accept(this, argu); - n.f5.accept(this, argu); - TypeInstance ret = (id.get_type() == TypeEnum.classname && - vars.has_checked() && - mehs.has_checked()) ? + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + TypeInstance id = n.f1.accept(this, symt); + n.f2.accept(this, symt); + TypeInstance vars = n.f3.accept(this, symt); + TypeInstance mehs = n.f4.accept(this, symt); + n.f5.accept(this, symt); + TypeInstance ret = (id.getType() == TypeEnum.classname && + vars.hasChecked() && + mehs.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -242,25 +242,25 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f6 -> ( MethodDeclaration() )* * f7 -> "}" */ - public TypeInstance visit(ClassExtendsDeclaration n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ClassExtendsDeclaration n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - TypeInstance id = n.f1.accept(this, argu); - n.f2.accept(this, argu); - TypeInstance ext = n.f3.accept(this, argu); - n.f4.accept(this, argu); - TypeInstance vars = n.f5.accept(this, argu); - TypeInstance mehs = n.f6.accept(this, argu); - n.f7.accept(this, argu); - TypeInstance ret = (id.get_type() == TypeEnum.classname && - vars.has_checked() && - mehs.has_checked()) ? + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + TypeInstance id = n.f1.accept(this, symt); + n.f2.accept(this, symt); + TypeInstance ext = n.f3.accept(this, symt); + n.f4.accept(this, symt); + TypeInstance vars = n.f5.accept(this, symt); + TypeInstance mehs = n.f6.accept(this, symt); + n.f7.accept(this, symt); + TypeInstance ret = (id.getType() == TypeEnum.classname && + vars.hasChecked() && + mehs.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -271,15 +271,15 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> Identifier() * f2 -> ";" */ - public TypeInstance visit(VarDeclaration n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(VarDeclaration n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -300,29 +300,29 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f11 -> ";" * f12 -> "}" */ - public TypeInstance visit(MethodDeclaration n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(MethodDeclaration n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - TypeInstance ret_type = 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); - TypeInstance stmt = n.f8.accept(this, argu); - n.f9.accept(this, argu); - TypeInstance retur = n.f10.accept(this, argu); - n.f11.accept(this, argu); - n.f12.accept(this, argu); - TypeInstance ret = (stmt.same_type(ret_type) && - stmt.has_checked()) ? + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + TypeInstance ret_type = n.f1.accept(this, symt); + n.f2.accept(this, symt); + n.f3.accept(this, symt); + n.f4.accept(this, symt); + n.f5.accept(this, symt); + n.f6.accept(this, symt); + n.f7.accept(this, symt); + TypeInstance stmt = n.f8.accept(this, symt); + n.f9.accept(this, symt); + TypeInstance retur = n.f10.accept(this, symt); + n.f11.accept(this, symt); + n.f12.accept(this, symt); + TypeInstance ret = (stmt.sameType(ret_type) && + stmt.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -331,19 +331,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> FormalParameter() * f1 -> ( FormalParameterRest() )* */ - public TypeInstance visit(FormalParameterList n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(FormalParameterList n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance _ret=null; - TypeInstance para1 = n.f0.accept(this, argu); - TypeInstance parar = n.f1.accept(this, argu); - TypeInstance ret = (para1.has_checked() && - parar.has_checked()) ? + TypeInstance para1 = n.f0.accept(this, symt); + TypeInstance parar = n.f1.accept(this, symt); + TypeInstance ret = (para1.hasChecked() && + parar.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -352,14 +352,14 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> Type() * f1 -> Identifier() */ - public TypeInstance visit(FormalParameter n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(FormalParameter n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); - n.f1.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); + n.f1.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -368,14 +368,14 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> "," * f1 -> FormalParameter() */ - public TypeInstance visit(FormalParameterRest n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(FormalParameterRest n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); - TypeInstance ret = n.f1.accept(this, argu); + n.f0.accept(this, symt); + TypeInstance ret = n.f1.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -386,13 +386,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * | IntegerType() * | Identifier() */ - public TypeInstance visit(Type n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(Type n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -402,13 +402,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "[" * f2 -> "]" */ - public TypeInstance visit(ArrayType n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ArrayType n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret = new TypeInstance(null, TypeEnum.intarray); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -416,13 +416,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst /** * f0 -> "boolean" */ - public TypeInstance visit(BooleanType n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(BooleanType n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret = new TypeInstance(null, TypeEnum.bool); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -430,13 +430,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst /** * f0 -> "int" */ - public TypeInstance visit(IntegerType n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(IntegerType n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); TypeInstance ret = new TypeInstance(null, TypeEnum.integer); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -449,13 +449,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * | WhileStatement() * | PrintStatement() */ - public TypeInstance visit(Statement n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(Statement n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -465,15 +465,15 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> ( Statement() )* * f2 -> "}" */ - public TypeInstance visit(Block n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(Block n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); - TypeInstance ret = n.f1.accept(this, argu); - n.f2.accept(this, argu); + n.f0.accept(this, symt); + TypeInstance ret = n.f1.accept(this, symt); + n.f2.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -488,19 +488,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f2 -> Expression() * f3 -> ";" */ - public TypeInstance visit(AssignmentStatement n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(AssignmentStatement n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance lhs = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance rhs = n.f2.accept(this, argu); - n.f3.accept(this, argu); - TypeInstance ret = (lhs.same_type(rhs)) ? + TypeInstance lhs = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance rhs = n.f2.accept(this, symt); + n.f3.accept(this, symt); + TypeInstance ret = (lhs.sameType(rhs)) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -517,24 +517,24 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f5 -> Expression() * f6 -> ";" */ - public TypeInstance visit(ArrayAssignmentStatement n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ArrayAssignmentStatement n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - TypeInstance id = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance index = n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - TypeInstance value = n.f5.accept(this, argu); - n.f6.accept(this, argu); - TypeInstance ret = (id.get_type() == TypeEnum.intarray && - index.get_type() == TypeEnum.integer && - value.get_type() == TypeEnum.integer) ? + this.printNode(n, symt, true, null); + + TypeInstance id = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance index = n.f2.accept(this, symt); + n.f3.accept(this, symt); + n.f4.accept(this, symt); + TypeInstance value = n.f5.accept(this, symt); + n.f6.accept(this, symt); + TypeInstance ret = (id.getType() == TypeEnum.intarray && + index.getType() == TypeEnum.integer && + value.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -550,24 +550,24 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f5 -> "else" * f6 -> Statement() */ - public TypeInstance visit(IfStatement n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(IfStatement n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance expr = n.f2.accept(this, argu); - n.f3.accept(this, argu); - TypeInstance stmt1 = n.f4.accept(this, argu); - n.f5.accept(this, argu); - TypeInstance stmt2 = n.f6.accept(this, argu); - TypeInstance ret = (expr.get_type() == TypeEnum.bool && - stmt1.get_type() == stmt2.get_type() && - stmt1.has_checked()) ? + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance expr = n.f2.accept(this, symt); + n.f3.accept(this, symt); + TypeInstance stmt1 = n.f4.accept(this, symt); + n.f5.accept(this, symt); + TypeInstance stmt2 = n.f6.accept(this, symt); + TypeInstance ret = (expr.getType() == TypeEnum.bool && + stmt1.getType() == stmt2.getType() && + stmt1.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; @@ -582,21 +582,21 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f3 -> ")" * f4 -> Statement() */ - public TypeInstance visit(WhileStatement n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(WhileStatement n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance expr = n.f2.accept(this, argu); - n.f3.accept(this, argu); - TypeInstance stmt = n.f4.accept(this, argu); - TypeInstance ret = (expr.get_type() == TypeEnum.bool && - stmt.has_checked()) ? + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance expr = n.f2.accept(this, symt); + n.f3.accept(this, symt); + TypeInstance stmt = n.f4.accept(this, symt); + TypeInstance ret = (expr.getType() == TypeEnum.bool && + stmt.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -610,20 +610,20 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f3 -> ")" * f4 -> ";" */ - public TypeInstance visit(PrintStatement n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(PrintStatement n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance ret = n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - ret = (ret.get_type() == TypeEnum.integer) ? + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance ret = n.f2.accept(this, symt); + n.f3.accept(this, symt); + n.f4.accept(this, symt); + ret = (ret.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -639,13 +639,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * | MessageSend() * | PrimaryExpression() */ - public TypeInstance visit(Expression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(Expression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -657,19 +657,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "&&" * f2 -> PrimaryExpression() */ - public TypeInstance visit(AndExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(AndExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance oper1 = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance oper2 = n.f2.accept(this, argu); - TypeInstance ret = (oper1.get_type() == TypeEnum.bool && - oper2.get_type() == TypeEnum.bool) ? + TypeInstance oper1 = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance oper2 = n.f2.accept(this, symt); + TypeInstance ret = (oper1.getType() == TypeEnum.bool && + oper2.getType() == TypeEnum.bool) ? new TypeInstance(null, TypeEnum.bool) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -681,19 +681,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "<" * f2 -> PrimaryExpression() */ - public TypeInstance visit(CompareExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(CompareExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance oper1 = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance oper2 = n.f2.accept(this, argu); - TypeInstance ret = (oper1.get_type() == TypeEnum.integer && - oper2.get_type() == TypeEnum.integer) ? + TypeInstance oper1 = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance oper2 = n.f2.accept(this, symt); + TypeInstance ret = (oper1.getType() == TypeEnum.integer && + oper2.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.bool) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -705,19 +705,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "+" * f2 -> PrimaryExpression() */ - public TypeInstance visit(PlusExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(PlusExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance oper1 = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance oper2 = n.f2.accept(this, argu); - TypeInstance ret = (oper1.get_type() == TypeEnum.integer && - oper2.get_type() == TypeEnum.integer) ? + TypeInstance oper1 = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance oper2 = n.f2.accept(this, symt); + TypeInstance ret = (oper1.getType() == TypeEnum.integer && + oper2.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.integer) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -729,19 +729,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "-" * f2 -> PrimaryExpression() */ - public TypeInstance visit(MinusExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(MinusExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance oper1 = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance oper2 = n.f2.accept(this, argu); - TypeInstance ret = (oper1.get_type() == TypeEnum.integer && - oper2.get_type() == TypeEnum.integer) ? + TypeInstance oper1 = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance oper2 = n.f2.accept(this, symt); + TypeInstance ret = (oper1.getType() == TypeEnum.integer && + oper2.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.integer) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -753,19 +753,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "*" * f2 -> PrimaryExpression() */ - public TypeInstance visit(TimesExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(TimesExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance oper1 = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance oper2 = n.f2.accept(this, argu); - TypeInstance ret = (oper1.get_type() == TypeEnum.integer && - oper2.get_type() == TypeEnum.integer) ? + TypeInstance oper1 = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance oper2 = n.f2.accept(this, symt); + TypeInstance ret = (oper1.getType() == TypeEnum.integer && + oper2.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.integer) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -779,20 +779,20 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f2 -> PrimaryExpression() * f3 -> "]" */ - public TypeInstance visit(ArrayLookup n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ArrayLookup n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - TypeInstance array = n.f0.accept(this, argu); - n.f1.accept(this, argu); - TypeInstance index = n.f2.accept(this, argu); - n.f3.accept(this, argu); - TypeInstance ret = (array.get_type() == TypeEnum.intarray && - index.get_type() == TypeEnum.integer) ? + this.printNode(n, symt, true, null); + + TypeInstance array = n.f0.accept(this, symt); + n.f1.accept(this, symt); + TypeInstance index = n.f2.accept(this, symt); + n.f3.accept(this, symt); + TypeInstance ret = (array.getType() == TypeEnum.intarray && + index.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.integer) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -804,17 +804,17 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> "." * f2 -> "length" */ - public TypeInstance visit(ArrayLength n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ArrayLength n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - ret = (ret.get_type() == TypeEnum.intarray) ? new TypeInstance(null, TypeEnum.integer) : + TypeInstance ret = n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); + ret = (ret.getType() == TypeEnum.intarray) ? new TypeInstance(null, TypeEnum.integer) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -830,16 +830,16 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f4 -> ( ExpressionList() )? * f5 -> ")" */ - public TypeInstance visit(MessageSend n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(MessageSend n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, 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); + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); + n.f3.accept(this, symt); + n.f4.accept(this, symt); + n.f5.accept(this, symt); --this.offset; return new TypeInstance(null, TypeEnum.ERROR); } @@ -849,18 +849,18 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> Expression() * f1 -> ( ExpressionRest() )* */ - public TypeInstance visit(ExpressionList n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ExpressionList n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance expr1 = n.f0.accept(this, argu); - TypeInstance exprr = n.f1.accept(this, argu); - TypeInstance ret = (expr1.has_checked() && - exprr.has_checked()) ? + TypeInstance expr1 = n.f0.accept(this, symt); + TypeInstance exprr = n.f1.accept(this, symt); + TypeInstance ret = (expr1.hasChecked() && + exprr.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -869,14 +869,14 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> "," * f1 -> Expression() */ - public TypeInstance visit(ExpressionRest n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ExpressionRest n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); - TypeInstance ret = n.f1.accept(this, argu); + n.f0.accept(this, symt); + TypeInstance ret = n.f1.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -892,13 +892,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * | NotExpression() * | BracketExpression() */ - public TypeInstance visit(PrimaryExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(PrimaryExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -909,11 +909,11 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * * f0 -> <INTEGER_LITERAL> */ - public TypeInstance visit(IntegerLiteral n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(IntegerLiteral n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - this.printNode(n, argu, false, TypeEnum.integer); + this.printNode(n, symt, false, TypeEnum.integer); --this.offset; return new TypeInstance(null, TypeEnum.integer); } @@ -923,11 +923,11 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * * f0 -> "true" */ - public TypeInstance visit(TrueLiteral n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(TrueLiteral n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - this.printNode(n, argu, false, TypeEnum.bool); + this.printNode(n, symt, false, TypeEnum.bool); --this.offset; return new TypeInstance(null, TypeEnum.bool); } @@ -937,11 +937,11 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * * f0 -> "false" */ - public TypeInstance visit(FalseLiteral n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(FalseLiteral n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - this.printNode(n, argu, false, TypeEnum.bool); + this.printNode(n, symt, false, TypeEnum.bool); --this.offset; return new TypeInstance(null, TypeEnum.bool); } @@ -952,16 +952,17 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * * f0 -> <IDENTIFIER> */ - public TypeInstance visit(Identifier n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(Identifier n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - TypeInstance ret = (argu.get(n.f0.tokenImage) != null) ? - new TypeInstance(argu.get(n.f0.tokenImage).get_name(), - argu.get(n.f0.tokenImage).get_type()) : + TypeInstance type; + TypeInstance ret = ((type = symt.getType(n.f0.tokenImage)) != null) ? + new TypeInstance(type.getName(), + type.getType()) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -972,14 +973,14 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * * f0 -> "this" */ - public TypeInstance visit(ThisExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ThisExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); + n.f0.accept(this, symt); TypeInstance ret = new TypeInstance(null, TypeEnum.CHECK); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -993,19 +994,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f3 -> Expression() * f4 -> "]" */ - public TypeInstance visit(ArrayAllocationExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(ArrayAllocationExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); - - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - TypeInstance ret = n.f3.accept(this, argu); - n.f4.accept(this, argu); - ret = (ret.get_type() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.intarray) : + this.printNode(n, symt, true, null); + + n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); + TypeInstance ret = n.f3.accept(this, symt); + n.f4.accept(this, symt); + ret = (ret.getType() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.intarray) : new TypeInstance(null, TypeEnum.ERROR); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -1019,16 +1020,16 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f2 -> "(" * f3 -> ")" */ - public TypeInstance visit(AllocationExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(AllocationExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); - TypeInstance ret = n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); + n.f0.accept(this, symt); + TypeInstance ret = n.f1.accept(this, symt); + n.f2.accept(this, symt); + n.f3.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } @@ -1039,16 +1040,16 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f0 -> "!" * f1 -> Expression() */ - public TypeInstance visit(NotExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(NotExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); - TypeInstance ret = n.f1.accept(this, argu); + n.f0.accept(this, symt); + TypeInstance ret = n.f1.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; - return (ret.get_type() == TypeEnum.bool) ? ret : new TypeInstance(null, TypeEnum.ERROR); + return (ret.getType() == TypeEnum.bool) ? ret : new TypeInstance(null, TypeEnum.ERROR); } /** @@ -1058,15 +1059,15 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,HashMap<String,Abst * f1 -> Expression() * f2 -> ")" */ - public TypeInstance visit(BracketExpression n, HashMap<String,AbstractInstance> argu) { + public TypeInstance visit(BracketExpression n, SymbolTable symt) { ++this.offset; - this.printNode(n, argu, true, null); + this.printNode(n, symt, true, null); - n.f0.accept(this, argu); - TypeInstance ret = n.f1.accept(this, argu); - n.f2.accept(this, argu); + n.f0.accept(this, symt); + TypeInstance ret = n.f1.accept(this, symt); + n.f2.accept(this, symt); - this.printNode(n, argu, false, ret.get_type()); + this.printNode(n, symt, false, ret.getType()); --this.offset; return ret; } |