Skip to content

Commit

Permalink
Add binding rules for function calls (TBD: binding of named arguments)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Jun 26, 2024
1 parent a19ae4f commit 140dfe4
Show file tree
Hide file tree
Showing 18 changed files with 1,026 additions and 51 deletions.
40 changes: 39 additions & 1 deletion crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,12 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @expr.type -> @name.ref
}

;; General case for nested expressions
@expr [Expression ... variant: [_ ... @child [Expression] ...] ...] {
edge @child.lexical_scope -> @expr.lexical_scope
}

;; Expressions as statements
@stmt [Statement ... variant: [_ ... @expr [Expression] ...] ...] {
edge @expr.lexical_scope -> @stmt.lexical_scope
}
Expand All @@ -521,7 +523,6 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @expr.lexical_scope -> @state_var.lexical_scope
}


;;; Member access expressions

@member [MemberAccess] {
Expand Down Expand Up @@ -550,3 +551,40 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @member.lexical_scope -> member
edge member -> @expr.type
}

;;; Function call expressions

@args [ArgumentsDeclaration] {
node @args.lexical_scope
}

@args [ArgumentsDeclaration [PositionalArgumentsDeclaration
...
[PositionalArguments ... @argument [Expression] ...]
...
]] {
edge @argument.lexical_scope -> @args.lexical_scope
}

@named_arg [NamedArgument ... @name [Identifier] [Colon] @value [Expression]] {
node @named_arg.lexical_scope

edge @value.lexical_scope -> @named_arg.lexical_scope

node ref
attr (ref) node_reference = @name
;; TODO: bind the named argument to the parameters definition of the function
;; (is this possible given that function references are expressions?)
}

@args [ArgumentsDeclaration [NamedArgumentsDeclaration
...
[NamedArgumentGroup ... [NamedArguments ... @argument [NamedArgument] ...] ...]
...
]] {
edge @argument.lexical_scope -> @args.lexical_scope
}

