mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[libevmasm] EVM Assembly JSON Import: add support for sub-object index.
This commit is contained in:
parent
2ffa8aa57a
commit
c5de882bbb
@ -508,7 +508,7 @@ Json::Value Assembly::assemblyJSON(std::vector<std::string> const& _sources, boo
|
||||
std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSON(Json::Value const& _json, vector<string> const& _sourceList, int _level)
|
||||
{
|
||||
solRequire(_json.isObject(), AssemblyImportException, "Supplied JSON is not an object.");
|
||||
static set<string> const validMembers{".code", ".data", ".auxdata", "sourceList"};
|
||||
static set<string> const validMembers{".code", ".data", ".auxdata", "sourceList", "index"};
|
||||
for (auto const& attribute: _json.getMemberNames())
|
||||
solRequire(validMembers.count(attribute), AssemblyImportException, "Unknown attribute '" + attribute + "'.");
|
||||
solRequire(_json.isMember(".code"), AssemblyImportException, "Member '.code' does not exist.");
|
||||
@ -580,9 +580,13 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
|
||||
}
|
||||
else if (code.isObject())
|
||||
{
|
||||
solAssert(code.isMember("index"));
|
||||
size_t index = static_cast<size_t>(code["index"].asInt());
|
||||
if (result->m_subs.size() <= index)
|
||||
result->m_subs.resize(index + 1);
|
||||
shared_ptr<Assembly> subassembly(Assembly::fromJSON(code, sourceList, _level + 1).first);
|
||||
solAssert(subassembly);
|
||||
result->m_subs.emplace_back(subassembly);
|
||||
result->m_subs[index] = subassembly;
|
||||
}
|
||||
else
|
||||
solThrow(AssemblyImportException, "Key inside '.data' '" + dataItemID + "' can only be a valid hex-string or an object.");
|
||||
|
@ -198,12 +198,12 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
||||
"{\"begin\":6,\"end\":8,\"name\":\"PUSHIMMUTABLE\",\"source\":1,\"value\":\"someImmutable\"},"
|
||||
"{\"begin\":6,\"end\":8,\"name\":\"PUSH [ErrorTag]\",\"source\":1},"
|
||||
"{\"begin\":6,\"end\":8,\"name\":\"INVALID\",\"source\":1}"
|
||||
"]},"
|
||||
"],\"index\":0},"
|
||||
"\"1\":{\".code\":["
|
||||
"{\"begin\":8,\"end\":18,\"name\":\"VERBATIM\",\"source\":2,\"value\":\"ffff\"},"
|
||||
"{\"begin\":8,\"end\":18,\"name\":\"VERBATIM\",\"source\":2,\"value\":\"74657374\"},"
|
||||
"{\"begin\":8,\"end\":18,\"name\":\"MSTORE\",\"source\":2}"
|
||||
"]},\"A6885B3731702DA62E8E4A8F584AC46A7F6822F4E2BA50FBA902F67B1588D23B\":\"01020304\"},\"sourceList\":[\"root.asm\",\"sub.asm\",\"verbatim.asm\"]}"
|
||||
"],\"index\":1},\"A6885B3731702DA62E8E4A8F584AC46A7F6822F4E2BA50FBA902F67B1588D23B\":\"01020304\"},\"sourceList\":[\"root.asm\",\"sub.asm\",\"verbatim.asm\"]}"
|
||||
};
|
||||
Json::Value jsonValue;
|
||||
BOOST_CHECK(util::jsonParseStrict(json, jsonValue));
|
||||
@ -388,7 +388,7 @@ BOOST_AUTO_TEST_CASE(immutable)
|
||||
"{\"begin\":6,\"end\":8,\"name\":\"PUSHIMMUTABLE\",\"source\":1,\"value\":\"someImmutable\"},"
|
||||
"{\"begin\":6,\"end\":8,\"name\":\"PUSHIMMUTABLE\",\"source\":1,\"value\":\"someOtherImmutable\"},"
|
||||
"{\"begin\":6,\"end\":8,\"name\":\"PUSHIMMUTABLE\",\"source\":1,\"value\":\"someImmutable\"}"
|
||||
"]}},\"sourceList\":[\"root.asm\",\"sub.asm\"]}"
|
||||
"],\"index\":0}},\"sourceList\":[\"root.asm\",\"sub.asm\"]}"
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user