diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-14 02:20:43 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-14 02:20:43 -0600 |
commit | 6ecd1893b4586c7077c6969431b47ca4e0962240 (patch) | |
tree | d2900b503fe723820f1b66e9499b2b79ad6c00b1 | |
parent | 9f344f33b0fbc948815511f60296ce6804bd9c02 (diff) |
TypeCheck.MessageSend partial implementation
-rw-r--r-- | typecheck/library/TypeCheckSimp.java | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/typecheck/library/TypeCheckSimp.java b/typecheck/library/TypeCheckSimp.java index 2eb5bf1..b50fa53 100644 --- a/typecheck/library/TypeCheckSimp.java +++ b/typecheck/library/TypeCheckSimp.java @@ -219,11 +219,10 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { 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); + TypeInstance mtds = n.f4.accept(this, symt); n.f5.accept(this, symt); - TypeInstance ret = (id.getType() == TypeEnum.classname && - vars.hasChecked() && - mehs.hasChecked()) ? + TypeInstance ret = (vars.hasChecked() && + mtds.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); @@ -286,6 +285,9 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { // FIXME /** + * [7.5]: Parameters identifiers are distinct, local vars are distinct, + * (vars in scope?), all statements type check + * * f0 -> "public" * f1 -> Type() * f2 -> Identifier() @@ -304,6 +306,7 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { ++this.offset; this.printNode(n, symt, true, null); + MethodInstance self = symt.getMethod(n.f2.f0.tokenImage); n.f0.accept(this, symt); TypeInstance ret_type = n.f1.accept(this, symt); n.f2.accept(this, symt); @@ -314,10 +317,10 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { n.f7.accept(this, symt); TypeInstance stmt = n.f8.accept(this, symt); n.f9.accept(this, symt); - TypeInstance retur = n.f10.accept(this, symt); + TypeInstance rtrn = n.f10.accept(this, symt); n.f11.accept(this, symt); n.f12.accept(this, symt); - TypeInstance ret = (stmt.sameType(ret_type) && + TypeInstance ret = (self.getReturn() == rtrn.getType() && // FIXME I am checking that the rtrn matches the method's declared return type. Is this in the document? stmt.hasChecked()) ? new TypeInstance(null, TypeEnum.CHECK) : new TypeInstance(null, TypeEnum.ERROR); @@ -834,14 +837,19 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { ++this.offset; this.printNode(n, symt, true, null); - n.f0.accept(this, symt); + // this MUST be an instance of a class! + TypeInstance t = n.f0.accept(this, symt); + ClassInstance c = t.getClassInstance(); n.f1.accept(this, symt); n.f2.accept(this, symt); + MethodInstance m = symt.getMethod(n.f2.f0.tokenImage); n.f3.accept(this, symt); n.f4.accept(this, symt); n.f5.accept(this, symt); --this.offset; - return new TypeInstance(null, TypeEnum.ERROR); + return (true) ? + new TypeInstance(null, m.getReturn()) : + new TypeInstance(null, TypeEnum.ERROR); } // FIXME @@ -957,10 +965,21 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { this.printNode(n, symt, true, null); TypeInstance type; - TypeInstance ret = ((type = symt.getType(n.f0.tokenImage)) != null) ? - new TypeInstance(type.getName(), - type.getType()) : - new TypeInstance(null, TypeEnum.ERROR); + TypeInstance ret; + ClassInstance cls; + if ((cls = symt.getClass(n.f0.tokenImage)) != null) { + // covers "anonymous" instance + ret = new TypeInstance(cls.getName(), + TypeEnum.classname); + ret.addClassInstance(cls); + } else { + if ((type = symt.getType(n.f0.tokenImage)) != null) { + ret = new TypeInstance(type.getName(), + type.getType()); + ret.addClassInstance(type.getClassInstance()); + } else + ret = new TypeInstance(null, TypeEnum.ERROR); + } this.printNode(n, symt, false, ret.getType()); --this.offset; |