-
Notifications
You must be signed in to change notification settings - Fork 35
Add #result for Return Refinements
#145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
9d7e2dc
e111574
ab4d600
58a5475
a3bee27
515ddf5
b38a5fc
a0edc1f
4969ce5
98d9760
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| f.setRefReturn(ret); | ||
| return Predicate.createConjunction(joint, ret); | ||
| } | ||
|
|
@@ -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; | ||
| } | ||
|
||
|
|
||
| List<Variable> lv = fi.getArguments(); | ||
| for (Variable v : lv) { | ||
| rtc.getContext().addVarToContext(v); | ||
|
|
||
rajshivu marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -159,9 +160,18 @@ else if (rc instanceof VarContext) { | |
| } else if (rc instanceof TargetInvocationContext) { | ||
| // TODO Finish Invocation with Target (a.len()) | ||
| return null; | ||
| } else { | ||
| } | ||
| // else { | ||
|
||
| // return create(((InvocationContext) rc).functionCall()); | ||
| // } | ||
| 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 { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comment.