mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add ast json converter for EnumValue
This commit is contained in:
parent
a9e04217a4
commit
95832da16e
@ -144,6 +144,12 @@ bool ASTJsonConverter::visit(EnumDefinition const& _node)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(EnumValue const& _node)
|
||||
{
|
||||
addJsonNode(_node, "EnumValue", { make_pair("name", _node.name()) }, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(ParameterList const& _node)
|
||||
{
|
||||
addJsonNode(_node, "ParameterList", {}, true);
|
||||
@ -383,6 +389,11 @@ void ASTJsonConverter::endVisit(EnumDefinition const&)
|
||||
goUp();
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(EnumValue const&)
|
||||
{
|
||||
goUp();
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(ParameterList const&)
|
||||
{
|
||||
goUp();
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
bool visit(UsingForDirective const& _node) override;
|
||||
bool visit(StructDefinition const& _node) override;
|
||||
bool visit(EnumDefinition const& _node) override;
|
||||
bool visit(EnumValue const& _node) override;
|
||||
bool visit(ParameterList const& _node) override;
|
||||
bool visit(FunctionDefinition const& _node) override;
|
||||
bool visit(VariableDeclaration const& _node) override;
|
||||
@ -94,6 +95,7 @@ public:
|
||||
void endVisit(UsingForDirective const&) override;
|
||||
void endVisit(StructDefinition const&) override;
|
||||
void endVisit(EnumDefinition const&) override;
|
||||
void endVisit(EnumValue const&) override;
|
||||
void endVisit(ParameterList const&) override;
|
||||
void endVisit(FunctionDefinition const&) override;
|
||||
void endVisit(VariableDeclaration const&) override;
|
||||
|
@ -108,6 +108,23 @@ BOOST_AUTO_TEST_CASE(enum_definition)
|
||||
BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(enum_value)
|
||||
{
|
||||
CompilerStack c;
|
||||
c.addSource("a", "contract C { enum E { A, B } }");
|
||||
c.parse();
|
||||
map<string, unsigned> sourceIndices;
|
||||
sourceIndices["a"] = 1;
|
||||
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
|
||||
Json::Value enumDefinition = astJson["children"][0]["children"][0];
|
||||
BOOST_CHECK_EQUAL(enumDefinition["children"][0]["name"], "EnumValue");
|
||||
BOOST_CHECK_EQUAL(enumDefinition["children"][0]["attributes"]["name"], "A");
|
||||
BOOST_CHECK_EQUAL(enumDefinition["children"][0]["src"], "22:1:1");
|
||||
BOOST_CHECK_EQUAL(enumDefinition["children"][1]["name"], "EnumValue");
|
||||
BOOST_CHECK_EQUAL(enumDefinition["children"][1]["attributes"]["name"], "B");
|
||||
BOOST_CHECK_EQUAL(enumDefinition["children"][1]["src"], "25:1:1");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user