Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions liquidjava-example/src/main/java/testSuite/CorrectResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testSuite;

import liquidjava.specification.Refinement;

public class CorrectResult {

@Refinement("$result > 10")
public int getLargeNumber() {
return 15;
}

@Refinement("$result == (a + b)")
public int sum(int a, int b) {
return a + b;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Not Found Error
package testSuite;
import liquidjava.specification.Refinement;

public class ErrorResultVariable {
public void test() {
@Refinement("$result > 0")
int x = 10;
}
}
4 changes: 3 additions & 1 deletion liquidjava-verifier/src/main/antlr4/rj/grammar/RJ.g4
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ operand:
literalExpression:
'(' literalExpression ')' #litGroup
| literal #lit
| RESULT #result
| ID #var
| ID '.' functionCall #targetInvocation
| functionCall #invocation
Expand Down Expand Up @@ -91,7 +92,8 @@ ARITHOP : '+'|'*'|'/'|'%';//|'-';
BOOL : 'true' | 'false';
ID_UPPER: ([A-Z][a-zA-Z0-9]*);
OBJECT_TYPE:
(([a-zA-Z][a-zA-Z0-9]+) ('.' [a-zA-Z][a-zA-Z0-9]*)+);
(([a-zA-Z][a-zA-Z0-9]+) ('.' [a-zA-Z][a-zA-Z0-9]*)+);
RESULT : '$result';
ID : '#'*[a-zA-Z_][a-zA-Z0-9_#]*;
STRING : '"'(~["])*'"';
INT : (([0-9]+) | ([0-9]+('_'[0-9]+)*));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private Predicate handleFunctionRefinements(RefinedFunction f, CtElement method,
Optional<Predicate> oret = rtc.getRefinementFromAnnotation(method);
Predicate ret = oret.orElse(new Predicate());
ret = ret.substituteVariable("return", Keys.WILDCARD);
ret = ret.substituteVariable("$result", Keys.WILDCARD);// added for refinement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment.

f.setRefReturn(ret);
return Predicate.createConjunction(joint, ret);
}
Expand All @@ -180,6 +181,13 @@ public <R> void getReturnRefinements(CtReturn<R> ret) throws LJError {
RefinedFunction fi = rtc.getContext().getFunction(method.getSimpleName(),
((CtClass<?>) method.getParent()).getQualifiedName(), method.getParameters().size());

if (fi == null)
return;// null check refinement

if (fi.getRefReturn() == null) {
return;
}
Comment on lines +184 to +189
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also faced a NullPointerException because of fi being null, which I fixed in #150 and added the same check there. However, fi.getRefReturn() never returns null. With that being said, you can remove both of these checks.


List<Variable> lv = fi.getArguments();
for (Variable v : lv) {
rtc.getContext().addVarToContext(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import rj.grammar.RJParser.PredLogicContext;
import rj.grammar.RJParser.PredNegateContext;
import rj.grammar.RJParser.ProgContext;
import rj.grammar.RJParser.ResultContext;
import rj.grammar.RJParser.StartContext;
import rj.grammar.RJParser.StartPredContext;
import rj.grammar.RJParser.TargetInvocationContext;
Expand Down Expand Up @@ -159,9 +160,14 @@ else if (rc instanceof VarContext) {
} else if (rc instanceof TargetInvocationContext) {
// TODO Finish Invocation with Target (a.len())
return null;
} else {
} else if (rc instanceof ResultContext) {
return new Var("$result");
} else if (rc instanceof InvocationContext) {
return create(((InvocationContext) rc).functionCall());
} else {
throw new IllegalStateException("Unknown literalExpression: " + rc.getClass());
}

}

private Expression functionCallCreate(FunctionCallContext rc) throws LJError {
Expand Down