2015-01-05 14:46:40 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2015-01-05 14:46:40 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2015-01-05 14:46:40 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2015-01-05 14:46:40 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Lefteris <lefteris@ethdev.com>
|
|
|
|
* @date 2015
|
|
|
|
* Converts the AST into json format
|
|
|
|
*/
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/ASTJsonConverter.h>
|
2015-10-06 10:35:10 +00:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2016-09-01 22:21:39 +00:00
|
|
|
#include <libdevcore/UTF8.h>
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/AST.h>
|
2016-12-12 19:21:57 +00:00
|
|
|
#include <libsolidity/interface/Exceptions.h>
|
2015-01-05 14:46:40 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
void ASTJsonConverter::addJsonNode(
|
|
|
|
ASTNode const& _node,
|
|
|
|
string const& _nodeName,
|
2016-08-17 17:07:44 +00:00
|
|
|
initializer_list<pair<string const, Json::Value const>> _attributes,
|
2016-07-01 08:14:50 +00:00
|
|
|
bool _hasChildren = false
|
|
|
|
)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
|
|
|
Json::Value node;
|
|
|
|
|
2017-01-17 09:31:09 +00:00
|
|
|
node["id"] = _node.id();
|
2016-07-01 08:14:50 +00:00
|
|
|
node["src"] = sourceLocationToString(_node.location());
|
2015-01-15 15:54:59 +00:00
|
|
|
node["name"] = _nodeName;
|
2016-08-17 17:07:44 +00:00
|
|
|
if (_attributes.size() != 0)
|
2015-01-15 15:54:59 +00:00
|
|
|
{
|
|
|
|
Json::Value attrs;
|
2016-08-17 17:07:44 +00:00
|
|
|
for (auto& e: _attributes)
|
|
|
|
attrs[e.first] = e.second;
|
2015-01-15 15:54:59 +00:00
|
|
|
node["attributes"] = attrs;
|
|
|
|
}
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2015-01-16 10:44:55 +00:00
|
|
|
m_jsonNodePtrs.top()->append(node);
|
2015-01-06 15:50:04 +00:00
|
|
|
|
2015-01-15 15:54:59 +00:00
|
|
|
if (_hasChildren)
|
|
|
|
{
|
|
|
|
Json::Value& addedNode = (*m_jsonNodePtrs.top())[m_jsonNodePtrs.top()->size() - 1];
|
2015-01-06 15:50:04 +00:00
|
|
|
Json::Value children(Json::arrayValue);
|
2015-01-15 15:54:59 +00:00
|
|
|
addedNode["children"] = children;
|
|
|
|
m_jsonNodePtrs.push(&addedNode["children"]);
|
2015-01-06 15:50:04 +00:00
|
|
|
}
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
string ASTJsonConverter::sourceLocationToString(SourceLocation const& _location) const
|
|
|
|
{
|
|
|
|
int sourceIndex{-1};
|
|
|
|
if (_location.sourceName && m_sourceIndices.count(*_location.sourceName))
|
|
|
|
sourceIndex = m_sourceIndices.at(*_location.sourceName);
|
|
|
|
int length = -1;
|
|
|
|
if (_location.start >= 0 && _location.end >= 0)
|
|
|
|
length = _location.end - _location.start;
|
|
|
|
return std::to_string(_location.start) + ":" + std::to_string(length) + ":" + std::to_string(sourceIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTJsonConverter::ASTJsonConverter(
|
|
|
|
ASTNode const& _ast,
|
2016-08-01 22:57:58 +00:00
|
|
|
map<string, unsigned> _sourceIndices
|
2016-07-01 08:14:50 +00:00
|
|
|
): m_ast(&_ast), m_sourceIndices(_sourceIndices)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::print(ostream& _stream)
|
|
|
|
{
|
2015-01-28 07:50:53 +00:00
|
|
|
process();
|
2015-01-05 14:46:40 +00:00
|
|
|
_stream << m_astJson;
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:50:53 +00:00
|
|
|
Json::Value const& ASTJsonConverter::json()
|
|
|
|
{
|
|
|
|
process();
|
|
|
|
return m_astJson;
|
|
|
|
}
|
|
|
|
|
2016-08-18 12:51:17 +00:00
|
|
|
bool ASTJsonConverter::visit(SourceUnit const&)
|
|
|
|
{
|
|
|
|
Json::Value children(Json::arrayValue);
|
|
|
|
|
2016-08-18 15:38:20 +00:00
|
|
|
m_astJson["name"] = "SourceUnit";
|
2016-08-18 12:51:17 +00:00
|
|
|
m_astJson["children"] = children;
|
|
|
|
m_jsonNodePtrs.push(&m_astJson["children"]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:57:21 +00:00
|
|
|
bool ASTJsonConverter::visit(PragmaDirective const& _node)
|
|
|
|
{
|
|
|
|
Json::Value literals(Json::arrayValue);
|
|
|
|
for (auto const& literal: _node.literals())
|
|
|
|
literals.append(literal);
|
|
|
|
addJsonNode(_node, "PragmaDirective", { make_pair("literals", literals) });
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(ImportDirective const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "ImportDirective", { make_pair("file", _node.path())});
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(ContractDefinition const& _node)
|
|
|
|
{
|
2016-08-17 17:07:44 +00:00
|
|
|
Json::Value linearizedBaseContracts(Json::arrayValue);
|
|
|
|
for (auto const& baseContract: _node.annotation().linearizedBaseContracts)
|
2017-01-17 09:31:09 +00:00
|
|
|
linearizedBaseContracts.append(baseContract->id());
|
2016-08-17 17:07:44 +00:00
|
|
|
addJsonNode(_node, "ContractDefinition", {
|
|
|
|
make_pair("name", _node.name()),
|
|
|
|
make_pair("isLibrary", _node.isLibrary()),
|
|
|
|
make_pair("fullyImplemented", _node.annotation().isFullyImplemented),
|
|
|
|
make_pair("linearizedBaseContracts", linearizedBaseContracts),
|
|
|
|
}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 13:25:25 +00:00
|
|
|
bool ASTJsonConverter::visit(InheritanceSpecifier const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "InheritanceSpecifier", {}, true);
|
2016-08-16 14:28:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(UsingForDirective const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "UsingForDirective", {}, true);
|
2016-08-16 13:25:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(StructDefinition const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "StructDefinition", { make_pair("name", _node.name()) }, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 15:18:57 +00:00
|
|
|
bool ASTJsonConverter::visit(EnumDefinition const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "EnumDefinition", { make_pair("name", _node.name()) }, true);
|
2016-08-16 15:18:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 15:38:24 +00:00
|
|
|
bool ASTJsonConverter::visit(EnumValue const& _node)
|
|
|
|
{
|
2016-08-18 13:29:44 +00:00
|
|
|
addJsonNode(_node, "EnumValue", { make_pair("name", _node.name()) });
|
2016-08-16 15:38:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(ParameterList const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "ParameterList", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(FunctionDefinition const& _node)
|
|
|
|
{
|
2016-08-17 17:07:44 +00:00
|
|
|
addJsonNode(_node, "FunctionDefinition", {
|
|
|
|
make_pair("name", _node.name()),
|
2016-11-03 15:36:38 +00:00
|
|
|
make_pair("constant", _node.isDeclaredConst()),
|
2016-12-12 19:21:57 +00:00
|
|
|
make_pair("payable", _node.isPayable()),
|
|
|
|
make_pair("visibility", visibility(_node.visibility()))
|
2016-08-17 17:07:44 +00:00
|
|
|
}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(VariableDeclaration const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "VariableDeclaration", {
|
2015-09-24 10:12:31 +00:00
|
|
|
make_pair("name", _node.name()),
|
2016-08-17 17:07:44 +00:00
|
|
|
make_pair("type", type(_node))
|
2015-09-24 10:12:31 +00:00
|
|
|
}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:23:20 +00:00
|
|
|
bool ASTJsonConverter::visit(ModifierDefinition const& _node)
|
|
|
|
{
|
|
|
|
addJsonNode(_node, "ModifierDefinition", { make_pair("name", _node.name()) }, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-17 14:52:14 +00:00
|
|
|
bool ASTJsonConverter::visit(ModifierInvocation const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "ModifierInvocation", {}, true);
|
2016-08-17 14:52:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 15:54:59 +00:00
|
|
|
bool ASTJsonConverter::visit(TypeName const&)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:52:14 +00:00
|
|
|
bool ASTJsonConverter::visit(EventDefinition const& _node)
|
|
|
|
{
|
2016-08-18 13:12:15 +00:00
|
|
|
addJsonNode(_node, "EventDefinition", { make_pair("name", _node.name()) }, true);
|
2016-08-17 14:52:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(ElementaryTypeName const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "ElementaryTypeName", { make_pair("name", _node.typeName().toString()) });
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(UserDefinedTypeName const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "UserDefinedTypeName", {
|
2015-10-06 10:35:10 +00:00
|
|
|
make_pair("name", boost::algorithm::join(_node.namePath(), "."))
|
|
|
|
});
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 19:37:32 +00:00
|
|
|
bool ASTJsonConverter::visit(FunctionTypeName const& _node)
|
|
|
|
{
|
|
|
|
addJsonNode(_node, "FunctionTypeName", {
|
|
|
|
make_pair("payable", _node.isPayable()),
|
2016-12-12 19:21:57 +00:00
|
|
|
make_pair("visibility", visibility(_node.visibility())),
|
2016-09-27 19:37:32 +00:00
|
|
|
make_pair("constant", _node.isDeclaredConst())
|
2016-11-14 12:13:37 +00:00
|
|
|
}, true);
|
2016-09-27 19:37:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Mapping const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Mapping", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 15:09:21 +00:00
|
|
|
bool ASTJsonConverter::visit(ArrayTypeName const& _node)
|
|
|
|
{
|
|
|
|
addJsonNode(_node, "ArrayTypeName", {}, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(InlineAssembly const& _node)
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "InlineAssembly", {}, true);
|
2016-02-22 01:13:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Block const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Block", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 15:20:17 +00:00
|
|
|
bool ASTJsonConverter::visit(PlaceholderStatement const& _node)
|
|
|
|
{
|
2016-08-18 13:29:44 +00:00
|
|
|
addJsonNode(_node, "PlaceholderStatement", {});
|
2016-08-17 15:20:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(IfStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "IfStatement", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(WhileStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-30 07:13:05 +00:00
|
|
|
addJsonNode(
|
|
|
|
_node,
|
|
|
|
_node.isDoWhile() ? "DoWhileStatement" : "WhileStatement",
|
|
|
|
{},
|
|
|
|
true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(ForStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "ForStatement", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Continue const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Continue", {});
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Break const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Break", {});
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Return const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Return", {}, true);;
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Throw const& _node)
|
2015-09-15 14:33:14 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Throw", {}, true);;
|
2015-09-15 14:33:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-12-11 05:07:08 +00:00
|
|
|
addJsonNode(_node, "VariableDeclarationStatement", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(ExpressionStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "ExpressionStatement", {}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Conditional const& _node)
|
2015-12-22 16:47:00 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Conditional", {}, true);
|
2015-12-22 16:47:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(Assignment const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Assignment",
|
2015-08-31 16:44:29 +00:00
|
|
|
{ make_pair("operator", Token::toString(_node.assignmentOperator())),
|
2015-09-01 09:19:02 +00:00
|
|
|
make_pair("type", type(_node)) },
|
2015-01-15 15:54:59 +00:00
|
|
|
true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(TupleExpression const& _node)
|
2015-10-12 21:02:35 +00:00
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "TupleExpression",{}, true);
|
2015-10-12 21:02:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(UnaryOperation const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "UnaryOperation",
|
2016-08-17 17:07:44 +00:00
|
|
|
{ make_pair("prefix", _node.isPrefixOperation()),
|
2015-01-15 15:54:59 +00:00
|
|
|
make_pair("operator", Token::toString(_node.getOperator())),
|
2015-09-01 09:19:02 +00:00
|
|
|
make_pair("type", type(_node)) },
|
2015-01-06 15:50:04 +00:00
|
|
|
true);
|
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(BinaryOperation const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "BinaryOperation", {
|
2015-09-16 14:56:30 +00:00
|
|
|
make_pair("operator", Token::toString(_node.getOperator())),
|
|
|
|
make_pair("type", type(_node))
|
|
|
|
}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(FunctionCall const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "FunctionCall", {
|
2016-08-17 17:07:44 +00:00
|
|
|
make_pair("type_conversion", _node.annotation().isTypeConversion),
|
2015-09-16 14:56:30 +00:00
|
|
|
make_pair("type", type(_node))
|
|
|
|
}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(NewExpression const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "NewExpression", { make_pair("type", type(_node)) }, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(MemberAccess const& _node)
|
|
|
|
{
|
2016-08-17 17:07:44 +00:00
|
|
|
addJsonNode(_node, "MemberAccess", {
|
|
|
|
make_pair("member_name", _node.memberName()),
|
|
|
|
make_pair("type", type(_node))
|
|
|
|
}, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(IndexAccess const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "IndexAccess", { make_pair("type", type(_node)) }, true);
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(Identifier const& _node)
|
|
|
|
{
|
2016-07-01 08:14:50 +00:00
|
|
|
addJsonNode(_node, "Identifier",
|
2015-09-01 09:19:02 +00:00
|
|
|
{ make_pair("value", _node.name()), make_pair("type", type(_node)) });
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
|
|
|
|
{
|
2016-12-11 05:07:08 +00:00
|
|
|
addJsonNode(_node, "ElementaryTypeNameExpression", {
|
2016-08-17 17:07:44 +00:00
|
|
|
make_pair("value", _node.typeName().toString()),
|
|
|
|
make_pair("type", type(_node))
|
|
|
|
});
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(Literal const& _node)
|
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
char const* tokenString = Token::toString(_node.token());
|
2016-09-01 22:21:39 +00:00
|
|
|
Json::Value value{_node.value()};
|
2016-11-28 22:07:55 +00:00
|
|
|
if (!dev::validateUTF8(_node.value()))
|
2016-09-01 22:21:39 +00:00
|
|
|
value = Json::nullValue;
|
|
|
|
Token::Value subdenomination = Token::Value(_node.subDenomination());
|
2016-08-17 17:07:44 +00:00
|
|
|
addJsonNode(_node, "Literal", {
|
2016-09-01 22:21:39 +00:00
|
|
|
make_pair("token", tokenString ? tokenString : Json::Value()),
|
|
|
|
make_pair("value", value),
|
|
|
|
make_pair("hexvalue", toHex(_node.value())),
|
|
|
|
make_pair(
|
|
|
|
"subdenomination",
|
|
|
|
subdenomination == Token::Illegal ?
|
|
|
|
Json::nullValue :
|
|
|
|
Json::Value{Token::toString(subdenomination)}
|
|
|
|
),
|
2016-08-17 17:07:44 +00:00
|
|
|
make_pair("type", type(_node))
|
|
|
|
});
|
2015-01-06 15:50:04 +00:00
|
|
|
return true;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-18 12:51:17 +00:00
|
|
|
void ASTJsonConverter::endVisit(SourceUnit const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:57:21 +00:00
|
|
|
void ASTJsonConverter::endVisit(PragmaDirective const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(ImportDirective const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(ContractDefinition const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 13:25:25 +00:00
|
|
|
void ASTJsonConverter::endVisit(InheritanceSpecifier const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2016-08-16 14:28:28 +00:00
|
|
|
void ASTJsonConverter::endVisit(UsingForDirective const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(StructDefinition const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 15:18:57 +00:00
|
|
|
void ASTJsonConverter::endVisit(EnumDefinition const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2016-08-16 15:38:24 +00:00
|
|
|
void ASTJsonConverter::endVisit(EnumValue const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(ParameterList const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(FunctionDefinition const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(VariableDeclaration const&)
|
|
|
|
{
|
2016-08-10 13:04:12 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:23:20 +00:00
|
|
|
void ASTJsonConverter::endVisit(ModifierDefinition const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2016-08-17 14:52:14 +00:00
|
|
|
void ASTJsonConverter::endVisit(ModifierInvocation const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(EventDefinition const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(TypeName const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(ElementaryTypeName const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(UserDefinedTypeName const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:37:32 +00:00
|
|
|
void ASTJsonConverter::endVisit(FunctionTypeName const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(Mapping const&)
|
|
|
|
{
|
2016-08-11 16:48:43 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 15:09:21 +00:00
|
|
|
void ASTJsonConverter::endVisit(ArrayTypeName const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
void ASTJsonConverter::endVisit(InlineAssembly const&)
|
|
|
|
{
|
2016-08-11 16:48:43 +00:00
|
|
|
goUp();
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(Block const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 15:20:17 +00:00
|
|
|
void ASTJsonConverter::endVisit(PlaceholderStatement const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(IfStatement const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(WhileStatement const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(ForStatement const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(Continue const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(Break const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(Return const&)
|
|
|
|
{
|
2015-01-15 15:54:59 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 14:33:14 +00:00
|
|
|
void ASTJsonConverter::endVisit(Throw const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:21:38 +00:00
|
|
|
void ASTJsonConverter::endVisit(VariableDeclarationStatement const&)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(ExpressionStatement const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 16:47:00 +00:00
|
|
|
void ASTJsonConverter::endVisit(Conditional const&)
|
|
|
|
{
|
|
|
|
goUp();
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
void ASTJsonConverter::endVisit(Assignment const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-10-12 21:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(TupleExpression const&)
|
|
|
|
{
|
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(UnaryOperation const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(BinaryOperation const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(FunctionCall const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(NewExpression const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(MemberAccess const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(IndexAccess const&)
|
|
|
|
{
|
2015-01-06 15:50:04 +00:00
|
|
|
goUp();
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(Identifier const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(ElementaryTypeNameExpression const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(Literal const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:50:53 +00:00
|
|
|
void ASTJsonConverter::process()
|
|
|
|
{
|
|
|
|
if (!processed)
|
|
|
|
m_ast->accept(*this);
|
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
|
2016-12-12 19:21:57 +00:00
|
|
|
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."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 09:19:02 +00:00
|
|
|
string ASTJsonConverter::type(Expression const& _expression)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2015-09-16 14:56:30 +00:00
|
|
|
return _expression.annotation().type ? _expression.annotation().type->toString() : "Unknown";
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 10:12:31 +00:00
|
|
|
string ASTJsonConverter::type(VariableDeclaration const& _varDecl)
|
|
|
|
{
|
|
|
|
return _varDecl.annotation().type ? _varDecl.annotation().type->toString() : "Unknown";
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
}
|