Add ast json converter for EnumDefinition

This commit is contained in:
Alex Sinyagin 2016-08-16 15:18:57 +00:00
parent af64219e17
commit a9e04217a4
3 changed files with 27 additions and 0 deletions

View File

@ -138,6 +138,12 @@ bool ASTJsonConverter::visit(StructDefinition const& _node)
return true;
}
bool ASTJsonConverter::visit(EnumDefinition const& _node)
{
addJsonNode(_node, "Enum", { make_pair("name", _node.name()) }, true);
return true;
}
bool ASTJsonConverter::visit(ParameterList const& _node)
{
addJsonNode(_node, "ParameterList", {}, true);
@ -372,6 +378,11 @@ void ASTJsonConverter::endVisit(StructDefinition const&)
goUp();
}
void ASTJsonConverter::endVisit(EnumDefinition const&)
{
goUp();
}
void ASTJsonConverter::endVisit(ParameterList const&)
{
goUp();

View File

@ -56,6 +56,7 @@ public:
bool visit(InheritanceSpecifier const& _node) override;
bool visit(UsingForDirective const& _node) override;
bool visit(StructDefinition const& _node) override;
bool visit(EnumDefinition const& _node) override;
bool visit(ParameterList const& _node) override;
bool visit(FunctionDefinition const& _node) override;
bool visit(VariableDeclaration const& _node) override;
@ -92,6 +93,7 @@ public:
void endVisit(InheritanceSpecifier const&) override;
void endVisit(UsingForDirective const&) override;
void endVisit(StructDefinition const&) override;
void endVisit(EnumDefinition const&) override;
void endVisit(ParameterList const&) override;
void endVisit(FunctionDefinition const&) override;
void endVisit(VariableDeclaration const&) override;

View File

@ -94,6 +94,20 @@ BOOST_AUTO_TEST_CASE(using_for_directive)
BOOST_CHECK_EQUAL(usingFor["children"][1]["attributes"]["name"], "uint");
}
BOOST_AUTO_TEST_CASE(enum_definition)
{
CompilerStack c;
c.addSource("a", "contract C { enum E {} }");
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["name"], "Enum");
BOOST_CHECK_EQUAL(enumDefinition["attributes"]["name"], "E");
BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1");
}
BOOST_AUTO_TEST_SUITE_END()
}