summaryrefslogtreecommitdiff
path: root/heat/HeatVisitor.java
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-26 18:23:59 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-26 18:23:59 -0600
commit289a419681bfde1edd91a695ca97116a57d62433 (patch)
tree2eb1c3918e6f3da4249bbf31d4abd0b31018b008 /heat/HeatVisitor.java
parent7c6c79a437a4c1e7cf85964d005a3cdeb59809f1 (diff)
Implemented some basic HeatVisitor rules
Diffstat (limited to 'heat/HeatVisitor.java')
-rw-r--r--heat/HeatVisitor.java218
1 files changed, 112 insertions, 106 deletions
diff --git a/heat/HeatVisitor.java b/heat/HeatVisitor.java
index 746166c..fdc71ad 100644
--- a/heat/HeatVisitor.java
+++ b/heat/HeatVisitor.java
@@ -113,24 +113,9 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
this.symt.setActive(TypeEnum.classname, symt.getClass(id));
this.symt.setActive(TypeEnum.method, symt.getMethod(n.f6.tokenImage));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
- n.f4.accept(this, argu);
- n.f5.accept(this, argu);
- n.f6.accept(this, argu);
- n.f7.accept(this, argu);
- n.f8.accept(this, argu);
- n.f9.accept(this, argu);
- n.f10.accept(this, argu);
- n.f11.accept(this, argu);
- n.f12.accept(this, argu);
- n.f13.accept(this, argu);
n.f14.accept(this, argu);
n.f15.accept(this, argu);
- n.f16.accept(this, argu);
- n.f17.accept(this, argu);
///////////////////////////////////////////////////////////////
this.symt.removeActive(TypeEnum.method);
this.symt.removeActive(TypeEnum.classname);
@@ -173,12 +158,9 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
id));
this.symt.setActive(TypeEnum.classname, symt.getClass(id));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
n.f3.accept(this, argu);
n.f4.accept(this, argu);
- n.f5.accept(this, argu);
///////////////////////////////////////////////////////////////
this.symt.removeActive(TypeEnum.classname);
MinimalLogger.info(String.format("<- %s (%s)",
@@ -205,14 +187,10 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
id));
this.symt.setActive(TypeEnum.classname, symt.getClass(id));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
n.f3.accept(this, argu);
- n.f4.accept(this, argu);
n.f5.accept(this, argu);
n.f6.accept(this, argu);
- n.f7.accept(this, argu);
///////////////////////////////////////////////////////////////
this.symt.removeActive(TypeEnum.classname);
MinimalLogger.info(String.format("<- %s (%s)",
@@ -235,7 +213,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
///////////////////////////////////////////////////////////////
n.f0.accept(this, argu);
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s (%s)",
n.getClass().getSimpleName(),
@@ -266,19 +243,12 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
id));
this.symt.setActive(TypeEnum.method, symt.getMethod(id));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
n.f2.accept(this, argu);
- n.f3.accept(this, argu);
n.f4.accept(this, argu);
- n.f5.accept(this, argu);
- n.f6.accept(this, argu);
n.f7.accept(this, argu);
n.f8.accept(this, argu);
- n.f9.accept(this, argu);
n.f10.accept(this, argu);
- n.f11.accept(this, argu);
- n.f12.accept(this, argu);
///////////////////////////////////////////////////////////////
this.symt.removeActive(TypeEnum.method);
MinimalLogger.info(String.format("<- %s (%s)",
@@ -335,7 +305,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
@@ -373,9 +342,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -391,7 +357,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -407,7 +372,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -446,9 +410,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -469,9 +431,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
n.f0.accept(this, argu);
- n.f1.accept(this, argu);
n.f2.accept(this, argu);
- n.f3.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -494,12 +454,8 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
n.f0.accept(this, argu);
- n.f1.accept(this, argu);
n.f2.accept(this, argu);
- n.f3.accept(this, argu);
- n.f4.accept(this, argu);
n.f5.accept(this, argu);
- n.f6.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -521,12 +477,8 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
n.f2.accept(this, argu);
- n.f3.accept(this, argu);
n.f4.accept(this, argu);
- n.f5.accept(this, argu);
n.f6.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
@@ -547,10 +499,10 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!_ret.isBool())
+ throw new TypecheckException(String.format("%s called on non-bool conditional!",
+ n.getClass().getSimpleName()));
n.f4.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
@@ -571,11 +523,10 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
- n.f4.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!_ret.isInt())
+ throw new TypecheckException(String.format("%s called on a non-integer!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -599,7 +550,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
+ _ret = n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -617,9 +568,11 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ TypeBundle tb = n.f0.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!tb.isBool() || _ret.isBool())
+ throw new TypecheckException(String.format("%s tried with something other than an Boolean!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -637,9 +590,12 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ TypeBundle tb = n.f0.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!tb.isInt() || _ret.isInt())
+ throw new TypecheckException(String.format("%s tried with something other than an integer!",
+ n.getClass().getSimpleName()));
+ _ret = new TypeBundle(TypeEnum.bool, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -657,9 +613,11 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ TypeBundle tb = n.f0.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!tb.isInt() || _ret.isInt())
+ throw new TypecheckException(String.format("%s tried with something other than an integer!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -677,9 +635,15 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ TypeBundle tb = n.f0.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!tb.isInt() || _ret.isInt())
+ throw new TypecheckException(String.format("%s tried with something other than an integer!",
+ n.getClass().getSimpleName()));
+ ///////////////////////////////////////////////////////////////
+ MinimalLogger.info(String.format("<- %s with %s",
+ n.getClass().getSimpleName(),
+ _ret));
return _ret;
}
@@ -693,9 +657,11 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ TypeBundle tb = n.f0.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!tb.isInt() || _ret.isInt())
+ throw new TypecheckException(String.format("%s tried with something other than an integer!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -714,10 +680,11 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
+ TypeBundle tb = n.f0.accept(this, argu);
+ _ret = n.f2.accept(this, argu);
+ if (!tb.isArray() || !_ret.isInt())
+ throw new TypecheckException(String.format("%s tried on a non-array, or with a non-int index!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -735,9 +702,12 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ _ret = n.f0.accept(this, argu);
+ if (_ret.isArray())
+ _ret = new TypeBundle(TypeEnum.integer, null);
+ else
+ throw new TypecheckException(String.format("%s tried on a non-array!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -758,12 +728,53 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
+ TypeInstance t;
+ switch (n.f0.f0.which) {
+ case 3:
+ MinimalLogger.info(String.format("Message send found IDENTIFIER"));
+ t = this.symt.getType(((Identifier) n.f0.f0.choice).f0.tokenImage);
+ break;
+ case 4:
+ MinimalLogger.info(String.format("Message send found THIS"));
+ t = new TypeInstance("null",null,null,null);
+ t.addClassInstance((ClassInstance) this.symt.getActive(TypeEnum.classname));
+ break;
+ case 6:
+ MinimalLogger.info(String.format("Message send found ANONYMOUS"));
+ t = new TypeInstance("null",null,null,null);
+ break;
+ case 8:
+ MinimalLogger.info(String.format("Message send found BRACKET"));
+ t = new TypeInstance("null",null,null,null);
+ break;
+ default:
+ MinimalLogger.info(String.format("Message send found UNKNOWN %s",
+ n.f0.f0.choice.toString()));
+ t = null;
+ }
+
+ if (t == null || t.getClassInstance() == null)
+ throw new TypecheckException(String.format("%s called on a missing/non class variable!",
+ n.getClass().getSimpleName()));
+
+ MethodInstance m = this.symt.getMethod(n.f2.f0.tokenImage, t.getClassInstance());
+
+ if (m == null)
+ throw new TypecheckException(String.format("%s called a method not part of %s!",
+ n.getClass().getSimpleName(),
+ t.getName()));
+
+ // FIXME Evaluate parameters!
n.f4.accept(this, argu);
- n.f5.accept(this, argu);
+ String ret = m.getReturn().getName();
+ if (ret.equals("intarray"))
+ _ret = new TypeBundle(TypeEnum.intarray, null);
+ else if (ret.equals("bool"))
+ _ret = new TypeBundle(TypeEnum.bool, null);
+ else if (ret.equals("int"))
+ _ret = new TypeBundle(TypeEnum.integer, null);
+ else
+ _ret = new TypeBundle(TypeEnum.classname, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -781,7 +792,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
n.f0.accept(this, argu);
- n.f1.accept(this, argu);
+ _ret = n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -798,8 +809,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
+ _ret = n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -823,7 +833,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
+ _ret = n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -839,7 +849,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
+ _ret = new TypeBundle(TypeEnum.integer, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -855,7 +865,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
+ _ret = new TypeBundle(TypeEnum.bool, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -871,7 +881,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
+ _ret = new TypeBundle(TypeEnum.bool, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -887,6 +897,8 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
+ if (true)
+ throw new TypecheckException("Identifier says: stop calling me!");
n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
@@ -903,7 +915,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -923,11 +934,12 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
- n.f4.accept(this, argu);
+ _ret = n.f3.accept(this, argu);
+ if (_ret.isInt())
+ _ret = new TypeBundle(TypeEnum.intarray, null);
+ else
+ throw new TypecheckException(String.format("%s tried with a non-integer!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -946,10 +958,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
- n.f3.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -966,8 +975,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
+ _ret = n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -985,9 +993,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
- n.f2.accept(this, argu);
+ _ret = n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),