Skip to content

Commit

Permalink
Binding rules for function types
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Aug 20, 2024
1 parent 7bb64cf commit 4b40e18
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @type_name.output -> @array.output
}

@type_name [TypeName @ftype [FunctionType]] {
edge @ftype.lexical_scope -> @type_name.type_ref
edge @type_name.output -> @ftype.output
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Mappings
Expand Down Expand Up @@ -438,6 +443,25 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function types
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

@ftype [FunctionType] {
node @ftype.lexical_scope
node @ftype.output
}

@ftype [FunctionType @params [ParametersDeclaration]] {
edge @params.lexical_scope -> @ftype.lexical_scope
}

@ftype [FunctionType [ReturnsDeclaration @return_params [ParametersDeclaration]]] {
edge @return_params.lexical_scope -> @ftype.lexical_scope
}



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Identifier Paths (aka. references to custom types)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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,32 @@
contract Test {
struct Coords {
// ^def:1
int x;
int y;
}
enum HitTest {
//^def:2
Inside,
Outside
}
struct Box {
// ^def:3
function (Coords memory) external returns (HitTest) hitTest;
// ^def:4
// ^ref:2
// ^ref:1
}
Box[] boxes;
// ^def:5
//<ref:3

function insideBoxes(Coords memory p) public returns (bool) {
for (uint i = 0; i < boxes.length; i++) {
if (boxes[i].hitTest(p) == HitTest.Inside) return true;
// ^ref:2
// ^ref:4
// ^ref:5
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library Utils {
enum Answer { Yes, No }
// ^def:1

function runCallback(Answer input, function (Answer) f) internal {
// ^def:2
// ^ref:1
f(input);
//<ref:2
}

function map(Answer input, function (Answer) returns (Answer) f)
// ^def:3
// ^ref:1
// ^ref:1
internal returns (Answer result)
{
result = f(input);
// ^ref:3
}
}

0 comments on commit 4b40e18

Please sign in to comment.