Skip to content
Snippets Groups Projects
Verified Commit b0176d4c authored by Miles Vella's avatar Miles Vella
Browse files

Support IF-ELSIF-ELSE expressions

parent 85da40ac
No related branches found
No related tags found
No related merge requests found
Pipeline #152321 passed
...@@ -412,13 +412,24 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker { ...@@ -412,13 +412,24 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker {
UntypedType x = new UntypedType(); UntypedType x = new UntypedType();
setType(node.getThen(), x); setType(node.getThen(), x);
node.getElsifs().forEach(n -> setType(n, x));
setType(node.getElse(), x); setType(node.getElse(), x);
node.getThen().apply(this); node.getThen().apply(this);
node.getElsifs().forEach(n -> n.apply(this));
node.getElse().apply(this); node.getElse().apply(this);
BType found = getType(node.getThen()); BType found = getType(node.getThen());
unify(getType(node), found, node); unify(getType(node), found, node);
} }
@Override
public void caseAIfElsifExprExpression(AIfElsifExprExpression node) {
setType(node.getCondition(), BoolType.getInstance());
node.getCondition().apply(this);
setType(node.getThen(), getType(node));
node.getThen().apply(this);
}
@Override @Override
public void caseANotEqualPredicate(ANotEqualPredicate node) { public void caseANotEqualPredicate(ANotEqualPredicate node) {
try { try {
......
...@@ -33,7 +33,7 @@ public class UnsupportedConstructsFinder extends DepthFirstAdapter { ...@@ -33,7 +33,7 @@ public class UnsupportedConstructsFinder extends DepthFirstAdapter {
add(AFloatSetExpression.class); add(AFloatSetExpression.class);
add(ARealExpression.class); add(ARealExpression.class);
add(AIfElsifExprExpression.class); // should have been rewritten in parser
add(AIfPredicatePredicate.class); add(AIfPredicatePredicate.class);
add(AIfElsifPredicatePredicate.class); add(AIfElsifPredicatePredicate.class);
......
...@@ -1146,6 +1146,7 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -1146,6 +1146,7 @@ public class TLAPrinter extends DepthFirstAdapter {
@Override @Override
public void caseAIfThenElseExpression(AIfThenElseExpression node) { public void caseAIfThenElseExpression(AIfThenElseExpression node) {
if (node.getElsifs().isEmpty()) {
moduleStringAppend("(IF "); moduleStringAppend("(IF ");
node.getCondition().apply(this); node.getCondition().apply(this);
moduleStringAppend(" THEN "); moduleStringAppend(" THEN ");
...@@ -1153,6 +1154,26 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -1153,6 +1154,26 @@ public class TLAPrinter extends DepthFirstAdapter {
moduleStringAppend(" ELSE "); moduleStringAppend(" ELSE ");
node.getElse().apply(this); node.getElse().apply(this);
moduleStringAppend(")"); moduleStringAppend(")");
} else {
moduleStringAppend("(CASE ");
node.getCondition().apply(this);
moduleStringAppend(" -> ");
node.getThen().apply(this);
node.getElsifs().forEach(n -> {
moduleStringAppend(" [] ");
n.apply(this);
});
moduleStringAppend(" [] OTHER -> ");
node.getElse().apply(this);
moduleStringAppend(")");
}
}
@Override
public void caseAIfElsifExprExpression(AIfElsifExprExpression node) {
node.getCondition().apply(this);
moduleStringAppend(" -> ");
node.getThen().apply(this);
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment