mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[libsolidity] Preserve sourceList order, if assembly json import is used.
This commit is contained in:
parent
4f2056ff8f
commit
200684a3b9
@ -391,10 +391,23 @@ bool CompilerStack::parse()
|
|||||||
void CompilerStack::importEvmAssemblyJson(map<string, Json::Value> const& _sources)
|
void CompilerStack::importEvmAssemblyJson(map<string, Json::Value> const& _sources)
|
||||||
{
|
{
|
||||||
solAssert(_sources.size() == 1, "");
|
solAssert(_sources.size() == 1, "");
|
||||||
|
solAssert(m_sources.empty(), "");
|
||||||
|
solAssert(m_sourceOrder.empty(), "");
|
||||||
if (m_stackState != Empty)
|
if (m_stackState != Empty)
|
||||||
solThrow(CompilerError, "Must call importEvmAssemblyJson only before the SourcesSet state.");
|
solThrow(CompilerError, "Must call importEvmAssemblyJson only before the SourcesSet state.");
|
||||||
|
|
||||||
m_evmAssemblyJson[_sources.begin()->first] = _sources.begin()->second;
|
Json::Value jsonValue = _sources.begin()->second;
|
||||||
|
if (jsonValue.isMember("sourceList"))
|
||||||
|
{
|
||||||
|
for (auto const& item: jsonValue["sourceList"])
|
||||||
|
{
|
||||||
|
Source source;
|
||||||
|
source.charStream = std::make_shared<CharStream>(item.asString(), "");
|
||||||
|
m_sources.emplace(std::make_pair(item.asString(), source));
|
||||||
|
m_sourceOrder.push_back(&m_sources[item.asString()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_evmAssemblyJson[_sources.begin()->first] = jsonValue;
|
||||||
m_importedSources = true;
|
m_importedSources = true;
|
||||||
m_stackState = SourcesSet;
|
m_stackState = SourcesSet;
|
||||||
}
|
}
|
||||||
@ -608,6 +621,9 @@ bool CompilerStack::parseAndAnalyze(State _stopAfter)
|
|||||||
{
|
{
|
||||||
m_stopAfter = _stopAfter;
|
m_stopAfter = _stopAfter;
|
||||||
|
|
||||||
|
if (!m_evmAssemblyJson.empty())
|
||||||
|
return true;
|
||||||
|
|
||||||
bool success = parse();
|
bool success = parse();
|
||||||
if (m_stackState >= m_stopAfter)
|
if (m_stackState >= m_stopAfter)
|
||||||
return success;
|
return success;
|
||||||
@ -962,9 +978,10 @@ Json::Value CompilerStack::assemblyJSON(string const& _contractName) const
|
|||||||
|
|
||||||
vector<string> CompilerStack::sourceNames() const
|
vector<string> CompilerStack::sourceNames() const
|
||||||
{
|
{
|
||||||
vector<string> names;
|
map<string, unsigned> indices = sourceIndices();
|
||||||
for (auto const& s: m_sources)
|
vector<string> names(indices.size());
|
||||||
names.push_back(s.first);
|
for (auto const& s: indices)
|
||||||
|
names[s.second] = s.first;
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -972,10 +989,16 @@ map<string, unsigned> CompilerStack::sourceIndices() const
|
|||||||
{
|
{
|
||||||
map<string, unsigned> indices;
|
map<string, unsigned> indices;
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
for (auto const& s: m_sources)
|
if (m_evmAssemblyJson.empty())
|
||||||
indices[s.first] = index++;
|
{
|
||||||
solAssert(!indices.count(CompilerContext::yulUtilityFileName()), "");
|
for (auto const& s: m_sources)
|
||||||
indices[CompilerContext::yulUtilityFileName()] = index++;
|
indices[s.first] = index++;
|
||||||
|
solAssert(!indices.count(CompilerContext::yulUtilityFileName()), "");
|
||||||
|
indices[CompilerContext::yulUtilityFileName()] = index++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (auto const& s: m_sourceOrder)
|
||||||
|
indices[s->charStream->source()] = index++;
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user