-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement binding rules for control statements (#1076)
This PR adds support in the binding rules for: - `if`/`else` statements - `for` loops - `while` and `do-while` loops - `emit` statements and basic event definitions - `try-catch` statements - `revert` and basic error definitions - `unchecked` blocks It also includes a reorganization of the rules file to improve readability and maintainability. Previously we were attempting to maintain compatibility with strict evaluation mode which meant that nodes and edges needed to be defined in previous rules. But since to build the stack graph the lazy evaluation mode is used anyway, this restriction can be dropped. The file is now organized more or less hierarchically, with all the rules affecting a node and its descendants grouped together.
- Loading branch information
Showing
47 changed files
with
2,084 additions
and
530 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
727 changes: 469 additions & 258 deletions
727
...s/solidity/outputs/cargo/slang_solidity/src/generated/bindings/generated/binding_rules.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
60 changes: 60 additions & 0 deletions
60
crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/control.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mod.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
55 changes: 55 additions & 0 deletions
55
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/control.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mod.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
17 changes: 17 additions & 0 deletions
17
crates/solidity/testing/snapshots/bindings_assertions/control/do_while.sol
This file contains 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,17 @@ | ||
contract Test { | ||
function test() public returns (int) { | ||
int i = 1; | ||
// ^def:1 | ||
do { | ||
int odd = i % 2; | ||
// ^def:2 | ||
// ^ref:1 | ||
i *= 3; | ||
//<ref:1 | ||
} while (i < 100); | ||
// ^ref:1 | ||
return odd; | ||
// ^ref:! (>= 0.5.0) | ||
// ^ref:2 (< 0.5.0) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
crates/solidity/testing/snapshots/bindings_assertions/control/emit_event.sol
This file contains 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,23 @@ | ||
contract Test { | ||
event TestEvent(int id); | ||
// ^def:1 | ||
|
||
function test_emit() public { | ||
int x = 1; | ||
// ^def:2 | ||
|
||
emit TestEvent(x); | ||
// ^ref:2 (>= 0.4.21) | ||
// ^ref:1 (>= 0.4.21) | ||
emit Utils.Debug(x); | ||
// ^ref:2 (>= 0.4.21) | ||
// ^ref:4 (>= 0.4.21) | ||
// ^ref:3 (>= 0.4.21) | ||
} | ||
} | ||
|
||
library Utils { | ||
// ^def:3 | ||
event Debug(int subject); | ||
// ^def:4 | ||
} |
24 changes: 24 additions & 0 deletions
24
crates/solidity/testing/snapshots/bindings_assertions/control/for_empty_init_or_cond.sol
This file contains 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,24 @@ | ||
contract Test { | ||
function empty_init() public { | ||
int i = 1; | ||
// ^def:1 | ||
int x = 0; | ||
// ^def:2 | ||
for (; i < 10; i++) { | ||
// ^ref:1 | ||
// ^ref:1 | ||
x += i; | ||
//<ref:2 | ||
// ^ref:1 | ||
} | ||
} | ||
|
||
function empty_condition() public { | ||
for (int i = 0;; i++) { | ||
// ^def:3 | ||
// ^ref:3 | ||
if (i > 10) break; | ||
// ^ref:3 | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
crates/solidity/testing/snapshots/bindings_assertions/control/for_stmt.sol
This file contains 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,32 @@ | ||
contract Test { | ||
function simple_loop() public returns (int) { | ||
int x = 1; | ||
// ^def:1 | ||
for (int i = 0; i < 10; i++) { | ||
// ^def:2 | ||
// ^ref:2 | ||
// ^ref:2 | ||
x = x * 2; | ||
//<ref:1 | ||
// ^ref:1 | ||
} | ||
return x + i; | ||
// ^ref:! (>= 0.5.0) | ||
// ^ref:2 (< 0.5.0) | ||
} | ||
|
||
function loop_with_outside_var() public { | ||
int z; | ||
// ^def:3 | ||
int w = 0; | ||
// ^def:4 | ||
for ( z = 10; z > 0; w += z) { | ||
//^ref:3 | ||
// ^ref:3 | ||
// ^ref:4 | ||
// ^ref:3 | ||
z--; | ||
//<ref:3 | ||
} | ||
} | ||
} |
Oops, something went wrong.