From 43a8d788ef893abeaaaf0637022fe6c70fea424b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Mon, 4 Nov 2024 17:41:26 -0500 Subject: [PATCH] Resolve qualified members in any position in the inheritance chain This changes how the internal scope for contracts is laid out. Instead of linking everything (state vars, functions, parent bases) to the lexical scope, this is now done to an internal node, which then links to the lexical scope. The lexical scope also contains the path to apply any dynamic scope changes set in the contract (eg. any `using` directives). --- crates/solidity/inputs/language/bindings/rules.msgb | 11 ++++++----- .../src/generated/bindings/generated/binding_rules.rs | 11 ++++++----- .../{0.4.11-failure.txt => 0.4.11-success.txt} | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) rename crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/{0.4.11-failure.txt => 0.4.11-success.txt} (95%) diff --git a/crates/solidity/inputs/language/bindings/rules.msgb b/crates/solidity/inputs/language/bindings/rules.msgb index 9094d9d4f..726768c92 100644 --- a/crates/solidity/inputs/language/bindings/rules.msgb +++ b/crates/solidity/inputs/language/bindings/rules.msgb @@ -305,14 +305,13 @@ inherit .lexical_scope ; be accessed) node internal attr (internal) push_symbol = "@internal" - edge heir.lexical_scope -> internal edge heir.internal -> internal edge internal -> @type_name.push_begin ; Base members can also be accessed qualified with the base name (eg. `Base.something`) node member_pop attr (member_pop) pop_symbol = "." - edge heir.lexical_scope -> @type_name.pop_begin + edge heir.internal -> @type_name.pop_begin edge @type_name.pop_end -> member_pop edge member_pop -> member ; Qualified access should also allow us to bind internal members of the parent contract @@ -358,9 +357,11 @@ inherit .lexical_scope node @contract.state_vars node @contract.internal - edge @contract.lexical_scope -> @contract.members - edge @contract.lexical_scope -> @contract.type_members - edge @contract.lexical_scope -> @contract.state_vars + edge @contract.lexical_scope -> @contract.internal + + edge @contract.internal -> @contract.members + edge @contract.internal -> @contract.type_members + edge @contract.internal -> @contract.state_vars ;; Modifiers are available as a contract type members through a special '@modifier' symbol node modifier 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 d5edd472a..51df7f1ef 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 @@ -310,14 +310,13 @@ inherit .lexical_scope ; be accessed) node internal attr (internal) push_symbol = "@internal" - edge heir.lexical_scope -> internal edge heir.internal -> internal edge internal -> @type_name.push_begin ; Base members can also be accessed qualified with the base name (eg. `Base.something`) node member_pop attr (member_pop) pop_symbol = "." - edge heir.lexical_scope -> @type_name.pop_begin + edge heir.internal -> @type_name.pop_begin edge @type_name.pop_end -> member_pop edge member_pop -> member ; Qualified access should also allow us to bind internal members of the parent contract @@ -363,9 +362,11 @@ inherit .lexical_scope node @contract.state_vars node @contract.internal - edge @contract.lexical_scope -> @contract.members - edge @contract.lexical_scope -> @contract.type_members - edge @contract.lexical_scope -> @contract.state_vars + edge @contract.lexical_scope -> @contract.internal + + edge @contract.internal -> @contract.members + edge @contract.internal -> @contract.type_members + edge @contract.internal -> @contract.state_vars ;; Modifiers are available as a contract type members through a special '@modifier' symbol node modifier diff --git a/crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/0.4.11-failure.txt b/crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/0.4.11-success.txt similarity index 95% rename from crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/0.4.11-failure.txt rename to crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/0.4.11-success.txt index 13c333946..e0763a81c 100644 --- a/crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/0.4.11-failure.txt +++ b/crates/solidity/testing/snapshots/bindings_output/contracts/qualified_parent_call/generated/0.4.11-success.txt @@ -27,5 +27,5 @@ References and definitions: │ ──┬─ ───┬─── │ ╰─────────── ref: 1 │ │ - │ ╰───── unresolved + │ ╰───── ref: 2 ───╯