-
Notifications
You must be signed in to change notification settings - Fork 35
Add support for Long operations inside predicates #139
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
liquidjava-example/src/main/java/testSuite/ErrorLongUsagePredicates1.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Refinement Error | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| public class ErrorLongUsagePredicates1 { | ||
| void testUUID(){ | ||
| @Refinement("((v/4096) % 16) == 2") | ||
| long v = 0x01000000122341666L; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
liquidjava-example/src/main/java/testSuite/ErrorLongUsagePredicates2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Refinement Error | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| public class ErrorLongUsagePredicates2 { | ||
| void testLargeSubtractionWrong() { | ||
| @Refinement("v - 9007199254740992 == 2") | ||
| long v = 9007199254740993L; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
liquidjava-example/src/main/java/testSuite/ErrorLongUsagePredicates3.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Refinement Error | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| public class ErrorLongUsagePredicates3 { | ||
| void testWrongSign() { | ||
| @Refinement("v < 0") | ||
| long v = 42L; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
liquidjava-verifier/src/main/java/liquidjava/rj_language/ast/LiteralLong.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package liquidjava.rj_language.ast; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import liquidjava.diagnostics.errors.LJError; | ||
| import liquidjava.rj_language.visitors.ExpressionVisitor; | ||
|
|
||
| public class LiteralLong extends Expression { | ||
|
|
||
| private final long value; | ||
|
|
||
| public LiteralLong(long v) { | ||
| value = v; | ||
| } | ||
|
|
||
| public LiteralLong(String v) { | ||
| value = Long.parseLong(v); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T accept(ExpressionVisitor<T> visitor) throws LJError { | ||
| return visitor.visitLiteralLong(this); | ||
| } | ||
|
|
||
| public String toString() { | ||
| return Long.toString(value); | ||
| } | ||
|
|
||
| public long getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public void getVariableNames(List<String> toAdd) { | ||
| // end leaf | ||
| } | ||
|
|
||
| @Override | ||
| public void getStateInvocations(List<String> toAdd, List<String> all) { | ||
| // end leaf | ||
| } | ||
|
|
||
| @Override | ||
| public Expression clone() { | ||
| return new LiteralLong(value); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isBooleanTrue() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| final int prime = 31; | ||
| int result = 1; | ||
| result = prime * result + Long.hashCode(value); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) | ||
| return true; | ||
| if (obj == null) | ||
| return false; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| LiteralLong other = (LiteralLong) obj; | ||
| return value == other.value; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So we only convert a long to a
LiteralLongif it overflows 32 bits, even if it was declared as a long, right?Also, instead of using a try-catch here, we could do this:
Both are fine for me. Which one do you prefer?
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.
to have
literalContext.LONG()i needed to change the grammar in.g4and i didn't want to 😅 We could not catch the exception its true, it probably is more readable so I'll change it! Athough we usually have more examples with ints but its fine