Merge pull request #12199 from ethereum/expose-parsingAndImporting

Expose "parsingAndImporting" setting to user
This commit is contained in:
chriseth 2021-11-08 17:06:20 +01:00 committed by GitHub
commit 1633e367c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 11 deletions

View File

@ -10,6 +10,7 @@ Compiler Features:
* 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: Support ``--asm``, ``--bin``, ``--ir-optimized``, ``--ewasm`` and ``--ewasm-ir`` output selection options in assembler mode.
* 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: 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``.

View File

@ -351,8 +351,22 @@ bool CompilerStack::parse()
else
{
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)
for (auto const& newSource: loadMissingSources(*source.ast, path))
for (auto const& newSource: loadMissingSources(*source.ast))
{
string const& newPath = newSource.first;
string const& newContents = newSource.second;
@ -1092,7 +1106,7 @@ string const& CompilerStack::Source::ipfsUrl() const
return ipfsUrlCached;
}
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath)
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast)
{
solAssert(m_stackState < ParsedAndImported, "");
StringMap newSources;
@ -1101,14 +1115,8 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string
for (auto const& node: _ast.nodes())
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))
continue;

View File

@ -392,9 +392,9 @@ private:
void findAndReportCyclicContractDependencies();
/// 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.
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);
void resolveImports();

View File

@ -0,0 +1 @@
--pretty-json --json-indent 4

View File

@ -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"]}}
}
}

View File

@ -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
}
}
}

View File

@ -5,6 +5,7 @@
"nodes":
[
{
"absolutePath": "notexisting.sol",
"file": "notexisting.sol",
"id": 1,
"nameLocation": "28:11:1",