diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 16:59:15 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 16:59:15 -0600 |
commit | 34fad9467618d10178d55f30c034f93ce03ada25 (patch) | |
tree | 494b3fd4cb4797070232b5add521f35c2adc70d8 | |
parent | 971666e64a46f342d633c4410ef08f216c5049b4 (diff) |
BoilVisitor.MessageSend for Bracket, proper class Extension in ST
-rw-r--r-- | J2V.java | 3 | ||||
-rw-r--r-- | boil/library/BoilVisitor.java | 20 | ||||
-rw-r--r-- | st/MethodInstance.java | 8 | ||||
-rw-r--r-- | st/SymTableMethods.java | 12 | ||||
-rw-r--r-- | st/SymTableVars.java | 5 | ||||
-rw-r--r-- | st/SymbolTable.java | 10 |
6 files changed, 44 insertions, 14 deletions
@@ -27,8 +27,11 @@ public class J2V { root.accept(new SymTableMethods<Void>(), symt); MinimalLogger.info("Populating variables..."); root.accept(new SymTableVars<Void>(), symt); + MinimalLogger.info("Populating extensions..."); + root.accept(new SymTableExtend<Void>(), symt); MinimalLogger.info(symt.toString()); + BoilVisitor vp = new BoilVisitor(symt); root.accept(vp, null); diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java index 560dda8..7ae02b2 100644 --- a/boil/library/BoilVisitor.java +++ b/boil/library/BoilVisitor.java @@ -13,6 +13,8 @@ public class BoilVisitor extends GJDepthFirst<String,String> { private int id; private SymbolTable symt; + private MethodInstance recentMethod = null; // the most recent method called + public BoilVisitor(SymbolTable symt) { this.symt = symt; this.vapor = ""; @@ -930,6 +932,8 @@ public class BoilVisitor extends GJDepthFirst<String,String> { MinimalLogger.info("Message send found an IDENTIFIER"); rhs = ((Identifier) n.f0.f0.choice).f0.tokenImage; t = this.symt.getType(rhs); + if (t == null) + t = this.symt.getTypeAttr(rhs); break; case 4: // we'll do everything here and exit the function @@ -952,6 +956,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { this.tf.retrieveRecentList(this.symt.getMethod(mtd, cur) .getArguments() .size()))); + this.recentMethod = this.symt.getMethod(mtd, cur); return _ret; case 6: MinimalLogger.info("Message send found ANONYMOUS"); @@ -971,8 +976,18 @@ public class BoilVisitor extends GJDepthFirst<String,String> { 0, rhs)); break; + case 8: + MinimalLogger.info("Message send found BRACKET"); + rhs = n.f0.accept(this, argu); + ClassInstance cls = this.recentMethod.getReturn(); + t = new TypeInstance(this.getUniqueID(), TypeEnum.ERROR, + (MethodInstance) this.symt.getActive(TypeEnum.method), + (ClassInstance) this.symt.getActive(TypeEnum.classname)); + t.addClassInstance(cls); + break; default: - MinimalLogger.severe("Message send found UNKNOWN"); + MinimalLogger.severe(String.format("Message send found UNKNOWN %s", + n.f0.f0.choice.toString())); rhs = null; t = null; } @@ -988,6 +1003,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { MinimalLogger.info("Calculating method index to call..."); MinimalLogger.severe("t: " + t); MinimalLogger.severe("t.getClassInstance() " + t.getClassInstance()); + this.recentMethod = this.symt.getMethod(mtd, t.getClassInstance()); int mtdIndex = t.getClassInstance().getMethods() .indexOf(this.symt.getMethod(mtd, t.getClassInstance())) * 4; @@ -1227,7 +1243,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { * f1 -> Expression() */ public String visit(NotExpression n, String argu) { - String _ret=null; + String _ret=""; MinimalLogger.info(String.format("-> %s", n.getClass().getSimpleName())); _ret += this.tf.alias(this.getUniqueID()); diff --git a/st/MethodInstance.java b/st/MethodInstance.java index c2f978b..9f1e6df 100644 --- a/st/MethodInstance.java +++ b/st/MethodInstance.java @@ -5,10 +5,10 @@ import java.util.ArrayList; public class MethodInstance extends AbstractInstance { private ArrayList<TypeInstance> args; // the list of arguments private ArrayList<TypeInstance> lvars; // the list of local variables - protected ClassInstance par_cls; // the surrounding class - private TypeEnum rtrn; // the returned type + protected ClassInstance par_cls; // the surrounding class + private ClassInstance rtrn; // the returned type - public MethodInstance(String name, TypeEnum rtrn, ClassInstance par_cls) { + public MethodInstance(String name, ClassInstance rtrn, ClassInstance par_cls) { super(name, TypeEnum.method); this.lvars = new ArrayList<>(); this.args = new ArrayList<>(); @@ -31,7 +31,7 @@ public class MethodInstance extends AbstractInstance { return this.lvars; } - public TypeEnum getReturn() { + public ClassInstance getReturn() { return this.rtrn; } diff --git a/st/SymTableMethods.java b/st/SymTableMethods.java index 6dc7d68..b14676a 100644 --- a/st/SymTableMethods.java +++ b/st/SymTableMethods.java @@ -54,7 +54,7 @@ public class SymTableMethods<R> extends GJDepthFirst<R,SymbolTable> { n.f17.accept(this, symt); TokenKey id = new TokenKey(n.f6.tokenImage, (ClassInstance) symt.getActive(TypeEnum.classname), null); - MethodInstance main = new MethodInstance(id.getName(), TypeEnum.ERROR, (ClassInstance) symt.getActive(TypeEnum.classname)); + MethodInstance main = new MethodInstance(id.getName(), null, (ClassInstance) symt.getActive(TypeEnum.classname)); symt.put(id, main); @@ -145,16 +145,16 @@ public class SymTableMethods<R> extends GJDepthFirst<R,SymbolTable> { TokenKey id = new TokenKey(n.f2.f0.tokenImage, (ClassInstance) symt.getActive(TypeEnum.classname), null); - TypeEnum rtrn = TypeEnum.ERROR; + ClassInstance rtrn = null; switch (n.f1.f0.which) { case 0: - rtrn = TypeEnum.intarray; break; + rtrn = new ClassInstance("intarray"); break; case 1: - rtrn = TypeEnum.bool; break; + rtrn = new ClassInstance("bool"); break; case 2: - rtrn = TypeEnum.integer; break; + rtrn = new ClassInstance("int"); break; case 3: - rtrn = TypeEnum.classname; break; + rtrn = new ClassInstance(((Identifier) n.f1.f0.choice).f0.tokenImage); break; default: MinimalLogger.severe("Unsupported case"); } diff --git a/st/SymTableVars.java b/st/SymTableVars.java index 36f02fc..37747dc 100644 --- a/st/SymTableVars.java +++ b/st/SymTableVars.java @@ -213,6 +213,11 @@ public class SymTableVars<R> extends GJDepthFirst<R,SymbolTable> { symt.put(id, instance); symt.addParameter(id.getName()); + String cls = (n.f0.f0.which == 3) ? + ((Identifier) n.f0.f0.choice).f0.tokenImage : + null; + symt.addClassInstance(instance, cls); + return null; } diff --git a/st/SymbolTable.java b/st/SymbolTable.java index 7f3c788..90640c6 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -55,11 +55,19 @@ public class SymbolTable { t.getName(), t.getType(), cls.getName(), cls.getType())); cls.addLocal(t); + this.symt.put(new TokenKey(t.getName(), + cls, + null), + t); } for (MethodInstance m : ext.getMethods()) { MinimalLogger.info(String.format("Added %s (%s) as a method of %s (%s)", m.getName(), m.getType(), cls.getName(), cls.getType())); + this.symt.put(new TokenKey(m.getName(), + cls, + null), + m); cls.addMethod(m); } } @@ -202,8 +210,6 @@ public class SymbolTable { if (ret == null) MinimalLogger.severe(String.format("getClass returning null for missing alias %s!", id)); - MinimalLogger.severe(String.format("It was: %s", - this.symt.get(id))); return ret; } |