Skip to content

Commit 638ed4f

Browse files
cameelr0qs
authored andcommitted
fixup! [libevmasm] Add support to import evm assembly json.
1 parent e293bca commit 638ed4f

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
}
@@ -526,8 +526,8 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
526526
if (_json.isMember("sourceList"))
527527
{
528528
solRequire(_json["sourceList"].isArray(), AssemblyImportException, "Optional member 'sourceList' is not an array.");
529-
for (Json::Value const& sourceListItem: _json["sourceList"])
530-
solRequire(sourceListItem.isString(), AssemblyImportException, "The 'sourceList' array contains an item that is not a string.");
529+
for (Json::Value const& sourceName: _json["sourceList"])
530+
solRequire(sourceName.isString(), AssemblyImportException, "The 'sourceList' array contains an item that is not a string.");
531531
}
532532
}
533533
else
@@ -542,14 +542,14 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
542542
if (_json.isMember("sourceList"))
543543
{
544544
solAssert(_level == 0);
545-
for (Json::Value const& it: _json["sourceList"])
545+
for (Json::Value const& sourceName: _json["sourceList"])
546546
{
547547
solRequire(
548-
std::find(sourceList.begin(), sourceList.end(), it.asString()) == sourceList.end(),
548+
std::find(sourceList.begin(), sourceList.end(), sourceName.asString()) == sourceList.end(),
549549
AssemblyImportException,
550550
"Items in 'sourceList' array are not unique."
551551
);
552-
sourceList.emplace_back(it.asString());
552+
sourceList.emplace_back(sourceName.asString());
553553
}
554554
}
555555
else
@@ -571,22 +571,22 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
571571
{
572572
solRequire(dataIter.key().isString(), AssemblyImportException, "Key inside '.data' is not a string.");
573573
std::string dataItemID = dataIter.key().asString();
574-
Json::Value const& code = data[dataItemID];
575-
if (code.isString())
574+
Json::Value const& dataItem = data[dataItemID];
575+
if (dataItem.isString())
576576
{
577577
solRequire(
578-
code.asString().empty() || !fromHex(code.asString()).empty(),
578+
dataItem.asString().empty() || !fromHex(dataItem.asString()).empty(),
579579
AssemblyImportException,
580580
"The value for key '" + dataItemID + "' inside '.data' is not a valid hexadecimal string."
581581
);
582-
result->m_data[h256(fromHex(dataItemID))] = fromHex(code.asString());
582+
result->m_data[h256(fromHex(dataItemID))] = fromHex(dataItem.asString());
583583
}
584-
else if (code.isObject())
584+
else if (dataItem.isObject())
585585
{
586586
size_t index = static_cast<size_t>(std::stoi(dataItemID));
587587
if (result->m_subs.size() <= index)
588588
result->m_subs.resize(index + 1);
589-
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(code, sourceList, _level + 1).first);
589+
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);
590590
solAssert(subassembly);
591591
result->m_subs[index] = subassembly;
592592
}

0 commit comments

Comments
 (0)