Skip to content

Commit ae2d762

Browse files
committed
Improve Method Names & Javadocs
1 parent 18ccf11 commit ae2d762

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/TypeChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import liquidjava.processor.facade.GhostDTO;
1717
import liquidjava.rj_language.Predicate;
1818
import liquidjava.rj_language.parsing.RefinementsParser;
19-
import liquidjava.smt.Counterexample;
2019
import liquidjava.smt.SMTResult;
2120
import liquidjava.utils.Utils;
2221
import liquidjava.utils.constants.Formats;
@@ -315,7 +314,8 @@ public void checkStateSMT(Predicate prevState, Predicate expectedState, CtElemen
315314
}
316315

317316
public boolean checkStateSMT(Predicate prevState, Predicate expectedState, SourcePosition p) throws LJError {
318-
SMTResult result = vcChecker.canProcessSubtyping(prevState, expectedState, context.getGhostState(), p, factory);
317+
SMTResult result = vcChecker.verifySMTSubtypeStates(prevState, expectedState, context.getGhostState(), p,
318+
factory);
319319
return result.isOk();
320320
}
321321

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/VCChecker.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,41 @@ public void processSubtyping(Predicate expectedType, List<GhostState> list, CtEl
5656
e.setPosition(element.getPosition());
5757
throw e;
5858
}
59-
SMTResult result = smtChecks(expected, premises, element.getPosition());
59+
SMTResult result = verifySMTSubtype(expected, premises, element.getPosition());
6060
if (result.isError()) {
6161
throw new RefinementError(element.getPosition(), expectedType.simplify(), premisesBeforeChange.simplify(),
6262
map, result.getCounterexample(), customMessage);
6363
}
6464
}
6565

6666
/**
67-
* Check that type is a subtype of expectedType Throws RefinementError otherwise
68-
*
67+
* Checks if type is a subtype of expectedType
68+
*
6969
* @param type
7070
* @param expectedType
7171
* @param list
7272
* @param element
7373
* @param f
74-
*
74+
*
7575
* @throws LJError
7676
*/
7777
public void processSubtyping(Predicate type, Predicate expectedType, List<GhostState> list, CtElement element,
7878
Factory f) throws LJError {
79-
SMTResult result = canProcessSubtyping(type, expectedType, list, element.getPosition(), f);
79+
SMTResult result = verifySMTSubtypeStates(type, expectedType, list, element.getPosition(), f);
8080
if (result.isError())
8181
throwRefinementError(element.getPosition(), expectedType, type, result.getCounterexample(), null);
8282
}
8383

8484
/**
85-
* Checks the expected against the found constraint
86-
*
85+
* Verifies whether the found predicate is a subtype of the expected predicate
86+
*
8787
* @param expected
8888
* @param found
8989
* @param position
90-
*
91-
* @return counterexample if expected type is not subtype of found type, otherwise null
92-
*
93-
* @throws LJError
90+
*
91+
* @return the result of the verification, containing a counterexample if the verification fails
9492
*/
95-
public SMTResult smtChecks(Predicate expected, Predicate found, SourcePosition position) throws LJError {
93+
public SMTResult verifySMTSubtype(Predicate expected, Predicate found, SourcePosition position) throws LJError {
9694
try {
9795
return new SMTEvaluator().verifySubtype(found, expected, context);
9896
} catch (LJError e) {
@@ -103,8 +101,19 @@ public SMTResult smtChecks(Predicate expected, Predicate found, SourcePosition p
103101
}
104102
}
105103

106-
public SMTResult canProcessSubtyping(Predicate type, Predicate expectedType, List<GhostState> list,
107-
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 {
108117
List<RefinedVariable> lrv = new ArrayList<>(), mainVars = new ArrayList<>();
109118
gatherVariables(expectedType, lrv, mainVars);
110119
gatherVariables(type, lrv, mainVars);
@@ -114,13 +123,14 @@ public SMTResult canProcessSubtyping(Predicate type, Predicate expectedType, Lis
114123
TranslationTable map = new TranslationTable();
115124
String[] s = { Keys.WILDCARD, Keys.THIS };
116125
Predicate premises = joinPredicates(expectedType, mainVars, lrv, map).toConjunctions();
117-
List<GhostState> filtered = filterGhostStatesForVariables(list, mainVars, lrv);
126+
List<GhostState> filtered = filterGhostStatesForVariables(states, mainVars, lrv);
118127
premises = Predicate.createConjunction(premises, type).changeStatesToRefinements(filtered, s)
119-
.changeAliasToRefinement(context, f);
120-
Predicate expected = expectedType.changeStatesToRefinements(filtered, s).changeAliasToRefinement(context, f);
128+
.changeAliasToRefinement(context, factory);
129+
Predicate expected = expectedType.changeStatesToRefinements(filtered, s).changeAliasToRefinement(context,
130+
factory);
121131

122132
// check subtyping
123-
return smtChecks(expected, premises, position);
133+
return verifySMTSubtype(expected, premises, position);
124134
}
125135

126136
/**

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,36 @@
1313

1414
public class SMTEvaluator {
1515

16-
public SMTResult verifySubtype(Predicate subRef, Predicate supRef, Context c) throws Exception {
17-
// Creates a parser for our SMT-ready refinement language
18-
// Discharges the verification to z3
16+
/**
17+
* Verifies that subRef is a subtype of supRef by checking the satisfiability of subRef && !supRef. Creates a parser
18+
* for our SMT-ready refinement language and discharges the verification to Z3
19+
*
20+
* @param subRef
21+
* @param supRef
22+
* @param context
23+
*
24+
* @return the result of the verification, containing a counterexample if the verification fails
25+
*/
26+
public SMTResult verifySubtype(Predicate subRef, Predicate supRef, Context context) throws Exception {
1927
Predicate toVerify = Predicate.createConjunction(subRef, supRef.negate());
2028
try {
2129
Expression exp = toVerify.getExpression();
22-
try (TranslatorToZ3 tz3 = new TranslatorToZ3(c)) {
30+
try (TranslatorToZ3 tz3 = new TranslatorToZ3(context)) {
2331
ExpressionToZ3Visitor visitor = new ExpressionToZ3Visitor(tz3);
2432
Expr<?> e = exp.accept(visitor);
2533
Solver solver = tz3.makeSolverForExpression(e);
2634
Status result = solver.check();
35+
36+
// subRef is not a subtype of supRef
2737
if (result.equals(Status.SATISFIABLE)) {
2838
Model model = solver.getModel();
2939
Counterexample counterexample = tz3.getCounterexample(model);
3040
return SMTResult.error(counterexample);
3141
}
3242
}
33-
} catch (SyntaxException e1) {
43+
} catch (SyntaxException e) {
3444
System.out.println("Could not parse: " + toVerify);
35-
e1.printStackTrace();
45+
e.printStackTrace();
3646
} catch (Z3Exception e) {
3747
throw new Z3Exception(e.getLocalizedMessage());
3848
}

0 commit comments

Comments
 (0)