2015-01-05 14:46:40 +00:00
|
|
|
/*
|
2019-02-13 15:56:46 +00:00
|
|
|
This file is part of solidity.
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
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.
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
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.
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2015-01-05 14:46:40 +00:00
|
|
|
*/
|
|
|
|
/**
|
2017-07-27 14:40:01 +00:00
|
|
|
* @date 2017
|
2015-01-05 14:46:40 +00:00
|
|
|
* Converts the AST into json format
|
|
|
|
*/
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/ASTJsonConverter.h>
|
2018-12-17 14:33:15 +00:00
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/AST.h>
|
2019-10-15 10:38:12 +00:00
|
|
|
|
|
|
|
#include <libyul/AsmJsonConverter.h>
|
2018-11-23 10:18:57 +00:00
|
|
|
#include <libyul/AsmData.h>
|
|
|
|
#include <libyul/AsmPrinter.h>
|
2020-01-14 11:46:47 +00:00
|
|
|
#include <libyul/backends/evm/EVMDialect.h>
|
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/JSON.h>
|
|
|
|
#include <libsolutil/UTF8.h>
|
2019-10-15 10:38:12 +00:00
|
|
|
|
2018-12-17 14:33:15 +00:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2019-10-15 10:38:12 +00:00
|
|
|
#include <boost/range/algorithm/sort.hpp>
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2020-04-01 03:04:29 +00:00
|
|
|
#include <utility>
|
2019-08-19 14:26:14 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
using namespace std;
|
2019-12-11 16:31:36 +00:00
|
|
|
using namespace solidity::langutil;
|
2015-01-05 14:46:40 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
|
|
|
|
2017-03-20 18:06:17 +00:00
|
|
|
ASTJsonConverter::ASTJsonConverter(bool _legacy, map<string, unsigned> _sourceIndices):
|
|
|
|
m_legacy(_legacy),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_sourceIndices(std::move(_sourceIndices))
|
2017-03-20 18:06:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTJsonConverter::setJsonNode(
|
2016-07-01 08:14:50 +00:00
|
|
|
ASTNode const& _node,
|
|
|
|
string const& _nodeName,
|
2017-03-20 18:06:17 +00:00
|
|
|
initializer_list<pair<string, Json::Value>>&& _attributes
|
2016-07-01 08:14:50 +00:00
|
|
|
)
|
2017-03-13 14:19:41 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
ASTJsonConverter::setJsonNode(
|
2017-03-13 14:19:41 +00:00
|
|
|
_node,
|
|
|
|
_nodeName,
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>>(std::move(_attributes))
|
2017-03-13 14:19:41 +00:00
|
|
|
);
|
|
|
|
}
|
2017-03-20 18:06:17 +00:00
|
|
|
|
|
|
|
void ASTJsonConverter::setJsonNode(
|
2017-03-13 14:19:41 +00:00
|
|
|
ASTNode const& _node,
|
2017-03-20 18:06:17 +00:00
|
|
|
string const& _nodeType,
|
|
|
|
std::vector<pair<string, Json::Value>>&& _attributes
|
2017-03-13 14:19:41 +00:00
|
|
|
)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
m_currentValue = Json::objectValue;
|
|
|
|
m_currentValue["id"] = nodeId(_node);
|
|
|
|
m_currentValue["src"] = sourceLocationToString(_node.location());
|
|
|
|
if (!m_legacy)
|
2015-01-15 15:54:59 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
m_currentValue["nodeType"] = _nodeType;
|
2016-08-17 17:07:44 +00:00
|
|
|
for (auto& e: _attributes)
|
2017-03-20 18:06:17 +00:00
|
|
|
m_currentValue[e.first] = std::move(e.second);
|
2015-01-15 15:54:59 +00:00
|
|
|
}
|
2017-03-20 18:06:17 +00:00
|
|
|
else
|
2015-01-15 15:54:59 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
m_currentValue["name"] = _nodeType;
|
|
|
|
Json::Value attrs(Json::objectValue);
|
|
|
|
if (
|
|
|
|
//these nodeTypes need to have a children-node even if it is empty
|
|
|
|
(_nodeType == "VariableDeclaration") ||
|
|
|
|
(_nodeType == "ParameterList") ||
|
|
|
|
(_nodeType == "Block") ||
|
|
|
|
(_nodeType == "InlineAssembly") ||
|
|
|
|
(_nodeType == "Throw")
|
|
|
|
)
|
2017-07-27 14:40:01 +00:00
|
|
|
m_currentValue["children"] = Json::arrayValue;
|
2017-03-20 18:06:17 +00:00
|
|
|
|
|
|
|
for (auto& e: _attributes)
|
|
|
|
{
|
2017-07-27 14:40:01 +00:00
|
|
|
if ((!e.second.isNull()) && (
|
|
|
|
(e.second.isObject() && e.second.isMember("name")) ||
|
|
|
|
(e.second.isArray() && e.second[0].isObject() && e.second[0].isMember("name")) ||
|
|
|
|
(e.first == "declarations") // (in the case (_,x)= ... there's a nullpointer at [0]
|
|
|
|
))
|
2017-03-20 18:06:17 +00:00
|
|
|
{
|
|
|
|
if (e.second.isObject())
|
2017-08-17 01:13:16 +00:00
|
|
|
{
|
|
|
|
if (!m_currentValue["children"].isArray())
|
|
|
|
m_currentValue["children"] = Json::arrayValue;
|
2017-07-27 14:40:01 +00:00
|
|
|
appendMove(m_currentValue["children"], std::move(e.second));
|
2017-08-17 01:13:16 +00:00
|
|
|
}
|
2017-03-20 18:06:17 +00:00
|
|
|
if (e.second.isArray())
|
2017-04-25 16:47:11 +00:00
|
|
|
for (auto& child: e.second)
|
2017-03-20 18:06:17 +00:00
|
|
|
if (!child.isNull())
|
2017-08-17 01:13:16 +00:00
|
|
|
{
|
|
|
|
if (!m_currentValue["children"].isArray())
|
|
|
|
m_currentValue["children"] = Json::arrayValue;
|
2017-07-27 14:40:01 +00:00
|
|
|
appendMove(m_currentValue["children"], std::move(child));
|
2017-08-17 01:13:16 +00:00
|
|
|
}
|
2017-03-20 18:06:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e.first == "typeDescriptions")
|
|
|
|
attrs["type"] = Json::Value(e.second["typeString"]);
|
|
|
|
else
|
|
|
|
attrs[e.first] = std::move(e.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!attrs.empty())
|
|
|
|
m_currentValue["attributes"] = std::move(attrs);
|
2015-01-06 15:50:04 +00:00
|
|
|
}
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 10:38:12 +00:00
|
|
|
size_t ASTJsonConverter::sourceIndexFromLocation(SourceLocation const& _location) const
|
2016-07-01 08:14:50 +00:00
|
|
|
{
|
2018-11-28 15:19:22 +00:00
|
|
|
if (_location.source && m_sourceIndices.count(_location.source->name()))
|
2019-10-15 10:38:12 +00:00
|
|
|
return m_sourceIndices.at(_location.source->name());
|
|
|
|
else
|
|
|
|
return size_t(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
string ASTJsonConverter::sourceLocationToString(SourceLocation const& _location) const
|
|
|
|
{
|
|
|
|
size_t sourceIndex = sourceIndexFromLocation(_location);
|
2016-07-01 08:14:50 +00:00
|
|
|
int length = -1;
|
|
|
|
if (_location.start >= 0 && _location.end >= 0)
|
|
|
|
length = _location.end - _location.start;
|
2018-08-08 14:26:30 +00:00
|
|
|
return to_string(_location.start) + ":" + to_string(length) + ":" + to_string(sourceIndex);
|
2016-07-01 08:14:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 21:44:46 +00:00
|
|
|
string ASTJsonConverter::namePathToString(std::vector<ASTString> const& _namePath)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
return boost::algorithm::join(_namePath, ".");
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 15:40:19 +00:00
|
|
|
Json::Value ASTJsonConverter::typePointerToJson(TypePointer _tp, bool _short)
|
2017-03-20 18:06:17 +00:00
|
|
|
{
|
|
|
|
Json::Value typeDescriptions(Json::objectValue);
|
2018-03-21 15:40:19 +00:00
|
|
|
typeDescriptions["typeString"] = _tp ? Json::Value(_tp->toString(_short)) : Json::nullValue;
|
2017-03-20 18:06:17 +00:00
|
|
|
typeDescriptions["typeIdentifier"] = _tp ? Json::Value(_tp->identifier()) : Json::nullValue;
|
|
|
|
return typeDescriptions;
|
|
|
|
|
|
|
|
}
|
2019-10-28 10:39:30 +00:00
|
|
|
Json::Value ASTJsonConverter::typePointerToJson(std::optional<FuncCallArguments> const& _tps)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
if (_tps)
|
|
|
|
{
|
|
|
|
Json::Value arguments(Json::arrayValue);
|
2019-03-19 16:12:21 +00:00
|
|
|
for (auto const& tp: _tps->types)
|
2017-07-27 14:40:01 +00:00
|
|
|
appendMove(arguments, typePointerToJson(tp));
|
2017-03-20 18:06:17 +00:00
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return Json::nullValue;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 18:06:17 +00:00
|
|
|
void ASTJsonConverter::appendExpressionAttributes(
|
2017-05-19 13:45:01 +00:00
|
|
|
std::vector<pair<string, Json::Value>>& _attributes,
|
2017-03-20 18:06:17 +00:00
|
|
|
ExpressionAnnotation const& _annotation
|
|
|
|
)
|
2015-01-28 07:50:53 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> exprAttributes = {
|
2017-05-19 13:45:01 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_annotation.type)),
|
2017-04-25 16:47:11 +00:00
|
|
|
make_pair("isConstant", _annotation.isConstant),
|
|
|
|
make_pair("isPure", _annotation.isPure),
|
|
|
|
make_pair("isLValue", _annotation.isLValue),
|
2020-04-09 10:48:57 +00:00
|
|
|
make_pair("lValueRequested", _annotation.willBeWrittenTo),
|
2019-03-19 16:12:21 +00:00
|
|
|
make_pair("argumentTypes", typePointerToJson(_annotation.arguments))
|
2017-03-20 18:06:17 +00:00
|
|
|
};
|
2017-05-19 13:45:01 +00:00
|
|
|
_attributes += exprAttributes;
|
2015-01-28 07:50:53 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<yul::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const
|
2017-05-17 13:52:45 +00:00
|
|
|
{
|
|
|
|
Json::Value tuple(Json::objectValue);
|
|
|
|
tuple["src"] = sourceLocationToString(_info.first->location);
|
|
|
|
tuple["declaration"] = idOrNull(_info.second.declaration);
|
|
|
|
tuple["isSlot"] = Json::Value(_info.second.isSlot);
|
|
|
|
tuple["isOffset"] = Json::Value(_info.second.isOffset);
|
2017-05-22 18:36:41 +00:00
|
|
|
tuple["valueSize"] = Json::Value(Json::LargestUInt(_info.second.valueSize));
|
2017-05-17 13:52:45 +00:00
|
|
|
return tuple;
|
|
|
|
}
|
2017-03-20 18:06:17 +00:00
|
|
|
|
|
|
|
void ASTJsonConverter::print(ostream& _stream, ASTNode const& _node)
|
2016-08-18 12:51:17 +00:00
|
|
|
{
|
2020-04-27 08:28:54 +00:00
|
|
|
_stream << util::jsonPrettyPrint(util::removeNullMembers(toJson(_node)));
|
2017-03-20 18:06:17 +00:00
|
|
|
}
|
2016-08-18 12:51:17 +00:00
|
|
|
|
2017-07-27 14:40:01 +00:00
|
|
|
Json::Value&& ASTJsonConverter::toJson(ASTNode const& _node)
|
2017-03-20 18:06:17 +00:00
|
|
|
{
|
|
|
|
_node.accept(*this);
|
|
|
|
return std::move(m_currentValue);
|
|
|
|
}
|
2016-08-18 12:51:17 +00:00
|
|
|
|
2017-03-20 18:06:17 +00:00
|
|
|
bool ASTJsonConverter::visit(SourceUnit const& _node)
|
|
|
|
{
|
|
|
|
Json::Value exportedSymbols = Json::objectValue;
|
|
|
|
for (auto const& sym: _node.annotation().exportedSymbols)
|
|
|
|
{
|
|
|
|
exportedSymbols[sym.first] = Json::arrayValue;
|
|
|
|
for (Declaration const* overload: sym.second)
|
|
|
|
exportedSymbols[sym.first].append(nodeId(*overload));
|
|
|
|
}
|
|
|
|
setJsonNode(
|
|
|
|
_node,
|
|
|
|
"SourceUnit",
|
|
|
|
{
|
|
|
|
make_pair("absolutePath", _node.annotation().path),
|
|
|
|
make_pair("exportedSymbols", move(exportedSymbols)),
|
2020-05-12 09:56:28 +00:00
|
|
|
make_pair("license", _node.licenseString() ? Json::Value(*_node.licenseString()) : Json::nullValue),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("nodes", toJson(_node.nodes()))
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
2016-08-18 12:51:17 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode( _node, "PragmaDirective", {
|
|
|
|
make_pair("literals", std::move(literals))
|
|
|
|
});
|
|
|
|
return false;
|
2016-08-19 17:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(ImportDirective const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("file", _node.path()),
|
|
|
|
make_pair("absolutePath", _node.annotation().absolutePath),
|
2017-04-21 12:46:53 +00:00
|
|
|
make_pair(m_legacy ? "SourceUnit" : "sourceUnit", nodeId(*_node.annotation().sourceUnit)),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("scope", idOrNull(_node.scope()))
|
|
|
|
};
|
2018-12-10 18:02:39 +00:00
|
|
|
attributes.emplace_back("unitAlias", _node.name());
|
2017-03-20 18:06:17 +00:00
|
|
|
Json::Value symbolAliases(Json::arrayValue);
|
|
|
|
for (auto const& symbolAlias: _node.symbolAliases())
|
|
|
|
{
|
|
|
|
Json::Value tuple(Json::objectValue);
|
2019-09-25 12:14:44 +00:00
|
|
|
solAssert(symbolAlias.symbol, "");
|
2019-11-21 14:47:10 +00:00
|
|
|
tuple["foreign"] = toJson(*symbolAlias.symbol);
|
2019-09-25 12:14:44 +00:00
|
|
|
tuple["local"] = symbolAlias.alias ? Json::Value(*symbolAlias.alias) : Json::nullValue;
|
2017-03-20 18:06:17 +00:00
|
|
|
symbolAliases.append(tuple);
|
|
|
|
}
|
2018-12-10 18:02:39 +00:00
|
|
|
attributes.emplace_back("symbolAliases", std::move(symbolAliases));
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ImportDirective", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(ContractDefinition const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ContractDefinition", {
|
2016-08-17 17:07:44 +00:00
|
|
|
make_pair("name", _node.name()),
|
2020-01-29 22:27:21 +00:00
|
|
|
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
|
2017-05-05 14:15:09 +00:00
|
|
|
make_pair("contractKind", contractKind(_node.contractKind())),
|
2019-09-04 22:01:13 +00:00
|
|
|
make_pair("abstract", _node.abstract()),
|
2020-04-15 10:42:15 +00:00
|
|
|
make_pair("fullyImplemented", _node.annotation().unimplementedDeclarations.empty()),
|
2017-04-25 16:47:11 +00:00
|
|
|
make_pair("linearizedBaseContracts", getContainerIds(_node.annotation().linearizedBaseContracts)),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("baseContracts", toJson(_node.baseContracts())),
|
2019-08-19 14:26:14 +00:00
|
|
|
make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies, true)),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("nodes", toJson(_node.subNodes())),
|
|
|
|
make_pair("scope", idOrNull(_node.scope()))
|
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 13:25:25 +00:00
|
|
|
bool ASTJsonConverter::visit(InheritanceSpecifier const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "InheritanceSpecifier", {
|
|
|
|
make_pair("baseName", toJson(_node.name())),
|
2018-04-10 09:22:26 +00:00
|
|
|
make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue)
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2016-08-16 14:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(UsingForDirective const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "UsingForDirective", {
|
2017-05-05 14:15:09 +00:00
|
|
|
make_pair("libraryName", toJson(_node.libraryName())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("typeName", _node.typeName() ? toJson(*_node.typeName()) : Json::nullValue)
|
|
|
|
});
|
|
|
|
return false;
|
2016-08-16 13:25:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(StructDefinition const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "StructDefinition", {
|
|
|
|
make_pair("name", _node.name()),
|
2017-08-09 13:29:03 +00:00
|
|
|
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("canonicalName", _node.annotation().canonicalName),
|
|
|
|
make_pair("members", toJson(_node.members())),
|
|
|
|
make_pair("scope", idOrNull(_node.scope()))
|
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 15:18:57 +00:00
|
|
|
bool ASTJsonConverter::visit(EnumDefinition const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "EnumDefinition", {
|
|
|
|
make_pair("name", _node.name()),
|
|
|
|
make_pair("canonicalName", _node.annotation().canonicalName),
|
|
|
|
make_pair("members", toJson(_node.members()))
|
|
|
|
});
|
|
|
|
return false;
|
2016-08-16 15:18:57 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 15:38:24 +00:00
|
|
|
bool ASTJsonConverter::visit(EnumValue const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "EnumValue", {
|
|
|
|
make_pair("name", _node.name())
|
|
|
|
});
|
|
|
|
return false;
|
2016-08-16 15:38:24 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(ParameterList const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ParameterList", {
|
|
|
|
make_pair("parameters", toJson(_node.parameters()))
|
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 14:47:10 +00:00
|
|
|
bool ASTJsonConverter::visit(OverrideSpecifier const& _node)
|
|
|
|
{
|
|
|
|
setJsonNode(_node, "OverrideSpecifier", {
|
|
|
|
make_pair("overrides", toJson(_node.overrides()))
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(FunctionDefinition const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2016-08-17 17:07:44 +00:00
|
|
|
make_pair("name", _node.name()),
|
2020-01-29 22:27:21 +00:00
|
|
|
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
|
2019-09-09 16:22:02 +00:00
|
|
|
make_pair("kind", TokenTraits::toString(_node.kind())),
|
2017-08-24 14:23:00 +00:00
|
|
|
make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
|
2017-08-09 13:29:03 +00:00
|
|
|
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
2019-11-21 14:47:10 +00:00
|
|
|
make_pair("virtual", _node.markedVirtual()),
|
|
|
|
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
|
2017-04-25 16:47:11 +00:00
|
|
|
make_pair("parameters", toJson(_node.parameterList())),
|
|
|
|
make_pair("returnParameters", toJson(*_node.returnParameterList())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("modifiers", toJson(_node.modifiers())),
|
|
|
|
make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue),
|
2017-05-05 14:15:09 +00:00
|
|
|
make_pair("implemented", _node.isImplemented()),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("scope", idOrNull(_node.scope()))
|
|
|
|
};
|
2019-12-09 00:26:23 +00:00
|
|
|
if (_node.isPartOfExternalInterface())
|
|
|
|
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
2019-12-05 02:17:28 +00:00
|
|
|
if (!_node.annotation().baseFunctions.empty())
|
|
|
|
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
|
2018-08-07 19:49:14 +00:00
|
|
|
if (m_legacy)
|
|
|
|
attributes.emplace_back("isConstructor", _node.isConstructor());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "FunctionDefinition", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(VariableDeclaration const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2015-09-24 10:12:31 +00:00
|
|
|
make_pair("name", _node.name()),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("typeName", toJsonOrNull(_node.typeName())),
|
2017-04-25 16:47:11 +00:00
|
|
|
make_pair("constant", _node.isConstant()),
|
2020-04-07 09:10:10 +00:00
|
|
|
make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())),
|
2017-05-19 13:45:01 +00:00
|
|
|
make_pair("stateVariable", _node.isStateVariable()),
|
2017-03-13 14:19:41 +00:00
|
|
|
make_pair("storageLocation", location(_node.referenceLocation())),
|
2019-11-21 14:47:10 +00:00
|
|
|
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
|
2017-08-09 13:29:03 +00:00
|
|
|
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("value", _node.value() ? toJson(*_node.value()) : Json::nullValue),
|
|
|
|
make_pair("scope", idOrNull(_node.scope())),
|
2018-03-21 15:40:19 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
2017-03-20 18:06:17 +00:00
|
|
|
};
|
2019-12-09 00:26:23 +00:00
|
|
|
if (_node.isStateVariable() && _node.isPublic())
|
|
|
|
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
2020-03-24 22:44:39 +00:00
|
|
|
if (_node.isStateVariable() && _node.documentation())
|
|
|
|
attributes.emplace_back("documentation", toJson(*_node.documentation()));
|
2017-03-13 14:19:41 +00:00
|
|
|
if (m_inEvent)
|
2018-12-10 18:02:39 +00:00
|
|
|
attributes.emplace_back("indexed", _node.isIndexed());
|
2019-12-11 14:32:28 +00:00
|
|
|
if (!_node.annotation().baseFunctions.empty())
|
|
|
|
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "VariableDeclaration", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:23:20 +00:00
|
|
|
bool ASTJsonConverter::visit(ModifierDefinition const& _node)
|
|
|
|
{
|
2019-12-09 15:54:52 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("name", _node.name()),
|
2020-01-29 22:27:21 +00:00
|
|
|
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
|
2017-08-09 13:29:03 +00:00
|
|
|
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("parameters", toJson(_node.parameterList())),
|
2019-11-21 14:47:10 +00:00
|
|
|
make_pair("virtual", _node.markedVirtual()),
|
|
|
|
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
|
2020-04-15 10:42:15 +00:00
|
|
|
make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue)
|
2019-12-09 15:54:52 +00:00
|
|
|
};
|
|
|
|
if (!_node.annotation().baseFunctions.empty())
|
|
|
|
attributes.emplace_back(make_pair("baseModifiers", getContainerIds(_node.annotation().baseFunctions, true)));
|
|
|
|
setJsonNode(_node, "ModifierDefinition", std::move(attributes));
|
2017-03-20 18:06:17 +00:00
|
|
|
return false;
|
2016-08-17 14:23:20 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:52:14 +00:00
|
|
|
bool ASTJsonConverter::visit(ModifierInvocation const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ModifierInvocation", {
|
|
|
|
make_pair("modifierName", toJson(*_node.name())),
|
2018-04-10 09:22:26 +00:00
|
|
|
make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue)
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2016-08-17 14:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(EventDefinition const& _node)
|
|
|
|
{
|
2017-03-13 14:19:41 +00:00
|
|
|
m_inEvent = true;
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "EventDefinition", {
|
|
|
|
make_pair("name", _node.name()),
|
2020-01-29 22:27:21 +00:00
|
|
|
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("parameters", toJson(_node.parameterList())),
|
2017-04-25 16:47:11 +00:00
|
|
|
make_pair("anonymous", _node.isAnonymous())
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2016-08-17 14:52:14 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(ElementaryTypeName const& _node)
|
|
|
|
{
|
2018-09-10 10:49:15 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("name", _node.typeName().toString()),
|
2018-03-21 15:40:19 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
2018-09-10 10:49:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_node.stateMutability())
|
|
|
|
attributes.emplace_back(make_pair("stateMutability", stateMutabilityToString(*_node.stateMutability())));
|
|
|
|
|
|
|
|
setJsonNode(_node, "ElementaryTypeName", std::move(attributes));
|
2017-03-20 18:06:17 +00:00
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(UserDefinedTypeName const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "UserDefinedTypeName", {
|
|
|
|
make_pair("name", namePathToString(_node.namePath())),
|
|
|
|
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
|
|
|
|
make_pair("contractScope", idOrNull(_node.annotation().contractScope)),
|
2018-03-21 15:40:19 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
2015-10-06 10:35:10 +00:00
|
|
|
});
|
2017-03-20 18:06:17 +00:00
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 19:37:32 +00:00
|
|
|
bool ASTJsonConverter::visit(FunctionTypeName const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "FunctionTypeName", {
|
2017-08-09 13:29:03 +00:00
|
|
|
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
|
2017-08-24 14:23:00 +00:00
|
|
|
make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
|
2017-05-24 11:52:16 +00:00
|
|
|
make_pair("parameterTypes", toJson(*_node.parameterTypeList())),
|
|
|
|
make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())),
|
2018-03-21 15:40:19 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2016-09-27 19:37:32 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Mapping const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Mapping", {
|
|
|
|
make_pair("keyType", toJson(_node.keyType())),
|
|
|
|
make_pair("valueType", toJson(_node.valueType())),
|
2018-03-21 15:40:19 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 15:09:21 +00:00
|
|
|
bool ASTJsonConverter::visit(ArrayTypeName const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ArrayTypeName", {
|
|
|
|
make_pair("baseType", toJson(_node.baseType())),
|
|
|
|
make_pair("length", toJsonOrNull(_node.length())),
|
2018-03-21 15:40:19 +00:00
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2016-08-17 15:09:21 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(InlineAssembly const& _node)
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
2019-10-15 10:38:12 +00:00
|
|
|
vector<pair<string, Json::Value>> externalReferences;
|
2020-01-14 11:46:47 +00:00
|
|
|
|
2019-06-24 13:31:32 +00:00
|
|
|
for (auto const& it: _node.annotation().externalReferences)
|
2017-05-17 13:52:45 +00:00
|
|
|
if (it.first)
|
2019-10-15 10:38:12 +00:00
|
|
|
externalReferences.emplace_back(make_pair(
|
|
|
|
it.first->name.str(),
|
|
|
|
inlineAssemblyIdentifierToJson(it)
|
|
|
|
));
|
2020-01-14 11:46:47 +00:00
|
|
|
|
2019-10-15 10:38:12 +00:00
|
|
|
Json::Value externalReferencesJson = Json::arrayValue;
|
2020-01-14 11:46:47 +00:00
|
|
|
|
2019-10-15 10:38:12 +00:00
|
|
|
for (auto&& it: boost::range::sort(externalReferences))
|
|
|
|
externalReferencesJson.append(std::move(it.second));
|
|
|
|
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "InlineAssembly", {
|
2019-10-15 10:38:12 +00:00
|
|
|
m_legacy ?
|
|
|
|
make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))) :
|
|
|
|
make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))),
|
2020-01-14 11:46:47 +00:00
|
|
|
make_pair("externalReferences", std::move(externalReferencesJson)),
|
|
|
|
make_pair("evmVersion", dynamic_cast<solidity::yul::EVMDialect const&>(_node.dialect()).evmVersion().name())
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
2020-01-14 11:46:47 +00:00
|
|
|
|
2017-03-20 18:06:17 +00:00
|
|
|
return false;
|
2016-02-22 01:13:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(Block const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Block", {
|
|
|
|
make_pair("statements", toJson(_node.statements()))
|
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 15:20:17 +00:00
|
|
|
bool ASTJsonConverter::visit(PlaceholderStatement const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "PlaceholderStatement", {});
|
|
|
|
return false;
|
2016-08-17 15:20:17 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(IfStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "IfStatement", {
|
|
|
|
make_pair("condition", toJson(_node.condition())),
|
|
|
|
make_pair("trueBody", toJson(_node.trueStatement())),
|
|
|
|
make_pair("falseBody", toJsonOrNull(_node.falseStatement()))
|
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 14:17:02 +00:00
|
|
|
bool ASTJsonConverter::visit(TryCatchClause const& _node)
|
|
|
|
{
|
|
|
|
setJsonNode(_node, "TryCatchClause", {
|
|
|
|
make_pair("errorName", _node.errorName()),
|
|
|
|
make_pair("parameters", toJsonOrNull(_node.parameters())),
|
|
|
|
make_pair("block", toJson(_node.block()))
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(TryStatement const& _node)
|
|
|
|
{
|
|
|
|
setJsonNode(_node, "TryStatement", {
|
|
|
|
make_pair("externalCall", toJson(_node.externalCall())),
|
|
|
|
make_pair("clauses", toJson(_node.clauses()))
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(WhileStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(
|
2016-07-30 07:13:05 +00:00
|
|
|
_node,
|
|
|
|
_node.isDoWhile() ? "DoWhileStatement" : "WhileStatement",
|
2017-03-20 18:06:17 +00:00
|
|
|
{
|
|
|
|
make_pair("condition", toJson(_node.condition())),
|
|
|
|
make_pair("body", toJson(_node.body()))
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ForStatement", {
|
2017-05-05 14:15:09 +00:00
|
|
|
make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("condition", toJsonOrNull(_node.condition())),
|
|
|
|
make_pair("loopExpression", toJsonOrNull(_node.loopExpression())),
|
|
|
|
make_pair("body", toJson(_node.body()))
|
|
|
|
});
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Continue", {});
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Break", {});
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Return", {
|
|
|
|
make_pair("expression", toJsonOrNull(_node.expression())),
|
|
|
|
make_pair("functionReturnParameters", idOrNull(_node.annotation().functionReturnParameters))
|
|
|
|
});
|
|
|
|
return false;
|
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
|
|
|
{
|
2018-02-16 15:55:21 +00:00
|
|
|
setJsonNode(_node, "Throw", {});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(EmitStatement const& _node)
|
|
|
|
{
|
|
|
|
setJsonNode(_node, "EmitStatement", {
|
|
|
|
make_pair("eventCall", toJson(_node.eventCall()))
|
|
|
|
});
|
2017-03-20 18:06:17 +00:00
|
|
|
return false;
|
2015-09-15 14:33:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:14:50 +00:00
|
|
|
bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node)
|
2015-01-05 14:46:40 +00:00
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
Json::Value varDecs(Json::arrayValue);
|
2018-07-04 16:34:24 +00:00
|
|
|
for (auto const& v: _node.declarations())
|
|
|
|
appendMove(varDecs, idOrNull(v.get()));
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "VariableDeclarationStatement", {
|
|
|
|
make_pair("assignments", std::move(varDecs)),
|
|
|
|
make_pair("declarations", toJson(_node.declarations())),
|
|
|
|
make_pair("initialValue", toJsonOrNull(_node.initialValue()))
|
|
|
|
});
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ExpressionStatement", {
|
|
|
|
make_pair("expression", toJson(_node.expression()))
|
|
|
|
});
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("condition", toJson(_node.condition())),
|
|
|
|
make_pair("trueExpression", toJson(_node.trueExpression())),
|
|
|
|
make_pair("falseExpression", toJson(_node.falseExpression()))
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Conditional", std::move(attributes));
|
|
|
|
return false;
|
2015-12-22 16:47:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(Assignment const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2018-10-22 14:48:21 +00:00
|
|
|
make_pair("operator", TokenTraits::toString(_node.assignmentOperator())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("leftHandSide", toJson(_node.leftHandSide())),
|
|
|
|
make_pair("rightHandSide", toJson(_node.rightHandSide()))
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode( _node, "Assignment", std::move(attributes));
|
|
|
|
return false;
|
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
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("isInlineArray", Json::Value(_node.isInlineArray())),
|
|
|
|
make_pair("components", toJson(_node.components())),
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "TupleExpression", std::move(attributes));
|
|
|
|
return false;
|
2015-10-12 21:02:35 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(UnaryOperation const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("prefix", _node.isPrefixOperation()),
|
2018-10-22 14:48:21 +00:00
|
|
|
make_pair("operator", TokenTraits::toString(_node.getOperator())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("subExpression", toJson(_node.subExpression()))
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "UnaryOperation", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(BinaryOperation const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2018-10-22 14:48:21 +00:00
|
|
|
make_pair("operator", TokenTraits::toString(_node.getOperator())),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("leftExpression", toJson(_node.leftExpression())),
|
|
|
|
make_pair("rightExpression", toJson(_node.rightExpression())),
|
|
|
|
make_pair("commonType", typePointerToJson(_node.annotation().commonType)),
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "BinaryOperation", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(FunctionCall const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
Json::Value names(Json::arrayValue);
|
|
|
|
for (auto const& name: _node.names())
|
|
|
|
names.append(Json::Value(*name));
|
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("expression", toJson(_node.expression())),
|
|
|
|
make_pair("names", std::move(names)),
|
2019-09-02 14:17:02 +00:00
|
|
|
make_pair("arguments", toJson(_node.arguments())),
|
|
|
|
make_pair("tryCall", _node.annotation().tryCall)
|
2017-05-19 13:45:01 +00:00
|
|
|
};
|
|
|
|
if (m_legacy)
|
|
|
|
{
|
2018-12-10 18:02:39 +00:00
|
|
|
attributes.emplace_back("isStructConstructorCall", _node.annotation().kind == FunctionCallKind::StructConstructorCall);
|
|
|
|
attributes.emplace_back("type_conversion", _node.annotation().kind == FunctionCallKind::TypeConversion);
|
2017-05-19 13:45:01 +00:00
|
|
|
}
|
|
|
|
else
|
2018-12-10 18:02:39 +00:00
|
|
|
attributes.emplace_back("kind", functionCallKind(_node.annotation().kind));
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "FunctionCall", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 14:42:50 +00:00
|
|
|
bool ASTJsonConverter::visit(FunctionCallOptions const& _node)
|
|
|
|
{
|
|
|
|
Json::Value names(Json::arrayValue);
|
|
|
|
for (auto const& name: _node.names())
|
|
|
|
names.append(Json::Value(*name));
|
|
|
|
|
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("expression", toJson(_node.expression())),
|
|
|
|
make_pair("names", std::move(names)),
|
|
|
|
make_pair("options", toJson(_node.options())),
|
|
|
|
};
|
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
|
|
|
|
|
|
|
setJsonNode(_node, "FunctionCallOptions", std::move(attributes));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(NewExpression const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("typeName", toJson(_node.typeName()))
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "NewExpression", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(MemberAccess const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2017-04-21 12:46:53 +00:00
|
|
|
make_pair(m_legacy ? "member_name" : "memberName", _node.memberName()),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("expression", toJson(_node.expression())),
|
|
|
|
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "MemberAccess", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(IndexAccess const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("baseExpression", toJson(_node.baseExpression())),
|
|
|
|
make_pair("indexExpression", toJsonOrNull(_node.indexExpression())),
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "IndexAccess", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 16:30:00 +00:00
|
|
|
bool ASTJsonConverter::visit(IndexRangeAccess const& _node)
|
|
|
|
{
|
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("baseExpression", toJson(_node.baseExpression())),
|
|
|
|
make_pair("startExpression", toJsonOrNull(_node.startExpression())),
|
|
|
|
make_pair("endExpression", toJsonOrNull(_node.endExpression())),
|
|
|
|
};
|
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
|
|
|
setJsonNode(_node, "IndexRangeAccess", std::move(attributes));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:46:40 +00:00
|
|
|
bool ASTJsonConverter::visit(Identifier const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
Json::Value overloads(Json::arrayValue);
|
|
|
|
for (auto const& dec: _node.annotation().overloadedDeclarations)
|
|
|
|
overloads.append(nodeId(*dec));
|
|
|
|
setJsonNode(_node, "Identifier", {
|
2017-04-21 12:46:53 +00:00
|
|
|
make_pair(m_legacy ? "value" : "name", _node.name()),
|
2017-03-20 18:06:17 +00:00
|
|
|
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
|
|
|
|
make_pair("overloadedDeclarations", overloads),
|
|
|
|
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)),
|
2019-03-19 16:12:21 +00:00
|
|
|
make_pair("argumentTypes", typePointerToJson(_node.annotation().arguments))
|
2017-03-20 18:06:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
|
|
|
|
{
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2019-11-21 14:47:10 +00:00
|
|
|
make_pair(m_legacy ? "value" : "typeName", toJson(_node.type()))
|
2017-03-20 18:06:17 +00:00
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "ElementaryTypeNameExpression", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTJsonConverter::visit(Literal const& _node)
|
|
|
|
{
|
2016-09-01 22:21:39 +00:00
|
|
|
Json::Value value{_node.value()};
|
2019-12-11 16:31:36 +00:00
|
|
|
if (!util::validateUTF8(_node.value()))
|
2016-09-01 22:21:39 +00:00
|
|
|
value = Json::nullValue;
|
2018-10-22 14:48:21 +00:00
|
|
|
Token subdenomination = Token(_node.subDenomination());
|
2017-03-20 18:06:17 +00:00
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
2017-06-05 13:36:06 +00:00
|
|
|
make_pair(m_legacy ? "token" : "kind", literalTokenKind(_node.token())),
|
2016-09-01 22:21:39 +00:00
|
|
|
make_pair("value", value),
|
2019-12-11 16:31:36 +00:00
|
|
|
make_pair(m_legacy ? "hexvalue" : "hexValue", util::toHex(util::asBytes(_node.value()))),
|
2016-09-01 22:21:39 +00:00
|
|
|
make_pair(
|
|
|
|
"subdenomination",
|
|
|
|
subdenomination == Token::Illegal ?
|
|
|
|
Json::nullValue :
|
2018-10-22 14:48:21 +00:00
|
|
|
Json::Value{TokenTraits::toString(subdenomination)}
|
2017-03-20 18:06:17 +00:00
|
|
|
)
|
|
|
|
};
|
2017-04-25 16:47:11 +00:00
|
|
|
appendExpressionAttributes(attributes, _node.annotation());
|
2017-03-20 18:06:17 +00:00
|
|
|
setJsonNode(_node, "Literal", std::move(attributes));
|
|
|
|
return false;
|
2015-01-05 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 22:27:21 +00:00
|
|
|
bool ASTJsonConverter::visit(StructuredDocumentation const& _node)
|
|
|
|
{
|
|
|
|
Json::Value text{*_node.text()};
|
|
|
|
std::vector<pair<string, Json::Value>> attributes = {
|
|
|
|
make_pair("text", text)
|
|
|
|
};
|
|
|
|
setJsonNode(_node, "StructuredDocumentation", std::move(attributes));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-17 14:52:14 +00:00
|
|
|
|
|
|
|
void ASTJsonConverter::endVisit(EventDefinition const&)
|
|
|
|
{
|
2017-03-13 14:19:41 +00:00
|
|
|
m_inEvent = false;
|
2015-01-28 07:50:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 13:44:44 +00:00
|
|
|
string ASTJsonConverter::location(VariableDeclaration::Location _location)
|
2017-03-13 14:19:41 +00:00
|
|
|
{
|
|
|
|
switch (_location)
|
|
|
|
{
|
2018-08-17 23:09:31 +00:00
|
|
|
case VariableDeclaration::Location::Unspecified:
|
2017-03-13 14:19:41 +00:00
|
|
|
return "default";
|
|
|
|
case VariableDeclaration::Location::Storage:
|
|
|
|
return "storage";
|
|
|
|
case VariableDeclaration::Location::Memory:
|
|
|
|
return "memory";
|
2018-05-23 04:31:20 +00:00
|
|
|
case VariableDeclaration::Location::CallData:
|
|
|
|
return "calldata";
|
2017-03-13 14:19:41 +00:00
|
|
|
}
|
2018-09-30 07:10:38 +00:00
|
|
|
// To make the compiler happy
|
|
|
|
return {};
|
2017-03-13 14:19:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-07 14:11:29 +00:00
|
|
|
string ASTJsonConverter::contractKind(ContractKind _kind)
|
2017-05-05 14:15:09 +00:00
|
|
|
{
|
|
|
|
switch (_kind)
|
|
|
|
{
|
2020-01-07 14:11:29 +00:00
|
|
|
case ContractKind::Interface:
|
2017-05-05 14:15:09 +00:00
|
|
|
return "interface";
|
2020-01-07 14:11:29 +00:00
|
|
|
case ContractKind::Contract:
|
2017-05-05 14:15:09 +00:00
|
|
|
return "contract";
|
2020-01-07 14:11:29 +00:00
|
|
|
case ContractKind::Library:
|
2017-05-05 14:15:09 +00:00
|
|
|
return "library";
|
2017-05-19 13:45:01 +00:00
|
|
|
}
|
2018-09-30 07:10:38 +00:00
|
|
|
|
|
|
|
// To make the compiler happy
|
|
|
|
return {};
|
2017-05-19 13:45:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string ASTJsonConverter::functionCallKind(FunctionCallKind _kind)
|
|
|
|
{
|
|
|
|
switch (_kind)
|
|
|
|
{
|
|
|
|
case FunctionCallKind::FunctionCall:
|
|
|
|
return "functionCall";
|
|
|
|
case FunctionCallKind::TypeConversion:
|
|
|
|
return "typeConversion";
|
|
|
|
case FunctionCallKind::StructConstructorCall:
|
|
|
|
return "structConstructorCall";
|
|
|
|
default:
|
2017-07-19 01:19:00 +00:00
|
|
|
solAssert(false, "Unknown kind of function call.");
|
2017-05-05 14:15:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:48:21 +00:00
|
|
|
string ASTJsonConverter::literalTokenKind(Token _token)
|
2017-05-30 17:07:47 +00:00
|
|
|
{
|
|
|
|
switch (_token)
|
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
case Token::Number:
|
2017-05-30 17:07:47 +00:00
|
|
|
return "number";
|
2019-12-11 16:31:36 +00:00
|
|
|
case Token::StringLiteral:
|
|
|
|
case Token::HexStringLiteral:
|
2017-05-30 17:07:47 +00:00
|
|
|
return "string";
|
2019-12-11 16:31:36 +00:00
|
|
|
case Token::TrueLiteral:
|
|
|
|
case Token::FalseLiteral:
|
2017-05-30 17:07:47 +00:00
|
|
|
return "bool";
|
|
|
|
default:
|
2017-07-19 01:19:00 +00:00
|
|
|
solAssert(false, "Unknown kind of literal token.");
|
2017-05-30 17:07:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|