mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
FileReader: Store files loaded by the callback under their source unit name
This commit is contained in:
parent
b9b483a0c3
commit
6a41b417a3
@ -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:
|
||||
|
@ -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)
|
||||
|
1
test/cmdlineTests/ast_compact_json_with_base_path/args
Normal file
1
test/cmdlineTests/ast_compact_json_with_base_path/args
Normal file
@ -0,0 +1 @@
|
||||
--ast-compact-json --base-path . --allow-paths .
|
4
test/cmdlineTests/ast_compact_json_with_base_path/c.sol
Normal file
4
test/cmdlineTests/ast_compact_json_with_base_path/c.sol
Normal file
@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
|
||||
contract C {}
|
@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
|
||||
import "./c.sol";
|
91
test/cmdlineTests/ast_compact_json_with_base_path/output
Normal file
91
test/cmdlineTests/ast_compact_json_with_base_path/output
Normal 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"
|
||||
}
|
1
test/cmdlineTests/combined_json_with_base_path/args
Normal file
1
test/cmdlineTests/combined_json_with_base_path/args
Normal file
@ -0,0 +1 @@
|
||||
--combined-json ast --base-path . --allow-paths .
|
4
test/cmdlineTests/combined_json_with_base_path/c.sol
Normal file
4
test/cmdlineTests/combined_json_with_base_path/c.sol
Normal file
@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
|
||||
contract C {}
|
4
test/cmdlineTests/combined_json_with_base_path/input.sol
Normal file
4
test/cmdlineTests/combined_json_with_base_path/input.sol
Normal file
@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
|
||||
import "./c.sol";
|
1
test/cmdlineTests/combined_json_with_base_path/output
Normal file
1
test/cmdlineTests/combined_json_with_base_path/output
Normal 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>"}
|
Loading…
Reference in New Issue
Block a user