Add a ast json converter for InheritanceSpecifier

This commit is contained in:
Alex Sinyagin 2016-08-16 13:25:25 +00:00
parent c282ab379a
commit 9e7fc12463
3 changed files with 27 additions and 0 deletions

View File

@ -120,6 +120,12 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
return true;
}
bool ASTJsonConverter::visit(InheritanceSpecifier const& _node)
{
addJsonNode(_node, "Inheritance", { }, true);
return true;
}
bool ASTJsonConverter::visit(StructDefinition const& _node)
{
addJsonNode(_node, "Struct", { make_pair("name", _node.name()) }, true);
@ -345,6 +351,11 @@ void ASTJsonConverter::endVisit(ContractDefinition const&)
goUp();
}
void ASTJsonConverter::endVisit(InheritanceSpecifier const&)
{
goUp();
}
void ASTJsonConverter::endVisit(StructDefinition const&)
{
goUp();

View File

@ -53,6 +53,7 @@ public:
bool visit(ImportDirective const& _node) override;
bool visit(ContractDefinition const& _node) override;
bool visit(InheritanceSpecifier const& _node) override;
bool visit(StructDefinition const& _node) override;
bool visit(ParameterList const& _node) override;
bool visit(FunctionDefinition const& _node) override;
@ -87,6 +88,7 @@ public:
void endVisit(ImportDirective const&) override;
void endVisit(ContractDefinition const&) override;
void endVisit(InheritanceSpecifier const&) override;
void endVisit(StructDefinition const&) override;
void endVisit(ParameterList const&) override;
void endVisit(FunctionDefinition const&) override;

View File

@ -62,6 +62,20 @@ BOOST_AUTO_TEST_CASE(source_location)
BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["src"], "13:32:1");
}
BOOST_AUTO_TEST_CASE(inheritance_specifier)
{
CompilerStack c;
c.addSource("a", "contract C1 {} contract C2 is C1 {}");
c.parse();
map<string, unsigned> sourceIndices;
sourceIndices["a"] = 1;
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
BOOST_CHECK_EQUAL(astJson["children"][1]["attributes"]["name"], "C2");
BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["name"], "Inheritance");
BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["name"], "UserDefinedTypeName");
BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["attributes"]["name"], "C1");
}
BOOST_AUTO_TEST_SUITE_END()
}