Skip to content

Commit

Permalink
Replacing per-member path with enum's value ref typenode
Browse files Browse the repository at this point in the history
  • Loading branch information
beta-ziliani committed Jan 13, 2025
1 parent 1b73b89 commit 0f17d5a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 68 deletions.
62 changes: 29 additions & 33 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -2063,44 +2063,40 @@ inherit .star_extension

; Path to link min and max to the enum's scope (#1158)
; It resolves paths of the form `type(<enum>).min.<something>`
node typeof
attr (typeof) pop_symbol = "@typeof"
if (version-matches ">= 0.6.8") {
node typeof
attr (typeof) pop_symbol = "@typeof"

node built_in_member
attr (built_in_member) pop_symbol = "."
node min_built_in
attr (min_built_in) pop_symbol = "min"
node max_built_in
attr (max_built_in) pop_symbol = "max"
node minmax_type_of
attr (minmax_type_of) push_symbol = "@typeof"
node minmax_replace
attr (minmax_replace) push_symbol = (source-text @name)

edge type -> typeof
edge typeof -> built_in_member
edge built_in_member -> min_built_in
edge built_in_member -> max_built_in
edge min_built_in -> minmax_type_of
edge max_built_in -> minmax_type_of
edge minmax_type_of -> minmax_replace
edge minmax_replace -> @enum.lexical_scope
}

@enum [EnumDefinition @name name: [Identifier]
members: [EnumMembers @item [Identifier]]
] {
node built_in_member
attr (built_in_member) pop_symbol = "."
node min_built_in
attr (min_built_in) pop_symbol = "min"
node max_built_in
attr (max_built_in) pop_symbol = "max"
node @enum.value_ref_typeof
attr (@enum.value_ref_typeof) push_symbol = "@typeof"
node value_ref_type
attr (value_ref_type) push_symbol = (source-text @name)

edge type -> typeof
edge typeof -> built_in_member
edge built_in_member -> min_built_in
edge built_in_member -> max_built_in
edge min_built_in -> @enum.value_ref_typeof
edge max_built_in -> @enum.value_ref_typeof
edge @enum.value_ref_typeof -> value_ref_type
edge value_ref_type -> @enum.lexical_scope
}
}

@enum [EnumDefinition members: [EnumMembers @item [Identifier]]] {
node def
attr (def) node_definition = @item
attr (def) definiens_node = @item

node type_of
attr (type_of) push_symbol = "@typeof"
node type_def
attr (type_def) push_symbol = (source-text @name)
edge def -> type_of
edge type_of -> type_def
edge type_def -> @enum.lexical_scope
if (version-matches ">= 0.6.8") {
edge def -> @enum.value_ref_typeof
}

edge @enum.members -> def
}
Expand Down

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
Expand Up @@ -44,12 +44,12 @@ References and definitions:
│ │ │
│ ╰────── unresolved
│ │
│ ╰── ref: 4
│ ╰── unresolved
16 │ type(Answer).max.id();
│ ───┬── ─┬─ ─┬
│ ╰──────────── ref: 1
│ │ │
│ ╰────── unresolved
│ │
│ ╰── ref: 4
│ ╰── unresolved
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

References and definitions:
╭─[input.sol:1:1]
1 │ enum Answer {
│ ───┬──
│ ╰──── def: 1
2 │ Yes
│ ─┬─
│ ╰─── def: 2
5 │ library Id {
│ ─┬
│ ╰── def: 3
6 │ function id(Answer ans) returns (Answer) {
│ ─┬ ───┬── ─┬─ ───┬──
│ ╰────────────────────────────── def: 4
│ │ │ │
│ ╰───────────────────────── ref: 1
│ │ │
│ ╰──────────────────── def: 5
│ │
│ ╰──── ref: 1
7 │ return ans;
│ ─┬─
│ ╰─── ref: 5
11 │ contract Test {
│ ──┬─
│ ╰─── def: 6
12 │ using Id for Answer;
│ ─┬ ───┬──
│ ╰───────────── ref: 3
│ │
│ ╰──── ref: 1
14 │ function testFunc() returns (Answer) {
│ ────┬─── ───┬──
│ ╰─────────────────────── def: 7
│ │
│ ╰──── ref: 1
15 │ Answer.Yes.id();
│ ───┬── ─┬─ ─┬
│ ╰─────────── ref: 1
│ │ │
│ ╰────── ref: 2
│ │
│ ╰── unresolved
────╯

0 comments on commit 0f17d5a

Please sign in to comment.