1212import liquidjava .processor .VCImplication ;
1313import liquidjava .processor .context .*;
1414import liquidjava .rj_language .Predicate ;
15+ import liquidjava .smt .Counterexample ;
1516import liquidjava .smt .SMTEvaluator ;
16- import liquidjava .smt .TypeCheckError ;
17+ import liquidjava .smt .SMTResult ;
1718import liquidjava .utils .constants .Keys ;
1819import spoon .reflect .cu .SourcePosition ;
1920import spoon .reflect .declaration .CtElement ;
@@ -55,47 +56,43 @@ public void processSubtyping(Predicate expectedType, List<GhostState> list, CtEl
5556 e .setPosition (element .getPosition ());
5657 throw e ;
5758 }
58- boolean isSubtype = smtChecks (expected , premises , element .getPosition ());
59- if (! isSubtype )
59+ SMTResult result = verifySMTSubtype (expected , premises , element .getPosition ());
60+ if (result . isError ()) {
6061 throw new RefinementError (element .getPosition (), expectedType .simplify (), premisesBeforeChange .simplify (),
61- map , customMessage );
62+ map , result .getCounterexample (), customMessage );
63+ }
6264 }
6365
6466 /**
65- * Check that type is a subtype of expectedType Throws RefinementError otherwise
66- *
67+ * Checks if type is a subtype of expectedType
68+ *
6769 * @param type
6870 * @param expectedType
6971 * @param list
7072 * @param element
7173 * @param f
72- *
74+ *
7375 * @throws LJError
7476 */
7577 public void processSubtyping (Predicate type , Predicate expectedType , List <GhostState > list , CtElement element ,
7678 Factory f ) throws LJError {
77- boolean b = canProcessSubtyping (type , expectedType , list , element .getPosition (), f );
78- if (! b )
79- throwRefinementError (element .getPosition (), expectedType , type , null );
79+ SMTResult result = verifySMTSubtypeStates (type , expectedType , list , element .getPosition (), f );
80+ if (result . isError () )
81+ throwRefinementError (element .getPosition (), expectedType , type , result . getCounterexample (), null );
8082 }
8183
8284 /**
83- * Checks the expected against the found constraint
84- *
85+ * Verifies whether the found predicate is a subtype of the expected predicate
86+ *
8587 * @param expected
8688 * @param found
8789 * @param position
88- *
89- * @return true if expected type is subtype of found type, false otherwise
90- *
91- * @throws LJError
90+ *
91+ * @return the result of the verification, containing a counterexample if the verification fails
9292 */
93- public boolean smtChecks (Predicate expected , Predicate found , SourcePosition position ) throws LJError {
93+ public SMTResult verifySMTSubtype (Predicate expected , Predicate found , SourcePosition position ) throws LJError {
9494 try {
95- new SMTEvaluator ().verifySubtype (found , expected , context );
96- return true ;
97- } catch (TypeCheckError e ) {
98- return false ;
95+ return new SMTEvaluator ().verifySubtype (found , expected , context );
9996 } catch (LJError e ) {
10097 e .setPosition (position );
10198 throw e ;
@@ -104,24 +101,36 @@ public boolean smtChecks(Predicate expected, Predicate found, SourcePosition pos
104101 }
105102 }
106103
107- public boolean canProcessSubtyping (Predicate type , Predicate expectedType , List <GhostState > list ,
108- SourcePosition position , Factory f ) throws LJError {
104+ /**
105+ * Verifies whether the found predicate is a subtype of the expected predicate, taking into account the ghost states
106+ *
107+ * @param type
108+ * @param expectedType
109+ * @param states
110+ * @param position
111+ * @param factory
112+ *
113+ * @return the result of the verification, containing a counterexample if the verification fails
114+ */
115+ public SMTResult verifySMTSubtypeStates (Predicate type , Predicate expectedType , List <GhostState > states ,
116+ SourcePosition position , Factory factory ) throws LJError {
109117 List <RefinedVariable > lrv = new ArrayList <>(), mainVars = new ArrayList <>();
110118 gatherVariables (expectedType , lrv , mainVars );
111119 gatherVariables (type , lrv , mainVars );
112120 if (expectedType .isBooleanTrue () && type .isBooleanTrue ())
113- return true ;
121+ return SMTResult . ok () ;
114122
115123 TranslationTable map = new TranslationTable ();
116124 String [] s = { Keys .WILDCARD , Keys .THIS };
117125 Predicate premises = joinPredicates (expectedType , mainVars , lrv , map ).toConjunctions ();
118- List <GhostState > filtered = filterGhostStatesForVariables (list , mainVars , lrv );
126+ List <GhostState > filtered = filterGhostStatesForVariables (states , mainVars , lrv );
119127 premises = Predicate .createConjunction (premises , type ).changeStatesToRefinements (filtered , s )
120- .changeAliasToRefinement (context , f );
121- Predicate expected = expectedType .changeStatesToRefinements (filtered , s ).changeAliasToRefinement (context , f );
128+ .changeAliasToRefinement (context , factory );
129+ Predicate expected = expectedType .changeStatesToRefinements (filtered , s ).changeAliasToRefinement (context ,
130+ factory );
122131
123132 // check subtyping
124- return smtChecks (expected , premises , position );
133+ return verifySMTSubtype (expected , premises , position );
125134 }
126135
127136 /**
@@ -262,13 +271,14 @@ void removePathVariableThatIncludes(String otherVar) {
262271 // Errors---------------------------------------------------------------------------------------------------
263272
264273 protected void throwRefinementError (SourcePosition position , Predicate expected , Predicate found ,
265- String customMessage ) throws RefinementError {
274+ Counterexample counterexample , String customMessage ) throws RefinementError {
266275 List <RefinedVariable > lrv = new ArrayList <>(), mainVars = new ArrayList <>();
267276 gatherVariables (expected , lrv , mainVars );
268277 gatherVariables (found , lrv , mainVars );
269278 TranslationTable map = new TranslationTable ();
270279 Predicate premises = joinPredicates (expected , mainVars , lrv , map ).toConjunctions ();
271- throw new RefinementError (position , expected .simplify (), premises .simplify (), map , customMessage );
280+ throw new RefinementError (position , expected .simplify (), premises .simplify (), map , counterexample ,
281+ customMessage );
272282 }
273283
274284 protected void throwStateRefinementError (SourcePosition position , Predicate found , Predicate expected ,
0 commit comments