diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-26 23:07:54 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-26 23:09:01 -0600 |
commit | 5db69446e6e898129c28bea19fbb8bb111c5101c (patch) | |
tree | 73c23d1fa22e529fe25315e19895160eaaf8018f | |
parent | d85af967c1e537a84aa99c4072de1726374b3c39 (diff) |
Many new tests (probably) proper sub-typing
-rw-r--r-- | heat/HeatVisitor.java | 36 | ||||
-rw-r--r-- | heat/TypeBundle.java | 6 |
2 files changed, 28 insertions, 14 deletions
diff --git a/heat/HeatVisitor.java b/heat/HeatVisitor.java index 02d10d4..243812c 100644 --- a/heat/HeatVisitor.java +++ b/heat/HeatVisitor.java @@ -443,15 +443,21 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,ArrayList<TypeBundle>> if (t == null) t = this.symt.getTypeAttr(id); if (t == null) - throw new TypecheckException(String.format("%s was never declared!", + throw new TypecheckException(String.format("%s found that %s was never declared!", + n.getClass().getSimpleName(), id)); - TypeBundle tb = new TypeBundle(t.getType(), null); + TypeBundle tb = new TypeBundle(t.getType(), t.getClassInstance()); - // Fixme---add subtyping? _ret = n.f2.accept(this, argu); + + MinimalLogger.severe(String.format("t is %s, tb is %s", + tb.getInstance(), + _ret.getInstance())); + if (!tb.equals(_ret)) - throw new TypecheckException(String.format("%s tried to assign unequal types!", - n.getClass().getSimpleName())); + throw new TypecheckException(String.format("%s tried to assign unequal type to %s!", + n.getClass().getSimpleName(), + id)); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<- %s with %s", n.getClass().getSimpleName(), @@ -478,17 +484,20 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,ArrayList<TypeBundle>> if (t == null) t = this.symt.getTypeAttr(id); if (t == null) - throw new TypecheckException(String.format("%s was never declared!", + throw new TypecheckException(String.format("%s found that %s was never declared!", + n.getClass().getSimpleName(), id)); if (t.getType() != TypeEnum.intarray) - throw new TypecheckException(String.format("%s called on non-array!", - n.getClass().getSimpleName())); + throw new TypecheckException(String.format("%s called on %s, a non-array!", + n.getClass().getSimpleName(), + id)); TypeBundle tb = n.f2.accept(this, argu); _ret = n.f5.accept(this, argu); if (!tb.isInt() || !_ret.isInt()) - throw new TypecheckException(String.format("%s tried with something other than an integer!", - n.getClass().getSimpleName())); + throw new TypecheckException(String.format("%s tried to assign %s to a non-integer!", + n.getClass().getSimpleName(), + id)); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<- %s with %s", n.getClass().getSimpleName(), @@ -773,8 +782,9 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,ArrayList<TypeBundle>> if (t == null) t = this.symt.getTypeAttr(((Identifier) n.f0.f0.choice).f0.tokenImage); if (t == null) - throw new TypecheckException(String.format("%s was never declared!", - ((Identifier) n.f0.f0.choice).f0.tokenImage)); + throw new TypecheckException(String.format("%s found that %s was never declared!", + n.getClass().getSimpleName(), + ((Identifier) n.f0.f0.choice).f0.tokenImage)); // HOW TO CALL? break; case 4: MinimalLogger.info(String.format("Message send found THIS")); @@ -836,7 +846,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,ArrayList<TypeBundle>> else if (ret.equals("int")) _ret = new TypeBundle(TypeEnum.integer, null); else - _ret = new TypeBundle(TypeEnum.classname, null); + _ret = new TypeBundle(TypeEnum.classname, m.getReturn()); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<- %s with %s", n.getClass().getSimpleName(), diff --git a/heat/TypeBundle.java b/heat/TypeBundle.java index ac00e71..1867e0d 100644 --- a/heat/TypeBundle.java +++ b/heat/TypeBundle.java @@ -25,8 +25,12 @@ class TypeBundle { } @Override public boolean equals(Object other) { + TypeBundle tb; return (other instanceof TypeBundle) && - ((TypeBundle) other).type == this.type; + (tb = (TypeBundle) other).type == this.type && + (tb.instance == this.instance || + (tb.instance != null && tb.instance.getExtend() != null && + tb.instance.getExtend().equals(this.instance))); } public boolean isClass() { |