Skip to content

Commit

Permalink
Expose .selector and .address only on external/public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Oct 23, 2024
1 parent c743c01 commit 9a9779c
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 28 deletions.
26 changes: 21 additions & 5 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -895,21 +895,30 @@ inherit .lexical_scope
;;; Function types
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

@ftype [FunctionType] {
@ftype [FunctionType @attrs [FunctionTypeAttributes]] {
; Compute the built-in type of the function
; %functionExternal provides access to .selector and .address
var type = "%function"
scan (source-text @attrs) {
"external" {
set type = "%functionExternal"
}
}

node @ftype.lexical_scope
node @ftype.output

; This path pushes the function type to the symbol stack
; TODO: add parameter and return types to distinguish between different function types
node function_type
attr (function_type) push_symbol = "%function"
attr (function_type) push_symbol = type

edge @ftype.output -> function_type
edge function_type -> @ftype.lexical_scope

; the pop path for the using directive
node pop_function_type
attr (pop_function_type) pop_symbol = "%function"
attr (pop_function_type) pop_symbol = type

let @ftype.pop_begin = pop_function_type
let @ftype.pop_end = pop_function_type
Expand Down Expand Up @@ -1036,7 +1045,14 @@ inherit .lexical_scope
edge @params.defs -> @param.def
}

@function [FunctionDefinition] {
@function [FunctionDefinition @attrs [FunctionAttributes]] {
var function_type = "%function"
scan (source-text @attrs) {
"\\b(public|external)\\b" {
set function_type = "%functionExternal"
}
}

node @function.lexical_scope
node @function.def

Expand All @@ -1045,7 +1061,7 @@ inherit .lexical_scope
node typeof
attr (typeof) push_symbol = "@typeof"
node type_function
attr (type_function) push_symbol = "%function"
attr (type_function) push_symbol = function_type
edge @function.def -> typeof
edge typeof -> type_function
edge type_function -> @function.lexical_scope
Expand Down
2 changes: 1 addition & 1 deletion crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6898,7 +6898,7 @@ codegen_language_macros::compile!(Language(
enabled = From("0.6.2")
),
BuiltInType(
name = "$function",
name = "$functionExternal",
fields = [
BuiltInField(definition = "$address $address", enabled = From("0.8.2")),
BuiltInField(definition = "$selector selector", enabled = From("0.4.17"))
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.

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.

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.

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.

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.

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.

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,23 @@
# 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 β”‚ function() external v1;
β”‚ ─┬
β”‚ ╰── def: 3
4 β”‚ v1.selector;
β”‚ ─┬ ────┬───
β”‚ ╰─────────── ref: 3
β”‚ β”‚
β”‚ ╰───── unresolved
5 β”‚ v1.address;
β”‚ ─┬
β”‚ ╰── ref: 3
───╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 β”‚ function() external v1;
β”‚ ─┬
β”‚ ╰── def: 3
4 β”‚ v1.selector;
β”‚ ─┬ ────┬───
β”‚ ╰─────────── ref: 3
β”‚ β”‚
β”‚ ╰───── ref: built-in
5 β”‚ v1.address;
β”‚ ─┬
β”‚ ╰── ref: 3
───╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract Test {
function test() public {
function() external v1;
v1.selector;
v1.address;
}
}

0 comments on commit 9a9779c

Please sign in to comment.