Skip to content

Commit 2c23a2e

Browse files
committed
Extracted enum logic to its own method
1 parent 2754337 commit 2c23a2e

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/smt/TranslatorContextToZ3.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,8 @@ public class TranslatorContextToZ3 {
2222

2323
static void translateVariables(Context z3, Map<String, CtTypeReference<?>> ctx,
2424
Map<String, Expr<?>> varTranslation) {
25-
// Create EnumSorts and register enum literal constants, and create variable for enum if not present
26-
Map<String, EnumSort<?>> enumSorts = new HashMap<>();
2725

28-
for (Map.Entry<String, CtTypeReference<?>> entry : ctx.entrySet()) {
29-
String name = entry.getKey();
30-
CtTypeReference<?> type = entry.getValue();
31-
if (type.isEnum() && type.getDeclaration()instanceof CtEnum<?> enumDecl) {
32-
EnumSort<?> enumSort = translateEnum(z3, varTranslation, enumSorts, type, enumDecl);
33-
// translateEnum may have already registered name as a literal constant
34-
// (e.g. Mode.Photo), no need to overwrite
35-
if (!varTranslation.containsKey(name)) {
36-
varTranslation.put(name, z3.mkConst(name, enumSort));
37-
}
38-
}
39-
}
26+
createEnumVariables(z3, ctx, varTranslation);
4027

4128
for (Map.Entry<String, CtTypeReference<?>> entry : ctx.entrySet()) {
4229
String name = entry.getKey();
@@ -79,6 +66,27 @@ public static void storeVariablesSubtypes(Context z3, List<RefinedVariable> vari
7966
}
8067
}
8168

69+
/**
70+
* Create EnumSorts and register enum literal constants, and create variable for enum if not present
71+
*/
72+
public static void createEnumVariables(Context z3, Map<String, CtTypeReference<?>> ctx,
73+
Map<String, Expr<?>> varTranslation) {
74+
Map<String, EnumSort<?>> enumSorts = new HashMap<>();
75+
76+
for (Map.Entry<String, CtTypeReference<?>> entry : ctx.entrySet()) {
77+
String name = entry.getKey();
78+
CtTypeReference<?> type = entry.getValue();
79+
if (type.isEnum() && type.getDeclaration()instanceof CtEnum<?> enumDecl) {
80+
EnumSort<?> enumSort = translateEnum(z3, varTranslation, enumSorts, type, enumDecl);
81+
// translateEnum may have already registered name as a literal constant
82+
// (e.g. Mode.Photo), no need to overwrite
83+
if (!varTranslation.containsKey(name)) {
84+
varTranslation.put(name, z3.mkConst(name, enumSort));
85+
}
86+
}
87+
}
88+
}
89+
8290
private static Expr<?> getExpr(Context z3, String name, CtTypeReference<?> type) {
8391
String typeName = type.getQualifiedName();
8492

0 commit comments

Comments
 (0)