diff options
| author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 14:14:17 -0600 | 
|---|---|---|
| committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 14:14:17 -0600 | 
| commit | 63270d092073ec2bed15151315d005a0b8858073 (patch) | |
| tree | fb45c078a1885f30672ad30375ac940025c10660 /boil/library/BoilVisitor.java | |
| parent | e7e8d7751690c80cd2dd681f548d069d053cf23e (diff) | |
Fix last new bug in BoilVisitor from symt changessymbol-table-new-key
Diffstat (limited to 'boil/library/BoilVisitor.java')
| -rw-r--r-- | boil/library/BoilVisitor.java | 51 | 
1 files changed, 19 insertions, 32 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<String,String> {          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<String,String> {          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<String,String> {                                           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<String,String> {                                           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<String,String> {                                           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<String,String> {                                           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<String,String> {                                           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<String,String> {                                           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<String,String> {          _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<String,String> {          _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<String,String> {                                           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);          }  | 
