mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove the legacy AST JSON output
This commit is contained in:
@@ -70,8 +70,7 @@ void addIfSet(std::vector<pair<string, Json::Value>>& _attributes, string const&
|
||||
namespace solidity::frontend
|
||||
{
|
||||
|
||||
ASTJsonConverter::ASTJsonConverter(bool _legacy, CompilerStack::State _stackState, map<string, unsigned> _sourceIndices):
|
||||
m_legacy(_legacy),
|
||||
ASTJsonConverter::ASTJsonConverter(CompilerStack::State _stackState, map<string, unsigned> _sourceIndices):
|
||||
m_stackState(_stackState),
|
||||
m_sourceIndices(std::move(_sourceIndices))
|
||||
{
|
||||
@@ -100,60 +99,9 @@ void ASTJsonConverter::setJsonNode(
|
||||
m_currentValue = Json::objectValue;
|
||||
m_currentValue["id"] = nodeId(_node);
|
||||
m_currentValue["src"] = sourceLocationToString(_node.location());
|
||||
if (!m_legacy)
|
||||
{
|
||||
m_currentValue["nodeType"] = _nodeType;
|
||||
for (auto& e: _attributes)
|
||||
m_currentValue[e.first] = std::move(e.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
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")
|
||||
)
|
||||
m_currentValue["children"] = Json::arrayValue;
|
||||
|
||||
for (auto& e: _attributes)
|
||||
{
|
||||
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]
|
||||
))
|
||||
{
|
||||
if (e.second.isObject())
|
||||
{
|
||||
if (!m_currentValue["children"].isArray())
|
||||
m_currentValue["children"] = Json::arrayValue;
|
||||
appendMove(m_currentValue["children"], std::move(e.second));
|
||||
}
|
||||
if (e.second.isArray())
|
||||
for (auto& child: e.second)
|
||||
if (!child.isNull())
|
||||
{
|
||||
if (!m_currentValue["children"].isArray())
|
||||
m_currentValue["children"] = Json::arrayValue;
|
||||
appendMove(m_currentValue["children"], std::move(child));
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
m_currentValue["nodeType"] = _nodeType;
|
||||
for (auto& e: _attributes)
|
||||
m_currentValue[e.first] = std::move(e.second);
|
||||
}
|
||||
|
||||
size_t ASTJsonConverter::sourceIndexFromLocation(SourceLocation const& _location) const
|
||||
@@ -285,7 +233,7 @@ bool ASTJsonConverter::visit(ImportDirective const& _node)
|
||||
{
|
||||
std::vector<pair<string, Json::Value>> attributes = {
|
||||
make_pair("file", _node.path()),
|
||||
make_pair(m_legacy ? "SourceUnit" : "sourceUnit", idOrNull(_node.annotation().sourceUnit)),
|
||||
make_pair("sourceUnit", idOrNull(_node.annotation().sourceUnit)),
|
||||
make_pair("scope", idOrNull(_node.scope()))
|
||||
};
|
||||
|
||||
@@ -442,8 +390,6 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
|
||||
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
||||
if (!_node.annotation().baseFunctions.empty())
|
||||
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
|
||||
if (m_legacy)
|
||||
attributes.emplace_back("isConstructor", _node.isConstructor());
|
||||
setJsonNode(_node, "FunctionDefinition", std::move(attributes));
|
||||
return false;
|
||||
}
|
||||
@@ -586,9 +532,7 @@ bool ASTJsonConverter::visit(InlineAssembly const& _node)
|
||||
externalReferencesJson.append(std::move(it.second));
|
||||
|
||||
setJsonNode(_node, "InlineAssembly", {
|
||||
m_legacy ?
|
||||
make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))) :
|
||||
make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))),
|
||||
make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))),
|
||||
make_pair("externalReferences", std::move(externalReferencesJson)),
|
||||
make_pair("evmVersion", dynamic_cast<solidity::yul::EVMDialect const&>(_node.dialect()).evmVersion().name())
|
||||
});
|
||||
@@ -794,14 +738,7 @@ bool ASTJsonConverter::visit(FunctionCall const& _node)
|
||||
if (_node.annotation().kind.set())
|
||||
{
|
||||
FunctionCallKind nodeKind = *_node.annotation().kind;
|
||||
|
||||
if (m_legacy)
|
||||
{
|
||||
attributes.emplace_back("isStructConstructorCall", nodeKind == FunctionCallKind::StructConstructorCall);
|
||||
attributes.emplace_back("type_conversion", nodeKind == FunctionCallKind::TypeConversion);
|
||||
}
|
||||
else
|
||||
attributes.emplace_back("kind", functionCallKind(nodeKind));
|
||||
attributes.emplace_back("kind", functionCallKind(nodeKind));
|
||||
}
|
||||
|
||||
appendExpressionAttributes(attributes, _node.annotation());
|
||||
@@ -839,7 +776,7 @@ bool ASTJsonConverter::visit(NewExpression const& _node)
|
||||
bool ASTJsonConverter::visit(MemberAccess const& _node)
|
||||
{
|
||||
std::vector<pair<string, Json::Value>> attributes = {
|
||||
make_pair(m_legacy ? "member_name" : "memberName", _node.memberName()),
|
||||
make_pair("memberName", _node.memberName()),
|
||||
make_pair("expression", toJson(_node.expression())),
|
||||
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
|
||||
};
|
||||
@@ -877,7 +814,7 @@ bool ASTJsonConverter::visit(Identifier const& _node)
|
||||
for (auto const& dec: _node.annotation().overloadedDeclarations)
|
||||
overloads.append(nodeId(*dec));
|
||||
setJsonNode(_node, "Identifier", {
|
||||
make_pair(m_legacy ? "value" : "name", _node.name()),
|
||||
make_pair("name", _node.name()),
|
||||
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
|
||||
make_pair("overloadedDeclarations", overloads),
|
||||
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)),
|
||||
@@ -889,7 +826,7 @@ bool ASTJsonConverter::visit(Identifier const& _node)
|
||||
bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
|
||||
{
|
||||
std::vector<pair<string, Json::Value>> attributes = {
|
||||
make_pair(m_legacy ? "value" : "typeName", toJson(_node.type()))
|
||||
make_pair("typeName", toJson(_node.type()))
|
||||
};
|
||||
appendExpressionAttributes(attributes, _node.annotation());
|
||||
setJsonNode(_node, "ElementaryTypeNameExpression", std::move(attributes));
|
||||
@@ -903,9 +840,9 @@ bool ASTJsonConverter::visit(Literal const& _node)
|
||||
value = Json::nullValue;
|
||||
Token subdenomination = Token(_node.subDenomination());
|
||||
std::vector<pair<string, Json::Value>> attributes = {
|
||||
make_pair(m_legacy ? "token" : "kind", literalTokenKind(_node.token())),
|
||||
make_pair("kind", literalTokenKind(_node.token())),
|
||||
make_pair("value", value),
|
||||
make_pair(m_legacy ? "hexvalue" : "hexValue", util::toHex(util::asBytes(_node.value()))),
|
||||
make_pair("hexValue", util::toHex(util::asBytes(_node.value()))),
|
||||
make_pair(
|
||||
"subdenomination",
|
||||
subdenomination == Token::Illegal ?
|
||||
|
||||
Reference in New Issue
Block a user