@funcall [Expression [FunctionCallExpression ... @args [ArgumentsDeclaration]]] {
edge @args.lexical_scope -> @funcall.lexical_scope
}

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
Expand Up @@ -65,7 +65,7 @@ line 132 column 8`"/]
N15[\"`**getAnswer** @(6, 1)
def
line 132 column 8`"/]
N16[\"`**getAnswer2** @(10, 1)
N16[\"`**getOtherAnswer** @(10, 1)
def
line 132 column 8`"/]
N17["`**17** @(4, 24)
Expand All @@ -76,7 +76,7 @@ line 144 column 19`"]
@type_name.type
line 144 column 19`"]
N18 --> N28
N19["`**19** @(11, 36)
N19["`**19** @(11, 40)
@type_name.type
line 144 column 19`"]
N19 --> N30
Expand All @@ -88,7 +88,7 @@ line 148 column 17`"]
@id_path.ref
line 148 column 17`"]
N21 --> N18
N22["`**22** @(11, 36)
N22["`**22** @(11, 40)
@id_path.ref
line 148 column 17`"]
N22 --> N19
Expand All @@ -100,7 +100,7 @@ line 156 column 14`"\]
@name.ref
line 156 column 14`"\]
N24 --> N21
N25[/"`**Answer** @(11, 36)
N25[/"`**Answer** @(11, 40)
@name.ref
line 156 column 14`"\]
N25 --> N22
Expand All @@ -120,11 +120,11 @@ line 178 column 15`"]
@param.defs
line 179 column 15`"]
N29 --> N34
N30["`**30** @(11, 36)
N30["`**30** @(11, 40)
@param.lexical_scope
line 178 column 15`"]
N30 --> N11
N31["`**31** @(11, 36)
N31["`**31** @(11, 40)
@param.defs
line 179 column 15`"]
N32[\"`**ans** @(4, 24)
Expand Down Expand Up @@ -159,12 +159,12 @@ line 265 column 15`"]
@block.defs
line 266 column 15`"]
N39 --> N43
N40["`**40** @(11, 43)
N40["`**40** @(11, 47)
@block.lexical_scope
line 265 column 15`"]
N40 --> N11
N40 --> N45
N41["`**41** @(11, 43)
N41["`**41** @(11, 47)
@block.defs
line 266 column 15`"]
N41 --> N45
Expand Down Expand Up @@ -260,25 +260,25 @@ line 492 column 14`"\]
N65 --> N61
N66["`**66** @(8, 22)
@member.lexical_scope
line 529 column 16`"]
line 530 column 16`"]
N66 --> N70
N67["`**67** @(12, 23)
@member.lexical_scope
line 529 column 16`"]
line 530 column 16`"]
N67 --> N71
N68[/"`**Yes** @(8, 22)
ref
line 533 column 8`"\]
line 534 column 8`"\]
N68 --> N66
N69[/"`**No** @(12, 23)
ref
line 533 column 8`"\]
line 534 column 8`"\]
N69 --> N67
N70[/"`**.** @(8, 14)
member
line 548 column 8`"\]
line 549 column 8`"\]
N70 --> N58
N71[/"`**.** @(12, 15)
member
line 548 column 8`"\]
line 549 column 8`"\]
N71 --> N62
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ References and definitions:
│ │
│ ╰─── ref: 3
11 │ function getAnswer2() returns (Answer) {
│ ───────── ───┬──
──────────────────────── def: 9
│ │
│ ╰──── ref: 2
11 │ function getOtherAnswer() returns (Answer) {
│ ───────┬────── ───┬──
╰────────────────────────── def: 9
╰──── ref: 2
12 │ return Answer.No;
│ ───┬── ─┬
│ ╰─────── ref: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ line 132 column 8`"/]
N15[\"`**getAnswer** @(6, 1)
def
line 132 column 8`"/]
N16[\"`**getAnswer2** @(10, 1)
N16[\"`**getOtherAnswer** @(10, 1)
def
line 132 column 8`"/]
N17["`**17** @(4, 24)
Expand All @@ -76,7 +76,7 @@ line 144 column 19`"]
@type_name.type
line 144 column 19`"]
N18 --> N28
N19["`**19** @(11, 36)
N19["`**19** @(11, 40)
@type_name.type
line 144 column 19`"]
N19 --> N30
Expand All @@ -88,7 +88,7 @@ line 148 column 17`"]
@id_path.ref
line 148 column 17`"]
N21 --> N18
N22["`**22** @(11, 36)
N22["`**22** @(11, 40)
@id_path.ref
line 148 column 17`"]
N22 --> N19
Expand All @@ -100,7 +100,7 @@ line 156 column 14`"\]
@name.ref
line 156 column 14`"\]
N24 --> N21
N25[/"`**Answer** @(11, 36)
N25[/"`**Answer** @(11, 40)
@name.ref
line 156 column 14`"\]
N25 --> N22
Expand All @@ -120,11 +120,11 @@ line 178 column 15`"]
@param.defs
line 179 column 15`"]
N29 --> N34
N30["`**30** @(11, 36)
N30["`**30** @(11, 40)
@param.lexical_scope
line 178 column 15`"]
N30 --> N11
N31["`**31** @(11, 36)
N31["`**31** @(11, 40)
@param.defs
line 179 column 15`"]
N32[\"`**ans** @(4, 24)
Expand Down Expand Up @@ -157,11 +157,11 @@ line 265 column 15`"]
N39["`**39** @(7, 46)
@block.defs
line 266 column 15`"]
N40["`**40** @(11, 43)
N40["`**40** @(11, 47)
@block.lexical_scope
line 265 column 15`"]
N40 --> N11
N41["`**41** @(11, 43)
N41["`**41** @(11, 47)
@block.defs
line 266 column 15`"]
N42["`**42** @(8, 1)
Expand Down Expand Up @@ -258,25 +258,25 @@ line 492 column 14`"\]
N65 --> N61
N66["`**66** @(8, 22)
@member.lexical_scope
line 529 column 16`"]
line 530 column 16`"]
N66 --> N70
N67["`**67** @(12, 23)
@member.lexical_scope
line 529 column 16`"]
line 530 column 16`"]
N67 --> N71
N68[/"`**Yes** @(8, 22)
ref
line 533 column 8`"\]
line 534 column 8`"\]
N68 --> N66
N69[/"`**No** @(12, 23)
ref
line 533 column 8`"\]
line 534 column 8`"\]
N69 --> N67
N70[/"`**.** @(8, 14)
member
line 548 column 8`"\]
line 549 column 8`"\]
N70 --> N58
N71[/"`**.** @(12, 15)
member
line 548 column 8`"\]
line 549 column 8`"\]
N71 --> N62
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ line 492 column 14`"\]
N24 --> N22
N25["`**25** @(4, 28)
@member.lexical_scope
line 529 column 16`"]
line 530 column 16`"]
N25 --> N27
N26[/"`**Yes** @(4, 28)
ref
line 533 column 8`"\]
line 534 column 8`"\]
N26 --> N25
N27[/"`**.** @(4, 20)
member
line 548 column 8`"\]
line 549 column 8`"\]
N27 --> N23
Loading

0 comments on commit 140dfe4

Please sign in to comment.