Skip to content

Commit

Permalink
Add preliminary support for super resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Aug 9, 2024
1 parent 64dbcf4 commit d4e1d57
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 2 deletions.
34 changes: 33 additions & 1 deletion crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
node @contract.def
node @contract.members
node @contract.type_members
node @contract.super_scope

edge @contract.lexical_scope -> @contract.members
edge @contract.lexical_scope -> @contract.type_members
Expand Down Expand Up @@ -283,9 +284,23 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge def -> type_member

edge type_member -> @contract.type_members

;; Define "super" effectively as if it was a state variable of a type connected by our super_scope
;; super_scope will later connect to the base contract defs directly
node super
attr (super) pop_symbol = "super"

node super_typeof
attr (super_typeof) push_symbol = "@typeof"

edge super -> super_typeof
edge super_typeof -> @contract.super_scope

;; Finally make "super" available in the contract's lexical scope for function bodies to use
edge @contract.lexical_scope -> super
}

@contract [ContractDefinition [InheritanceSpecifier [InheritanceTypes [InheritanceType
@contract [ContractDefinition [InheritanceSpecifier [InheritanceTypes @type [InheritanceType
@type_name [IdentifierPath]
]]]] {
;; Resolve contract bases names through the parent scope of the contract (aka
Expand All @@ -309,6 +324,12 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i

edge @contract.type_members -> type_member
edge type_member -> @type_name.right

;; The base contract defs are directly accesible through our special super scope
edge @contract.super_scope -> @type_name.right
;; Precedence order for bases defined from right to left (ie. rightmost base has higher precedence)
let p = (plus 1 (named-child-index @type))
attr (@contract.super_scope -> @type_name.right) precedence = p
}

@interface [InterfaceDefinition @name name: [Identifier]] {
Expand Down Expand Up @@ -484,6 +505,17 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @library.members -> @function.def
}

;;; Function modifiers

@contract [ContractDefinition [ContractMembers [ContractMember
@_function [FunctionDefinition [FunctionAttributes [FunctionAttribute
[OverrideSpecifier [OverridePathsDeclaration [OverridePaths
@base_ident [IdentifierPath]
]]]
]]]
]]] {
edge @base_ident.left -> @contract.parent_scope
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract A {
// ^def:dummy -- to have at least one assertion in 0.4.11
function foo() public pure virtual returns (string memory) {
// ^def:1
return "A";
}
}

contract B is A {
function foo() public pure virtual override returns (string memory) {
// ^def:2
return "B";
}
}

contract C is A {
function foo() public pure virtual override returns (string memory) {
// ^def:3
return "C";
}
}

contract D is B, C {
// D.foo() returns "C"
function foo() public pure override(B, C) returns (string memory) {
return super.foo();
// ^ref:3 (>=0.6.0)
}
}

contract E is C, B {
// E.foo() returns "B"
function foo() public pure override(C, B) returns (string memory) {
return super.foo();
// ^ref:2 (>=0.6.0)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected OpenBrace or ReturnsKeyword or Semicolon.
╭─[input.sol:5:27]
5 │ ╭─▶ function foo() public pure virtual returns (string memory) {
┆ ┆
7 │ ├─▶ }
│ │
│ ╰─────────── Error occurred here.
───╯
Error: Expected OpenBrace or ReturnsKeyword or Semicolon.
╭─[input.sol:12:27]
12 │ ╭─▶ function foo() public pure virtual override(A) returns (string memory) {
┆ ┆
14 │ ├─▶ }
│ │
│ ╰─────────── Error occurred here.
────╯
References and definitions:
╭─[input.sol:1:1]
4 │ contract A {
│ ┬
│ ╰── def: 1
5 │ function foo() public pure virtual returns (string memory) {
│ ─┬─
│ ╰─── def: 2
10 │ contract B is A {
│ ┬ ┬
│ ╰─────── def: 3
│ │
│ ╰── ref: 1
12 │ function foo() public pure virtual override(A) returns (string memory) {
│ ─┬─
│ ╰─── def: 4
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

References and definitions:
╭─[input.sol:1:1]
4 │ contract A {
│ ┬
│ ╰── def: 1
5 │ function foo() public pure virtual returns (string memory) {
│ ─┬─ ───┬───
│ ╰───────────────────────── def: 2
│ │
│ ╰───── unresolved
10 │ contract B is A {
│ ┬ ┬
│ ╰─────── def: 3
│ │
│ ╰── ref: 1
12 │ function foo() public pure virtual override(A) returns (string memory) {
│ ─┬─ ───┬─── ────┬─── ┬
│ ╰──────────────────────────────────── def: 4
│ │ │ │
│ ╰──────────────── unresolved
│ │ │
│ ╰─────── unresolved
│ │
│ ╰── unresolved
13 │ return super.foo();
│ ──┬── ─┬─
│ ╰──────── unresolved
│ │
│ ╰─── ref: 2
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected OpenBrace or ReturnsKeyword or Semicolon.
╭─[input.sol:12:40]
12 │ ╭─▶ function foo() public pure virtual override(A) returns (string memory) {
┆ ┆
14 │ ├─▶ }
│ │
│ ╰─────────── Error occurred here.
────╯
References and definitions:
╭─[input.sol:1:1]
4 │ contract A {
│ ┬
│ ╰── def: 1
5 │ function foo() public pure virtual returns (string memory) {
│ ─┬─ ───┬───
│ ╰───────────────────────── def: 2
│ │
│ ╰───── unresolved
10 │ contract B is A {
│ ┬ ┬
│ ╰─────── def: 3
│ │
│ ╰── ref: 1
12 │ function foo() public pure virtual override(A) returns (string memory) {
│ ─┬─ ───┬───
│ ╰───────────────────────── def: 4
│ │
│ ╰───── unresolved
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

References and definitions:
╭─[input.sol:1:1]
4 │ contract A {
│ ┬
│ ╰── def: 1
5 │ function foo() public pure virtual returns (string memory) {
│ ─┬─
│ ╰─── def: 2
10 │ contract B is A {
│ ┬ ┬
│ ╰─────── def: 3
│ │
│ ╰── ref: 1
12 │ function foo() public pure virtual override(A) returns (string memory) {
│ ─┬─ ┬
│ ╰──────────────────────────────────── def: 4
│ │
│ ╰── ref: 1
13 │ return super.foo();
│ ──┬── ─┬─
│ ╰──────── unresolved
│ │
│ ╰─── ref: 2
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract A {
function foo() public pure virtual returns (string memory) {
return "A";
}
}

contract B is A {
// A super;
function foo() public pure virtual override(A) returns (string memory) {
return super.foo();
}
}
Loading

0 comments on commit d4e1d57

Please sign in to comment.