summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-26 20:57:37 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-26 20:57:37 -0600
commit797440387c1ec590914ccb45c1350dce2b549a92 (patch)
tree6b0ffae8121f9c43b5936c0185388177be211f51
parent75b0f765acdaf6571a723b8933ad584b980d08d4 (diff)
HeatVisitor.MethodDeclaraction checks correct return type
-rw-r--r--heat/HeatVisitor.java17
-rw-r--r--heat/TypeBundle.java4
2 files changed, 18 insertions, 3 deletions
diff --git a/heat/HeatVisitor.java b/heat/HeatVisitor.java
index 8d29813..f099a43 100644
--- a/heat/HeatVisitor.java
+++ b/heat/HeatVisitor.java
@@ -240,11 +240,19 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,ArrayList<String>> {
id));
this.symt.setActive(TypeEnum.method, symt.getMethod(id));
///////////////////////////////////////////////////////////////
- // n.f1.accept(this, argu);
+ TypeBundle tb = n.f1.accept(this, argu);
// n.f4.accept(this, para);
n.f7.accept(this, argu);
n.f8.accept(this, argu);
- n.f10.accept(this, argu);
+ _ret = n.f10.accept(this, argu);
+
+ // NOT
+ // if it is a class and the classes are equal
+ // or it is not a class and the types are equal
+ if (!((tb.getInstance() != null && tb.getInstance().equals(_ret.getInstance())) ||
+ (tb.getInstance() == null && tb.getType() == _ret.getType())))
+ throw new TypecheckException(String.format("%s returns the wrong type!",
+ id));
///////////////////////////////////////////////////////////////
this.symt.removeActive(TypeEnum.method);
MinimalLogger.info(String.format("<- %s (%s)",
@@ -319,7 +327,10 @@ public class HeatVisitor extends GJDepthFirst<TypeBundle,ArrayList<String>> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- _ret = n.f0.accept(this, argu);
+ if (n.f0.which == 3)
+ _ret = new TypeBundle(TypeEnum.classname, this.symt.getClass(((Identifier) n.f0.choice).f0.tokenImage));
+ else
+ _ret = n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
diff --git a/heat/TypeBundle.java b/heat/TypeBundle.java
index d8bfb4f..ac00e71 100644
--- a/heat/TypeBundle.java
+++ b/heat/TypeBundle.java
@@ -53,4 +53,8 @@ class TypeBundle {
return this.type;
}
+ public ClassInstance getInstance() {
+ return this.instance;
+ }
+
}