|
1 | 1 | package liquidjava.smt; |
2 | 2 |
|
3 | 3 | import com.microsoft.z3.Context; |
| 4 | +import com.microsoft.z3.EnumSort; |
4 | 5 | import com.microsoft.z3.Expr; |
5 | 6 | import com.microsoft.z3.FPExpr; |
6 | 7 | import com.microsoft.z3.FuncDecl; |
|
13 | 14 | import liquidjava.processor.context.GhostFunction; |
14 | 15 | import liquidjava.processor.context.GhostState; |
15 | 16 | import liquidjava.processor.context.RefinedVariable; |
| 17 | +import spoon.reflect.declaration.CtEnum; |
| 18 | +import spoon.reflect.declaration.CtType; |
16 | 19 | import spoon.reflect.reference.CtTypeReference; |
17 | 20 |
|
18 | 21 | public class TranslatorContextToZ3 { |
@@ -41,19 +44,24 @@ public static void storeVariablesSubtypes(Context z3, List<RefinedVariable> vari |
41 | 44 |
|
42 | 45 | private static Expr<?> getExpr(Context z3, String name, CtTypeReference<?> type) { |
43 | 46 | String typeName = type.getQualifiedName(); |
| 47 | + |
| 48 | + if (type.isEnum()) { |
| 49 | + CtType<?> decl = type.getDeclaration(); |
| 50 | + if (decl instanceof CtEnum<?> enumDecl) { |
| 51 | + String[] enumValueNames = enumDecl.getEnumValues().stream().map(ev -> ev.getSimpleName()).toArray(String[]::new); |
| 52 | + EnumSort<Object> enumSort = z3.mkEnumSort(typeName, enumValueNames); |
| 53 | + return z3.mkConst(name, enumSort); |
| 54 | + } |
| 55 | + } |
| 56 | + |
44 | 57 | return switch (typeName) { |
45 | 58 | case "int", "short", "char", "java.lang.Integer", "java.lang.Short", "java.lang.Character" -> z3 |
46 | 59 | .mkIntConst(name); |
47 | 60 | case "boolean", "java.lang.Boolean" -> z3.mkBoolConst(name); |
48 | 61 | case "long", "java.lang.Long" -> z3.mkRealConst(name); |
49 | 62 | case "float", "double", "java.lang.Float", "java.lang.Double" -> (FPExpr) z3.mkConst(name, z3.mkFPSort64()); |
50 | 63 | case "int[]" -> z3.mkArrayConst(name, z3.mkIntSort(), z3.mkIntSort()); |
51 | | - case "java.lang.Enum" -> z3.mkIntConst(name); |
52 | | - default -> { |
53 | | - if (type.isEnum()) |
54 | | - yield z3.mkIntConst(name); |
55 | | - yield z3.mkConst(name, z3.mkUninterpretedSort(typeName)); |
56 | | - } |
| 64 | + default -> z3.mkConst(name, z3.mkUninterpretedSort(typeName)); |
57 | 65 | }; |
58 | 66 | } |
59 | 67 |
|
|
0 commit comments