Skip to content

Commit

Permalink
Resolve array type names and value types
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Aug 19, 2024
1 parent 8cdebda commit 249ec48
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
38 changes: 38 additions & 0 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @type_name.output -> @mapping.output
}

@type_name [TypeName @array [ArrayTypeName]] {
edge @array.lexical_scope -> @type_name.type_ref
edge @type_name.output -> @array.output
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Mappings
Expand Down Expand Up @@ -397,6 +402,39 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Arrays types
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

@array [ArrayTypeName] {
node @array.lexical_scope
node @array.output
}

@array [ArrayTypeName @type_name [TypeName]] {
edge @type_name.type_ref -> @array.lexical_scope

node typeof_input
attr (typeof_input) pop_symbol = "@typeof"

node index
attr (index) pop_symbol = "[]"

node typeof_output
attr (typeof_output) push_symbol = "@typeof"

;; The array type exposes the `[]` operator that returns the value type
edge @array.output -> typeof_input
edge typeof_input -> index
edge index -> typeof_output
edge typeof_output -> @type_name.output
}

@array [ArrayTypeName @size index: [Expression]] {
edge @size.lexical_scope -> @array.lexical_scope
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Identifier Paths (aka. references to custom types)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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,41 @@
contract CustomArrays {
uint constant SIZE = 5;
// ^def:7

struct Value {
// ^def:1
uint value;
// ^def:2
}

Value[][SIZE] values;
// ^def:3
// ^ref:7
//<ref:1

function test() public returns (uint total) {
// ^def:6
for (uint i = 0; i < values.length; i++) {
// ^ref:3
// ^def:4
for (uint j = 0; j < SIZE - 1; j++) {
// ^def:5
values[i][j + 1].value += values[i][j].value;
// ^ref:2
// ^ref:5
// ^ref:4
// ^ref:3
// ^ref:2
// ^ref:5
// ^ref:4
//<ref:3
}
total += values[i][SIZE - 1].value;
// ^ref:2
// ^ref:7
// ^ref:4
// ^ref:3
//<ref:6
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contract Arrays {
uint[10] ary;
// ^def:1

function test() public {
uint i = 4;
// ^def:2
uint[3] indices = [1, 2, 3];
// ^def:3
ary[1] = ary[i + indices[1]];
// ^ref:3
// ^ref:1
//<ref:1
}
}

0 comments on commit 249ec48

Please sign in to comment.