diff --git a/crates/solidity/inputs/language/bindings/rules.msgb b/crates/solidity/inputs/language/bindings/rules.msgb index a16cfc0f4..43c8d0727 100644 --- a/crates/solidity/inputs/language/bindings/rules.msgb +++ b/crates/solidity/inputs/language/bindings/rules.msgb @@ -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 @@ -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 @@ -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 diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 3c30b06d8..5b95f9cf6 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -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")) diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs index 308679ab0..bdcdb0e36 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs @@ -900,21 +900,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 @@ -1041,7 +1050,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 @@ -1050,7 +1066,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 diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.11.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.11.sol index 6c969175e..7536fff39 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.11.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.11.sol @@ -49,7 +49,7 @@ contract $BuiltIns$ { struct $bytes { function($args) returns (bytes memory) concat; } - struct $function { + struct $functionExternal { function(uint) returns ($function) gas; function(uint) returns ($function) value; } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.17.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.17.sol index 7186f25fb..10f7ee8d0 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.17.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.17.sol @@ -49,7 +49,7 @@ contract $BuiltIns$ { struct $bytes { function($args) returns (bytes memory) concat; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.22.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.22.sol index c624b4908..d6f7ff087 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.22.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.4.22.sol @@ -57,7 +57,7 @@ contract $BuiltIns$ { struct $bytes { function($args) returns (bytes memory) concat; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.0.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.0.sol index 571815c17..3407296c3 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.0.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.0.sol @@ -55,7 +55,7 @@ contract $BuiltIns$ { struct $bytes { function($args) returns (bytes memory) concat; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.3.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.3.sol index 8fbfefff4..576c67d41 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.3.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.5.3.sol @@ -55,7 +55,7 @@ contract $BuiltIns$ { struct $bytes { function($args) returns (bytes memory) concat; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.0.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.0.sol index 5404b9383..62cbfb474 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.0.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.0.sol @@ -56,7 +56,7 @@ contract $BuiltIns$ { struct $bytes { function($args) returns (bytes memory) concat; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.2.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.2.sol index 9a6a100ca..a6663f213 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.2.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.2.sol @@ -61,7 +61,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.7.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.7.sol index ef95f1574..761834811 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.7.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.7.sol @@ -61,7 +61,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.8.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.8.sol index 53d32c482..513963ed5 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.8.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.6.8.sol @@ -61,7 +61,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $selector selector; function(uint) returns ($function) gas; function(uint) returns ($function) value; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.7.0.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.7.0.sol index 3dd3483d8..c87ceb27f 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.7.0.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.7.0.sol @@ -61,7 +61,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $selector selector; } struct $msgType { diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.0.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.0.sol index 9dc51bff4..8855131af 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.0.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.0.sol @@ -59,7 +59,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $selector selector; } struct $msgType { diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.11.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.11.sol index aa84183fd..1d3162cc7 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.11.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.11.sol @@ -61,7 +61,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $address $address; $selector selector; } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.18.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.18.sol index 76dd0f67e..1f9a447d6 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.18.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.18.sol @@ -62,7 +62,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $address $address; $selector selector; } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.2.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.2.sol index 59e99f1ee..6c6c4fa49 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.2.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.2.sol @@ -59,7 +59,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $address $address; $selector selector; } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.24.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.24.sol index fb40e6815..6ac5e16c5 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.24.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.24.sol @@ -64,7 +64,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $address $address; $selector selector; } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.26.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.26.sol index ccf42106b..6b26ce05d 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.26.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.26.sol @@ -65,7 +65,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $address $address; $selector selector; } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.7.sol b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.7.sol index b6eda9879..6fae2fa91 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.7.sol +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/built_ins/0.8.7.sol @@ -60,7 +60,7 @@ contract $BuiltIns$ { uint salt; uint value; } - struct $function { + struct $functionExternal { $address $address; $selector selector; } diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/function_types.rs b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/function_types.rs index db63511c8..75d90a18e 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/function_types.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/function_types.rs @@ -9,6 +9,11 @@ fn call() -> Result<()> { run("function_types", "call") } +#[test] +fn externals() -> Result<()> { + run("function_types", "externals") +} + #[test] fn reference() -> Result<()> { run("function_types", "reference") diff --git a/crates/solidity/testing/snapshots/bindings_output/function_types/externals/generated/0.4.11-failure.txt b/crates/solidity/testing/snapshots/bindings_output/function_types/externals/generated/0.4.11-failure.txt new file mode 100644 index 000000000..a28daa37a --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/function_types/externals/generated/0.4.11-failure.txt @@ -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 +───╯ diff --git a/crates/solidity/testing/snapshots/bindings_output/function_types/externals/generated/0.4.21-success.txt b/crates/solidity/testing/snapshots/bindings_output/function_types/externals/generated/0.4.21-success.txt new file mode 100644 index 000000000..499920025 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/function_types/externals/generated/0.4.21-success.txt @@ -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 +───╯ diff --git a/crates/solidity/testing/snapshots/bindings_output/function_types/externals/input.sol b/crates/solidity/testing/snapshots/bindings_output/function_types/externals/input.sol new file mode 100644 index 000000000..b0433ea76 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/function_types/externals/input.sol @@ -0,0 +1,7 @@ +contract Test { + function test() public { + function() external v1; + v1.selector; + v1.address; + } +}