1818import java .util .ArrayList ;
1919import java .util .Arrays ;
2020import java .util .HashMap ;
21+ import java .util .HashSet ;
2122import java .util .List ;
2223import java .util .Map ;
24+ import java .util .Set ;
2325import java .util .stream .Collectors ;
2426
2527import liquidjava .diagnostics .errors .LJError ;
@@ -40,13 +42,15 @@ public class TranslatorToZ3 implements AutoCloseable {
4042 private final Map <String , FuncDecl <?>> funcTranslation = new HashMap <>();
4143 private final Map <String , Expr <?>> funcAppTranslation = new HashMap <>();
4244 private final Map <Expr <?>, String > exprToNameTranslation = new HashMap <>();
45+ private final Set <String > instanceVariableRefinements ;
4346
44- public TranslatorToZ3 (liquidjava .processor .context .Context c ) {
45- TranslatorContextToZ3 .translateVariables (z3 , c .getContext (), varTranslation );
46- TranslatorContextToZ3 .storeVariablesSubtypes (z3 , c .getAllVariablesWithSupertypes (), varSuperTypes );
47- TranslatorContextToZ3 .addAliases (c .getAliases (), aliasTranslation );
48- TranslatorContextToZ3 .addGhostFunctions (z3 , c .getGhosts (), funcTranslation );
49- TranslatorContextToZ3 .addGhostStates (z3 , c .getGhostStates (), funcTranslation );
47+ public TranslatorToZ3 (liquidjava .processor .context .Context context ) {
48+ TranslatorContextToZ3 .translateVariables (z3 , context .getContext (), varTranslation );
49+ TranslatorContextToZ3 .storeVariablesSubtypes (z3 , context .getAllVariablesWithSupertypes (), varSuperTypes );
50+ TranslatorContextToZ3 .addAliases (context .getAliases (), aliasTranslation );
51+ TranslatorContextToZ3 .addGhostFunctions (z3 , context .getGhosts (), funcTranslation );
52+ TranslatorContextToZ3 .addGhostStates (z3 , context .getGhostStates (), funcTranslation );
53+ instanceVariableRefinements = context .getCtxInstanceVars ().stream ().map (v -> v .getRefinement ().toString ()).collect (Collectors .toSet ());
5054 }
5155
5256 @ SuppressWarnings ("unchecked" )
@@ -66,18 +70,21 @@ public Counterexample getCounterexample(Model model) {
6670 if (decl .getArity () == 0 ) {
6771 Symbol name = decl .getName ();
6872 Expr <?> value = model .getConstInterp (decl );
73+ String assignment = name + " == " + value ;
6974 // Skip values of uninterpreted sorts
70- if (value .getSort ().getSortKind () != Z3_sort_kind .Z3_UNINTERPRETED_SORT )
71- assignments .add (name + " == " + value );
75+ if (value .getSort ().getSortKind () != Z3_sort_kind .Z3_UNINTERPRETED_SORT && ! instanceVariableRefinements . contains ( assignment ) )
76+ assignments .add (assignment );
7277 }
7378 }
7479 // Extract function application values
7580 for (Map .Entry <String , Expr <?>> entry : funcAppTranslation .entrySet ()) {
76- String label = entry .getKey ();
81+ String name = entry .getKey ();
7782 Expr <?> application = entry .getValue ();
7883 Expr <?> value = model .eval (application , true );
79- assignments .add (label + " = " + value );
80- }
84+ String assignment = name + " == " + value ;
85+ if (!instanceVariableRefinements .contains (assignment ))
86+ assignments .add (assignment );
87+ }
8188 return new Counterexample (assignments );
8289 }
8390
0 commit comments