Skip to content

Commit a210f95

Browse files
committed
Added util to show code snippet, moved debug print
Added a util to get the expression from a SourcePosition. Moved the print in the verifySubtype to verifySMTSubtype.
1 parent 6f0107d commit a210f95

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.stream.Collectors;
99

1010
import liquidjava.diagnostics.errors.*;
11+
import liquidjava.api.CommandLineLauncher;
1112
import liquidjava.diagnostics.TranslationTable;
1213
import liquidjava.processor.VCImplication;
1314
import liquidjava.processor.context.*;
@@ -16,6 +17,7 @@
1617
import liquidjava.smt.SMTEvaluator;
1718
import liquidjava.smt.SMTResult;
1819
import liquidjava.utils.constants.Keys;
20+
import liquidjava.utils.Utils;
1921
import spoon.reflect.cu.SourcePosition;
2022
import spoon.reflect.declaration.CtElement;
2123
import spoon.reflect.factory.Factory;
@@ -92,6 +94,11 @@ public void processSubtyping(Predicate type, Predicate expectedType, List<GhostS
9294
*/
9395
public SMTResult verifySMTSubtype(Predicate expected, Predicate found, SourcePosition position) throws LJError {
9496
try {
97+
if (CommandLineLauncher.cmdArgs.debugMode) {
98+
System.out.println(String.format("%s <: %s on expression '%s' at %s", expected, found,
99+
Utils.getExpressionFromPosition(position),
100+
position.getFile().getName() + ":" + position.getLine()));
101+
}
95102
return new SMTEvaluator().verifySubtype(found, expected, context);
96103
} catch (LJError e) {
97104
e.setPosition(position);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.microsoft.z3.Status;
88
import com.microsoft.z3.Z3Exception;
99

10-
import liquidjava.api.CommandLineLauncher;
1110
import liquidjava.processor.context.Context;
1211
import liquidjava.rj_language.Predicate;
1312
import liquidjava.rj_language.ast.Expression;
@@ -26,9 +25,6 @@ public class SMTEvaluator {
2625
*/
2726
public SMTResult verifySubtype(Predicate subRef, Predicate supRef, Context context) throws Exception {
2827
Predicate toVerify = Predicate.createConjunction(subRef, supRef.negate());
29-
if (CommandLineLauncher.cmdArgs.debugMode) {
30-
System.out.println(String.format("%s <: %s", subRef, supRef));
31-
}
3228
try {
3329
Expression exp = toVerify.getExpression();
3430
try (TranslatorToZ3 tz3 = new TranslatorToZ3(context)) {

liquidjava-verifier/src/main/java/liquidjava/utils/Utils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package liquidjava.utils;
22

33
import java.util.Map;
4+
import java.util.Scanner;
45
import java.util.Set;
56
import java.util.stream.Stream;
67

@@ -92,4 +93,22 @@ public static SourcePosition getRealPosition(CtElement element) {
9293
}
9394
return element.getPosition();
9495
}
96+
97+
public static String getExpressionFromPosition(SourcePosition position) {
98+
if (position == null || position.getFile() == null)
99+
return null;
100+
try (Scanner scanner = new Scanner(position.getFile())) {
101+
int currentLine = 1;
102+
while (scanner.hasNextLine()) {
103+
String line = scanner.nextLine();
104+
if (currentLine == position.getLine()) {
105+
return line.substring(position.getColumn() - 1).trim();
106+
}
107+
currentLine++;
108+
}
109+
} catch (Exception e) {
110+
// ignore
111+
}
112+
return null;
113+
}
95114
}

0 commit comments

Comments
 (0)