diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 13:52:13 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 13:52:13 -0600 |
commit | e7e8d7751690c80cd2dd681f548d069d053cf23e (patch) | |
tree | 6b70a921b4a4d85372d0fd609eb326e2043d2f6b /boil/library/BoilVisitor.java | |
parent | c28a1cc9d206bdde41a621b018c01980b3c8a617 (diff) |
Fix first bugs in BoilVisitor for new SymbolTable
Diffstat (limited to 'boil/library/BoilVisitor.java')
-rw-r--r-- | boil/library/BoilVisitor.java | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java index 00d7dc7..cbbb434 100644 --- a/boil/library/BoilVisitor.java +++ b/boil/library/BoilVisitor.java @@ -37,7 +37,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { return attr_index; } - public String memoryReadFilter(TokenKey rhs) { + public String memoryReadFilter(String rhs) { /** * when a method recieves an id of either an alias * or an untranslated variable name, this method will @@ -174,11 +174,11 @@ public class BoilVisitor extends GJDepthFirst<String,String> { String _ret=null; this.tf.reset(); String id = n.f1.f0.tokenImage; - this.symt.setActive(TypeEnum.classname, id); - this.symt.setActive(TypeEnum.method, "main"); MinimalLogger.info(String.format("-> %s (%s)", n.getClass().getSimpleName(), id)); + this.symt.setActive(TypeEnum.classname, symt.getClass(id)); + this.symt.setActive(TypeEnum.method, symt.getMethod(n.f6.tokenImage)); /////////////////////////////////////////////////////////////// this.addVapor("func Main()\n"); n.f1.accept(this, argu); @@ -188,6 +188,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { this.addVapor(" ret\n\n"); /////////////////////////////////////////////////////////////// this.symt.removeActive(TypeEnum.method); + symt.removeActive(TypeEnum.classname); MinimalLogger.info(String.format("<- %s (%s)", n.getClass().getSimpleName(), id)); @@ -222,10 +223,10 @@ public class BoilVisitor extends GJDepthFirst<String,String> { public String visit(ClassDeclaration n, String argu) { String _ret=null; String id = n.f1.f0.tokenImage; - this.symt.setActive(TypeEnum.classname, id); MinimalLogger.info(String.format("-> %s (%s)", n.getClass().getSimpleName(), id)); + this.symt.setActive(TypeEnum.classname, symt.getClass(id)); /////////////////////////////////////////////////////////////// this.addVapor(String.format("const functable_%s\n", id)); for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { @@ -255,10 +256,10 @@ public class BoilVisitor extends GJDepthFirst<String,String> { public String visit(ClassExtendsDeclaration n, String argu) { String _ret=null; String id = n.f1.f0.tokenImage; - this.symt.setActive(TypeEnum.classname, id); MinimalLogger.info(String.format("-> %s (%s)", n.getClass().getSimpleName(), id)); + this.symt.setActive(TypeEnum.classname, symt.getClass(id)); /////////////////////////////////////////////////////////////// this.addVapor(String.format("const functable_%s\n", id)); for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { @@ -320,10 +321,10 @@ public class BoilVisitor extends GJDepthFirst<String,String> { String _ret=null; this.tf.reset(); String id = n.f2.f0.tokenImage; - this.symt.setActive(TypeEnum.method, id); MinimalLogger.info(String.format("-> %s (%s)", n.getClass().getSimpleName(), id)); + this.symt.setActive(TypeEnum.method, symt.getMethod(id)); /////////////////////////////////////////////////////////////// // n.f1.accept(this, argu); this.addVapor(String.format("func %s_%s(this ", @@ -531,7 +532,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { } if ((t = this.symt.getType(lhs)) != null) { // memory store - ClassInstance cur = this.symt.getClass(this.symt.getActive(TypeEnum.classname)); + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); attr_index = getVarIndex(cur, t); lhs = String.format("[this+%d]", attr_index); } @@ -873,7 +874,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { /** * f0 -> PrimaryExpression() * f1 -> "." - * f2 -> "length"l + * f2 -> "length" */ // Expressions return a TYPE alias which is equal to the expression! public String visit(ArrayLength n, String argu) { @@ -925,10 +926,10 @@ public class BoilVisitor extends GJDepthFirst<String,String> { // we'll do everything here and exit the function MinimalLogger.info("Message send found THIS"); rhs = n.f0.accept(this, argu); - ClassInstance cur = this.symt.getClass(this.symt.getActive(TypeEnum.classname)); + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); MinimalLogger.info("Calculating method index to call..."); int mtdIndex = cur.getMethods() - .indexOf(this.symt.getMethod(mtd)) * 4; + .indexOf(this.symt.getMethod(mtd, cur)) * 4; this.addVapor(n.f4.accept(this, argu)); this.addVapor(String.format(" %s = [%s+%d]\n", @@ -939,7 +940,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { _ret, rhs)); this.addVapor(String.format(" %s)\n", - this.tf.retrieveRecentList(this.symt.getMethod(mtd) + this.tf.retrieveRecentList(this.symt.getMethod(mtd, cur) .getArguments() .size()))); return _ret; @@ -947,7 +948,9 @@ public class BoilVisitor extends GJDepthFirst<String,String> { MinimalLogger.info("Message send found ANONYMOUS"); // expand the entire object out! rhs = n.f0.accept(this, argu); - t = new TypeInstance(this.getUniqueID(), TypeEnum.ERROR); + t = new TypeInstance(this.getUniqueID(), TypeEnum.ERROR, + (MethodInstance) this.symt.getActive(TypeEnum.method), + (ClassInstance) this.symt.getActive(TypeEnum.classname)); t.addClassInstance(this.symt.getClass(rhs.substring(rhs.indexOf('_')+1))); this.addVapor(String.format(" %s = HeapAllocZ(%d)\n", @@ -977,7 +980,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { MinimalLogger.severe("t: " + t); MinimalLogger.severe("t.getClassInstance() " + t.getClassInstance()); int mtdIndex = t.getClassInstance().getMethods() - .indexOf(this.symt.getMethod(mtd)) * 4; + .indexOf(this.symt.getMethod(mtd, t.getClassInstance())) * 4; this.vapor += String.format(" %s = [%s+%d]\n", tp2, @@ -992,7 +995,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { this.tf.alias(t.getName()))); this.addVapor(String.format(" %s)\n", - this.tf.retrieveRecentList(this.symt.getMethod(mtd) + this.tf.retrieveRecentList(this.symt.getMethod(mtd, t.getClassInstance()) .getArguments() .size()))); /////////////////////////////////////////////////////////////// @@ -1125,7 +1128,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { n.getClass().getSimpleName(), id)); /////////////////////////////////////////////////////////////// - ClassInstance cur = this.symt.getClass(this.symt.getActive(TypeEnum.classname)); + ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); TypeInstance t = this.symt.getType(id); if (cur.getLocals().contains(t)) { MinimalLogger.info(String.format("Identifier found a class variable %s", |