summaryrefslogtreecommitdiff
path: root/minijava
diff options
context:
space:
mode:
Diffstat (limited to 'minijava')
-rw-r--r--minijava/PPrinter.java12
-rw-r--r--minijava/SymTableVis.java20
-rw-r--r--minijava/TypeCheckSimp.java105
3 files changed, 68 insertions, 69 deletions
diff --git a/minijava/PPrinter.java b/minijava/PPrinter.java
index aed7ec4..9ffadf7 100644
--- a/minijava/PPrinter.java
+++ b/minijava/PPrinter.java
@@ -14,8 +14,8 @@ public class PPrinter<R,A> extends GJDepthFirst<R,A> {
private void printNode(Node n, A argu) {
for (int i=0; i < this.offset; ++i)
- System.out.print(".");
- System.out.println(n.getClass().getSimpleName());
+ Utilities.print_filter(".", false);
+ Utilities.print_filter(n.getClass().getSimpleName(), true);
++this.offset;
}
@@ -726,10 +726,10 @@ public class PPrinter<R,A> extends GJDepthFirst<R,A> {
public R visit(NodeToken n, A argu) {
for (int i=0; i < this.offset; ++i)
- System.out.print(".");
- System.out.println(n.getClass().getSimpleName() +
- " => " +
- n.toString());
+ Utilities.print_filter(".", false);
+ Utilities.print_filter(n.getClass().getSimpleName() +
+ " => " +
+ n.toString(), true);
R _ret=null;
return _ret;
}
diff --git a/minijava/SymTableVis.java b/minijava/SymTableVis.java
index 6f03c45..1a48fd2 100644
--- a/minijava/SymTableVis.java
+++ b/minijava/SymTableVis.java
@@ -12,12 +12,6 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> {
public HashMap<String,TypeInstance> symt = new HashMap<>();
- private void print_filter(String message) {
- boolean debug = true;
- if (debug)
- System.out.println(message);
- }
-
/**
* f0 -> "class"
* f1 -> Identifier()
@@ -45,12 +39,12 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> {
n.f14.accept(this, argu);
n.f15.accept(this, argu);
- this.print_filter("Processing main");
+ Utilities.print_filter("Processing main", true);
String id = n.f1.f0.tokenImage;
TypeInstance type = new TypeInstance(id, TypeEnum.classname);
- this.print_filter("Inserting " + id + " => " + type);
+ Utilities.print_filter("Inserting " + id + " => " + type, true);
symt.put(id, type);
return null;
@@ -64,7 +58,7 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> {
*/
public R visit(VarDeclaration n, A argu) {
- this.print_filter("Processing declaration");
+ Utilities.print_filter("Processing declaration", true);
String id = n.f1.f0.tokenImage;
TypeInstance type = new TypeInstance("ERROR", TypeEnum.ERROR);
@@ -78,10 +72,10 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> {
case 3:
type = new TypeInstance(id, TypeEnum.classname); break;
default:
- this.print_filter("Unsupported case");
+ Utilities.print_filter("Unsupported case", true);
}
- this.print_filter("Inserting " + id + " => " + type);
+ Utilities.print_filter("Inserting " + id + " => " + type, true);
// Safe?
symt.put(id, type);
@@ -90,12 +84,12 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> {
public R visit(ClassDeclaration n, A argu) {
- this.print_filter("Processing class");
+ Utilities.print_filter("Processing class", true);
String id = n.f1.f0.tokenImage;
TypeInstance type = new TypeInstance(id, TypeEnum.classname);
- this.print_filter("Inserting " + id + " => " + type);
+ Utilities.print_filter("Inserting " + id + " => " + type, true);
// Safe?
symt.put(id, type);
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;