diff options
Diffstat (limited to 'minijava/TypeCheckSimp.java')
-rw-r--r-- | minijava/TypeCheckSimp.java | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/minijava/TypeCheckSimp.java b/minijava/TypeCheckSimp.java index 4ad0639..57b6be9 100644 --- a/minijava/TypeCheckSimp.java +++ b/minijava/TypeCheckSimp.java @@ -14,19 +14,19 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type private void printNode(Node n, HashMap<String,TypeInstance> argu, boolean enter, TypeEnum consensus) { for (int i=0; i < this.offset; ++i) - System.out.print("."); + Utilities.print_filter(".", false); if (enter) - System.out.print("Visiting "); + Utilities.print_filter("Visiting ", false); else - System.out.print("Leaving "); - System.out.print(n.getClass().getSimpleName()); + Utilities.print_filter("Leaving ", false); + Utilities.print_filter(n.getClass().getSimpleName(), false); if (!enter) { if (consensus == TypeEnum.ERROR) - System.out.print(" did not type check."); + Utilities.print_filter(" did not type check.", false); else - System.out.print(" found type " + consensus); + Utilities.print_filter(" found type " + consensus, false); } - System.out.println(); + Utilities.print_filter("", true); } // @@ -174,7 +174,7 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type n.f8.accept(this, argu); n.f9.accept(this, argu); n.f10.accept(this, argu); - // TypeInstance args = n.f11.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); @@ -189,7 +189,7 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type /** * f0 -> ClassDeclaration() - * | ClassExtendsDeclaration() + * | ClassExtendsDeclaration() */ public TypeInstance visit(TypeDeclaration n, HashMap<String,TypeInstance> argu) { ++this.offset; @@ -245,20 +245,26 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type ++this.offset; this.printNode(n, argu, true, null); - TypeInstance _ret=null; n.f0.accept(this, argu); - n.f1.accept(this, argu); + TypeInstance id = n.f1.accept(this, argu); n.f2.accept(this, argu); - n.f3.accept(this, argu); + TypeInstance ext = n.f3.accept(this, argu); n.f4.accept(this, argu); - n.f5.accept(this, argu); - n.f6.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()) ? + new TypeInstance(null, TypeEnum.CHECK) : + new TypeInstance(null, TypeEnum.ERROR); + + this.printNode(n, argu, false, ret.get_type()); --this.offset; - return _ret; + return ret; } - // FIXME + // FIXME (this may be ST-only) /** * f0 -> Type() * f1 -> Identifier() @@ -375,15 +381,15 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type /** * f0 -> ArrayType() - * | BooleanType() - * | IntegerType() - * | Identifier() + * | BooleanType() + * | IntegerType() + * | Identifier() */ public TypeInstance visit(Type n, HashMap<String,TypeInstance> argu) { ++this.offset; this.printNode(n, argu, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, argu); this.printNode(n, argu, false, ret.get_type()); --this.offset; @@ -413,7 +419,7 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type ++this.offset; this.printNode(n, argu, true, null); - TypeInstance ret = new TypeInstance(null, TypeEnum.bool); + TypeInstance ret = new TypeInstance(null, TypeEnum.bool); this.printNode(n, argu, false, ret.get_type()); --this.offset; @@ -427,7 +433,7 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type ++this.offset; this.printNode(n, argu, true, null); - TypeInstance ret = new TypeInstance(null, TypeEnum.integer); + TypeInstance ret = new TypeInstance(null, TypeEnum.integer); this.printNode(n, argu, false, ret.get_type()); --this.offset; @@ -436,17 +442,17 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type /** * f0 -> Block() - * | AssignmentStatement() - * | ArrayAssignmentStatement() - * | IfStatement() - * | WhileStatement() - * | PrintStatement() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() */ public TypeInstance visit(Statement n, HashMap<String,TypeInstance> argu) { ++this.offset; this.printNode(n, argu, true, null); - TypeInstance ret = n.f0.accept(this, argu); + TypeInstance ret = n.f0.accept(this, argu); this.printNode(n, argu, false, ret.get_type()); --this.offset; @@ -521,9 +527,9 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type n.f4.accept(this, argu); TypeInstance value = n.f5.accept(this, argu); n.f6.accept(this, argu); - TypeInstance ret = (id.get_type() == TypeEnum.int_array && - index.get_type() == TypeEnum.integer && - value.get_type() == TypeEnum.integer) ? + TypeInstance ret = (id.get_type() == TypeEnum.int_array && + index.get_type() == TypeEnum.integer && + value.get_type() == TypeEnum.integer) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); @@ -623,14 +629,14 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type /** * f0 -> AndExpression() - * | CompareExpression() - * | PlusExpression() - * | MinusExpression() - * | TimesExpression() - * | ArrayLookup() - * | ArrayLength() - * | MessageSend() - * | PrimaryExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() */ public TypeInstance visit(Expression n, HashMap<String,TypeInstance> argu) { ++this.offset; @@ -814,7 +820,7 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type // FIXME FIXME FIXME /** - * [35]: + * [35]: * * f0 -> PrimaryExpression() * f1 -> "." @@ -827,7 +833,6 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type ++this.offset; this.printNode(n, argu, true, null); - TypeInstance _ret=null; n.f0.accept(this, argu); n.f1.accept(this, argu); n.f2.accept(this, argu); @@ -835,7 +840,7 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type n.f4.accept(this, argu); n.f5.accept(this, argu); --this.offset; - return _ret; + return new TypeInstance(null, TypeEnum.ERROR); } // FIXME @@ -877,14 +882,14 @@ public class TypeCheckSimp implements GJVisitor<TypeInstance,HashMap<String,Type /** * f0 -> IntegerLiteral() - * | TrueLiteral() - * | FalseLiteral() - * | Identifier() - * | ThisExpression() - * | ArrayAllocationExpression() - * | AllocationExpression() - * | NotExpression() - * | BracketExpression() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() */ public TypeInstance visit(PrimaryExpression n, HashMap<String,TypeInstance> argu) { ++this.offset; |