Add ast json converter for EnumValue

This commit is contained in:
Alex Sinyagin 2016-08-16 15:38:24 +00:00
parent a9e04217a4
commit 95832da16e
3 changed files with 30 additions and 0 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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()
}