FileReader: Store files loaded by the callback under their source unit name

This commit is contained in:
Kamil Śliwak 2021-04-10 19:33:37 +02:00
parent b9b483a0c3
commit 6a41b417a3
10 changed files with 113 additions and 3 deletions

View File

@ -30,6 +30,7 @@ Bugfixes:
* SMTChecker: Fix internal error on public getter returning dynamic data on older EVM versions where these are not available.
* SMTChecker: Fix internal error on try-catch with function call in catch block.
* Type Checker: Fix missing error when events are used without an emit statement.
* Commandline interface: Fix internal error when printing AST and using ``--base-path`` or ``file://`` prefix in imports.
AST Changes:

View File

@ -55,8 +55,7 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _pa
if (validPath.find("file://") == 0)
validPath.erase(0, 7);
auto const path = m_basePath / validPath;
auto canonicalPath = boost::filesystem::weakly_canonical(path);
auto canonicalPath = boost::filesystem::weakly_canonical(m_basePath / validPath);
bool isAllowed = false;
for (auto const& allowedDir: m_allowedDirectories)
{
@ -81,7 +80,7 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _pa
// NOTE: we ignore the FileNotFound exception as we manually check above
auto contents = readFileAsString(canonicalPath.string());
m_sourceCodes[path.generic_string()] = contents;
m_sourceCodes[_path] = contents;
return ReadCallback::Result{true, contents};
}
catch (util::Exception const& _exception)

View File

@ -0,0 +1 @@
--ast-compact-json --base-path . --allow-paths .

View File

@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract C {}

View File

@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
import "./c.sol";

View File

@ -0,0 +1,91 @@
JSON AST (compact format):
======= ast_compact_json_with_base_path/c.sol =======
{
"absolutePath": "ast_compact_json_with_base_path/c.sol",
"exportedSymbols":
{
"C":
[
5
]
},
"id": 6,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 4,
"literals":
[
"solidity",
">=",
"0.0"
],
"nodeType": "PragmaDirective",
"src": "36:22:0"
},
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 5,
"linearizedBaseContracts":
[
5
],
"name": "C",
"nameLocation": "69:1:0",
"nodeType": "ContractDefinition",
"nodes": [],
"scope": 6,
"src": "60:13:0"
}
],
"src": "36:38:0"
}
======= ast_compact_json_with_base_path/input.sol =======
{
"absolutePath": "ast_compact_json_with_base_path/input.sol",
"exportedSymbols":
{
"C":
[
5
]
},
"id": 3,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 1,
"literals":
[
"solidity",
">=",
"0.0"
],
"nodeType": "PragmaDirective",
"src": "36:22:1"
},
{
"absolutePath": "ast_compact_json_with_base_path/c.sol",
"file": "./c.sol",
"id": 2,
"nameLocation": "-1:-1:-1",
"nodeType": "ImportDirective",
"scope": 3,
"sourceUnit": 6,
"src": "60:17:1",
"symbolAliases": [],
"unitAlias": ""
}
],
"src": "36:42:1"
}

View File

@ -0,0 +1 @@
--combined-json ast --base-path . --allow-paths .

View File

@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract C {}

View File

@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
import "./c.sol";

View File

@ -0,0 +1 @@
{"contracts":{"combined_json_with_base_path/c.sol:C":{}},"sourceList":["combined_json_with_base_path/c.sol","combined_json_with_base_path/input.sol"],"sources":{"combined_json_with_base_path/c.sol":{"AST":{"absolutePath":"combined_json_with_base_path/c.sol","exportedSymbols":{"C":[5]},"id":6,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":4,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"contractDependencies":[],"contractKind":"contract","fullyImplemented":true,"id":5,"linearizedBaseContracts":[5],"name":"C","nameLocation":"69:1:0","nodeType":"ContractDefinition","nodes":[],"scope":6,"src":"60:13:0"}],"src":"36:38:0"}},"combined_json_with_base_path/input.sol":{"AST":{"absolutePath":"combined_json_with_base_path/input.sol","exportedSymbols":{"C":[5]},"id":3,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:1"},{"absolutePath":"combined_json_with_base_path/c.sol","file":"./c.sol","id":2,"nameLocation":"-1:-1:-1","nodeType":"ImportDirective","scope":3,"sourceUnit":6,"src":"60:17:1","symbolAliases":[],"unitAlias":""}],"src":"36:42:1"}}},"version": "<VERSION REMOVED>"}