Clarify FileReader interface.

This commit is contained in:
chriseth
2021-12-13 14:54:58 +01:00
parent 9131475b7c
commit 0e6388a907
4 changed files with 38 additions and 39 deletions
+15 -15
View File
@@ -483,7 +483,7 @@ void CommandLineInterface::readInputFiles()
}
else
{
m_fileReader.setSource(infile, move(fileContent));
m_fileReader.addOrUpdateFile(infile, move(fileContent));
m_fileReader.allowDirectory(boost::filesystem::canonical(infile).remove_filename());
}
}
@@ -499,7 +499,7 @@ void CommandLineInterface::readInputFiles()
m_fileReader.setStdin(readUntilEnd(m_sin));
}
if (m_fileReader.sourceCodes().empty() && !m_standardJsonInput.has_value())
if (m_fileReader.sourceUnits().empty() && !m_standardJsonInput.has_value())
solThrow(CommandLineValidationError, "All specified input files either do not exist or are not regular files.");
}
@@ -510,7 +510,7 @@ map<string, Json::Value> CommandLineInterface::parseAstFromInput()
map<string, Json::Value> sourceJsons;
map<string, string> tmpSources;
for (SourceCode const& sourceCode: m_fileReader.sourceCodes() | ranges::views::values)
for (SourceCode const& sourceCode: m_fileReader.sourceUnits() | ranges::views::values)
{
Json::Value ast;
astAssert(jsonParseStrict(sourceCode, ast), "Input file could not be parsed to JSON");
@@ -528,7 +528,7 @@ map<string, Json::Value> CommandLineInterface::parseAstFromInput()
}
}
m_fileReader.setSources(tmpSources);
m_fileReader.setSourceUnits(tmpSources);
return sourceJsons;
}
@@ -721,7 +721,7 @@ void CommandLineInterface::compile()
}
else
{
m_compiler->setSources(m_fileReader.sourceCodes());
m_compiler->setSources(m_fileReader.sourceUnits());
m_compiler->setParserErrorRecovery(m_options.input.errorRecovery);
}
@@ -835,7 +835,7 @@ void CommandLineInterface::handleCombinedJSON()
if (m_options.compiler.combinedJsonRequests->ast)
{
output[g_strSources] = Json::Value(Json::objectValue);
for (auto const& sourceCode: m_fileReader.sourceCodes())
for (auto const& sourceCode: m_fileReader.sourceUnits())
{
ASTJsonConverter converter(m_compiler->state(), m_compiler->sourceIndices());
output[g_strSources][sourceCode.first] = Json::Value(Json::objectValue);
@@ -858,12 +858,12 @@ void CommandLineInterface::handleAst()
return;
vector<ASTNode const*> asts;
for (auto const& sourceCode: m_fileReader.sourceCodes())
for (auto const& sourceCode: m_fileReader.sourceUnits())
asts.push_back(&m_compiler->ast(sourceCode.first));
if (!m_options.output.dir.empty())
{
for (auto const& sourceCode: m_fileReader.sourceCodes())
for (auto const& sourceCode: m_fileReader.sourceUnits())
{
stringstream data;
string postfix = "";
@@ -876,7 +876,7 @@ void CommandLineInterface::handleAst()
else
{
sout() << "JSON AST (compact format):" << endl << endl;
for (auto const& sourceCode: m_fileReader.sourceCodes())
for (auto const& sourceCode: m_fileReader.sourceUnits())
{
sout() << endl << "======= " << sourceCode.first << " =======" << endl;
ASTJsonConverter(m_compiler->state(), m_compiler->sourceIndices()).print(sout(), m_compiler->ast(sourceCode.first));
@@ -908,7 +908,7 @@ void CommandLineInterface::link()
librariesReplacements[replacement] = library.second;
}
FileReader::StringMap sourceCodes = m_fileReader.sourceCodes();
FileReader::StringMap sourceCodes = m_fileReader.sourceUnits();
for (auto& src: sourceCodes)
{
auto end = src.second.end();
@@ -944,14 +944,14 @@ void CommandLineInterface::link()
while (!src.second.empty() && *prev(src.second.end()) == '\n')
src.second.resize(src.second.size() - 1);
}
m_fileReader.setSources(move(sourceCodes));
m_fileReader.setSourceUnits(move(sourceCodes));
}
void CommandLineInterface::writeLinkedFiles()
{
solAssert(m_options.input.mode == InputMode::Linker, "");
for (auto const& src: m_fileReader.sourceCodes())
for (auto const& src: m_fileReader.sourceUnits())
if (src.first == g_stdinFileName)
sout() << src.second << endl;
else
@@ -989,7 +989,7 @@ void CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
bool successful = true;
map<string, yul::AssemblyStack> assemblyStacks;
for (auto const& src: m_fileReader.sourceCodes())
for (auto const& src: m_fileReader.sourceUnits())
{
// --no-optimize-yul option is not accepted in assembly mode.
solAssert(!m_options.optimizer.noOptimizeYul, "");
@@ -1029,7 +1029,7 @@ void CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
solThrow(CommandLineExecutionError, "");
}
for (auto const& src: m_fileReader.sourceCodes())
for (auto const& src: m_fileReader.sourceUnits())
{
string machine =
_targetMachine == yul::AssemblyStack::Machine::EVM ? "EVM" :
@@ -1118,7 +1118,7 @@ void CommandLineInterface::outputCompilationResults()
if (m_options.compiler.outputs.asmJson)
ret = jsonPrettyPrint(removeNullMembers(m_compiler->assemblyJSON(contract)));
else
ret = m_compiler->assemblyString(contract, m_fileReader.sourceCodes());
ret = m_compiler->assemblyString(contract, m_fileReader.sourceUnits());
if (!m_options.output.dir.empty())
createFile(m_compiler->filesystemFriendlyName(contract) + (m_options.compiler.outputs.asmJson ? "_evm.json" : ".evm"), ret);