Merge pull request #8063 from ethereum/yulvisit-7656

Use yul::AstWalker for assembly reference resolving
This commit is contained in:
Mathias L. Baumann
2020-01-29 14:56:19 +01:00
committed by GitHub
8 changed files with 468 additions and 83 deletions
@@ -0,0 +1,166 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
8
]
},
"id": 9,
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 8,
"linearizedBaseContracts":
[
8
],
"name": "C",
"nodeType": "ContractDefinition",
"nodes":
[
{
"body":
{
"id": 6,
"nodeType": "Block",
"src": "57:97:1",
"statements":
[
{
"AST":
{
"nodeType": "YulBlock",
"src": "72:78:1",
"statements":
[
{
"body":
{
"nodeType": "YulBlock",
"src": "94:50:1",
"statements":
[
{
"body":
{
"nodeType": "YulBlock",
"src": "118:3:1",
"statements": []
},
"name": "f2",
"nodeType": "YulFunctionDefinition",
"src": "104:17:1"
},
{
"nodeType": "YulAssignment",
"src": "130:6:1",
"value":
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "135:1:1",
"type": "",
"value": "2"
},
"variableNames":
[
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "130:1:1"
}
]
}
]
},
"name": "f1",
"nodeType": "YulFunctionDefinition",
"src": "80:64:1"
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 5,
"nodeType": "InlineAssembly",
"src": "63:87:1"
}
]
},
"documentation": null,
"functionSelector": "26121ff0",
"id": 7,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "f",
"nodeType": "FunctionDefinition",
"overrides": null,
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "25:2:1"
},
"returnParameters":
{
"id": 4,
"nodeType": "ParameterList",
"parameters":
[
{
"constant": false,
"id": 3,
"name": "x",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 7,
"src": "49:6:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName":
{
"id": 2,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "49:4:1",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
}
],
"src": "48:8:1"
},
"scope": 8,
"src": "15:139:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
}
],
"scope": 9,
"src": "0:156:1"
}
],
"src": "0:157:1"
}
@@ -0,0 +1,12 @@
contract C {
function f() public pure returns (uint x) {
assembly {
function f1() {
function f2() { }
x := 2
}
}
}
}
// ----
@@ -0,0 +1,148 @@
{
"attributes":
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
8
]
}
},
"children":
[
{
"attributes":
{
"abstract": false,
"baseContracts":
[
null
],
"contractDependencies":
[
null
],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"linearizedBaseContracts":
[
8
],
"name": "C",
"scope": 9
},
"children":
[
{
"attributes":
{
"documentation": null,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,
"kind": "function",
"modifiers":
[
null
],
"name": "f",
"overrides": null,
"scope": 8,
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
},
"children":
[
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 1,
"name": "ParameterList",
"src": "25:2:1"
},
{
"children":
[
{
"attributes":
{
"constant": false,
"name": "x",
"overrides": null,
"scope": 7,
"stateVariable": false,
"storageLocation": "default",
"type": "uint256",
"value": null,
"visibility": "internal"
},
"children":
[
{
"attributes":
{
"name": "uint",
"type": "uint256"
},
"id": 2,
"name": "ElementaryTypeName",
"src": "49:4:1"
}
],
"id": 3,
"name": "VariableDeclaration",
"src": "49:6:1"
}
],
"id": 4,
"name": "ParameterList",
"src": "48:8:1"
},
{
"children":
[
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null
],
"operations": "{\n function f1()\n {\n function f2()\n { }\n x := 2\n }\n}"
},
"children": [],
"id": 5,
"name": "InlineAssembly",
"src": "63:87:1"
}
],
"id": 6,
"name": "Block",
"src": "57:97:1"
}
],
"id": 7,
"name": "FunctionDefinition",
"src": "15:139:1"
}
],
"id": 8,
"name": "ContractDefinition",
"src": "0:156:1"
}
],
"id": 9,
"name": "SourceUnit",
"src": "0:157:1"
}
+17 -1
View File
@@ -158,7 +158,23 @@
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"externalReferences":
[
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "141:1:1",
"valueSize": 18446744073709551615
},
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "172:1:1",
"valueSize": 18446744073709551615
}
],
"id": 3,
"nodeType": "InlineAssembly",
"src": "52:138:1"
@@ -92,7 +92,20 @@
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "141:1:1",
"valueSize": 18446744073709551615
},
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "172:1:1",
"valueSize": 18446744073709551615
}
],
"operations": "{\n let f := 0\n switch calldatasize()\n case 0 { f := 1 }\n default { f := 2 }\n}"
},
@@ -0,0 +1,12 @@
contract C {
function f() public pure returns (uint x) {
assembly {
function f1() {
function f2() { }
x := 2
}
}
}
}
// ----
// DeclarationError: (130-131): Cannot access local Solidity variables from inside an inline assembly function.