This commit is contained in:
Christian Parpart
2020-06-08 10:20:39 +02:00
parent 0e13a3ae3c
commit e1fcd53216
8 changed files with 156 additions and 120 deletions
+42
View File
@@ -263,6 +263,8 @@ bool CompilerStack::parse()
m_sources[newPath].scanner = make_shared<Scanner>(CharStream(newContents, newPath));
sourcesToParse.push_back(newPath);
}
loadMissingInterfaces();
}
}
@@ -272,6 +274,46 @@ bool CompilerStack::parse()
return !m_hasError;
}
void CompilerStack::loadMissingInterfaces()
{
for (auto const& sourcePair: m_sources)
{
ASTPointer<SourceUnit> const& source = sourcePair.second.ast;;
for (auto const& astNode: source->nodes())
{
if (auto* contract = dynamic_cast<ContractDefinition*>(astNode.get()))
{
if (auto const fileName = contract->jsonSourceFile(); fileName.has_value())
{
printf("%s needs replacement\n", fileName->string().c_str());
ReadCallback::Result result{false, string("File not supplied initially.")};
if (m_readFile)
result = m_readFile(ReadCallback::kindString(ReadCallback::Kind::ReadFile), fileName.value().string());
if (result.success)
{
string const& jsonString = result.responseOrErrorMessage;
printf("jsonString: %s\n", jsonString.c_str());
Json::Value json;
util::jsonParseStrict(jsonString, json, nullptr);
ASTPointer<ContractDefinition> jsonContract = ASTJsonImporter{m_evmVersion}.jsonToContract(json);
//TODO: contract = *jsonContract;
}
else
{
m_errorReporter.fatalParserError(
31415_error, // TODO
contract->location(),
"Cannot load JSON source."
);
}
}
}
}
}
}
void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
{
if (m_stackState != Empty)
+2
View File
@@ -360,6 +360,8 @@ private:
std::string applyRemapping(std::string const& _path, std::string const& _context);
void resolveImports();
void loadMissingInterfaces();
/// @returns true if the source is requested to be compiled.
bool isRequestedSource(std::string const& _sourceName) const;