diff options
author | chriseth <chris@ethereum.org> | 2016-08-19 18:55:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-19 18:55:24 +0800 |
commit | 64cec9793a881e5a8ee77cb73e3f3599f330c044 (patch) | |
tree | 2214dd854ec91e19834b162f4586211dab30f1eb /libsolidity/ast | |
parent | 32c93cf9c9fca4ea1331d1a089bc492f47122ce2 (diff) | |
parent | 4b9eb299d023989873528e6e52fdc8925d3fcda9 (diff) | |
download | dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.tar dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.tar.gz dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.tar.bz2 dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.tar.lz dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.tar.xz dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.tar.zst dexon-solidity-64cec9793a881e5a8ee77cb73e3f3599f330c044.zip |
Merge pull request #919 from asinyagin/develop
Add the missing AST-JSON converters
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/ASTJsonConverter.cpp | 128 | ||||
-rw-r--r-- | libsolidity/ast/ASTJsonConverter.h | 20 |
2 files changed, 138 insertions, 10 deletions
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index c4134f4e..d23c4890 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -89,11 +89,6 @@ ASTJsonConverter::ASTJsonConverter( map<string, unsigned> _sourceIndices ): m_ast(&_ast), m_sourceIndices(_sourceIndices) { - Json::Value children(Json::arrayValue); - - m_astJson["name"] = "root"; - m_astJson["children"] = children; - m_jsonNodePtrs.push(&m_astJson["children"]); } void ASTJsonConverter::print(ostream& _stream) @@ -108,21 +103,56 @@ Json::Value const& ASTJsonConverter::json() return m_astJson; } +bool ASTJsonConverter::visit(SourceUnit const&) +{ + Json::Value children(Json::arrayValue); + + m_astJson["name"] = "SourceUnit"; + m_astJson["children"] = children; + m_jsonNodePtrs.push(&m_astJson["children"]); + + return true; +} + 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, "InheritanceSpecifier", {}, true); + return true; +} + +bool ASTJsonConverter::visit(UsingForDirective const& _node) +{ + 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, "EnumDefinition", { make_pair("name", _node.name()) }, true); + return true; +} + +bool ASTJsonConverter::visit(EnumValue const& _node) +{ + addJsonNode(_node, "EnumValue", { make_pair("name", _node.name()) }); return true; } @@ -134,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())) }, @@ -151,11 +181,29 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node) return true; } +bool ASTJsonConverter::visit(ModifierDefinition const& _node) +{ + addJsonNode(_node, "ModifierDefinition", { make_pair("name", _node.name()) }, true); + return true; +} + +bool ASTJsonConverter::visit(ModifierInvocation const& _node) +{ + addJsonNode(_node, "ModifierInvocation", {}, true); + return true; +} + bool ASTJsonConverter::visit(TypeName const&) { return true; } +bool ASTJsonConverter::visit(EventDefinition const& _node) +{ + addJsonNode(_node, "EventDefinition", { make_pair("name", _node.name()) }, true); + return true; +} + bool ASTJsonConverter::visit(ElementaryTypeName const& _node) { addJsonNode(_node, "ElementaryTypeName", { make_pair("name", _node.typeName().toString()) }); @@ -176,6 +224,12 @@ bool ASTJsonConverter::visit(Mapping const& _node) return true; } +bool ASTJsonConverter::visit(ArrayTypeName const& _node) +{ + addJsonNode(_node, "ArrayTypeName", {}, true); + return true; +} + bool ASTJsonConverter::visit(InlineAssembly const& _node) { addJsonNode(_node, "InlineAssembly", {}, true); @@ -188,6 +242,12 @@ bool ASTJsonConverter::visit(Block const& _node) return true; } +bool ASTJsonConverter::visit(PlaceholderStatement const& _node) +{ + addJsonNode(_node, "PlaceholderStatement", {}); + return true; +} + bool ASTJsonConverter::visit(IfStatement const& _node) { addJsonNode(_node, "IfStatement", {}, true); @@ -232,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; } @@ -336,6 +396,11 @@ bool ASTJsonConverter::visit(Literal const& _node) return true; } +void ASTJsonConverter::endVisit(SourceUnit const&) +{ + goUp(); +} + void ASTJsonConverter::endVisit(ImportDirective const&) { } @@ -345,11 +410,30 @@ void ASTJsonConverter::endVisit(ContractDefinition const&) goUp(); } +void ASTJsonConverter::endVisit(InheritanceSpecifier const&) +{ + goUp(); +} + +void ASTJsonConverter::endVisit(UsingForDirective const&) +{ + goUp(); +} + void ASTJsonConverter::endVisit(StructDefinition const&) { goUp(); } +void ASTJsonConverter::endVisit(EnumDefinition const&) +{ + goUp(); +} + +void ASTJsonConverter::endVisit(EnumValue const&) +{ +} + void ASTJsonConverter::endVisit(ParameterList const&) { goUp(); @@ -365,6 +449,21 @@ void ASTJsonConverter::endVisit(VariableDeclaration const&) goUp(); } +void ASTJsonConverter::endVisit(ModifierDefinition const&) +{ + goUp(); +} + +void ASTJsonConverter::endVisit(ModifierInvocation const&) +{ + goUp(); +} + +void ASTJsonConverter::endVisit(EventDefinition const&) +{ + goUp(); +} + void ASTJsonConverter::endVisit(TypeName const&) { } @@ -382,6 +481,11 @@ void ASTJsonConverter::endVisit(Mapping const&) goUp(); } +void ASTJsonConverter::endVisit(ArrayTypeName const&) +{ + goUp(); +} + void ASTJsonConverter::endVisit(InlineAssembly const&) { goUp(); @@ -392,6 +496,10 @@ void ASTJsonConverter::endVisit(Block const&) goUp(); } +void ASTJsonConverter::endVisit(PlaceholderStatement const&) +{ +} + void ASTJsonConverter::endVisit(IfStatement const&) { goUp(); diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index ca4d9c2d..192c4c4f 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -51,18 +51,28 @@ public: void print(std::ostream& _stream); Json::Value const& json(); + bool visit(SourceUnit const& _node) override; bool visit(ImportDirective const& _node) override; bool visit(ContractDefinition const& _node) override; + 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(EnumValue const& _node) override; bool visit(ParameterList const& _node) override; 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; bool visit(Mapping const& _node) override; + bool visit(ArrayTypeName const& _node) override; bool visit(InlineAssembly const& _node) override; bool visit(Block const& _node) override; + bool visit(PlaceholderStatement const& _node) override; bool visit(IfStatement const& _node) override; bool visit(WhileStatement const& _node) override; bool visit(ForStatement const& _node) override; @@ -85,18 +95,28 @@ public: bool visit(ElementaryTypeNameExpression const& _node) override; bool visit(Literal const& _node) override; + void endVisit(SourceUnit const&) override; void endVisit(ImportDirective const&) override; void endVisit(ContractDefinition const&) override; + void endVisit(InheritanceSpecifier const&) override; + 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; + 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; void endVisit(Mapping const&) override; + void endVisit(ArrayTypeName const&) override; void endVisit(InlineAssembly const&) override; void endVisit(Block const&) override; + void endVisit(PlaceholderStatement const&) override; void endVisit(IfStatement const&) override; void endVisit(WhileStatement const&) override; void endVisit(ForStatement const&) override; |