From 2a2a9d37ee69ca77ef530fe18524a3dc8b053104 Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Mon, 14 Aug 2023 14:39:16 +0200 Subject: [PATCH] Purge using namespace std from libsolidity/ast --- libsolidity/ast/AST.cpp | 81 +++-- libsolidity/ast/ASTAnnotations.cpp | 1 - libsolidity/ast/ASTJsonExporter.cpp | 485 ++++++++++++++-------------- libsolidity/ast/ASTJsonImporter.cpp | 116 ++++--- libsolidity/ast/CallGraph.cpp | 15 +- libsolidity/ast/TypeProvider.cpp | 251 +++++++------- libsolidity/ast/Types.cpp | 387 +++++++++++----------- scripts/check_style.sh | 3 +- 8 files changed, 666 insertions(+), 673 deletions(-) diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index 833ba739e..c0bf90091 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -39,13 +39,12 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::frontend; namespace { -TryCatchClause const* findClause(vector> const& _clauses, optional _errorName = {}) +TryCatchClause const* findClause(std::vector> const& _clauses, std::optional _errorName = {}) { for (auto const& clause: ranges::views::tail(_clauses)) 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 { if (!m_annotation) - m_annotation = make_unique(); + m_annotation = std::make_unique(); return *m_annotation; } @@ -128,9 +127,9 @@ SourceUnitAnnotation& SourceUnit::annotation() const return initAnnotation(); } -set SourceUnit::referencedSourceUnits(bool _recurse, set _skipList) const +std::set SourceUnit::referencedSourceUnits(bool _recurse, std::set _skipList) const { - set sourceUnits; + std::set sourceUnits; for (ImportDirective const* importDirective: filteredNodes(nodes())) { auto const& sourceUnit = importDirective->annotation().sourceUnit; @@ -161,11 +160,11 @@ bool ContractDefinition::derivesFrom(ContractDefinition const& _base) const return util::contains(annotation().linearizedBaseContracts, &_base); } -map, FunctionTypePointer> ContractDefinition::interfaceFunctions(bool _includeInheritedFunctions) const +std::map, FunctionTypePointer> ContractDefinition::interfaceFunctions(bool _includeInheritedFunctions) const { auto exportedFunctionList = interfaceFunctionList(_includeInheritedFunctions); - map, FunctionTypePointer> exportedFunctions; + std::map, FunctionTypePointer> exportedFunctions; for (auto const& it: exportedFunctionList) exportedFunctions.insert(it); @@ -208,11 +207,11 @@ FunctionDefinition const* ContractDefinition::receiveFunction() const return nullptr; } -vector const& ContractDefinition::definedInterfaceEvents() const +std::vector const& ContractDefinition::definedInterfaceEvents() const { return m_interfaceEvents.init([&]{ - set eventsSeen; - vector interfaceEvents; + std::set eventsSeen; + std::vector interfaceEvents; for (ContractDefinition const* contract: annotation().linearizedBaseContracts) for (EventDefinition const* e: contract->events()) @@ -222,7 +221,7 @@ vector const& ContractDefinition::definedInterfaceEvents /// and not to function encoding (jump vs. call) FunctionType const* functionType = e->functionType(true); solAssert(functionType, ""); - string eventSignature = functionType->externalSignature(); + std::string eventSignature = functionType->externalSignature(); if (eventsSeen.count(eventSignature) == 0) { eventsSeen.insert(eventSignature); @@ -233,7 +232,7 @@ vector const& ContractDefinition::definedInterfaceEvents }); } -vector const ContractDefinition::usedInterfaceEvents() const +std::vector const ContractDefinition::usedInterfaceEvents() const { solAssert(annotation().creationCallGraph.set(), ""); @@ -243,9 +242,9 @@ vector const ContractDefinition::usedInterfaceEvents() c ); } -vector ContractDefinition::interfaceEvents(bool _requireCallGraph) const +std::vector ContractDefinition::interfaceEvents(bool _requireCallGraph) const { - set result; + std::set result; for (ContractDefinition const* contract: annotation().linearizedBaseContracts) result += contract->events(); solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set()); @@ -255,12 +254,12 @@ vector ContractDefinition::interfaceEvents(bool _require result += usedInterfaceEvents(); // We could filter out all events that do not have an external interface // if _requireCallGraph is false. - return util::convertContainer>(std::move(result)); + return util::convertContainer>(std::move(result)); } -vector ContractDefinition::interfaceErrors(bool _requireCallGraph) const +std::vector ContractDefinition::interfaceErrors(bool _requireCallGraph) const { - set result; + std::set result; for (ContractDefinition const* contract: annotation().linearizedBaseContracts) result += filteredNodes(contract->m_subNodes); solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set(), ""); @@ -270,20 +269,20 @@ vector ContractDefinition::interfaceErrors(bool _require result += (*annotation().creationCallGraph)->usedErrors + (*annotation().deployedCallGraph)->usedErrors; - return util::convertContainer>(std::move(result)); + return util::convertContainer>(std::move(result)); } -vector, FunctionTypePointer>> const& ContractDefinition::interfaceFunctionList(bool _includeInheritedFunctions) const +std::vector, FunctionTypePointer>> const& ContractDefinition::interfaceFunctionList(bool _includeInheritedFunctions) const { return m_interfaceFunctionList[_includeInheritedFunctions].init([&]{ - set signaturesSeen; - vector, FunctionTypePointer>> interfaceFunctionList; + std::set signaturesSeen; + std::vector, FunctionTypePointer>> interfaceFunctionList; for (ContractDefinition const* contract: annotation().linearizedBaseContracts) { if (_includeInheritedFunctions == false && contract != this) continue; - vector functions; + std::vector functions; for (FunctionDefinition const* f: contract->definedFunctions()) if (f->isPartOfExternalInterface()) functions.push_back(TypeProvider::function(*f, FunctionType::Kind::External)); @@ -295,7 +294,7 @@ vector, FunctionTypePointer>> const& ContractDefinition: if (!fun->interfaceFunctionType()) // Fails hopefully because we already registered the error continue; - string functionSignature = fun->externalSignature(); + std::string functionSignature = fun->externalSignature(); if (signaturesSeen.count(functionSignature) == 0) { signaturesSeen.insert(functionSignature); @@ -357,7 +356,7 @@ FunctionDefinition const* ContractDefinition::nextConstructor(ContractDefinition return nullptr; } -multimap const& ContractDefinition::definedFunctionsByName() const +std::multimap const& ContractDefinition::definedFunctionsByName() const { return m_definedFunctionsByName.init([&]{ std::multimap result; @@ -386,7 +385,7 @@ TypeDeclarationAnnotation& UserDefinedValueTypeDefinition::annotation() const std::vector, std::optional>> UsingForDirective::functionsAndOperators() const { - return ranges::zip_view(m_functionsOrLibrary, m_operators) | ranges::to; + return ranges::zip_view(m_functionsOrLibrary, m_operators) | ranges::to; } Type const* StructDefinition::type() const @@ -484,12 +483,12 @@ Type const* FunctionDefinition::typeViaContractName() const return TypeProvider::function(*this, FunctionType::Kind::Declaration); } -string FunctionDefinition::externalSignature() const +std::string FunctionDefinition::externalSignature() const { return TypeProvider::function(*this)->externalSignature(); } -string FunctionDefinition::externalIdentifierHex() const +std::string FunctionDefinition::externalIdentifierHex() const { return TypeProvider::function(*this)->externalIdentifierHex(); } @@ -639,7 +638,7 @@ CallableDeclaration const* Scopable::functionOrModifierDefinition() const return nullptr; } -string Scopable::sourceUnitName() const +std::string Scopable::sourceUnitName() const { return *sourceUnit().annotation().path; } @@ -701,7 +700,7 @@ bool VariableDeclaration::isCallableOrCatchParameter() const if (isReturnParameter() || isTryCatchParameter()) return true; - vector> const* parameters = nullptr; + std::vector> const* parameters = nullptr; if (auto const* funTypeName = dynamic_cast(scope())) parameters = &funTypeName->parameterTypes(); @@ -722,7 +721,7 @@ bool VariableDeclaration::isLocalOrReturn() const bool VariableDeclaration::isReturnParameter() const { - vector> const* returnParameters = nullptr; + std::vector> const* returnParameters = nullptr; if (auto const* funTypeName = dynamic_cast(scope())) returnParameters = &funTypeName->returnParameterTypes(); @@ -813,15 +812,15 @@ bool VariableDeclaration::isFileLevelVariable() const return dynamic_cast(scope()); } -set VariableDeclaration::allowedDataLocations() const +std::set VariableDeclaration::allowedDataLocations() const { using Location = VariableDeclaration::Location; if (!hasReferenceOrMappingType() || isStateVariable() || isEventOrErrorParameter()) - return set{ Location::Unspecified }; + return std::set{ Location::Unspecified }; else if (isCallableOrCatchParameter()) { - set locations{ Location::Memory }; + std::set locations{ Location::Memory }; if ( isConstructorParameter() || isInternalCallableParameter() || @@ -835,13 +834,13 @@ set VariableDeclaration::allowedDataLocations() c } else if (isLocalVariable()) // Further restrictions will be imposed later on. - return set{ Location::Memory, Location::Storage, Location::CallData }; + return std::set{ Location::Memory, Location::Storage, Location::CallData }; else // Struct members etc. - return set{ Location::Unspecified }; + return std::set{ Location::Unspecified }; } -string VariableDeclaration::externalIdentifierHex() const +std::string VariableDeclaration::externalIdentifierHex() const { solAssert(isStateVariable() && isPublic(), "Can only be called for public state variables"); return TypeProvider::function(*this)->externalIdentifierHex(); @@ -958,7 +957,7 @@ FunctionCallAnnotation& FunctionCall::annotation() const return initAnnotation(); } -vector> FunctionCall::sortedArguments() const +std::vector> FunctionCall::sortedArguments() const { // normal arguments if (m_names.empty()) @@ -975,7 +974,7 @@ vector> FunctionCall::sortedArguments() const else functionType = dynamic_cast(m_expression->annotation().type); - vector> sorted; + std::vector> sorted; for (auto const& parameterName: functionType->parameterNames()) { bool found = false; @@ -1030,13 +1029,13 @@ bool Literal::passesAddressChecksum() const return util::passesAddressChecksum(valueWithoutUnderscores(), true); } -string Literal::getChecksummedAddress() const +std::string Literal::getChecksummedAddress() const { solAssert(isHexNumber(), "Expected hex number"); /// Pad literal to be a proper hex address. - string address = valueWithoutUnderscores().substr(2); + std::string address = valueWithoutUnderscores().substr(2); if (address.length() > 40) - return string(); + return std::string(); address.insert(address.begin(), 40 - address.size(), '0'); return util::getChecksummedAddress(address); } diff --git a/libsolidity/ast/ASTAnnotations.cpp b/libsolidity/ast/ASTAnnotations.cpp index 3556041d8..84d49fa2f 100644 --- a/libsolidity/ast/ASTAnnotations.cpp +++ b/libsolidity/ast/ASTAnnotations.cpp @@ -23,7 +23,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend; diff --git a/libsolidity/ast/ASTJsonExporter.cpp b/libsolidity/ast/ASTJsonExporter.cpp index da7f76936..ac847a339 100644 --- a/libsolidity/ast/ASTJsonExporter.cpp +++ b/libsolidity/ast/ASTJsonExporter.cpp @@ -44,7 +44,6 @@ #include #include -using namespace std; using namespace std::string_literals; using namespace solidity::langutil; @@ -52,14 +51,14 @@ namespace { template typename C> -void addIfSet(std::vector>& _attributes, string const& _name, C const& _value) +void addIfSet(std::vector>& _attributes, std::string const& _name, C const& _value) { if constexpr (std::is_same_v, solidity::util::SetOnce>) { if (!_value.set()) return; } - else if constexpr (std::is_same_v, optional>) + else if constexpr (std::is_same_v, std::optional>) { if (!_value.has_value()) return; @@ -73,7 +72,7 @@ void addIfSet(std::vector>& _attributes, string const& namespace solidity::frontend { -ASTJsonExporter::ASTJsonExporter(CompilerStack::State _stackState, map _sourceIndices): +ASTJsonExporter::ASTJsonExporter(CompilerStack::State _stackState, std::map _sourceIndices): m_stackState(_stackState), m_sourceIndices(std::move(_sourceIndices)) { @@ -82,21 +81,21 @@ ASTJsonExporter::ASTJsonExporter(CompilerStack::State _stackState, map>&& _attributes + std::string const& _nodeName, + std::initializer_list>&& _attributes ) { ASTJsonExporter::setJsonNode( _node, _nodeName, - std::vector>(std::move(_attributes)) + std::vector>(std::move(_attributes)) ); } void ASTJsonExporter::setJsonNode( ASTNode const& _node, - string const& _nodeType, - std::vector>&& _attributes + std::string const& _nodeType, + std::vector>&& _attributes ) { m_currentValue = Json::objectValue; @@ -110,24 +109,24 @@ void ASTJsonExporter::setJsonNode( m_currentValue[e.first] = std::move(e.second); } -optional ASTJsonExporter::sourceIndexFromLocation(SourceLocation const& _location) const +std::optional ASTJsonExporter::sourceIndexFromLocation(SourceLocation const& _location) const { if (_location.sourceName && m_sourceIndices.count(*_location.sourceName)) return m_sourceIndices.at(*_location.sourceName); else - return nullopt; + return std::nullopt; } -string ASTJsonExporter::sourceLocationToString(SourceLocation const& _location) const +std::string ASTJsonExporter::sourceLocationToString(SourceLocation const& _location) const { - optional sourceIndexOpt = sourceIndexFromLocation(_location); + std::optional sourceIndexOpt = sourceIndexFromLocation(_location); int length = -1; if (_location.start >= 0 && _location.end >= 0) 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 const& _sourceLocations) const +Json::Value ASTJsonExporter::sourceLocationsToJson(std::vector const& _sourceLocations) const { Json::Value locations = Json::arrayValue; @@ -137,7 +136,7 @@ Json::Value ASTJsonExporter::sourceLocationsToJson(vector const& return locations; } -string ASTJsonExporter::namePathToString(std::vector const& _namePath) +std::string ASTJsonExporter::namePathToString(std::vector const& _namePath) { return boost::algorithm::join(_namePath, "."s); } @@ -164,13 +163,13 @@ Json::Value ASTJsonExporter::typePointerToJson(std::optional } void ASTJsonExporter::appendExpressionAttributes( - std::vector>& _attributes, + std::vector>& _attributes, ExpressionAnnotation const& _annotation ) { - std::vector> exprAttributes = { - make_pair("typeDescriptions", typePointerToJson(_annotation.type)), - make_pair("argumentTypes", typePointerToJson(_annotation.arguments)) + std::vector> exprAttributes = { + std::make_pair("typeDescriptions", typePointerToJson(_annotation.type)), + std::make_pair("argumentTypes", typePointerToJson(_annotation.arguments)) }; addIfSet(exprAttributes, "isLValue", _annotation.isLValue); @@ -183,7 +182,7 @@ void ASTJsonExporter::appendExpressionAttributes( _attributes += exprAttributes; } -Json::Value ASTJsonExporter::inlineAssemblyIdentifierToJson(pair _info) const +Json::Value ASTJsonExporter::inlineAssemblyIdentifierToJson(std::pair _info) const { Json::Value tuple(Json::objectValue); tuple["src"] = sourceLocationToString(nativeLocationOf(*_info.first)); @@ -199,7 +198,7 @@ Json::Value ASTJsonExporter::inlineAssemblyIdentifierToJson(pair> attributes = { - make_pair("license", _node.licenseString() ? Json::Value(*_node.licenseString()) : Json::nullValue), - make_pair("nodes", toJson(_node.nodes())), + std::vector> attributes = { + std::make_pair("license", _node.licenseString() ? Json::Value(*_node.licenseString()) : Json::nullValue), + std::make_pair("nodes", toJson(_node.nodes())), }; if (_node.experimentalSolidity()) @@ -246,17 +245,17 @@ bool ASTJsonExporter::visit(PragmaDirective const& _node) for (auto const& literal: _node.literals()) literals.append(literal); setJsonNode(_node, "PragmaDirective", { - make_pair("literals", std::move(literals)) + std::make_pair("literals", std::move(literals)) }); return false; } bool ASTJsonExporter::visit(ImportDirective const& _node) { - std::vector> attributes = { - make_pair("file", _node.path()), - make_pair("sourceUnit", idOrNull(_node.annotation().sourceUnit)), - make_pair("scope", idOrNull(_node.scope())) + std::vector> attributes = { + std::make_pair("file", _node.path()), + std::make_pair("sourceUnit", idOrNull(_node.annotation().sourceUnit)), + std::make_pair("scope", idOrNull(_node.scope())) }; addIfSet(attributes, "absolutePath", _node.annotation().absolutePath); @@ -281,19 +280,19 @@ bool ASTJsonExporter::visit(ImportDirective const& _node) bool ASTJsonExporter::visit(ContractDefinition const& _node) { - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("contractKind", contractKind(_node.contractKind())), - make_pair("abstract", _node.abstract()), - make_pair("baseContracts", toJson(_node.baseContracts())), - make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies | ranges::views::keys)), + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("contractKind", contractKind(_node.contractKind())), + std::make_pair("abstract", _node.abstract()), + std::make_pair("baseContracts", toJson(_node.baseContracts())), + 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. - make_pair("usedEvents", getContainerIds(_node.interfaceEvents(false))), - make_pair("usedErrors", getContainerIds(_node.interfaceErrors(false))), - make_pair("nodes", toJson(_node.subNodes())), - make_pair("scope", idOrNull(_node.scope())) + std::make_pair("usedEvents", getContainerIds(_node.interfaceEvents(false))), + std::make_pair("usedErrors", getContainerIds(_node.interfaceErrors(false))), + std::make_pair("nodes", toJson(_node.subNodes())), + std::make_pair("scope", idOrNull(_node.scope())) }; addIfSet(attributes, "canonicalName", _node.annotation().canonicalName); @@ -306,7 +305,7 @@ bool ASTJsonExporter::visit(ContractDefinition const& _node) { Json::Value internalFunctionIDs(Json::objectValue); 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)); } @@ -322,9 +321,9 @@ bool ASTJsonExporter::visit(IdentifierPath const& _node) nameLocations.append(sourceLocationToString(location)); setJsonNode(_node, "IdentifierPath", { - make_pair("name", namePathToString(_node.path())), - make_pair("nameLocations", nameLocations), - make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)) + std::make_pair("name", namePathToString(_node.path())), + std::make_pair("nameLocations", nameLocations), + std::make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)) }); return false; } @@ -332,16 +331,16 @@ bool ASTJsonExporter::visit(IdentifierPath const& _node) bool ASTJsonExporter::visit(InheritanceSpecifier const& _node) { setJsonNode(_node, "InheritanceSpecifier", { - make_pair("baseName", toJson(_node.name())), - make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue) + std::make_pair("baseName", toJson(_node.name())), + std::make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue) }); return false; } bool ASTJsonExporter::visit(UsingForDirective const& _node) { - vector> attributes = { - make_pair("typeName", _node.typeName() ? toJson(*_node.typeName()) : Json::nullValue) + std::vector> attributes = { + std::make_pair("typeName", _node.typeName() ? toJson(*_node.typeName()) : Json::nullValue) }; if (_node.usesBraces()) @@ -355,7 +354,7 @@ bool ASTJsonExporter::visit(UsingForDirective const& _node) else { functionNode["definition"] = toJson(*function); - functionNode["operator"] = string(TokenTraits::toString(*op)); + functionNode["operator"] = std::string(TokenTraits::toString(*op)); } functionList.append(std::move(functionNode)); } @@ -377,13 +376,13 @@ bool ASTJsonExporter::visit(UsingForDirective const& _node) bool ASTJsonExporter::visit(StructDefinition const& _node) { - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("visibility", Declaration::visibilityToString(_node.visibility())), - make_pair("members", toJson(_node.members())), - make_pair("scope", idOrNull(_node.scope())) + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())), + std::make_pair("members", toJson(_node.members())), + std::make_pair("scope", idOrNull(_node.scope())) }; addIfSet(attributes,"canonicalName", _node.annotation().canonicalName); @@ -395,11 +394,11 @@ bool ASTJsonExporter::visit(StructDefinition const& _node) bool ASTJsonExporter::visit(EnumDefinition const& _node) { - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("members", toJson(_node.members())) + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("members", toJson(_node.members())) }; addIfSet(attributes,"canonicalName", _node.annotation().canonicalName); @@ -412,8 +411,8 @@ bool ASTJsonExporter::visit(EnumDefinition const& _node) bool ASTJsonExporter::visit(EnumValue const& _node) { setJsonNode(_node, "EnumValue", { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), }); return false; } @@ -421,10 +420,10 @@ bool ASTJsonExporter::visit(EnumValue const& _node) bool ASTJsonExporter::visit(UserDefinedValueTypeDefinition const& _node) { solAssert(_node.underlyingType(), ""); - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("underlyingType", toJson(*_node.underlyingType())) + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("underlyingType", toJson(*_node.underlyingType())) }; addIfSet(attributes, "canonicalName", _node.annotation().canonicalName); @@ -436,7 +435,7 @@ bool ASTJsonExporter::visit(UserDefinedValueTypeDefinition const& _node) bool ASTJsonExporter::visit(ParameterList const& _node) { setJsonNode(_node, "ParameterList", { - make_pair("parameters", toJson(_node.parameters())) + std::make_pair("parameters", toJson(_node.parameters())) }); return false; } @@ -444,30 +443,30 @@ bool ASTJsonExporter::visit(ParameterList const& _node) bool ASTJsonExporter::visit(OverrideSpecifier const& _node) { setJsonNode(_node, "OverrideSpecifier", { - make_pair("overrides", toJson(_node.overrides())) + std::make_pair("overrides", toJson(_node.overrides())) }); return false; } bool ASTJsonExporter::visit(FunctionDefinition const& _node) { - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("kind", _node.isFree() ? "freeFunction" : TokenTraits::toString(_node.kind())), - make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())), - make_pair("virtual", _node.markedVirtual()), - make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), - make_pair("parameters", toJson(_node.parameterList())), - make_pair("returnParameters", toJson(*_node.returnParameterList())), - make_pair("modifiers", toJson(_node.modifiers())), - make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue), - make_pair("implemented", _node.isImplemented()), - make_pair("scope", idOrNull(_node.scope())) + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("kind", _node.isFree() ? "freeFunction" : TokenTraits::toString(_node.kind())), + std::make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())), + std::make_pair("virtual", _node.markedVirtual()), + std::make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), + std::make_pair("parameters", toJson(_node.parameterList())), + std::make_pair("returnParameters", toJson(*_node.returnParameterList())), + std::make_pair("modifiers", toJson(_node.modifiers())), + std::make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue), + std::make_pair("implemented", _node.isImplemented()), + std::make_pair("scope", idOrNull(_node.scope())) }; - optional visibility; + std::optional visibility; if (_node.isConstructor()) { if (_node.annotation().contract) @@ -482,7 +481,7 @@ bool ASTJsonExporter::visit(FunctionDefinition const& _node) if (_node.isPartOfExternalInterface() && m_stackState > CompilerStack::State::ParsedAndImported) attributes.emplace_back("functionSelector", _node.externalIdentifierHex()); 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)); return false; @@ -490,19 +489,19 @@ bool ASTJsonExporter::visit(FunctionDefinition const& _node) bool ASTJsonExporter::visit(VariableDeclaration const& _node) { - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("typeName", toJson(_node.typeName())), - make_pair("constant", _node.isConstant()), - make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())), - make_pair("stateVariable", _node.isStateVariable()), - make_pair("storageLocation", location(_node.referenceLocation())), - make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), - make_pair("visibility", Declaration::visibilityToString(_node.visibility())), - make_pair("value", _node.value() ? toJson(*_node.value()) : Json::nullValue), - make_pair("scope", idOrNull(_node.scope())), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("typeName", toJson(_node.typeName())), + std::make_pair("constant", _node.isConstant()), + std::make_pair("mutability", VariableDeclaration::mutabilityToString(_node.mutability())), + std::make_pair("stateVariable", _node.isStateVariable()), + std::make_pair("storageLocation", location(_node.referenceLocation())), + std::make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), + std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())), + std::make_pair("value", _node.value() ? toJson(*_node.value()) : Json::nullValue), + std::make_pair("scope", idOrNull(_node.scope())), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) }; if (_node.isStateVariable() && _node.isPublic()) attributes.emplace_back("functionSelector", _node.externalIdentifierHex()); @@ -511,34 +510,34 @@ bool ASTJsonExporter::visit(VariableDeclaration const& _node) if (m_inEvent) attributes.emplace_back("indexed", _node.isIndexed()); 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)); return false; } bool ASTJsonExporter::visit(ModifierDefinition const& _node) { - std::vector> attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("visibility", Declaration::visibilityToString(_node.visibility())), - make_pair("parameters", toJson(_node.parameterList())), - make_pair("virtual", _node.markedVirtual()), - make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), - make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue) + std::vector> attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())), + std::make_pair("parameters", toJson(_node.parameterList())), + std::make_pair("virtual", _node.markedVirtual()), + std::make_pair("overrides", _node.overrides() ? toJson(*_node.overrides()) : Json::nullValue), + std::make_pair("body", _node.isImplemented() ? toJson(_node.body()) : Json::nullValue) }; 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)); return false; } bool ASTJsonExporter::visit(ModifierInvocation const& _node) { - std::vector> attributes{ - make_pair("modifierName", toJson(_node.name())), - make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue) + std::vector> attributes{ + std::make_pair("modifierName", toJson(_node.name())), + std::make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue) }; if (Declaration const* declaration = _node.name().annotation().referencedDeclaration) { @@ -554,16 +553,16 @@ bool ASTJsonExporter::visit(ModifierInvocation const& _node) bool ASTJsonExporter::visit(EventDefinition const& _node) { m_inEvent = true; - std::vector> _attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("parameters", toJson(_node.parameterList())), - make_pair("anonymous", _node.isAnonymous()) + std::vector> _attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("parameters", toJson(_node.parameterList())), + std::make_pair("anonymous", _node.isAnonymous()) }; if (m_stackState >= CompilerStack::State::AnalysisPerformed) _attributes.emplace_back( - make_pair( + std::make_pair( "eventSelector", 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) { - std::vector> _attributes = { - make_pair("name", _node.name()), - make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), - make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), - make_pair("parameters", toJson(_node.parameterList())) + std::vector> _attributes = { + std::make_pair("name", _node.name()), + std::make_pair("nameLocation", sourceLocationToString(_node.nameLocation())), + std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue), + std::make_pair("parameters", toJson(_node.parameterList())) }; 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)); return false; @@ -589,13 +588,13 @@ bool ASTJsonExporter::visit(ErrorDefinition const& _node) bool ASTJsonExporter::visit(ElementaryTypeName const& _node) { - std::vector> attributes = { - make_pair("name", _node.typeName().toString()), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) + std::vector> attributes = { + std::make_pair("name", _node.typeName().toString()), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) }; 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)); return false; @@ -604,9 +603,9 @@ bool ASTJsonExporter::visit(ElementaryTypeName const& _node) bool ASTJsonExporter::visit(UserDefinedTypeName const& _node) { setJsonNode(_node, "UserDefinedTypeName", { - make_pair("pathNode", toJson(_node.pathNode())), - make_pair("referencedDeclaration", idOrNull(_node.pathNode().annotation().referencedDeclaration)), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) + std::make_pair("pathNode", toJson(_node.pathNode())), + std::make_pair("referencedDeclaration", idOrNull(_node.pathNode().annotation().referencedDeclaration)), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) }); return false; } @@ -614,11 +613,11 @@ bool ASTJsonExporter::visit(UserDefinedTypeName const& _node) bool ASTJsonExporter::visit(FunctionTypeName const& _node) { setJsonNode(_node, "FunctionTypeName", { - make_pair("visibility", Declaration::visibilityToString(_node.visibility())), - make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())), - make_pair("parameterTypes", toJson(*_node.parameterTypeList())), - make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) + std::make_pair("visibility", Declaration::visibilityToString(_node.visibility())), + std::make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())), + std::make_pair("parameterTypes", toJson(*_node.parameterTypeList())), + std::make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) }); return false; } @@ -626,13 +625,13 @@ bool ASTJsonExporter::visit(FunctionTypeName const& _node) bool ASTJsonExporter::visit(Mapping const& _node) { setJsonNode(_node, "Mapping", { - make_pair("keyType", toJson(_node.keyType())), - make_pair("keyName", _node.keyName()), - make_pair("keyNameLocation", sourceLocationToString(_node.keyNameLocation())), - make_pair("valueType", toJson(_node.valueType())), - make_pair("valueName", _node.valueName()), - make_pair("valueNameLocation", sourceLocationToString(_node.valueNameLocation())), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) + std::make_pair("keyType", toJson(_node.keyType())), + std::make_pair("keyName", _node.keyName()), + std::make_pair("keyNameLocation", sourceLocationToString(_node.keyNameLocation())), + std::make_pair("valueType", toJson(_node.valueType())), + std::make_pair("valueName", _node.valueName()), + std::make_pair("valueNameLocation", sourceLocationToString(_node.valueNameLocation())), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) }); return false; } @@ -640,20 +639,20 @@ bool ASTJsonExporter::visit(Mapping const& _node) bool ASTJsonExporter::visit(ArrayTypeName const& _node) { setJsonNode(_node, "ArrayTypeName", { - make_pair("baseType", toJson(_node.baseType())), - make_pair("length", toJsonOrNull(_node.length())), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) + std::make_pair("baseType", toJson(_node.baseType())), + std::make_pair("length", toJsonOrNull(_node.length())), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true)) }); return false; } bool ASTJsonExporter::visit(InlineAssembly const& _node) { - vector> externalReferences; + std::vector> externalReferences; for (auto const& it: _node.annotation().externalReferences) if (it.first) - externalReferences.emplace_back(make_pair( + externalReferences.emplace_back(std::make_pair( it.first->name.str(), inlineAssemblyIdentifierToJson(it) )); @@ -664,10 +663,10 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node) for (Json::Value& it: externalReferences | ranges::views::values) externalReferencesJson.append(std::move(it)); - std::vector> attributes = { - make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))), - make_pair("externalReferences", std::move(externalReferencesJson)), - make_pair("evmVersion", dynamic_cast(_node.dialect()).evmVersion().name()) + std::vector> attributes = { + std::make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))), + std::make_pair("externalReferences", std::move(externalReferencesJson)), + std::make_pair("evmVersion", dynamic_cast(_node.dialect()).evmVersion().name()) }; if (_node.flags()) @@ -678,7 +677,7 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node) flags.append(*flag); else 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)); @@ -688,7 +687,7 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node) bool ASTJsonExporter::visit(Block const& _node) { setJsonNode(_node, _node.unchecked() ? "UncheckedBlock" : "Block", { - make_pair("statements", toJson(_node.statements())) + std::make_pair("statements", toJson(_node.statements())) }); return false; } @@ -702,9 +701,9 @@ bool ASTJsonExporter::visit(PlaceholderStatement const& _node) bool ASTJsonExporter::visit(IfStatement const& _node) { setJsonNode(_node, "IfStatement", { - make_pair("condition", toJson(_node.condition())), - make_pair("trueBody", toJson(_node.trueStatement())), - make_pair("falseBody", toJsonOrNull(_node.falseStatement())) + std::make_pair("condition", toJson(_node.condition())), + std::make_pair("trueBody", toJson(_node.trueStatement())), + std::make_pair("falseBody", toJsonOrNull(_node.falseStatement())) }); return false; } @@ -712,9 +711,9 @@ bool ASTJsonExporter::visit(IfStatement const& _node) bool ASTJsonExporter::visit(TryCatchClause const& _node) { setJsonNode(_node, "TryCatchClause", { - make_pair("errorName", _node.errorName()), - make_pair("parameters", toJsonOrNull(_node.parameters())), - make_pair("block", toJson(_node.block())) + std::make_pair("errorName", _node.errorName()), + std::make_pair("parameters", toJsonOrNull(_node.parameters())), + std::make_pair("block", toJson(_node.block())) }); return false; } @@ -722,8 +721,8 @@ bool ASTJsonExporter::visit(TryCatchClause const& _node) bool ASTJsonExporter::visit(TryStatement const& _node) { setJsonNode(_node, "TryStatement", { - make_pair("externalCall", toJson(_node.externalCall())), - make_pair("clauses", toJson(_node.clauses())) + std::make_pair("externalCall", toJson(_node.externalCall())), + std::make_pair("clauses", toJson(_node.clauses())) }); return false; } @@ -734,8 +733,8 @@ bool ASTJsonExporter::visit(WhileStatement const& _node) _node, _node.isDoWhile() ? "DoWhileStatement" : "WhileStatement", { - make_pair("condition", toJson(_node.condition())), - make_pair("body", toJson(_node.body())) + std::make_pair("condition", toJson(_node.condition())), + std::make_pair("body", toJson(_node.body())) } ); return false; @@ -744,10 +743,10 @@ bool ASTJsonExporter::visit(WhileStatement const& _node) bool ASTJsonExporter::visit(ForStatement const& _node) { setJsonNode(_node, "ForStatement", { - make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())), - make_pair("condition", toJsonOrNull(_node.condition())), - make_pair("loopExpression", toJsonOrNull(_node.loopExpression())), - make_pair("body", toJson(_node.body())) + std::make_pair("initializationExpression", toJsonOrNull(_node.initializationExpression())), + std::make_pair("condition", toJsonOrNull(_node.condition())), + std::make_pair("loopExpression", toJsonOrNull(_node.loopExpression())), + std::make_pair("body", toJson(_node.body())) }); return false; } @@ -767,8 +766,8 @@ bool ASTJsonExporter::visit(Break const& _node) bool ASTJsonExporter::visit(Return const& _node) { setJsonNode(_node, "Return", { - make_pair("expression", toJsonOrNull(_node.expression())), - make_pair("functionReturnParameters", idOrNull(_node.annotation().functionReturnParameters)) + std::make_pair("expression", toJsonOrNull(_node.expression())), + std::make_pair("functionReturnParameters", idOrNull(_node.annotation().functionReturnParameters)) }); return false; } @@ -782,7 +781,7 @@ bool ASTJsonExporter::visit(Throw const& _node) bool ASTJsonExporter::visit(EmitStatement const& _node) { setJsonNode(_node, "EmitStatement", { - make_pair("eventCall", toJson(_node.eventCall())) + std::make_pair("eventCall", toJson(_node.eventCall())) }); return false; } @@ -790,7 +789,7 @@ bool ASTJsonExporter::visit(EmitStatement const& _node) bool ASTJsonExporter::visit(RevertStatement const& _node) { setJsonNode(_node, "RevertStatement", { - make_pair("errorCall", toJson(_node.errorCall())) + std::make_pair("errorCall", toJson(_node.errorCall())) }); return false; } @@ -801,9 +800,9 @@ bool ASTJsonExporter::visit(VariableDeclarationStatement const& _node) for (auto const& v: _node.declarations()) appendMove(varDecs, idOrNull(v.get())); setJsonNode(_node, "VariableDeclarationStatement", { - make_pair("assignments", std::move(varDecs)), - make_pair("declarations", toJson(_node.declarations())), - make_pair("initialValue", toJsonOrNull(_node.initialValue())) + std::make_pair("assignments", std::move(varDecs)), + std::make_pair("declarations", toJson(_node.declarations())), + std::make_pair("initialValue", toJsonOrNull(_node.initialValue())) }); return false; } @@ -811,17 +810,17 @@ bool ASTJsonExporter::visit(VariableDeclarationStatement const& _node) bool ASTJsonExporter::visit(ExpressionStatement const& _node) { setJsonNode(_node, "ExpressionStatement", { - make_pair("expression", toJson(_node.expression())) + std::make_pair("expression", toJson(_node.expression())) }); return false; } bool ASTJsonExporter::visit(Conditional const& _node) { - std::vector> attributes = { - make_pair("condition", toJson(_node.condition())), - make_pair("trueExpression", toJson(_node.trueExpression())), - make_pair("falseExpression", toJson(_node.falseExpression())) + std::vector> attributes = { + std::make_pair("condition", toJson(_node.condition())), + std::make_pair("trueExpression", toJson(_node.trueExpression())), + std::make_pair("falseExpression", toJson(_node.falseExpression())) }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "Conditional", std::move(attributes)); @@ -830,10 +829,10 @@ bool ASTJsonExporter::visit(Conditional const& _node) bool ASTJsonExporter::visit(Assignment const& _node) { - std::vector> attributes = { - make_pair("operator", TokenTraits::toString(_node.assignmentOperator())), - make_pair("leftHandSide", toJson(_node.leftHandSide())), - make_pair("rightHandSide", toJson(_node.rightHandSide())) + std::vector> attributes = { + std::make_pair("operator", TokenTraits::toString(_node.assignmentOperator())), + std::make_pair("leftHandSide", toJson(_node.leftHandSide())), + std::make_pair("rightHandSide", toJson(_node.rightHandSide())) }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "Assignment", std::move(attributes)); @@ -842,9 +841,9 @@ bool ASTJsonExporter::visit(Assignment const& _node) bool ASTJsonExporter::visit(TupleExpression const& _node) { - std::vector> attributes = { - make_pair("isInlineArray", Json::Value(_node.isInlineArray())), - make_pair("components", toJson(_node.components())), + std::vector> attributes = { + std::make_pair("isInlineArray", Json::Value(_node.isInlineArray())), + std::make_pair("components", toJson(_node.components())), }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "TupleExpression", std::move(attributes)); @@ -853,10 +852,10 @@ bool ASTJsonExporter::visit(TupleExpression const& _node) bool ASTJsonExporter::visit(UnaryOperation const& _node) { - std::vector> attributes = { - make_pair("prefix", _node.isPrefixOperation()), - make_pair("operator", TokenTraits::toString(_node.getOperator())), - make_pair("subExpression", toJson(_node.subExpression())) + std::vector> attributes = { + std::make_pair("prefix", _node.isPrefixOperation()), + std::make_pair("operator", TokenTraits::toString(_node.getOperator())), + 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. 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) { - std::vector> attributes = { - make_pair("operator", TokenTraits::toString(_node.getOperator())), - make_pair("leftExpression", toJson(_node.leftExpression())), - make_pair("rightExpression", toJson(_node.rightExpression())), - make_pair("commonType", typePointerToJson(_node.annotation().commonType)), + std::vector> attributes = { + std::make_pair("operator", TokenTraits::toString(_node.getOperator())), + std::make_pair("leftExpression", toJson(_node.leftExpression())), + std::make_pair("rightExpression", toJson(_node.rightExpression())), + 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. if (_node.annotation().userDefinedFunction.set() && *_node.annotation().userDefinedFunction != nullptr) @@ -887,12 +886,12 @@ bool ASTJsonExporter::visit(FunctionCall const& _node) Json::Value names(Json::arrayValue); for (auto const& name: _node.names()) names.append(Json::Value(*name)); - std::vector> attributes = { - make_pair("expression", toJson(_node.expression())), - make_pair("names", std::move(names)), - make_pair("nameLocations", sourceLocationsToJson(_node.nameLocations())), - make_pair("arguments", toJson(_node.arguments())), - make_pair("tryCall", _node.annotation().tryCall) + std::vector> attributes = { + std::make_pair("expression", toJson(_node.expression())), + std::make_pair("names", std::move(names)), + std::make_pair("nameLocations", sourceLocationsToJson(_node.nameLocations())), + std::make_pair("arguments", toJson(_node.arguments())), + std::make_pair("tryCall", _node.annotation().tryCall) }; if (_node.annotation().kind.set()) @@ -912,10 +911,10 @@ bool ASTJsonExporter::visit(FunctionCallOptions const& _node) for (auto const& name: _node.names()) names.append(Json::Value(*name)); - std::vector> attributes = { - make_pair("expression", toJson(_node.expression())), - make_pair("names", std::move(names)), - make_pair("options", toJson(_node.options())), + std::vector> attributes = { + std::make_pair("expression", toJson(_node.expression())), + std::make_pair("names", std::move(names)), + std::make_pair("options", toJson(_node.options())), }; appendExpressionAttributes(attributes, _node.annotation()); @@ -925,8 +924,8 @@ bool ASTJsonExporter::visit(FunctionCallOptions const& _node) bool ASTJsonExporter::visit(NewExpression const& _node) { - std::vector> attributes = { - make_pair("typeName", toJson(_node.typeName())) + std::vector> attributes = { + std::make_pair("typeName", toJson(_node.typeName())) }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "NewExpression", std::move(attributes)); @@ -935,11 +934,11 @@ bool ASTJsonExporter::visit(NewExpression const& _node) bool ASTJsonExporter::visit(MemberAccess const& _node) { - std::vector> attributes = { - make_pair("memberName", _node.memberName()), - make_pair("memberLocation", Json::Value(sourceLocationToString(_node.memberLocation()))), - make_pair("expression", toJson(_node.expression())), - make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)), + std::vector> attributes = { + std::make_pair("memberName", _node.memberName()), + std::make_pair("memberLocation", Json::Value(sourceLocationToString(_node.memberLocation()))), + std::make_pair("expression", toJson(_node.expression())), + std::make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)), }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "MemberAccess", std::move(attributes)); @@ -948,9 +947,9 @@ bool ASTJsonExporter::visit(MemberAccess const& _node) bool ASTJsonExporter::visit(IndexAccess const& _node) { - std::vector> attributes = { - make_pair("baseExpression", toJson(_node.baseExpression())), - make_pair("indexExpression", toJsonOrNull(_node.indexExpression())), + std::vector> attributes = { + std::make_pair("baseExpression", toJson(_node.baseExpression())), + std::make_pair("indexExpression", toJsonOrNull(_node.indexExpression())), }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "IndexAccess", std::move(attributes)); @@ -959,10 +958,10 @@ bool ASTJsonExporter::visit(IndexAccess const& _node) bool ASTJsonExporter::visit(IndexRangeAccess const& _node) { - std::vector> attributes = { - make_pair("baseExpression", toJson(_node.baseExpression())), - make_pair("startExpression", toJsonOrNull(_node.startExpression())), - make_pair("endExpression", toJsonOrNull(_node.endExpression())), + std::vector> attributes = { + std::make_pair("baseExpression", toJson(_node.baseExpression())), + std::make_pair("startExpression", toJsonOrNull(_node.startExpression())), + std::make_pair("endExpression", toJsonOrNull(_node.endExpression())), }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "IndexRangeAccess", std::move(attributes)); @@ -975,19 +974,19 @@ bool ASTJsonExporter::visit(Identifier const& _node) for (auto const& dec: _node.annotation().overloadedDeclarations) overloads.append(nodeId(*dec)); setJsonNode(_node, "Identifier", { - make_pair("name", _node.name()), - make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)), - make_pair("overloadedDeclarations", overloads), - make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)), - make_pair("argumentTypes", typePointerToJson(_node.annotation().arguments)) + std::make_pair("name", _node.name()), + std::make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration)), + std::make_pair("overloadedDeclarations", overloads), + std::make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)), + std::make_pair("argumentTypes", typePointerToJson(_node.annotation().arguments)) }); return false; } bool ASTJsonExporter::visit(ElementaryTypeNameExpression const& _node) { - std::vector> attributes = { - make_pair("typeName", toJson(_node.type())) + std::vector> attributes = { + std::make_pair("typeName", toJson(_node.type())) }; appendExpressionAttributes(attributes, _node.annotation()); setJsonNode(_node, "ElementaryTypeNameExpression", std::move(attributes)); @@ -1000,11 +999,11 @@ bool ASTJsonExporter::visit(Literal const& _node) if (!util::validateUTF8(_node.value())) value = Json::nullValue; Token subdenomination = Token(_node.subDenomination()); - std::vector> attributes = { - make_pair("kind", literalTokenKind(_node.token())), - make_pair("value", value), - make_pair("hexValue", util::toHex(util::asBytes(_node.value()))), - make_pair( + std::vector> attributes = { + std::make_pair("kind", literalTokenKind(_node.token())), + std::make_pair("value", value), + std::make_pair("hexValue", util::toHex(util::asBytes(_node.value()))), + std::make_pair( "subdenomination", subdenomination == Token::Illegal ? Json::nullValue : @@ -1019,8 +1018,8 @@ bool ASTJsonExporter::visit(Literal const& _node) bool ASTJsonExporter::visit(StructuredDocumentation const& _node) { Json::Value text{*_node.text()}; - std::vector> attributes = { - make_pair("text", text) + std::vector> attributes = { + std::make_pair("text", text) }; setJsonNode(_node, "StructuredDocumentation", std::move(attributes)); return false; @@ -1033,7 +1032,7 @@ void ASTJsonExporter::endVisit(EventDefinition const&) m_inEvent = false; } -string ASTJsonExporter::location(VariableDeclaration::Location _location) +std::string ASTJsonExporter::location(VariableDeclaration::Location _location) { switch (_location) { @@ -1050,7 +1049,7 @@ string ASTJsonExporter::location(VariableDeclaration::Location _location) return {}; } -string ASTJsonExporter::contractKind(ContractKind _kind) +std::string ASTJsonExporter::contractKind(ContractKind _kind) { switch (_kind) { @@ -1066,7 +1065,7 @@ string ASTJsonExporter::contractKind(ContractKind _kind) return {}; } -string ASTJsonExporter::functionCallKind(FunctionCallKind _kind) +std::string ASTJsonExporter::functionCallKind(FunctionCallKind _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) { @@ -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"; } -string ASTJsonExporter::type(VariableDeclaration const& _varDecl) +std::string ASTJsonExporter::type(VariableDeclaration const& _varDecl) { return _varDecl.annotation().type ? _varDecl.annotation().type->toString() : "Unknown"; } diff --git a/libsolidity/ast/ASTJsonImporter.cpp b/libsolidity/ast/ASTJsonImporter.cpp index dd7098aab..6e6dd9eb5 100644 --- a/libsolidity/ast/ASTJsonImporter.cpp +++ b/libsolidity/ast/ASTJsonImporter.cpp @@ -37,8 +37,6 @@ #include #include -using namespace std; - namespace solidity::frontend { @@ -50,16 +48,16 @@ ASTPointer ASTJsonImporter::nullOrCast(Json::Value const& _json) if (_json.isNull()) return nullptr; else - return dynamic_pointer_cast(convertJsonToASTNode(_json)); + return std::dynamic_pointer_cast(convertJsonToASTNode(_json)); } // ============ public =========================== -map> ASTJsonImporter::jsonToSourceUnit(map const& _sourceList) +std::map> ASTJsonImporter::jsonToSourceUnit(std::map const& _sourceList) { for (auto const& src: _sourceList) - m_sourceNames.emplace_back(make_shared(src.first)); + m_sourceNames.emplace_back(std::make_shared(src.first)); for (auto const& srcPair: _sourceList) { astAssert(!srcPair.second.isNull()); @@ -81,7 +79,7 @@ ASTPointer ASTJsonImporter::createASTNode(Json::Value const& _node, Args&&... astAssert(m_usedIDs.insert(id).second, "Found duplicate node ID!"); - auto n = make_shared( + auto n = std::make_shared( id, createSourceLocation(_node), std::forward(_args)... @@ -96,9 +94,9 @@ SourceLocation const ASTJsonImporter::createSourceLocation(Json::Value const& _n return solidity::langutil::parseSourceLocation(_node["src"].asString(), m_sourceNames); } -optional> ASTJsonImporter::createSourceLocations(Json::Value const& _node) const +std::optional> ASTJsonImporter::createSourceLocations(Json::Value const& _node) const { - vector locations; + std::vector locations; if (_node.isMember("nameLocations") && _node["nameLocations"].isArray()) { @@ -107,7 +105,7 @@ optional> ASTJsonImporter::createSourceLocations(Json::Va return locations; } - return nullopt; + return std::nullopt; } SourceLocation ASTJsonImporter::createNameSourceLocation(Json::Value const& _node) @@ -134,7 +132,7 @@ SourceLocation ASTJsonImporter::createValueNameSourceLocation(Json::Value const& template ASTPointer ASTJsonImporter::convertJsonToASTNode(Json::Value const& _node) { - ASTPointer ret = dynamic_pointer_cast(convertJsonToASTNode(_node)); + ASTPointer ret = std::dynamic_pointer_cast(convertJsonToASTNode(_node)); astAssert(ret, "cast of converted json-node must not be nullptr"); return ret; } @@ -143,7 +141,7 @@ ASTPointer ASTJsonImporter::convertJsonToASTNode(Json::Value const& _node) ASTPointer ASTJsonImporter::convertJsonToASTNode(Json::Value const& _json) { 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") return createPragmaDirective(_json); if (nodeType == "ImportDirective") @@ -265,9 +263,9 @@ ASTPointer ASTJsonImporter::convertJsonToASTNode(Json::Value const& _js // ============ functions to instantiate the AST-Nodes from Json-Nodes ============== -ASTPointer ASTJsonImporter::createSourceUnit(Json::Value const& _node, string const& _srcName) +ASTPointer ASTJsonImporter::createSourceUnit(Json::Value const& _node, std::string const& _srcName) { - optional license; + std::optional license; if (_node.isMember("license") && !_node["license"].isNull()) license = _node["license"].asString(); @@ -275,7 +273,7 @@ ASTPointer ASTJsonImporter::createSourceUnit(Json::Value const& _nod if (_node.isMember("experimentalSolidity") && !_node["experimentalSolidity"].isNull()) experimentalSolidity = _node["experimentalSolidity"].asBool(); - vector> nodes; + std::vector> nodes; for (auto& child: member(_node, "nodes")) nodes.emplace_back(convertJsonToASTNode(child)); @@ -286,11 +284,11 @@ ASTPointer ASTJsonImporter::createSourceUnit(Json::Value const& _nod ASTPointer ASTJsonImporter::createPragmaDirective(Json::Value const& _node) { - vector tokens; - vector literals; + std::vector tokens; + std::vector literals; for (auto const& lit: member(_node, "literals")) { - string l = lit.asString(); + std::string l = lit.asString(); literals.push_back(l); tokens.push_back(scanSingleToken(l)); } @@ -309,7 +307,7 @@ ASTPointer ASTJsonImporter::createImportDirective(Json::Value c symbolAliases.push_back({ createIdentifier(tuple["foreign"]), - tuple["local"].isNull() ? nullptr : make_shared(tuple["local"].asString()), + tuple["local"].isNull() ? nullptr : std::make_shared(tuple["local"].asString()), createSourceLocation(tuple["foreign"])} ); } @@ -343,7 +341,7 @@ ASTPointer ASTJsonImporter::createContractDefinition(Json::V return createASTNode( _node, - make_shared(_node["name"].asString()), + std::make_shared(_node["name"].asString()), createNameSourceLocation(_node), _node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")), baseContracts, @@ -357,13 +355,13 @@ ASTPointer ASTJsonImporter::createIdentifierPath(Json::Value con { astAssert(_node["name"].isString(), "Expected 'name' to be a string!"); - vector namePath; - vector namePathLocations; - vector strs; - string nameString = member(_node, "name").asString(); + std::vector namePath; + std::vector namePathLocations; + std::vector strs; + std::string nameString = member(_node, "name").asString(); boost::algorithm::split(strs, nameString, boost::is_any_of(".")); 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."); namePath.emplace_back(s); @@ -395,20 +393,20 @@ ASTPointer ASTJsonImporter::createInheritanceSpecifier(Jso return createASTNode( _node, createIdentifierPath(member(_node, "baseName")), - member(_node, "arguments").isNull() ? nullptr : make_unique>>(arguments) + member(_node, "arguments").isNull() ? nullptr : std::make_unique>>(arguments) ); } ASTPointer ASTJsonImporter::createUsingForDirective(Json::Value const& _node) { - vector> functions; - vector> operators; + std::vector> functions; + std::vector> operators; if (_node.isMember("libraryName")) { astAssert(!_node["libraryName"].isArray()); astAssert(!_node["libraryName"]["operator"]); functions.emplace_back(createIdentifierPath(_node["libraryName"])); - operators.emplace_back(nullopt); + operators.emplace_back(std::nullopt); } else if (_node.isMember("functionList")) for (Json::Value const& function: _node["functionList"]) @@ -419,7 +417,7 @@ ASTPointer ASTJsonImporter::createUsingForDirective(Json::Val astAssert(!function.isMember("definition")); functions.emplace_back(createIdentifierPath(function["function"])); - operators.emplace_back(nullopt); + operators.emplace_back(std::nullopt); } else { @@ -520,7 +518,7 @@ ASTPointer ASTJsonImporter::createFunctionDefinition(Json::V Token kind; bool freeFunction = false; - string kindStr = member(_node, "kind").asString(); + std::string kindStr = member(_node, "kind").asString(); if (kindStr == "constructor") kind = Token::Constructor; @@ -572,7 +570,7 @@ ASTPointer ASTJsonImporter::createVariableDeclaration(Json: VariableDeclaration::Mutability mutability{}; 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") { mutability = VariableDeclaration::Mutability::Constant; @@ -592,7 +590,7 @@ ASTPointer ASTJsonImporter::createVariableDeclaration(Json: return createASTNode( _node, nullOrCast(member(_node, "typeName")), - make_shared(member(_node, "name").asString()), + std::make_shared(member(_node, "name").asString()), createNameSourceLocation(_node), nullOrCast(member(_node, "value")), visibility(_node), @@ -626,7 +624,7 @@ ASTPointer ASTJsonImporter::createModifierInvocation(Json::V return createASTNode( _node, createIdentifierPath(member(_node, "modifierName")), - member(_node, "arguments").isNull() ? nullptr : make_unique>>(arguments) + member(_node, "arguments").isNull() ? nullptr : std::make_unique>>(arguments) ); } @@ -660,9 +658,9 @@ ASTPointer ASTJsonImporter::createElementaryTypeName(Json::V 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; - tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(name); + std::tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(name); ElementaryTypeNameToken elem(token, firstNum, secondNum); std::optional mutability = {}; @@ -721,19 +719,19 @@ ASTPointer ASTJsonImporter::createInlineAssembly(Json::Value con astAssert(m_evmVersion == evmVersion, "Imported tree evm version differs from configured evm version!"); yul::Dialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(evmVersion.value()); - ASTPointer>> flags; + ASTPointer>> flags; if (_node.isMember("flags")) { - flags = make_shared>>(); + flags = std::make_shared>>(); Json::Value const& flagsNode = _node["flags"]; astAssert(flagsNode.isArray(), "Assembly flags must be an array."); for (Json::ArrayIndex i = 0; i < flagsNode.size(); ++i) { astAssert(flagsNode[i].isString(), "Assembly flag must be a string."); - flags->emplace_back(make_shared(flagsNode[i].asString())); + flags->emplace_back(std::make_shared(flagsNode[i].asString())); } } - shared_ptr operations = make_shared(yul::AsmJsonImporter(m_sourceNames).createBlock(member(_node, "AST"))); + std::shared_ptr operations = std::make_shared(yul::AsmJsonImporter(m_sourceNames).createBlock(member(_node, "AST"))); return createASTNode( _node, nullOrASTString(_node, "documentation"), @@ -787,7 +785,7 @@ ASTPointer ASTJsonImporter::createTryCatchClause(Json::Value con ASTPointer ASTJsonImporter::createTryStatement(Json::Value const& _node) { - vector> clauses; + std::vector> clauses; for (auto& param: _node["clauses"]) clauses.emplace_back(createTryCatchClause(param)); @@ -957,10 +955,10 @@ ASTPointer ASTJsonImporter::createFunctionCall(Json::Value const& for (auto& name: member(_node, "names")) { astAssert(name.isString(), "Expected 'names' members to be strings!"); - names.push_back(make_shared(name.asString())); + names.push_back(std::make_shared(name.asString())); } - optional> sourceLocations = createSourceLocations(_node); + std::optional> sourceLocations = createSourceLocations(_node); return createASTNode( _node, @@ -969,7 +967,7 @@ ASTPointer ASTJsonImporter::createFunctionCall(Json::Value const& names, sourceLocations ? *sourceLocations : - vector(names.size()) + std::vector(names.size()) ); } @@ -982,7 +980,7 @@ ASTPointer ASTJsonImporter::createFunctionCallOptions(Json: for (auto& name: member(_node, "names")) { astAssert(name.isString(), "Expected 'names' members to be strings!"); - names.push_back(make_shared(name.asString())); + names.push_back(std::make_shared(name.asString())); } return createASTNode( @@ -1049,14 +1047,14 @@ ASTPointer ASTJsonImporter::createElementaryTypeNa ASTPointer ASTJsonImporter::createLiteral(Json::Value const& _node) { - static string const valStr = "value"; - static string const hexValStr = "hexValue"; + static std::string const valStr = "value"; + static std::string const hexValStr = "hexValue"; astAssert(member(_node, valStr).isString() || member(_node, hexValStr).isString(), "Literal-value is unset."); ASTPointer value = _node.isMember(hexValStr) ? - make_shared(util::asString(util::fromHex(_node[hexValStr].asString()))) : - make_shared(_node[valStr].asString()); + std::make_shared(util::asString(util::fromHex(_node[hexValStr].asString()))) : + std::make_shared(_node[valStr].asString()); return createASTNode( _node, @@ -1068,19 +1066,19 @@ ASTPointer ASTJsonImporter::createLiteral(Json::Value const& _node) ASTPointer 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"); return createASTNode( _node, - make_shared(_node[textString].asString()) + std::make_shared(_node[textString].asString()) ); } // ===== 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)) return Json::nullValue; @@ -1095,19 +1093,19 @@ Token ASTJsonImporter::scanSingleToken(Json::Value const& _node) return scanner.currentToken(); } -ASTPointer ASTJsonImporter::nullOrASTString(Json::Value const& _json, string const& _name) +ASTPointer ASTJsonImporter::nullOrASTString(Json::Value const& _json, std::string const& _name) { return _json[_name].isString() ? memberAsASTString(_json, _name) : nullptr; } -ASTPointer ASTJsonImporter::memberAsASTString(Json::Value const& _node, string const& _name) +ASTPointer ASTJsonImporter::memberAsASTString(Json::Value const& _node, std::string const& _name) { Json::Value value = member(_node, _name); astAssert(value.isString(), "field " + _name + " must be of type string."); - return make_shared(_node[_name].asString()); + return std::make_shared(_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); 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"); astAssert(visibility.isString(), "'visibility' expected to be a string."); - string const visibilityStr = visibility.asString(); + std::string const visibilityStr = visibility.asString(); if (visibilityStr == "default") return Visibility::Default; @@ -1180,7 +1178,7 @@ VariableDeclaration::Location ASTJsonImporter::location(Json::Value const& _node Json::Value storageLoc = member(_node, "storageLocation"); astAssert(storageLoc.isString(), "'storageLocation' expected to be a string."); - string const storageLocStr = storageLoc.asString(); + std::string const storageLocStr = storageLoc.asString(); if (storageLocStr == "default") return VariableDeclaration::Location::Unspecified; @@ -1206,7 +1204,7 @@ Literal::SubDenomination ASTJsonImporter::subdenomination(Json::Value const& _no astAssert(subDen.isString(), "'subDenomination' expected to be string."); - string const subDenStr = subDen.asString(); + std::string const subDenStr = subDen.asString(); if (subDenStr == "wei") return Literal::SubDenomination::Wei; @@ -1236,7 +1234,7 @@ Literal::SubDenomination ASTJsonImporter::subdenomination(Json::Value const& _no StateMutability ASTJsonImporter::stateMutability(Json::Value const& _node) { 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") return StateMutability::Pure; diff --git a/libsolidity/ast/CallGraph.cpp b/libsolidity/ast/CallGraph.cpp index bf37b2264..04275c374 100644 --- a/libsolidity/ast/CallGraph.cpp +++ b/libsolidity/ast/CallGraph.cpp @@ -18,7 +18,6 @@ #include -using namespace std; using namespace solidity::frontend; 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()) return _lhs.index() < _rhs.index(); - if (holds_alternative(_lhs)) - return get(_lhs) < get(_rhs); - return get(_lhs)->id() < get(_rhs)->id(); + if (std::holds_alternative(_lhs)) + return std::get(_lhs) < std::get(_rhs); + return std::get(_lhs)->id() < std::get(_rhs)->id(); } bool CallGraph::CompareByID::operator()(Node const& _lhs, int64_t _rhs) const { - solAssert(!holds_alternative(_lhs), ""); + solAssert(!std::holds_alternative(_lhs), ""); - return get(_lhs)->id() < _rhs; + return std::get(_lhs)->id() < _rhs; } bool CallGraph::CompareByID::operator()(int64_t _lhs, Node const& _rhs) const { - solAssert(!holds_alternative(_rhs), ""); + solAssert(!std::holds_alternative(_rhs), ""); - return _lhs < get(_rhs)->id(); + return _lhs < std::get(_rhs)->id(); } diff --git a/libsolidity/ast/TypeProvider.cpp b/libsolidity/ast/TypeProvider.cpp index 6cf8b5c03..da5087556 100644 --- a/libsolidity/ast/TypeProvider.cpp +++ b/libsolidity/ast/TypeProvider.cpp @@ -21,7 +21,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::frontend; 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 /// they rely on `byte` being available which we cannot guarantee in the static init context. -unique_ptr TypeProvider::m_bytesStorage; -unique_ptr TypeProvider::m_bytesMemory; -unique_ptr TypeProvider::m_bytesCalldata; -unique_ptr TypeProvider::m_stringStorage; -unique_ptr TypeProvider::m_stringMemory; +std::unique_ptr TypeProvider::m_bytesStorage; +std::unique_ptr TypeProvider::m_bytesMemory; +std::unique_ptr TypeProvider::m_bytesCalldata; +std::unique_ptr TypeProvider::m_stringStorage; +std::unique_ptr TypeProvider::m_stringMemory; TupleType const TypeProvider::m_emptyTuple{}; AddressType const TypeProvider::m_payableAddress{StateMutability::Payable}; AddressType const TypeProvider::m_address{StateMutability::NonPayable}; -array, 32> const TypeProvider::m_intM{{ - {make_unique(8 * 1, IntegerType::Modifier::Signed)}, - {make_unique(8 * 2, IntegerType::Modifier::Signed)}, - {make_unique(8 * 3, IntegerType::Modifier::Signed)}, - {make_unique(8 * 4, IntegerType::Modifier::Signed)}, - {make_unique(8 * 5, IntegerType::Modifier::Signed)}, - {make_unique(8 * 6, IntegerType::Modifier::Signed)}, - {make_unique(8 * 7, IntegerType::Modifier::Signed)}, - {make_unique(8 * 8, IntegerType::Modifier::Signed)}, - {make_unique(8 * 9, IntegerType::Modifier::Signed)}, - {make_unique(8 * 10, IntegerType::Modifier::Signed)}, - {make_unique(8 * 11, IntegerType::Modifier::Signed)}, - {make_unique(8 * 12, IntegerType::Modifier::Signed)}, - {make_unique(8 * 13, IntegerType::Modifier::Signed)}, - {make_unique(8 * 14, IntegerType::Modifier::Signed)}, - {make_unique(8 * 15, IntegerType::Modifier::Signed)}, - {make_unique(8 * 16, IntegerType::Modifier::Signed)}, - {make_unique(8 * 17, IntegerType::Modifier::Signed)}, - {make_unique(8 * 18, IntegerType::Modifier::Signed)}, - {make_unique(8 * 19, IntegerType::Modifier::Signed)}, - {make_unique(8 * 20, IntegerType::Modifier::Signed)}, - {make_unique(8 * 21, IntegerType::Modifier::Signed)}, - {make_unique(8 * 22, IntegerType::Modifier::Signed)}, - {make_unique(8 * 23, IntegerType::Modifier::Signed)}, - {make_unique(8 * 24, IntegerType::Modifier::Signed)}, - {make_unique(8 * 25, IntegerType::Modifier::Signed)}, - {make_unique(8 * 26, IntegerType::Modifier::Signed)}, - {make_unique(8 * 27, IntegerType::Modifier::Signed)}, - {make_unique(8 * 28, IntegerType::Modifier::Signed)}, - {make_unique(8 * 29, IntegerType::Modifier::Signed)}, - {make_unique(8 * 30, IntegerType::Modifier::Signed)}, - {make_unique(8 * 31, IntegerType::Modifier::Signed)}, - {make_unique(8 * 32, IntegerType::Modifier::Signed)} +std::array, 32> const TypeProvider::m_intM{{ + {std::make_unique(8 * 1, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 2, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 3, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 4, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 5, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 6, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 7, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 8, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 9, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 10, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 11, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 12, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 13, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 14, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 15, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 16, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 17, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 18, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 19, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 20, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 21, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 22, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 23, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 24, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 25, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 26, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 27, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 28, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 29, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 30, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 31, IntegerType::Modifier::Signed)}, + {std::make_unique(8 * 32, IntegerType::Modifier::Signed)} }}; -array, 32> const TypeProvider::m_uintM{{ - {make_unique(8 * 1, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 2, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 3, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 4, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 5, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 6, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 7, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 8, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 9, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 10, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 11, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 12, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 13, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 14, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 15, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 16, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 17, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 18, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 19, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 20, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 21, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 22, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 23, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 24, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 25, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 26, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 27, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 28, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 29, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 30, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 31, IntegerType::Modifier::Unsigned)}, - {make_unique(8 * 32, IntegerType::Modifier::Unsigned)} +std::array, 32> const TypeProvider::m_uintM{{ + {std::make_unique(8 * 1, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 2, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 3, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 4, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 5, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 6, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 7, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 8, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 9, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 10, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 11, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 12, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 13, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 14, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 15, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 16, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 17, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 18, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 19, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 20, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 21, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 22, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 23, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 24, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 25, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 26, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 27, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 28, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 29, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 30, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 31, IntegerType::Modifier::Unsigned)}, + {std::make_unique(8 * 32, IntegerType::Modifier::Unsigned)} }}; -array, 32> const TypeProvider::m_bytesM{{ - {make_unique(1)}, - {make_unique(2)}, - {make_unique(3)}, - {make_unique(4)}, - {make_unique(5)}, - {make_unique(6)}, - {make_unique(7)}, - {make_unique(8)}, - {make_unique(9)}, - {make_unique(10)}, - {make_unique(11)}, - {make_unique(12)}, - {make_unique(13)}, - {make_unique(14)}, - {make_unique(15)}, - {make_unique(16)}, - {make_unique(17)}, - {make_unique(18)}, - {make_unique(19)}, - {make_unique(20)}, - {make_unique(21)}, - {make_unique(22)}, - {make_unique(23)}, - {make_unique(24)}, - {make_unique(25)}, - {make_unique(26)}, - {make_unique(27)}, - {make_unique(28)}, - {make_unique(29)}, - {make_unique(30)}, - {make_unique(31)}, - {make_unique(32)} +std::array, 32> const TypeProvider::m_bytesM{{ + {std::make_unique(1)}, + {std::make_unique(2)}, + {std::make_unique(3)}, + {std::make_unique(4)}, + {std::make_unique(5)}, + {std::make_unique(6)}, + {std::make_unique(7)}, + {std::make_unique(8)}, + {std::make_unique(9)}, + {std::make_unique(10)}, + {std::make_unique(11)}, + {std::make_unique(12)}, + {std::make_unique(13)}, + {std::make_unique(14)}, + {std::make_unique(15)}, + {std::make_unique(16)}, + {std::make_unique(17)}, + {std::make_unique(18)}, + {std::make_unique(19)}, + {std::make_unique(20)}, + {std::make_unique(21)}, + {std::make_unique(22)}, + {std::make_unique(23)}, + {std::make_unique(24)}, + {std::make_unique(25)}, + {std::make_unique(26)}, + {std::make_unique(27)}, + {std::make_unique(28)}, + {std::make_unique(29)}, + {std::make_unique(30)}, + {std::make_unique(31)}, + {std::make_unique(32)} }}; -array, 4> const TypeProvider::m_magics{{ - {make_unique(MagicType::Kind::Block)}, - {make_unique(MagicType::Kind::Message)}, - {make_unique(MagicType::Kind::Transaction)}, - {make_unique(MagicType::Kind::ABI)} +std::array, 4> const TypeProvider::m_magics{{ + {std::make_unique(MagicType::Kind::Block)}, + {std::make_unique(MagicType::Kind::Message)}, + {std::make_unique(MagicType::Kind::Transaction)}, + {std::make_unique(MagicType::Kind::ABI)} // MetaType is stored separately }}; @@ -160,7 +159,7 @@ inline void clearCache(Type const& type) } template -inline void clearCache(unique_ptr const& type) +inline void clearCache(std::unique_ptr const& type) { // Some lazy-initialized types might not exist yet. if (type) @@ -200,7 +199,7 @@ void TypeProvider::reset() template inline T const* TypeProvider::createAndGet(Args&& ... _args) { - instance().m_generalTypes.emplace_back(make_unique(std::forward(_args)...)); + instance().m_generalTypes.emplace_back(std::make_unique(std::forward(_args)...)); return static_cast(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 nameParts; + std::vector nameParts; boost::split(nameParts, _name, boost::is_any_of(" ")); solAssert(nameParts.size() == 1 || nameParts.size() == 2, "Cannot parse elementary type: " + _name); Token token; 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)); if (auto* ref = dynamic_cast(t)) @@ -307,35 +306,35 @@ Type const* TypeProvider::fromElementaryTypeName(string const& _name) ArrayType const* TypeProvider::bytesStorage() { if (!m_bytesStorage) - m_bytesStorage = make_unique(DataLocation::Storage, false); + m_bytesStorage = std::make_unique(DataLocation::Storage, false); return m_bytesStorage.get(); } ArrayType const* TypeProvider::bytesMemory() { if (!m_bytesMemory) - m_bytesMemory = make_unique(DataLocation::Memory, false); + m_bytesMemory = std::make_unique(DataLocation::Memory, false); return m_bytesMemory.get(); } ArrayType const* TypeProvider::bytesCalldata() { if (!m_bytesCalldata) - m_bytesCalldata = make_unique(DataLocation::CallData, false); + m_bytesCalldata = std::make_unique(DataLocation::CallData, false); return m_bytesCalldata.get(); } ArrayType const* TypeProvider::stringStorage() { if (!m_stringStorage) - m_stringStorage = make_unique(DataLocation::Storage, true); + m_stringStorage = std::make_unique(DataLocation::Storage, true); return m_stringStorage.get(); } ArrayType const* TypeProvider::stringMemory() { if (!m_stringMemory) - m_stringMemory = make_unique(DataLocation::Memory, true); + m_stringMemory = std::make_unique(DataLocation::Memory, true); return m_stringMemory.get(); } @@ -376,30 +375,30 @@ RationalNumberType const* TypeProvider::rationalNumber(Literal const& _literal) return nullptr; } -StringLiteralType const* TypeProvider::stringLiteral(string const& literal) +StringLiteralType const* TypeProvider::stringLiteral(std::string const& literal) { auto i = instance().m_stringLiteralTypes.find(literal); if (i != instance().m_stringLiteralTypes.end()) return i->second.get(); else - return instance().m_stringLiteralTypes.emplace(literal, make_unique(literal)).first->second.get(); + return instance().m_stringLiteralTypes.emplace(literal, std::make_unique(literal)).first->second.get(); } FixedPointType const* TypeProvider::fixedPoint(unsigned m, unsigned n, FixedPointType::Modifier _modifier) { 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()) return i->second.get(); return map.emplace( - make_pair(m, n), - make_unique(m, n, _modifier) + std::make_pair(m, n), + std::make_unique(m, n, _modifier) ).first->second.get(); } -TupleType const* TypeProvider::tuple(vector members) +TupleType const* TypeProvider::tuple(std::vector members) { if (members.empty()) return &m_emptyTuple; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 2b955369f..7b3e42143 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -54,7 +54,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -111,7 +110,7 @@ util::Result transformParametersToExternal(TypePointers const& _pa return transformed; } -string toStringInParentheses(TypePointers const& _types, bool _withoutDataLocation) +std::string toStringInParentheses(TypePointers const& _types, bool _withoutDataLocation) { return '(' + util::joinHumanReadable( _types | ranges::views::transform([&](auto const* _type) { return _type->toString(_withoutDataLocation); }), @@ -125,7 +124,7 @@ MemberList::Member::Member(Declaration const* _declaration, Type const* _type): Member(_declaration, _type, _declaration->name()) {} -MemberList::Member::Member(Declaration const* _declaration, Type const* _type, string _name): +MemberList::Member::Member(Declaration const* _declaration, Type const* _type, std::string _name): name(std::move(_name)), type(_type), declaration(_declaration) @@ -143,7 +142,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types) { bigint slotOffset = 0; unsigned byteOffset = 0; - map> offsets; + std::map> offsets; for (size_t i = 0; i < _types.size(); ++i) { Type const* type = _types[i]; @@ -156,7 +155,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types) byteOffset = 0; } solAssert(slotOffset < bigint(1) << 256 ,"Object too large for storage."); - offsets[i] = make_pair(u256(slotOffset), byteOffset); + offsets[i] = std::make_pair(u256(slotOffset), byteOffset); solAssert(type->storageSize() >= 1, "Invalid storage size."); if (type->storageSize() == 1 && byteOffset + type->storageBytes() <= 32) byteOffset += type->storageBytes(); @@ -173,7 +172,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types) swap(m_offsets, offsets); } -pair const* StorageOffsets::offset(size_t _index) const +std::pair const* StorageOffsets::offset(size_t _index) const { if (m_offsets.count(_index)) return &m_offsets.at(_index); @@ -186,7 +185,7 @@ void MemberList::combine(MemberList const & _other) m_memberTypes += _other.m_memberTypes; } -pair const* MemberList::memberStorageOffset(string const& _name) const +std::pair const* MemberList::memberStorageOffset(std::string const& _name) const { StorageOffsets const& offsets = storageOffsets(); @@ -219,33 +218,33 @@ StorageOffsets const& MemberList::storageOffsets() const { namespace { -string parenthesizeIdentifier(string const& _internal) +std::string parenthesizeIdentifier(std::string const& _internal) { return "(" + _internal + ")"; } template -string identifierList(Range const&& _list) +std::string identifierList(Range const&& _list) { return parenthesizeIdentifier(boost::algorithm::join(_list, ",")); } -string richIdentifier(Type const* _type) +std::string richIdentifier(Type const* _type) { return _type ? _type->richIdentifier() : ""; } -string identifierList(vector const& _list) +std::string identifierList(std::vector const& _list) { return identifierList(_list | ranges::views::transform(richIdentifier)); } -string identifierList(Type const* _type) +std::string identifierList(Type const* _type) { return parenthesizeIdentifier(richIdentifier(_type)); } -string identifierList(Type const* _type1, Type const* _type2) +std::string identifierList(Type const* _type1, Type const* _type2) { TypePointers list; list.push_back(_type1); @@ -253,16 +252,16 @@ string identifierList(Type const* _type1, Type const* _type2) return identifierList(list); } -string parenthesizeUserIdentifier(string const& _internal) +std::string parenthesizeUserIdentifier(std::string const& _internal) { return parenthesizeIdentifier(_internal); } } -string Type::escapeIdentifier(string const& _identifier) +std::string Type::escapeIdentifier(std::string const& _identifier) { - string ret = _identifier; + std::string ret = _identifier; // FIXME: should be _$$$_ boost::algorithm::replace_all(ret, "$", "$$$"); boost::algorithm::replace_all(ret, ",", "_$_"); @@ -271,12 +270,12 @@ string Type::escapeIdentifier(string const& _identifier) return ret; } -string Type::identifier() const +std::string Type::identifier() const { - string ret = escapeIdentifier(richIdentifier()); + std::string ret = escapeIdentifier(richIdentifier()); solAssert(ret.find_first_of("0123456789") != 0, "Identifier cannot start with a number."); solAssert( - ret.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ_$") == string::npos, + ret.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ_$") == std::string::npos, "Identifier contains invalid characters." ); return ret; @@ -306,7 +305,7 @@ MemberList const& Type::members(ASTNode const* _currentScope) const MemberList::MemberMap members = nativeMembers(_currentScope); if (_currentScope) members += attachedFunctions(*this, *_currentScope); - m_members[_currentScope] = make_unique(std::move(members)); + m_members[_currentScope] = std::make_unique(std::move(members)); } return *m_members[_currentScope]; } @@ -341,9 +340,9 @@ Type const* Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool) c namespace { -vector usingForDirectivesForType(Type const& _type, ASTNode const& _scope) +std::vector usingForDirectivesForType(Type const& _type, ASTNode const& _scope) { - vector usingForDirectives; + std::vector usingForDirectives; SourceUnit const* sourceUnit = dynamic_cast(&_scope); if (auto const* contract = dynamic_cast(&_scope)) { @@ -378,12 +377,12 @@ vector usingForDirectivesForType(Type const& _type, AS _directive->typeName()->annotation().type, true ); - }) | ranges::to>; + }) | ranges::to>; } } -set Type::operatorDefinitions( +std::set Type::operatorDefinitions( Token _token, ASTNode const& _scope, bool _unary @@ -392,7 +391,7 @@ set Type::operatorDefinitions( if (!typeDefinition()) return {}; - set matchingDefinitions; + std::set matchingDefinitions; for (UsingForDirective const* directive: usingForDirectivesForType(*this, _scope)) for (auto const& [identifierPath, operator_]: directive->functionsAndOperators()) { @@ -419,8 +418,8 @@ MemberList::MemberMap Type::attachedFunctions(Type const& _type, ASTNode const& { MemberList::MemberMap members; - set> seenFunctions; - auto addFunction = [&](FunctionDefinition const& _function, optional _name = {}) + std::set> seenFunctions; + auto addFunction = [&](FunctionDefinition const& _function, std::optional _name = {}) { if (!_name) _name = _function.name(); @@ -432,7 +431,7 @@ MemberList::MemberMap Type::attachedFunctions(Type const& _type, ASTNode const& solAssert(withBoundFirstArgument, ""); if (_type.isImplicitlyConvertibleTo(*withBoundFirstArgument->selfType())) - if (seenFunctions.insert(make_pair(*_name, &_function)).second) + if (seenFunctions.insert(std::make_pair(*_name, &_function)).second) members.emplace_back(&_function, withBoundFirstArgument, *_name); }; @@ -474,7 +473,7 @@ AddressType::AddressType(StateMutability _stateMutability): solAssert(m_stateMutability == StateMutability::Payable || m_stateMutability == StateMutability::NonPayable, ""); } -string AddressType::richIdentifier() const +std::string AddressType::richIdentifier() const { if (m_stateMutability == StateMutability::Payable) return "t_address_payable"; @@ -508,7 +507,7 @@ BoolResult AddressType::isExplicitlyConvertibleTo(Type const& _convertTo) const return false; } -string AddressType::toString(bool) const +std::string AddressType::toString(bool) const { if (m_stateMutability == StateMutability::Payable) return "address payable"; @@ -516,7 +515,7 @@ string AddressType::toString(bool) const return "address"; } -string AddressType::canonicalName() const +std::string AddressType::canonicalName() const { return "address"; } @@ -596,9 +595,9 @@ IntegerType::IntegerType(unsigned _bits, IntegerType::Modifier _modifier): ); } -string IntegerType::richIdentifier() const +std::string IntegerType::richIdentifier() const { - return "t_" + string(isSigned() ? "" : "u") + "int" + to_string(numBits()); + return "t_" + std::string(isSigned() ? "" : "u") + "int" + std::to_string(numBits()); } BoolResult IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const @@ -666,9 +665,9 @@ bool IntegerType::operator==(Type const& _other) const return other.m_bits == m_bits && other.m_modifier == m_modifier; } -string IntegerType::toString(bool) const +std::string IntegerType::toString(bool) const { - string prefix = isSigned() ? "int" : "uint"; + std::string prefix = isSigned() ? "int" : "uint"; return prefix + util::toString(m_bits); } @@ -763,9 +762,9 @@ FixedPointType::FixedPointType(unsigned _totalBits, unsigned _fractionalDigits, ); } -string FixedPointType::richIdentifier() const +std::string FixedPointType::richIdentifier() const { - return "t_" + string(isSigned() ? "" : "u") + "fixed" + to_string(m_totalBits) + "x" + to_string(m_fractionalDigits); + return "t_" + std::string(isSigned() ? "" : "u") + "fixed" + std::to_string(m_totalBits) + "x" + std::to_string(m_fractionalDigits); } BoolResult FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const @@ -815,9 +814,9 @@ bool FixedPointType::operator==(Type const& _other) const return other.m_totalBits == m_totalBits && other.m_fractionalDigits == m_fractionalDigits && other.m_modifier == m_modifier; } -string FixedPointType::toString(bool) const +std::string FixedPointType::toString(bool) const { - string prefix = isSigned() ? "fixed" : "ufixed"; + std::string prefix = isSigned() ? "fixed" : "ufixed"; return prefix + util::toString(m_totalBits) + "x" + util::toString(m_fractionalDigits); } @@ -858,7 +857,7 @@ IntegerType const* FixedPointType::asIntegerType() const return TypeProvider::integer(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned); } -tuple RationalNumberType::parseRational(string const& _value) +std::tuple RationalNumberType::parseRational(std::string const& _value) { rational value; try @@ -871,7 +870,7 @@ tuple RationalNumberType::parseRational(string const& _value) !all_of(radixPoint + 1, _value.end(), util::isDigit) || !all_of(_value.begin(), radixPoint, util::isDigit) ) - return make_tuple(false, rational(0)); + return std::make_tuple(false, rational(0)); // Only decimal notation allowed here, leading zeros would switch to octal. auto fractionalBegin = find_if_not( @@ -883,25 +882,25 @@ tuple RationalNumberType::parseRational(string const& _value) rational numerator; rational denominator(1); - denominator = bigint(string(fractionalBegin, _value.end())); + denominator = bigint(std::string(fractionalBegin, _value.end())); denominator /= boost::multiprecision::pow( bigint(10), static_cast(distance(radixPoint + 1, _value.end())) ); - numerator = bigint(string(_value.begin(), radixPoint)); + numerator = bigint(std::string(_value.begin(), radixPoint)); value = numerator + denominator; } else value = bigint(_value); - return make_tuple(true, value); + return std::make_tuple(true, value); } catch (...) { - return make_tuple(false, rational(0)); + return std::make_tuple(false, rational(0)); } } -tuple RationalNumberType::isValidLiteral(Literal const& _literal) +std::tuple RationalNumberType::isValidLiteral(Literal const& _literal) { rational value; try @@ -920,27 +919,27 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal else if (expPoint != valueString.end()) { // Parse mantissa and exponent. Checks numeric limit. - tuple mantissa = parseRational(string(valueString.begin(), expPoint)); + std::tuple mantissa = parseRational(std::string(valueString.begin(), expPoint)); - if (!get<0>(mantissa)) - return make_tuple(false, rational(0)); - value = get<1>(mantissa); + if (!std::get<0>(mantissa)) + return std::make_tuple(false, rational(0)); + value = std::get<1>(mantissa); // 0E... is always zero. if (value == 0) - return make_tuple(true, rational(0)); + return std::make_tuple(true, rational(0)); - bigint exp = bigint(string(expPoint + 1, valueString.end())); + bigint exp = bigint(std::string(expPoint + 1, valueString.end())); - if (exp > numeric_limits::max() || exp < numeric_limits::min()) - return make_tuple(false, rational(0)); + if (exp > std::numeric_limits::max() || exp < std::numeric_limits::min()) + return std::make_tuple(false, rational(0)); uint32_t expAbs = bigint(abs(exp)).convert_to(); if (exp < 0) { if (!fitsPrecisionBase10(abs(value.denominator()), expAbs)) - return make_tuple(false, rational(0)); + return std::make_tuple(false, rational(0)); value /= boost::multiprecision::pow( bigint(10), expAbs @@ -949,7 +948,7 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal else if (exp > 0) { if (!fitsPrecisionBase10(abs(value.numerator()), expAbs)) - return make_tuple(false, rational(0)); + return std::make_tuple(false, rational(0)); value *= boost::multiprecision::pow( bigint(10), expAbs @@ -959,15 +958,15 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal else { // parse as rational number - tuple tmp = parseRational(valueString); - if (!get<0>(tmp)) + std::tuple tmp = parseRational(valueString); + if (!std::get<0>(tmp)) return tmp; - value = get<1>(tmp); + value = std::get<1>(tmp); } } catch (...) { - return make_tuple(false, rational(0)); + return std::make_tuple(false, rational(0)); } switch (_literal.subDenomination()) { @@ -999,7 +998,7 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal } - return make_tuple(true, value); + return std::make_tuple(true, value); } BoolResult RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const @@ -1062,7 +1061,7 @@ BoolResult RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo) TypeResult RationalNumberType::unaryOperatorResult(Token _operator) const { - if (optional value = ConstantEvaluator::evaluateUnaryOperator(_operator, m_value)) + if (std::optional value = ConstantEvaluator::evaluateUnaryOperator(_operator, m_value)) return TypeResult{TypeProvider::rationalNumber(*value)}; else return nullptr; @@ -1120,10 +1119,10 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, Type const* return nullptr; return thisMobile->binaryOperatorResult(_operator, otherMobile); } - else if (optional value = ConstantEvaluator::evaluateBinaryOperator(_operator, m_value, other.m_value)) + else if (std::optional value = ConstantEvaluator::evaluateBinaryOperator(_operator, m_value, other.m_value)) { // verify that numerator and denominator fit into 4096 bit after every operation - if (value->numerator() != 0 && max(boost::multiprecision::msb(abs(value->numerator())), boost::multiprecision::msb(abs(value->denominator()))) > 4096) + if (value->numerator() != 0 && std::max(boost::multiprecision::msb(abs(value->numerator())), boost::multiprecision::msb(abs(value->denominator()))) > 4096) return TypeResult::err("Precision of rational constants is limited to 4096 bits."); return TypeResult{TypeProvider::rationalNumber(*value)}; @@ -1132,7 +1131,7 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, Type const* return nullptr; } -string RationalNumberType::richIdentifier() const +std::string RationalNumberType::richIdentifier() const { // rational seemingly will put the sign always on the numerator, // but let just make it deterministic here. @@ -1152,24 +1151,24 @@ bool RationalNumberType::operator==(Type const& _other) const return m_value == other.m_value; } -string RationalNumberType::bigintToReadableString(bigint const& _num) +std::string RationalNumberType::bigintToReadableString(bigint const& _num) { - string str = _num.str(); + std::string str = _num.str(); if (str.size() > 32) { size_t omitted = str.size() - 8; - str = str.substr(0, 4) + "...(" + to_string(omitted) + " digits omitted)..." + str.substr(str.size() - 4, 4); + str = str.substr(0, 4) + "...(" + std::to_string(omitted) + " digits omitted)..." + str.substr(str.size() - 4, 4); } return str; } -string RationalNumberType::toString(bool) const +std::string RationalNumberType::toString(bool) const { if (!isFractional()) return "int_const " + bigintToReadableString(m_value.numerator()); - string numerator = bigintToReadableString(m_value.numerator()); - string denominator = bigintToReadableString(m_value.denominator()); + std::string numerator = bigintToReadableString(m_value.numerator()); + std::string denominator = bigintToReadableString(m_value.denominator()); return "rational_const " + numerator + " / " + denominator; } @@ -1221,7 +1220,7 @@ IntegerType const* RationalNumberType::integerType() const return nullptr; else return TypeProvider::integer( - max(numberEncodingSize(value), 1u) * 8, + std::max(numberEncodingSize(value), 1u) * 8, negative ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned ); } @@ -1255,7 +1254,7 @@ FixedPointType const* RationalNumberType::fixedPointType() const if (v > u256(-1)) return nullptr; - unsigned totalBits = max(numberEncodingSize(v), 1u) * 8; + unsigned totalBits = std::max(numberEncodingSize(v), 1u) * 8; solAssert(totalBits <= 256, ""); return TypeProvider::fixedPoint( @@ -1269,7 +1268,7 @@ StringLiteralType::StringLiteralType(Literal const& _literal): { } -StringLiteralType::StringLiteralType(string _value): +StringLiteralType::StringLiteralType(std::string _value): m_value{std::move(_value)} { } @@ -1300,9 +1299,9 @@ BoolResult StringLiteralType::isImplicitlyConvertibleTo(Type const& _convertTo) return false; } -string StringLiteralType::richIdentifier() const +std::string StringLiteralType::richIdentifier() const { - // Since we have to return a valid identifier and the string itself may contain + // Since we have to return a valid identifier and the std::string itself may contain // anything, we hash it. return "t_stringliteral_" + util::toHex(util::keccak256(m_value).asBytes()); } @@ -1316,7 +1315,7 @@ bool StringLiteralType::operator==(Type const& _other) const std::string StringLiteralType::toString(bool) const { - auto isPrintableASCII = [](string const& s) + auto isPrintableASCII = [](std::string const& s) { for (auto c: s) { @@ -1405,9 +1404,9 @@ MemberList::MemberMap FixedBytesType::nativeMembers(ASTNode const*) const return MemberList::MemberMap{MemberList::Member{"length", TypeProvider::uint(8)}}; } -string FixedBytesType::richIdentifier() const +std::string FixedBytesType::richIdentifier() const { - return "t_bytes" + to_string(m_bytes); + return "t_bytes" + std::to_string(m_bytes); } bool FixedBytesType::operator==(Type const& _other) const @@ -1511,10 +1510,10 @@ TypeResult ContractType::unaryOperatorResult(Token _operator) const return nullptr; } -vector CompositeType::fullDecomposition() const +std::vector CompositeType::fullDecomposition() const { - vector res = {this}; - unordered_set seen = {richIdentifier()}; + std::vector res = {this}; + std::unordered_set seen = {richIdentifier()}; for (size_t k = 0; k < res.size(); ++k) if (auto composite = dynamic_cast(res[k])) for (Type const* next: composite->decomposition()) @@ -1562,12 +1561,12 @@ Type const* ReferenceType::copyForLocationIfReference(Type const* _type) const return TypeProvider::withLocationIfReference(m_location, _type); } -string ReferenceType::stringForReferencePart() const +std::string ReferenceType::stringForReferencePart() const { switch (m_location) { case DataLocation::Storage: - return string("storage ") + (isPointer() ? "pointer" : "ref"); + return std::string("storage ") + (isPointer() ? "pointer" : "ref"); case DataLocation::CallData: return "calldata"; case DataLocation::Memory: @@ -1577,9 +1576,9 @@ string ReferenceType::stringForReferencePart() const return ""; } -string ReferenceType::identifierLocationSuffix() const +std::string ReferenceType::identifierLocationSuffix() const { - string id; + std::string id; switch (location()) { case DataLocation::Storage: @@ -1656,7 +1655,7 @@ BoolResult ArrayType::isExplicitlyConvertibleTo(Type const& _convertTo) const { if (isImplicitlyConvertibleTo(_convertTo)) return true; - // allow conversion bytes <-> string and bytes -> bytesNN + // allow conversion bytes <-> std::string and bytes -> bytesNN if (_convertTo.category() != category()) return isByteArray() && _convertTo.category() == Type::Category::FixedBytes; auto& convertTo = dynamic_cast(_convertTo); @@ -1667,9 +1666,9 @@ BoolResult ArrayType::isExplicitlyConvertibleTo(Type const& _convertTo) const return true; } -string ArrayType::richIdentifier() const +std::string ArrayType::richIdentifier() const { - string id; + std::string id; if (isString()) id = "t_string"; else if (isByteArrayOrString()) @@ -1735,13 +1734,13 @@ BoolResult ArrayType::validForLocation(DataLocation _loc) const size *= type->memoryHeadSize(); else size *= type->memoryDataSize(); - if (size >= numeric_limits::max()) + if (size >= std::numeric_limits::max()) return BoolResult::err("Type too large for memory."); break; } case DataLocation::CallData: { - if (unlimitedStaticCalldataSize(true) >= numeric_limits::max()) + if (unlimitedStaticCalldataSize(true) >= std::numeric_limits::max()) return BoolResult::err("Type too large for calldata."); break; } @@ -1766,7 +1765,7 @@ unsigned ArrayType::calldataEncodedSize(bool _padded) const { solAssert(!isDynamicallyEncoded(), ""); bigint size = unlimitedStaticCalldataSize(_padded); - solAssert(size <= numeric_limits::max(), "Array size does not fit unsigned."); + solAssert(size <= std::numeric_limits::max(), "Array size does not fit unsigned."); return unsigned(size); } @@ -1778,7 +1777,7 @@ unsigned ArrayType::calldataEncodedTailSize() const // length must still be present. return 32; bigint size = unlimitedStaticCalldataSize(false); - solAssert(size <= numeric_limits::max(), "Array size does not fit unsigned."); + solAssert(size <= std::numeric_limits::max(), "Array size does not fit unsigned."); return unsigned(size); } @@ -1812,10 +1811,10 @@ u256 ArrayType::storageSize() const else size = bigint(length()) * baseType()->storageSize(); solAssert(size < bigint(1) << 256, "Array too large for storage."); - return max(1, u256(size)); + return std::max(1, u256(size)); } -vector> ArrayType::makeStackItems() const +std::vector> ArrayType::makeStackItems() const { switch (m_location) { @@ -1833,9 +1832,9 @@ vector> ArrayType::makeStackItems() const solAssert(false, ""); } -string ArrayType::toString(bool _withoutDataLocation) const +std::string ArrayType::toString(bool _withoutDataLocation) const { - string ret; + std::string ret; if (isString()) ret = "string"; else if (isByteArrayOrString()) @@ -1852,9 +1851,9 @@ string ArrayType::toString(bool _withoutDataLocation) const return ret; } -string ArrayType::humanReadableName() const +std::string ArrayType::humanReadableName() const { - string ret; + std::string ret; if (isString()) ret = "string"; else if (isByteArrayOrString()) @@ -1870,9 +1869,9 @@ string ArrayType::humanReadableName() const return ret; } -string ArrayType::canonicalName() const +std::string ArrayType::canonicalName() const { - string ret; + std::string ret; if (isString()) ret = "string"; else if (isByteArrayOrString()) @@ -1887,7 +1886,7 @@ string ArrayType::canonicalName() const return ret; } -string ArrayType::signatureInExternalFunction(bool _structsByName) const +std::string ArrayType::signatureInExternalFunction(bool _structsByName) const { if (isByteArrayOrString()) return canonicalName(); @@ -1914,21 +1913,21 @@ MemberList::MemberMap ArrayType::nativeMembers(ASTNode const*) const members.emplace_back("push", TypeProvider::function( TypePointers{thisAsPointer}, TypePointers{baseType()}, - strings{string()}, - strings{string()}, + strings{std::string()}, + strings{std::string()}, FunctionType::Kind::ArrayPush )->withBoundFirstArgument()); members.emplace_back("push", TypeProvider::function( TypePointers{thisAsPointer, baseType()}, TypePointers{}, - strings{string(),string()}, + strings{std::string(),std::string()}, strings{}, FunctionType::Kind::ArrayPush )->withBoundFirstArgument()); members.emplace_back("pop", TypeProvider::function( TypePointers{thisAsPointer}, TypePointers{}, - strings{string()}, + strings{std::string()}, strings{}, FunctionType::Kind::ArrayPop )->withBoundFirstArgument()); @@ -2006,13 +2005,13 @@ u256 ArrayType::memoryDataSize() const solAssert(m_location == DataLocation::Memory, ""); solAssert(!isByteArrayOrString(), ""); bigint size = bigint(m_length) * m_baseType->memoryHeadSize(); - solAssert(size <= numeric_limits::max(), "Array size does not fit u256."); + solAssert(size <= std::numeric_limits::max(), "Array size does not fit u256."); return u256(size); } std::unique_ptr ArrayType::copyForLocation(DataLocation _location, bool _isPointer) const { - auto copy = make_unique(_location); + auto copy = std::make_unique(_location); if (_location == DataLocation::Storage) copy->m_isPointer = _isPointer; copy->m_arrayKind = m_arrayKind; @@ -2040,7 +2039,7 @@ BoolResult ArraySliceType::isExplicitlyConvertibleTo(Type const& _convertTo) con m_arrayType.isExplicitlyConvertibleTo(_convertTo); } -string ArraySliceType::richIdentifier() const +std::string ArraySliceType::richIdentifier() const { return m_arrayType.richIdentifier() + "_slice"; } @@ -2052,12 +2051,12 @@ bool ArraySliceType::operator==(Type const& _other) const return false; } -string ArraySliceType::toString(bool _withoutDataLocation) const +std::string ArraySliceType::toString(bool _withoutDataLocation) const { return m_arrayType.toString(_withoutDataLocation) + " slice"; } -string ArraySliceType::humanReadableName() const +std::string ArraySliceType::humanReadableName() const { return m_arrayType.humanReadableName() + " slice"; } @@ -2080,9 +2079,9 @@ std::vector> ArraySliceType::makeStackItems return {{"offset", TypeProvider::uint256()}, {"length", TypeProvider::uint256()}}; } -string ContractType::richIdentifier() const +std::string ContractType::richIdentifier() const { - return (m_super ? "t_super" : "t_contract") + parenthesizeUserIdentifier(m_contract.name()) + to_string(m_contract.id()); + return (m_super ? "t_super" : "t_contract") + parenthesizeUserIdentifier(m_contract.name()) + std::to_string(m_contract.id()); } bool ContractType::operator==(Type const& _other) const @@ -2093,15 +2092,15 @@ bool ContractType::operator==(Type const& _other) const return other.m_contract == m_contract && other.m_super == m_super; } -string ContractType::toString(bool) const +std::string ContractType::toString(bool) const { return - string(m_contract.isLibrary() ? "library " : "contract ") + - string(m_super ? "super " : "") + + std::string(m_contract.isLibrary() ? "library " : "contract ") + + std::string(m_super ? "super " : "") + m_contract.name(); } -string ContractType::canonicalName() const +std::string ContractType::canonicalName() const { return *m_contract.annotation().canonicalName; } @@ -2127,9 +2126,9 @@ FunctionType const* ContractType::newExpressionType() const return m_constructorType; } -vector> ContractType::stateVariables() const +std::vector> ContractType::stateVariables() const { - vector variables; + std::vector variables; for (ContractDefinition const* contract: m_contract.annotation().linearizedBaseContracts | ranges::views::reverse) for (VariableDeclaration const* variable: contract->stateVariables()) if (!(variable->isConstant() || variable->immutable())) @@ -2140,16 +2139,16 @@ vector> ContractType::stateVar StorageOffsets offsets; offsets.computeOffsets(types); - vector> variablesAndOffsets; + std::vector> variablesAndOffsets; for (size_t index = 0; index < variables.size(); ++index) if (auto const* offset = offsets.offset(index)) variablesAndOffsets.emplace_back(variables[index], offset->first, offset->second); return variablesAndOffsets; } -vector ContractType::immutableVariables() const +std::vector ContractType::immutableVariables() const { - vector variables; + std::vector variables; for (ContractDefinition const* contract: m_contract.annotation().linearizedBaseContracts | ranges::views::reverse) for (VariableDeclaration const* variable: contract->stateVariables()) if (variable->immutable()) @@ -2157,12 +2156,12 @@ vector ContractType::immutableVariables() const return variables; } -vector> ContractType::makeStackItems() const +std::vector> ContractType::makeStackItems() const { if (m_super) return {}; else - return {make_tuple("address", isPayable() ? TypeProvider::payableAddress() : TypeProvider::address())}; + return {std::make_tuple("address", isPayable() ? TypeProvider::payableAddress() : TypeProvider::address())}; } void StructType::clearCache() const @@ -2194,9 +2193,9 @@ BoolResult StructType::isImplicitlyConvertibleTo(Type const& _convertTo) const return this->m_struct == convertTo.m_struct; } -string StructType::richIdentifier() const +std::string StructType::richIdentifier() const { - return "t_struct" + parenthesizeUserIdentifier(m_struct.name()) + to_string(m_struct.id()) + identifierLocationSuffix(); + return "t_struct" + parenthesizeUserIdentifier(m_struct.name()) + std::to_string(m_struct.id()) + identifierLocationSuffix(); } bool StructType::operator==(Type const& _other) const @@ -2284,7 +2283,7 @@ bigint StructType::storageSizeUpperBound() const u256 StructType::storageSize() const { - return max(1, members(nullptr).storageSize()); + return std::max(1, members(nullptr).storageSize()); } bool StructType::containsNestedMapping() const @@ -2323,9 +2322,9 @@ bool StructType::containsNestedMapping() const return m_struct.annotation().containsNestedMapping.value(); } -string StructType::toString(bool _withoutDataLocation) const +std::string StructType::toString(bool _withoutDataLocation) const { - string ret = "struct " + *m_struct.annotation().canonicalName; + std::string ret = "struct " + *m_struct.annotation().canonicalName; if (!_withoutDataLocation) ret += " " + stringForReferencePart(); return ret; @@ -2482,20 +2481,20 @@ bool StructType::recursive() const std::unique_ptr StructType::copyForLocation(DataLocation _location, bool _isPointer) const { - auto copy = make_unique(m_struct, _location); + auto copy = std::make_unique(m_struct, _location); if (_location == DataLocation::Storage) copy->m_isPointer = _isPointer; return copy; } -string StructType::signatureInExternalFunction(bool _structsByName) const +std::string StructType::signatureInExternalFunction(bool _structsByName) const { if (_structsByName) return canonicalName(); else { TypePointers memberTypes = memoryMemberTypes(); - auto memberTypeStrings = memberTypes | ranges::views::transform([&](Type const* _t) -> string + auto memberTypeStrings = memberTypes | ranges::views::transform([&](Type const* _t) -> std::string { solAssert(_t, "Parameter should have external type."); auto t = _t->interfaceType(_structsByName); @@ -2506,7 +2505,7 @@ string StructType::signatureInExternalFunction(bool _structsByName) const } } -string StructType::canonicalName() const +std::string StructType::canonicalName() const { return *m_struct.annotation().canonicalName; } @@ -2530,14 +2529,14 @@ FunctionTypePointer StructType::constructorType() const ); } -pair const& StructType::storageOffsetsOfMember(string const& _name) const +std::pair const& StructType::storageOffsetsOfMember(std::string const& _name) const { auto const* offsets = members(nullptr).memberStorageOffset(_name); solAssert(offsets, "Storage offset of non-existing member requested."); return *offsets; } -u256 StructType::memoryOffsetOfMember(string const& _name) const +u256 StructType::memoryOffsetOfMember(std::string const& _name) const { u256 offset; for (auto const& member: members(nullptr)) @@ -2559,7 +2558,7 @@ TypePointers StructType::memoryMemberTypes() const return types; } -vector> StructType::makeStackItems() const +std::vector> StructType::makeStackItems() const { switch (m_location) { @@ -2573,9 +2572,9 @@ vector> StructType::makeStackItems() const solAssert(false, ""); } -vector StructType::decomposition() const +std::vector StructType::decomposition() const { - vector res; + std::vector res; for (MemberList::Member const& member: members(nullptr)) res.push_back(member.type); return res; @@ -2597,9 +2596,9 @@ TypeResult EnumType::unaryOperatorResult(Token _operator) const return _operator == Token::Delete ? TypeProvider::emptyTuple() : nullptr; } -string EnumType::richIdentifier() const +std::string EnumType::richIdentifier() const { - return "t_enum" + parenthesizeUserIdentifier(m_enum.name()) + to_string(m_enum.id()); + return "t_enum" + parenthesizeUserIdentifier(m_enum.name()) + std::to_string(m_enum.id()); } bool EnumType::operator==(Type const& _other) const @@ -2616,12 +2615,12 @@ unsigned EnumType::storageBytes() const return 1; } -string EnumType::toString(bool) const +std::string EnumType::toString(bool) const { - return string("enum ") + *m_enum.annotation().canonicalName; + return std::string("enum ") + *m_enum.annotation().canonicalName; } -string EnumType::canonicalName() const +std::string EnumType::canonicalName() const { return *m_enum.annotation().canonicalName; } @@ -2665,9 +2664,9 @@ Declaration const* UserDefinedValueType::typeDefinition() const return &m_definition; } -string UserDefinedValueType::richIdentifier() const +std::string UserDefinedValueType::richIdentifier() const { - return "t_userDefinedValueType" + parenthesizeIdentifier(m_definition.name()) + to_string(m_definition.id()); + return "t_userDefinedValueType" + parenthesizeIdentifier(m_definition.name()) + std::to_string(m_definition.id()); } bool UserDefinedValueType::operator==(Type const& _other) const @@ -2678,17 +2677,17 @@ bool UserDefinedValueType::operator==(Type const& _other) const return other.definition() == definition(); } -string UserDefinedValueType::toString(bool /* _withoutDataLocation */) const +std::string UserDefinedValueType::toString(bool /* _withoutDataLocation */) const { return *definition().annotation().canonicalName; } -string UserDefinedValueType::canonicalName() const +std::string UserDefinedValueType::canonicalName() const { return *definition().annotation().canonicalName; } -vector> UserDefinedValueType::makeStackItems() const +std::vector> UserDefinedValueType::makeStackItems() const { return underlyingType().stackItems(); } @@ -2713,7 +2712,7 @@ BoolResult TupleType::isImplicitlyConvertibleTo(Type const& _other) const return false; } -string TupleType::richIdentifier() const +std::string TupleType::richIdentifier() const { return "t_tuple" + identifierList(components()); } @@ -2726,22 +2725,22 @@ bool TupleType::operator==(Type const& _other) const return false; } -string TupleType::toString(bool _withoutDataLocation) const +std::string TupleType::toString(bool _withoutDataLocation) const { if (components().empty()) return "tuple()"; - string str = "tuple("; + std::string str = "tuple("; for (auto const& t: components()) str += (t ? t->toString(_withoutDataLocation) : "") + ","; str.pop_back(); return str + ")"; } -string TupleType::humanReadableName() const +std::string TupleType::humanReadableName() const { if (components().empty()) return "tuple()"; - string str = "tuple("; + std::string str = "tuple("; for (auto const& t: components()) str += (t ? t->humanReadableName() : "") + ","; str.pop_back(); @@ -2753,9 +2752,9 @@ u256 TupleType::storageSize() const solAssert(false, "Storage size of non-storable tuple type requested."); } -vector> TupleType::makeStackItems() const +std::vector> TupleType::makeStackItems() const { - vector> slots; + std::vector> slots; unsigned i = 1; for (auto const& t: components()) { @@ -2990,11 +2989,11 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c ); } -vector FunctionType::parameterNames() const +std::vector FunctionType::parameterNames() const { if (!hasBoundFirstArgument()) return m_parameterNames; - return vector(m_parameterNames.cbegin() + 1, m_parameterNames.cend()); + return std::vector(m_parameterNames.cbegin() + 1, m_parameterNames.cend()); } TypePointers FunctionType::returnParameterTypesWithoutDynamicTypes() const @@ -3031,9 +3030,9 @@ TypePointers const& FunctionType::parameterTypesIncludingSelf() const return m_parameterTypes; } -string FunctionType::richIdentifier() const +std::string FunctionType::richIdentifier() const { - string id = "t_function_"; + std::string id = "t_function_"; switch (m_kind) { case Kind::Declaration: id += "declaration"; break; @@ -3178,13 +3177,13 @@ TypeResult FunctionType::binaryOperatorResult(Token _operator, Type const* _othe return nullptr; } -string FunctionType::canonicalName() const +std::string FunctionType::canonicalName() const { solAssert(m_kind == Kind::External, ""); return "function"; } -string FunctionType::humanReadableName() const +std::string FunctionType::humanReadableName() const { switch (m_kind) { @@ -3197,9 +3196,9 @@ string FunctionType::humanReadableName() const } } -string FunctionType::toString(bool _withoutDataLocation) const +std::string FunctionType::toString(bool _withoutDataLocation) const { - string name = "function "; + std::string name = "function "; if (m_kind == Kind::Declaration) { auto const* functionDefinition = dynamic_cast(m_declaration); @@ -3263,9 +3262,9 @@ bool FunctionType::nameable() const !saltSet(); } -vector> FunctionType::makeStackItems() const +std::vector> FunctionType::makeStackItems() const { - vector> slots; + std::vector> slots; Kind kind = m_kind; if (m_kind == Kind::SetGas || m_kind == Kind::SetValue) { @@ -3278,8 +3277,8 @@ vector> FunctionType::makeStackItems() const case Kind::External: case Kind::DelegateCall: slots = { - make_tuple("address", TypeProvider::address()), - make_tuple("functionSelector", TypeProvider::uint(32)) + std::make_tuple("address", TypeProvider::address()), + std::make_tuple("functionSelector", TypeProvider::uint(32)) }; break; case Kind::BareCall: @@ -3288,10 +3287,10 @@ vector> FunctionType::makeStackItems() const case Kind::BareStaticCall: case Kind::Transfer: case Kind::Send: - slots = {make_tuple("address", TypeProvider::address())}; + slots = {std::make_tuple("address", TypeProvider::address())}; break; case Kind::Internal: - slots = {make_tuple("functionIdentifier", TypeProvider::uint256())}; + slots = {std::make_tuple("functionIdentifier", TypeProvider::uint256())}; break; case Kind::ArrayPush: case Kind::ArrayPop: @@ -3597,7 +3596,7 @@ bool FunctionType::isBareCall() const } } -string FunctionType::externalSignature() const +std::string FunctionType::externalSignature() const { solAssert(m_declaration != nullptr, "External signature of function needs declaration"); solAssert(!m_declaration->name().empty(), "Fallback function has no signature."); @@ -3624,9 +3623,9 @@ string FunctionType::externalSignature() const solAssert(extParams.message().empty(), extParams.message()); - auto typeStrings = extParams.get() | ranges::views::transform([&](Type const* _t) -> string + auto typeStrings = extParams.get() | ranges::views::transform([&](Type const* _t) -> std::string { - string typeName = _t->signatureInExternalFunction(inLibrary); + std::string typeName = _t->signatureInExternalFunction(inLibrary); if (inLibrary && _t->dataStoredIn(DataLocation::Storage)) typeName += " storage"; @@ -3640,7 +3639,7 @@ u256 FunctionType::externalIdentifier() const return util::selectorFromSignatureU32(externalSignature()); } -string FunctionType::externalIdentifierHex() const +std::string FunctionType::externalIdentifierHex() const { return util::selectorFromSignatureH32(externalSignature()).hex(); } @@ -3672,7 +3671,7 @@ TypePointers FunctionType::parseElementaryTypeVector(strings const& _types) { TypePointers pointers; pointers.reserve(_types.size()); - for (string const& type: _types) + for (std::string const& type: _types) pointers.push_back(TypeProvider::fromElementaryTypeName(type)); return pointers; } @@ -3797,7 +3796,7 @@ Type const* MappingType::encodingType() const return TypeProvider::integer(256, IntegerType::Modifier::Unsigned); } -string MappingType::richIdentifier() const +std::string MappingType::richIdentifier() const { return "t_mapping" + identifierList(m_keyType, m_valueType); } @@ -3810,12 +3809,12 @@ bool MappingType::operator==(Type const& _other) const return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType; } -string MappingType::toString(bool _withoutDataLocation) const +std::string MappingType::toString(bool _withoutDataLocation) const { return "mapping(" + keyType()->toString(_withoutDataLocation) + " => " + valueType()->toString(_withoutDataLocation) + ")"; } -string MappingType::canonicalName() const +std::string MappingType::canonicalName() const { return "mapping(" + keyType()->canonicalName() + " => " + valueType()->canonicalName() + ")"; } @@ -3848,7 +3847,7 @@ std::vector> MappingType::makeStackItems() return {std::make_tuple("slot", TypeProvider::uint256())}; } -string TypeType::richIdentifier() const +std::string TypeType::richIdentifier() const { return "t_type" + identifierList(actualType()); } @@ -3866,13 +3865,13 @@ u256 TypeType::storageSize() const solAssert(false, "Storage size of non-storable type type requested."); } -vector> TypeType::makeStackItems() const +std::vector> TypeType::makeStackItems() const { if (auto contractType = dynamic_cast(m_actualType)) if (contractType->contractDefinition().isLibrary()) { solAssert(!contractType->isSuper(), ""); - return {make_tuple("address", TypeProvider::address())}; + return {std::make_tuple("address", TypeProvider::address())}; } return {}; @@ -3959,8 +3958,8 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons TypeProvider::function( TypePointers{&userDefined.underlyingType()}, TypePointers{&userDefined}, - strings{string{}}, - strings{string{}}, + strings{std::string{}}, + strings{std::string{}}, FunctionType::Kind::Wrap, StateMutability::Pure ) @@ -3970,8 +3969,8 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons TypeProvider::function( TypePointers{&userDefined}, TypePointers{&userDefined.underlyingType()}, - strings{string{}}, - strings{string{}}, + strings{std::string{}}, + strings{std::string{}}, FunctionType::Kind::Unwrap, StateMutability::Pure ) @@ -3985,7 +3984,7 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons TypePointers{}, TypePointers{arrayType->isString() ? TypeProvider::stringMemory() : TypeProvider::bytesMemory()}, strings{}, - strings{string{}}, + strings{std::string{}}, arrayType->isString() ? FunctionType::Kind::StringConcat : FunctionType::Kind::BytesConcat, StateMutability::Pure, nullptr, @@ -4017,7 +4016,7 @@ u256 ModifierType::storageSize() const solAssert(false, "Storage size of non-storable type type requested."); } -string ModifierType::richIdentifier() const +std::string ModifierType::richIdentifier() const { return "t_modifier" + identifierList(m_parameterTypes); } @@ -4042,17 +4041,17 @@ bool ModifierType::operator==(Type const& _other) const return true; } -string ModifierType::toString(bool _withoutDataLocation) const +std::string ModifierType::toString(bool _withoutDataLocation) const { - string name = "modifier ("; + std::string name = "modifier ("; for (auto it = m_parameterTypes.begin(); it != m_parameterTypes.end(); ++it) name += (*it)->toString(_withoutDataLocation) + (it + 1 == m_parameterTypes.end() ? "" : ","); return name + ")"; } -string ModuleType::richIdentifier() const +std::string ModuleType::richIdentifier() const { - return "t_module_" + to_string(m_sourceUnit.id()); + return "t_module_" + std::to_string(m_sourceUnit.id()); } bool ModuleType::operator==(Type const& _other) const @@ -4071,12 +4070,12 @@ MemberList::MemberMap ModuleType::nativeMembers(ASTNode const*) const return symbols; } -string ModuleType::toString(bool) const +std::string ModuleType::toString(bool) const { - return string("module \"") + *m_sourceUnit.annotation().path + string("\""); + return std::string("module \"") + *m_sourceUnit.annotation().path + std::string("\""); } -string MagicType::richIdentifier() const +std::string MagicType::richIdentifier() const { switch (m_kind) { @@ -4243,7 +4242,7 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const return {}; } -string MagicType::toString(bool _withoutDataLocation) const +std::string MagicType::toString(bool _withoutDataLocation) const { switch (m_kind) { diff --git a/scripts/check_style.sh b/scripts/check_style.sh index a396a7d76..6a4803413 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -25,7 +25,8 @@ NAMESPACE_STD_FREE_FILES=( liblangutil/* libsmtutil/* libsolc/* - libsolidity/analysis/* + libsolidity/analysis/* + libsolidity/ast/* ) (