From 63270d092073ec2bed15151315d005a0b8858073 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Thu, 25 Apr 2024 14:14:17 -0600 Subject: Fix last new bug in BoilVisitor from symt changes --- boil/library/BoilVisitor.java | 51 ++++++++++++++++--------------------------- st/SymbolTable.java | 19 ++++++++++++++-- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java index cbbb434..eb47432 100644 --- a/boil/library/BoilVisitor.java +++ b/boil/library/BoilVisitor.java @@ -37,22 +37,8 @@ public class BoilVisitor extends GJDepthFirst { return attr_index; } - public String memoryReadFilter(String rhs) { - /** - * when a method recieves an id of either an alias - * or an untranslated variable name, this method will - * automatically create a memory store var. - */ + public String memoryRead(String rhs) { String lhs = this.tf.alias(this.getUniqueID()); - int attr_index = 0; - TypeInstance t; - if ((t = this.symt.getType(rhs)) != null) { - // memory store - ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); - attr_index = getVarIndex(cur, t); - rhs = String.format("[this+%d]", attr_index); - } - this.addVapor(String.format(" %s = %s\n", lhs, rhs)); @@ -335,7 +321,7 @@ public class BoilVisitor extends GJDepthFirst { n.f7.accept(this, argu); n.f8.accept(this, argu); - String ret = this.memoryReadFilter(n.f10.accept(this, argu)); + String ret = n.f10.accept(this, argu); String retID = this.getUniqueID(); this.addVapor(String.format(" %s = %s\n ret %s\n\n", this.tf.alias(retID), @@ -562,7 +548,7 @@ public class BoilVisitor extends GJDepthFirst { n.getClass().getSimpleName())); /////////////////////////////////////////////////////////////// String arrID = this.tf.alias(this.getUniqueID()); - String arr = this.memoryReadFilter(n.f0.accept(this, argu)); + String arr = n.f0.accept(this, argu); this.addVapor(String.format(" %s = %s\n", arrID, arr)); @@ -728,8 +714,8 @@ public class BoilVisitor extends GJDepthFirst { n.getClass().getSimpleName())); _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// - String oper1 = n.f0.accept(this, argu); - String oper2 = n.f2.accept(this, argu); + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); this.addVapor(String.format(" %s = Eq(%s %s)\n", _ret, oper1, @@ -753,8 +739,8 @@ public class BoilVisitor extends GJDepthFirst { n.getClass().getSimpleName())); _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// - String oper1 = n.f0.accept(this, argu); - String oper2 = n.f2.accept(this, argu); + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); this.addVapor(String.format(" %s = LtS(%s %s)\n", _ret, oper1, @@ -778,8 +764,8 @@ public class BoilVisitor extends GJDepthFirst { n.getClass().getSimpleName())); _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// - String oper1 = this.memoryReadFilter(n.f0.accept(this, argu)); - String oper2 = this.memoryReadFilter(n.f2.accept(this, argu)); + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); this.addVapor(String.format(" %s = Add(%s %s)\n", _ret, oper1, @@ -803,8 +789,8 @@ public class BoilVisitor extends GJDepthFirst { n.getClass().getSimpleName())); _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// - String oper1 = this.memoryReadFilter(n.f0.accept(this, argu)); - String oper2 = this.memoryReadFilter(n.f2.accept(this, argu)); + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); this.addVapor(String.format(" %s = Sub(%s %s)\n", _ret, oper1, @@ -828,8 +814,8 @@ public class BoilVisitor extends GJDepthFirst { n.getClass().getSimpleName())); _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// - String oper1 = this.memoryReadFilter(n.f0.accept(this, argu)); - String oper2 = this.memoryReadFilter(n.f2.accept(this, argu)); + String oper1 = this.memoryRead(n.f0.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); this.addVapor(String.format(" %s = MulS(%s %s)\n", _ret, oper1, @@ -855,7 +841,7 @@ public class BoilVisitor extends GJDepthFirst { _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// String arrID = this.tf.alias(this.getUniqueID()); - String arr = this.memoryReadFilter(n.f0.accept(this, argu)); + String arr = n.f0.accept(this, argu); int index = Integer.parseInt(n.f2.accept(this, argu)) * 4 + 4; this.addVapor(String.format(" %s = %s\n", arrID, @@ -884,7 +870,7 @@ public class BoilVisitor extends GJDepthFirst { _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// String arrID = this.tf.alias(this.getUniqueID()); - String arr = this.memoryReadFilter(n.f0.accept(this, argu)); + String arr = n.f0.accept(this, argu); this.addVapor(String.format(" %s = %s\n", arrID, arr)); @@ -1129,12 +1115,13 @@ public class BoilVisitor extends GJDepthFirst { id)); /////////////////////////////////////////////////////////////// ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname); - TypeInstance t = this.symt.getType(id); + // TypeInstance localt = this.symt.getType(id); + TypeInstance t = this.symt.getTypeAttr(id); if (cur.getLocals().contains(t)) { MinimalLogger.info(String.format("Identifier found a class variable %s", id)); - // handle elsewhere :( - _ret += n.f0.tokenImage; + int attr_index = getVarIndex(cur, t); + _ret += String.format("[this+%d]", attr_index); } else { _ret += this.tf.alias(id); } diff --git a/st/SymbolTable.java b/st/SymbolTable.java index ed1506b..7f3c788 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -148,6 +148,21 @@ public class SymbolTable { return ret; } + public TypeInstance getTypeAttr(String name) { + TokenKey id = new TokenKey(name, + (ClassInstance) this.getActive(TypeEnum.classname), + null); + AbstractInstance symbol; + TypeInstance ret = ((symbol = this.symt.get(id)) != + null && symbol instanceof TypeInstance) ? + (TypeInstance) symbol : null; + if (ret == null) + MinimalLogger.severe(String.format("getType returning null for missing alias %s!", + id)); + return ret; + } + + public MethodInstance getMethod(String name) { TokenKey id = new TokenKey(name, (ClassInstance) this.getActive(TypeEnum.classname), @@ -189,11 +204,11 @@ public class SymbolTable { id)); MinimalLogger.severe(String.format("It was: %s", this.symt.get(id))); - return ret; + return ret; } public AbstractInstance getActive(TypeEnum type) { - return this.active.get(type); + return this.active.get(type); } } -- cgit v1.2.3