Skip to content

Commit

Permalink
Binding rules for while and do-while statements
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Aug 14, 2024
1 parent f7e41a6 commit 4be812f
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 6 deletions.
40 changes: 37 additions & 3 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
;;; Control statements
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; If conditionals

@stmt [Statement [IfStatement @body body: [Statement]]] {
edge @body.lexical_scope -> @stmt.lexical_scope
if (version-matches "< 0.5.0") {
Expand All @@ -635,9 +637,9 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
}
}

@stmt [Statement [ForStatement
@body body: [Statement]
]] {
;; For loops

@stmt [Statement [ForStatement @body body: [Statement]]] {
node @stmt.init_defs

edge @body.lexical_scope -> @stmt.lexical_scope
Expand Down Expand Up @@ -666,6 +668,24 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @cond_stmt.lexical_scope -> @stmt.init_defs
}

;; While loops

@stmt [Statement [WhileStatement @body body: [Statement]]] {
edge @body.lexical_scope -> @stmt.lexical_scope
if (version-matches "< 0.5.0") {
edge @stmt.defs -> @body.defs
}
}

;; Do-while loops

@stmt [Statement [DoWhileStatement @body body: [Statement]]] {
edge @body.lexical_scope -> @stmt.lexical_scope
if (version-matches "< 0.5.0") {
edge @stmt.defs -> @body.defs
}
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; State Variables
Expand Down Expand Up @@ -879,6 +899,20 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @iter_expr.lexical_scope -> @stmt.init_defs
}

;; Expressions in while conditions
@stmt [Statement [WhileStatement
@condition condition: [Expression]
]] {
edge @condition.lexical_scope -> @stmt.lexical_scope
}

;; Expressions in do-while conditions
@stmt [Statement [DoWhileStatement
@condition condition: [Expression]
]] {
edge @condition.lexical_scope -> @stmt.lexical_scope
}

;; Expressions used for state variable declarations
@state_var [StateVariableDefinition
value: [StateVariableDefinitionValue @expr [Expression]]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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)
}
}
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
while (i < 100) {
// ^ref:1
int odd = i % 2;
// ^def:2
// ^ref:1
i *= 3;
//<ref:1
}
return odd;
// ^ref:! (>= 0.5.0)
// ^ref:2 (< 0.5.0)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

References and definitions:
╭─[input.sol:1:1]
1 │ contract Test {
│ ──┬─
│ ╰─── def: 1
2 │ function test() public {
│ ──┬─
│ ╰─── def: 2
3 │ int i = 1;
│ ┬
│ ╰── def: 3
4 │ while (i < 100) {
│ ┬
│ ╰── ref: 3
5 │ i *= 3;
│ ┬
│ ╰── ref: 3
───╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract Test {
function test() public {
int i = 1;
while (i < 100) {
i *= 3;
}
}
}

0 comments on commit 4be812f

Please sign in to comment.