diff options
author | Alex Sinyagin <sinyagin.alexander@gmail.com> | 2016-08-17 22:52:14 +0800 |
---|---|---|
committer | Alex Sinyagin <sinyagin.alexander@gmail.com> | 2016-08-18 20:30:00 +0800 |
commit | bdc2436ae38b9028311736ef52f36e3525227eb6 (patch) | |
tree | b2f4a7b26c15c6cdcdaa94ed8df2e7217e9fac87 | |
parent | a5d15e6895212a034f459ba06fe0ca62ba5c0904 (diff) | |
download | dexon-solidity-bdc2436ae38b9028311736ef52f36e3525227eb6.tar.gz dexon-solidity-bdc2436ae38b9028311736ef52f36e3525227eb6.tar.zst dexon-solidity-bdc2436ae38b9028311736ef52f36e3525227eb6.zip |
Add ast json converter for ModifierInvocation and EventDefinition
-rw-r--r-- | libsolidity/ast/ASTJsonConverter.cpp | 22 | ||||
-rw-r--r-- | libsolidity/ast/ASTJsonConverter.h | 4 | ||||
-rw-r--r-- | test/libsolidity/ASTJSON.cpp | 30 |
3 files changed, 56 insertions, 0 deletions
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index bcf2577a..b8d5f43e 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -181,11 +181,23 @@ bool ASTJsonConverter::visit(ModifierDefinition const& _node) return true; } +bool ASTJsonConverter::visit(ModifierInvocation const& _node) +{ + addJsonNode(_node, "Modifier", {}, true); + return true; +} + bool ASTJsonConverter::visit(TypeName const&) { return true; } +bool ASTJsonConverter::visit(EventDefinition const& _node) +{ + addJsonNode(_node, "Event", { make_pair("name", _node.name()) }, true); + return true; +} + bool ASTJsonConverter::visit(ElementaryTypeName const& _node) { addJsonNode(_node, "ElementaryTypeName", { make_pair("name", _node.typeName().toString()) }); @@ -420,6 +432,16 @@ void ASTJsonConverter::endVisit(ModifierDefinition const&) goUp(); } +void ASTJsonConverter::endVisit(ModifierInvocation const&) +{ + goUp(); +} + +void ASTJsonConverter::endVisit(EventDefinition const&) +{ + goUp(); +} + void ASTJsonConverter::endVisit(TypeName const&) { } diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index 7808d76f..e26bab75 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -62,6 +62,8 @@ public: bool visit(FunctionDefinition const& _node) override; bool visit(VariableDeclaration const& _node) override; bool visit(ModifierDefinition const& _node) override; + bool visit(ModifierInvocation const& _node) override; + bool visit(EventDefinition const& _node) override; bool visit(TypeName const& _node) override; bool visit(ElementaryTypeName const& _node) override; bool visit(UserDefinedTypeName const& _node) override; @@ -101,6 +103,8 @@ public: void endVisit(FunctionDefinition const&) override; void endVisit(VariableDeclaration const&) override; void endVisit(ModifierDefinition const&) override; + void endVisit(ModifierInvocation const&) override; + void endVisit(EventDefinition const&) override; void endVisit(TypeName const&) override; void endVisit(ElementaryTypeName const&) override; void endVisit(UserDefinedTypeName const&) override; diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 04733055..69c42814 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -139,6 +139,36 @@ BOOST_AUTO_TEST_CASE(modifier_definition) BOOST_CHECK_EQUAL(modifier["src"], "13:24:1"); } +BOOST_AUTO_TEST_CASE(modifier_invocation) +{ + CompilerStack c; + c.addSource("a", "contract C { modifier M(uint i) { _ } function F() M(1) {} }"); + c.parse(); + map<string, unsigned> sourceIndices; + 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["src"], "51:4:1"); + BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["type"], "modifier (uint256)"); + BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["value"], "M"); + BOOST_CHECK_EQUAL(modifier["children"][1]["attributes"]["value"], "1"); +} + +BOOST_AUTO_TEST_CASE(event_definition) +{ + CompilerStack c; + c.addSource("a", "contract C { event E(); }"); + c.parse(); + map<string, unsigned> sourceIndices; + 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["attributes"]["name"], "E"); + BOOST_CHECK_EQUAL(event["src"], "13:10:1"); +} + BOOST_AUTO_TEST_SUITE_END() } |