|
1 | 1 | package liquidjava.rj_language.ast; |
2 | 2 |
|
3 | | -import com.microsoft.z3.Expr; |
4 | 3 | import java.util.List; |
5 | | -import liquidjava.smt.TranslatorToZ3; |
| 4 | + |
| 5 | +import liquidjava.rj_language.visitors.ExpressionVisitor; |
6 | 6 |
|
7 | 7 | public class BinaryExpression extends Expression { |
8 | 8 |
|
@@ -40,45 +40,8 @@ public boolean isArithmeticOperation() { |
40 | 40 | } |
41 | 41 |
|
42 | 42 | @Override |
43 | | - public Expr<?> eval(TranslatorToZ3 ctx) throws Exception { |
44 | | - Expr<?> ee1 = getFirstOperand().eval(ctx); |
45 | | - Expr<?> ee2 = getSecondOperand().eval(ctx); |
46 | | - return evalBinaryOp(ctx, ee1, ee2); |
47 | | - } |
48 | | - |
49 | | - private Expr<?> evalBinaryOp(TranslatorToZ3 ctx, Expr<?> e1, Expr<?> e2) { |
50 | | - switch (op) { |
51 | | - case "&&": |
52 | | - return ctx.makeAnd(e1, e2); |
53 | | - case "||": |
54 | | - return ctx.makeOr(e1, e2); |
55 | | - case "-->": |
56 | | - return ctx.makeImplies(e1, e2); |
57 | | - case "==": |
58 | | - return ctx.makeEquals(e1, e2); |
59 | | - case "!=": |
60 | | - return ctx.mkNot(ctx.makeEquals(e1, e2)); |
61 | | - case ">=": |
62 | | - return ctx.makeGtEq(e1, e2); |
63 | | - case ">": |
64 | | - return ctx.makeGt(e1, e2); |
65 | | - case "<=": |
66 | | - return ctx.makeLtEq(e1, e2); |
67 | | - case "<": |
68 | | - return ctx.makeLt(e1, e2); |
69 | | - case "+": |
70 | | - return ctx.makeAdd(e1, e2); |
71 | | - case "-": |
72 | | - return ctx.makeSub(e1, e2); |
73 | | - case "*": |
74 | | - return ctx.makeMul(e1, e2); |
75 | | - case "/": |
76 | | - return ctx.makeDiv(e1, e2); |
77 | | - case "%": |
78 | | - return ctx.makeMod(e1, e2); |
79 | | - default: // last case % |
80 | | - throw new RuntimeException("Operation " + op + "not supported by z3"); |
81 | | - } |
| 43 | + public <T> T accept(ExpressionVisitor<T> visitor) throws Exception { |
| 44 | + return visitor.visitBinaryExpression(this); |
82 | 45 | } |
83 | 46 |
|
84 | 47 | @Override |
|
0 commit comments