Skip to content

Commit 1eeb351

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent 4af2272 commit 1eeb351

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

libevmasm/Assembly.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ void Assembly::importAssemblyItemsFromJSON(Json::Value const& _code, std::vector
8181
{
8282
solAssert(m_items.empty());
8383
solRequire(_code.isArray(), AssemblyImportException, "Supplied JSON is not an array.");
84-
for (auto current = std::begin(_code); current != std::end(_code); ++current)
84+
for (auto jsonItemIter = std::begin(_code); jsonItemIter != std::end(_code); ++jsonItemIter)
8585
{
86-
AssemblyItem const& item = m_items.emplace_back(createAssemblyItemFromJSON(*current, _sourceList));
87-
if (item == Instruction::JUMPDEST)
86+
AssemblyItem const& newItem = m_items.emplace_back(createAssemblyItemFromJSON(*jsonItemIter, _sourceList));
87+
if (newItem == Instruction::JUMPDEST)
8888
solThrow(AssemblyImportException, "JUMPDEST instruction without a tag");
89-
else if (item.type() == AssemblyItemType::Tag)
89+
else if (newItem.type() == AssemblyItemType::Tag)
9090
{
91-
++current;
92-
if (current != std::end(_code) && createAssemblyItemFromJSON(*current, _sourceList) != Instruction::JUMPDEST)
91+
++jsonItemIter;
92+
if (jsonItemIter != std::end(_code) && createAssemblyItemFromJSON(*jsonItemIter, _sourceList) != Instruction::JUMPDEST)
9393
solThrow(AssemblyImportException, "JUMPDEST expected after tag.");
9494
}
9595
}
@@ -530,8 +530,8 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
530530
if (_json.isMember("sourceList"))
531531
{
532532
solRequire(_json["sourceList"].isArray(), AssemblyImportException, "Optional member 'sourceList' is not an array.");
533-
for (Json::Value const& sourceListItem: _json["sourceList"])
534-
solRequire(sourceListItem.isString(), AssemblyImportException, "The 'sourceList' array contains an item that is not a string.");
533+
for (Json::Value const& sourceName: _json["sourceList"])
534+
solRequire(sourceName.isString(), AssemblyImportException, "The 'sourceList' array contains an item that is not a string.");
535535
}
536536
}
537537
else
@@ -545,14 +545,14 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
545545
if (_json.isMember("sourceList"))
546546
{
547547
solAssert(_level == 0);
548-
for (Json::Value const& it: _json["sourceList"])
548+
for (Json::Value const& sourceName: _json["sourceList"])
549549
{
550550
solRequire(
551-
std::find(sourceList.begin(), sourceList.end(), it.asString()) == sourceList.end(),
551+
std::find(sourceList.begin(), sourceList.end(), sourceName.asString()) == sourceList.end(),
552552
AssemblyImportException,
553553
"Items in 'sourceList' array are not unique."
554554
);
555-
sourceList.emplace_back(it.asString());
555+
sourceList.emplace_back(sourceName.asString());
556556
}
557557
}
558558
else
@@ -574,22 +574,22 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
574574
{
575575
solRequire(dataIter.key().isString(), AssemblyImportException, "Key inside '.data' is not a string.");
576576
std::string dataItemID = dataIter.key().asString();
577-
Json::Value const& code = data[dataItemID];
578-
if (code.isString())
577+
Json::Value const& dataItem = data[dataItemID];
578+
if (dataItem.isString())
579579
{
580580
solRequire(
581-
code.asString().empty() || !fromHex(code.asString()).empty(),
581+
dataItem.asString().empty() || !fromHex(dataItem.asString()).empty(),
582582
AssemblyImportException,
583583
"Member '.data' contains a value for '" + dataItemID + "' that is not a valid hexadecimal string."
584584
);
585-
result->m_data[h256(fromHex(dataItemID))] = fromHex(code.asString());
585+
result->m_data[h256(fromHex(dataItemID))] = fromHex(dataItem.asString());
586586
}
587-
else if (code.isObject())
587+
else if (dataItem.isObject())
588588
{
589589
size_t index = static_cast<size_t>(std::stoi(dataItemID));
590590
if (result->m_subs.size() <= index)
591591
result->m_subs.resize(index + 1);
592-
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(code, sourceList, _level + 1).first);
592+
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);
593593
solAssert(subassembly);
594594
result->m_subs[index] = subassembly;
595595
}

0 commit comments

Comments
 (0)