|
6 | 6 | import java.util.Set; |
7 | 7 |
|
8 | 8 | import liquidjava.rj_language.ast.BinaryExpression; |
| 9 | +import liquidjava.rj_language.ast.Enum; |
9 | 10 | import liquidjava.rj_language.ast.Expression; |
10 | 11 | import liquidjava.rj_language.ast.FunctionInvocation; |
11 | 12 | import liquidjava.rj_language.ast.Var; |
@@ -56,9 +57,9 @@ private static void resolveRecursive(Expression exp, Map<String, Expression> map |
56 | 57 | String leftKey = substitutionKey(left); |
57 | 58 | String rightKey = substitutionKey(right); |
58 | 59 |
|
59 | | - if (leftKey != null && right.isLiteral()) { |
| 60 | + if (leftKey != null && isConstant(right)) { |
60 | 61 | map.put(leftKey, right.clone()); |
61 | | - } else if (rightKey != null && left.isLiteral()) { |
| 62 | + } else if (rightKey != null && isConstant(left)) { |
62 | 63 | map.put(rightKey, left.clone()); |
63 | 64 | } else if (left instanceof Var leftVar && right instanceof Var rightVar) { |
64 | 65 | // to substitute internal variable with user-facing variable |
@@ -144,15 +145,15 @@ private static boolean hasUsage(Expression exp, String name, Expression value) { |
144 | 145 | Expression left = binary.getFirstOperand(); |
145 | 146 | Expression right = binary.getSecondOperand(); |
146 | 147 | if (left instanceof Var v && v.getName().equals(name) && right.equals(value) |
147 | | - && (right.isLiteral() || (!(right instanceof Var) && canSubstitute(v, right)))) |
| 148 | + && (isConstant(right) || (!(right instanceof Var) && canSubstitute(v, right)))) |
148 | 149 | return false; |
149 | 150 | if (left instanceof FunctionInvocation && left.toString().equals(name) && right.equals(value) |
150 | | - && (right.isLiteral() || (!(right instanceof Var) && !containsExpression(right, left)))) |
| 151 | + && (isConstant(right) || (!(right instanceof Var) && !containsExpression(right, left)))) |
151 | 152 | return false; |
152 | | - if (right instanceof Var v && v.getName().equals(name) && left.equals(value) && left.isLiteral()) |
| 153 | + if (right instanceof Var v && v.getName().equals(name) && left.equals(value) && isConstant(left)) |
153 | 154 | return false; |
154 | 155 | if (right instanceof FunctionInvocation && right.toString().equals(name) && left.equals(value) |
155 | | - && left.isLiteral()) |
| 156 | + && isConstant(left)) |
156 | 157 | return false; |
157 | 158 | } |
158 | 159 |
|
@@ -198,6 +199,10 @@ private static boolean canSubstitute(Var var, Expression value) { |
198 | 199 | return !isReturnVar(var) && !isFreshVar(var) && !containsVariable(value, var.getName()); |
199 | 200 | } |
200 | 201 |
|
| 202 | + private static boolean isConstant(Expression exp) { |
| 203 | + return exp.isLiteral() || exp instanceof Enum; |
| 204 | + } |
| 205 | + |
201 | 206 | private static boolean containsVariable(Expression exp, String name) { |
202 | 207 | if (exp instanceof Var var) |
203 | 208 | return var.getName().equals(name); |
|
0 commit comments