aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast/ASTJsonConverter.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-03-18 00:24:58 +0800
committerGitHub <noreply@github.com>2017-03-18 00:24:58 +0800
commitc37397c17871591bb897ca6f390a315f2ad0b030 (patch)
treea4a41525426b6077779c1a354a13525911a4fff4 /libsolidity/ast/ASTJsonConverter.cpp
parent248563bf514d8da69dc241af78d1301fa281796b (diff)
parent44a032992144222aa604e94c1a2b6a63f9f34b4d (diff)
downloaddexon-solidity-c37397c17871591bb897ca6f390a315f2ad0b030.tar.gz
dexon-solidity-c37397c17871591bb897ca6f390a315f2ad0b030.tar.zst
dexon-solidity-c37397c17871591bb897ca6f390a315f2ad0b030.zip
Merge pull request #1773 from ethereum/ASTEntry
Ast entry
Diffstat (limited to 'libsolidity/ast/ASTJsonConverter.cpp')
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp45
1 files changed, 42 insertions, 3 deletions
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index 69c10c8d..9ea23687 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -40,6 +40,21 @@ void ASTJsonConverter::addJsonNode(
bool _hasChildren = false
)
{
+ ASTJsonConverter::addJsonNode(
+ _node,
+ _nodeName,
+ std::vector<pair<string const, Json::Value const>>(_attributes),
+ _hasChildren
+ );
+}
+
+void ASTJsonConverter::addJsonNode(
+ ASTNode const& _node,
+ string const& _nodeName,
+ std::vector<pair<string const, Json::Value const>> const& _attributes,
+ bool _hasChildren = false
+)
+{
Json::Value node;
node["id"] = Json::UInt64(_node.id());
@@ -183,11 +198,18 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
bool ASTJsonConverter::visit(VariableDeclaration const& _node)
{
- addJsonNode(_node, "VariableDeclaration", {
+ std::vector<pair<string const, Json::Value const>> attributes = {
make_pair("name", _node.name()),
- make_pair("type", type(_node))
- }, true);
+ make_pair("type", type(_node)),
+ make_pair("constant", _node.isConstant()),
+ make_pair("storageLocation", location(_node.referenceLocation())),
+ make_pair("visibility", visibility(_node.visibility()))
+ };
+ if (m_inEvent)
+ attributes.push_back(make_pair("indexed", _node.isIndexed()));
+ addJsonNode(_node, "VariableDeclaration", attributes, true);
return true;
+
}
bool ASTJsonConverter::visit(ModifierDefinition const& _node)
@@ -209,6 +231,7 @@ bool ASTJsonConverter::visit(TypeName const&)
bool ASTJsonConverter::visit(EventDefinition const& _node)
{
+ m_inEvent = true;
addJsonNode(_node, "EventDefinition", { make_pair("name", _node.name()) }, true);
return true;
}
@@ -502,6 +525,7 @@ void ASTJsonConverter::endVisit(ModifierInvocation const&)
void ASTJsonConverter::endVisit(EventDefinition const&)
{
+ m_inEvent = false;
goUp();
}
@@ -670,6 +694,21 @@ string ASTJsonConverter::visibility(Declaration::Visibility const& _visibility)
}
}
+string ASTJsonConverter::location(VariableDeclaration::Location _location)
+{
+ switch (_location)
+ {
+ case VariableDeclaration::Location::Default:
+ return "default";
+ case VariableDeclaration::Location::Storage:
+ return "storage";
+ case VariableDeclaration::Location::Memory:
+ return "memory";
+ default:
+ BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown declaration location."));
+ }
+}
+
string ASTJsonConverter::type(Expression const& _expression)
{
return _expression.annotation().type ? _expression.annotation().type->toString() : "Unknown";