Skip to content

Commit

Permalink
Bind elementary casting and struct construction to the resulting type
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Oct 28, 2024
1 parent 51ccfe6 commit 00a016b
Show file tree
Hide file tree
Showing 30 changed files with 325 additions and 22 deletions.
27 changes: 27 additions & 0 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,12 @@ inherit .lexical_scope
attr (param_names) pop_symbol = "@param_names"
edge def -> param_names
edge param_names -> @struct.members

; Used as a function call, should bind to itself
node call
attr (call) pop_symbol = "()"
edge def -> call
edge call -> member
}

@struct [StructDefinition [StructMembers
Expand Down Expand Up @@ -1945,6 +1951,16 @@ inherit .lexical_scope
@expr [Expression @type [ElementaryType]] {
edge @expr.output -> @type.ref
edge @type.ref -> @expr.lexical_scope

; Elementary types can also be used for casting; instead of defining built-in
; struct for each available elementary type, we define a special path here
node call
attr (call) pop_symbol = "()"
node typeof
attr (typeof) push_symbol = "@typeof"
edge @expr.output -> call
edge call -> typeof
edge typeof -> @type.ref
}

;; Index access expressions
Expand Down Expand Up @@ -2064,6 +2080,17 @@ inherit .lexical_scope
}


;;; Payable
; These work like `address`, should they should bind to `%address`
@expr [Expression [PayableKeyword]] {
node ref
attr (ref) push_symbol = "%address"

edge ref -> @expr.lexical_scope
edge @expr.output -> ref
}



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Yul
Expand Down
5 changes: 0 additions & 5 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6620,11 +6620,6 @@ codegen_language_macros::compile!(Language(
)
],
built_ins = [
BuiltInFunction(
name = "$address",
parameters = [],
return_type = "$address"
),
BuiltInFunction(
name = "addmod",
parameters = ["uint x", "uint y", "uint k"],
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.

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,42 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected AddressKeyword or AssemblyKeyword or BoolKeyword or BreakKeyword or ByteKeyword or BytesKeyword or CloseBrace or ContinueKeyword or DecimalLiteral or DoKeyword or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or FalseKeyword or FixedKeyword or ForKeyword or FunctionKeyword or HexLiteral or Identifier or IfKeyword or IntKeyword or MappingKeyword or NewKeyword or OpenBrace or OpenBracket or OpenParen or ReturnKeyword or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or StringKeyword or ThrowKeyword or TrueKeyword or UfixedKeyword or UintKeyword or VarKeyword or WhileKeyword.
╭─[input.sol:6:9]
6 │ ╭─▶ payable(a).call("");
┆ ┆
8 │ ├─▶ }
│ │
│ ╰─────────── Error occurred here.
───╯
References and definitions:
╭─[input.sol:1:1]
1 │ contract Test {
│ ──┬─
│ ╰─── def: 1
2 │ using Lib for uint;
│ ─┬─
│ ╰─── ref: 4
4 │ function test(address a) public {
│ ──┬─ ┬
│ ╰───────────── def: 2
│ │
│ ╰── def: 3
5 │ address(this).balance;
│ ──┬─ ───┬───
│ ╰──────────── ref: built-in
│ │
│ ╰───── ref: built-in
11 │ library Lib {
│ ─┬─
│ ╰─── def: 4
12 │ function noop(uint x) public returns (uint) {}
│ ──┬─ ┬
│ ╰────────── def: 5
│ │
│ ╰── def: 6
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected AddressKeyword or AssemblyKeyword or BoolKeyword or BreakKeyword or ByteKeyword or BytesKeyword or CloseBrace or ContinueKeyword or DecimalLiteral or DoKeyword or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or EmitKeyword or FalseKeyword or FixedKeyword or ForKeyword or FunctionKeyword or HexLiteral or Identifier or IfKeyword or IntKeyword or MappingKeyword or NewKeyword or OpenBrace or OpenBracket or OpenParen or ReturnKeyword or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or StringKeyword or ThrowKeyword or TrueKeyword or UfixedKeyword or UintKeyword or VarKeyword or WhileKeyword.
╭─[input.sol:6:9]
6 │ ╭─▶ payable(a).call("");
┆ ┆
8 │ ├─▶ }
│ │
│ ╰─────────── Error occurred here.
───╯
References and definitions:
╭─[input.sol:1:1]
1 │ contract Test {
│ ──┬─
│ ╰─── def: 1
2 │ using Lib for uint;
│ ─┬─
│ ╰─── ref: 4
4 │ function test(address a) public {
│ ──┬─ ┬
│ ╰───────────── def: 2
│ │
│ ╰── def: 3
5 │ address(this).balance;
│ ──┬─ ───┬───
│ ╰──────────── ref: built-in
│ │
│ ╰───── ref: built-in
11 │ library Lib {
│ ─┬─
│ ╰─── def: 4
12 │ function noop(uint x) public returns (uint) {}
│ ──┬─ ┬
│ ╰────────── def: 5
│ │
│ ╰── def: 6
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected AddressKeyword or AssemblyKeyword or BoolKeyword or BreakKeyword or ByteKeyword or BytesKeyword or CloseBrace or ContinueKeyword or DecimalLiteral or DoKeyword or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or EmitKeyword or FalseKeyword or FixedKeyword or ForKeyword or FunctionKeyword or HexLiteral or Identifier or IfKeyword or IntKeyword or MappingKeyword or NewKeyword or OpenBrace or OpenBracket or OpenParen or ReturnKeyword or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or StringKeyword or TrueKeyword or UfixedKeyword or UintKeyword or WhileKeyword.
╭─[input.sol:6:9]
6 │ ╭─▶ payable(a).call("");
┆ ┆
8 │ ├─▶ }
│ │
│ ╰─────────── Error occurred here.
───╯
References and definitions:
╭─[input.sol:1:1]
1 │ contract Test {
│ ──┬─
│ ╰─── def: 1
2 │ using Lib for uint;
│ ─┬─
│ ╰─── ref: 4
4 │ function test(address a) public {
│ ──┬─ ┬
│ ╰───────────── def: 2
│ │
│ ╰── def: 3
5 │ address(this).balance;
│ ──┬─ ───┬───
│ ╰──────────── ref: built-in
│ │
│ ╰───── ref: built-in
11 │ library Lib {
│ ─┬─
│ ╰─── def: 4
12 │ function noop(uint x) public returns (uint) {}
│ ──┬─ ┬
│ ╰────────── def: 5
│ │
│ ╰── def: 6
────╯
Loading

0 comments on commit 00a016b

Please sign in to comment.