From e4e0472407ce3037e546cf46610459dbb50dbc86 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 22 Aug 2023 15:05:39 +0200 Subject: [PATCH] Eliminate using namespace std. --- .../experimental/analysis/Analysis.cpp | 3 +- .../experimental/analysis/TypeInference.cpp | 79 +++++++++---------- .../analysis/TypeRegistration.cpp | 5 +- libsolidity/experimental/ast/Type.cpp | 1 - libsolidity/experimental/ast/TypeSystem.cpp | 29 ++++--- .../experimental/ast/TypeSystemHelper.cpp | 51 ++++++------ libsolidity/experimental/codegen/Common.cpp | 23 +++--- .../experimental/codegen/IRGenerator.cpp | 11 ++- .../codegen/IRGeneratorForStatements.cpp | 25 +++--- .../experimental/codegen/IRVariable.cpp | 1 - scripts/check_style.sh | 1 + 11 files changed, 110 insertions(+), 119 deletions(-) diff --git a/libsolidity/experimental/analysis/Analysis.cpp b/libsolidity/experimental/analysis/Analysis.cpp index 7695f15e8..7e1cf94b6 100644 --- a/libsolidity/experimental/analysis/Analysis.cpp +++ b/libsolidity/experimental/analysis/Analysis.cpp @@ -21,7 +21,6 @@ #include #include -using namespace std; using namespace solidity::langutil; using namespace solidity::frontend::experimental; @@ -120,7 +119,7 @@ std::tuple...> makeIndexTuple(std::index_sequ return std::make_tuple( std::integral_constant{}...); } -bool Analysis::check(vector> const& _sourceUnits) +bool Analysis::check(std::vector> const& _sourceUnits) { using AnalysisSteps = std::tuple; diff --git a/libsolidity/experimental/analysis/TypeInference.cpp b/libsolidity/experimental/analysis/TypeInference.cpp index 52a0679da..56dec5dc6 100644 --- a/libsolidity/experimental/analysis/TypeInference.cpp +++ b/libsolidity/experimental/analysis/TypeInference.cpp @@ -33,7 +33,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::frontend; using namespace solidity::frontend::experimental; @@ -51,9 +50,9 @@ m_typeSystem(_analysis.typeSystem()) _name, nullptr ); - if (auto error = get_if(&result)) + if (auto error = std::get_if(&result)) solAssert(!error, *error); - TypeClass resultClass = get(result); + TypeClass resultClass = std::get(result); // TODO: validation? annotation().typeClassFunctions[resultClass] = _memberCreator(type); solAssert(annotation().builtinClassesByName.emplace(_name, _class).second); @@ -111,7 +110,7 @@ m_typeSystem(_analysis.typeSystem()) m_env = &m_typeSystem.env(); { - auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Bool), map{}); + auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Bool), std::map{}); solAssert(newlyInserted); members->second.emplace("abs", TypeMember{helper.functionType(m_wordType, m_boolType)}); members->second.emplace("rep", TypeMember{helper.functionType(m_boolType, m_wordType)}); @@ -120,7 +119,7 @@ m_typeSystem(_analysis.typeSystem()) Type first = m_typeSystem.freshTypeVariable({}); Type second = m_typeSystem.freshTypeVariable({}); Type pairType = m_typeSystem.type(PrimitiveType::Pair, {first, second}); - auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Pair), map{}); + auto [members, newlyInserted] = annotation().members.emplace(m_typeSystem.constructor(PrimitiveType::Pair), std::map{}); solAssert(newlyInserted); members->second.emplace("first", TypeMember{helper.functionType(pairType, first)}); members->second.emplace("second", TypeMember{helper.functionType(pairType, second)}); @@ -140,7 +139,7 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition) if (functionAnnotation.type) return false; - ScopedSaveAndRestore signatureRestore(m_currentFunctionType, nullopt); + ScopedSaveAndRestore signatureRestore(m_currentFunctionType, std::nullopt); Type argumentsType = m_typeSystem.freshTypeVariable({}); Type returnType = m_typeSystem.freshTypeVariable({}); @@ -174,7 +173,7 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition) void TypeInference::endVisit(Return const& _return) { solAssert(m_currentFunctionType); - Type functionReturnType = get<1>(TypeSystemHelpers{m_typeSystem}.destFunctionType(*m_currentFunctionType)); + Type functionReturnType = std::get<1>(TypeSystemHelpers{m_typeSystem}.destFunctionType(*m_currentFunctionType)); if (_return.expression()) unify(functionReturnType, getType(*_return.expression()), _return.location()); else @@ -186,7 +185,7 @@ void TypeInference::endVisit(ParameterList const& _parameterList) auto& listAnnotation = annotation(_parameterList); solAssert(!listAnnotation.type); listAnnotation.type = TypeSystemHelpers{m_typeSystem}.tupleType( - _parameterList.parameters() | ranges::views::transform([&](auto _arg) { return getType(*_arg); }) | ranges::to> + _parameterList.parameters() | ranges::views::transform([&](auto _arg) { return getType(*_arg); }) | ranges::to> ); } @@ -202,7 +201,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition) _typeClassDefinition.typeVariable().accept(*this); } - map functionTypes; + std::map functionTypes; Type typeVar = m_typeSystem.freshTypeVariable({}); auto& typeMembers = annotation().members[typeConstructor(&_typeClassDefinition)]; @@ -283,7 +282,7 @@ bool TypeInference::visit(InlineAssembly const& _inlineAssembly) return true; }; solAssert(!_inlineAssembly.annotation().analysisInfo, ""); - _inlineAssembly.annotation().analysisInfo = make_shared(); + _inlineAssembly.annotation().analysisInfo = std::make_shared(); yul::AsmAnalyzer analyzer( *_inlineAssembly.annotation().analysisInfo, m_errorReporter, @@ -306,7 +305,7 @@ bool TypeInference::visit(ElementaryTypeNameExpression const& _expression) case ExpressionContext::Type: if (auto constructor = m_analysis.annotation(_expression).typeConstructor) { - vector arguments; + std::vector arguments; std::generate_n(std::back_inserter(arguments), m_typeSystem.constructorInfo(*constructor).arguments(), [&]() { return m_typeSystem.freshTypeVariable({}); }); @@ -631,7 +630,7 @@ void TypeInference::endVisit(TupleExpression const& _tupleExpression) auto& componentAnnotation = annotation(*_expr); solAssert(componentAnnotation.type); return *componentAnnotation.type; - }) | ranges::to>; + }) | ranges::to>; switch (m_expressionContext) { case ExpressionContext::Term: @@ -666,7 +665,7 @@ bool TypeInference::visit(IdentifierPath const& _identifierPath) bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation) { - ScopedSaveAndRestore activeInstantiations{m_activeInstantiations, m_activeInstantiations + set{&_typeClassInstantiation}}; + ScopedSaveAndRestore activeInstantiations{m_activeInstantiations, m_activeInstantiations + std::set{&_typeClassInstantiation}}; // Note: recursion is resolved due to special handling during unification. auto& instantiationAnnotation = annotation(_typeClassInstantiation); if (instantiationAnnotation.type) @@ -686,7 +685,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation) else { m_errorReporter.typeError(0000_error, _typeClassInstantiation.typeClass().location(), "Expected type class."); - return nullopt; + return std::nullopt; } }, [&](Token _token) -> std::optional { @@ -694,7 +693,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation) if (auto typeClass = util::valueOrNullptr(annotation().builtinClasses, *builtinClass)) return *typeClass; m_errorReporter.typeError(0000_error, _typeClassInstantiation.location(), "Invalid type class name."); - return nullopt; + return std::nullopt; } }, _typeClassInstantiation.typeClass().name()); if (!typeClass) @@ -708,7 +707,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation) return false; } - vector arguments; + std::vector arguments; Arity arity{ {}, *typeClass @@ -724,13 +723,13 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation) arguments = TypeSystemHelpers{m_typeSystem}.destTupleType(*argumentSortAnnotation.type); arity.argumentSorts = arguments | ranges::views::transform([&](Type _type) { return m_env->sort(_type); - }) | ranges::to>; + }) | ranges::to>; } } Type type{TypeConstant{*typeConstructor, arguments}}; - map functionTypes; + std::map functionTypes; for (auto subNode: _typeClassInstantiation.subNodes()) { @@ -834,7 +833,7 @@ bool TypeInference::visit(TypeDefinition const& _typeDefinition) underlyingType = annotation(*_typeDefinition.typeExpression()).type; } - vector arguments; + std::vector arguments; if (_typeDefinition.arguments()) for (size_t i = 0; i < _typeDefinition.arguments()->parameters().size(); ++i) arguments.emplace_back(m_typeSystem.freshTypeVariable({})); @@ -846,7 +845,7 @@ bool TypeInference::visit(TypeDefinition const& _typeDefinition) typeDefinitionAnnotation.type = helper.typeFunctionType(helper.tupleType(arguments), definedType); TypeConstructor constructor = typeConstructor(&_typeDefinition); - auto [members, newlyInserted] = annotation().members.emplace(constructor, map{}); + auto [members, newlyInserted] = annotation().members.emplace(constructor, std::map{}); solAssert(newlyInserted); if (underlyingType) { @@ -910,7 +909,7 @@ void TypeInference::endVisit(FunctionCall const& _functionCall) namespace { -optional parseRational(string const& _value) +std::optional parseRational(std::string const& _value) { rational value; try @@ -923,7 +922,7 @@ optional parseRational(string const& _value) !all_of(radixPoint + 1, _value.end(), util::isDigit) || !all_of(_value.begin(), radixPoint, util::isDigit) ) - return nullopt; + return std::nullopt; // Only decimal notation allowed here, leading zeros would switch to octal. auto fractionalBegin = find_if_not( @@ -935,12 +934,12 @@ optional 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 @@ -949,7 +948,7 @@ optional parseRational(string const& _value) } catch (...) { - return nullopt; + return std::nullopt; } } @@ -960,7 +959,7 @@ bool fitsPrecisionBase10(bigint const& _mantissa, uint32_t _expBase10) return fitsPrecisionBaseX(_mantissa, log2Of10AwayFromZero, _expBase10); } -optional rationalValue(Literal const& _literal) +std::optional rationalValue(Literal const& _literal) { rational value; try @@ -979,27 +978,27 @@ optional rationalValue(Literal const& _literal) else if (expPoint != valueString.end()) { // Parse mantissa and exponent. Checks numeric limit. - optional mantissa = parseRational(string(valueString.begin(), expPoint)); + std::optional mantissa = parseRational(std::string(valueString.begin(), expPoint)); if (!mantissa) - return nullopt; + return std::nullopt; value = *mantissa; // 0E... is always zero. if (value == 0) - return nullopt; + return std::nullopt; - 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 nullopt; + if (exp > std::numeric_limits::max() || exp < std::numeric_limits::min()) + return std::nullopt; uint32_t expAbs = bigint(abs(exp)).convert_to(); if (exp < 0) { if (!fitsPrecisionBase10(abs(value.denominator()), expAbs)) - return nullopt; + return std::nullopt; value /= boost::multiprecision::pow( bigint(10), expAbs @@ -1008,7 +1007,7 @@ optional rationalValue(Literal const& _literal) else if (exp > 0) { if (!fitsPrecisionBase10(abs(value.numerator()), expAbs)) - return nullopt; + return std::nullopt; value *= boost::multiprecision::pow( bigint(10), expAbs @@ -1018,15 +1017,15 @@ optional rationalValue(Literal const& _literal) else { // parse as rational number - optional tmp = parseRational(valueString); + std::optional tmp = parseRational(valueString); if (!tmp) - return nullopt; + return std::nullopt; value = *tmp; } } catch (...) { - return nullopt; + return std::nullopt; } switch (_literal.subDenomination()) { @@ -1069,7 +1068,7 @@ bool TypeInference::visit(Literal const& _literal) m_errorReporter.typeError(0000_error, _literal.location(), "Only number literals are supported."); return false; } - optional value = rationalValue(_literal); + std::optional value = rationalValue(_literal); if (!value) { m_errorReporter.typeError(0000_error, _literal.location(), "Invalid number literals."); @@ -1127,7 +1126,7 @@ void TypeInference::unify(Type _a, Type _b, langutil::SourceLocation _location) bool onlyMissingInstantiations = [&]() { for (auto failure: unificationFailures) { - if (auto* sortMismatch = get_if(&failure)) + if (auto* sortMismatch = std::get_if(&failure)) if (helper.isTypeConstant(sortMismatch->type)) { TypeConstructor constructor = std::get<0>(helper.destTypeConstant(sortMismatch->type)); @@ -1220,7 +1219,7 @@ TypeConstructor TypeInference::typeConstructor(Declaration const* _type) const m_errorReporter.fatalTypeError(0000_error, _type->location(), "Unregistered type."); util::unreachable(); } -experimental::Type TypeInference::type(Declaration const* _type, vector _arguments) const +experimental::Type TypeInference::type(Declaration const* _type, std::vector _arguments) const { return m_typeSystem.type(typeConstructor(_type), std::move(_arguments)); } diff --git a/libsolidity/experimental/analysis/TypeRegistration.cpp b/libsolidity/experimental/analysis/TypeRegistration.cpp index 3cc46c438..424dc78ff 100644 --- a/libsolidity/experimental/analysis/TypeRegistration.cpp +++ b/libsolidity/experimental/analysis/TypeRegistration.cpp @@ -26,7 +26,6 @@ #include #include -using namespace std; using namespace solidity::frontend; using namespace solidity::frontend::experimental; using namespace solidity::langutil; @@ -61,7 +60,7 @@ bool TypeRegistration::visit(ElementaryTypeName const& _typeName) { if (annotation(_typeName).typeConstructor) return false; - annotation(_typeName).typeConstructor = [&]() -> optional { + annotation(_typeName).typeConstructor = [&]() -> std::optional { switch(_typeName.typeName().token()) { case Token::Void: @@ -80,7 +79,7 @@ bool TypeRegistration::visit(ElementaryTypeName const& _typeName) return m_typeSystem.constructor(PrimitiveType::Bool); default: m_errorReporter.fatalTypeError(0000_error, _typeName.location(), "Expected primitive type."); - return nullopt; + return std::nullopt; } }(); return true; diff --git a/libsolidity/experimental/ast/Type.cpp b/libsolidity/experimental/ast/Type.cpp index 9650a6411..ec822dc64 100644 --- a/libsolidity/experimental/ast/Type.cpp +++ b/libsolidity/experimental/ast/Type.cpp @@ -25,7 +25,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend::experimental; diff --git a/libsolidity/experimental/ast/TypeSystem.cpp b/libsolidity/experimental/ast/TypeSystem.cpp index 443946b8d..3ed04fd1f 100644 --- a/libsolidity/experimental/ast/TypeSystem.cpp +++ b/libsolidity/experimental/ast/TypeSystem.cpp @@ -32,14 +32,13 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend; using namespace solidity::frontend::experimental; -vector TypeEnvironment::unify(Type _a, Type _b) +std::vector TypeEnvironment::unify(Type _a, Type _b) { - vector failures; + std::vector failures; auto unificationFailure = [&]() { failures.emplace_back(UnificationFailure{TypeMismatch{_a, _b}}); }; @@ -151,9 +150,9 @@ TypeSystem::TypeSystem() TypeClass classType = primitiveClass(PrimitiveClass::Type); //TypeClass classKind = primitiveClass(PrimitiveClass::Kind); Sort typeSort{{classType}}; - m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::TypeFunction).m_index).arities = {Arity{vector{{typeSort},{typeSort}}, classType}}; - m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{vector{{typeSort, typeSort}}, classType}}; - m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{vector{{typeSort, typeSort}}, classType}}; + m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::TypeFunction).m_index).arities = {Arity{std::vector{{typeSort},{typeSort}}, classType}}; + m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector{{typeSort, typeSort}}, classType}}; + m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector{{typeSort, typeSort}}, classType}}; } experimental::Type TypeSystem::freshVariable(Sort _sort) @@ -168,7 +167,7 @@ experimental::Type TypeSystem::freshTypeVariable(Sort _sort) return freshVariable(_sort); } -vector TypeEnvironment::instantiate(TypeVariable _variable, Type _type) +std::vector TypeEnvironment::instantiate(TypeVariable _variable, Type _type) { for (auto typeVar: TypeEnvironmentHelpers{*this}.typeVars(_type)) if (typeVar.index() == _variable.index()) @@ -201,7 +200,7 @@ experimental::Type TypeEnvironment::resolveRecursive(Type _type) const _type.constructor, _type.arguments | ranges::views::transform([&](Type _argType) { return resolveRecursive(_argType); - }) | ranges::to> + }) | ranges::to> }; }, [&](TypeVariable const&) -> Type { @@ -221,7 +220,7 @@ Sort TypeEnvironment::sort(Type _type) const auto const& constructorInfo = m_typeSystem.constructorInfo(_expression.constructor); auto argumentSorts = _expression.arguments | ranges::views::transform([&](Type _argumentType) { return sort(resolve(_argumentType)); - }) | ranges::to>; + }) | ranges::to>; Sort sort; for (auto const& arity: constructorInfo.arities) { @@ -246,7 +245,7 @@ Sort TypeEnvironment::sort(Type _type) const }, _type); } -TypeConstructor TypeSystem::declareTypeConstructor(string _name, string _canonicalName, size_t _arguments, Declaration const* _declaration) +TypeConstructor TypeSystem::declareTypeConstructor(std::string _name, std::string _canonicalName, size_t _arguments, Declaration const* _declaration) { solAssert(m_canonicalTypeNames.insert(_canonicalName).second, "Duplicate canonical type name."); Sort baseSort{{primitiveClass(PrimitiveClass::Type)}}; @@ -254,7 +253,7 @@ TypeConstructor TypeSystem::declareTypeConstructor(string _name, string _canonic m_typeConstructors.emplace_back(TypeConstructorInfo{ _name, _canonicalName, - {Arity{vector{_arguments, baseSort}, primitiveClass(PrimitiveClass::Type)}}, + {Arity{std::vector{_arguments, baseSort}, primitiveClass(PrimitiveClass::Type)}}, _declaration }); TypeConstructor constructor{index}; @@ -277,7 +276,7 @@ TypeConstructor TypeSystem::declareTypeConstructor(string _name, string _canonic std::variant TypeSystem::declareTypeClass(Type _typeVariable, std::string _name, Declaration const* _declaration) { - TypeVariable const* typeVariable = get_if(&_typeVariable); + TypeVariable const* typeVariable = std::get_if(&_typeVariable); if (!typeVariable) return "Invalid type variable."; @@ -310,13 +309,13 @@ experimental::Type TypeEnvironment::fresh(Type _type) _type.constructor, _type.arguments | ranges::views::transform([&](Type _argType) { return _recurse(_argType, _recurse); - }) | ranges::to> + }) | ranges::to> }; }, [&](TypeVariable const& _var) -> Type { if (auto* mapped = util::valueOrNullptr(mapping, _var.index())) { - auto* typeVariable = get_if(mapped); + auto* typeVariable = std::get_if(mapped); solAssert(typeVariable); // TODO: can there be a mismatch? solAssert(typeVariable->sort() == _var.sort()); @@ -343,5 +342,5 @@ std::optional TypeSystem::instantiateClass(Type _instanceVariable, typeConstructorInfo.arities.emplace_back(_arity); - return nullopt; + return std::nullopt; } diff --git a/libsolidity/experimental/ast/TypeSystemHelper.cpp b/libsolidity/experimental/ast/TypeSystemHelper.cpp index b8d72b85b..2d86ea4b5 100644 --- a/libsolidity/experimental/ast/TypeSystemHelper.cpp +++ b/libsolidity/experimental/ast/TypeSystemHelper.cpp @@ -32,7 +32,6 @@ #include -using namespace std; using namespace solidity::langutil; using namespace solidity::frontend; using namespace solidity::frontend::experimental; @@ -97,7 +96,7 @@ std::optional experimental::builtinClassFromToken(langutil::Token case Token::GreaterThanOrEqual: return BuiltinClass::GreaterOrEqual; default: - return nullopt; + return std::nullopt; } } /* @@ -116,7 +115,7 @@ std::optional experimental::typeClassFromTypeClassName(TypeClassName }, _typeClass.name()); } */ -experimental::Type TypeSystemHelpers::tupleType(vector _elements) const +experimental::Type TypeSystemHelpers::tupleType(std::vector _elements) const { if (_elements.empty()) return typeSystem.type(PrimitiveType::Unit, {}); @@ -128,7 +127,7 @@ experimental::Type TypeSystemHelpers::tupleType(vector _elements) const return result; } -vector TypeSystemHelpers::destTupleType(Type _tupleType) const +std::vector TypeSystemHelpers::destTupleType(Type _tupleType) const { if (!isTypeConstant(_tupleType)) return {_tupleType}; @@ -140,7 +139,7 @@ vector TypeSystemHelpers::destTupleType(Type _tupleType) con return {_tupleType}; solAssert(arguments.size() == 2); - vector result; + std::vector result; result.emplace_back(arguments.front()); Type tail = arguments.back(); while(true) @@ -158,7 +157,7 @@ vector TypeSystemHelpers::destTupleType(Type _tupleType) con return result; } -experimental::Type TypeSystemHelpers::sumType(vector _elements) const +experimental::Type TypeSystemHelpers::sumType(std::vector _elements) const { if (_elements.empty()) return typeSystem.type(PrimitiveType::Void, {}); @@ -170,7 +169,7 @@ experimental::Type TypeSystemHelpers::sumType(vector _elements) const return result; } -vector TypeSystemHelpers::destSumType(Type _tupleType) const +std::vector TypeSystemHelpers::destSumType(Type _tupleType) const { if (!isTypeConstant(_tupleType)) return {_tupleType}; @@ -182,7 +181,7 @@ vector TypeSystemHelpers::destSumType(Type _tupleType) const return {_tupleType}; solAssert(arguments.size() == 2); - vector result; + std::vector result; result.emplace_back(arguments.front()); Type tail = arguments.back(); while(true) @@ -200,9 +199,9 @@ vector TypeSystemHelpers::destSumType(Type _tupleType) const return result; } -tuple> TypeSystemHelpers::destTypeConstant(Type _type) const +std::tuple> TypeSystemHelpers::destTypeConstant(Type _type) const { - using ResultType = tuple>; + using ResultType = std::tuple>; return std::visit(util::GenericVisitor{ [&](TypeConstant const& _type) -> ResultType { return std::make_tuple(_type.constructor, _type.arguments); @@ -230,19 +229,19 @@ experimental::Type TypeSystemHelpers::functionType(experimental::Type _argType, return typeSystem.type(PrimitiveType::Function, {_argType, _resultType}); } -tuple TypeSystemHelpers::destFunctionType(Type _functionType) const +std::tuple TypeSystemHelpers::destFunctionType(Type _functionType) const { auto [constructor, arguments] = destTypeConstant(_functionType); solAssert(constructor == typeSystem.constructor(PrimitiveType::Function)); solAssert(arguments.size() == 2); - return make_tuple(arguments.front(), arguments.back()); + return std::make_tuple(arguments.front(), arguments.back()); } bool TypeSystemHelpers::isFunctionType(Type _type) const { if (!isTypeConstant(_type)) return false; - auto constructor = get<0>(destTypeConstant(_type)); + auto constructor = std::get<0>(destTypeConstant(_type)); return constructor == typeSystem.constructor(PrimitiveType::Function); } @@ -251,26 +250,26 @@ experimental::Type TypeSystemHelpers::typeFunctionType(experimental::Type _argTy return typeSystem.type(PrimitiveType::TypeFunction, {_argType, _resultType}); } -tuple TypeSystemHelpers::destTypeFunctionType(Type _functionType) const +std::tuple TypeSystemHelpers::destTypeFunctionType(Type _functionType) const { auto [constructor, arguments] = destTypeConstant(_functionType); solAssert(constructor == typeSystem.constructor(PrimitiveType::TypeFunction)); solAssert(arguments.size() == 2); - return make_tuple(arguments.front(), arguments.back()); + return std::make_tuple(arguments.front(), arguments.back()); } bool TypeSystemHelpers::isTypeFunctionType(Type _type) const { if (!isTypeConstant(_type)) return false; - auto constructor = get<0>(destTypeConstant(_type)); + auto constructor = std::get<0>(destTypeConstant(_type)); return constructor == typeSystem.constructor(PrimitiveType::TypeFunction); } -vector TypeEnvironmentHelpers::typeVars(Type _type) const +std::vector TypeEnvironmentHelpers::typeVars(Type _type) const { - set indices; - vector typeVars; + std::set indices; + std::vector typeVars; auto typeVarsImpl = [&](Type _type, auto _recurse) -> void { std::visit(util::GenericVisitor{ [&](TypeConstant const& _type) { @@ -310,10 +309,10 @@ std::string TypeSystemHelpers::sortToString(Sort _sort) const } } -string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const +std::string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const { return visit(util::GenericVisitor{ - [&](TypeConstant _type) -> string { + [&](TypeConstant _type) -> std::string { std::stringstream stream; stream << env.typeSystem().constructorInfo(_type.constructor).canonicalName; if (!_type.arguments.empty()) @@ -326,10 +325,10 @@ string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const } return stream.str(); }, - [](TypeVariable) -> string { + [](TypeVariable) -> std::string { solAssert(false); }, - [](std::monostate) -> string { + [](std::monostate) -> std::string { solAssert(false); }, }, env.resolve(_type)); @@ -337,7 +336,7 @@ string TypeEnvironmentHelpers::canonicalTypeName(Type _type) const std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const { - std::map)>> formatters{ + std::map)>> formatters{ {env.typeSystem().constructor(PrimitiveType::Function), [&](auto const& _args) { solAssert(_args.size() == 2); return fmt::format("{} -> {}", typeToString(_args.front()), typeToString(_args.back())); @@ -348,7 +347,7 @@ std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const }}, {env.typeSystem().constructor(PrimitiveType::Pair), [&](auto const& _arguments) { auto tupleTypes = TypeSystemHelpers{env.typeSystem()}.destTupleType(_arguments.back()); - string result = "("; + std::string result = "("; result += typeToString(_arguments.front()); for (auto type: tupleTypes) result += ", " + typeToString(type); @@ -398,6 +397,6 @@ std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const } return stream.str(); }, - [](std::monostate) -> string { solAssert(false); } + [](std::monostate) -> std::string { solAssert(false); } }, env.resolve(_type)); } diff --git a/libsolidity/experimental/codegen/Common.cpp b/libsolidity/experimental/codegen/Common.cpp index b14c51c67..de50fd47c 100644 --- a/libsolidity/experimental/codegen/Common.cpp +++ b/libsolidity/experimental/codegen/Common.cpp @@ -24,7 +24,6 @@ #include -using namespace std; using namespace solidity::langutil; using namespace solidity::frontend; using namespace solidity::util; @@ -33,42 +32,42 @@ using namespace solidity::yul; namespace solidity::frontend::experimental { -string IRNames::function(TypeEnvironment const& _env, FunctionDefinition const& _function, Type _type) +std::string IRNames::function(TypeEnvironment const& _env, FunctionDefinition const& _function, Type _type) { if (_function.isConstructor()) return constructor(*_function.annotation().contract); - return "fun_" + _function.name() + "_" + to_string(_function.id()) + "$" + TypeEnvironmentHelpers{_env}.canonicalTypeName(_type) + "$"; + return "fun_" + _function.name() + "_" + std::to_string(_function.id()) + "$" + TypeEnvironmentHelpers{_env}.canonicalTypeName(_type) + "$"; } -string IRNames::function(VariableDeclaration const& _varDecl) +std::string IRNames::function(VariableDeclaration const& _varDecl) { - return "getter_fun_" + _varDecl.name() + "_" + to_string(_varDecl.id()); + return "getter_fun_" + _varDecl.name() + "_" + std::to_string(_varDecl.id()); } -string IRNames::creationObject(ContractDefinition const& _contract) +std::string IRNames::creationObject(ContractDefinition const& _contract) { return _contract.name() + "_" + toString(_contract.id()); } -string IRNames::deployedObject(ContractDefinition const& _contract) +std::string IRNames::deployedObject(ContractDefinition const& _contract) { return _contract.name() + "_" + toString(_contract.id()) + "_deployed"; } -string IRNames::constructor(ContractDefinition const& _contract) +std::string IRNames::constructor(ContractDefinition const& _contract) { - return "constructor_" + _contract.name() + "_" + to_string(_contract.id()); + return "constructor_" + _contract.name() + "_" + std::to_string(_contract.id()); } -string IRNames::localVariable(VariableDeclaration const& _declaration) +std::string IRNames::localVariable(VariableDeclaration const& _declaration) { return "var_" + _declaration.name() + '_' + std::to_string(_declaration.id()); } -string IRNames::localVariable(Expression const& _expression) +std::string IRNames::localVariable(Expression const& _expression) { - return "expr_" + to_string(_expression.id()); + return "expr_" + std::to_string(_expression.id()); } } diff --git a/libsolidity/experimental/codegen/IRGenerator.cpp b/libsolidity/experimental/codegen/IRGenerator.cpp index a050ed07a..257bd2be1 100644 --- a/libsolidity/experimental/codegen/IRGenerator.cpp +++ b/libsolidity/experimental/codegen/IRGenerator.cpp @@ -40,7 +40,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend::experimental; using namespace solidity::langutil; @@ -64,10 +63,10 @@ m_context{_analysis, &m_env, {}, {}} { } -string IRGenerator::run( +std::string IRGenerator::run( ContractDefinition const& _contract, bytes const& /*_cborMetadata*/, - map const& /*_otherYulSources*/ + std::map const& /*_otherYulSources*/ ) { @@ -91,7 +90,7 @@ string IRGenerator::run( return t.render(); } -string IRGenerator::generate(ContractDefinition const& _contract) +std::string IRGenerator::generate(ContractDefinition const& _contract) { std::stringstream code; code << "{\n"; @@ -110,7 +109,7 @@ string IRGenerator::generate(ContractDefinition const& _contract) { auto queueEntry = m_context.functionQueue.front(); m_context.functionQueue.pop_front(); - auto& generatedTypes = m_context.generatedFunctions.insert(std::make_pair(queueEntry.function, vector{})).first->second; + auto& generatedTypes = m_context.generatedFunctions.insert(std::make_pair(queueEntry.function, std::vector{})).first->second; if (!util::contains_if(generatedTypes, [&](auto const& _generatedType) { return m_context.env->typeEquals(_generatedType, queueEntry.type); })) { generatedTypes.emplace_back(queueEntry.type); @@ -121,7 +120,7 @@ string IRGenerator::generate(ContractDefinition const& _contract) return code.str(); } -string IRGenerator::generate(FunctionDefinition const& _function, Type _type) +std::string IRGenerator::generate(FunctionDefinition const& _function, Type _type) { TypeEnvironment newEnv = m_context.env->clone(); ScopedSaveAndRestore envRestore{m_context.env, &newEnv}; diff --git a/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp b/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp index 911dc11f9..6add66c42 100644 --- a/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp +++ b/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp @@ -33,7 +33,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::util; using namespace solidity::frontend; @@ -54,7 +53,7 @@ struct CopyTranslate: public yul::ASTCopier CopyTranslate( IRGenerationContext const& _context, yul::Dialect const& _dialect, - map _references + std::map _references ): m_context(_context), m_dialect(_dialect), m_references(std::move(_references)) {} using ASTCopier::operator(); @@ -83,8 +82,8 @@ struct CopyTranslate: public yul::ASTCopier return ASTCopier::translate(_identifier); yul::Expression translated = translateReference(_identifier); - solAssert(holds_alternative(translated)); - return get(std::move(translated)); + solAssert(std::holds_alternative(translated)); + return std::get(std::move(translated)); } private: @@ -100,20 +99,20 @@ private: auto type = m_context.analysis.annotation(*varDecl).type; solAssert(type); solAssert(m_context.env->typeEquals(*type, m_context.analysis.typeSystem().type(PrimitiveType::Word, {}))); - string value = IRNames::localVariable(*varDecl); + std::string value = IRNames::localVariable(*varDecl); return yul::Identifier{_identifier.debugData, yul::YulString{value}}; } IRGenerationContext const& m_context; yul::Dialect const& m_dialect; - map m_references; + std::map m_references; }; } bool IRGeneratorForStatements::visit(TupleExpression const& _tupleExpression) { - std::vector components; + std::vector components; for (auto const& component: _tupleExpression.components()) { solUnimplementedAssert(component); @@ -130,7 +129,7 @@ bool IRGeneratorForStatements::visit(InlineAssembly const& _assembly) { CopyTranslate bodyCopier{m_context, _assembly.dialect(), _assembly.annotation().externalReferences}; yul::Statement modified = bodyCopier(_assembly.operations()); - solAssert(holds_alternative(modified)); + solAssert(std::holds_alternative(modified)); m_code << yul::AsmPrinter()(std::get(modified)) << "\n"; return false; } @@ -223,7 +222,7 @@ TypeRegistration::TypeClassInstantiations const& typeClassInstantiations(IRGener } } -FunctionDefinition const& IRGeneratorForStatements::resolveTypeClassFunction(TypeClass _class, string _name, Type _type) +FunctionDefinition const& IRGeneratorForStatements::resolveTypeClassFunction(TypeClass _class, std::string _name, Type _type) { TypeSystemHelpers helper{m_context.analysis.typeSystem()}; @@ -232,7 +231,7 @@ FunctionDefinition const& IRGeneratorForStatements::resolveTypeClassFunction(Typ auto typeVars = TypeEnvironmentHelpers{env}.typeVars(genericFunctionType); solAssert(typeVars.size() == 1); solAssert(env.unify(genericFunctionType, _type).empty()); - auto typeClassInstantiation = get<0>(helper.destTypeConstant(env.resolve(typeVars.front()))); + auto typeClassInstantiation = std::get<0>(helper.destTypeConstant(env.resolve(typeVars.front()))); auto const& instantiations = typeClassInstantiations(m_context, _class); TypeClassInstantiation const* instantiation = instantiations.at(typeClassInstantiation); @@ -271,7 +270,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess) solAssert(declaration); if (auto const* typeClassDefinition = dynamic_cast(declaration)) { - optional typeClass = m_context.analysis.annotation(*typeClassDefinition).typeClass; + std::optional typeClass = m_context.analysis.annotation(*typeClassDefinition).typeClass; solAssert(typeClass); solAssert(m_expressionDeclaration.emplace( &_memberAccess, @@ -299,7 +298,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) { Type functionType = type(_functionCall.expression()); auto declaration = m_expressionDeclaration.at(&_functionCall.expression()); - if (auto builtin = get_if(&declaration)) + if (auto builtin = std::get_if(&declaration)) { switch(*builtin) { @@ -315,7 +314,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) } solAssert(false); } - FunctionDefinition const* functionDefinition = dynamic_cast(get(declaration)); + FunctionDefinition const* functionDefinition = dynamic_cast(std::get(declaration)); solAssert(functionDefinition); // TODO: get around resolveRecursive by passing the environment further down? functionType = m_context.env->resolveRecursive(functionType); diff --git a/libsolidity/experimental/codegen/IRVariable.cpp b/libsolidity/experimental/codegen/IRVariable.cpp index 3f2c6f648..7c5a50585 100644 --- a/libsolidity/experimental/codegen/IRVariable.cpp +++ b/libsolidity/experimental/codegen/IRVariable.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::frontend::experimental; using namespace solidity::util; diff --git a/scripts/check_style.sh b/scripts/check_style.sh index dd1f58348..a14dcc46b 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -29,6 +29,7 @@ NAMESPACE_STD_FREE_FILES=( libsolidity/ast/* libsolidity/codegen/ir/* libsolidity/codegen/* + libsolidity/experimental/* libsolidity/formal/* libsolidity/interface/* libsolidity/lsp/*