Skip to content
Snippets Groups Projects
Commit 0d19e402 authored by hansen's avatar hansen
Browse files

Some modifications in the type checker

parent 812da092
Branches
Tags
No related merge requests found
...@@ -324,6 +324,7 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns, ...@@ -324,6 +324,7 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
TLAType type = (TLAType) rightside.getToolObject(TYPE_ID); TLAType type = (TLAType) rightside.getToolObject(TYPE_ID);
try { try {
TLAType res = type.unify(expected); TLAType res = type.unify(expected);
setType(exprNode, res);
return res; return res;
} catch (UnificationException e) { } catch (UnificationException e) {
throw new TypeErrorException(String.format( throw new TypeErrorException(String.format(
...@@ -331,6 +332,7 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns, ...@@ -331,6 +332,7 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
exprNode.getLocation())); exprNode.getLocation()));
} }
} }
case LetInKind: { case LetInKind: {
...@@ -356,6 +358,14 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns, ...@@ -356,6 +358,14 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
} }
private void setType(SemanticNode node, TLAType type){
node.setToolObject(TYPE_ID, type);
if (type instanceof AbstractHasFollowers){
((AbstractHasFollowers) type).addFollower(node);
}
}
/** /**
* @param n * @param n
* @param expected * @param expected
...@@ -852,15 +862,14 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns, ...@@ -852,15 +862,14 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
TupleOrFunction tupleOrFunc = new TupleOrFunction( TupleOrFunction tupleOrFunc = new TupleOrFunction(
num.val(), u); num.val(), u);
TLAType funcOrTuple = visitExprOrOpArgNode(n.getArgs()[0], TLAType res = visitExprOrOpArgNode(n.getArgs()[0],
tupleOrFunc); tupleOrFunc);
n.getArgs()[0].setToolObject(TYPE_ID, funcOrTuple); n.getArgs()[0].setToolObject(TYPE_ID, res);
tupleNodeList.add(n.getArgs()[0]); tupleNodeList.add(n.getArgs()[0]);
if (funcOrTuple instanceof AbstractHasFollowers) { if (res instanceof AbstractHasFollowers) {
((AbstractHasFollowers) funcOrTuple).addFollower(n ((AbstractHasFollowers) res).addFollower(n
.getArgs()[0]); .getArgs()[0]);
} }
TLAType found = (TLAType) n.getToolObject(TYPE_ID); TLAType found = (TLAType) n.getToolObject(TYPE_ID);
try { try {
found = found.unify(expected); found = found.unify(expected);
...@@ -1196,6 +1205,8 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns, ...@@ -1196,6 +1205,8 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
return domType; return domType;
} }
/** /**
* @param n * @param n
* @param expected * @param expected
......
...@@ -320,6 +320,7 @@ public class TupleOrFunction extends AbstractHasFollowers { ...@@ -320,6 +320,7 @@ public class TupleOrFunction extends AbstractHasFollowers {
} }
} }
update();
} }
public TLAType getFinalType() { public TLAType getFinalType() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment