aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-12-15 00:23:14 +0800
committerGitHub <noreply@github.com>2016-12-15 00:23:14 +0800
commitf8fe6e4f7c1f71756699ca31ce39cad2efd74557 (patch)
tree545e7daf406f87f830d0e4e075fa9ac22454cc30 /libsolidity/ast
parente97ba77a45b871e7404d8ff5b6432b2f7090dc61 (diff)
parent9ed65f2ab9d5d6e67e07219006434356ce5c64ee (diff)
downloaddexon-solidity-f8fe6e4f7c1f71756699ca31ce39cad2efd74557.tar.gz
dexon-solidity-f8fe6e4f7c1f71756699ca31ce39cad2efd74557.tar.zst
dexon-solidity-f8fe6e4f7c1f71756699ca31ce39cad2efd74557.zip
Merge pull request #1503 from federicobond/json-visibility
Include visibility level for functions in AST
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp28
-rw-r--r--libsolidity/ast/ASTJsonConverter.h1
2 files changed, 22 insertions, 7 deletions
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index 493707b9..abaad0fd 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -24,6 +24,7 @@
#include <boost/algorithm/string/join.hpp>
#include <libdevcore/UTF8.h>
#include <libsolidity/ast/AST.h>
+#include <libsolidity/interface/Exceptions.h>
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 277476d5..49f23f99 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()