summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-26 18:46:54 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-26 18:46:54 -0600
commit42512ab2cfd16422909263475b044f40b3829707 (patch)
tree80e48cd04ef86900f77e7e63e57147499c9b5e43
parent289a419681bfde1edd91a695ca97116a57d62433 (diff)
Most simple methods reimplemented in HeatVisitor
-rw-r--r--heat/HeatVisitor.java57
-rw-r--r--heat/TypeBundle.java8
2 files changed, 43 insertions, 22 deletions
diff --git a/heat/HeatVisitor.java b/heat/HeatVisitor.java
index fdc71ad..ba739c9 100644
--- a/heat/HeatVisitor.java
+++ b/heat/HeatVisitor.java
@@ -113,7 +113,6 @@ 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.f1.accept(this, argu);
n.f14.accept(this, argu);
n.f15.accept(this, argu);
///////////////////////////////////////////////////////////////
@@ -158,7 +157,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
id));
this.symt.setActive(TypeEnum.classname, symt.getClass(id));
///////////////////////////////////////////////////////////////
- n.f1.accept(this, argu);
n.f3.accept(this, argu);
n.f4.accept(this, argu);
///////////////////////////////////////////////////////////////
@@ -182,13 +180,12 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
public TypeBundle visit(ClassExtendsDeclaration n, String argu) {
TypeBundle _ret=null;
String id = n.f1.f0.tokenImage;
+ String id0 = n.f3.f0.tokenImage;
MinimalLogger.info(String.format("-> %s (%s)",
n.getClass().getSimpleName(),
id));
this.symt.setActive(TypeEnum.classname, symt.getClass(id));
///////////////////////////////////////////////////////////////
- n.f1.accept(this, argu);
- n.f3.accept(this, argu);
n.f5.accept(this, argu);
n.f6.accept(this, argu);
///////////////////////////////////////////////////////////////
@@ -211,8 +208,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
n.getClass().getSimpleName(),
id));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
+ _ret = n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s (%s)",
n.getClass().getSimpleName(),
@@ -244,7 +240,6 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
this.symt.setActive(TypeEnum.method, symt.getMethod(id));
///////////////////////////////////////////////////////////////
n.f1.accept(this, argu);
- n.f2.accept(this, argu);
n.f4.accept(this, argu);
n.f7.accept(this, argu);
n.f8.accept(this, argu);
@@ -266,6 +261,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
+ // FIXME Check distinct!
n.f0.accept(this, argu);
n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
@@ -286,8 +282,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
n.getClass().getSimpleName(),
id));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f1.accept(this, argu);
+ _ret = n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s (%s)",
n.getClass().getSimpleName(),
@@ -305,7 +300,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f1.accept(this, argu);
+ _ret = n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -324,7 +319,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(),
@@ -342,6 +337,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
+ _ret = new TypeBundle(TypeEnum.intarray, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -357,6 +353,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
+ _ret = new TypeBundle(TypeEnum.bool, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -372,6 +369,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
+ _ret = new TypeBundle(TypeEnum.integer, null);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -392,7 +390,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(),
@@ -410,7 +408,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f1.accept(this, argu);
+ _ret = n.f1.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -430,8 +428,16 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f2.accept(this, argu);
+ TypeBundle tb = new TypeBundle(this.symt.getType(id).getType(), null);
+ if (tb.getType() == null)
+ throw new TypecheckException(String.format("%s glowers at symbol table!",
+ n.getClass().getSimpleName()));
+
+ // Fixme---add subtyping?
+ _ret = n.f2.accept(this, argu);
+ if (!tb.equals(_ret))
+ throw new TypecheckException(String.format("%s tried to assign unequal types!",
+ n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -450,12 +456,20 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
*/
public TypeBundle visit(ArrayAssignmentStatement n, String argu) {
TypeBundle _ret=null;
+ String id = n.f0.f0.tokenImage;
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f0.accept(this, argu);
- n.f2.accept(this, argu);
- n.f5.accept(this, argu);
+ TypeInstance t = this.symt.getType(id);
+ if (t == null || t.getType() != TypeEnum.intarray)
+ throw new TypecheckException(String.format("%s called on non-array!",
+ n.getClass().getSimpleName()));
+
+ 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()));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -477,7 +491,10 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- n.f2.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);
n.f6.accept(this, argu);
///////////////////////////////////////////////////////////////
@@ -754,7 +771,7 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,String> {
}
if (t == null || t.getClassInstance() == null)
- throw new TypecheckException(String.format("%s called on a missing/non class variable!",
+ throw new TypecheckException(String.format("%s called on a non class variable!",
n.getClass().getSimpleName()));
MethodInstance m = this.symt.getMethod(n.f2.f0.tokenImage, t.getClassInstance());
diff --git a/heat/TypeBundle.java b/heat/TypeBundle.java
index 44e3749..d8bfb4f 100644
--- a/heat/TypeBundle.java
+++ b/heat/TypeBundle.java
@@ -9,8 +9,8 @@ import st.ClassInstance;
*/
class TypeBundle {
- TypeEnum type;
- ClassInstance instance;
+ private TypeEnum type;
+ private ClassInstance instance;
protected TypeBundle(TypeEnum type, ClassInstance instance) {
this.type = type;
@@ -49,4 +49,8 @@ class TypeBundle {
return this.type == TypeEnum.integer;
}
+ public TypeEnum getType() {
+ return this.type;
+ }
+
}