Skip to content

Commit f8e3241

Browse files
committed
Error Improvements
1 parent 55da74e commit f8e3241

7 files changed

Lines changed: 27 additions & 23 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/diagnostics/errors/CustomError.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public CustomError(String message, SourcePosition pos) {
1818
super("Error", message, null, pos, null);
1919
}
2020

21+
public CustomError(String message, String detail, CtElement element) {
22+
super("Error", message, detail, element.getPosition(), null);
23+
}
24+
2125
public CustomError(String message, CtElement element) {
2226
super("Error", message, null, element.getPosition(), null);
2327
}

liquidjava-verifier/src/main/java/liquidjava/diagnostics/errors/StateRefinementError.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.Arrays;
44

55
import liquidjava.diagnostics.TranslationTable;
6-
import liquidjava.rj_language.Predicate;
76
import liquidjava.rj_language.ast.Expression;
87
import spoon.reflect.declaration.CtElement;
98

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public <T> void visitCtInterface(CtInterface<T> intrface) {
4848
if (externalRefinements.isPresent()) {
4949
this.prefix = externalRefinements.get();
5050
if (!classExists(prefix)) {
51-
String message = String.format("Could not find external class '%s'", prefix);
51+
String message = String.format("Could not find class '%s'", prefix);
5252
diagnostics.add(new ExternalClassNotFoundWarning(intrface, message, prefix));
5353
return;
5454
}
@@ -130,7 +130,7 @@ protected void getGhostFunction(String value, CtElement element) {
130130
}
131131

132132
} catch (ParsingException e) {
133-
diagnostics.add(new CustomError("Could not parse the ghost function" + e.getMessage(), element));
133+
diagnostics.add(new CustomError("Could not parse the ghost function", e.getMessage(), element));
134134
}
135135
}
136136

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ private void createStateSet(CtNewArray<String> e, int set, CtElement element) {
121121
CtLiteral<String> s = (CtLiteral<String>) ce;
122122
String f = s.getValue();
123123
if (Character.isUpperCase(f.charAt(0))) {
124-
diagnostics
125-
.add(new CustomError(String.format("State name must start with lowercase in '%s'", f), s));
124+
diagnostics.add(new CustomError("State names must start with lowercase", s));
126125
}
127126
}
128127
}
@@ -163,12 +162,12 @@ private void createStateGhost(String string, CtAnnotation<? extends Annotation>
163162
try {
164163
gd = RefinementsParser.getGhostDeclaration(string);
165164
} catch (ParsingException e) {
166-
diagnostics.add(new CustomError("Could not parse the ghost function " + e.getMessage(), ann));
165+
diagnostics.add(new CustomError("Could not parse the ghost function", e.getMessage(), ann));
167166
return;
168167
}
169168
if (gd.getParam_types().size() > 0) {
170-
diagnostics.add(new CustomError("Ghost States have the class as parameter "
171-
+ "by default, no other parameters are allowed in '" + string + "'", ann));
169+
diagnostics.add(new CustomError(
170+
"Ghost States have the class as parameter " + "by default, no other parameters are allowed", ann));
172171
return;
173172
}
174173
// Set class as parameter of Ghost
@@ -226,7 +225,7 @@ protected void getGhostFunction(String value, CtElement element) {
226225
context.addGhostFunction(gh);
227226
}
228227
} catch (ParsingException e) {
229-
diagnostics.add(new CustomError("Could not parse the ghost function " + e.getMessage(), element));
228+
diagnostics.add(new CustomError("Could not parse the ghost function", e.getMessage(), element));
230229
// e.printStackTrace();
231230
return;
232231
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,24 @@ private void recAuxGetVars(RefinedVariable var, List<RefinedVariable> newVars) {
236236
getVariablesFromContext(l, newVars, varName);
237237
}
238238

239-
public boolean smtChecks(Predicate cSMT, Predicate expectedType, SourcePosition p) {
239+
public boolean smtChecks(Predicate found, Predicate expectedType, SourcePosition p) {
240240
try {
241-
new SMTEvaluator().verifySubtype(cSMT, expectedType, context, p);
241+
new SMTEvaluator().verifySubtype(found, expectedType, context, p);
242242
} catch (TypeCheckError e) {
243243
return false;
244244
} catch (Exception e) {
245-
diagnostics.add(new CustomError(e.getMessage(), p));
245+
String msg = e.getLocalizedMessage().toLowerCase();
246+
LJError error;
247+
if (msg.contains("wrong number of arguments")) {
248+
error = new GhostInvocationError("Wrong number of arguments in ghost invocation", p,
249+
expectedType.getExpression(), null);
250+
} else if (msg.contains("sort mismatch")) {
251+
error = new GhostInvocationError("Type mismatch in arguments of ghost invocation", p,
252+
expectedType.getExpression(), null);
253+
} else {
254+
error = new CustomError(e.getMessage(), p);
255+
}
256+
diagnostics.add(error);
246257
}
247258
return true;
248259
}

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/object_checkers/AuxStateHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,8 @@ public static void updateGhostField(CtFieldWrite<?> fw, TypeChecker tc) {
390390
stateChange.setFrom(fromPredicate);
391391
stateChange.setTo(toPredicate);
392392
} catch (ParsingException e) {
393-
String message = String.format(
394-
"Parsing error while constructing assignment update for `%s` in class `%s` : %s", fw,
395-
field.getDeclaringType().getQualifiedName(), e.getMessage());
396-
diagnostics.add(new CustomError(message, field));
393+
String message = String.format("Parsing error while constructing assignment update for `%s`", fw);
394+
diagnostics.add(new CustomError(message, e.getMessage(), field));
397395
return;
398396
}
399397

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

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

3-
import static liquidjava.diagnostics.LJDiagnostics.diagnostics;
4-
53
import com.martiansoftware.jsap.SyntaxException;
64
import com.microsoft.z3.Expr;
75
import com.microsoft.z3.Status;
86
import com.microsoft.z3.Z3Exception;
97

10-
import liquidjava.diagnostics.errors.GhostInvocationError;
118
import liquidjava.processor.context.Context;
129
import liquidjava.rj_language.Predicate;
1310
import liquidjava.rj_language.ast.Expression;
@@ -42,10 +39,6 @@ public void verifySubtype(Predicate subRef, Predicate supRef, Context c, SourceP
4239
System.out.println("Could not parse: " + toVerify);
4340
e1.printStackTrace();
4441
} catch (Z3Exception e) {
45-
String msg = e.getLocalizedMessage().toLowerCase();
46-
if (msg.contains("wrong number of arguments") || msg.contains("sort mismatch"))
47-
diagnostics.add(new GhostInvocationError(msg, pos, supRef.getExpression(), null));
48-
4942
throw new Z3Exception(e.getLocalizedMessage());
5043
}
5144
}

0 commit comments

Comments
 (0)