Purge using namespace std from libsolidity/ast

This commit is contained in:
Nikola Matic 2023-08-14 14:39:16 +02:00
parent b4d4b49dca
commit 2a2a9d37ee
8 changed files with 666 additions and 673 deletions

View File

@ -39,13 +39,12 @@
#include <functional> #include <functional>
#include <utility> #include <utility>
using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::frontend; using namespace solidity::frontend;
namespace namespace
{ {
TryCatchClause const* findClause(vector<ASTPointer<TryCatchClause>> const& _clauses, optional<string> _errorName = {}) TryCatchClause const* findClause(std::vector<ASTPointer<TryCatchClause>> const& _clauses, std::optional<std::string> _errorName = {})
{ {
for (auto const& clause: ranges::views::tail(_clauses)) for (auto const& clause: ranges::views::tail(_clauses))
if (_errorName.has_value() ? clause->errorName() == _errorName : clause->errorName().empty()) if (_errorName.has_value() ? clause->errorName() == _errorName : clause->errorName().empty())
@ -119,7 +118,7 @@ FunctionDefinition const* ASTNode::resolveFunctionCall(FunctionCall const& _func
ASTAnnotation& ASTNode::annotation() const ASTAnnotation& ASTNode::annotation() const
{ {
if (!m_annotation) if (!m_annotation)
m_annotation = make_unique<ASTAnnotation>(); m_annotation = std::make_unique<ASTAnnotation>();
return *m_annotation; return *m_annotation;
} }
@ -128,9 +127,9 @@ SourceUnitAnnotation& SourceUnit::annotation() const
return initAnnotation<SourceUnitAnnotation>(); return initAnnotation<SourceUnitAnnotation>();
} }
set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse, set<SourceUnit const*> _skipList) const std::set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse, std::set<SourceUnit const*> _skipList) const
{ {
set<SourceUnit const*> sourceUnits; std::set<SourceUnit const*> sourceUnits;
for (ImportDirective const* importDirective: filteredNodes<ImportDirective>(nodes())) for (ImportDirective const* importDirective: filteredNodes<ImportDirective>(nodes()))
{ {
auto const& sourceUnit = importDirective->annotation().sourceUnit; auto const& sourceUnit = importDirective->annotation().sourceUnit;
@ -161,11 +160,11 @@ bool ContractDefinition::derivesFrom(ContractDefinition const& _base) const
return util::contains(annotation().linearizedBaseContracts, &_base); return util::contains(annotation().linearizedBaseContracts, &_base);
} }
map<util::FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions(bool _includeInheritedFunctions) const std::map<util::FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions(bool _includeInheritedFunctions) const
{ {
auto exportedFunctionList = interfaceFunctionList(_includeInheritedFunctions); auto exportedFunctionList = interfaceFunctionList(_includeInheritedFunctions);
map<util::FixedHash<4>, FunctionTypePointer> exportedFunctions; std::map<util::FixedHash<4>, FunctionTypePointer> exportedFunctions;
for (auto const& it: exportedFunctionList) for (auto const& it: exportedFunctionList)
exportedFunctions.insert(it); exportedFunctions.insert(it);
@ -208,11 +207,11 @@ FunctionDefinition const* ContractDefinition::receiveFunction() const
return nullptr; return nullptr;
} }
vector<EventDefinition const*> const& ContractDefinition::definedInterfaceEvents() const std::vector<EventDefinition const*> const& ContractDefinition::definedInterfaceEvents() const
{ {
return m_interfaceEvents.init([&]{ return m_interfaceEvents.init([&]{
set<string> eventsSeen; std::set<std::string> eventsSeen;
vector<EventDefinition const*> interfaceEvents; std::vector<EventDefinition const*> interfaceEvents;
for (ContractDefinition const* contract: annotation().linearizedBaseContracts) for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
for (EventDefinition const* e: contract->events()) for (EventDefinition const* e: contract->events())
@ -222,7 +221,7 @@ vector<EventDefinition const*> const& ContractDefinition::definedInterfaceEvents
/// and not to function encoding (jump vs. call) /// and not to function encoding (jump vs. call)
FunctionType const* functionType = e->functionType(true); FunctionType const* functionType = e->functionType(true);
solAssert(functionType, ""); solAssert(functionType, "");
string eventSignature = functionType->externalSignature(); std::string eventSignature = functionType->externalSignature();
if (eventsSeen.count(eventSignature) == 0) if (eventsSeen.count(eventSignature) == 0)
{ {
eventsSeen.insert(eventSignature); eventsSeen.insert(eventSignature);
@ -233,7 +232,7 @@ vector<EventDefinition const*> const& ContractDefinition::definedInterfaceEvents
}); });
} }
vector<EventDefinition const*> const ContractDefinition::usedInterfaceEvents() const std::vector<EventDefinition const*> const ContractDefinition::usedInterfaceEvents() const
{ {
solAssert(annotation().creationCallGraph.set(), ""); solAssert(annotation().creationCallGraph.set(), "");
@ -243,9 +242,9 @@ vector<EventDefinition const*> const ContractDefinition::usedInterfaceEvents() c
); );
} }
vector<EventDefinition const*> ContractDefinition::interfaceEvents(bool _requireCallGraph) const std::vector<EventDefinition const*> ContractDefinition::interfaceEvents(bool _requireCallGraph) const
{ {
set<EventDefinition const*, CompareByID> result; std::set<EventDefinition const*, CompareByID> result;
for (ContractDefinition const* contract: annotation().linearizedBaseContracts) for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
result += contract->events(); result += contract->events();
solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set()); solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set());
@ -255,12 +254,12 @@ vector<EventDefinition const*> ContractDefinition::interfaceEvents(bool _require
result += usedInterfaceEvents(); result += usedInterfaceEvents();
// We could filter out all events that do not have an external interface // We could filter out all events that do not have an external interface
// if _requireCallGraph is false. // if _requireCallGraph is false.
return util::convertContainer<vector<EventDefinition const*>>(std::move(result)); return util::convertContainer<std::vector<EventDefinition const*>>(std::move(result));
} }
vector<ErrorDefinition const*> ContractDefinition::interfaceErrors(bool _requireCallGraph) const std::vector<ErrorDefinition const*> ContractDefinition::interfaceErrors(bool _requireCallGraph) const
{ {
set<ErrorDefinition const*, CompareByID> result; std::set<ErrorDefinition const*, CompareByID> result;
for (ContractDefinition const* contract: annotation().linearizedBaseContracts) for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
result += filteredNodes<ErrorDefinition>(contract->m_subNodes); result += filteredNodes<ErrorDefinition>(contract->m_subNodes);
solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set(), ""); solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set(), "");
@ -270,20 +269,20 @@ vector<ErrorDefinition const*> ContractDefinition::interfaceErrors(bool _require
result += result +=
(*annotation().creationCallGraph)->usedErrors + (*annotation().creationCallGraph)->usedErrors +
(*annotation().deployedCallGraph)->usedErrors; (*annotation().deployedCallGraph)->usedErrors;
return util::convertContainer<vector<ErrorDefinition const*>>(std::move(result)); return util::convertContainer<std::vector<ErrorDefinition const*>>(std::move(result));
} }
vector<pair<util::FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::interfaceFunctionList(bool _includeInheritedFunctions) const std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::interfaceFunctionList(bool _includeInheritedFunctions) const
{ {
return m_interfaceFunctionList[_includeInheritedFunctions].init([&]{ return m_interfaceFunctionList[_includeInheritedFunctions].init([&]{
set<string> signaturesSeen; std::set<std::string> signaturesSeen;
vector<pair<util::FixedHash<4>, FunctionTypePointer>> interfaceFunctionList; std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>> interfaceFunctionList;
for (ContractDefinition const* contract: annotation().linearizedBaseContracts) for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
{ {
if (_includeInheritedFunctions == false && contract != this) if (_includeInheritedFunctions == false && contract != this)
continue; continue;
vector<FunctionTypePointer> functions; std::vector<FunctionTypePointer> functions;
for (FunctionDefinition const* f: contract->definedFunctions()) for (FunctionDefinition const* f: contract->definedFunctions())
if (f->isPartOfExternalInterface()) if (f->isPartOfExternalInterface())
functions.push_back(TypeProvider::function(*f, FunctionType::Kind::External)); functions.push_back(TypeProvider::function(*f, FunctionType::Kind::External));
@ -295,7 +294,7 @@ vector<pair<util::FixedHash<4>, FunctionTypePointer>> const& ContractDefinition:
if (!fun->interfaceFunctionType()) if (!fun->interfaceFunctionType())
// Fails hopefully because we already registered the error // Fails hopefully because we already registered the error
continue; continue;
string functionSignature = fun->externalSignature(); std::string functionSignature = fun->externalSignature();
if (signaturesSeen.count(functionSignature) == 0) if (signaturesSeen.count(functionSignature) == 0)
{ {
signaturesSeen.insert(functionSignature); signaturesSeen.insert(functionSignature);
@ -357,7 +356,7 @@ FunctionDefinition const* ContractDefinition::nextConstructor(ContractDefinition
return nullptr; return nullptr;
} }
multimap<std::string, FunctionDefinition const*> const& ContractDefinition::definedFunctionsByName() const std::multimap<std::string, FunctionDefinition const*> const& ContractDefinition::definedFunctionsByName() const
{ {
return m_definedFunctionsByName.init([&]{ return m_definedFunctionsByName.init([&]{
std::multimap<std::string, FunctionDefinition const*> result; std::multimap<std::string, FunctionDefinition const*> result;
@ -386,7 +385,7 @@ TypeDeclarationAnnotation& UserDefinedValueTypeDefinition::annotation() const
std::vector<std::pair<ASTPointer<IdentifierPath>, std::optional<Token>>> UsingForDirective::functionsAndOperators() const std::vector<std::pair<ASTPointer<IdentifierPath>, std::optional<Token>>> UsingForDirective::functionsAndOperators() const
{ {
return ranges::zip_view(m_functionsOrLibrary, m_operators) | ranges::to<vector>; return ranges::zip_view(m_functionsOrLibrary, m_operators) | ranges::to<std::vector>;
} }
Type const* StructDefinition::type() const Type const* StructDefinition::type() const
@ -484,12 +483,12 @@ Type const* FunctionDefinition::typeViaContractName() const
return TypeProvider::function(*this, FunctionType::Kind::Declaration); return TypeProvider::function(*this, FunctionType::Kind::Declaration);
} }
string FunctionDefinition::externalSignature() const std::string FunctionDefinition::externalSignature() const
{ {
return TypeProvider::function(*this)->externalSignature(); return TypeProvider::function(*this)->externalSignature();
} }
string FunctionDefinition::externalIdentifierHex() const std::string FunctionDefinition::externalIdentifierHex() const
{ {
return TypeProvider::function(*this)->externalIdentifierHex(); return TypeProvider::function(*this)->externalIdentifierHex();
} }
@ -639,7 +638,7 @@ CallableDeclaration const* Scopable::functionOrModifierDefinition() const
return nullptr; return nullptr;
} }
string Scopable::sourceUnitName() const std::string Scopable::sourceUnitName() const
{ {
return *sourceUnit().annotation().path; return *sourceUnit().annotation().path;
} }
@ -701,7 +700,7 @@ bool VariableDeclaration::isCallableOrCatchParameter() const
if (isReturnParameter() || isTryCatchParameter()) if (isReturnParameter() || isTryCatchParameter())
return true; return true;
vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr; std::vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr;
if (auto const* funTypeName = dynamic_cast<FunctionTypeName const*>(scope())) if (auto const* funTypeName = dynamic_cast<FunctionTypeName const*>(scope()))
parameters = &funTypeName->parameterTypes(); parameters = &funTypeName->parameterTypes();
@ -722,7 +721,7 @@ bool VariableDeclaration::isLocalOrReturn() const
bool VariableDeclaration::isReturnParameter() const bool VariableDeclaration::isReturnParameter() const
{ {
vector<ASTPointer<VariableDeclaration>> const* returnParameters = nullptr; std::vector<ASTPointer<VariableDeclaration>> const* returnParameters = nullptr;
if (auto const* funTypeName = dynamic_cast<FunctionTypeName const*>(scope())) if (auto const* funTypeName = dynamic_cast<FunctionTypeName const*>(scope()))
returnParameters = &funTypeName->returnParameterTypes(); returnParameters = &funTypeName->returnParameterTypes();
@ -813,15 +812,15 @@ bool VariableDeclaration::isFileLevelVariable() const
return dynamic_cast<SourceUnit const*>(scope()); return dynamic_cast<SourceUnit const*>(scope());
} }
set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() const std::set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() const
{ {
using Location = VariableDeclaration::Location; using Location = VariableDeclaration::Location;
if (!hasReferenceOrMappingType() || isStateVariable() || isEventOrErrorParameter()) if (!hasReferenceOrMappingType() || isStateVariable() || isEventOrErrorParameter())
return set<Location>{ Location::Unspecified }; return std::set<Location>{ Location::Unspecified };
else if (isCallableOrCatchParameter()) else if (isCallableOrCatchParameter())
{ {
set<Location> locations{ Location::Memory }; std::set<Location> locations{ Location::Memory };
if ( if (
isConstructorParameter() || isConstructorParameter() ||
isInternalCallableParameter() || isInternalCallableParameter() ||
@ -835,13 +834,13 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
} }
else if (isLocalVariable()) else if (isLocalVariable())
// Further restrictions will be imposed later on. // Further restrictions will be imposed later on.
return set<Location>{ Location::Memory, Location::Storage, Location::CallData }; return std::set<Location>{ Location::Memory, Location::Storage, Location::CallData };
else else
// Struct members etc. // Struct members etc.
return set<Location>{ Location::Unspecified }; return std::set<Location>{ Location::Unspecified };
} }
string VariableDeclaration::externalIdentifierHex() const std::string VariableDeclaration::externalIdentifierHex() const
{ {
solAssert(isStateVariable() && isPublic(), "Can only be called for public state variables"); solAssert(isStateVariable() && isPublic(), "Can only be called for public state variables");
return TypeProvider::function(*this)->externalIdentifierHex(); return TypeProvider::function(*this)->externalIdentifierHex();
@ -958,7 +957,7 @@ FunctionCallAnnotation& FunctionCall::annotation() const
return initAnnotation<FunctionCallAnnotation>(); return initAnnotation<FunctionCallAnnotation>();
} }
vector<ASTPointer<Expression const>> FunctionCall::sortedArguments() const std::vector<ASTPointer<Expression const>> FunctionCall::sortedArguments() const
{ {
// normal arguments // normal arguments
if (m_names.empty()) if (m_names.empty())
@ -975,7 +974,7 @@ vector<ASTPointer<Expression const>> FunctionCall::sortedArguments() const
else else
functionType = dynamic_cast<FunctionType const*>(m_expression->annotation().type); functionType = dynamic_cast<FunctionType const*>(m_expression->annotation().type);
vector<ASTPointer<Expression const>> sorted; std::vector<ASTPointer<Expression const>> sorted;
for (auto const& parameterName: functionType->parameterNames()) for (auto const& parameterName: functionType->parameterNames())
{ {
bool found = false; bool found = false;
@ -1030,13 +1029,13 @@ bool Literal::passesAddressChecksum() const
return util::passesAddressChecksum(valueWithoutUnderscores(), true); return util::passesAddressChecksum(valueWithoutUnderscores(), true);
} }
string Literal::getChecksummedAddress() const std::string Literal::getChecksummedAddress() const
{ {
solAssert(isHexNumber(), "Expected hex number"); solAssert(isHexNumber(), "Expected hex number");
/// Pad literal to be a proper hex address. /// Pad literal to be a proper hex address.
string address = valueWithoutUnderscores().substr(2); std::string address = valueWithoutUnderscores().substr(2);
if (address.length() > 40) if (address.length() > 40)
return string(); return std::string();
address.insert(address.begin(), 40 - address.size(), '0'); address.insert(address.begin(), 40 - address.size(), '0');
return util::getChecksummedAddress(address); return util::getChecksummedAddress(address);
} }

View File

@ -23,7 +23,6 @@
#include <libsolidity/ast/ASTAnnotations.h> #include <libsolidity/ast/ASTAnnotations.h>
using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::frontend; using namespace solidity::frontend;

View File

@ -44,7 +44,6 @@
#include <type_traits> #include <type_traits>
#include <range/v3/view/map.hpp> #include <range/v3/view/map.hpp>
using namespace std;
using namespace std::string_literals; using namespace std::string_literals;
using namespace solidity::langutil; using namespace solidity::langutil;
@ -52,14 +51,14 @@ namespace
{ {
template<typename V, template<typename> typename C> template<typename V, template<typename> typename C>
void addIfSet(std::vector<pair<string, Json::Value>>& _attributes, string const& _name, C<V> const& _value) void addIfSet(std::vector<std::pair<std::string, Json::Value>>& _attributes, std::string const& _name, C<V> const& _value)
{ {
if constexpr (std::is_same_v<C<V>, solidity::util::SetOnce<V>>) if constexpr (std::is_same_v<C<V>, solidity::util::SetOnce<V>>)
{ {
if (!_value.set()) if (!_value.set())
return; return;
} }
else if constexpr (std::is_same_v<C<V>, optional<V>>) else if constexpr (std::is_same_v<C<V>, std::optional<V>>)
{ {
if (!_value.has_value()) if (!_value.has_value())
return; return;
@ -73,7 +72,7 @@ void addIfSet(std::vector<pair<string, Json::Value>>& _attributes, string const&
namespace solidity::frontend namespace solidity::frontend
{ {
ASTJsonExporter::ASTJsonExporter(CompilerStack::State _stackState, map<string, unsigned> _sourceIndices): ASTJsonExporter::ASTJsonExporter(CompilerStack::State _stackState, std::map<std::string, unsigned> _sourceIndices):
m_stackState(_stackState), m_stackState(_stackState),
m_sourceIndices(std::move(_sourceIndices)) m_sourceIndices(std::move(_sourceIndices))
{ {
@ -82,21 +81,21 @@ ASTJsonExporter::ASTJsonExporter(CompilerStack::State _stackState, map<string, u
void ASTJsonExporter::setJsonNode( void ASTJsonExporter::setJsonNode(
ASTNode const& _node, ASTNode const& _node,
string const& _nodeName, std::string const& _nodeName,
initializer_list<pair<string, Json::Value>>&& _attributes std::initializer_list<std::pair<std::string, Json::Value>>&& _attributes
) )
{ {
ASTJsonExporter::setJsonNode( ASTJsonExporter::setJsonNode(
_node, _node,
_nodeName, _nodeName,
std::vector<pair<string, Json::Value>>(std::move(_attributes)) std::vector<std::pair<std::string, Json::Value>>(std::move(_attributes))
); );
} }
void ASTJsonExporter::setJsonNode( void ASTJsonExporter::setJsonNode(
ASTNode const& _node, ASTNode const& _node,
string const& _nodeType, std::string const& _nodeType,
std::vector<pair<string, Json::Value>>&& _attributes std::vector<std::pair<std::string, Json::Value>>&& _attributes
) )
{ {
m_currentValue = Json::objectValue; m_currentValue = Json::objectValue;
@ -110,24 +109,24 @@ void ASTJsonExporter::setJsonNode(
m_currentValue[e.first] = std::move(e.second); m_currentValue[e.first] = std::move(e.second);
} }
optional<size_t> ASTJsonExporter::sourceIndexFromLocation(SourceLocation const& _location) const std::optional<size_t> ASTJsonExporter::sourceIndexFromLocation(SourceLocation const& _location) const
{ {
if (_location.sourceName && m_sourceIndices.count(*_location.sourceName)) if (_location.sourceName && m_sourceIndices.count(*_location.sourceName))
return m_sourceIndices.at(*_location.sourceName); return m_sourceIndices.at(*_location.sourceName);
else else
return nullopt; return std::nullopt;
} }
string ASTJsonExporter::sourceLocationToString(SourceLocation const& _location) const std::string ASTJsonExporter::sourceLocationToString(SourceLocation const& _location) const
{ {
optional<size_t> sourceIndexOpt = sourceIndexFromLocation(_location); std::optional<size_t> sourceIndexOpt = sourceIndexFromLocation(_location);
int length = -1; int length = -1;
if (_location.start >= 0 && _location.end >= 0) if (_location.start >= 0 && _location.end >= 0)
length = _location.end - _location.start; length = _location.end - _location.start;
return to_string(_location.start) + ":" + to_string(length) + ":" + (sourceIndexOpt.has_value() ? to_string(sourceIndexOpt.value()) : "-1"); return std::to_string(_location.start) + ":" + std::to_string(length) + ":" + (sourceIndexOpt.has_value() ? std::to_string(sourceIndexOpt.value()) : "-1");
} }
Json::Value ASTJsonExporter::sourceLocationsToJson(vector<SourceLocation> const& _sourceLocations) const Json::Value ASTJsonExporter::sourceLocationsToJson(std::vector<SourceLocation> const& _sourceLocations) const
{ {
Json::Value locations = Json::arrayValue; Json::Value locations = Json::arrayValue;
@ -137,7 +136,7 @@ Json::Value ASTJsonExporter::sourceLocationsToJson(vector<SourceLocation> const&
return locations; return locations;
} }
string ASTJsonExporter::namePathToString(std::vector<ASTString> const& _namePath) std::string ASTJsonExporter::namePathToString(std::vector<ASTString> const& _namePath)
{ {
return boost::algorithm::join(_namePath, "."s); return boost::algorithm::join(_namePath, "."s);
} }
@ -164,13 +163,13 @@ Json::Value ASTJsonExporter::typePointerToJson(std::optional<FuncCallArguments>
} }
void ASTJsonExporter::appendExpressionAttributes( void ASTJsonExporter::appendExpressionAttributes(
std::vector<pair<string, Json::Value>>& _attributes, std::vector<std::pair<std::string, Json::Value>>& _attributes,
ExpressionAnnotation const& _annotation ExpressionAnnotation const& _annotation
) )
{ {
std::vector<pair<string, Json::Value>> exprAttributes = { std::vector<std::pair<std::string, Json::Value>> exprAttributes = {
make_pair("typeDescriptions", typePointerToJson(_annotation.type)), std::make_pair("typeDescriptions", typePointerToJson(_annotation.type)),
make_pair("argumentTypes", typePointerToJson(_annotation.arguments)) std::make_pair("argumentTypes", typePointerToJson(_annotation.arguments))
}; };
addIfSet(exprAttributes, "isLValue", _annotation.isLValue); addIfSet(exprAttributes, "isLValue", _annotation.isLValue);
@ -183,7 +182,7 @@ void ASTJsonExporter::appendExpressionAttributes(
_attributes += exprAttributes; _attributes += exprAttributes;
} }
Json::Value ASTJsonExporter::inlineAssemblyIdentifierToJson(pair<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const Json::Value ASTJsonExporter::inlineAssemblyIdentifierToJson(std::pair<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const
{ {
Json::Value tuple(Json::objectValue); Json::Value tuple(Json::objectValue);
tuple["src"] = sourceLocationToString(nativeLocationOf(*_info.first)); tuple["src"] = sourceLocationToString(nativeLocationOf(*_info.first));
@ -199,7 +198,7 @@ Json::Value ASTJsonExporter::inlineAssemblyIdentifierToJson(pair<yul::Identifier
return tuple; return tuple;
} }
void ASTJsonExporter::print(ostream& _stream, ASTNode const& _node, util::JsonFormat const& _format) void ASTJsonExporter::print(std::ostream& _stream, ASTNode const& _node, util::JsonFormat const& _format)
{ {
_stream << util::jsonPrint(toJson(_node), _format); _stream << util::jsonPrint(toJson(_node), _format);
} }
@ -212,9 +211,9 @@ Json::Value ASTJsonExporter::toJson(ASTNode const& _node)
bool ASTJsonExporter::visit(SourceUnit const& _node) bool ASTJsonExporter::visit(SourceUnit const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("license", _node.licenseString() ? Json::Value(*_node.licenseString()) : Json::nullValue), std::make_pair("license", _node.licenseString() ? Json::Value(*_node.licenseString()) : Json::nullValue),
make_pair("nodes", toJson(_node.nodes())), std::make_pair("nodes", toJson(_node.nodes())),
}; };
if (_node.experimentalSolidity()) if (_node.experimentalSolidity())
@ -246,17 +245,17 @@ bool ASTJsonExporter::visit(PragmaDirective const& _node)
for (auto const& literal: _node.literals()) for (auto const& literal: _node.literals())
literals.append(literal); literals.append(literal);
setJsonNode(_node, "PragmaDirective", { setJsonNode(_node, "PragmaDirective", {
make_pair("literals", std::move(literals)) std::make_pair("literals", std::move(literals))
}); });
return false; return false;
} }
bool ASTJsonExporter::visit(ImportDirective const& _node) bool ASTJsonExporter::visit(ImportDirective const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("file", _node.path()), std::make_pair("file", _node.path()),
make_pair("sourceUnit", idOrNull(_node.annotation().sourceUnit)), std::make_pair("sourceUnit", idOrNull(_node.annotation().sourceUnit)),
make_pair("scope", idOrNull(_node.scope())) std::make_pair("scope", idOrNull(_node.scope()))
}; };
addIfSet(attributes, "absolutePath", _node.annotation().absolutePath); addIfSet(attributes, "absolutePath", _node.annotation().absolutePath);
@ -281,19 +280,19 @@ bool ASTJsonExporter::visit(ImportDirective const& _node)
bool ASTJsonExporter::visit(ContractDefinition const& _node) bool ASTJsonExporter::visit(ContractDefinition const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("contractKind", contractKind(_node.contractKind())), std::make_pair("contractKind", contractKind(_node.contractKind())),
make_pair("abstract", _node.abstract()), std::make_pair("abstract", _node.abstract()),
make_pair("baseContracts", toJson(_node.baseContracts())), std::make_pair("baseContracts", toJson(_node.baseContracts())),
make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies | ranges::views::keys)), std::make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies | ranges::views::keys)),
// Do not require call graph because the AST is also created for incorrect sources. // Do not require call graph because the AST is also created for incorrect sources.
make_pair("usedEvents", getContainerIds(_node.interfaceEvents(false))), std::make_pair("usedEvents", getContainerIds(_node.interfaceEvents(false))),
make_pair("usedErrors", getContainerIds(_node.interfaceErrors(false))), std::make_pair("usedErrors", getContainerIds(_node.interfaceErrors(false))),
make_pair("nodes", toJson(_node.subNodes())), std::make_pair("nodes", toJson(_node.subNodes())),
make_pair("scope", idOrNull(_node.scope())) std::make_pair("scope", idOrNull(_node.scope()))
}; };
addIfSet(attributes, "canonicalName", _node.annotation().canonicalName); addIfSet(attributes, "canonicalName", _node.annotation().canonicalName);
@ -306,7 +305,7 @@ bool ASTJsonExporter::visit(ContractDefinition const& _node)
{ {
Json::Value internalFunctionIDs(Json::objectValue); Json::Value internalFunctionIDs(Json::objectValue);
for (auto const& [functionDefinition, internalFunctionID]: _node.annotation().internalFunctionIDs) for (auto const& [functionDefinition, internalFunctionID]: _node.annotation().internalFunctionIDs)
internalFunctionIDs[to_string(functionDefinition->id())] = internalFunctionID; internalFunctionIDs[std::to_string(functionDefinition->id())] = internalFunctionID;
attributes.emplace_back("internalFunctionIDs", std::move(internalFunctionIDs)); attributes.emplace_back("internalFunctionIDs", std::move(internalFunctionIDs));
} }
@ -322,9 +321,9 @@ bool ASTJsonExporter::visit(IdentifierPath const& _node)
nameLocations.append(sourceLocationToString(location)); nameLocations.append(sourceLocationToString(location));
setJsonNode(_node, "IdentifierPath", { setJsonNode(_node, "IdentifierPath", {
make_pair("name", namePathToString(_node.path())), std::make_pair("name", namePathToString(_node.path())),
make_pair("nameLocations", nameLocations), std::make_pair("nameLocations", nameLocations),
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)) std::make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration))
}); });
return false; return false;
} }
@ -332,16 +331,16 @@ bool ASTJsonExporter::visit(IdentifierPath const& _node)
bool ASTJsonExporter::visit(InheritanceSpecifier const& _node) bool ASTJsonExporter::visit(InheritanceSpecifier const& _node)
{ {
setJsonNode(_node, "InheritanceSpecifier", { setJsonNode(_node, "InheritanceSpecifier", {
make_pair("baseName", toJson(_node.name())), std::make_pair("baseName", toJson(_node.name())),
make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue) std::make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue)
}); });
return false; return false;
} }
bool ASTJsonExporter::visit(UsingForDirective const& _node) bool ASTJsonExporter::visit(UsingForDirective const& _node)
{ {
vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("typeName", _node.typeName() ? toJson(*_node.typeName()) : Json::nullValue) std::make_pair("typeName", _node.typeName() ? toJson(*_node.typeName()) : Json::nullValue)
}; };
if (_node.usesBraces()) if (_node.usesBraces())
@ -355,7 +354,7 @@ bool ASTJsonExporter::visit(UsingForDirective const& _node)
else else
{ {
functionNode["definition"] = toJson(*function); functionNode["definition"] = toJson(*function);
functionNode["operator"] = string(TokenTraits::toString(*op)); functionNode["operator"] = std::string(TokenTraits::toString(*op));
} }
functionList.append(std::move(functionNode)); functionList.append(std::move(functionNode));
} }
@ -377,13 +376,13 @@ bool ASTJsonExporter::visit(UsingForDirective const& _node)
bool ASTJsonExporter::visit(StructDefinition const& _node) bool ASTJsonExporter::visit(StructDefinition const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())), std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("members", toJson(_node.members())), std::make_pair("members", toJson(_node.members())),
make_pair("scope", idOrNull(_node.scope())) std::make_pair("scope", idOrNull(_node.scope()))
}; };
addIfSet(attributes,"canonicalName", _node.annotation().canonicalName); addIfSet(attributes,"canonicalName", _node.annotation().canonicalName);
@ -395,11 +394,11 @@ bool ASTJsonExporter::visit(StructDefinition const& _node)
bool ASTJsonExporter::visit(EnumDefinition const& _node) bool ASTJsonExporter::visit(EnumDefinition const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("members", toJson(_node.members())) std::make_pair("members", toJson(_node.members()))
}; };
addIfSet(attributes,"canonicalName", _node.annotation().canonicalName); addIfSet(attributes,"canonicalName", _node.annotation().canonicalName);
@ -412,8 +411,8 @@ bool ASTJsonExporter::visit(EnumDefinition const& _node)
bool ASTJsonExporter::visit(EnumValue const& _node) bool ASTJsonExporter::visit(EnumValue const& _node)
{ {
setJsonNode(_node, "EnumValue", { setJsonNode(_node, "EnumValue", {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
}); });
return false; return false;
} }
@ -421,10 +420,10 @@ bool ASTJsonExporter::visit(EnumValue const& _node)
bool ASTJsonExporter::visit(UserDefinedValueTypeDefinition const& _node) bool ASTJsonExporter::visit(UserDefinedValueTypeDefinition const& _node)
{ {
solAssert(_node.underlyingType(), ""); solAssert(_node.underlyingType(), "");
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("underlyingType", toJson(*_node.underlyingType())) std::make_pair("underlyingType", toJson(*_node.underlyingType()))
}; };
addIfSet(attributes, "canonicalName", _node.annotation().canonicalName); addIfSet(attributes, "canonicalName", _node.annotation().canonicalName);
@ -436,7 +435,7 @@ bool ASTJsonExporter::visit(UserDefinedValueTypeDefinition const& _node)
bool ASTJsonExporter::visit(ParameterList const& _node) bool ASTJsonExporter::visit(ParameterList const& _node)
{ {
setJsonNode(_node, "ParameterList", { setJsonNode(_node, "ParameterList", {
make_pair("parameters", toJson(_node.parameters())) std::make_pair("parameters", toJson(_node.parameters()))
}); });
return false; return false;
} }
@ -444,30 +443,30 @@ bool ASTJsonExporter::visit(ParameterList const& _node)
bool ASTJsonExporter::visit(OverrideSpecifier const& _node) bool ASTJsonExporter::visit(OverrideSpecifier const& _node)
{ {
setJsonNode(_node, "OverrideSpecifier", { setJsonNode(_node, "OverrideSpecifier", {
make_pair("overrides", toJson(_node.overrides())) std::make_pair("overrides", toJson(_node.overrides()))
}); });
return false; return false;
} }
bool ASTJsonExporter::visit(FunctionDefinition const& _node) bool ASTJsonExporter::visit(FunctionDefinition const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("kind", _node.isFree() ? "freeFunction" : TokenTraits::toString(_node.kind())), std::make_pair("kind", _node.isFree() ? "freeFunction" : TokenTraits::toString(_node.kind())),
make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())), std::make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
make_pair("virtual", _node.markedVirtual()), std::make_pair("virtual", _node.markedVirtual()),
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), std::make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
make_pair("parameters", toJson(_node.parameterList())), std::make_pair("parameters", toJson(_node.parameterList())),
make_pair("returnParameters", toJson(*_node.returnParameterList())), std::make_pair("returnParameters", toJson(*_node.returnParameterList())),
make_pair("modifiers", toJson(_node.modifiers())), std::make_pair("modifiers", toJson(_node.modifiers())),
make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue), std::make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue),
make_pair("implemented", _node.isImplemented()), std::make_pair("implemented", _node.isImplemented()),
make_pair("scope", idOrNull(_node.scope())) std::make_pair("scope", idOrNull(_node.scope()))
}; };
optional<Visibility> visibility; std::optional<Visibility> visibility;
if (_node.isConstructor()) if (_node.isConstructor())
{ {
if (_node.annotation().contract) if (_node.annotation().contract)
@ -482,7 +481,7 @@ bool ASTJsonExporter::visit(FunctionDefinition const& _node)
if (_node.isPartOfExternalInterface() && m_stackState > CompilerStack::State::ParsedAndImported) if (_node.isPartOfExternalInterface() && m_stackState > CompilerStack::State::ParsedAndImported)
attributes.emplace_back("functionSelector", _node.externalIdentifierHex()); attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
if (!_node.annotation().baseFunctions.empty()) if (!_node.annotation().baseFunctions.empty())
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true))); attributes.emplace_back(std::make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
setJsonNode(_node, "FunctionDefinition", std::move(attributes)); setJsonNode(_node, "FunctionDefinition", std::move(attributes));
return false; return false;
@ -490,19 +489,19 @@ bool ASTJsonExporter::visit(FunctionDefinition const& _node)
bool ASTJsonExporter::visit(VariableDeclaration const& _node) bool ASTJsonExporter::visit(VariableDeclaration const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("typeName", toJson(_node.typeName())), std::make_pair("typeName", toJson(_node.typeName())),
make_pair("constant", _node.isConstant()), std::make_pair("constant", _node.isConstant()),
make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())), std::make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())),
make_pair("stateVariable", _node.isStateVariable()), std::make_pair("stateVariable", _node.isStateVariable()),
make_pair("storageLocation", location(_node.referenceLocation())), std::make_pair("storageLocation", location(_node.referenceLocation())),
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), std::make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())), std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("value", _node.value() ? toJson(*_node.value()) : Json::nullValue), std::make_pair("value", _node.value() ? toJson(*_node.value()) : Json::nullValue),
make_pair("scope", idOrNull(_node.scope())), std::make_pair("scope", idOrNull(_node.scope())),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
}; };
if (_node.isStateVariable() && _node.isPublic()) if (_node.isStateVariable() && _node.isPublic())
attributes.emplace_back("functionSelector", _node.externalIdentifierHex()); attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
@ -511,34 +510,34 @@ bool ASTJsonExporter::visit(VariableDeclaration const& _node)
if (m_inEvent) if (m_inEvent)
attributes.emplace_back("indexed", _node.isIndexed()); attributes.emplace_back("indexed", _node.isIndexed());
if (!_node.annotation().baseFunctions.empty()) if (!_node.annotation().baseFunctions.empty())
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true))); attributes.emplace_back(std::make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
setJsonNode(_node, "VariableDeclaration", std::move(attributes)); setJsonNode(_node, "VariableDeclaration", std::move(attributes));
return false; return false;
} }
bool ASTJsonExporter::visit(ModifierDefinition const& _node) bool ASTJsonExporter::visit(ModifierDefinition const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())), std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("parameters", toJson(_node.parameterList())), std::make_pair("parameters", toJson(_node.parameterList())),
make_pair("virtual", _node.markedVirtual()), std::make_pair("virtual", _node.markedVirtual()),
make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), std::make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue),
make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue) std::make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue)
}; };
if (!_node.annotation().baseFunctions.empty()) if (!_node.annotation().baseFunctions.empty())
attributes.emplace_back(make_pair("baseModifiers", getContainerIds(_node.annotation().baseFunctions, true))); attributes.emplace_back(std::make_pair("baseModifiers", getContainerIds(_node.annotation().baseFunctions, true)));
setJsonNode(_node, "ModifierDefinition", std::move(attributes)); setJsonNode(_node, "ModifierDefinition", std::move(attributes));
return false; return false;
} }
bool ASTJsonExporter::visit(ModifierInvocation const& _node) bool ASTJsonExporter::visit(ModifierInvocation const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes{ std::vector<std::pair<std::string, Json::Value>> attributes{
make_pair("modifierName", toJson(_node.name())), std::make_pair("modifierName", toJson(_node.name())),
make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue) std::make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue)
}; };
if (Declaration const* declaration = _node.name().annotation().referencedDeclaration) if (Declaration const* declaration = _node.name().annotation().referencedDeclaration)
{ {
@ -554,16 +553,16 @@ bool ASTJsonExporter::visit(ModifierInvocation const& _node)
bool ASTJsonExporter::visit(EventDefinition const& _node) bool ASTJsonExporter::visit(EventDefinition const& _node)
{ {
m_inEvent = true; m_inEvent = true;
std::vector<pair<string, Json::Value>> _attributes = { std::vector<std::pair<std::string, Json::Value>> _attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("parameters", toJson(_node.parameterList())), std::make_pair("parameters", toJson(_node.parameterList())),
make_pair("anonymous", _node.isAnonymous()) std::make_pair("anonymous", _node.isAnonymous())
}; };
if (m_stackState >= CompilerStack::State::AnalysisPerformed) if (m_stackState >= CompilerStack::State::AnalysisPerformed)
_attributes.emplace_back( _attributes.emplace_back(
make_pair( std::make_pair(
"eventSelector", "eventSelector",
toHex(u256(util::h256::Arith(util::keccak256(_node.functionType(true)->externalSignature())))) toHex(u256(util::h256::Arith(util::keccak256(_node.functionType(true)->externalSignature()))))
)); ));
@ -574,14 +573,14 @@ bool ASTJsonExporter::visit(EventDefinition const& _node)
bool ASTJsonExporter::visit(ErrorDefinition const& _node) bool ASTJsonExporter::visit(ErrorDefinition const& _node)
{ {
std::vector<pair<string, Json::Value>> _attributes = { std::vector<std::pair<std::string, Json::Value>> _attributes = {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("parameters", toJson(_node.parameterList())) std::make_pair("parameters", toJson(_node.parameterList()))
}; };
if (m_stackState >= CompilerStack::State::AnalysisPerformed) if (m_stackState >= CompilerStack::State::AnalysisPerformed)
_attributes.emplace_back(make_pair("errorSelector", _node.functionType(true)->externalIdentifierHex())); _attributes.emplace_back(std::make_pair("errorSelector", _node.functionType(true)->externalIdentifierHex()));
setJsonNode(_node, "ErrorDefinition", std::move(_attributes)); setJsonNode(_node, "ErrorDefinition", std::move(_attributes));
return false; return false;
@ -589,13 +588,13 @@ bool ASTJsonExporter::visit(ErrorDefinition const& _node)
bool ASTJsonExporter::visit(ElementaryTypeName const& _node) bool ASTJsonExporter::visit(ElementaryTypeName const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("name", _node.typeName().toString()), std::make_pair("name", _node.typeName().toString()),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
}; };
if (_node.stateMutability()) if (_node.stateMutability())
attributes.emplace_back(make_pair("stateMutability", stateMutabilityToString(*_node.stateMutability()))); attributes.emplace_back(std::make_pair("stateMutability", stateMutabilityToString(*_node.stateMutability())));
setJsonNode(_node, "ElementaryTypeName", std::move(attributes)); setJsonNode(_node, "ElementaryTypeName", std::move(attributes));
return false; return false;
@ -604,9 +603,9 @@ bool ASTJsonExporter::visit(ElementaryTypeName const& _node)
bool ASTJsonExporter::visit(UserDefinedTypeName const& _node) bool ASTJsonExporter::visit(UserDefinedTypeName const& _node)
{ {
setJsonNode(_node, "UserDefinedTypeName", { setJsonNode(_node, "UserDefinedTypeName", {
make_pair("pathNode", toJson(_node.pathNode())), std::make_pair("pathNode", toJson(_node.pathNode())),
make_pair("referencedDeclaration", idOrNull(_node.pathNode().annotation().referencedDeclaration)), std::make_pair("referencedDeclaration", idOrNull(_node.pathNode().annotation().referencedDeclaration)),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
}); });
return false; return false;
} }
@ -614,11 +613,11 @@ bool ASTJsonExporter::visit(UserDefinedTypeName const& _node)
bool ASTJsonExporter::visit(FunctionTypeName const& _node) bool ASTJsonExporter::visit(FunctionTypeName const& _node)
{ {
setJsonNode(_node, "FunctionTypeName", { setJsonNode(_node, "FunctionTypeName", {
make_pair("visibility", Declaration::visibilityToString(_node.visibility())), std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())), std::make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
make_pair("parameterTypes", toJson(*_node.parameterTypeList())), std::make_pair("parameterTypes", toJson(*_node.parameterTypeList())),
make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())), std::make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
}); });
return false; return false;
} }
@ -626,13 +625,13 @@ bool ASTJsonExporter::visit(FunctionTypeName const& _node)
bool ASTJsonExporter::visit(Mapping const& _node) bool ASTJsonExporter::visit(Mapping const& _node)
{ {
setJsonNode(_node, "Mapping", { setJsonNode(_node, "Mapping", {
make_pair("keyType", toJson(_node.keyType())), std::make_pair("keyType", toJson(_node.keyType())),
make_pair("keyName", _node.keyName()), std::make_pair("keyName", _node.keyName()),
make_pair("keyNameLocation", sourceLocationToString(_node.keyNameLocation())), std::make_pair("keyNameLocation", sourceLocationToString(_node.keyNameLocation())),
make_pair("valueType", toJson(_node.valueType())), std::make_pair("valueType", toJson(_node.valueType())),
make_pair("valueName", _node.valueName()), std::make_pair("valueName", _node.valueName()),
make_pair("valueNameLocation", sourceLocationToString(_node.valueNameLocation())), std::make_pair("valueNameLocation", sourceLocationToString(_node.valueNameLocation())),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
}); });
return false; return false;
} }
@ -640,20 +639,20 @@ bool ASTJsonExporter::visit(Mapping const& _node)
bool ASTJsonExporter::visit(ArrayTypeName const& _node) bool ASTJsonExporter::visit(ArrayTypeName const& _node)
{ {
setJsonNode(_node, "ArrayTypeName", { setJsonNode(_node, "ArrayTypeName", {
make_pair("baseType", toJson(_node.baseType())), std::make_pair("baseType", toJson(_node.baseType())),
make_pair("length", toJsonOrNull(_node.length())), std::make_pair("length", toJsonOrNull(_node.length())),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
}); });
return false; return false;
} }
bool ASTJsonExporter::visit(InlineAssembly const& _node) bool ASTJsonExporter::visit(InlineAssembly const& _node)
{ {
vector<pair<string, Json::Value>> externalReferences; std::vector<std::pair<std::string, Json::Value>> externalReferences;
for (auto const& it: _node.annotation().externalReferences) for (auto const& it: _node.annotation().externalReferences)
if (it.first) if (it.first)
externalReferences.emplace_back(make_pair( externalReferences.emplace_back(std::make_pair(
it.first->name.str(), it.first->name.str(),
inlineAssemblyIdentifierToJson(it) inlineAssemblyIdentifierToJson(it)
)); ));
@ -664,10 +663,10 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node)
for (Json::Value& it: externalReferences | ranges::views::values) for (Json::Value& it: externalReferences | ranges::views::values)
externalReferencesJson.append(std::move(it)); externalReferencesJson.append(std::move(it));
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))), std::make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))),
make_pair("externalReferences", std::move(externalReferencesJson)), std::make_pair("externalReferences", std::move(externalReferencesJson)),
make_pair("evmVersion", dynamic_cast<solidity::yul::EVMDialect const&>(_node.dialect()).evmVersion().name()) std::make_pair("evmVersion", dynamic_cast<solidity::yul::EVMDialect const&>(_node.dialect()).evmVersion().name())
}; };
if (_node.flags()) if (_node.flags())
@ -678,7 +677,7 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node)
flags.append(*flag); flags.append(*flag);
else else
flags.append(Json::nullValue); flags.append(Json::nullValue);
attributes.emplace_back(make_pair("flags", std::move(flags))); attributes.emplace_back(std::make_pair("flags", std::move(flags)));
} }
setJsonNode(_node, "InlineAssembly", std::move(attributes)); setJsonNode(_node, "InlineAssembly", std::move(attributes));
@ -688,7 +687,7 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node)
bool ASTJsonExporter::visit(Block const& _node) bool ASTJsonExporter::visit(Block const& _node)
{ {
setJsonNode(_node, _node.unchecked() ? "UncheckedBlock" : "Block", { setJsonNode(_node, _node.unchecked() ? "UncheckedBlock" : "Block", {
make_pair("statements", toJson(_node.statements())) std::make_pair("statements", toJson(_node.statements()))
}); });
return false; return false;
} }
@ -702,9 +701,9 @@ bool ASTJsonExporter::visit(PlaceholderStatement const& _node)
bool ASTJsonExporter::visit(IfStatement const& _node) bool ASTJsonExporter::visit(IfStatement const& _node)
{ {
setJsonNode(_node, "IfStatement", { setJsonNode(_node, "IfStatement", {
make_pair("condition", toJson(_node.condition())), std::make_pair("condition", toJson(_node.condition())),
make_pair("trueBody", toJson(_node.trueStatement())), std::make_pair("trueBody", toJson(_node.trueStatement())),
make_pair("falseBody", toJsonOrNull(_node.falseStatement())) std::make_pair("falseBody", toJsonOrNull(_node.falseStatement()))
}); });
return false; return false;
} }
@ -712,9 +711,9 @@ bool ASTJsonExporter::visit(IfStatement const& _node)
bool ASTJsonExporter::visit(TryCatchClause const& _node) bool ASTJsonExporter::visit(TryCatchClause const& _node)
{ {
setJsonNode(_node, "TryCatchClause", { setJsonNode(_node, "TryCatchClause", {
make_pair("errorName", _node.errorName()), std::make_pair("errorName", _node.errorName()),
make_pair("parameters", toJsonOrNull(_node.parameters())), std::make_pair("parameters", toJsonOrNull(_node.parameters())),
make_pair("block", toJson(_node.block())) std::make_pair("block", toJson(_node.block()))
}); });
return false; return false;
} }
@ -722,8 +721,8 @@ bool ASTJsonExporter::visit(TryCatchClause const& _node)
bool ASTJsonExporter::visit(TryStatement const& _node) bool ASTJsonExporter::visit(TryStatement const& _node)
{ {
setJsonNode(_node, "TryStatement", { setJsonNode(_node, "TryStatement", {
make_pair("externalCall", toJson(_node.externalCall())), std::make_pair("externalCall", toJson(_node.externalCall())),
make_pair("clauses", toJson(_node.clauses())) std::make_pair("clauses", toJson(_node.clauses()))
}); });
return false; return false;
} }
@ -734,8 +733,8 @@ bool ASTJsonExporter::visit(WhileStatement const& _node)
_node, _node,
_node.isDoWhile() ? "DoWhileStatement" : "WhileStatement", _node.isDoWhile() ? "DoWhileStatement" : "WhileStatement",
{ {
make_pair("condition", toJson(_node.condition())), std::make_pair("condition", toJson(_node.condition())),
make_pair("body", toJson(_node.body())) std::make_pair("body", toJson(_node.body()))
} }
); );
return false; return false;
@ -744,10 +743,10 @@ bool ASTJsonExporter::visit(WhileStatement const& _node)
bool ASTJsonExporter::visit(ForStatement const& _node) bool ASTJsonExporter::visit(ForStatement const& _node)
{ {
setJsonNode(_node, "ForStatement", { setJsonNode(_node, "ForStatement", {
make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())), std::make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())),
make_pair("condition", toJsonOrNull(_node.condition())), std::make_pair("condition", toJsonOrNull(_node.condition())),
make_pair("loopExpression", toJsonOrNull(_node.loopExpression())), std::make_pair("loopExpression", toJsonOrNull(_node.loopExpression())),
make_pair("body", toJson(_node.body())) std::make_pair("body", toJson(_node.body()))
}); });
return false; return false;
} }
@ -767,8 +766,8 @@ bool ASTJsonExporter::visit(Break const& _node)
bool ASTJsonExporter::visit(Return const& _node) bool ASTJsonExporter::visit(Return const& _node)
{ {
setJsonNode(_node, "Return", { setJsonNode(_node, "Return", {
make_pair("expression", toJsonOrNull(_node.expression())), std::make_pair("expression", toJsonOrNull(_node.expression())),
make_pair("functionReturnParameters", idOrNull(_node.annotation().functionReturnParameters)) std::make_pair("functionReturnParameters", idOrNull(_node.annotation().functionReturnParameters))
}); });
return false; return false;
} }
@ -782,7 +781,7 @@ bool ASTJsonExporter::visit(Throw const& _node)
bool ASTJsonExporter::visit(EmitStatement const& _node) bool ASTJsonExporter::visit(EmitStatement const& _node)
{ {
setJsonNode(_node, "EmitStatement", { setJsonNode(_node, "EmitStatement", {
make_pair("eventCall", toJson(_node.eventCall())) std::make_pair("eventCall", toJson(_node.eventCall()))
}); });
return false; return false;
} }
@ -790,7 +789,7 @@ bool ASTJsonExporter::visit(EmitStatement const& _node)
bool ASTJsonExporter::visit(RevertStatement const& _node) bool ASTJsonExporter::visit(RevertStatement const& _node)
{ {
setJsonNode(_node, "RevertStatement", { setJsonNode(_node, "RevertStatement", {
make_pair("errorCall", toJson(_node.errorCall())) std::make_pair("errorCall", toJson(_node.errorCall()))
}); });
return false; return false;
} }
@ -801,9 +800,9 @@ bool ASTJsonExporter::visit(VariableDeclarationStatement const& _node)
for (auto const& v: _node.declarations()) for (auto const& v: _node.declarations())
appendMove(varDecs, idOrNull(v.get())); appendMove(varDecs, idOrNull(v.get()));
setJsonNode(_node, "VariableDeclarationStatement", { setJsonNode(_node, "VariableDeclarationStatement", {
make_pair("assignments", std::move(varDecs)), std::make_pair("assignments", std::move(varDecs)),
make_pair("declarations", toJson(_node.declarations())), std::make_pair("declarations", toJson(_node.declarations())),
make_pair("initialValue", toJsonOrNull(_node.initialValue())) std::make_pair("initialValue", toJsonOrNull(_node.initialValue()))
}); });
return false; return false;
} }
@ -811,17 +810,17 @@ bool ASTJsonExporter::visit(VariableDeclarationStatement const& _node)
bool ASTJsonExporter::visit(ExpressionStatement const& _node) bool ASTJsonExporter::visit(ExpressionStatement const& _node)
{ {
setJsonNode(_node, "ExpressionStatement", { setJsonNode(_node, "ExpressionStatement", {
make_pair("expression", toJson(_node.expression())) std::make_pair("expression", toJson(_node.expression()))
}); });
return false; return false;
} }
bool ASTJsonExporter::visit(Conditional const& _node) bool ASTJsonExporter::visit(Conditional const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("condition", toJson(_node.condition())), std::make_pair("condition", toJson(_node.condition())),
make_pair("trueExpression", toJson(_node.trueExpression())), std::make_pair("trueExpression", toJson(_node.trueExpression())),
make_pair("falseExpression", toJson(_node.falseExpression())) std::make_pair("falseExpression", toJson(_node.falseExpression()))
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "Conditional", std::move(attributes)); setJsonNode(_node, "Conditional", std::move(attributes));
@ -830,10 +829,10 @@ bool ASTJsonExporter::visit(Conditional const& _node)
bool ASTJsonExporter::visit(Assignment const& _node) bool ASTJsonExporter::visit(Assignment const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("operator", TokenTraits::toString(_node.assignmentOperator())), std::make_pair("operator", TokenTraits::toString(_node.assignmentOperator())),
make_pair("leftHandSide", toJson(_node.leftHandSide())), std::make_pair("leftHandSide", toJson(_node.leftHandSide())),
make_pair("rightHandSide", toJson(_node.rightHandSide())) std::make_pair("rightHandSide", toJson(_node.rightHandSide()))
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "Assignment", std::move(attributes)); setJsonNode(_node, "Assignment", std::move(attributes));
@ -842,9 +841,9 @@ bool ASTJsonExporter::visit(Assignment const& _node)
bool ASTJsonExporter::visit(TupleExpression const& _node) bool ASTJsonExporter::visit(TupleExpression const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("isInlineArray", Json::Value(_node.isInlineArray())), std::make_pair("isInlineArray", Json::Value(_node.isInlineArray())),
make_pair("components", toJson(_node.components())), std::make_pair("components", toJson(_node.components())),
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "TupleExpression", std::move(attributes)); setJsonNode(_node, "TupleExpression", std::move(attributes));
@ -853,10 +852,10 @@ bool ASTJsonExporter::visit(TupleExpression const& _node)
bool ASTJsonExporter::visit(UnaryOperation const& _node) bool ASTJsonExporter::visit(UnaryOperation const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("prefix", _node.isPrefixOperation()), std::make_pair("prefix", _node.isPrefixOperation()),
make_pair("operator", TokenTraits::toString(_node.getOperator())), std::make_pair("operator", TokenTraits::toString(_node.getOperator())),
make_pair("subExpression", toJson(_node.subExpression())) std::make_pair("subExpression", toJson(_node.subExpression()))
}; };
// NOTE: This annotation is guaranteed to be set but only if we didn't stop at the parsing stage. // NOTE: This annotation is guaranteed to be set but only if we didn't stop at the parsing stage.
if (_node.annotation().userDefinedFunction.set() && *_node.annotation().userDefinedFunction != nullptr) if (_node.annotation().userDefinedFunction.set() && *_node.annotation().userDefinedFunction != nullptr)
@ -868,11 +867,11 @@ bool ASTJsonExporter::visit(UnaryOperation const& _node)
bool ASTJsonExporter::visit(BinaryOperation const& _node) bool ASTJsonExporter::visit(BinaryOperation const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("operator", TokenTraits::toString(_node.getOperator())), std::make_pair("operator", TokenTraits::toString(_node.getOperator())),
make_pair("leftExpression", toJson(_node.leftExpression())), std::make_pair("leftExpression", toJson(_node.leftExpression())),
make_pair("rightExpression", toJson(_node.rightExpression())), std::make_pair("rightExpression", toJson(_node.rightExpression())),
make_pair("commonType", typePointerToJson(_node.annotation().commonType)), std::make_pair("commonType", typePointerToJson(_node.annotation().commonType)),
}; };
// NOTE: This annotation is guaranteed to be set but only if we didn't stop at the parsing stage. // NOTE: This annotation is guaranteed to be set but only if we didn't stop at the parsing stage.
if (_node.annotation().userDefinedFunction.set() && *_node.annotation().userDefinedFunction != nullptr) if (_node.annotation().userDefinedFunction.set() && *_node.annotation().userDefinedFunction != nullptr)
@ -887,12 +886,12 @@ bool ASTJsonExporter::visit(FunctionCall const& _node)
Json::Value names(Json::arrayValue); Json::Value names(Json::arrayValue);
for (auto const& name: _node.names()) for (auto const& name: _node.names())
names.append(Json::Value(*name)); names.append(Json::Value(*name));
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("expression", toJson(_node.expression())), std::make_pair("expression", toJson(_node.expression())),
make_pair("names", std::move(names)), std::make_pair("names", std::move(names)),
make_pair("nameLocations", sourceLocationsToJson(_node.nameLocations())), std::make_pair("nameLocations", sourceLocationsToJson(_node.nameLocations())),
make_pair("arguments", toJson(_node.arguments())), std::make_pair("arguments", toJson(_node.arguments())),
make_pair("tryCall", _node.annotation().tryCall) std::make_pair("tryCall", _node.annotation().tryCall)
}; };
if (_node.annotation().kind.set()) if (_node.annotation().kind.set())
@ -912,10 +911,10 @@ bool ASTJsonExporter::visit(FunctionCallOptions const& _node)
for (auto const& name: _node.names()) for (auto const& name: _node.names())
names.append(Json::Value(*name)); names.append(Json::Value(*name));
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("expression", toJson(_node.expression())), std::make_pair("expression", toJson(_node.expression())),
make_pair("names", std::move(names)), std::make_pair("names", std::move(names)),
make_pair("options", toJson(_node.options())), std::make_pair("options", toJson(_node.options())),
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
@ -925,8 +924,8 @@ bool ASTJsonExporter::visit(FunctionCallOptions const& _node)
bool ASTJsonExporter::visit(NewExpression const& _node) bool ASTJsonExporter::visit(NewExpression const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("typeName", toJson(_node.typeName())) std::make_pair("typeName", toJson(_node.typeName()))
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "NewExpression", std::move(attributes)); setJsonNode(_node, "NewExpression", std::move(attributes));
@ -935,11 +934,11 @@ bool ASTJsonExporter::visit(NewExpression const& _node)
bool ASTJsonExporter::visit(MemberAccess const& _node) bool ASTJsonExporter::visit(MemberAccess const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("memberName", _node.memberName()), std::make_pair("memberName", _node.memberName()),
make_pair("memberLocation", Json::Value(sourceLocationToString(_node.memberLocation()))), std::make_pair("memberLocation", Json::Value(sourceLocationToString(_node.memberLocation()))),
make_pair("expression", toJson(_node.expression())), std::make_pair("expression", toJson(_node.expression())),
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)), std::make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "MemberAccess", std::move(attributes)); setJsonNode(_node, "MemberAccess", std::move(attributes));
@ -948,9 +947,9 @@ bool ASTJsonExporter::visit(MemberAccess const& _node)
bool ASTJsonExporter::visit(IndexAccess const& _node) bool ASTJsonExporter::visit(IndexAccess const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("baseExpression", toJson(_node.baseExpression())), std::make_pair("baseExpression", toJson(_node.baseExpression())),
make_pair("indexExpression", toJsonOrNull(_node.indexExpression())), std::make_pair("indexExpression", toJsonOrNull(_node.indexExpression())),
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "IndexAccess", std::move(attributes)); setJsonNode(_node, "IndexAccess", std::move(attributes));
@ -959,10 +958,10 @@ bool ASTJsonExporter::visit(IndexAccess const& _node)
bool ASTJsonExporter::visit(IndexRangeAccess const& _node) bool ASTJsonExporter::visit(IndexRangeAccess const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("baseExpression", toJson(_node.baseExpression())), std::make_pair("baseExpression", toJson(_node.baseExpression())),
make_pair("startExpression", toJsonOrNull(_node.startExpression())), std::make_pair("startExpression", toJsonOrNull(_node.startExpression())),
make_pair("endExpression", toJsonOrNull(_node.endExpression())), std::make_pair("endExpression", toJsonOrNull(_node.endExpression())),
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "IndexRangeAccess", std::move(attributes)); setJsonNode(_node, "IndexRangeAccess", std::move(attributes));
@ -975,19 +974,19 @@ bool ASTJsonExporter::visit(Identifier const& _node)
for (auto const& dec: _node.annotation().overloadedDeclarations) for (auto const& dec: _node.annotation().overloadedDeclarations)
overloads.append(nodeId(*dec)); overloads.append(nodeId(*dec));
setJsonNode(_node, "Identifier", { setJsonNode(_node, "Identifier", {
make_pair("name", _node.name()), std::make_pair("name", _node.name()),
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)), std::make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)),
make_pair("overloadedDeclarations", overloads), std::make_pair("overloadedDeclarations", overloads),
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)), std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)),
make_pair("argumentTypes", typePointerToJson(_node.annotation().arguments)) std::make_pair("argumentTypes", typePointerToJson(_node.annotation().arguments))
}); });
return false; return false;
} }
bool ASTJsonExporter::visit(ElementaryTypeNameExpression const& _node) bool ASTJsonExporter::visit(ElementaryTypeNameExpression const& _node)
{ {
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("typeName", toJson(_node.type())) std::make_pair("typeName", toJson(_node.type()))
}; };
appendExpressionAttributes(attributes, _node.annotation()); appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "ElementaryTypeNameExpression", std::move(attributes)); setJsonNode(_node, "ElementaryTypeNameExpression", std::move(attributes));
@ -1000,11 +999,11 @@ bool ASTJsonExporter::visit(Literal const& _node)
if (!util::validateUTF8(_node.value())) if (!util::validateUTF8(_node.value()))
value = Json::nullValue; value = Json::nullValue;
Token subdenomination = Token(_node.subDenomination()); Token subdenomination = Token(_node.subDenomination());
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("kind", literalTokenKind(_node.token())), std::make_pair("kind", literalTokenKind(_node.token())),
make_pair("value", value), std::make_pair("value", value),
make_pair("hexValue", util::toHex(util::asBytes(_node.value()))), std::make_pair("hexValue", util::toHex(util::asBytes(_node.value()))),
make_pair( std::make_pair(
"subdenomination", "subdenomination",
subdenomination == Token::Illegal ? subdenomination == Token::Illegal ?
Json::nullValue : Json::nullValue :
@ -1019,8 +1018,8 @@ bool ASTJsonExporter::visit(Literal const& _node)
bool ASTJsonExporter::visit(StructuredDocumentation const& _node) bool ASTJsonExporter::visit(StructuredDocumentation const& _node)
{ {
Json::Value text{*_node.text()}; Json::Value text{*_node.text()};
std::vector<pair<string, Json::Value>> attributes = { std::vector<std::pair<std::string, Json::Value>> attributes = {
make_pair("text", text) std::make_pair("text", text)
}; };
setJsonNode(_node, "StructuredDocumentation", std::move(attributes)); setJsonNode(_node, "StructuredDocumentation", std::move(attributes));
return false; return false;
@ -1033,7 +1032,7 @@ void ASTJsonExporter::endVisit(EventDefinition const&)
m_inEvent = false; m_inEvent = false;
} }
string ASTJsonExporter::location(VariableDeclaration::Location _location) std::string ASTJsonExporter::location(VariableDeclaration::Location _location)
{ {
switch (_location) switch (_location)
{ {
@ -1050,7 +1049,7 @@ string ASTJsonExporter::location(VariableDeclaration::Location _location)
return {}; return {};
} }
string ASTJsonExporter::contractKind(ContractKind _kind) std::string ASTJsonExporter::contractKind(ContractKind _kind)
{ {
switch (_kind) switch (_kind)
{ {
@ -1066,7 +1065,7 @@ string ASTJsonExporter::contractKind(ContractKind _kind)
return {}; return {};
} }
string ASTJsonExporter::functionCallKind(FunctionCallKind _kind) std::string ASTJsonExporter::functionCallKind(FunctionCallKind _kind)
{ {
switch (_kind) switch (_kind)
{ {
@ -1081,7 +1080,7 @@ string ASTJsonExporter::functionCallKind(FunctionCallKind _kind)
} }
} }
string ASTJsonExporter::literalTokenKind(Token _token) std::string ASTJsonExporter::literalTokenKind(Token _token)
{ {
switch (_token) switch (_token)
{ {
@ -1101,12 +1100,12 @@ string ASTJsonExporter::literalTokenKind(Token _token)
} }
} }
string ASTJsonExporter::type(Expression const& _expression) std::string ASTJsonExporter::type(Expression const& _expression)
{ {
return _expression.annotation().type ? _expression.annotation().type->toString() : "Unknown"; return _expression.annotation().type ? _expression.annotation().type->toString() : "Unknown";
} }
string ASTJsonExporter::type(VariableDeclaration const& _varDecl) std::string ASTJsonExporter::type(VariableDeclaration const& _varDecl)
{ {
return _varDecl.annotation().type ? _varDecl.annotation().type->toString() : "Unknown"; return _varDecl.annotation().type ? _varDecl.annotation().type->toString() : "Unknown";
} }

View File

@ -37,8 +37,6 @@
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
using namespace std;
namespace solidity::frontend namespace solidity::frontend
{ {
@ -50,16 +48,16 @@ ASTPointer<T> ASTJsonImporter::nullOrCast(Json::Value const& _json)
if (_json.isNull()) if (_json.isNull())
return nullptr; return nullptr;
else else
return dynamic_pointer_cast<T>(convertJsonToASTNode(_json)); return std::dynamic_pointer_cast<T>(convertJsonToASTNode(_json));
} }
// ============ public =========================== // ============ public ===========================
map<string, ASTPointer<SourceUnit>> ASTJsonImporter::jsonToSourceUnit(map<string, Json::Value> const& _sourceList) std::map<std::string, ASTPointer<SourceUnit>> ASTJsonImporter::jsonToSourceUnit(std::map<std::string, Json::Value> const& _sourceList)
{ {
for (auto const& src: _sourceList) for (auto const& src: _sourceList)
m_sourceNames.emplace_back(make_shared<string const>(src.first)); m_sourceNames.emplace_back(std::make_shared<std::string const>(src.first));
for (auto const& srcPair: _sourceList) for (auto const& srcPair: _sourceList)
{ {
astAssert(!srcPair.second.isNull()); astAssert(!srcPair.second.isNull());
@ -81,7 +79,7 @@ ASTPointer<T> ASTJsonImporter::createASTNode(Json::Value const& _node, Args&&...
astAssert(m_usedIDs.insert(id).second, "Found duplicate node ID!"); astAssert(m_usedIDs.insert(id).second, "Found duplicate node ID!");
auto n = make_shared<T>( auto n = std::make_shared<T>(
id, id,
createSourceLocation(_node), createSourceLocation(_node),
std::forward<Args>(_args)... std::forward<Args>(_args)...
@ -96,9 +94,9 @@ SourceLocation const ASTJsonImporter::createSourceLocation(Json::Value const& _n
return solidity::langutil::parseSourceLocation(_node["src"].asString(), m_sourceNames); return solidity::langutil::parseSourceLocation(_node["src"].asString(), m_sourceNames);
} }
optional<vector<SourceLocation>> ASTJsonImporter::createSourceLocations(Json::Value const& _node) const std::optional<std::vector<SourceLocation>> ASTJsonImporter::createSourceLocations(Json::Value const& _node) const
{ {
vector<SourceLocation> locations; std::vector<SourceLocation> locations;
if (_node.isMember("nameLocations") && _node["nameLocations"].isArray()) if (_node.isMember("nameLocations") && _node["nameLocations"].isArray())
{ {
@ -107,7 +105,7 @@ optional<vector<SourceLocation>> ASTJsonImporter::createSourceLocations(Json::Va
return locations; return locations;
} }
return nullopt; return std::nullopt;
} }
SourceLocation ASTJsonImporter::createNameSourceLocation(Json::Value const& _node) SourceLocation ASTJsonImporter::createNameSourceLocation(Json::Value const& _node)
@ -134,7 +132,7 @@ SourceLocation ASTJsonImporter::createValueNameSourceLocation(Json::Value const&
template<class T> template<class T>
ASTPointer<T> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _node) ASTPointer<T> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _node)
{ {
ASTPointer<T> ret = dynamic_pointer_cast<T>(convertJsonToASTNode(_node)); ASTPointer<T> ret = std::dynamic_pointer_cast<T>(convertJsonToASTNode(_node));
astAssert(ret, "cast of converted json-node must not be nullptr"); astAssert(ret, "cast of converted json-node must not be nullptr");
return ret; return ret;
} }
@ -143,7 +141,7 @@ ASTPointer<T> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _node)
ASTPointer<ASTNode> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _json) ASTPointer<ASTNode> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _json)
{ {
astAssert(_json["nodeType"].isString() && _json.isMember("id"), "JSON-Node needs to have 'nodeType' and 'id' fields."); astAssert(_json["nodeType"].isString() && _json.isMember("id"), "JSON-Node needs to have 'nodeType' and 'id' fields.");
string nodeType = _json["nodeType"].asString(); std::string nodeType = _json["nodeType"].asString();
if (nodeType == "PragmaDirective") if (nodeType == "PragmaDirective")
return createPragmaDirective(_json); return createPragmaDirective(_json);
if (nodeType == "ImportDirective") if (nodeType == "ImportDirective")
@ -265,9 +263,9 @@ ASTPointer<ASTNode> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _js
// ============ functions to instantiate the AST-Nodes from Json-Nodes ============== // ============ functions to instantiate the AST-Nodes from Json-Nodes ==============
ASTPointer<SourceUnit> ASTJsonImporter::createSourceUnit(Json::Value const& _node, string const& _srcName) ASTPointer<SourceUnit> ASTJsonImporter::createSourceUnit(Json::Value const& _node, std::string const& _srcName)
{ {
optional<string> license; std::optional<std::string> license;
if (_node.isMember("license") && !_node["license"].isNull()) if (_node.isMember("license") && !_node["license"].isNull())
license = _node["license"].asString(); license = _node["license"].asString();
@ -275,7 +273,7 @@ ASTPointer<SourceUnit> ASTJsonImporter::createSourceUnit(Json::Value const& _nod
if (_node.isMember("experimentalSolidity") && !_node["experimentalSolidity"].isNull()) if (_node.isMember("experimentalSolidity") && !_node["experimentalSolidity"].isNull())
experimentalSolidity = _node["experimentalSolidity"].asBool(); experimentalSolidity = _node["experimentalSolidity"].asBool();
vector<ASTPointer<ASTNode>> nodes; std::vector<ASTPointer<ASTNode>> nodes;
for (auto& child: member(_node, "nodes")) for (auto& child: member(_node, "nodes"))
nodes.emplace_back(convertJsonToASTNode(child)); nodes.emplace_back(convertJsonToASTNode(child));
@ -286,11 +284,11 @@ ASTPointer<SourceUnit> ASTJsonImporter::createSourceUnit(Json::Value const& _nod
ASTPointer<PragmaDirective> ASTJsonImporter::createPragmaDirective(Json::Value const& _node) ASTPointer<PragmaDirective> ASTJsonImporter::createPragmaDirective(Json::Value const& _node)
{ {
vector<Token> tokens; std::vector<Token> tokens;
vector<ASTString> literals; std::vector<ASTString> literals;
for (auto const& lit: member(_node, "literals")) for (auto const& lit: member(_node, "literals"))
{ {
string l = lit.asString(); std::string l = lit.asString();
literals.push_back(l); literals.push_back(l);
tokens.push_back(scanSingleToken(l)); tokens.push_back(scanSingleToken(l));
} }
@ -309,7 +307,7 @@ ASTPointer<ImportDirective> ASTJsonImporter::createImportDirective(Json::Value c
symbolAliases.push_back({ symbolAliases.push_back({
createIdentifier(tuple["foreign"]), createIdentifier(tuple["foreign"]),
tuple["local"].isNull() ? nullptr : make_shared<ASTString>(tuple["local"].asString()), tuple["local"].isNull() ? nullptr : std::make_shared<ASTString>(tuple["local"].asString()),
createSourceLocation(tuple["foreign"])} createSourceLocation(tuple["foreign"])}
); );
} }
@ -343,7 +341,7 @@ ASTPointer<ContractDefinition> ASTJsonImporter::createContractDefinition(Json::V
return createASTNode<ContractDefinition>( return createASTNode<ContractDefinition>(
_node, _node,
make_shared<ASTString>(_node["name"].asString()), std::make_shared<ASTString>(_node["name"].asString()),
createNameSourceLocation(_node), createNameSourceLocation(_node),
_node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")), _node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")),
baseContracts, baseContracts,
@ -357,13 +355,13 @@ ASTPointer<IdentifierPath> ASTJsonImporter::createIdentifierPath(Json::Value con
{ {
astAssert(_node["name"].isString(), "Expected 'name' to be a string!"); astAssert(_node["name"].isString(), "Expected 'name' to be a string!");
vector<ASTString> namePath; std::vector<ASTString> namePath;
vector<SourceLocation> namePathLocations; std::vector<SourceLocation> namePathLocations;
vector<string> strs; std::vector<std::string> strs;
string nameString = member(_node, "name").asString(); std::string nameString = member(_node, "name").asString();
boost::algorithm::split(strs, nameString, boost::is_any_of(".")); boost::algorithm::split(strs, nameString, boost::is_any_of("."));
astAssert(!strs.empty(), "Expected at least one element in IdentifierPath."); astAssert(!strs.empty(), "Expected at least one element in IdentifierPath.");
for (string s: strs) for (std::string s: strs)
{ {
astAssert(!s.empty(), "Expected non-empty string for IdentifierPath element."); astAssert(!s.empty(), "Expected non-empty string for IdentifierPath element.");
namePath.emplace_back(s); namePath.emplace_back(s);
@ -395,20 +393,20 @@ ASTPointer<InheritanceSpecifier> ASTJsonImporter::createInheritanceSpecifier(Jso
return createASTNode<InheritanceSpecifier>( return createASTNode<InheritanceSpecifier>(
_node, _node,
createIdentifierPath(member(_node, "baseName")), createIdentifierPath(member(_node, "baseName")),
member(_node, "arguments").isNull() ? nullptr : make_unique<std::vector<ASTPointer<Expression>>>(arguments) member(_node, "arguments").isNull() ? nullptr : std::make_unique<std::vector<ASTPointer<Expression>>>(arguments)
); );
} }
ASTPointer<UsingForDirective> ASTJsonImporter::createUsingForDirective(Json::Value const& _node) ASTPointer<UsingForDirective> ASTJsonImporter::createUsingForDirective(Json::Value const& _node)
{ {
vector<ASTPointer<IdentifierPath>> functions; std::vector<ASTPointer<IdentifierPath>> functions;
vector<optional<Token>> operators; std::vector<std::optional<Token>> operators;
if (_node.isMember("libraryName")) if (_node.isMember("libraryName"))
{ {
astAssert(!_node["libraryName"].isArray()); astAssert(!_node["libraryName"].isArray());
astAssert(!_node["libraryName"]["operator"]); astAssert(!_node["libraryName"]["operator"]);
functions.emplace_back(createIdentifierPath(_node["libraryName"])); functions.emplace_back(createIdentifierPath(_node["libraryName"]));
operators.emplace_back(nullopt); operators.emplace_back(std::nullopt);
} }
else if (_node.isMember("functionList")) else if (_node.isMember("functionList"))
for (Json::Value const& function: _node["functionList"]) for (Json::Value const& function: _node["functionList"])
@ -419,7 +417,7 @@ ASTPointer<UsingForDirective> ASTJsonImporter::createUsingForDirective(Json::Val
astAssert(!function.isMember("definition")); astAssert(!function.isMember("definition"));
functions.emplace_back(createIdentifierPath(function["function"])); functions.emplace_back(createIdentifierPath(function["function"]));
operators.emplace_back(nullopt); operators.emplace_back(std::nullopt);
} }
else else
{ {
@ -520,7 +518,7 @@ ASTPointer<FunctionDefinition> ASTJsonImporter::createFunctionDefinition(Json::V
Token kind; Token kind;
bool freeFunction = false; bool freeFunction = false;
string kindStr = member(_node, "kind").asString(); std::string kindStr = member(_node, "kind").asString();
if (kindStr == "constructor") if (kindStr == "constructor")
kind = Token::Constructor; kind = Token::Constructor;
@ -572,7 +570,7 @@ ASTPointer<VariableDeclaration> ASTJsonImporter::createVariableDeclaration(Json:
VariableDeclaration::Mutability mutability{}; VariableDeclaration::Mutability mutability{};
astAssert(member(_node, "mutability").isString(), "'mutability' expected to be string."); astAssert(member(_node, "mutability").isString(), "'mutability' expected to be string.");
string const mutabilityStr = member(_node, "mutability").asString(); std::string const mutabilityStr = member(_node, "mutability").asString();
if (mutabilityStr == "constant") if (mutabilityStr == "constant")
{ {
mutability = VariableDeclaration::Mutability::Constant; mutability = VariableDeclaration::Mutability::Constant;
@ -592,7 +590,7 @@ ASTPointer<VariableDeclaration> ASTJsonImporter::createVariableDeclaration(Json:
return createASTNode<VariableDeclaration>( return createASTNode<VariableDeclaration>(
_node, _node,
nullOrCast<TypeName>(member(_node, "typeName")), nullOrCast<TypeName>(member(_node, "typeName")),
make_shared<ASTString>(member(_node, "name").asString()), std::make_shared<ASTString>(member(_node, "name").asString()),
createNameSourceLocation(_node), createNameSourceLocation(_node),
nullOrCast<Expression>(member(_node, "value")), nullOrCast<Expression>(member(_node, "value")),
visibility(_node), visibility(_node),
@ -626,7 +624,7 @@ ASTPointer<ModifierInvocation> ASTJsonImporter::createModifierInvocation(Json::V
return createASTNode<ModifierInvocation>( return createASTNode<ModifierInvocation>(
_node, _node,
createIdentifierPath(member(_node, "modifierName")), createIdentifierPath(member(_node, "modifierName")),
member(_node, "arguments").isNull() ? nullptr : make_unique<std::vector<ASTPointer<Expression>>>(arguments) member(_node, "arguments").isNull() ? nullptr : std::make_unique<std::vector<ASTPointer<Expression>>>(arguments)
); );
} }
@ -660,9 +658,9 @@ ASTPointer<ElementaryTypeName> ASTJsonImporter::createElementaryTypeName(Json::V
astAssert(_node["name"].isString(), "Expected 'name' to be a string!"); astAssert(_node["name"].isString(), "Expected 'name' to be a string!");
string name = member(_node, "name").asString(); std::string name = member(_node, "name").asString();
Token token; Token token;
tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(name); std::tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(name);
ElementaryTypeNameToken elem(token, firstNum, secondNum); ElementaryTypeNameToken elem(token, firstNum, secondNum);
std::optional<StateMutability> mutability = {}; std::optional<StateMutability> mutability = {};
@ -721,19 +719,19 @@ ASTPointer<InlineAssembly> ASTJsonImporter::createInlineAssembly(Json::Value con
astAssert(m_evmVersion == evmVersion, "Imported tree evm version differs from configured evm version!"); astAssert(m_evmVersion == evmVersion, "Imported tree evm version differs from configured evm version!");
yul::Dialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(evmVersion.value()); yul::Dialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(evmVersion.value());
ASTPointer<vector<ASTPointer<ASTString>>> flags; ASTPointer<std::vector<ASTPointer<ASTString>>> flags;
if (_node.isMember("flags")) if (_node.isMember("flags"))
{ {
flags = make_shared<vector<ASTPointer<ASTString>>>(); flags = std::make_shared<std::vector<ASTPointer<ASTString>>>();
Json::Value const& flagsNode = _node["flags"]; Json::Value const& flagsNode = _node["flags"];
astAssert(flagsNode.isArray(), "Assembly flags must be an array."); astAssert(flagsNode.isArray(), "Assembly flags must be an array.");
for (Json::ArrayIndex i = 0; i < flagsNode.size(); ++i) for (Json::ArrayIndex i = 0; i < flagsNode.size(); ++i)
{ {
astAssert(flagsNode[i].isString(), "Assembly flag must be a string."); astAssert(flagsNode[i].isString(), "Assembly flag must be a string.");
flags->emplace_back(make_shared<ASTString>(flagsNode[i].asString())); flags->emplace_back(std::make_shared<ASTString>(flagsNode[i].asString()));
} }
} }
shared_ptr<yul::Block> operations = make_shared<yul::Block>(yul::AsmJsonImporter(m_sourceNames).createBlock(member(_node, "AST"))); std::shared_ptr<yul::Block> operations = std::make_shared<yul::Block>(yul::AsmJsonImporter(m_sourceNames).createBlock(member(_node, "AST")));
return createASTNode<InlineAssembly>( return createASTNode<InlineAssembly>(
_node, _node,
nullOrASTString(_node, "documentation"), nullOrASTString(_node, "documentation"),
@ -787,7 +785,7 @@ ASTPointer<TryCatchClause> ASTJsonImporter::createTryCatchClause(Json::Value con
ASTPointer<TryStatement> ASTJsonImporter::createTryStatement(Json::Value const& _node) ASTPointer<TryStatement> ASTJsonImporter::createTryStatement(Json::Value const& _node)
{ {
vector<ASTPointer<TryCatchClause>> clauses; std::vector<ASTPointer<TryCatchClause>> clauses;
for (auto& param: _node["clauses"]) for (auto& param: _node["clauses"])
clauses.emplace_back(createTryCatchClause(param)); clauses.emplace_back(createTryCatchClause(param));
@ -957,10 +955,10 @@ ASTPointer<FunctionCall> ASTJsonImporter::createFunctionCall(Json::Value const&
for (auto& name: member(_node, "names")) for (auto& name: member(_node, "names"))
{ {
astAssert(name.isString(), "Expected 'names' members to be strings!"); astAssert(name.isString(), "Expected 'names' members to be strings!");
names.push_back(make_shared<ASTString>(name.asString())); names.push_back(std::make_shared<ASTString>(name.asString()));
} }
optional<vector<SourceLocation>> sourceLocations = createSourceLocations(_node); std::optional<std::vector<SourceLocation>> sourceLocations = createSourceLocations(_node);
return createASTNode<FunctionCall>( return createASTNode<FunctionCall>(
_node, _node,
@ -969,7 +967,7 @@ ASTPointer<FunctionCall> ASTJsonImporter::createFunctionCall(Json::Value const&
names, names,
sourceLocations ? sourceLocations ?
*sourceLocations : *sourceLocations :
vector<SourceLocation>(names.size()) std::vector<SourceLocation>(names.size())
); );
} }
@ -982,7 +980,7 @@ ASTPointer<FunctionCallOptions> ASTJsonImporter::createFunctionCallOptions(Json:
for (auto& name: member(_node, "names")) for (auto& name: member(_node, "names"))
{ {
astAssert(name.isString(), "Expected 'names' members to be strings!"); astAssert(name.isString(), "Expected 'names' members to be strings!");
names.push_back(make_shared<ASTString>(name.asString())); names.push_back(std::make_shared<ASTString>(name.asString()));
} }
return createASTNode<FunctionCallOptions>( return createASTNode<FunctionCallOptions>(
@ -1049,14 +1047,14 @@ ASTPointer<ElementaryTypeNameExpression> ASTJsonImporter::createElementaryTypeNa
ASTPointer<ASTNode> ASTJsonImporter::createLiteral(Json::Value const& _node) ASTPointer<ASTNode> ASTJsonImporter::createLiteral(Json::Value const& _node)
{ {
static string const valStr = "value"; static std::string const valStr = "value";
static string const hexValStr = "hexValue"; static std::string const hexValStr = "hexValue";
astAssert(member(_node, valStr).isString() || member(_node, hexValStr).isString(), "Literal-value is unset."); astAssert(member(_node, valStr).isString() || member(_node, hexValStr).isString(), "Literal-value is unset.");
ASTPointer<ASTString> value = _node.isMember(hexValStr) ? ASTPointer<ASTString> value = _node.isMember(hexValStr) ?
make_shared<ASTString>(util::asString(util::fromHex(_node[hexValStr].asString()))) : std::make_shared<ASTString>(util::asString(util::fromHex(_node[hexValStr].asString()))) :
make_shared<ASTString>(_node[valStr].asString()); std::make_shared<ASTString>(_node[valStr].asString());
return createASTNode<Literal>( return createASTNode<Literal>(
_node, _node,
@ -1068,19 +1066,19 @@ ASTPointer<ASTNode> ASTJsonImporter::createLiteral(Json::Value const& _node)
ASTPointer<StructuredDocumentation> ASTJsonImporter::createDocumentation(Json::Value const& _node) ASTPointer<StructuredDocumentation> ASTJsonImporter::createDocumentation(Json::Value const& _node)
{ {
static string const textString = "text"; static std::string const textString = "text";
astAssert(member(_node, textString).isString(), "'text' must be a string"); astAssert(member(_node, textString).isString(), "'text' must be a string");
return createASTNode<StructuredDocumentation>( return createASTNode<StructuredDocumentation>(
_node, _node,
make_shared<ASTString>(_node[textString].asString()) std::make_shared<ASTString>(_node[textString].asString())
); );
} }
// ===== helper functions ========== // ===== helper functions ==========
Json::Value ASTJsonImporter::member(Json::Value const& _node, string const& _name) Json::Value ASTJsonImporter::member(Json::Value const& _node, std::string const& _name)
{ {
if (!_node.isMember(_name)) if (!_node.isMember(_name))
return Json::nullValue; return Json::nullValue;
@ -1095,19 +1093,19 @@ Token ASTJsonImporter::scanSingleToken(Json::Value const& _node)
return scanner.currentToken(); return scanner.currentToken();
} }
ASTPointer<ASTString> ASTJsonImporter::nullOrASTString(Json::Value const& _json, string const& _name) ASTPointer<ASTString> ASTJsonImporter::nullOrASTString(Json::Value const& _json, std::string const& _name)
{ {
return _json[_name].isString() ? memberAsASTString(_json, _name) : nullptr; return _json[_name].isString() ? memberAsASTString(_json, _name) : nullptr;
} }
ASTPointer<ASTString> ASTJsonImporter::memberAsASTString(Json::Value const& _node, string const& _name) ASTPointer<ASTString> ASTJsonImporter::memberAsASTString(Json::Value const& _node, std::string const& _name)
{ {
Json::Value value = member(_node, _name); Json::Value value = member(_node, _name);
astAssert(value.isString(), "field " + _name + " must be of type string."); astAssert(value.isString(), "field " + _name + " must be of type string.");
return make_shared<ASTString>(_node[_name].asString()); return std::make_shared<ASTString>(_node[_name].asString());
} }
bool ASTJsonImporter::memberAsBool(Json::Value const& _node, string const& _name) bool ASTJsonImporter::memberAsBool(Json::Value const& _node, std::string const& _name)
{ {
Json::Value value = member(_node, _name); Json::Value value = member(_node, _name);
astAssert(value.isBool(), "field " + _name + " must be of type boolean."); astAssert(value.isBool(), "field " + _name + " must be of type boolean.");
@ -1156,7 +1154,7 @@ Visibility ASTJsonImporter::visibility(Json::Value const& _node)
Json::Value visibility = member(_node, "visibility"); Json::Value visibility = member(_node, "visibility");
astAssert(visibility.isString(), "'visibility' expected to be a string."); astAssert(visibility.isString(), "'visibility' expected to be a string.");
string const visibilityStr = visibility.asString(); std::string const visibilityStr = visibility.asString();
if (visibilityStr == "default") if (visibilityStr == "default")
return Visibility::Default; return Visibility::Default;
@ -1180,7 +1178,7 @@ VariableDeclaration::Location ASTJsonImporter::location(Json::Value const& _node
Json::Value storageLoc = member(_node, "storageLocation"); Json::Value storageLoc = member(_node, "storageLocation");
astAssert(storageLoc.isString(), "'storageLocation' expected to be a string."); astAssert(storageLoc.isString(), "'storageLocation' expected to be a string.");
string const storageLocStr = storageLoc.asString(); std::string const storageLocStr = storageLoc.asString();
if (storageLocStr == "default") if (storageLocStr == "default")
return VariableDeclaration::Location::Unspecified; return VariableDeclaration::Location::Unspecified;
@ -1206,7 +1204,7 @@ Literal::SubDenomination ASTJsonImporter::subdenomination(Json::Value const& _no
astAssert(subDen.isString(), "'subDenomination' expected to be string."); astAssert(subDen.isString(), "'subDenomination' expected to be string.");
string const subDenStr = subDen.asString(); std::string const subDenStr = subDen.asString();
if (subDenStr == "wei") if (subDenStr == "wei")
return Literal::SubDenomination::Wei; return Literal::SubDenomination::Wei;
@ -1236,7 +1234,7 @@ Literal::SubDenomination ASTJsonImporter::subdenomination(Json::Value const& _no
StateMutability ASTJsonImporter::stateMutability(Json::Value const& _node) StateMutability ASTJsonImporter::stateMutability(Json::Value const& _node)
{ {
astAssert(member(_node, "stateMutability").isString(), "StateMutability' expected to be string."); astAssert(member(_node, "stateMutability").isString(), "StateMutability' expected to be string.");
string const mutabilityStr = member(_node, "stateMutability").asString(); std::string const mutabilityStr = member(_node, "stateMutability").asString();
if (mutabilityStr == "pure") if (mutabilityStr == "pure")
return StateMutability::Pure; return StateMutability::Pure;

View File

@ -18,7 +18,6 @@
#include <libsolidity/ast/CallGraph.h> #include <libsolidity/ast/CallGraph.h>
using namespace std;
using namespace solidity::frontend; using namespace solidity::frontend;
bool CallGraph::CompareByID::operator()(Node const& _lhs, Node const& _rhs) const bool CallGraph::CompareByID::operator()(Node const& _lhs, Node const& _rhs) const
@ -26,21 +25,21 @@ bool CallGraph::CompareByID::operator()(Node const& _lhs, Node const& _rhs) cons
if (_lhs.index() != _rhs.index()) if (_lhs.index() != _rhs.index())
return _lhs.index() < _rhs.index(); return _lhs.index() < _rhs.index();
if (holds_alternative<SpecialNode>(_lhs)) if (std::holds_alternative<SpecialNode>(_lhs))
return get<SpecialNode>(_lhs) < get<SpecialNode>(_rhs); return std::get<SpecialNode>(_lhs) < std::get<SpecialNode>(_rhs);
return get<CallableDeclaration const*>(_lhs)->id() < get<CallableDeclaration const*>(_rhs)->id(); return std::get<CallableDeclaration const*>(_lhs)->id() < std::get<CallableDeclaration const*>(_rhs)->id();
} }
bool CallGraph::CompareByID::operator()(Node const& _lhs, int64_t _rhs) const bool CallGraph::CompareByID::operator()(Node const& _lhs, int64_t _rhs) const
{ {
solAssert(!holds_alternative<SpecialNode>(_lhs), ""); solAssert(!std::holds_alternative<SpecialNode>(_lhs), "");
return get<CallableDeclaration const*>(_lhs)->id() < _rhs; return std::get<CallableDeclaration const*>(_lhs)->id() < _rhs;
} }
bool CallGraph::CompareByID::operator()(int64_t _lhs, Node const& _rhs) const bool CallGraph::CompareByID::operator()(int64_t _lhs, Node const& _rhs) const
{ {
solAssert(!holds_alternative<SpecialNode>(_rhs), ""); solAssert(!std::holds_alternative<SpecialNode>(_rhs), "");
return _lhs < get<CallableDeclaration const*>(_rhs)->id(); return _lhs < std::get<CallableDeclaration const*>(_rhs)->id();
} }

View File

@ -21,7 +21,6 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::frontend; using namespace solidity::frontend;
using namespace solidity::util; using namespace solidity::util;
@ -31,126 +30,126 @@ InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamic{};
/// The string and bytes unique_ptrs are initialized when they are first used because /// The string and bytes unique_ptrs are initialized when they are first used because
/// they rely on `byte` being available which we cannot guarantee in the static init context. /// they rely on `byte` being available which we cannot guarantee in the static init context.
unique_ptr<ArrayType> TypeProvider::m_bytesStorage; std::unique_ptr<ArrayType> TypeProvider::m_bytesStorage;
unique_ptr<ArrayType> TypeProvider::m_bytesMemory; std::unique_ptr<ArrayType> TypeProvider::m_bytesMemory;
unique_ptr<ArrayType> TypeProvider::m_bytesCalldata; std::unique_ptr<ArrayType> TypeProvider::m_bytesCalldata;
unique_ptr<ArrayType> TypeProvider::m_stringStorage; std::unique_ptr<ArrayType> TypeProvider::m_stringStorage;
unique_ptr<ArrayType> TypeProvider::m_stringMemory; std::unique_ptr<ArrayType> TypeProvider::m_stringMemory;
TupleType const TypeProvider::m_emptyTuple{}; TupleType const TypeProvider::m_emptyTuple{};
AddressType const TypeProvider::m_payableAddress{StateMutability::Payable}; AddressType const TypeProvider::m_payableAddress{StateMutability::Payable};
AddressType const TypeProvider::m_address{StateMutability::NonPayable}; AddressType const TypeProvider::m_address{StateMutability::NonPayable};
array<unique_ptr<IntegerType>, 32> const TypeProvider::m_intM{{ std::array<std::unique_ptr<IntegerType>, 32> const TypeProvider::m_intM{{
{make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 2, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 2, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 3, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 3, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 4, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 4, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 5, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 5, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 6, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 6, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 7, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 7, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 8, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 8, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 9, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 9, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 10, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 10, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 11, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 11, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 12, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 12, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 13, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 13, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 14, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 14, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 15, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 15, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 16, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 16, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 17, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 17, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 18, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 18, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 19, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 19, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 20, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 20, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 21, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 21, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 22, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 22, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 23, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 23, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 24, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 24, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 25, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 25, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 26, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 26, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 27, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 27, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 28, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 28, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 29, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 29, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 30, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 30, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 31, IntegerType::Modifier::Signed)}, {std::make_unique<IntegerType>(8 * 31, IntegerType::Modifier::Signed)},
{make_unique<IntegerType>(8 * 32, IntegerType::Modifier::Signed)} {std::make_unique<IntegerType>(8 * 32, IntegerType::Modifier::Signed)}
}}; }};
array<unique_ptr<IntegerType>, 32> const TypeProvider::m_uintM{{ std::array<std::unique_ptr<IntegerType>, 32> const TypeProvider::m_uintM{{
{make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 2, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 2, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 3, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 3, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 4, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 4, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 5, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 5, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 6, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 6, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 7, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 7, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 8, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 8, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 9, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 9, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 10, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 10, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 11, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 11, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 12, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 12, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 13, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 13, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 14, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 14, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 15, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 15, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 16, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 16, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 17, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 17, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 18, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 18, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 19, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 19, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 20, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 20, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 21, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 21, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 22, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 22, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 23, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 23, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 24, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 24, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 25, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 25, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 26, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 26, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 27, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 27, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 28, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 28, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 29, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 29, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 30, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 30, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 31, IntegerType::Modifier::Unsigned)}, {std::make_unique<IntegerType>(8 * 31, IntegerType::Modifier::Unsigned)},
{make_unique<IntegerType>(8 * 32, IntegerType::Modifier::Unsigned)} {std::make_unique<IntegerType>(8 * 32, IntegerType::Modifier::Unsigned)}
}}; }};
array<unique_ptr<FixedBytesType>, 32> const TypeProvider::m_bytesM{{ std::array<std::unique_ptr<FixedBytesType>, 32> const TypeProvider::m_bytesM{{
{make_unique<FixedBytesType>(1)}, {std::make_unique<FixedBytesType>(1)},
{make_unique<FixedBytesType>(2)}, {std::make_unique<FixedBytesType>(2)},
{make_unique<FixedBytesType>(3)}, {std::make_unique<FixedBytesType>(3)},
{make_unique<FixedBytesType>(4)}, {std::make_unique<FixedBytesType>(4)},
{make_unique<FixedBytesType>(5)}, {std::make_unique<FixedBytesType>(5)},
{make_unique<FixedBytesType>(6)}, {std::make_unique<FixedBytesType>(6)},
{make_unique<FixedBytesType>(7)}, {std::make_unique<FixedBytesType>(7)},
{make_unique<FixedBytesType>(8)}, {std::make_unique<FixedBytesType>(8)},
{make_unique<FixedBytesType>(9)}, {std::make_unique<FixedBytesType>(9)},
{make_unique<FixedBytesType>(10)}, {std::make_unique<FixedBytesType>(10)},
{make_unique<FixedBytesType>(11)}, {std::make_unique<FixedBytesType>(11)},
{make_unique<FixedBytesType>(12)}, {std::make_unique<FixedBytesType>(12)},
{make_unique<FixedBytesType>(13)}, {std::make_unique<FixedBytesType>(13)},
{make_unique<FixedBytesType>(14)}, {std::make_unique<FixedBytesType>(14)},
{make_unique<FixedBytesType>(15)}, {std::make_unique<FixedBytesType>(15)},
{make_unique<FixedBytesType>(16)}, {std::make_unique<FixedBytesType>(16)},
{make_unique<FixedBytesType>(17)}, {std::make_unique<FixedBytesType>(17)},
{make_unique<FixedBytesType>(18)}, {std::make_unique<FixedBytesType>(18)},
{make_unique<FixedBytesType>(19)}, {std::make_unique<FixedBytesType>(19)},
{make_unique<FixedBytesType>(20)}, {std::make_unique<FixedBytesType>(20)},
{make_unique<FixedBytesType>(21)}, {std::make_unique<FixedBytesType>(21)},
{make_unique<FixedBytesType>(22)}, {std::make_unique<FixedBytesType>(22)},
{make_unique<FixedBytesType>(23)}, {std::make_unique<FixedBytesType>(23)},
{make_unique<FixedBytesType>(24)}, {std::make_unique<FixedBytesType>(24)},
{make_unique<FixedBytesType>(25)}, {std::make_unique<FixedBytesType>(25)},
{make_unique<FixedBytesType>(26)}, {std::make_unique<FixedBytesType>(26)},
{make_unique<FixedBytesType>(27)}, {std::make_unique<FixedBytesType>(27)},
{make_unique<FixedBytesType>(28)}, {std::make_unique<FixedBytesType>(28)},
{make_unique<FixedBytesType>(29)}, {std::make_unique<FixedBytesType>(29)},
{make_unique<FixedBytesType>(30)}, {std::make_unique<FixedBytesType>(30)},
{make_unique<FixedBytesType>(31)}, {std::make_unique<FixedBytesType>(31)},
{make_unique<FixedBytesType>(32)} {std::make_unique<FixedBytesType>(32)}
}}; }};
array<unique_ptr<MagicType>, 4> const TypeProvider::m_magics{{ std::array<std::unique_ptr<MagicType>, 4> const TypeProvider::m_magics{{
{make_unique<MagicType>(MagicType::Kind::Block)}, {std::make_unique<MagicType>(MagicType::Kind::Block)},
{make_unique<MagicType>(MagicType::Kind::Message)}, {std::make_unique<MagicType>(MagicType::Kind::Message)},
{make_unique<MagicType>(MagicType::Kind::Transaction)}, {std::make_unique<MagicType>(MagicType::Kind::Transaction)},
{make_unique<MagicType>(MagicType::Kind::ABI)} {std::make_unique<MagicType>(MagicType::Kind::ABI)}
// MetaType is stored separately // MetaType is stored separately
}}; }};
@ -160,7 +159,7 @@ inline void clearCache(Type const& type)
} }
template <typename T> template <typename T>
inline void clearCache(unique_ptr<T> const& type) inline void clearCache(std::unique_ptr<T> const& type)
{ {
// Some lazy-initialized types might not exist yet. // Some lazy-initialized types might not exist yet.
if (type) if (type)
@ -200,7 +199,7 @@ void TypeProvider::reset()
template <typename T, typename... Args> template <typename T, typename... Args>
inline T const* TypeProvider::createAndGet(Args&& ... _args) inline T const* TypeProvider::createAndGet(Args&& ... _args)
{ {
instance().m_generalTypes.emplace_back(make_unique<T>(std::forward<Args>(_args)...)); instance().m_generalTypes.emplace_back(std::make_unique<T>(std::forward<Args>(_args)...));
return static_cast<T const*>(instance().m_generalTypes.back().get()); return static_cast<T const*>(instance().m_generalTypes.back().get());
} }
@ -259,15 +258,15 @@ Type const* TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken const&
} }
} }
Type const* TypeProvider::fromElementaryTypeName(string const& _name) Type const* TypeProvider::fromElementaryTypeName(std::string const& _name)
{ {
vector<string> nameParts; std::vector<std::string> nameParts;
boost::split(nameParts, _name, boost::is_any_of(" ")); boost::split(nameParts, _name, boost::is_any_of(" "));
solAssert(nameParts.size() == 1 || nameParts.size() == 2, "Cannot parse elementary type: " + _name); solAssert(nameParts.size() == 1 || nameParts.size() == 2, "Cannot parse elementary type: " + _name);
Token token; Token token;
unsigned short firstNum, secondNum; unsigned short firstNum, secondNum;
tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(nameParts[0]); std::tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(nameParts[0]);
auto t = fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum)); auto t = fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum));
if (auto* ref = dynamic_cast<ReferenceType const*>(t)) if (auto* ref = dynamic_cast<ReferenceType const*>(t))
@ -307,35 +306,35 @@ Type const* TypeProvider::fromElementaryTypeName(string const& _name)
ArrayType const* TypeProvider::bytesStorage() ArrayType const* TypeProvider::bytesStorage()
{ {
if (!m_bytesStorage) if (!m_bytesStorage)
m_bytesStorage = make_unique<ArrayType>(DataLocation::Storage, false); m_bytesStorage = std::make_unique<ArrayType>(DataLocation::Storage, false);
return m_bytesStorage.get(); return m_bytesStorage.get();
} }
ArrayType const* TypeProvider::bytesMemory() ArrayType const* TypeProvider::bytesMemory()
{ {
if (!m_bytesMemory) if (!m_bytesMemory)
m_bytesMemory = make_unique<ArrayType>(DataLocation::Memory, false); m_bytesMemory = std::make_unique<ArrayType>(DataLocation::Memory, false);
return m_bytesMemory.get(); return m_bytesMemory.get();
} }
ArrayType const* TypeProvider::bytesCalldata() ArrayType const* TypeProvider::bytesCalldata()
{ {
if (!m_bytesCalldata) if (!m_bytesCalldata)
m_bytesCalldata = make_unique<ArrayType>(DataLocation::CallData, false); m_bytesCalldata = std::make_unique<ArrayType>(DataLocation::CallData, false);
return m_bytesCalldata.get(); return m_bytesCalldata.get();
} }
ArrayType const* TypeProvider::stringStorage() ArrayType const* TypeProvider::stringStorage()
{ {
if (!m_stringStorage) if (!m_stringStorage)
m_stringStorage = make_unique<ArrayType>(DataLocation::Storage, true); m_stringStorage = std::make_unique<ArrayType>(DataLocation::Storage, true);
return m_stringStorage.get(); return m_stringStorage.get();
} }
ArrayType const* TypeProvider::stringMemory() ArrayType const* TypeProvider::stringMemory()
{ {
if (!m_stringMemory) if (!m_stringMemory)
m_stringMemory = make_unique<ArrayType>(DataLocation::Memory, true); m_stringMemory = std::make_unique<ArrayType>(DataLocation::Memory, true);
return m_stringMemory.get(); return m_stringMemory.get();
} }
@ -376,30 +375,30 @@ RationalNumberType const* TypeProvider::rationalNumber(Literal const& _literal)
return nullptr; return nullptr;
} }
StringLiteralType const* TypeProvider::stringLiteral(string const& literal) StringLiteralType const* TypeProvider::stringLiteral(std::string const& literal)
{ {
auto i = instance().m_stringLiteralTypes.find(literal); auto i = instance().m_stringLiteralTypes.find(literal);
if (i != instance().m_stringLiteralTypes.end()) if (i != instance().m_stringLiteralTypes.end())
return i->second.get(); return i->second.get();
else else
return instance().m_stringLiteralTypes.emplace(literal, make_unique<StringLiteralType>(literal)).first->second.get(); return instance().m_stringLiteralTypes.emplace(literal, std::make_unique<StringLiteralType>(literal)).first->second.get();
} }
FixedPointType const* TypeProvider::fixedPoint(unsigned m, unsigned n, FixedPointType::Modifier _modifier) FixedPointType const* TypeProvider::fixedPoint(unsigned m, unsigned n, FixedPointType::Modifier _modifier)
{ {
auto& map = _modifier == FixedPointType::Modifier::Unsigned ? instance().m_ufixedMxN : instance().m_fixedMxN; auto& map = _modifier == FixedPointType::Modifier::Unsigned ? instance().m_ufixedMxN : instance().m_fixedMxN;
auto i = map.find(make_pair(m, n)); auto i = map.find(std::make_pair(m, n));
if (i != map.end()) if (i != map.end())
return i->second.get(); return i->second.get();
return map.emplace( return map.emplace(
make_pair(m, n), std::make_pair(m, n),
make_unique<FixedPointType>(m, n, _modifier) std::make_unique<FixedPointType>(m, n, _modifier)
).first->second.get(); ).first->second.get();
} }
TupleType const* TypeProvider::tuple(vector<Type const*> members) TupleType const* TypeProvider::tuple(std::vector<Type const*> members)
{ {
if (members.empty()) if (members.empty())
return &m_emptyTuple; return &m_emptyTuple;

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@ NAMESPACE_STD_FREE_FILES=(
libsmtutil/* libsmtutil/*
libsolc/* libsolc/*
libsolidity/analysis/* libsolidity/analysis/*
libsolidity/ast/*
) )
( (