Skip to content
Snippets Groups Projects
Commit 80e60b92 authored by Jan Gruteser's avatar Jan Gruteser
Browse files

support arithmetic operators for both reals and integers

should be simplified but fixes tests for now
parent 59852b07
No related branches found
No related tags found
No related merge requests found
Pipeline #134688 passed
...@@ -1193,25 +1193,44 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns, ...@@ -1193,25 +1193,44 @@ public class TypeChecker extends BuiltInOPs implements ASTConstants, BBuildIns,
case B_OPCODE_div: // / case B_OPCODE_div: // /
case B_OPCODE_mod: // % modulo case B_OPCODE_mod: // % modulo
case B_OPCODE_exp: { // x hoch y, x^y case B_OPCODE_exp: { // x hoch y, x^y
TLAType type;
// TODO: Simplify
if (expected instanceof RealType) {
try { try {
RealType.getInstance().unify(expected); RealType.getInstance().unify(expected);
for (int i = 0; i < n.getArgs().length; i++) { type = RealType.getInstance();
visitExprOrOpArgNode(n.getArgs()[i], RealType.getInstance());
}
return RealType.getInstance();
} catch (UnificationException e) { } catch (UnificationException e) {
throw new TypeErrorException(String.format("Expected %s, found REAL at '%s',%n%s", expected,
n.getOperator().getName(), n.getLocation()));
}
} else if (expected instanceof IntType) {
try { try {
IntType.getInstance().unify(expected); IntType.getInstance().unify(expected);
type = IntType.getInstance();
} catch (UnificationException ue) {
throw new TypeErrorException(String.format("Expected %s, found INTEGER at '%s',%n%s", expected,
n.getOperator().getName(), n.getLocation()));
}
} else if (expected instanceof UntypedType) {
IntType.getInstance().unify(expected);
type = IntType.getInstance();
try {
for (int i = 0; i < n.getArgs().length; i++) { for (int i = 0; i < n.getArgs().length; i++) {
visitExprOrOpArgNode(n.getArgs()[i], IntType.getInstance()); visitExprOrOpArgNode(n.getArgs()[i], type);
} }
return IntType.getInstance(); } catch (TypeErrorException e) {
} catch (UnificationException e2) { RealType.getInstance().unify(expected);
type = RealType.getInstance();
}
} else {
throw new TypeErrorException(String.format("Expected %s, found INTEGER at '%s',%n%s", expected, throw new TypeErrorException(String.format("Expected %s, found INTEGER at '%s',%n%s", expected,
n.getOperator().getName(), n.getLocation())); n.getOperator().getName(), n.getLocation()));
} }
for (int i = 0; i < n.getArgs().length; i++) {
visitExprOrOpArgNode(n.getArgs()[i], type);
} }
return type;
} }
case B_OPCODE_dotdot: // .. case B_OPCODE_dotdot: // ..
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment