Skip to content

Commit

Permalink
Use the full names for JSON AST nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
asinyagin committed Aug 18, 2016
1 parent 5061eb2 commit 9139d76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions libsolidity/ast/ASTJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,37 +116,37 @@ bool ASTJsonConverter::visit(SourceUnit const&)

bool ASTJsonConverter::visit(ImportDirective const& _node)
{
addJsonNode(_node, "Import", { make_pair("file", _node.path())});
addJsonNode(_node, "ImportDirective", { make_pair("file", _node.path())});
return true;
}

bool ASTJsonConverter::visit(ContractDefinition const& _node)
{
addJsonNode(_node, "Contract", { make_pair("name", _node.name()) }, true);
addJsonNode(_node, "ContractDefinition", { make_pair("name", _node.name()) }, true);
return true;
}

bool ASTJsonConverter::visit(InheritanceSpecifier const& _node)
{
addJsonNode(_node, "Inheritance", {}, true);
addJsonNode(_node, "InheritanceSpecifier", {}, true);
return true;
}

bool ASTJsonConverter::visit(UsingForDirective const& _node)
{
addJsonNode(_node, "UsingFor", {}, true);
addJsonNode(_node, "UsingForDirective", {}, true);
return true;
}

bool ASTJsonConverter::visit(StructDefinition const& _node)
{
addJsonNode(_node, "Struct", { make_pair("name", _node.name()) }, true);
addJsonNode(_node, "StructDefinition", { make_pair("name", _node.name()) }, true);
return true;
}

bool ASTJsonConverter::visit(EnumDefinition const& _node)
{
addJsonNode(_node, "Enum", { make_pair("name", _node.name()) }, true);
addJsonNode(_node, "EnumDefinition", { make_pair("name", _node.name()) }, true);
return true;
}

Expand All @@ -164,7 +164,7 @@ bool ASTJsonConverter::visit(ParameterList const& _node)

bool ASTJsonConverter::visit(FunctionDefinition const& _node)
{
addJsonNode(_node, "Function",
addJsonNode(_node, "FunctionDefinition",
{ make_pair("name", _node.name()),
make_pair("public", boost::lexical_cast<std::string>(_node.isPublic())),
make_pair("const", boost::lexical_cast<std::string>(_node.isDeclaredConst())) },
Expand All @@ -189,7 +189,7 @@ bool ASTJsonConverter::visit(ModifierDefinition const& _node)

bool ASTJsonConverter::visit(ModifierInvocation const& _node)
{
addJsonNode(_node, "Modifier", {}, true);
addJsonNode(_node, "ModifierInvocation", {}, true);
return true;
}

Expand All @@ -200,7 +200,7 @@ bool ASTJsonConverter::visit(TypeName const&)

bool ASTJsonConverter::visit(EventDefinition const& _node)
{
addJsonNode(_node, "Event", { make_pair("name", _node.name()) }, true);
addJsonNode(_node, "EventDefinition", { make_pair("name", _node.name()) }, true);
return true;
}

Expand Down Expand Up @@ -244,7 +244,7 @@ bool ASTJsonConverter::visit(Block const& _node)

bool ASTJsonConverter::visit(PlaceholderStatement const& _node)
{
addJsonNode(_node, "Placeholder", {}, true);
addJsonNode(_node, "PlaceholderStatement", {}, true);
return true;
}

Expand Down Expand Up @@ -292,7 +292,7 @@ bool ASTJsonConverter::visit(Throw const& _node)

bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node)
{
addJsonNode(_node, "VariableDefinition", {}, true);
addJsonNode(_node, "VariableDefinitionStatement", {}, true);
return true;
}

Expand Down
16 changes: 8 additions & 8 deletions test/libsolidity/ASTJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ BOOST_AUTO_TEST_CASE(source_location)
sourceIndices["a"] = 1;
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
BOOST_CHECK_EQUAL(astJson["name"], "root");
BOOST_CHECK_EQUAL(astJson["children"][0]["name"], "Contract");
BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["name"], "Function");
BOOST_CHECK_EQUAL(astJson["children"][0]["name"], "ContractDefinition");
BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["name"], "FunctionDefinition");
BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["src"], "13:32:1");
}

Expand All @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(inheritance_specifier)
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]["name"], "InheritanceSpecifier");
BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["src"], "30:2:1");
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");
Expand All @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(using_for_directive)
sourceIndices["a"] = 1;
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
Json::Value usingFor = astJson["children"][1]["children"][0];
BOOST_CHECK_EQUAL(usingFor["name"], "UsingFor");
BOOST_CHECK_EQUAL(usingFor["name"], "UsingForDirective");
BOOST_CHECK_EQUAL(usingFor["src"], "26:17:1");
BOOST_CHECK_EQUAL(usingFor["children"][0]["name"], "UserDefinedTypeName");
BOOST_CHECK_EQUAL(usingFor["children"][0]["attributes"]["name"], "L");
Expand All @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(enum_definition)
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["name"], "EnumDefinition");
BOOST_CHECK_EQUAL(enumDefinition["attributes"]["name"], "E");
BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1");
}
Expand Down Expand Up @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(modifier_invocation)
sourceIndices["a"] = 1;
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
Json::Value modifier = astJson["children"][0]["children"][1]["children"][2];
BOOST_CHECK_EQUAL(modifier["name"], "Modifier");
BOOST_CHECK_EQUAL(modifier["name"], "ModifierInvocation");
BOOST_CHECK_EQUAL(modifier["src"], "51:4:1");
BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["type"], "modifier (uint256)");
BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["value"], "M");
Expand All @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(event_definition)
sourceIndices["a"] = 1;
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
Json::Value event = astJson["children"][0]["children"][0];
BOOST_CHECK_EQUAL(event["name"], "Event");
BOOST_CHECK_EQUAL(event["name"], "EventDefinition");
BOOST_CHECK_EQUAL(event["attributes"]["name"], "E");
BOOST_CHECK_EQUAL(event["src"], "13:10:1");
}
Expand All @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(placeholder_statement)
sourceIndices["a"] = 1;
Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
Json::Value placeholder = astJson["children"][0]["children"][0]["children"][1]["children"][0];
BOOST_CHECK_EQUAL(placeholder["name"], "Placeholder");
BOOST_CHECK_EQUAL(placeholder["name"], "PlaceholderStatement");
BOOST_CHECK_EQUAL(placeholder["src"], "26:1:1");
}

Expand Down

0 comments on commit 9139d76

Please sign in to comment.