Skip to content

Commit 200684a

Browse files
committed
[libsolidity] Preserve sourceList order, if assembly json import is used.
1 parent 4f2056f commit 200684a

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

libsolidity/interface/CompilerStack.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,23 @@ bool CompilerStack::parse()
391391
void CompilerStack::importEvmAssemblyJson(map<string, Json::Value> const& _sources)
392392
{
393393
solAssert(_sources.size() == 1, "");
394+
solAssert(m_sources.empty(), "");
395+
solAssert(m_sourceOrder.empty(), "");
394396
if (m_stackState != Empty)
395397
solThrow(CompilerError, "Must call importEvmAssemblyJson only before the SourcesSet state.");
396398

397-
m_evmAssemblyJson[_sources.begin()->first] = _sources.begin()->second;
399+
Json::Value jsonValue = _sources.begin()->second;
400+
if (jsonValue.isMember("sourceList"))
401+
{
402+
for (auto const& item: jsonValue["sourceList"])
403+
{
404+
Source source;
405+
source.charStream = std::make_shared<CharStream>(item.asString(), "");
406+
m_sources.emplace(std::make_pair(item.asString(), source));
407+
m_sourceOrder.push_back(&m_sources[item.asString()]);
408+
}
409+
}
410+
m_evmAssemblyJson[_sources.begin()->first] = jsonValue;
398411
m_importedSources = true;
399412
m_stackState = SourcesSet;
400413
}
@@ -608,6 +621,9 @@ bool CompilerStack::parseAndAnalyze(State _stopAfter)
608621
{
609622
m_stopAfter = _stopAfter;
610623

624+
if (!m_evmAssemblyJson.empty())
625+
return true;
626+
611627
bool success = parse();
612628
if (m_stackState >= m_stopAfter)
613629
return success;
@@ -962,20 +978,27 @@ Json::Value CompilerStack::assemblyJSON(string const& _contractName) const
962978

963979
vector<string> CompilerStack::sourceNames() const
964980
{
965-
vector<string> names;
966-
for (auto const& s: m_sources)
967-
names.push_back(s.first);
981+
map<string, unsigned> indices = sourceIndices();
982+
vector<string> names(indices.size());
983+
for (auto const& s: indices)
984+
names[s.second] = s.first;
968985
return names;
969986
}
970987

971988
map<string, unsigned> CompilerStack::sourceIndices() const
972989
{
973990
map<string, unsigned> indices;
974991
unsigned index = 0;
975-
for (auto const& s: m_sources)
976-
indices[s.first] = index++;
977-
solAssert(!indices.count(CompilerContext::yulUtilityFileName()), "");
978-
indices[CompilerContext::yulUtilityFileName()] = index++;
992+
if (m_evmAssemblyJson.empty())
993+
{
994+
for (auto const& s: m_sources)
995+
indices[s.first] = index++;
996+
solAssert(!indices.count(CompilerContext::yulUtilityFileName()), "");
997+
indices[CompilerContext::yulUtilityFileName()] = index++;
998+
}
999+
else
1000+
for (auto const& s: m_sourceOrder)
1001+
indices[s->charStream->source()] = index++;
9791002
return indices;
9801003
}
9811004

0 commit comments

Comments
 (0)