mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Evaluate absolute paths for imports in 'parsing' stage
This commit is contained in:
parent
cede36930d
commit
fc224f74c7
@ -8,6 +8,7 @@ Compiler Features:
|
|||||||
* Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``.
|
* Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``.
|
||||||
* Commandline Interface: Add ``--debug-info`` option for selecting how much extra debug information should be included in the produced EVM assembly and Yul code.
|
* Commandline Interface: Add ``--debug-info`` option for selecting how much extra debug information should be included in the produced EVM assembly and Yul code.
|
||||||
* Commandline Interface: Use different colors when printing errors, warnings and infos.
|
* Commandline Interface: Use different colors when printing errors, warnings and infos.
|
||||||
|
* JSON AST: Set absolute paths of imports earlier, in the ``parsing`` stage.
|
||||||
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
|
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
|
||||||
* SMTChecker: Report contract invariants and reentrancy properties. This can be enabled via the CLI option ``--model-checker-invariants`` or the Standard JSON option ``settings.modelChecker.invariants``.
|
* SMTChecker: Report contract invariants and reentrancy properties. This can be enabled via the CLI option ``--model-checker-invariants`` or the Standard JSON option ``settings.modelChecker.invariants``.
|
||||||
* Standard JSON: Accept nested brackets in step sequences passed to ``settings.optimizer.details.yulDetails.optimizerSteps``.
|
* Standard JSON: Accept nested brackets in step sequences passed to ``settings.optimizer.details.yulDetails.optimizerSteps``.
|
||||||
|
@ -350,8 +350,22 @@ bool CompilerStack::parse()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
source.ast->annotation().path = path;
|
source.ast->annotation().path = path;
|
||||||
|
|
||||||
|
for (auto const& import: ASTNode::filteredNodes<ImportDirective>(source.ast->nodes()))
|
||||||
|
{
|
||||||
|
solAssert(!import->path().empty(), "Import path cannot be empty.");
|
||||||
|
|
||||||
|
// The current value of `path` is the absolute path as seen from this source file.
|
||||||
|
// We first have to apply remappings before we can store the actual absolute path
|
||||||
|
// as seen globally.
|
||||||
|
import->annotation().absolutePath = applyRemapping(util::absolutePath(
|
||||||
|
import->path(),
|
||||||
|
path
|
||||||
|
), path);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_stopAfter >= ParsedAndImported)
|
if (m_stopAfter >= ParsedAndImported)
|
||||||
for (auto const& newSource: loadMissingSources(*source.ast, path))
|
for (auto const& newSource: loadMissingSources(*source.ast))
|
||||||
{
|
{
|
||||||
string const& newPath = newSource.first;
|
string const& newPath = newSource.first;
|
||||||
string const& newContents = newSource.second;
|
string const& newContents = newSource.second;
|
||||||
@ -1091,7 +1105,7 @@ string const& CompilerStack::Source::ipfsUrl() const
|
|||||||
return ipfsUrlCached;
|
return ipfsUrlCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath)
|
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast)
|
||||||
{
|
{
|
||||||
solAssert(m_stackState < ParsedAndImported, "");
|
solAssert(m_stackState < ParsedAndImported, "");
|
||||||
StringMap newSources;
|
StringMap newSources;
|
||||||
@ -1100,14 +1114,8 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string
|
|||||||
for (auto const& node: _ast.nodes())
|
for (auto const& node: _ast.nodes())
|
||||||
if (ImportDirective const* import = dynamic_cast<ImportDirective*>(node.get()))
|
if (ImportDirective const* import = dynamic_cast<ImportDirective*>(node.get()))
|
||||||
{
|
{
|
||||||
solAssert(!import->path().empty(), "Import path cannot be empty.");
|
string const& importPath = *import->annotation().absolutePath;
|
||||||
|
|
||||||
string importPath = util::absolutePath(import->path(), _sourcePath);
|
|
||||||
// The current value of `path` is the absolute path as seen from this source file.
|
|
||||||
// We first have to apply remappings before we can store the actual absolute path
|
|
||||||
// as seen globally.
|
|
||||||
importPath = applyRemapping(importPath, _sourcePath);
|
|
||||||
import->annotation().absolutePath = importPath;
|
|
||||||
if (m_sources.count(importPath) || newSources.count(importPath))
|
if (m_sources.count(importPath) || newSources.count(importPath))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -392,9 +392,9 @@ private:
|
|||||||
void findAndReportCyclicContractDependencies();
|
void findAndReportCyclicContractDependencies();
|
||||||
|
|
||||||
/// Loads the missing sources from @a _ast (named @a _path) using the callback
|
/// Loads the missing sources from @a _ast (named @a _path) using the callback
|
||||||
/// @a m_readFile and stores the absolute paths of all imports in the AST annotations.
|
/// @a m_readFile
|
||||||
/// @returns the newly loaded sources.
|
/// @returns the newly loaded sources.
|
||||||
StringMap loadMissingSources(SourceUnit const& _ast, std::string const& _path);
|
StringMap loadMissingSources(SourceUnit const& _ast);
|
||||||
std::string applyRemapping(std::string const& _path, std::string const& _context);
|
std::string applyRemapping(std::string const& _path, std::string const& _context);
|
||||||
void resolveImports();
|
void resolveImports();
|
||||||
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
--pretty-json --json-indent 4
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"language": "Solidity",
|
||||||
|
"sources": {
|
||||||
|
"/project/../C.sol": {"content": "//SPDX-License-Identifier: GPL-2.0\npragma solidity >=0.0;\nimport \"../L.sol\";"},
|
||||||
|
"/lib/L.sol": {"content": "//SPDX-License-Identifier: GPL-2.0\npragma solidity >=0.0;\n"}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"stopAfter": "parsing",
|
||||||
|
"remappings": [":/project/=/lib/"],
|
||||||
|
"outputSelection": {"*": {"": ["ast"]}}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"sources":
|
||||||
|
{
|
||||||
|
"/lib/L.sol":
|
||||||
|
{
|
||||||
|
"ast":
|
||||||
|
{
|
||||||
|
"absolutePath": "/lib/L.sol",
|
||||||
|
"id": 2,
|
||||||
|
"license": "GPL-2.0",
|
||||||
|
"nodeType": "SourceUnit",
|
||||||
|
"nodes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"literals":
|
||||||
|
[
|
||||||
|
"solidity",
|
||||||
|
">=",
|
||||||
|
"0.0"
|
||||||
|
],
|
||||||
|
"nodeType": "PragmaDirective",
|
||||||
|
"src": "35:22:0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "35:23:0"
|
||||||
|
},
|
||||||
|
"id": 0
|
||||||
|
},
|
||||||
|
"/project/../C.sol":
|
||||||
|
{
|
||||||
|
"ast":
|
||||||
|
{
|
||||||
|
"absolutePath": "/project/../C.sol",
|
||||||
|
"id": 5,
|
||||||
|
"license": "GPL-2.0",
|
||||||
|
"nodeType": "SourceUnit",
|
||||||
|
"nodes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"literals":
|
||||||
|
[
|
||||||
|
"solidity",
|
||||||
|
">=",
|
||||||
|
"0.0"
|
||||||
|
],
|
||||||
|
"nodeType": "PragmaDirective",
|
||||||
|
"src": "35:22:1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"absolutePath": "/lib/L.sol",
|
||||||
|
"file": "../L.sol",
|
||||||
|
"id": 4,
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "ImportDirective",
|
||||||
|
"src": "58:18:1",
|
||||||
|
"symbolAliases": [],
|
||||||
|
"unitAlias": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "35:41:1"
|
||||||
|
},
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
"nodes":
|
"nodes":
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
"absolutePath": "notexisting.sol",
|
||||||
"file": "notexisting.sol",
|
"file": "notexisting.sol",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"nameLocation": "28:11:1",
|
"nameLocation": "28:11:1",
|
||||||
|
Loading…
Reference in New Issue
Block a user