diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 493707b9c..abaad0fdf 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace std; @@ -173,9 +174,9 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node) { addJsonNode(_node, "FunctionDefinition", { make_pair("name", _node.name()), - make_pair("public", _node.isPublic()), make_pair("constant", _node.isDeclaredConst()), - make_pair("payable", _node.isPayable()) + make_pair("payable", _node.isPayable()), + make_pair("visibility", visibility(_node.visibility())) }, true); return true; } @@ -228,13 +229,9 @@ bool ASTJsonConverter::visit(UserDefinedTypeName const& _node) bool ASTJsonConverter::visit(FunctionTypeName const& _node) { - string visibility = "internal"; - if (_node.visibility() == Declaration::Visibility::External) - visibility = "external"; - addJsonNode(_node, "FunctionTypeName", { make_pair("payable", _node.isPayable()), - make_pair("visibility", visibility), + make_pair("visibility", visibility(_node.visibility())), make_pair("constant", _node.isDeclaredConst()) }, true); return true; @@ -656,6 +653,23 @@ void ASTJsonConverter::process() processed = true; } +string ASTJsonConverter::visibility(Declaration::Visibility const& _visibility) +{ + switch (_visibility) + { + case Declaration::Visibility::Private: + return "private"; + case Declaration::Visibility::Internal: + return "internal"; + case Declaration::Visibility::Public: + return "public"; + case Declaration::Visibility::External: + return "external"; + default: + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown declaration visibility.")); + } +} + string ASTJsonConverter::type(Expression const& _expression) { return _expression.annotation().type ? _expression.annotation().type->toString() : "Unknown"; diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index 277476d59..49f23f999 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -152,6 +152,7 @@ private: bool _hasChildren ); std::string sourceLocationToString(SourceLocation const& _location) const; + std::string visibility(Declaration::Visibility const& _visibility); std::string type(Expression const& _expression); std::string type(VariableDeclaration const& _varDecl); inline void goUp()