Skip to content

Commit

Permalink
Expose public state variables so that they are accessible through this
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Sep 23, 2024
1 parent 2175d37 commit 81fa4f9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
18 changes: 13 additions & 5 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ inherit .enclosing_def
edge @contract.lexical_scope -> @member.def
}

;; Public state variables are also exposed as external member functions
@contract [ContractDefinition [ContractMembers [ContractMember
@state_var [StateVariableDefinition
[StateVariableAttributes [StateVariableAttribute [PublicKeyword]]]
]
]]] {
edge @contract.members -> @state_var.def
}

@contract [ContractDefinition members: [ContractMembers
item: [ContractMember @function variant: [FunctionDefinition]]
]] {
Expand Down Expand Up @@ -1243,17 +1252,16 @@ inherit .enclosing_def
@type_name type_name: [TypeName]
@name name: [Identifier]
] {
node def
attr (def) node_definition = @name
attr (def) definiens_node = @state_var
attr (@state_var.def) node_definition = @name
attr (@state_var.def) definiens_node = @state_var

edge @state_var.def -> def
edge @state_var.def -> @state_var.def
edge @type_name.type_ref -> @state_var.lexical_scope

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

edge def -> typeof
edge @state_var.def -> typeof
edge typeof -> @type_name.output
}

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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

References and definitions:
╭─[input.sol:1:1]
1 │ contract Foo {
│ ─┬─
│ ╰─── def: 1
2 │ int public x;
│ ┬
│ ╰── def: 2
5 │ contract Bar {
│ ─┬─
│ ╰─── def: 3
6 │ int public y;
│ ┬
│ ╰── def: 4
7 │ Foo f;
│ ─┬─ ┬
│ ╰───── ref: 1
│ │
│ ╰── def: 5
9 │ function test() public returns (int) {
│ ──┬─
│ ╰─── def: 6
10 │ return y + this.y() + f.x();
│ ┬ ──┬─ ┬ ┬ ┬
│ ╰─────────────────── ref: 4
│ │ │ │ │
│ ╰───────────── unresolved
│ │ │ │
│ ╰────────── ref: 4
│ │ │
│ ╰──── ref: 5
│ │
│ ╰── ref: 2
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract Foo {
int public x;
}

contract Bar {
int public y;
Foo f;

function test() public returns (int) {
return y + this.y() + f.x();
}
}

0 comments on commit 81fa4f9

Please sign in to comment.