From b7d2c8bb0ae4d0de0b83aed4bd4ebaf9ff3094da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 8 Aug 2023 16:11:57 +0200 Subject: [PATCH 01/66] SourceReferenceFormatter: Line wrapping and unused includes --- liblangutil/SourceReferenceFormatter.h | 5 ++++- libsolidity/codegen/ir/IRGenerator.cpp | 2 -- test/libsolidity/GasTest.cpp | 1 - test/libyul/Common.cpp | 1 - test/libyul/ControlFlowGraphTest.cpp | 1 - tools/yulPhaser/Program.cpp | 1 - 6 files changed, 4 insertions(+), 7 deletions(-) diff --git a/liblangutil/SourceReferenceFormatter.h b/liblangutil/SourceReferenceFormatter.h index def216efa..c072e72e2 100644 --- a/liblangutil/SourceReferenceFormatter.h +++ b/liblangutil/SourceReferenceFormatter.h @@ -46,7 +46,10 @@ public: bool _colored, bool _withErrorIds ): - m_stream(_stream), m_charStreamProvider(_charStreamProvider), m_colored(_colored), m_withErrorIds(_withErrorIds) + m_stream(_stream), + m_charStreamProvider(_charStreamProvider), + m_colored(_colored), + m_withErrorIds(_withErrorIds) {} /// Prints source location if it is given. diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index 223d712f0..67adb61bb 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -38,8 +38,6 @@ #include #include -#include - #include #include diff --git a/test/libsolidity/GasTest.cpp b/test/libsolidity/GasTest.cpp index 78a0ca907..0060c81e4 100644 --- a/test/libsolidity/GasTest.cpp +++ b/test/libsolidity/GasTest.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index 800684f35..f10414a9f 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include diff --git a/test/libyul/ControlFlowGraphTest.cpp b/test/libyul/ControlFlowGraphTest.cpp index dffc7ecbf..44fff4219 100644 --- a/test/libyul/ControlFlowGraphTest.cpp +++ b/test/libyul/ControlFlowGraphTest.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/tools/yulPhaser/Program.cpp b/tools/yulPhaser/Program.cpp index c62b8e130..3089591ed 100644 --- a/tools/yulPhaser/Program.cpp +++ b/tools/yulPhaser/Program.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include From 8407c8c615c39236db6c29d6c4f8ccbf071ee334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 8 Aug 2023 17:08:37 +0200 Subject: [PATCH 02/66] SourceReferenceFormatter: Support full range of options in formatErrorInformation() --- liblangutil/SourceReferenceFormatter.h | 26 ++++++++++++++----- libsolidity/interface/CompilerStack.cpp | 17 +++++------- test/libsolidity/InlineAssembly.cpp | 10 +++---- .../tools/ossfuzz/SolidityEvmoneInterface.cpp | 9 +++---- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/liblangutil/SourceReferenceFormatter.h b/liblangutil/SourceReferenceFormatter.h index c072e72e2..02a38288a 100644 --- a/liblangutil/SourceReferenceFormatter.h +++ b/liblangutil/SourceReferenceFormatter.h @@ -90,14 +90,28 @@ public: static std::string formatErrorInformation( Error const& _error, - CharStreamProvider const& _charStreamProvider + CharStreamProvider const& _charStreamProvider, + bool _colored = false, + bool _withErrorIds = false ) { - return formatExceptionInformation( - _error, - Error::errorSeverity(_error.type()), - _charStreamProvider - ); + std::ostringstream errorOutput; + SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds); + formatter.printErrorInformation(_error); + return errorOutput.str(); + } + + static std::string formatErrorInformation( + langutil::ErrorList const& _errors, + CharStreamProvider const& _charStreamProvider, + bool _colored = false, + bool _withErrorIds = false + ) + { + std::ostringstream errorOutput; + SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds); + formatter.printErrorInformation(_errors); + return errorOutput.str(); } static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream); diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index bbebc2508..84f886d72 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1486,16 +1486,13 @@ void CompilerStack::generateIR(ContractDefinition const& _contract) m_optimiserSettings, m_debugInfoSelection ); - if (!stack.parseAndAnalyze("", compiledContract.yulIR)) - { - string errorMessage; - for (auto const& error: stack.errors()) - errorMessage += langutil::SourceReferenceFormatter::formatErrorInformation( - *error, - stack.charStream("") - ); - solAssert(false, compiledContract.yulIR + "\n\nInvalid IR generated:\n" + errorMessage + "\n"); - } + bool yulAnalysisSuccessful = stack.parseAndAnalyze("", compiledContract.yulIR); + solAssert( + yulAnalysisSuccessful, + compiledContract.yulIR + "\n\n" + "Invalid IR generated:\n" + + langutil::SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack) + "\n" + ); compiledContract.yulIRAst = stack.astJson(); stack.optimize(); diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 4a8a9d617..d59b843dd 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -85,12 +85,10 @@ std::optional parseAndReturnFirstError( if (_allowWarnings && e->type() == Error::Type::Warning) continue; if (error) - { - string errors; - for (auto const& err: stack.errors()) - errors += SourceReferenceFormatter::formatErrorInformation(*err, stack); - BOOST_FAIL("Found more than one error:\n" + errors); - } + BOOST_FAIL( + "Found more than one error:\n" + + SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack) + ); error = e; } if (!success) diff --git a/test/tools/ossfuzz/SolidityEvmoneInterface.cpp b/test/tools/ossfuzz/SolidityEvmoneInterface.cpp index d2d18bcf5..341470908 100644 --- a/test/tools/ossfuzz/SolidityEvmoneInterface.cpp +++ b/test/tools/ossfuzz/SolidityEvmoneInterface.cpp @@ -42,11 +42,10 @@ optional SolidityCompilationFramework::compileContract() if (m_compilerInput.debugFailure) { cerr << "Compiling contract failed" << endl; - for (auto const& error: m_compiler.errors()) - cerr << SourceReferenceFormatter::formatErrorInformation( - *error, - m_compiler - ); + cerr << SourceReferenceFormatter::formatErrorInformation( + m_compiler.errors(), + m_compiler + ); } return {}; } From 4020552e1d7146ae0373092a3d04c86d40db2b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 8 Aug 2023 17:54:05 +0200 Subject: [PATCH 03/66] SourceReferenceFormatter: Remove the ineffective _withErrorIds parameter from formatExceptionInformation() --- liblangutil/SourceReferenceFormatter.h | 10 ++++------ libsolidity/interface/StandardCompiler.cpp | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/liblangutil/SourceReferenceFormatter.h b/liblangutil/SourceReferenceFormatter.h index 02a38288a..8d3121a7a 100644 --- a/liblangutil/SourceReferenceFormatter.h +++ b/liblangutil/SourceReferenceFormatter.h @@ -64,12 +64,11 @@ public: util::Exception const& _exception, Error::Type _type, CharStreamProvider const& _charStreamProvider, - bool _colored = false, - bool _withErrorIds = false + bool _colored = false ) { std::ostringstream errorOutput; - SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds); + SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, false /* _withErrorIds */); formatter.printExceptionInformation(_exception, _type); return errorOutput.str(); } @@ -78,12 +77,11 @@ public: util::Exception const& _exception, Error::Severity _severity, CharStreamProvider const& _charStreamProvider, - bool _colored = false, - bool _withErrorIds = false + bool _colored = false ) { std::ostringstream errorOutput; - SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds); + SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, false /* _withErrorIds */); formatter.printExceptionInformation(_exception, _severity); return errorOutput.str(); } diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 767792601..32d6cf8e8 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -125,8 +125,7 @@ Json::Value formatErrorWithException( _exception, _type, _charStreamProvider, - false, // colored - false // _withErrorIds + false // colored ); if (string const* description = _exception.comment()) From a59fc39f101449587bad937a92c0c9802c7d6438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 8 Aug 2023 17:17:37 +0200 Subject: [PATCH 04/66] Use printErrorInformation() over printExceptionInformation() where possible --- liblangutil/SourceReferenceFormatter.h | 4 ++++ solc/CommandLineInterface.cpp | 2 +- test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp | 5 +---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/liblangutil/SourceReferenceFormatter.h b/liblangutil/SourceReferenceFormatter.h index 8d3121a7a..91f1d7ddd 100644 --- a/liblangutil/SourceReferenceFormatter.h +++ b/liblangutil/SourceReferenceFormatter.h @@ -52,6 +52,10 @@ public: m_withErrorIds(_withErrorIds) {} + // WARNING: Use the xyzErrorInformation() variants over xyzExceptionInformation() when you + // do have access to an Error instance. Error is implicitly convertible to util::Exception + // but the conversion loses the error ID. + /// Prints source location if it is given. void printSourceLocation(SourceReference const& _ref); void printExceptionInformation(SourceReferenceExtractor::Message const& _msg); diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 7a28900b3..509279a71 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -827,7 +827,7 @@ void CommandLineInterface::compile() else { m_hasOutput = true; - formatter.printExceptionInformation(_error, Error::errorSeverity(_error.type())); + formatter.printErrorInformation(_error); solThrow(CommandLineExecutionError, ""); } } diff --git a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp index b1725a8fa..d1717a159 100644 --- a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp +++ b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp @@ -77,10 +77,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) Error::containsErrors(stack.errors()) ) { - SourceReferenceFormatter formatter(std::cout, stack, false, false); - - for (auto const& error: stack.errors()) - formatter.printExceptionInformation(*error, Error::errorSeverity(error->type())); + SourceReferenceFormatter{std::cout, stack, false, false}.printErrorInformation(stack.errors()); yulAssert(false, "Proto fuzzer generated malformed program"); } From 339053f185253fd50f3476dc75a57fd958544bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 8 Aug 2023 17:19:43 +0200 Subject: [PATCH 05/66] AnalysisFramework.formatErrors(): Fix _withErrorIds flag not having any effect --- test/libsolidity/AnalysisFramework.cpp | 15 ++++++++------- test/libsolidity/AnalysisFramework.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index dc1e4fbcf..6c6ad0cb8 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -147,15 +147,17 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni } string AnalysisFramework::formatErrors( - langutil::ErrorList _errors, + langutil::ErrorList const& _errors, bool _colored, bool _withErrorIds ) const { - string message; - for (auto const& error: _errors) - message += formatError(*error, _colored, _withErrorIds); - return message; + return SourceReferenceFormatter::formatErrorInformation( + _errors, + *m_compiler, + _colored, + _withErrorIds + ); } string AnalysisFramework::formatError( @@ -164,9 +166,8 @@ string AnalysisFramework::formatError( bool _withErrorIds ) const { - return SourceReferenceFormatter::formatExceptionInformation( + return SourceReferenceFormatter::formatErrorInformation( _error, - _error.type(), *m_compiler, _colored, _withErrorIds diff --git a/test/libsolidity/AnalysisFramework.h b/test/libsolidity/AnalysisFramework.h index 2e5d00e1d..d36884390 100644 --- a/test/libsolidity/AnalysisFramework.h +++ b/test/libsolidity/AnalysisFramework.h @@ -58,7 +58,7 @@ protected: langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); std::string formatErrors( - langutil::ErrorList _errors, + langutil::ErrorList const& _errors, bool _colored = false, bool _withErrorIds = false ) const; From de1a017ccb935d149ed6bcbdb730d89883f8ce02 Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Mon, 14 Aug 2023 10:37:11 +0200 Subject: [PATCH 06/66] Purge using namespace std from libsolidity/analysis --- libsolidity/analysis/ConstantEvaluator.cpp | 89 ++++++------ libsolidity/analysis/ContractLevelChecker.cpp | 33 ++--- libsolidity/analysis/ControlFlowAnalyzer.cpp | 19 ++- libsolidity/analysis/ControlFlowBuilder.cpp | 6 +- libsolidity/analysis/ControlFlowGraph.cpp | 1 - libsolidity/analysis/DeclarationContainer.cpp | 21 ++- .../analysis/DeclarationTypeChecker.cpp | 15 +- libsolidity/analysis/DocStringAnalyser.cpp | 15 +- libsolidity/analysis/DocStringTagParser.cpp | 39 +++-- libsolidity/analysis/FunctionCallGraph.cpp | 33 ++--- libsolidity/analysis/GlobalContext.cpp | 16 +- libsolidity/analysis/NameAndTypeResolver.cpp | 63 ++++---- libsolidity/analysis/OverrideChecker.cpp | 85 ++++++----- libsolidity/analysis/PostTypeChecker.cpp | 15 +- .../analysis/PostTypeContractLevelChecker.cpp | 5 +- libsolidity/analysis/ReferencesResolver.cpp | 23 ++- libsolidity/analysis/Scoper.cpp | 1 - libsolidity/analysis/StaticAnalyzer.cpp | 17 +-- libsolidity/analysis/SyntaxChecker.cpp | 35 +++-- libsolidity/analysis/TypeChecker.cpp | 137 +++++++++--------- libsolidity/analysis/ViewPureChecker.cpp | 15 +- scripts/check_style.sh | 1 + 22 files changed, 331 insertions(+), 353 deletions(-) diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp index 7fde36ec0..8e18183a8 100644 --- a/libsolidity/analysis/ConstantEvaluator.cpp +++ b/libsolidity/analysis/ConstantEvaluator.cpp @@ -29,7 +29,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend; using namespace solidity::langutil; @@ -47,9 +46,9 @@ bool fitsPrecisionExp(bigint const& _base, bigint const& _exp) solAssert(_base > 0, ""); - size_t const bitsMax = 4096; + std::size_t const bitsMax = 4096; - size_t mostSignificantBaseBit = static_cast(boost::multiprecision::msb(_base)); + std::size_t mostSignificantBaseBit = static_cast(boost::multiprecision::msb(_base)); if (mostSignificantBaseBit == 0) // _base == 1 return true; if (mostSignificantBaseBit > bitsMax) // _base >= 2 ^ 4096 @@ -68,7 +67,7 @@ bool fitsPrecisionBase2(bigint const& _mantissa, uint32_t _expBase2) } -optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, rational const& _left, rational const& _right) +std::optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, rational const& _left, rational const& _right) { bool fractional = _left.denominator() != 1 || _right.denominator() != 1; switch (_operator) @@ -76,17 +75,17 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra //bit operations will only be enabled for integers and fixed types that resemble integers case Token::BitOr: if (fractional) - return nullopt; + return std::nullopt; else return _left.numerator() | _right.numerator(); case Token::BitXor: if (fractional) - return nullopt; + return std::nullopt; else return _left.numerator() ^ _right.numerator(); case Token::BitAnd: if (fractional) - return nullopt; + return std::nullopt; else return _left.numerator() & _right.numerator(); case Token::Add: return _left + _right; @@ -94,12 +93,12 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra case Token::Mul: return _left * _right; case Token::Div: if (_right == rational(0)) - return nullopt; + return std::nullopt; else return _left / _right; case Token::Mod: if (_right == rational(0)) - return nullopt; + return std::nullopt; else if (fractional) { rational tempValue = _left / _right; @@ -111,7 +110,7 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra case Token::Exp: { if (_right.denominator() != 1) - return nullopt; + return std::nullopt; bigint const& exp = _right.numerator(); // x ** 0 = 1 @@ -127,13 +126,13 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra } else { - if (abs(exp) > numeric_limits::max()) - return nullopt; // This will need too much memory to represent. + if (abs(exp) > std::numeric_limits::max()) + return std::nullopt; // This will need too much memory to represent. uint32_t absExp = bigint(abs(exp)).convert_to(); if (!fitsPrecisionExp(abs(_left.numerator()), absExp) || !fitsPrecisionExp(abs(_left.denominator()), absExp)) - return nullopt; + return std::nullopt; static auto const optimizedPow = [](bigint const& _base, uint32_t _exponent) -> bigint { if (_base == 1) @@ -158,18 +157,18 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra case Token::SHL: { if (fractional) - return nullopt; + return std::nullopt; else if (_right < 0) - return nullopt; - else if (_right > numeric_limits::max()) - return nullopt; + return std::nullopt; + else if (_right > std::numeric_limits::max()) + return std::nullopt; if (_left.numerator() == 0) return 0; else { uint32_t exponent = _right.numerator().convert_to(); if (!fitsPrecisionBase2(abs(_left.numerator()), exponent)) - return nullopt; + return std::nullopt; return _left.numerator() * boost::multiprecision::pow(bigint(2), exponent); } break; @@ -179,11 +178,11 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra case Token::SAR: { if (fractional) - return nullopt; + return std::nullopt; else if (_right < 0) - return nullopt; - else if (_right > numeric_limits::max()) - return nullopt; + return std::nullopt; + else if (_right > std::numeric_limits::max()) + return std::nullopt; if (_left.numerator() == 0) return 0; else @@ -209,60 +208,60 @@ optional ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra break; } default: - return nullopt; + return std::nullopt; } } -optional ConstantEvaluator::evaluateUnaryOperator(Token _operator, rational const& _input) +std::optional ConstantEvaluator::evaluateUnaryOperator(Token _operator, rational const& _input) { switch (_operator) { case Token::BitNot: if (_input.denominator() != 1) - return nullopt; + return std::nullopt; else return ~_input.numerator(); case Token::Sub: return -_input; default: - return nullopt; + return std::nullopt; } } namespace { -optional convertType(rational const& _value, Type const& _type) +std::optional convertType(rational const& _value, Type const& _type) { if (_type.category() == Type::Category::RationalNumber) return TypedRational{TypeProvider::rationalNumber(_value), _value}; else if (auto const* integerType = dynamic_cast(&_type)) { if (_value > integerType->maxValue() || _value < integerType->minValue()) - return nullopt; + return std::nullopt; else return TypedRational{&_type, _value.numerator() / _value.denominator()}; } else - return nullopt; + return std::nullopt; } -optional convertType(optional const& _value, Type const& _type) +std::optional convertType(std::optional const& _value, Type const& _type) { - return _value ? convertType(_value->value, _type) : nullopt; + return _value ? convertType(_value->value, _type) : std::nullopt; } -optional constantToTypedValue(Type const& _type) +std::optional constantToTypedValue(Type const& _type) { if (_type.category() == Type::Category::RationalNumber) return TypedRational{&_type, dynamic_cast(_type).value()}; else - return nullopt; + return std::nullopt; } } -optional ConstantEvaluator::evaluate( +std::optional ConstantEvaluator::evaluate( langutil::ErrorReporter& _errorReporter, Expression const& _expr ) @@ -271,7 +270,7 @@ optional ConstantEvaluator::evaluate( } -optional ConstantEvaluator::evaluate(ASTNode const& _node) +std::optional ConstantEvaluator::evaluate(ASTNode const& _node) { if (!m_values.count(&_node)) { @@ -280,7 +279,7 @@ optional ConstantEvaluator::evaluate(ASTNode const& _node) solAssert(varDecl->isConstant(), ""); // In some circumstances, we do not yet have a type for the variable. if (!varDecl->value() || !varDecl->type()) - m_values[&_node] = nullopt; + m_values[&_node] = std::nullopt; else { m_depth++; @@ -298,7 +297,7 @@ optional ConstantEvaluator::evaluate(ASTNode const& _node) { expression->accept(*this); if (!m_values.count(&_node)) - m_values[&_node] = nullopt; + m_values[&_node] = std::nullopt; } } return m_values.at(&_node); @@ -306,7 +305,7 @@ optional ConstantEvaluator::evaluate(ASTNode const& _node) void ConstantEvaluator::endVisit(UnaryOperation const& _operation) { - optional value = evaluate(_operation.subExpression()); + std::optional value = evaluate(_operation.subExpression()); if (!value) return; @@ -317,9 +316,9 @@ void ConstantEvaluator::endVisit(UnaryOperation const& _operation) if (!value) return; - if (optional result = evaluateUnaryOperator(_operation.getOperator(), value->value)) + if (std::optional result = evaluateUnaryOperator(_operation.getOperator(), value->value)) { - optional convertedValue = convertType(*result, *resultType); + std::optional convertedValue = convertType(*result, *resultType); if (!convertedValue) m_errorReporter.fatalTypeError( 3667_error, @@ -332,8 +331,8 @@ void ConstantEvaluator::endVisit(UnaryOperation const& _operation) void ConstantEvaluator::endVisit(BinaryOperation const& _operation) { - optional left = evaluate(_operation.leftExpression()); - optional right = evaluate(_operation.rightExpression()); + std::optional left = evaluate(_operation.leftExpression()); + std::optional right = evaluate(_operation.rightExpression()); if (!left || !right) return; @@ -349,7 +348,7 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation) 6020_error, _operation.location(), "Operator " + - string(TokenTraits::toString(_operation.getOperator())) + + std::string(TokenTraits::toString(_operation.getOperator())) + " not compatible with types " + left->type->toString() + " and " + @@ -363,9 +362,9 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation) if (!left || !right) return; - if (optional value = evaluateBinaryOperator(_operation.getOperator(), left->value, right->value)) + if (std::optional value = evaluateBinaryOperator(_operation.getOperator(), left->value, right->value)) { - optional convertedValue = convertType(*value, *resultType); + std::optional convertedValue = convertType(*value, *resultType); if (!convertedValue) m_errorReporter.fatalTypeError( 2643_error, diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index e7e7041a0..eaeaf4851 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -32,7 +32,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -49,10 +48,10 @@ bool hasEqualExternalCallableParameters(T const& _a, B const& _b) } template -map> filterDeclarations( - map> const& _declarations) +std::map> filterDeclarations( + std::map> const& _declarations) { - map> filteredDeclarations; + std::map> filteredDeclarations; for (auto const& [name, overloads]: _declarations) for (auto const* declaration: overloads) if (auto typedDeclaration = dynamic_cast(declaration)) @@ -106,7 +105,7 @@ void ContractLevelChecker::checkDuplicateFunctions(ContractDefinition const& _co { /// Checks that two functions with the same name defined in this contract have different /// argument types and that there is at most one constructor. - map> functions; + std::map> functions; FunctionDefinition const* constructor = nullptr; FunctionDefinition const* fallback = nullptr; FunctionDefinition const* receive = nullptr; @@ -157,7 +156,7 @@ void ContractLevelChecker::checkDuplicateEvents(ContractDefinition const& _contr { /// Checks that two events with the same name defined in this contract have different /// argument types - map> events; + std::map> events; for (auto const* contract: _contract.annotation().linearizedBaseContracts) for (EventDefinition const* event: contract->events()) events[event->name()].push_back(event); @@ -195,12 +194,12 @@ void ContractLevelChecker::checkReceiveFunction(ContractDefinition const& _contr } template -void ContractLevelChecker::findDuplicateDefinitions(map> const& _definitions) +void ContractLevelChecker::findDuplicateDefinitions(std::map> const& _definitions) { for (auto const& it: _definitions) { - vector const& overloads = it.second; - set reported; + std::vector const& overloads = it.second; + std::set reported; for (size_t i = 0; i < overloads.size() && !reported.count(i); ++i) { SecondarySourceLocation ssl; @@ -228,15 +227,15 @@ void ContractLevelChecker::findDuplicateDefinitions(map> const if (ssl.infos.size() > 0) { ErrorId error; - string message; - if constexpr (is_same_v) + std::string message; + if constexpr (std::is_same_v) { error = 1686_error; message = "Function with same name and parameter types defined twice."; } else { - static_assert(is_same_v, "Expected \"FunctionDefinition const*\" or \"EventDefinition const*\""); + static_assert(std::is_same_v, "Expected \"FunctionDefinition const*\" or \"EventDefinition const*\""); error = 5883_error; message = "Event with same name and parameter types defined twice."; } @@ -258,7 +257,7 @@ void ContractLevelChecker::checkAbstractDefinitions(ContractDefinition const& _c { // Collects functions, static variable getters and modifiers. If they // override (unimplemented) base class ones, they are replaced. - set proxies; + std::set proxies; auto registerProxy = [&proxies](OverrideProxy const& _overrideProxy) { @@ -323,7 +322,7 @@ void ContractLevelChecker::checkAbstractDefinitions(ContractDefinition const& _c void ContractLevelChecker::checkBaseConstructorArguments(ContractDefinition const& _contract) { - vector const& bases = _contract.annotation().linearizedBaseContracts; + std::vector const& bases = _contract.annotation().linearizedBaseContracts; // Determine the arguments that are used for the base constructors. for (ContractDefinition const* contract: bases) @@ -430,7 +429,7 @@ void ContractLevelChecker::annotateBaseConstructorArguments( void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _contract) { - map>> externalDeclarations; + std::map>> externalDeclarations; for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts) { for (FunctionDefinition const* f: contract->definedFunctions()) @@ -467,7 +466,7 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contract) { - set> hashes; + std::set> hashes; for (auto const& it: _contract.interfaceFunctionList()) { util::FixedHash<4> const& hash = it.first; @@ -475,7 +474,7 @@ void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contra m_errorReporter.fatalTypeError( 1860_error, _contract.location(), - string("Function signature hash collision for ") + it.second->externalSignature() + std::string("Function signature hash collision for ") + it.second->externalSignature() ); hashes.insert(hash); } diff --git a/libsolidity/analysis/ControlFlowAnalyzer.cpp b/libsolidity/analysis/ControlFlowAnalyzer.cpp index e80964ace..7ae1aa76e 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.cpp +++ b/libsolidity/analysis/ControlFlowAnalyzer.cpp @@ -25,7 +25,6 @@ #include -using namespace std; using namespace std::placeholders; using namespace solidity::langutil; using namespace solidity::frontend; @@ -44,7 +43,7 @@ void ControlFlowAnalyzer::analyze(FunctionDefinition const& _function, ContractD if (!_function.isImplemented()) return; - optional mostDerivedContractName; + std::optional mostDerivedContractName; // The name of the most derived contract only required if it differs from // the functions contract @@ -61,13 +60,13 @@ void ControlFlowAnalyzer::analyze(FunctionDefinition const& _function, ContractD } -void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody, optional _contractName) +void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody, std::optional _contractName) { struct NodeInfo { - set unassignedVariablesAtEntry; - set unassignedVariablesAtExit; - set uninitializedVariableAccesses; + std::set unassignedVariablesAtEntry; + std::set unassignedVariablesAtExit; + std::set uninitializedVariableAccesses; /// Propagate the information from another node to this node. /// To be used to propagate information from a node to its exit nodes. /// Returns true, if new variables were added and thus the current node has @@ -84,8 +83,8 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod ; } }; - map nodeInfos; - set nodesToTraverse; + std::map nodeInfos; + std::set nodesToTraverse; nodesToTraverse.insert(_entry); // Walk all paths starting from the nodes in ``nodesToTraverse`` until ``NodeInfo::propagateFrom`` @@ -138,7 +137,7 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod auto const& exitInfo = nodeInfos[_exit]; if (!exitInfo.uninitializedVariableAccesses.empty()) { - vector uninitializedAccessesOrdered( + std::vector uninitializedAccessesOrdered( exitInfo.uninitializedVariableAccesses.begin(), exitInfo.uninitializedVariableAccesses.end() ); @@ -168,7 +167,7 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod varDecl.location(), ssl, "This variable is of " + - string(isStorage ? "storage" : "calldata") + + std::string(isStorage ? "storage" : "calldata") + " pointer type and can be " + (variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") + " without prior assignment, which would lead to undefined behaviour." diff --git a/libsolidity/analysis/ControlFlowBuilder.cpp b/libsolidity/analysis/ControlFlowBuilder.cpp index 1f2cfcac9..c20968a14 100644 --- a/libsolidity/analysis/ControlFlowBuilder.cpp +++ b/libsolidity/analysis/ControlFlowBuilder.cpp @@ -21,10 +21,8 @@ #include #include -using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; -using namespace std; ControlFlowBuilder::ControlFlowBuilder(CFG::NodeContainer& _nodeContainer, FunctionFlow const& _functionFlow, ContractDefinition const* _contract): m_nodeContainer(_nodeContainer), @@ -37,13 +35,13 @@ ControlFlowBuilder::ControlFlowBuilder(CFG::NodeContainer& _nodeContainer, Funct } -unique_ptr ControlFlowBuilder::createFunctionFlow( +std::unique_ptr ControlFlowBuilder::createFunctionFlow( CFG::NodeContainer& _nodeContainer, FunctionDefinition const& _function, ContractDefinition const* _contract ) { - auto functionFlow = make_unique(); + auto functionFlow = std::make_unique(); functionFlow->entry = _nodeContainer.newNode(); functionFlow->exit = _nodeContainer.newNode(); functionFlow->revert = _nodeContainer.newNode(); diff --git a/libsolidity/analysis/ControlFlowGraph.cpp b/libsolidity/analysis/ControlFlowGraph.cpp index 71acb8a67..518743ef1 100644 --- a/libsolidity/analysis/ControlFlowGraph.cpp +++ b/libsolidity/analysis/ControlFlowGraph.cpp @@ -20,7 +20,6 @@ #include -using namespace std; using namespace solidity::langutil; using namespace solidity::frontend; diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp index b6cd3eef0..df6e664ba 100644 --- a/libsolidity/analysis/DeclarationContainer.cpp +++ b/libsolidity/analysis/DeclarationContainer.cpp @@ -29,7 +29,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::frontend; @@ -41,7 +40,7 @@ Declaration const* DeclarationContainer::conflictingDeclaration( if (!_name) _name = &_declaration.name(); solAssert(!_name->empty(), ""); - vector declarations; + std::vector declarations; if (m_declarations.count(*_name)) declarations += m_declarations.at(*_name); if (m_invisibleDeclarations.count(*_name)) @@ -127,7 +126,7 @@ bool DeclarationContainer::registerDeclaration( m_homonymCandidates.emplace_back(*_name, _location ? _location : &_declaration.location()); } - vector& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name]; + std::vector& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name]; if (!util::contains(decls, &_declaration)) decls.push_back(&_declaration); return true; @@ -142,13 +141,13 @@ bool DeclarationContainer::registerDeclaration( return registerDeclaration(_declaration, nullptr, nullptr, _invisible, _update); } -vector DeclarationContainer::resolveName( +std::vector DeclarationContainer::resolveName( ASTString const& _name, ResolvingSettings _settings ) const { solAssert(!_name.empty(), "Attempt to resolve empty name."); - vector result; + std::vector result; if (m_declarations.count(_name)) { @@ -172,24 +171,24 @@ vector DeclarationContainer::resolveName( return result; } -vector DeclarationContainer::similarNames(ASTString const& _name) const +std::vector DeclarationContainer::similarNames(ASTString const& _name) const { // because the function below has quadratic runtime - it will not magically improve once a better algorithm is discovered ;) // since 80 is the suggested line length limit, we use 80^2 as length threshold static size_t const MAXIMUM_LENGTH_THRESHOLD = 80 * 80; - vector similar; + std::vector similar; size_t maximumEditDistance = _name.size() > 3 ? 2 : _name.size() / 2; for (auto const& declaration: m_declarations) { - string const& declarationName = declaration.first; + std::string const& declarationName = declaration.first; if (util::stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD)) similar.push_back(declarationName); } for (auto const& declaration: m_invisibleDeclarations) { - string const& declarationName = declaration.first; + std::string const& declarationName = declaration.first; if (util::stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD)) similar.push_back(declarationName); } @@ -200,7 +199,7 @@ vector DeclarationContainer::similarNames(ASTString const& _name) con return similar; } -void DeclarationContainer::populateHomonyms(back_insert_iterator _it) const +void DeclarationContainer::populateHomonyms(std::back_insert_iterator _it) const { for (DeclarationContainer const* innerContainer: m_innerContainers) innerContainer->populateHomonyms(_it); @@ -210,7 +209,7 @@ void DeclarationContainer::populateHomonyms(back_insert_iterator _it) ResolvingSettings settings; settings.recursive = true; settings.alsoInvisible = true; - vector const& declarations = m_enclosingContainer->resolveName(name, std::move(settings)); + std::vector const& declarations = m_enclosingContainer->resolveName(name, std::move(settings)); if (!declarations.empty()) _it = make_pair(location, declarations); } diff --git a/libsolidity/analysis/DeclarationTypeChecker.cpp b/libsolidity/analysis/DeclarationTypeChecker.cpp index f17c854a7..28c051c0a 100644 --- a/libsolidity/analysis/DeclarationTypeChecker.cpp +++ b/libsolidity/analysis/DeclarationTypeChecker.cpp @@ -29,7 +29,6 @@ #include -using namespace std; using namespace solidity::langutil; using namespace solidity::frontend; @@ -336,10 +335,10 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName) if (Expression const* length = _typeName.length()) { - optional lengthValue; + std::optional lengthValue; if (length->annotation().type && length->annotation().type->category() == Type::Category::RationalNumber) lengthValue = dynamic_cast(*length->annotation().type).value(); - else if (optional value = ConstantEvaluator::evaluate(m_errorReporter, *length)) + else if (std::optional value = ConstantEvaluator::evaluate(m_errorReporter, *length)) lengthValue = value->value; if (!lengthValue) @@ -399,10 +398,10 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) Location varLoc = _variable.referenceLocation(); DataLocation typeLoc = DataLocation::Memory; - set allowedDataLocations = _variable.allowedDataLocations(); + std::set allowedDataLocations = _variable.allowedDataLocations(); if (!allowedDataLocations.count(varLoc)) { - auto locationToString = [](VariableDeclaration::Location _location) -> string + auto locationToString = [](VariableDeclaration::Location _location) -> std::string { switch (_location) { @@ -414,7 +413,7 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) return {}; }; - string errorString; + std::string errorString; if (!_variable.hasReferenceOrMappingType()) errorString = "Data location can only be specified for array, struct or mapping types"; else @@ -430,9 +429,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) else if (_variable.isCallableOrCatchParameter()) errorString += " for " + - string(_variable.isReturnParameter() ? "return " : "") + + std::string(_variable.isReturnParameter() ? "return " : "") + "parameter in" + - string(_variable.isExternalCallableParameter() ? " external" : "") + + std::string(_variable.isExternalCallableParameter() ? " external" : "") + " function"; else errorString += " for variable"; diff --git a/libsolidity/analysis/DocStringAnalyser.cpp b/libsolidity/analysis/DocStringAnalyser.cpp index 5cff34f2a..d4afadf26 100644 --- a/libsolidity/analysis/DocStringAnalyser.cpp +++ b/libsolidity/analysis/DocStringAnalyser.cpp @@ -30,7 +30,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -38,7 +37,7 @@ using namespace solidity::frontend; namespace { -void copyMissingTags(set const& _baseFunctions, StructurallyDocumentedAnnotation& _target, FunctionType const* _functionType = nullptr) +void copyMissingTags(std::set const& _baseFunctions, StructurallyDocumentedAnnotation& _target, FunctionType const* _functionType = nullptr) { // Only copy if there is exactly one direct base function. if (_baseFunctions.size() != 1) @@ -50,7 +49,7 @@ void copyMissingTags(set const& _baseFunctions, Stru for (auto it = sourceDoc.docTags.begin(); it != sourceDoc.docTags.end();) { - string const& tag = it->first; + std::string const& tag = it->first; // Don't copy tag "inheritdoc", custom tags or already existing tags if (tag == "inheritdoc" || _target.docTags.count(tag) || boost::starts_with(tag, "custom")) { @@ -68,7 +67,7 @@ void copyMissingTags(set const& _baseFunctions, Stru if (_functionType && tag == "return") { size_t docParaNameEndPos = content.content.find_first_of(" \t"); - string const docParameterName = content.content.substr(0, docParaNameEndPos); + std::string const docParameterName = content.content.substr(0, docParaNameEndPos); if ( _functionType->returnParameterNames().size() > n && @@ -80,10 +79,10 @@ void copyMissingTags(set const& _baseFunctions, Stru baseFunction.returnParameters().size() > n && baseFunction.returnParameters().at(n)->name().empty(); - string paramName = _functionType->returnParameterNames().at(n); + std::string paramName = _functionType->returnParameterNames().at(n); content.content = (paramName.empty() ? "" : std::move(paramName) + " ") + ( - string::npos == docParaNameEndPos || baseHasNoName ? + std::string::npos == docParaNameEndPos || baseHasNoName ? content.content : content.content.substr(docParaNameEndPos + 1) ); @@ -95,7 +94,7 @@ void copyMissingTags(set const& _baseFunctions, Stru } } -CallableDeclaration const* findBaseCallable(set const& _baseFunctions, int64_t _contractId) +CallableDeclaration const* findBaseCallable(std::set const& _baseFunctions, int64_t _contractId) { for (CallableDeclaration const* baseFuncCandidate: _baseFunctions) if (baseFuncCandidate->annotation().contract->id() == _contractId) @@ -181,7 +180,7 @@ void DocStringAnalyser::handleCallable( } CallableDeclaration const* DocStringAnalyser::resolveInheritDoc( - set const& _baseFuncs, + std::set const& _baseFuncs, StructurallyDocumented const& _node, StructurallyDocumentedAnnotation& _annotation ) diff --git a/libsolidity/analysis/DocStringTagParser.cpp b/libsolidity/analysis/DocStringTagParser.cpp index 1dc2711ef..5d95f42e9 100644 --- a/libsolidity/analysis/DocStringTagParser.cpp +++ b/libsolidity/analysis/DocStringTagParser.cpp @@ -37,7 +37,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -67,7 +66,7 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU if (tagName == "return") { returnTagsVisited++; - vector returnParameterNames; + std::vector returnParameterNames; if (auto const* varDecl = dynamic_cast(&_node)) { @@ -82,8 +81,8 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU else continue; - string content = tagValue.content; - string firstWord = content.substr(0, content.find_first_of(" \t")); + std::string content = tagValue.content; + std::string firstWord = content.substr(0, content.find_first_of(" \t")); if (returnTagsVisited > returnParameterNames.size()) m_errorReporter.docstringParsingError( @@ -94,7 +93,7 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU ); else { - string const& parameter = returnParameterNames.at(returnTagsVisited - 1); + std::string const& parameter = returnParameterNames.at(returnTagsVisited - 1); if (!parameter.empty() && parameter != firstWord) m_errorReporter.docstringParsingError( 5856_error, @@ -113,7 +112,7 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU bool DocStringTagParser::visit(ContractDefinition const& _contract) { - static set const validTags = set{"author", "title", "dev", "notice"}; + static std::set const validTags = std::set{"author", "title", "dev", "notice"}; parseDocStrings(_contract, _contract.annotation(), validTags, "contracts"); return true; @@ -193,12 +192,12 @@ bool DocStringTagParser::visit(InlineAssembly const& _assembly) { if (tagName == "solidity") { - vector values; + std::vector values; boost::split(values, tagValue.content, isWhiteSpace); - set valuesSeen; - set duplicates; - for (auto const& value: values | ranges::views::filter(not_fn(&string::empty))) + std::set valuesSeen; + std::set duplicates; + for (auto const& value: values | ranges::views::filter(not_fn(&std::string::empty))) if (valuesSeen.insert(value).second) { if (value == "memory-safe-assembly") @@ -244,7 +243,7 @@ void DocStringTagParser::checkParameters( StructurallyDocumentedAnnotation& _annotation ) { - set validParams; + std::set validParams; for (auto const& p: _callable.parameters()) validParams.insert(p->name()); if (_callable.returnParameterList()) @@ -268,7 +267,7 @@ void DocStringTagParser::handleConstructor( StructurallyDocumentedAnnotation& _annotation ) { - static set const validTags = set{"author", "dev", "notice", "param"}; + static std::set const validTags = std::set{"author", "dev", "notice", "param"}; parseDocStrings(_node, _annotation, validTags, "constructor"); checkParameters(_callable, _node, _annotation); } @@ -279,10 +278,10 @@ void DocStringTagParser::handleCallable( StructurallyDocumentedAnnotation& _annotation ) { - static set const validEventTags = set{"dev", "notice", "return", "param"}; - static set const validErrorTags = set{"dev", "notice", "param"}; - static set const validModifierTags = set{"dev", "notice", "param", "inheritdoc"}; - static set const validTags = set{"dev", "notice", "return", "param", "inheritdoc"}; + static std::set const validEventTags = std::set{"dev", "notice", "return", "param"}; + static std::set const validErrorTags = std::set{"dev", "notice", "param"}; + static std::set const validModifierTags = std::set{"dev", "notice", "param", "inheritdoc"}; + static std::set const validTags = std::set{"dev", "notice", "return", "param", "inheritdoc"}; if (dynamic_cast(&_callable)) parseDocStrings(_node, _annotation, validEventTags, "events"); @@ -299,8 +298,8 @@ void DocStringTagParser::handleCallable( void DocStringTagParser::parseDocStrings( StructurallyDocumented const& _node, StructurallyDocumentedAnnotation& _annotation, - set const& _validTags, - string const& _nodeName + std::set const& _validTags, + std::string const& _nodeName ) { if (!_node.documentation()) @@ -310,7 +309,7 @@ void DocStringTagParser::parseDocStrings( for (auto const& [tagName, tagValue]: _annotation.docTags) { - string_view static constexpr customPrefix("custom:"); + std::string_view static constexpr customPrefix("custom:"); if (tagName == "custom" || tagName == "custom:") m_errorReporter.docstringParsingError( 6564_error, @@ -319,7 +318,7 @@ void DocStringTagParser::parseDocStrings( ); else if (boost::starts_with(tagName, customPrefix) && tagName.size() > customPrefix.size()) { - regex static const customRegex("^custom:[a-z][a-z-]*$"); + std::regex static const customRegex("^custom:[a-z][a-z-]*$"); if (!regex_match(tagName, customRegex)) m_errorReporter.docstringParsingError( 2968_error, diff --git a/libsolidity/analysis/FunctionCallGraph.cpp b/libsolidity/analysis/FunctionCallGraph.cpp index ce5c53934..1d01f1a6b 100644 --- a/libsolidity/analysis/FunctionCallGraph.cpp +++ b/libsolidity/analysis/FunctionCallGraph.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; using namespace solidity::frontend; using namespace solidity::util; @@ -72,7 +71,7 @@ CallGraph FunctionCallGraphBuilder::buildDeployedGraph( FunctionCallGraphBuilder builder(_contract); solAssert(builder.m_currentNode == CallGraph::Node(CallGraph::SpecialNode::Entry), ""); - auto getSecondElement = [](auto const& _tuple){ return get<1>(_tuple); }; + auto getSecondElement = [](auto const& _tuple){ return std::get<1>(_tuple); }; // Create graph for all publicly reachable functions for (FunctionTypePointer functionType: _contract.interfaceFunctionList() | ranges::views::transform(getSecondElement)) @@ -96,14 +95,14 @@ CallGraph FunctionCallGraphBuilder::buildDeployedGraph( // All functions present in internal dispatch at creation time could potentially be pointers // assigned to state variables and as such may be reachable after deployment as well. builder.m_currentNode = CallGraph::SpecialNode::InternalDispatch; - set defaultNode; + std::set defaultNode; for (CallGraph::Node const& dispatchTarget: util::valueOrDefault(_creationGraph.edges, CallGraph::SpecialNode::InternalDispatch, defaultNode)) { - solAssert(!holds_alternative(dispatchTarget), ""); - solAssert(get(dispatchTarget) != nullptr, ""); + solAssert(!std::holds_alternative(dispatchTarget), ""); + solAssert(std::get(dispatchTarget) != nullptr, ""); // Visit the callable to add not only it but also everything it calls too - builder.functionReferenced(*get(dispatchTarget), false); + builder.functionReferenced(*std::get(dispatchTarget), false); } builder.m_currentNode = CallGraph::SpecialNode::Entry; @@ -262,10 +261,10 @@ void FunctionCallGraphBuilder::processQueue() while (!m_visitQueue.empty()) { m_currentNode = m_visitQueue.front(); - solAssert(holds_alternative(m_currentNode), ""); + solAssert(std::holds_alternative(m_currentNode), ""); m_visitQueue.pop_front(); - get(m_currentNode)->accept(*this); + std::get(m_currentNode)->accept(*this); } m_currentNode = CallGraph::SpecialNode::Entry; @@ -281,7 +280,7 @@ void FunctionCallGraphBuilder::functionReferenced(CallableDeclaration const& _ca if (_calledDirectly) { solAssert( - holds_alternative(m_currentNode) || m_graph.edges.count(m_currentNode) > 0, + std::holds_alternative(m_currentNode) || m_graph.edges.count(m_currentNode) > 0, "Adding an edge from a node that has not been visited yet." ); @@ -293,10 +292,10 @@ void FunctionCallGraphBuilder::functionReferenced(CallableDeclaration const& _ca enqueueCallable(_callable); } -ostream& solidity::frontend::operator<<(ostream& _out, CallGraph::Node const& _node) +std::ostream& solidity::frontend::operator<<(std::ostream& _out, CallGraph::Node const& _node) { - if (holds_alternative(_node)) - switch (get(_node)) + if (std::holds_alternative(_node)) + switch (std::get(_node)) { case CallGraph::SpecialNode::InternalDispatch: _out << "InternalDispatch"; @@ -309,19 +308,19 @@ ostream& solidity::frontend::operator<<(ostream& _out, CallGraph::Node const& _n } else { - solAssert(holds_alternative(_node), ""); + solAssert(std::holds_alternative(_node), ""); - auto const* callableDeclaration = get(_node); + auto const* callableDeclaration = std::get(_node); solAssert(callableDeclaration, ""); auto const* function = dynamic_cast(callableDeclaration); auto const* event = dynamic_cast(callableDeclaration); auto const* modifier = dynamic_cast(callableDeclaration); - auto typeToString = [](auto const& _var) -> string { return _var->type()->toString(true); }; - vector parameters = callableDeclaration->parameters() | ranges::views::transform(typeToString) | ranges::to>(); + auto typeToString = [](auto const& _var) -> std::string { return _var->type()->toString(true); }; + std::vector parameters = callableDeclaration->parameters() | ranges::views::transform(typeToString) | ranges::to>(); - string scopeName; + std::string scopeName; if (!function || !function->isFree()) { solAssert(callableDeclaration->annotation().scope, ""); diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index 58ebea7b1..8f0ce9634 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -29,8 +29,6 @@ #include #include -using namespace std; - namespace solidity::frontend { @@ -65,10 +63,10 @@ int magicVariableToID(std::string const& _name) solAssert(false, "Unknown magic variable: \"" + _name + "\"."); } -inline vector> constructMagicVariables() +inline std::vector> constructMagicVariables() { - static auto const magicVarDecl = [](string const& _name, Type const* _type) { - return make_shared(magicVariableToID(_name), _name, _type); + static auto const magicVarDecl = [](std::string const& _name, Type const* _type) { + return std::make_shared(magicVariableToID(_name), _name, _type); }; return { @@ -116,9 +114,9 @@ void GlobalContext::setCurrentContract(ContractDefinition const& _contract) m_currentContract = &_contract; } -vector GlobalContext::declarations() const +std::vector GlobalContext::declarations() const { - vector declarations; + std::vector declarations; declarations.reserve(m_magicVariables.size()); for (ASTPointer const& variable: m_magicVariables) declarations.push_back(variable.get()); @@ -133,7 +131,7 @@ MagicVariableDeclaration const* GlobalContext::currentThis() const if (m_currentContract) type = TypeProvider::contract(*m_currentContract); m_thisPointer[m_currentContract] = - make_shared(magicVariableToID("this"), "this", type); + std::make_shared(magicVariableToID("this"), "this", type); } return m_thisPointer[m_currentContract].get(); } @@ -146,7 +144,7 @@ MagicVariableDeclaration const* GlobalContext::currentSuper() const if (m_currentContract) type = TypeProvider::typeType(TypeProvider::contract(*m_currentContract, true)); m_superPointer[m_currentContract] = - make_shared(magicVariableToID("super"), "super", type); + std::make_shared(magicVariableToID("super"), "super", type); } return m_superPointer[m_currentContract].get(); } diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 641f02280..d6ff63dbf 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -30,7 +30,6 @@ #include #include -using namespace std; using namespace solidity::langutil; namespace solidity::frontend @@ -45,7 +44,7 @@ NameAndTypeResolver::NameAndTypeResolver( m_errorReporter(_errorReporter), m_globalContext(_globalContext) { - m_scopes[nullptr] = make_shared(); + m_scopes[nullptr] = std::make_shared(); for (Declaration const* declaration: _globalContext.declarations()) { solAssert(m_scopes[nullptr]->registerDeclaration(*declaration, false, false), "Unable to register global declaration."); @@ -68,14 +67,14 @@ bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode return true; } -bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map const& _sourceUnits) +bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, std::map const& _sourceUnits) { DeclarationContainer& target = *m_scopes.at(&_sourceUnit); bool error = false; for (auto const& node: _sourceUnit.nodes()) if (auto imp = dynamic_cast(node.get())) { - string const& path = *imp->annotation().absolutePath; + std::string const& path = *imp->annotation().absolutePath; // The import resolution in CompilerStack enforces this. solAssert(_sourceUnits.count(path), ""); auto scope = m_scopes.find(_sourceUnits.at(path)); @@ -127,7 +126,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(SourceUnit& _source) { try { - for (shared_ptr const& node: _source.nodes()) + for (std::shared_ptr const& node: _source.nodes()) { setScope(&_source); if (!resolveNamesAndTypesInternal(*node, true)) @@ -159,7 +158,7 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) return true; } -void NameAndTypeResolver::activateVariable(string const& _name) +void NameAndTypeResolver::activateVariable(std::string const& _name) { solAssert(m_currentScope, ""); // Scoped local variables are invisible before activation. @@ -171,15 +170,15 @@ void NameAndTypeResolver::activateVariable(string const& _name) m_currentScope->activateVariable(_name); } -vector NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const +std::vector NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const { auto iterator = m_scopes.find(_scope); if (iterator == end(m_scopes)) - return vector({}); + return std::vector({}); return iterator->second->resolveName(_name); } -vector NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _includeInvisibles) const +std::vector NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _includeInvisibles) const { ResolvingSettings settings; settings.recursive = true; @@ -187,7 +186,7 @@ vector NameAndTypeResolver::nameFromCurrentScope(ASTString c return m_currentScope->resolveName(_name, std::move(settings)); } -Declaration const* NameAndTypeResolver::pathFromCurrentScope(vector const& _path) const +Declaration const* NameAndTypeResolver::pathFromCurrentScope(std::vector const& _path) const { if (auto declarations = pathFromCurrentScopeWithAllDeclarations(_path); !declarations.empty()) return declarations.back(); @@ -201,13 +200,13 @@ std::vector NameAndTypeResolver::pathFromCurrentScopeWithAll ) const { solAssert(!_path.empty(), ""); - vector pathDeclarations; + std::vector pathDeclarations; ResolvingSettings settings; settings.recursive = true; settings.alsoInvisible = _includeInvisibles; settings.onlyVisibleAsUnqualifiedNames = true; - vector candidates = m_currentScope->resolveName(_path.front(), settings); + std::vector candidates = m_currentScope->resolveName(_path.front(), settings); // inside the loop, use default settings, except for alsoInvisible settings.recursive = false; @@ -305,7 +304,7 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res if (success) { linearizeBaseContracts(*contract); - vector properBases( + std::vector properBases( ++contract->annotation().linearizedBaseContracts.begin(), contract->annotation().linearizedBaseContracts.end() ); @@ -405,7 +404,7 @@ void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract) { // order in the lists is from derived to base // list of lists to linearize, the last element is the list of direct bases - list> input(1, list{}); + std::list> input(1, std::list{}); for (ASTPointer const& baseSpecifier: _contract.baseContracts()) { IdentifierPath const& baseName = baseSpecifier->name(); @@ -415,25 +414,25 @@ void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract) // "push_front" has the effect that bases mentioned later can overwrite members of bases // mentioned earlier input.back().push_front(base); - vector const& basesBases = base->annotation().linearizedBaseContracts; + std::vector const& basesBases = base->annotation().linearizedBaseContracts; if (basesBases.empty()) m_errorReporter.fatalTypeError(2449_error, baseName.location(), "Definition of base has to precede definition of derived contract"); - input.push_front(list(basesBases.begin(), basesBases.end())); + input.push_front(std::list(basesBases.begin(), basesBases.end())); } input.back().push_front(&_contract); - vector result = cThreeMerge(input); + std::vector result = cThreeMerge(input); if (result.empty()) m_errorReporter.fatalTypeError(5005_error, _contract.location(), "Linearization of inheritance graph impossible"); _contract.annotation().linearizedBaseContracts = result; } template -vector NameAndTypeResolver::cThreeMerge(list>& _toMerge) +std::vector NameAndTypeResolver::cThreeMerge(std::list>& _toMerge) { // returns true iff _candidate appears only as last element of the lists auto appearsOnlyAtHead = [&](T const* _candidate) -> bool { - for (list const& bases: _toMerge) + for (std::list const& bases: _toMerge) { solAssert(!bases.empty(), ""); if (find(++bases.begin(), bases.end(), _candidate) != bases.end()) @@ -444,7 +443,7 @@ vector NameAndTypeResolver::cThreeMerge(list>& _toMerge // returns the next candidate to append to the linearized list or nullptr on failure auto nextCandidate = [&]() -> T const* { - for (list const& bases: _toMerge) + for (std::list const& bases: _toMerge) { solAssert(!bases.empty(), ""); if (appearsOnlyAtHead(bases.front())) @@ -465,26 +464,26 @@ vector NameAndTypeResolver::cThreeMerge(list>& _toMerge } }; - _toMerge.remove_if([](list const& _bases) { return _bases.empty(); }); - vector result; + _toMerge.remove_if([](std::list const& _bases) { return _bases.empty(); }); + std::vector result; while (!_toMerge.empty()) { T const* candidate = nextCandidate(); if (!candidate) - return vector(); + return std::vector(); result.push_back(candidate); removeCandidate(candidate); } return result; } -string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const + std::string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const { return util::quotedAlternativesList(m_currentScope->similarNames(_name)); } DeclarationRegistrationHelper::DeclarationRegistrationHelper( - map>& _scopes, + std::map>& _scopes, ASTNode& _astRoot, ErrorReporter& _errorReporter, GlobalContext& _globalContext, @@ -502,7 +501,7 @@ DeclarationRegistrationHelper::DeclarationRegistrationHelper( bool DeclarationRegistrationHelper::registerDeclaration( DeclarationContainer& _container, Declaration const& _declaration, - string const* _name, + std::string const* _name, SourceLocation const* _errorLocation, bool _inactive, ErrorReporter& _errorReporter @@ -511,13 +510,13 @@ bool DeclarationRegistrationHelper::registerDeclaration( if (!_errorLocation) _errorLocation = &_declaration.location(); - string name = _name ? *_name : _declaration.name(); + std::string name = _name ? *_name : _declaration.name(); // We use "invisible" for both inactive variables in blocks and for members invisible in contracts. // They cannot both be true at the same time. solAssert(!(_inactive && !_declaration.isVisibleInContract()), ""); - static set illegalNames{"_", "super", "this"}; + static std::set illegalNames{"_", "super", "this"}; if (illegalNames.count(name)) { @@ -580,7 +579,7 @@ bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit) { if (!m_scopes[&_sourceUnit]) // By importing, it is possible that the container already exists. - m_scopes[&_sourceUnit] = make_shared(m_currentScope, m_scopes[m_currentScope].get()); + m_scopes[&_sourceUnit] = std::make_shared(m_currentScope, m_scopes[m_currentScope].get()); return ASTVisitor::visit(_sourceUnit); } @@ -594,7 +593,7 @@ bool DeclarationRegistrationHelper::visit(ImportDirective& _import) SourceUnit const* importee = _import.annotation().sourceUnit; solAssert(!!importee, ""); if (!m_scopes[importee]) - m_scopes[importee] = make_shared(nullptr, m_scopes[nullptr].get()); + m_scopes[importee] = std::make_shared(nullptr, m_scopes[nullptr].get()); m_scopes[&_import] = m_scopes[importee]; ASTVisitor::visit(_import); return false; // Do not recurse into child nodes (Identifier for symbolAliases) @@ -641,7 +640,7 @@ bool DeclarationRegistrationHelper::visitNode(ASTNode& _node) if (auto* annotation = dynamic_cast(&_node.annotation())) { - string canonicalName = dynamic_cast(_node).name(); + std::string canonicalName = dynamic_cast(_node).name(); solAssert(!canonicalName.empty(), ""); for ( @@ -684,7 +683,7 @@ void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope) { bool newlyAdded = m_scopes.emplace( &_subScope, - make_shared(m_currentScope, m_scopes[m_currentScope].get()) + std::make_shared(m_currentScope, m_scopes[m_currentScope].get()) ).second; solAssert(newlyAdded, "Unable to add new scope."); } diff --git a/libsolidity/analysis/OverrideChecker.cpp b/libsolidity/analysis/OverrideChecker.cpp index d342ab100..f2a99340d 100644 --- a/libsolidity/analysis/OverrideChecker.cpp +++ b/libsolidity/analysis/OverrideChecker.cpp @@ -31,7 +31,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend; using namespace solidity::langutil; @@ -46,7 +45,7 @@ namespace // Helper struct to do a search by name struct MatchByName { - string const& m_name; + std::string const& m_name; bool operator()(OverrideProxy const& _item) { return _item.name() == m_name; @@ -61,7 +60,7 @@ struct MatchByName */ struct OverrideGraph { - OverrideGraph(set const& _baseCallables) + OverrideGraph(std::set const& _baseCallables) { for (auto const& baseFunction: _baseCallables) addEdge(0, visit(baseFunction)); @@ -131,17 +130,17 @@ private: run(vInd, _depth + 1); if (m_low[vInd] >= m_depths[_u] && m_parent[_u] != -1) m_cutVertices.insert(m_graph.nodeInv.at(static_cast(_u))); - m_low[_u] = min(m_low[_u], m_low[vInd]); + m_low[_u] = std::min(m_low[_u], m_low[vInd]); } else if (v != m_parent[_u]) - m_low[_u] = min(m_low[_u], m_depths[vInd]); + m_low[_u] = std::min(m_low[_u], m_depths[vInd]); } } }; -vector resolveDirectBaseContracts(ContractDefinition const& _contract) +std::vector resolveDirectBaseContracts(ContractDefinition const& _contract) { - vector resolvedContracts; + std::vector resolvedContracts; for (ASTPointer const& specifier: _contract.baseContracts()) { @@ -155,7 +154,7 @@ vector resolveDirectBaseContracts(ContractDefinition return resolvedContracts; } -vector> sortByContract(vector> const& _list) +std::vector> sortByContract(std::vector> const& _list) { auto sorted = _list; @@ -197,17 +196,17 @@ bool OverrideProxy::operator<(OverrideProxy const& _other) const bool OverrideProxy::isVariable() const { - return holds_alternative(m_item); + return std::holds_alternative(m_item); } bool OverrideProxy::isFunction() const { - return holds_alternative(m_item); + return std::holds_alternative(m_item); } bool OverrideProxy::isModifier() const { - return holds_alternative(m_item); + return std::holds_alternative(m_item); } bool OverrideProxy::CompareBySignature::operator()(OverrideProxy const& _a, OverrideProxy const& _b) const @@ -222,18 +221,18 @@ size_t OverrideProxy::id() const }, m_item); } -shared_ptr OverrideProxy::overrides() const +std::shared_ptr OverrideProxy::overrides() const { return std::visit(GenericVisitor{ [&](auto const* _item) { return _item->overrides(); } }, m_item); } -set OverrideProxy::baseFunctions() const +std::set OverrideProxy::baseFunctions() const { return std::visit(GenericVisitor{ - [&](auto const* _item) -> set { - set ret; + [&](auto const* _item) -> std::set { + std::set ret; for (auto const* f: _item->annotation().baseFunctions) ret.insert(makeOverrideProxy(*f)); return ret; @@ -256,10 +255,10 @@ void OverrideProxy::storeBaseFunction(OverrideProxy const& _base) const }, m_item); } -string const& OverrideProxy::name() const +std::string const& OverrideProxy::name() const { return std::visit(GenericVisitor{ - [&](auto const* _item) -> string const& { return _item->name(); } + [&](auto const* _item) -> std::string const& { return _item->name(); } }, m_item); } @@ -272,7 +271,7 @@ ContractDefinition const& OverrideProxy::contract() const }, m_item); } -string const& OverrideProxy::contractName() const +std::string const& OverrideProxy::contractName() const { return contract().name(); } @@ -357,7 +356,7 @@ SourceLocation const& OverrideProxy::location() const }, m_item); } -string OverrideProxy::astNodeName() const +std::string OverrideProxy::astNodeName() const { return std::visit(GenericVisitor{ [&](FunctionDefinition const*) { return "function"; }, @@ -366,7 +365,7 @@ string OverrideProxy::astNodeName() const }, m_item); } -string OverrideProxy::astNodeNameCapitalized() const +std::string OverrideProxy::astNodeNameCapitalized() const { return std::visit(GenericVisitor{ [&](FunctionDefinition const*) { return "Function"; }, @@ -375,7 +374,7 @@ string OverrideProxy::astNodeNameCapitalized() const }, m_item); } -string OverrideProxy::distinguishingProperty() const +std::string OverrideProxy::distinguishingProperty() const { return std::visit(GenericVisitor{ [&](FunctionDefinition const*) { return "name and parameter types"; }, @@ -418,10 +417,10 @@ OverrideProxy::OverrideComparator const& OverrideProxy::overrideComparator() con { if (!m_comparator) { - m_comparator = make_shared(std::visit(GenericVisitor{ + m_comparator = std::make_shared(std::visit(GenericVisitor{ [&](FunctionDefinition const* _function) { - vector paramTypes; + std::vector paramTypes; for (Type const* t: externalFunctionType()->parameterTypes()) paramTypes.emplace_back(t->richIdentifier()); return OverrideComparator{ @@ -432,7 +431,7 @@ OverrideProxy::OverrideComparator const& OverrideProxy::overrideComparator() con }, [&](VariableDeclaration const* _var) { - vector paramTypes; + std::vector paramTypes; for (Type const* t: externalFunctionType()->parameterTypes()) paramTypes.emplace_back(t->richIdentifier()); return OverrideComparator{ @@ -674,21 +673,21 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr void OverrideChecker::overrideListError( OverrideProxy const& _item, - set _secondary, + std::set _secondary, ErrorId _error, - string const& _message1, - string const& _message2 + std::string const& _message1, + std::string const& _message2 ) { // Using a set rather than a vector so the order is always the same - set names; + std::set names; SecondarySourceLocation ssl; for (Declaration const* c: _secondary) { ssl.append("This contract: ", c->location()); names.insert("\"" + c->name() + "\""); } - string contractSingularPlural = "contract "; + std::string contractSingularPlural = "contract "; if (_secondary.size() > 1) contractSingularPlural = "contracts "; @@ -708,8 +707,8 @@ void OverrideChecker::overrideError( OverrideProxy const& _overriding, OverrideProxy const& _super, ErrorId _error, - string const& _message, - optional const& _secondaryMsg + std::string const& _message, + std::optional const& _secondaryMsg ) { m_errorReporter.typeError( @@ -766,7 +765,7 @@ void OverrideChecker::checkAmbiguousOverrides(ContractDefinition const& _contrac } } -void OverrideChecker::checkAmbiguousOverridesInternal(set _baseCallables, SourceLocation const& _location) const +void OverrideChecker::checkAmbiguousOverridesInternal(std::set _baseCallables, SourceLocation const& _location) const { if (_baseCallables.size() <= 1) return; @@ -799,17 +798,17 @@ void OverrideChecker::checkAmbiguousOverridesInternal(set _baseCa for (OverrideProxy const& baseFunction: _baseCallables) ssl.append("Definition in \"" + baseFunction.contractName() + "\": ", baseFunction.location()); - string callableName = _baseCallables.begin()->astNodeName(); + std::string callableName = _baseCallables.begin()->astNodeName(); if (_baseCallables.begin()->isVariable()) callableName = "function"; - string distinguishigProperty = _baseCallables.begin()->distinguishingProperty(); + std::string distinguishigProperty = _baseCallables.begin()->distinguishingProperty(); bool foundVariable = false; for (auto const& base: _baseCallables) if (base.isVariable()) foundVariable = true; - string message = + std::string message = "Derived contract must override " + callableName + " \"" + _baseCallables.begin()->name() + "\". Two or more base classes define " + callableName + " with same " + distinguishigProperty + "."; @@ -822,9 +821,9 @@ void OverrideChecker::checkAmbiguousOverridesInternal(set _baseCa m_errorReporter.typeError(6480_error, _location, ssl, message); } -set OverrideChecker::resolveOverrideList(OverrideSpecifier const& _overrides) const +std::set OverrideChecker::resolveOverrideList(OverrideSpecifier const& _overrides) const { - set resolved; + std::set resolved; for (ASTPointer const& override: _overrides.overrides()) { @@ -842,7 +841,7 @@ set OverrideChecker::re void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySignatureMultiSet const& _inherited) { - set specifiedContracts = + std::set specifiedContracts = _item.overrides() ? resolveOverrideList(*_item.overrides()) : decltype(specifiedContracts){}; @@ -851,7 +850,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign if (_item.overrides() && specifiedContracts.size() != _item.overrides()->overrides().size()) { // Sort by contract id to find duplicate for error reporting - vector> list = + std::vector> list = sortByContract(_item.overrides()->overrides()); // Find duplicates and output error @@ -880,7 +879,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign } } - set expectedContracts; + std::set expectedContracts; // Build list of expected contracts for (auto [begin, end] = _inherited.equal_range(_item); begin != end; begin++) @@ -898,7 +897,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign _item.astNodeNameCapitalized() + " has override specified but does not override anything." ); - set missingContracts; + std::set missingContracts; // If we expect only one contract, no contract needs to be specified if (expectedContracts.size() > 1) missingContracts = expectedContracts - specifiedContracts; @@ -931,7 +930,7 @@ OverrideChecker::OverrideProxyBySignatureMultiSet const& OverrideChecker::inheri for (auto const* base: resolveDirectBaseContracts(_contract)) { - set functionsInBase; + std::set functionsInBase; for (FunctionDefinition const* fun: base->definedFunctions()) if (!fun->isConstructor()) functionsInBase.emplace(OverrideProxy{fun}); @@ -960,7 +959,7 @@ OverrideChecker::OverrideProxyBySignatureMultiSet const& OverrideChecker::inheri for (auto const* base: resolveDirectBaseContracts(_contract)) { - set modifiersInBase; + std::set modifiersInBase; for (ModifierDefinition const* mod: base->functionModifiers()) modifiersInBase.emplace(OverrideProxy{mod}); diff --git a/libsolidity/analysis/PostTypeChecker.cpp b/libsolidity/analysis/PostTypeChecker.cpp index c8b3b5f16..bc9df3dc4 100644 --- a/libsolidity/analysis/PostTypeChecker.cpp +++ b/libsolidity/analysis/PostTypeChecker.cpp @@ -27,7 +27,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -204,7 +203,7 @@ struct ConstStateVarCircularReferenceChecker: public PostTypeChecker::Checker // Iterating through the dependencies needs to be deterministic and thus cannot // depend on the memory layout. // Because of that, we sort by AST node id. - vector dependencies( + std::vector dependencies( m_constVariableDependencies[&_variable].begin(), m_constVariableDependencies[&_variable].end() ); @@ -427,10 +426,10 @@ struct ReservedErrorSelector: public PostTypeChecker::Checker PostTypeChecker::PostTypeChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) { - m_checkers.push_back(make_shared(_errorReporter)); - m_checkers.push_back(make_shared(_errorReporter)); - m_checkers.push_back(make_shared(_errorReporter)); - m_checkers.push_back(make_shared(_errorReporter)); - m_checkers.push_back(make_shared(_errorReporter)); - m_checkers.push_back(make_shared(_errorReporter)); + m_checkers.push_back(std::make_shared(_errorReporter)); + m_checkers.push_back(std::make_shared(_errorReporter)); + m_checkers.push_back(std::make_shared(_errorReporter)); + m_checkers.push_back(std::make_shared(_errorReporter)); + m_checkers.push_back(std::make_shared(_errorReporter)); + m_checkers.push_back(std::make_shared(_errorReporter)); } diff --git a/libsolidity/analysis/PostTypeContractLevelChecker.cpp b/libsolidity/analysis/PostTypeContractLevelChecker.cpp index 67d0623aa..6d8dc416a 100644 --- a/libsolidity/analysis/PostTypeContractLevelChecker.cpp +++ b/libsolidity/analysis/PostTypeContractLevelChecker.cpp @@ -26,7 +26,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -48,10 +47,10 @@ bool PostTypeContractLevelChecker::check(ContractDefinition const& _contract) "" ); - map> errorHashes; + std::map> errorHashes; for (ErrorDefinition const* error: _contract.interfaceErrors()) { - string signature = error->functionType(true)->externalSignature(); + std::string signature = error->functionType(true)->externalSignature(); uint32_t hash = util::selectorFromSignatureU32(signature); // Fail if there is a different signature for the same hash. if (!errorHashes[hash].empty() && !errorHashes[hash].count(signature)) diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 399c15b56..e68002133 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -39,7 +39,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -121,8 +120,8 @@ bool ReferencesResolver::visit(Identifier const& _identifier) auto declarations = m_resolver.nameFromCurrentScope(_identifier.name()); if (declarations.empty()) { - string suggestions = m_resolver.similarNameSuggestions(_identifier.name()); - string errorMessage = "Undeclared identifier."; + std::string suggestions = m_resolver.similarNameSuggestions(_identifier.name()); + std::string errorMessage = "Undeclared identifier."; if (!suggestions.empty()) { if ("\"" + _identifier.name() + "\"" == suggestions) @@ -192,10 +191,10 @@ bool ReferencesResolver::visit(UsingForDirective const& _usingFor) // _includeInvisibles is enabled here because external library functions are marked invisible. // As unintended side-effects other invisible names (eg.: super, this) may be returned as well. // DeclarationTypeChecker should detect and report such situations. - vector declarations = m_resolver.pathFromCurrentScopeWithAllDeclarations(path->path(), true /* _includeInvisibles */); + std::vector declarations = m_resolver.pathFromCurrentScopeWithAllDeclarations(path->path(), true /* _includeInvisibles */); if (declarations.empty()) { - string libraryOrFunctionNameErrorMessage = + std::string libraryOrFunctionNameErrorMessage = _usingFor.usesBraces() ? "Identifier is not a function name or not unique." : "Identifier is not a library name."; @@ -253,9 +252,9 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier) { solAssert(nativeLocationOf(_identifier) == originLocationOf(_identifier), ""); - static set suffixes{"slot", "offset", "length", "address", "selector"}; - string suffix; - for (string const& s: suffixes) + static std::set suffixes{"slot", "offset", "length", "address", "selector"}; + std::string suffix; + for (std::string const& s: suffixes) if (boost::algorithm::ends_with(_identifier.name.str(), "." + s)) suffix = s; @@ -269,7 +268,7 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier) if (!declarations.empty()) // the special identifier exists itself, we should not allow that. return; - string realName = _identifier.name.str().substr(0, _identifier.name.str().size() - suffix.size() - 1); + std::string realName = _identifier.name.str().substr(0, _identifier.name.str().size() - suffix.size() - 1); solAssert(!realName.empty(), "Empty name."); declarations = m_resolver.nameFromCurrentScope(realName); if (!declarations.empty()) @@ -350,7 +349,7 @@ void ReferencesResolver::resolveInheritDoc(StructuredDocumentation const& _docum break; case 1: { - string const& name = _annotation.docTags.find("inheritdoc")->second.content; + std::string const& name = _annotation.docTags.find("inheritdoc")->second.content; if (name.empty()) { m_errorReporter.docstringParsingError( @@ -361,7 +360,7 @@ void ReferencesResolver::resolveInheritDoc(StructuredDocumentation const& _docum return; } - vector path; + std::vector path; boost::split(path, name, boost::is_any_of(".")); if (any_of(path.begin(), path.end(), [](auto& _str) { return _str.empty(); })) { @@ -421,7 +420,7 @@ void ReferencesResolver::validateYulIdentifierName(yul::YulString _name, SourceL "User-defined identifiers in inline assembly cannot contain '.'." ); - if (set{"this", "super", "_"}.count(_name.str())) + if (std::set{"this", "super", "_"}.count(_name.str())) m_errorReporter.declarationError( 4113_error, _location, diff --git a/libsolidity/analysis/Scoper.cpp b/libsolidity/analysis/Scoper.cpp index 98716cf0f..a14ca4559 100644 --- a/libsolidity/analysis/Scoper.cpp +++ b/libsolidity/analysis/Scoper.cpp @@ -20,7 +20,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::frontend; diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 01ca601f1..10c2c922c 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -28,7 +28,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -71,7 +70,7 @@ private: return m_usesAssembly[&_contract]; } - map m_usesAssembly; + std::map m_usesAssembly; }; StaticAnalyzer::StaticAnalyzer(ErrorReporter& _errorReporter): @@ -124,7 +123,7 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&) 5667_error, var.first.second->location(), "Unused " + - string(var.first.second->isTryCatchParameter() ? "try/catch" : "function") + + std::string(var.first.second->isTryCatchParameter() ? "try/catch" : "function") + " parameter. Remove or comment out the variable name to silence this warning." ); else @@ -142,7 +141,7 @@ bool StaticAnalyzer::visit(Identifier const& _identifier) { solAssert(!var->name().empty(), ""); if (var->isLocalVariable()) - m_localVarUseCount[make_pair(var->id(), var)] += 1; + m_localVarUseCount[std::make_pair(var->id(), var)] += 1; } return true; } @@ -154,7 +153,7 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable) solAssert(_variable.isLocalVariable(), ""); if (_variable.name() != "") // This is not a no-op, the entry might pre-exist. - m_localVarUseCount[make_pair(_variable.id(), &_variable)] += 0; + m_localVarUseCount[std::make_pair(_variable.id(), &_variable)] += 0; } if (_variable.isStateVariable() || _variable.referenceLocation() == VariableDeclaration::Location::Storage) @@ -162,7 +161,7 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable) for (Type const* type: varType->fullDecomposition()) if (type->storageSizeUpperBound() >= (bigint(1) << 64)) { - string message = "Type " + type->toString(true) + + std::string message = "Type " + type->toString(true) + " covers a large part of storage and thus makes collisions likely." " Either use mappings or dynamic arrays and allow their size to be increased only" " in small quantities per transaction."; @@ -179,7 +178,7 @@ bool StaticAnalyzer::visit(Return const& _return) if (m_currentFunction && _return.expression()) for (auto const& var: m_currentFunction->returnParameters()) if (!var->name().empty()) - m_localVarUseCount[make_pair(var->id(), var.get())] += 1; + m_localVarUseCount[std::make_pair(var->id(), var.get())] += 1; return true; } @@ -214,7 +213,7 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess) else if (type->kind() == MagicType::Kind::MetaType && _memberAccess.memberName() == "runtimeCode") { if (!m_constructorUsesAssembly) - m_constructorUsesAssembly = make_unique(); + m_constructorUsesAssembly = std::make_unique(); ContractType const& contract = dynamic_cast(*type->typeArgument()); if (m_constructorUsesAssembly->check(contract.contractDefinition())) m_errorReporter.warning( @@ -288,7 +287,7 @@ bool StaticAnalyzer::visit(InlineAssembly const& _inlineAssembly) { solAssert(!var->name().empty(), ""); if (var->isLocalVariable()) - m_localVarUseCount[make_pair(var->id(), var)] += 1; + m_localVarUseCount[std::make_pair(var->id(), var)] += 1; } } diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 4f99f67ac..2546cfdda 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -32,7 +32,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -55,17 +54,17 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit) { if (!m_versionPragmaFound) { - string errorString("Source file does not specify required compiler version!"); - SemVerVersion recommendedVersion{string(VersionString)}; + std::string errorString("Source file does not specify required compiler version!"); + SemVerVersion recommendedVersion{std::string(VersionString)}; if (!recommendedVersion.isPrerelease()) errorString += " Consider adding \"pragma solidity ^" + - to_string(recommendedVersion.major()) + - string(".") + - to_string(recommendedVersion.minor()) + - string(".") + - to_string(recommendedVersion.patch()) + - string(";\""); + std::to_string(recommendedVersion.major()) + + std::string(".") + + std::to_string(recommendedVersion.minor()) + + std::string(".") + + std::to_string(recommendedVersion.patch()) + + std::string(";\""); // when reporting the warning, print the source name only m_errorReporter.warning(3420_error, {-1, -1, _sourceUnit.location().sourceName}, errorString); @@ -84,7 +83,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) else if (_pragma.literals()[0] == "experimental") { solAssert(m_sourceUnit, ""); - vector literals(_pragma.literals().begin() + 1, _pragma.literals().end()); + std::vector literals(_pragma.literals().begin() + 1, _pragma.literals().end()); if (literals.empty()) m_errorReporter.syntaxError( 9679_error, @@ -99,7 +98,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) ); else { - string const literal = literals[0]; + std::string const literal = literals[0]; if (literal.empty()) m_errorReporter.syntaxError(3250_error, _pragma.location(), "Empty experimental feature name is invalid."); else if (!ExperimentalFeatureNames.count(literal)) @@ -135,7 +134,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) solAssert(m_sourceUnit, ""); if ( _pragma.literals().size() != 2 || - !set{"v1", "v2"}.count(_pragma.literals()[1]) + !std::set{"v1", "v2"}.count(_pragma.literals()[1]) ) m_errorReporter.syntaxError( 2745_error, @@ -155,17 +154,17 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) { try { - vector tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end()); - vector literals(_pragma.literals().begin() + 1, _pragma.literals().end()); + std::vector tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end()); + std::vector literals(_pragma.literals().begin() + 1, _pragma.literals().end()); SemVerMatchExpressionParser parser(tokens, literals); SemVerMatchExpression matchExpression = parser.parse(); - static SemVerVersion const currentVersion{string(VersionString)}; + static SemVerVersion const currentVersion{std::string(VersionString)}; if (!matchExpression.matches(currentVersion)) m_errorReporter.syntaxError( 3997_error, _pragma.location(), "Source file requires different compiler version (current compiler is " + - string(VersionString) + ") - note that nightly builds are considered to be " + std::string(VersionString) + ") - note that nightly builds are considered to be " "strictly less than the released version" ); m_versionPragmaFound = true; @@ -412,7 +411,7 @@ bool SyntaxChecker::visit(UsingForDirective const& _usingFor) if (!_usingFor.usesBraces()) solAssert( _usingFor.functionsAndOperators().size() == 1 && - !get<1>(_usingFor.functionsAndOperators().front()) + !std::get<1>(_usingFor.functionsAndOperators().front()) ); if (!m_currentContractKind && !_usingFor.typeName()) @@ -455,7 +454,7 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function) if (!_function.isFree() && !_function.isConstructor() && _function.noVisibilitySpecified()) { - string suggestedVisibility = + std::string suggestedVisibility = _function.isFallback() || _function.isReceive() || m_currentContractKind == ContractKind::Interface diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index e7721fd9e..5c28d3cd2 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -51,7 +51,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::util; using namespace solidity::langutil; @@ -205,7 +204,7 @@ void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment) TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall const& _functionCall, bool _abiEncoderV2) { - vector> arguments = _functionCall.arguments(); + std::vector> arguments = _functionCall.arguments(); if (arguments.size() != 2) m_errorReporter.typeError( 5782_error, @@ -296,7 +295,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(FunctionCall const& _functionCall) { - vector> arguments = _functionCall.arguments(); + std::vector> arguments = _functionCall.arguments(); if (arguments.size() != 1) m_errorReporter.fatalTypeError( 8885_error, @@ -442,7 +441,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function) m_errorReporter.typeError(5587_error, _function.location(), "\"internal\" and \"private\" functions cannot be payable."); } - vector internalParametersInConstructor; + std::vector internalParametersInConstructor; auto checkArgumentAndReturnParameter = [&](VariableDeclaration const& _var) { if (type(_var)->containsNestedMapping()) @@ -472,7 +471,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function) if (!iType) { - string message = iType.message(); + std::string message = iType.message(); solAssert(!message.empty(), "Expected detailed error message!"); if (_function.isConstructor()) message += " You can make the contract abstract to avoid this problem."; @@ -483,7 +482,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function) !typeSupportedByOldABIEncoder(*type(_var), _function.libraryFunction()) ) { - string message = + std::string message = "This type is only supported in ABI coder v2. " "Use \"pragma abicoder v2;\" to enable the feature."; if (_function.isConstructor()) @@ -509,10 +508,10 @@ bool TypeChecker::visit(FunctionDefinition const& _function) var->accept(*this); } - set modifiers; + std::set modifiers; for (ASTPointer const& modifier: _function.modifiers()) { - vector baseContracts; + std::vector baseContracts; if (auto contract = dynamic_cast(_function.scope())) { baseContracts = contract->annotation().linearizedBaseContracts; @@ -522,7 +521,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function) visitManually( *modifier, - _function.isConstructor() ? baseContracts : vector() + _function.isConstructor() ? baseContracts : std::vector() ); Declaration const* decl = &dereference(modifier->name()); if (modifiers.count(decl)) @@ -642,7 +641,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) FunctionType getter(_variable); if (!useABICoderV2()) { - vector unsupportedTypes; + std::vector unsupportedTypes; for (auto const& param: getter.parameterTypes() + getter.returnParameterTypes()) if (!typeSupportedByOldABIEncoder(*param, false /* isLibrary */)) unsupportedTypes.emplace_back(param->humanReadableName()); @@ -713,7 +712,7 @@ void TypeChecker::endVisit(StructDefinition const& _struct) void TypeChecker::visitManually( ModifierInvocation const& _modifier, - vector const& _bases + std::vector const& _bases ) { std::vector> const& arguments = @@ -724,8 +723,8 @@ void TypeChecker::visitManually( _modifier.name().accept(*this); auto const* declaration = &dereference(_modifier.name()); - vector> emptyParameterList; - vector> const* parameters = nullptr; + std::vector> emptyParameterList; + std::vector> const* parameters = nullptr; if (auto modifierDecl = dynamic_cast(declaration)) { parameters = &modifierDecl->parameters(); @@ -920,8 +919,8 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) if (!identifierInfo.suffix.empty()) { - string const& suffix = identifierInfo.suffix; - solAssert((set{"offset", "slot", "length", "selector", "address"}).count(suffix), ""); + std::string const& suffix = identifierInfo.suffix; + solAssert((std::set{"offset", "slot", "length", "selector", "address"}).count(suffix), ""); if (!var->isConstant() && (var->isStateVariable() || var->type()->dataStoredIn(DataLocation::Storage))) { if (suffix != "slot" && suffix != "offset") @@ -1042,7 +1041,7 @@ bool TypeChecker::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, @@ -1113,9 +1112,9 @@ void TypeChecker::endVisit(TryStatement const& _tryStatement) 2800_error, successClause.location(), "Function returns " + - to_string(functionType.returnParameterTypes().size()) + + std::to_string(functionType.returnParameterTypes().size()) + " values, but returns clause has " + - to_string(parameters.size()) + + std::to_string(parameters.size()) + " variables." ); for (auto&& [parameter, returnType]: ranges::views::zip(parameters, returnTypes)) @@ -1363,7 +1362,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) else valueTypes = TypePointers{type(*_statement.initialValue())}; - vector> const& variables = _statement.declarations(); + std::vector> const& variables = _statement.declarations(); if (variables.empty()) // We already have an error for this in the SyntaxChecker. solAssert(m_errorReporter.hasErrors(), ""); @@ -1378,7 +1377,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) ")." ); - for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i) + for (size_t i = 0; i < std::min(variables.size(), valueTypes.size()); ++i) { if (!variables[i]) continue; @@ -1535,14 +1534,14 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const& m_errorReporter.typeError(5547_error, _expression.location(), "Empty tuple on the left hand side."); auto const* tupleType = dynamic_cast(&_type); - auto const& types = tupleType && tupleExpression->components().size() != 1 ? tupleType->components() : vector { &_type }; + auto const& types = tupleType && tupleExpression->components().size() != 1 ? tupleType->components() : std::vector { &_type }; solAssert( tupleExpression->components().size() == types.size() || m_errorReporter.hasErrors(), "Array sizes don't match and no errors generated." ); - for (size_t i = 0; i < min(tupleExpression->components().size(), types.size()); i++) + for (size_t i = 0; i < std::min(tupleExpression->components().size(), types.size()); i++) if (types[i]) { solAssert(!!tupleExpression->components()[i], ""); @@ -1607,7 +1606,7 @@ bool TypeChecker::visit(Assignment const& _assignment) 7366_error, _assignment.location(), "Operator " + - string(TokenTraits::friendlyName(_assignment.assignmentOperator())) + + std::string(TokenTraits::friendlyName(_assignment.assignmentOperator())) + " not compatible with types " + t->humanReadableName() + " and " + @@ -1621,7 +1620,7 @@ bool TypeChecker::visit(Assignment const& _assignment) bool TypeChecker::visit(TupleExpression const& _tuple) { _tuple.annotation().isConstant = false; - vector> const& components = _tuple.components(); + std::vector> const& components = _tuple.components(); TypePointers types; if (_tuple.annotation().willBeWrittenTo) @@ -1734,7 +1733,7 @@ bool TypeChecker::visit(UnaryOperation const& _operation) // Check if the operator is built-in or user-defined. TypeResult builtinResult = operandType->unaryOperatorResult(op); - set matchingDefinitions = operandType->operatorDefinitions( + std::set matchingDefinitions = operandType->operatorDefinitions( op, *currentDefinitionScope(), true // _unary @@ -1760,7 +1759,7 @@ bool TypeChecker::visit(UnaryOperation const& _operation) } else { - string description = fmt::format( + std::string description = fmt::format( "Built-in unary operator {} cannot be applied to type {}.", TokenTraits::friendlyName(op), operandType->humanReadableName() @@ -1802,7 +1801,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation) // Check if the operator is built-in or user-defined. TypeResult builtinResult = leftType->binaryOperatorResult(_operation.getOperator(), rightType); - set matchingDefinitions = leftType->operatorDefinitions( + std::set matchingDefinitions = leftType->operatorDefinitions( _operation.getOperator(), *currentDefinitionScope(), false // _unary @@ -1828,7 +1827,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation) } else { - string description = fmt::format( + std::string description = fmt::format( "Built-in binary operator {} cannot be applied to types {} and {}.", TokenTraits::friendlyName(_operation.getOperator()), leftType->humanReadableName(), @@ -1893,7 +1892,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation) if (_operation.getOperator() == Token::Exp || _operation.getOperator() == Token::SHL) { - string operation = _operation.getOperator() == Token::Exp ? "exponentiation" : "shift"; + std::string operation = _operation.getOperator() == Token::Exp ? "exponentiation" : "shift"; if ( leftType->category() == Type::Category::RationalNumber && rightType->category() != Type::Category::RationalNumber @@ -1933,7 +1932,7 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType( solAssert(*_functionCall.annotation().kind == FunctionCallKind::TypeConversion, ""); Type const* expressionType = type(_functionCall.expression()); - vector> const& arguments = _functionCall.arguments(); + std::vector> const& arguments = _functionCall.arguments(); bool const isPositionalCall = _functionCall.names().empty(); Type const* resultType = dynamic_cast(*expressionType).actualType(); @@ -2215,7 +2214,7 @@ void TypeChecker::typeCheckABIEncodeFunctions( } // Check additional arguments for variadic functions - vector> const& arguments = _functionCall.arguments(); + std::vector> const& arguments = _functionCall.arguments(); for (size_t i = 0; i < arguments.size(); ++i) { auto const& argType = type(*arguments[i]); @@ -2274,7 +2273,7 @@ void TypeChecker::typeCheckABIEncodeFunctions( void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCall) { - vector> const& arguments = _functionCall.arguments(); + std::vector> const& arguments = _functionCall.arguments(); // Expecting first argument to be the function pointer and second to be a tuple. if (arguments.size() != 2) @@ -2311,7 +2310,7 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa externalFunctionType->kind() != FunctionType::Kind::Declaration ) { - string msg = "Expected regular external function type, or external view on public function."; + std::string msg = "Expected regular external function type, or external view on public function."; switch (externalFunctionType->kind()) { @@ -2360,7 +2359,7 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa } solAssert(!externalFunctionType->takesArbitraryParameters(), "Function must have fixed parameters."); // Tuples with only one component become that component - vector> callArguments; + std::vector> callArguments; auto const* tupleType = dynamic_cast(type(*arguments[1])); if (tupleType) @@ -2387,9 +2386,9 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa 7788_error, _functionCall.location(), "Expected " + - to_string(externalFunctionType->parameterTypes().size()) + + std::to_string(externalFunctionType->parameterTypes().size()) + " instead of " + - to_string(callArguments.size()) + + std::to_string(callArguments.size()) + " components for the tuple parameter." ); else @@ -2397,13 +2396,13 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa 7515_error, _functionCall.location(), "Expected a tuple with " + - to_string(externalFunctionType->parameterTypes().size()) + + std::to_string(externalFunctionType->parameterTypes().size()) + " components instead of a single non-tuple parameter." ); } // Use min() to check as much as we can before failing fatally - size_t const numParameters = min(callArguments.size(), externalFunctionType->parameterTypes().size()); + size_t const numParameters = std::min(callArguments.size(), externalFunctionType->parameterTypes().size()); for (size_t i = 0; i < numParameters; i++) { @@ -2414,7 +2413,7 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa 5407_error, callArguments[i]->location(), "Cannot implicitly convert component at position " + - to_string(i) + + std::to_string(i) + " from \"" + argType.humanReadableName() + "\" to \"" + @@ -2437,7 +2436,7 @@ void TypeChecker::typeCheckStringConcatFunction( typeCheckFunctionGeneralChecks(_functionCall, _functionType); - for (shared_ptr const& argument: _functionCall.arguments()) + for (std::shared_ptr const& argument: _functionCall.arguments()) { Type const* argumentType = type(*argument); bool notConvertibleToString = !argumentType->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()); @@ -2464,7 +2463,7 @@ void TypeChecker::typeCheckBytesConcatFunction( typeCheckFunctionGeneralChecks(_functionCall, _functionType); - for (shared_ptr const& argument: _functionCall.arguments()) + for (std::shared_ptr const& argument: _functionCall.arguments()) { Type const* argumentType = type(*argument); bool notConvertibleToBytes = @@ -2504,8 +2503,8 @@ void TypeChecker::typeCheckFunctionGeneralChecks( ); TypePointers const& parameterTypes = _functionType->parameterTypes(); - vector> const& arguments = _functionCall.arguments(); - vector> const& argumentNames = _functionCall.names(); + std::vector> const& arguments = _functionCall.arguments(); + std::vector> const& argumentNames = _functionCall.names(); // Check number of passed in arguments if ( @@ -2516,22 +2515,22 @@ void TypeChecker::typeCheckFunctionGeneralChecks( bool const isStructConstructorCall = functionCallKind == FunctionCallKind::StructConstructorCall; - auto [errorId, description] = [&]() -> tuple { - string msg = isVariadic ? + auto [errorId, description] = [&]() -> std::tuple { + std::string msg = isVariadic ? "Need at least " + toString(parameterTypes.size()) + " arguments for " + - string(isStructConstructorCall ? "struct constructor" : "function call") + + std::string(isStructConstructorCall ? "struct constructor" : "function call") + ", but provided only " + toString(arguments.size()) + "." : "Wrong argument count for " + - string(isStructConstructorCall ? "struct constructor" : "function call") + + std::string(isStructConstructorCall ? "struct constructor" : "function call") + ": " + toString(arguments.size()) + " arguments given but " + - string(isVariadic ? "need at least " : "expected ") + + std::string(isVariadic ? "need at least " : "expected ") + toString(parameterTypes.size()) + "."; @@ -2659,8 +2658,8 @@ void TypeChecker::typeCheckFunctionGeneralChecks( BoolResult result = type(*paramArgMap[i])->isImplicitlyConvertibleTo(*parameterTypes[i]); if (!result) { - auto [errorId, description] = [&]() -> tuple { - string msg = + auto [errorId, description] = [&]() -> std::tuple { + std::string msg = "Invalid type for argument in function call. " "Invalid implicit conversion from " + type(*paramArgMap[i])->humanReadableName() + @@ -2751,7 +2750,7 @@ void TypeChecker::typeCheckFunctionGeneralChecks( bool TypeChecker::visit(FunctionCall const& _functionCall) { - vector> const& arguments = _functionCall.arguments(); + std::vector> const& arguments = _functionCall.arguments(); bool argumentsArePure = true; // We need to check arguments' type first as they will be needed for overload resolution. @@ -2991,7 +2990,7 @@ bool TypeChecker::visit(FunctionCallOptions const& _functionCallOptions) "{...}-option." ); - auto setCheckOption = [&](bool& _option, string const& _name) + auto setCheckOption = [&](bool& _option, std::string const& _name) { if (_option) m_errorReporter.typeError( @@ -3005,7 +3004,7 @@ bool TypeChecker::visit(FunctionCallOptions const& _functionCallOptions) for (size_t i = 0; i < _functionCallOptions.names().size(); ++i) { - string const& name = *(_functionCallOptions.names()[i]); + std::string const& name = *(_functionCallOptions.names()[i]); if (name == "salt") { if (kind == FunctionType::Kind::Creation) @@ -3185,8 +3184,8 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) ); } - auto [errorId, description] = [&]() -> tuple { - string errorMsg = "Member \"" + memberName + "\" not found or not visible " + auto [errorId, description] = [&]() -> std::tuple { + std::string errorMsg = "Member \"" + memberName + "\" not found or not visible " "after argument-dependent lookup in " + exprType->humanReadableName() + "."; if (auto const* funType = dynamic_cast(exprType)) @@ -3222,7 +3221,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) if (addressMember.name == memberName) { auto const* var = dynamic_cast(&_memberAccess.expression()); - string varName = var ? var->name() : "..."; + std::string varName = var ? var->name() : "..."; errorMsg += " Use \"address(" + varName + ")." + memberName + "\" to access this address member."; return { 3125_error, errorMsg }; } @@ -3606,13 +3605,13 @@ bool TypeChecker::visit(IndexRangeAccess const& _access) return false; } -vector TypeChecker::cleanOverloadedDeclarations( +std::vector TypeChecker::cleanOverloadedDeclarations( Identifier const& _identifier, - vector const& _candidates + std::vector const& _candidates ) { solAssert(_candidates.size() > 1, ""); - vector uniqueDeclarations; + std::vector uniqueDeclarations; for (Declaration const* declaration: _candidates) { @@ -3665,7 +3664,7 @@ bool TypeChecker::visit(Identifier const& _identifier) else if (!annotation.arguments) { // The identifier should be a public state variable shadowing other functions - vector candidates; + std::vector candidates; for (Declaration const* declaration: annotation.overloadedDeclarations) { @@ -3681,7 +3680,7 @@ bool TypeChecker::visit(Identifier const& _identifier) } else { - vector candidates; + std::vector candidates; for (Declaration const* declaration: annotation.overloadedDeclarations) { @@ -3700,7 +3699,7 @@ bool TypeChecker::visit(Identifier const& _identifier) if (!declaration->location().isValid()) { // Try to re-construct function definition - string description; + std::string description; for (auto const& param: declaration->functionType(true)->parameterTypes()) description += (description.empty() ? "" : ", ") + param->humanReadableName(); description = "function " + _identifier.name() + "(" + description + ")"; @@ -3816,12 +3815,12 @@ void TypeChecker::endVisit(Literal const& _literal) // Assign type here if it even looks like an address. This prevents double errors for invalid addresses _literal.annotation().type = TypeProvider::address(); - string msg; + std::string msg; if (_literal.valueWithoutUnderscores().length() != 42) // "0x" + 40 hex digits // looksLikeAddress enforces that it is a hex literal starting with "0x" msg = "This looks like an address but is not exactly 40 hex digits. It is " + - to_string(_literal.valueWithoutUnderscores().length() - 2) + + std::to_string(_literal.valueWithoutUnderscores().length() - 2) + " hex digits."; else if (!_literal.passesAddressChecksum()) { @@ -4034,7 +4033,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) bool isBinaryOnlyOperator = (TokenTraits::isBinaryOp(operator_.value()) && !TokenTraits::isUnaryOp(operator_.value())); bool firstParameterMatchesUsingFor = parameterCount == 0 || *usingForType == *parameterTypes.front(); - optional wrongParametersMessage; + std::optional wrongParametersMessage; if (isBinaryOnlyOperator && (parameterCount != 2 || !identicalFirstTwoParameters)) wrongParametersMessage = fmt::format("two parameters of type {} and the same data location", usingForType->canonicalName()); else if (isUnaryOnlyOperator && (parameterCount != 1 || !firstParameterMatchesUsingFor)) @@ -4065,7 +4064,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) TypePointers const& returnParameterTypes = functionType->returnParameterTypes(); size_t const returnParameterCount = returnParameterTypes.size(); - optional wrongReturnParametersMessage; + std::optional wrongReturnParametersMessage; if (!TokenTraits::isCompareOp(operator_.value()) && operator_.value() != Token::Not) { if (returnParameterCount != 1 || *usingForType != *returnParameterTypes.front()) @@ -4100,7 +4099,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) { // TODO: This is pretty inefficient. For every operator binding we find, we're // traversing all bindings in all `using for` directives in the current scope. - set matchingDefinitions = usingForType->operatorDefinitions( + std::set matchingDefinitions = usingForType->operatorDefinitions( operator_.value(), *currentDefinitionScope(), parameterCount == 1 // _unary @@ -4133,7 +4132,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) void TypeChecker::checkErrorAndEventParameters(CallableDeclaration const& _callable) { - string kind = dynamic_cast(&_callable) ? "event" : "error"; + std::string kind = dynamic_cast(&_callable) ? "event" : "error"; for (ASTPointer const& var: _callable.parameters()) { if (type(*var)->containsNestedMapping()) @@ -4223,7 +4222,7 @@ void TypeChecker::requireLValue(Expression const& _expression, bool _ordinaryAss if (*_expression.annotation().isLValue) return; - auto [errorId, description] = [&]() -> tuple { + auto [errorId, description] = [&]() -> std::tuple { if (*_expression.annotation().isConstant) return { 6520_error, "Cannot assign to a constant variable." }; diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index c370f8f9f..3f6b954e7 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -27,7 +27,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::frontend; @@ -312,13 +311,13 @@ ViewPureChecker::MutabilityAndLocation const& ViewPureChecker::modifierMutabilit { MutabilityAndLocation bestMutabilityAndLocation{}; FunctionDefinition const* currentFunction = nullptr; - swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation); - swap(currentFunction, m_currentFunction); + std::swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation); + std::swap(currentFunction, m_currentFunction); _modifier.accept(*this); - swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation); - swap(currentFunction, m_currentFunction); + std::swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation); + std::swap(currentFunction, m_currentFunction); } return m_inferredMutability.at(&_modifier); } @@ -384,8 +383,8 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess) break; case Type::Category::Magic: { - using MagicMember = pair; - set static const pureMembers{ + using MagicMember = std::pair; + std::set static const pureMembers{ {MagicType::Kind::ABI, "decode"}, {MagicType::Kind::ABI, "encode"}, {MagicType::Kind::ABI, "encodePacked"}, @@ -401,7 +400,7 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess) {MagicType::Kind::MetaType, "min"}, {MagicType::Kind::MetaType, "max"}, }; - set static const payableMembers{ + std::set static const payableMembers{ {MagicType::Kind::Message, "value"} }; diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 34fbf0381..a396a7d76 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -25,6 +25,7 @@ NAMESPACE_STD_FREE_FILES=( liblangutil/* libsmtutil/* libsolc/* + libsolidity/analysis/* ) ( From 2a2a9d37ee69ca77ef530fe18524a3dc8b053104 Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Mon, 14 Aug 2023 14:39:16 +0200 Subject: [PATCH 07/66] 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/* ) ( From ce423e5ae5673f5cc0f565371e26ed9a37861f94 Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Mon, 14 Aug 2023 21:37:31 +0200 Subject: [PATCH 08/66] Purge using namespace std from libsolidity/codegen --- libsolidity/codegen/ABIFunctions.cpp | 181 +++-- libsolidity/codegen/ArrayUtils.cpp | 5 +- libsolidity/codegen/Compiler.cpp | 3 +- libsolidity/codegen/CompilerContext.cpp | 73 +- libsolidity/codegen/CompilerUtils.cpp | 37 +- libsolidity/codegen/ContractCompiler.cpp | 57 +- libsolidity/codegen/ExpressionCompiler.cpp | 45 +- libsolidity/codegen/LValue.cpp | 9 +- .../codegen/MultiUseYulFunctionCollector.cpp | 23 +- libsolidity/codegen/YulUtilFunctions.cpp | 622 +++++++++--------- libsolidity/codegen/ir/Common.cpp | 65 +- .../codegen/ir/IRGenerationContext.cpp | 11 +- libsolidity/codegen/ir/IRGenerator.cpp | 202 +++--- .../codegen/ir/IRGeneratorForStatements.cpp | 231 ++++--- libsolidity/codegen/ir/IRVariable.cpp | 15 +- scripts/check_style.sh | 2 + 16 files changed, 785 insertions(+), 796 deletions(-) diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index c92525f21..bbcdb395b 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -30,12 +30,11 @@ #include -using namespace std; using namespace solidity; using namespace solidity::util; using namespace solidity::frontend; -string ABIFunctions::tupleEncoder( +std::string ABIFunctions::tupleEncoder( TypePointers const& _givenTypes, TypePointers _targetTypes, bool _encodeAsLibraryTypes, @@ -56,7 +55,7 @@ string ABIFunctions::tupleEncoder( solAssert(t, ""); } - string functionName = string("abi_encode_tuple_"); + std::string functionName = std::string("abi_encode_tuple_"); for (auto const& t: _givenTypes) functionName += t->identifier() + "_"; functionName += "_to_"; @@ -76,8 +75,8 @@ string ABIFunctions::tupleEncoder( )"); templ("functionName", functionName); size_t const headSize_ = headSize(_targetTypes); - templ("headSize", to_string(headSize_)); - string encodeElements; + templ("headSize", std::to_string(headSize_)); + std::string encodeElements; size_t headPos = 0; size_t stackPos = 0; for (size_t i = 0; i < _givenTypes.size(); ++i) @@ -88,24 +87,24 @@ string ABIFunctions::tupleEncoder( bool dynamic = _targetTypes[i]->isDynamicallyEncoded(); Whiskers elementTempl( dynamic ? - string(R"( + std::string(R"( mstore(add(headStart, ), sub(tail, headStart)) tail := ( tail) )") : - string(R"( + std::string(R"( ( add(headStart, )) )") ); - string values = suffixedVariableNameList("value", stackPos, stackPos + sizeOnStack); + std::string values = suffixedVariableNameList("value", stackPos, stackPos + sizeOnStack); elementTempl("values", values.empty() ? "" : values + ", "); - elementTempl("pos", to_string(headPos)); + elementTempl("pos", std::to_string(headPos)); elementTempl("abiEncode", abiEncodingFunction(*_givenTypes[i], *_targetTypes[i], options)); encodeElements += elementTempl.render(); headPos += _targetTypes[i]->calldataHeadSize(); stackPos += sizeOnStack; } solAssert(headPos == headSize_, ""); - string valueParams = + std::string valueParams = _reversed ? suffixedVariableNameList("value", stackPos, 0) : suffixedVariableNameList("value", 0, stackPos); @@ -116,7 +115,7 @@ string ABIFunctions::tupleEncoder( }); } -string ABIFunctions::tupleEncoderPacked( +std::string ABIFunctions::tupleEncoderPacked( TypePointers const& _givenTypes, TypePointers _targetTypes, bool _reversed @@ -135,7 +134,7 @@ string ABIFunctions::tupleEncoderPacked( solAssert(t, ""); } - string functionName = string("abi_encode_tuple_packed_"); + std::string functionName = std::string("abi_encode_tuple_packed_"); for (auto const& t: _givenTypes) functionName += t->identifier() + "_"; functionName += "_to_"; @@ -154,7 +153,7 @@ string ABIFunctions::tupleEncoderPacked( } )"); templ("functionName", functionName); - string encodeElements; + std::string encodeElements; size_t stackPos = 0; for (size_t i = 0; i < _givenTypes.size(); ++i) { @@ -164,23 +163,23 @@ string ABIFunctions::tupleEncoderPacked( bool dynamic = _targetTypes[i]->isDynamicallyEncoded(); Whiskers elementTempl( dynamic ? - string(R"( + std::string(R"( pos := ( pos) )") : - string(R"( + std::string(R"( ( pos) pos := add(pos, ) )") ); - string values = suffixedVariableNameList("value", stackPos, stackPos + sizeOnStack); + std::string values = suffixedVariableNameList("value", stackPos, stackPos + sizeOnStack); elementTempl("values", values.empty() ? "" : values + ", "); if (!dynamic) - elementTempl("calldataEncodedSize", to_string(_targetTypes[i]->calldataEncodedSize(false))); + elementTempl("calldataEncodedSize", std::to_string(_targetTypes[i]->calldataEncodedSize(false))); elementTempl("abiEncode", abiEncodingFunction(*_givenTypes[i], *_targetTypes[i], options)); encodeElements += elementTempl.render(); stackPos += sizeOnStack; } - string valueParams = + std::string valueParams = _reversed ? suffixedVariableNameList("value", stackPos, 0) : suffixedVariableNameList("value", 0, stackPos); @@ -190,9 +189,9 @@ string ABIFunctions::tupleEncoderPacked( return templ.render(); }); } -string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory) +std::string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory) { - string functionName = string("abi_decode_tuple_"); + std::string functionName = std::string("abi_decode_tuple_"); for (auto const& t: _types) functionName += t->identifier(); if (_fromMemory) @@ -211,10 +210,10 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory) )"); templ("functionName", functionName); templ("revertString", revertReasonIfDebugFunction("ABI decoding: tuple data too short")); - templ("minimumSize", to_string(headSize(decodingTypes))); + templ("minimumSize", std::to_string(headSize(decodingTypes))); - string decodeElements; - vector valueReturnParams; + std::string decodeElements; + std::vector valueReturnParams; size_t headPos = 0; size_t stackPos = 0; for (size_t i = 0; i < _types.size(); ++i) @@ -224,11 +223,11 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory) size_t sizeOnStack = _types[i]->sizeOnStack(); solAssert(sizeOnStack == decodingTypes[i]->sizeOnStack(), ""); solAssert(sizeOnStack > 0, ""); - vector valueNamesLocal; + std::vector valueNamesLocal; for (size_t j = 0; j < sizeOnStack; j++) { - valueNamesLocal.emplace_back("value" + to_string(stackPos)); - valueReturnParams.emplace_back("value" + to_string(stackPos)); + valueNamesLocal.emplace_back("value" + std::to_string(stackPos)); + valueReturnParams.emplace_back("value" + std::to_string(stackPos)); stackPos++; } Whiskers elementTempl(R"( @@ -247,7 +246,7 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory) elementTempl("revertString", revertReasonIfDebugFunction("ABI decoding: invalid tuple offset")); elementTempl("load", _fromMemory ? "mload" : "calldataload"); elementTempl("values", boost::algorithm::join(valueNamesLocal, ", ")); - elementTempl("pos", to_string(headPos)); + elementTempl("pos", std::to_string(headPos)); elementTempl("abiDecode", abiDecodingFunction(*_types[i], _fromMemory, true)); decodeElements += elementTempl.render(); headPos += decodingTypes[i]->calldataHeadSize(); @@ -260,9 +259,9 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory) }); } -string ABIFunctions::EncodingOptions::toFunctionNameSuffix() const +std::string ABIFunctions::EncodingOptions::toFunctionNameSuffix() const { - string suffix; + std::string suffix; if (!padded) suffix += "_nonPadded"; if (dynamicInplace) @@ -274,7 +273,7 @@ string ABIFunctions::EncodingOptions::toFunctionNameSuffix() const return suffix; } -string ABIFunctions::abiEncodingFunction( +std::string ABIFunctions::abiEncodingFunction( Type const& _from, Type const& _to, EncodingOptions const& _options @@ -349,7 +348,7 @@ string ABIFunctions::abiEncodingFunction( solAssert(_from.sizeOnStack() == 1, ""); solAssert(to.isValueType(), ""); solAssert(to.calldataEncodedSize() == 32, ""); - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -376,7 +375,7 @@ string ABIFunctions::abiEncodingFunction( } else { - string cleanupConvert; + std::string cleanupConvert; if (_from == to) cleanupConvert = m_utils.cleanupFunction(_from) + "(value)"; else @@ -389,21 +388,21 @@ string ABIFunctions::abiEncodingFunction( }); } -string ABIFunctions::abiEncodeAndReturnUpdatedPosFunction( +std::string ABIFunctions::abiEncodeAndReturnUpdatedPosFunction( Type const& _givenType, Type const& _targetType, ABIFunctions::EncodingOptions const& _options ) { - string functionName = + std::string functionName = "abi_encodeUpdatedPos_" + _givenType.identifier() + "_to_" + _targetType.identifier() + _options.toFunctionNameSuffix(); return createFunction(functionName, [&]() { - string values = suffixedVariableNameList("value", 0, numVariablesForType(_givenType, _options)); - string encoder = abiEncodingFunction(_givenType, _targetType, _options); + std::string values = suffixedVariableNameList("value", 0, numVariablesForType(_givenType, _options)); + std::string encoder = abiEncodingFunction(_givenType, _targetType, _options); Type const* targetEncoding = _targetType.fullEncodingType(_options.encodeAsLibraryTypes, true, false); solAssert(targetEncoding, ""); if (targetEncoding->isDynamicallyEncoded()) @@ -435,7 +434,7 @@ string ABIFunctions::abiEncodeAndReturnUpdatedPosFunction( }); } -string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( +std::string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( Type const& _from, Type const& _to, EncodingOptions const& _options @@ -461,7 +460,7 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( "" ); - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -522,13 +521,13 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( }); } -string ABIFunctions::abiEncodingFunctionSimpleArray( +std::string ABIFunctions::abiEncodingFunctionSimpleArray( ArrayType const& _from, ArrayType const& _to, EncodingOptions const& _options ) { - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -548,7 +547,7 @@ string ABIFunctions::abiEncodingFunctionSimpleArray( EncodingOptions subOptions(_options); subOptions.encodeFunctionFromStack = false; subOptions.padded = true; - string elementValues = suffixedVariableNameList("elementValue", 0, numVariablesForType(*_from.baseType(), subOptions)); + std::string elementValues = suffixedVariableNameList("elementValue", 0, numVariablesForType(*_from.baseType(), subOptions)); Whiskers templ( usesTail ? R"( @@ -632,13 +631,13 @@ string ABIFunctions::abiEncodingFunctionSimpleArray( }); } -string ABIFunctions::abiEncodingFunctionMemoryByteArray( +std::string ABIFunctions::abiEncodingFunctionMemoryByteArray( ArrayType const& _from, ArrayType const& _to, EncodingOptions const& _options ) { - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -669,13 +668,13 @@ string ABIFunctions::abiEncodingFunctionMemoryByteArray( }); } -string ABIFunctions::abiEncodingFunctionCompactStorageArray( +std::string ABIFunctions::abiEncodingFunctionCompactStorageArray( ArrayType const& _from, ArrayType const& _to, EncodingOptions const& _options ) { - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -791,13 +790,13 @@ string ABIFunctions::abiEncodingFunctionCompactStorageArray( templ("useSpill", "1"); else templ("useSpill", "0"); - templ("itemsPerSlot", to_string(itemsPerSlot)); + templ("itemsPerSlot", std::to_string(itemsPerSlot)); templ("stride", toCompactHexWithPrefix(_to.calldataStride())); EncodingOptions subOptions(_options); subOptions.encodeFunctionFromStack = false; subOptions.padded = true; - string encodeToMemoryFun = abiEncodingFunction( + std::string encodeToMemoryFun = abiEncodingFunction( *_from.baseType(), *_to.baseType(), subOptions @@ -820,13 +819,13 @@ string ABIFunctions::abiEncodingFunctionCompactStorageArray( }); } -string ABIFunctions::abiEncodingFunctionStruct( +std::string ABIFunctions::abiEncodingFunctionStruct( StructType const& _from, StructType const& _to, EncodingOptions const& _options ) { - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -867,7 +866,7 @@ string ABIFunctions::abiEncodingFunctionStruct( templ("init", _from.dataStoredIn(DataLocation::Storage) ? "let slotValue := 0" : ""); u256 previousSlotOffset(-1); u256 encodingOffset = 0; - vector> members; + std::vector> members; for (auto const& member: _to.members(nullptr)) { solAssert(member.type, ""); @@ -890,7 +889,7 @@ string ABIFunctions::abiEncodingFunctionStruct( solAssert(memberTypeFrom->isValueType() == memberTypeTo->isValueType(), ""); u256 storageSlotOffset; size_t intraSlotOffset; - tie(storageSlotOffset, intraSlotOffset) = _from.storageOffsetsOfMember(member.name); + std::tie(storageSlotOffset, intraSlotOffset) = _from.storageOffsetsOfMember(member.name); if (memberTypeFrom->isValueType()) { if (storageSlotOffset != previousSlotOffset) @@ -910,13 +909,13 @@ string ABIFunctions::abiEncodingFunctionStruct( } case DataLocation::Memory: { - string sourceOffset = toCompactHexWithPrefix(_from.memoryOffsetOfMember(member.name)); + std::string sourceOffset = toCompactHexWithPrefix(_from.memoryOffsetOfMember(member.name)); members.back()["retrieveValue"] = "mload(add(value, " + sourceOffset + "))"; break; } case DataLocation::CallData: { - string sourceOffset = toCompactHexWithPrefix(_from.calldataOffsetOfMember(member.name)); + std::string sourceOffset = toCompactHexWithPrefix(_from.calldataOffsetOfMember(member.name)); members.back()["retrieveValue"] = calldataAccessFunction(*memberTypeFrom) + "(value, add(value, " + sourceOffset + "))"; break; } @@ -929,10 +928,10 @@ string ABIFunctions::abiEncodingFunctionStruct( // Like with arrays, struct members are always padded. subOptions.padded = true; - string memberValues = suffixedVariableNameList("memberValue", 0, numVariablesForType(*memberTypeFrom, subOptions)); + std::string memberValues = suffixedVariableNameList("memberValue", 0, numVariablesForType(*memberTypeFrom, subOptions)); members.back()["memberValues"] = memberValues; - string encode; + std::string encode; if (_options.dynamicInplace) encode = Whiskers{"pos := (, pos)"} ("encode", abiEncodeAndReturnUpdatedPosFunction(*memberTypeFrom, *memberTypeTo, subOptions)) @@ -942,7 +941,7 @@ string ABIFunctions::abiEncodingFunctionStruct( { Whiskers encodeTempl( dynamicMember ? - string(R"( + std::string(R"( mstore(add(pos, ), sub(tail, pos)) tail := (, tail) )") : @@ -966,7 +965,7 @@ string ABIFunctions::abiEncodingFunctionStruct( }); } -string ABIFunctions::abiEncodingFunctionStringLiteral( +std::string ABIFunctions::abiEncodingFunctionStringLiteral( Type const& _from, Type const& _to, EncodingOptions const& _options @@ -974,7 +973,7 @@ string ABIFunctions::abiEncodingFunctionStringLiteral( { solAssert(_from.category() == Type::Category::StringLiteral, ""); - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -982,7 +981,7 @@ string ABIFunctions::abiEncodingFunctionStringLiteral( _options.toFunctionNameSuffix(); return createFunction(functionName, [&]() { auto const& strType = dynamic_cast(_from); - string const& value = strType.value(); + std::string const& value = strType.value(); solAssert(_from.sizeOnStack() == 0, ""); if (_to.isDynamicallySized()) @@ -998,12 +997,12 @@ string ABIFunctions::abiEncodingFunctionStringLiteral( templ("functionName", functionName); // TODO this can make use of CODECOPY for large strings once we have that in Yul - templ("length", to_string(value.size())); + templ("length", std::to_string(value.size())); templ("storeLength", arrayStoreLengthForEncodingFunction(dynamic_cast(_to), _options)); if (_options.padded) - templ("overallSize", to_string(((value.size() + 31) / 32) * 32)); + templ("overallSize", std::to_string(((value.size() + 31) / 32) * 32)); else - templ("overallSize", to_string(value.size())); + templ("overallSize", std::to_string(value.size())); templ("storeLiteralInMemory", m_utils.storeLiteralInMemoryFunction(value)); return templ.render(); } @@ -1023,7 +1022,7 @@ string ABIFunctions::abiEncodingFunctionStringLiteral( }); } -string ABIFunctions::abiEncodingFunctionFunctionType( +std::string ABIFunctions::abiEncodingFunctionFunctionType( FunctionType const& _from, Type const& _to, EncodingOptions const& _options @@ -1036,7 +1035,7 @@ string ABIFunctions::abiEncodingFunctionFunctionType( "Invalid function type conversion requested" ); - string functionName = + std::string functionName = "abi_encode_" + _from.identifier() + "_to_" + @@ -1069,7 +1068,7 @@ string ABIFunctions::abiEncodingFunctionFunctionType( }); } -string ABIFunctions::abiDecodingFunction(Type const& _type, bool _fromMemory, bool _forUseOnStack) +std::string ABIFunctions::abiDecodingFunction(Type const& _type, bool _fromMemory, bool _forUseOnStack) { // The decoding function has to perform bounds checks unless it decodes a value type. // Conversely, bounds checks have to be performed before the decoding function @@ -1104,7 +1103,7 @@ string ABIFunctions::abiDecodingFunction(Type const& _type, bool _fromMemory, bo return abiDecodingFunctionValueType(_type, _fromMemory); } -string ABIFunctions::abiDecodingFunctionValueType(Type const& _type, bool _fromMemory) +std::string ABIFunctions::abiDecodingFunctionValueType(Type const& _type, bool _fromMemory) { Type const* decodingType = _type.decodingType(); solAssert(decodingType, ""); @@ -1113,7 +1112,7 @@ string ABIFunctions::abiDecodingFunctionValueType(Type const& _type, bool _fromM solAssert(!decodingType->isDynamicallyEncoded(), ""); solAssert(decodingType->calldataEncodedSize() == 32, ""); - string functionName = + std::string functionName = "abi_decode_" + _type.identifier() + (_fromMemory ? "_fromMemory" : ""); @@ -1134,17 +1133,17 @@ string ABIFunctions::abiDecodingFunctionValueType(Type const& _type, bool _fromM } -string ABIFunctions::abiDecodingFunctionArray(ArrayType const& _type, bool _fromMemory) +std::string ABIFunctions::abiDecodingFunctionArray(ArrayType const& _type, bool _fromMemory) { solAssert(_type.dataStoredIn(DataLocation::Memory), ""); - string functionName = + std::string functionName = "abi_decode_" + _type.identifier() + (_fromMemory ? "_fromMemory" : ""); return createFunction(functionName, [&]() { - string load = _fromMemory ? "mload" : "calldataload"; + std::string load = _fromMemory ? "mload" : "calldataload"; Whiskers templ( R"( // @@ -1166,14 +1165,14 @@ string ABIFunctions::abiDecodingFunctionArray(ArrayType const& _type, bool _from }); } -string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _type, bool _fromMemory) +std::string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _type, bool _fromMemory) { solAssert(_type.dataStoredIn(DataLocation::Memory), ""); if (_type.isByteArrayOrString()) return abiDecodingFunctionByteArrayAvailableLength(_type, _fromMemory); solAssert(_type.calldataStride() > 0, ""); - string functionName = + std::string functionName = "abi_decode_available_length_" + _type.identifier() + (_fromMemory ? "_fromMemory" : ""); @@ -1224,7 +1223,7 @@ string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _t }); } -string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type) +std::string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type) { solAssert(_type.dataStoredIn(DataLocation::CallData), ""); if (!_type.isDynamicallySized()) @@ -1232,7 +1231,7 @@ string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type) solAssert(_type.calldataStride() > 0, ""); solAssert(_type.calldataStride() < u256("0xffffffffffffffff"), ""); - string functionName = + std::string functionName = "abi_decode_" + _type.identifier(); return createFunction(functionName, [&]() { @@ -1273,12 +1272,12 @@ string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type) }); } -string ABIFunctions::abiDecodingFunctionByteArrayAvailableLength(ArrayType const& _type, bool _fromMemory) +std::string ABIFunctions::abiDecodingFunctionByteArrayAvailableLength(ArrayType const& _type, bool _fromMemory) { solAssert(_type.dataStoredIn(DataLocation::Memory), ""); solAssert(_type.isByteArrayOrString(), ""); - string functionName = + std::string functionName = "abi_decode_available_length_" + _type.identifier() + (_fromMemory ? "_fromMemory" : ""); @@ -1302,10 +1301,10 @@ string ABIFunctions::abiDecodingFunctionByteArrayAvailableLength(ArrayType const }); } -string ABIFunctions::abiDecodingFunctionCalldataStruct(StructType const& _type) +std::string ABIFunctions::abiDecodingFunctionCalldataStruct(StructType const& _type) { solAssert(_type.dataStoredIn(DataLocation::CallData), ""); - string functionName = + std::string functionName = "abi_decode_" + _type.identifier(); @@ -1321,15 +1320,15 @@ string ABIFunctions::abiDecodingFunctionCalldataStruct(StructType const& _type) w("revertString", revertReasonIfDebugFunction("ABI decoding: struct calldata too short")); w("functionName", functionName); w("readableTypeName", _type.toString(true)); - w("minimumSize", to_string(_type.isDynamicallyEncoded() ? _type.calldataEncodedTailSize() : _type.calldataEncodedSize(true))); + w("minimumSize", std::to_string(_type.isDynamicallyEncoded() ? _type.calldataEncodedTailSize() : _type.calldataEncodedSize(true))); return w.render(); }); } -string ABIFunctions::abiDecodingFunctionStruct(StructType const& _type, bool _fromMemory) +std::string ABIFunctions::abiDecodingFunctionStruct(StructType const& _type, bool _fromMemory) { solAssert(!_type.dataStoredIn(DataLocation::CallData), ""); - string functionName = + std::string functionName = "abi_decode_" + _type.identifier() + (_fromMemory ? "_fromMemory" : ""); @@ -1356,7 +1355,7 @@ string ABIFunctions::abiDecodingFunctionStruct(StructType const& _type, bool _fr solAssert(_type.memoryDataSize() < u256("0xffffffffffffffff"), ""); templ("memorySize", toCompactHexWithPrefix(_type.memoryDataSize())); size_t headPos = 0; - vector> members; + std::vector> members; for (auto const& member: _type.members(nullptr)) { solAssert(member.type, ""); @@ -1376,7 +1375,7 @@ string ABIFunctions::abiDecodingFunctionStruct(StructType const& _type, bool _fr // TODO add test memberTempl("revertString", revertReasonIfDebugFunction("ABI decoding: invalid struct offset")); memberTempl("load", _fromMemory ? "mload" : "calldataload"); - memberTempl("pos", to_string(headPos)); + memberTempl("pos", std::to_string(headPos)); memberTempl("memoryOffset", toCompactHexWithPrefix(_type.memoryOffsetOfMember(member.name))); memberTempl("abiDecode", abiDecodingFunction(*member.type, _fromMemory, false)); @@ -1391,11 +1390,11 @@ string ABIFunctions::abiDecodingFunctionStruct(StructType const& _type, bool _fr }); } -string ABIFunctions::abiDecodingFunctionFunctionType(FunctionType const& _type, bool _fromMemory, bool _forUseOnStack) +std::string ABIFunctions::abiDecodingFunctionFunctionType(FunctionType const& _type, bool _fromMemory, bool _forUseOnStack) { solAssert(_type.kind() == FunctionType::Kind::External, ""); - string functionName = + std::string functionName = "abi_decode_" + _type.identifier() + (_fromMemory ? "_fromMemory" : "") + @@ -1430,10 +1429,10 @@ string ABIFunctions::abiDecodingFunctionFunctionType(FunctionType const& _type, }); } -string ABIFunctions::calldataAccessFunction(Type const& _type) +std::string ABIFunctions::calldataAccessFunction(Type const& _type) { solAssert(_type.isValueType() || _type.dataStoredIn(DataLocation::CallData), ""); - string functionName = "calldata_access_" + _type.identifier(); + std::string functionName = "calldata_access_" + _type.identifier(); return createFunction(functionName, [&]() { if (_type.isDynamicallyEncoded()) { @@ -1477,7 +1476,7 @@ string ABIFunctions::calldataAccessFunction(Type const& _type) } else if (_type.isValueType()) { - string decodingFunction; + std::string decodingFunction; if (auto const* functionType = dynamic_cast(&_type)) decodingFunction = abiDecodingFunctionFunctionType(*functionType, false, false); else @@ -1510,9 +1509,9 @@ string ABIFunctions::calldataAccessFunction(Type const& _type) }); } -string ABIFunctions::arrayStoreLengthForEncodingFunction(ArrayType const& _type, EncodingOptions const& _options) +std::string ABIFunctions::arrayStoreLengthForEncodingFunction(ArrayType const& _type, EncodingOptions const& _options) { - string functionName = "array_storeLengthForEncoding_" + _type.identifier() + _options.toFunctionNameSuffix(); + std::string functionName = "array_storeLengthForEncoding_" + _type.identifier() + _options.toFunctionNameSuffix(); return createFunction(functionName, [&]() { if (_type.isDynamicallySized() && !_options.dynamicInplace) return Whiskers(R"( @@ -1534,7 +1533,7 @@ string ABIFunctions::arrayStoreLengthForEncodingFunction(ArrayType const& _type, }); } -string ABIFunctions::createFunction(string const& _name, function const& _creator) +std::string ABIFunctions::createFunction(std::string const& _name, std::function const& _creator) { return m_functionCollector.createFunction(_name, _creator); } diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 609ff9993..afcc38fe8 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -36,7 +36,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::evmasm; using namespace solidity::frontend; @@ -314,7 +313,7 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord if (!_sourceType.isByteArrayOrString()) convertLengthToSize(_sourceType); - string routine = "calldatacopy(target, source, len)\n"; + std::string routine = "calldatacopy(target, source, len)\n"; if (_padToWordBoundaries) routine += R"( // Set padding suffix to zero @@ -890,7 +889,7 @@ void ArrayUtils::popStorageArrayElement(ArrayType const& _type) const sstore(ref, slot_value) })"); code("panicSelector", util::selectorFromSignatureU256("Panic(uint256)").str()); - code("emptyArrayPop", to_string(unsigned(util::PanicCode::EmptyArrayPop))); + code("emptyArrayPop", std::to_string(unsigned(util::PanicCode::EmptyArrayPop))); m_context.appendInlineAssembly(code.render(), {"ref", "slot_value", "length"}); m_context << Instruction::POP << Instruction::POP << Instruction::POP; } diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index c044760a0..844de8ba8 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -26,13 +26,12 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::frontend; void Compiler::compileContract( ContractDefinition const& _contract, - std::map> const& _otherCompilers, + std::map> const& _otherCompilers, bytes const& _metadata ) { diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index bc69f82c5..d9264c6ac 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -55,7 +55,6 @@ #undef SOL_OUTPUT_ASM -using namespace std; using namespace solidity; using namespace solidity::util; using namespace solidity::evmasm; @@ -68,7 +67,7 @@ void CompilerContext::addStateVariable( unsigned _byteOffset ) { - m_stateVariables[&_declaration] = make_pair(_storageOffset, _byteOffset); + m_stateVariables[&_declaration] = std::make_pair(_storageOffset, _byteOffset); } void CompilerContext::addImmutable(VariableDeclaration const& _variable) @@ -88,14 +87,14 @@ size_t CompilerContext::immutableMemoryOffset(VariableDeclaration const& _variab return m_immutableVariables.at(&_variable); } -vector CompilerContext::immutableVariableSlotNames(VariableDeclaration const& _variable) +std::vector CompilerContext::immutableVariableSlotNames(VariableDeclaration const& _variable) { - string baseName = to_string(_variable.id()); + std::string baseName = std::to_string(_variable.id()); solAssert(_variable.annotation().type->sizeOnStack() > 0, ""); if (_variable.annotation().type->sizeOnStack() == 1) return {baseName}; - vector names; - auto collectSlotNames = [&](string const& _baseName, Type const* type, auto const& _recurse) -> void { + std::vector names; + auto collectSlotNames = [&](std::string const& _baseName, Type const* type, auto const& _recurse) -> void { for (auto const& [slot, type]: type->stackItems()) if (type) _recurse(_baseName + " " + slot, type, _recurse); @@ -121,10 +120,10 @@ void CompilerContext::startFunction(Declaration const& _function) } void CompilerContext::callLowLevelFunction( - string const& _name, + std::string const& _name, unsigned _inArgs, unsigned _outArgs, - function const& _generator + std::function const& _generator ) { evmasm::AssemblyItem retTag = pushNewTag(); @@ -138,7 +137,7 @@ void CompilerContext::callLowLevelFunction( } void CompilerContext::callYulFunction( - string const& _name, + std::string const& _name, unsigned _inArgs, unsigned _outArgs ) @@ -152,10 +151,10 @@ void CompilerContext::callYulFunction( } evmasm::AssemblyItem CompilerContext::lowLevelFunctionTag( - string const& _name, + std::string const& _name, unsigned _inArgs, unsigned _outArgs, - function const& _generator + std::function const& _generator ) { auto it = m_lowLevelFunctions.find(_name); @@ -174,10 +173,10 @@ void CompilerContext::appendMissingLowLevelFunctions() { while (!m_lowLevelFunctionGenerationQueue.empty()) { - string name; + std::string name; unsigned inArgs; unsigned outArgs; - function generator; + std::function generator; tie(name, inArgs, outArgs, generator) = m_lowLevelFunctionGenerationQueue.front(); m_lowLevelFunctionGenerationQueue.pop(); @@ -195,7 +194,7 @@ void CompilerContext::appendYulUtilityFunctions(OptimiserSettings const& _optimi solAssert(!m_appendYulUtilityFunctionsRan, "requestedYulFunctions called more than once."); m_appendYulUtilityFunctionsRan = true; - string code = m_yulFunctionCollector.requestedFunctions(); + std::string code = m_yulFunctionCollector.requestedFunctions(); if (!code.empty()) { appendInlineAssembly( @@ -233,7 +232,7 @@ void CompilerContext::removeVariable(Declaration const& _declaration) void CompilerContext::removeVariablesAboveStackHeight(unsigned _stackHeight) { - vector toRemove; + std::vector toRemove; for (auto _var: m_localVariables) { solAssert(!_var.second.empty(), ""); @@ -250,14 +249,14 @@ unsigned CompilerContext::numberOfLocalVariables() const return static_cast(m_localVariables.size()); } -shared_ptr CompilerContext::compiledContract(ContractDefinition const& _contract) const +std::shared_ptr CompilerContext::compiledContract(ContractDefinition const& _contract) const { auto ret = m_otherCompilers.find(&_contract); solAssert(ret != m_otherCompilers.end(), "Compiled contract not found."); return ret->second->assemblyPtr(); } -shared_ptr CompilerContext::compiledContractRuntime(ContractDefinition const& _contract) const +std::shared_ptr CompilerContext::compiledContractRuntime(ContractDefinition const& _contract) const { auto ret = m_otherCompilers.find(&_contract); solAssert(ret != m_otherCompilers.end(), "Compiled contract not found."); @@ -320,7 +319,7 @@ unsigned CompilerContext::currentToBaseStackOffset(unsigned _offset) const return static_cast(m_asm->deposit()) - _offset - 1; } -pair CompilerContext::storageLocationOfVariable(Declaration const& _declaration) const +std::pair CompilerContext::storageLocationOfVariable(Declaration const& _declaration) const { auto it = m_stateVariables.find(&_declaration); solAssert(it != m_stateVariables.end(), "Variable not found in storage."); @@ -349,13 +348,13 @@ CompilerContext& CompilerContext::appendConditionalPanic(util::PanicCode _code) return *this; } -CompilerContext& CompilerContext::appendRevert(string const& _message) +CompilerContext& CompilerContext::appendRevert(std::string const& _message) { appendInlineAssembly("{ " + revertReasonIfDebug(_message) + " }"); return *this; } -CompilerContext& CompilerContext::appendConditionalRevert(bool _forwardReturnData, string const& _message) +CompilerContext& CompilerContext::appendConditionalRevert(bool _forwardReturnData, std::string const& _message) { if (_forwardReturnData && m_evmVersion.supportsReturndata()) appendInlineAssembly(R"({ @@ -372,24 +371,24 @@ CompilerContext& CompilerContext::appendConditionalRevert(bool _forwardReturnDat void CompilerContext::resetVisitedNodes(ASTNode const* _node) { - stack newStack; + std::stack newStack; newStack.push(_node); std::swap(m_visitedNodes, newStack); updateSourceLocation(); } void CompilerContext::appendInlineAssembly( - string const& _assembly, - vector const& _localVariables, - set const& _externallyUsedFunctions, + std::string const& _assembly, + std::vector const& _localVariables, + std::set const& _externallyUsedFunctions, bool _system, OptimiserSettings const& _optimiserSettings, - string _sourceName + std::string _sourceName ) { unsigned startStackHeight = stackHeight(); - set externallyUsedIdentifiers; + std::set externallyUsedIdentifiers; for (auto const& fun: _externallyUsedFunctions) externallyUsedIdentifiers.insert(yul::YulString(fun)); for (auto const& var: _localVariables) @@ -438,19 +437,19 @@ void CompilerContext::appendInlineAssembly( ErrorReporter errorReporter(errors); langutil::CharStream charStream(_assembly, _sourceName); yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion); - optional locationOverride; + std::optional locationOverride; if (!_system) locationOverride = m_asm->currentSourceLocation(); - shared_ptr parserResult = + std::shared_ptr parserResult = yul::Parser(errorReporter, dialect, std::move(locationOverride)) .parse(charStream); #ifdef SOL_OUTPUT_ASM cout << yul::AsmPrinter(&dialect)(*parserResult) << endl; #endif - auto reportError = [&](string const& _context) + auto reportError = [&](std::string const& _context) { - string message = + std::string message = "Error parsing/analyzing inline assembly block:\n" + _context + "\n" "------------------ Input: -----------------\n" + @@ -483,7 +482,7 @@ void CompilerContext::appendInlineAssembly( { yul::Object obj; obj.code = parserResult; - obj.analysisInfo = make_shared(analysisInfo); + obj.analysisInfo = std::make_shared(analysisInfo); solAssert(!dialect.providesObjectAccess()); optimizeYul(obj, dialect, _optimiserSettings, externallyUsedIdentifiers); @@ -493,7 +492,7 @@ void CompilerContext::appendInlineAssembly( // Store as generated sources, but first re-parse to update the source references. solAssert(m_generatedYulUtilityCode.empty(), ""); m_generatedYulUtilityCode = yul::AsmPrinter(dialect)(*obj.code); - string code = yul::AsmPrinter{dialect}(*obj.code); + std::string code = yul::AsmPrinter{dialect}(*obj.code); langutil::CharStream charStream(m_generatedYulUtilityCode, _sourceName); obj.code = yul::Parser(errorReporter, dialect).parse(charStream); *obj.analysisInfo = yul::AsmAnalyzer::analyzeStrictAssertCorrect(dialect, obj); @@ -548,7 +547,7 @@ void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _ _optimiserSettings.optimizeStackAllocation, _optimiserSettings.yulOptimiserSteps, _optimiserSettings.yulOptimiserCleanupSteps, - isCreation? nullopt : make_optional(_optimiserSettings.expectedExecutionsPerDeployment), + isCreation? std::nullopt : std::make_optional(_optimiserSettings.expectedExecutionsPerDeployment), _externalIdentifiers ); @@ -558,11 +557,11 @@ void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _ #endif } -string CompilerContext::revertReasonIfDebug(string const& _message) +std::string CompilerContext::revertReasonIfDebug(std::string const& _message) { return YulUtilFunctions::revertReasonIfDebugBody( m_revertStrings, - "mload(" + to_string(CompilerUtils::freeMemoryPointer) + ")", + "mload(" + std::to_string(CompilerUtils::freeMemoryPointer) + ")", _message ); } @@ -590,14 +589,14 @@ evmasm::AssemblyItem CompilerContext::FunctionCompilationQueue::entryLabel( } // some name that cannot clash with yul function names. - string labelName = "@" + _declaration.name() + "_" + to_string(_declaration.id()); + std::string labelName = "@" + _declaration.name() + "_" + std::to_string(_declaration.id()); evmasm::AssemblyItem tag = _context.namedTag( labelName, params, returns, _declaration.id() ); - m_entryLabels.insert(make_pair(&_declaration, tag)); + m_entryLabels.insert(std::make_pair(&_declaration, tag)); m_functionsToCompile.push(&_declaration); return tag.tag(); } diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 783a7b1a4..bf4f25bf2 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -33,7 +33,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::evmasm; using namespace solidity::frontend; @@ -105,9 +104,9 @@ void CompilerUtils::revertWithStringData(Type const& _argumentType) } void CompilerUtils::revertWithError( - string const& _signature, - vector const& _parameterTypes, - vector const& _argumentTypes + std::string const& _signature, + std::vector const& _parameterTypes, + std::vector const& _argumentTypes ) { fetchFreeMemoryPointer(); @@ -215,7 +214,7 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound m_context << Instruction::DUP1; storeStringData(bytesConstRef(str->value())); if (_padToWordBoundaries) - m_context << u256(max(32, ((str->value().size() + 31) / 32) * 32)); + m_context << u256(std::max(32, ((str->value().size() + 31) / 32) * 32)); else m_context << u256(str->value().size()); m_context << Instruction::ADD; @@ -264,7 +263,7 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem Whiskers templ(R"({ if lt(len, ) { } })"); - templ("encodedSize", to_string(encodedSize)); + templ("encodedSize", std::to_string(encodedSize)); templ("revertString", m_context.revertReasonIfDebug("Calldata too short")); m_context.appendInlineAssembly(templ.render(), {"len"}); @@ -320,7 +319,7 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem mstore(dst, array_length) dst := add(dst, 0x20) })"); - templ("item_size", to_string(arrayType.calldataStride())); + templ("item_size", std::to_string(arrayType.calldataStride())); // TODO add test templ("revertStringPointer", m_context.revertReasonIfDebug("ABI memory decoding: invalid data pointer")); templ("revertStringStart", m_context.revertReasonIfDebug("ABI memory decoding: invalid data start")); @@ -374,7 +373,7 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem m_context.appendInlineAssembly(Whiskers(R"({ if or( gt(array_length, 0x100000000), - gt(add(data_ptr, mul(array_length, )" + to_string(arrayType.calldataStride()) + R"()), input_end) + gt(add(data_ptr, mul(array_length, )" + std::to_string(arrayType.calldataStride()) + R"()), input_end) ) { } })") ("revertString", m_context.revertReasonIfDebug("ABI calldata decoding: invalid data pointer")) @@ -618,7 +617,7 @@ void CompilerUtils::abiEncodeV2( // stack: <$value0> <$value1> ... <$value(n-1)> <$headStart> - string encoderName = + std::string encoderName = _padToWordBoundaries ? m_context.abiFunctions().tupleEncoderReversed(_givenTypes, _targetTypes, _encodeAsLibraryTypes) : m_context.abiFunctions().tupleEncoderPackedReversed(_givenTypes, _targetTypes); @@ -631,7 +630,7 @@ void CompilerUtils::abiDecodeV2(TypePointers const& _parameterTypes, bool _fromM m_context << Instruction::DUP2 << Instruction::ADD; m_context << Instruction::SWAP1; // stack: - string decoderName = m_context.abiFunctions().tupleDecoder(_parameterTypes, _fromMemory); + std::string decoderName = m_context.abiFunctions().tupleDecoder(_parameterTypes, _fromMemory); m_context.callYulFunction(decoderName, 2, sizeOnStack(_parameterTypes)); } @@ -646,7 +645,7 @@ void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type) calldatacopy(memptr, calldatasize(), size) memptr := add(memptr, size) })"); - templ("element_size", to_string(_type.memoryStride())); + templ("element_size", std::to_string(_type.memoryStride())); m_context.appendInlineAssembly(templ.render(), {"length", "memptr"}); } else @@ -842,7 +841,7 @@ void CompilerUtils::convertType( m_context << Instruction::POP << u256(0); else if (targetType.numBytes() > typeOnStack.numBytes() || _cleanupNeeded) { - unsigned bytes = min(typeOnStack.numBytes(), targetType.numBytes()); + unsigned bytes = std::min(typeOnStack.numBytes(), targetType.numBytes()); m_context << ((u256(1) << (256 - bytes * 8)) - 1); m_context << Instruction::NOT << Instruction::AND; } @@ -960,7 +959,7 @@ void CompilerUtils::convertType( case Type::Category::StringLiteral: { auto const& literalType = dynamic_cast(_typeOnStack); - string const& value = literalType.value(); + std::string const& value = literalType.value(); bytesConstRef data(value); if (targetTypeCategory == Type::Category::FixedBytes) { @@ -1186,7 +1185,7 @@ void CompilerUtils::convertType( for (auto const& member: typeOnStack->members(nullptr)) { solAssert(!member.type->containsNestedMapping()); - pair const& offsets = typeOnStack->storageOffsetsOfMember(member.name); + std::pair const& offsets = typeOnStack->storageOffsetsOfMember(member.name); _context << offsets.first << Instruction::DUP3 << Instruction::ADD; _context << u256(offsets.second); StorageItem(_context, *member.type).retrieveValue(SourceLocation(), true); @@ -1268,7 +1267,7 @@ void CompilerUtils::convertType( if (sourceSize > 0 || targetSize > 0) { // Move it back into its place. - for (unsigned j = 0; j < min(sourceSize, targetSize); ++j) + for (unsigned j = 0; j < std::min(sourceSize, targetSize); ++j) m_context << swapInstruction(depth + targetSize - sourceSize) << Instruction::POP; @@ -1375,7 +1374,7 @@ void CompilerUtils::pushZeroValue(Type const& _type) [type](CompilerContext& _context) { CompilerUtils utils(_context); - utils.allocateMemory(max(32u, type->memoryDataSize())); + utils.allocateMemory(std::max(32u, type->memoryDataSize())); _context << Instruction::DUP1; if (auto structType = dynamic_cast(type)) @@ -1493,7 +1492,7 @@ void CompilerUtils::popAndJump(unsigned _toHeight, evmasm::AssemblyItem const& _ m_context.adjustStackOffset(static_cast(amount)); } -unsigned CompilerUtils::sizeOnStack(vector const& _variableTypes) +unsigned CompilerUtils::sizeOnStack(std::vector const& _variableTypes) { unsigned size = 0; for (Type const* type: _variableTypes) @@ -1509,7 +1508,7 @@ void CompilerUtils::computeHashStatic() void CompilerUtils::copyContractCodeToMemory(ContractDefinition const& contract, bool _creation) { - string which = _creation ? "Creation" : "Runtime"; + std::string which = _creation ? "Creation" : "Runtime"; m_context.callLowLevelFunction( "$copyContract" + which + "CodeToMemory_" + contract.type()->identifier(), 1, @@ -1517,7 +1516,7 @@ void CompilerUtils::copyContractCodeToMemory(ContractDefinition const& contract, [&contract, _creation](CompilerContext& _context) { // copy the contract's code into memory - shared_ptr assembly = + std::shared_ptr assembly = _creation ? _context.compiledContract(contract) : _context.compiledContractRuntime(contract); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index a6e7ab2fb..3dfdf76d8 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -55,7 +55,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::evmasm; using namespace solidity::frontend; @@ -80,7 +79,7 @@ public: { solAssert( m_context.stackHeight() == stackHeight, - std::string("I sense a disturbance in the stack: ") + to_string(m_context.stackHeight()) + " vs " + to_string(stackHeight) + std::string("I sense a disturbance in the stack: ") + std::to_string(m_context.stackHeight()) + " vs " + std::to_string(stackHeight) ); } private: @@ -92,7 +91,7 @@ private: void ContractCompiler::compileContract( ContractDefinition const& _contract, - map> const& _otherCompilers + std::map> const& _otherCompilers ) { CompilerContext::LocationSetter locationSetter(m_context, _contract); @@ -111,7 +110,7 @@ void ContractCompiler::compileContract( size_t ContractCompiler::compileConstructor( ContractDefinition const& _contract, - std::map> const& _otherCompilers + std::map> const& _otherCompilers ) { CompilerContext::LocationSetter locationSetter(m_context, _contract); @@ -126,7 +125,7 @@ size_t ContractCompiler::compileConstructor( void ContractCompiler::initializeContext( ContractDefinition const& _contract, - map> const& _otherCompilers + std::map> const& _otherCompilers ) { m_context.setUseABICoderV2(*_contract.sourceUnit().annotation().useABICoderV2); @@ -187,7 +186,7 @@ size_t ContractCompiler::packIntoContractCreator(ContractDefinition const& _cont CompilerContext::LocationSetter locationSetter(m_context, _contract); m_context << deployRoutine; - solAssert(m_context.runtimeSub() != numeric_limits::max(), "Runtime sub not registered"); + solAssert(m_context.runtimeSub() != std::numeric_limits::max(), "Runtime sub not registered"); ContractType contractType(_contract); auto const& immutables = contractType.immutableVariables(); @@ -231,7 +230,7 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract) CompilerContext::LocationSetter locationSetter(m_context, _contract); - solAssert(m_context.runtimeSub() != numeric_limits::max(), "Runtime sub not registered"); + solAssert(m_context.runtimeSub() != std::numeric_limits::max(), "Runtime sub not registered"); m_context.pushSubroutineSize(m_context.runtimeSub()); m_context.pushSubroutineOffset(m_context.runtimeSub()); // This code replaces the address added by appendDeployTimeAddress(). @@ -324,8 +323,8 @@ void ContractCompiler::appendDelegatecallCheck() } void ContractCompiler::appendInternalSelector( - map, evmasm::AssemblyItem const> const& _entryPoints, - vector> const& _ids, + std::map, evmasm::AssemblyItem const> const& _entryPoints, + std::vector> const& _ids, evmasm::AssemblyItem const& _notFoundTag, size_t _runs ) @@ -369,11 +368,11 @@ void ContractCompiler::appendInternalSelector( m_context << dupInstruction(1) << u256(FixedHash<4>::Arith(pivot)) << Instruction::GT; evmasm::AssemblyItem lessTag{m_context.appendConditionalJump()}; // Here, we have funid >= pivot - vector> larger{_ids.begin() + static_cast(pivotIndex), _ids.end()}; + std::vector> larger{_ids.begin() + static_cast(pivotIndex), _ids.end()}; appendInternalSelector(_entryPoints, larger, _notFoundTag, _runs); m_context << lessTag; // Here, we have funid < pivot - vector> smaller{_ids.begin(), _ids.begin() + static_cast(pivotIndex)}; + std::vector> smaller{_ids.begin(), _ids.begin() + static_cast(pivotIndex)}; appendInternalSelector(_entryPoints, smaller, _notFoundTag, _runs); } else @@ -411,8 +410,8 @@ bool hasPayableFunctions(ContractDefinition const& _contract) void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contract) { - map, FunctionTypePointer> interfaceFunctions = _contract.interfaceFunctions(); - map, evmasm::AssemblyItem const> callDataUnpackerEntryPoints; + std::map, FunctionTypePointer> interfaceFunctions = _contract.interfaceFunctions(); + std::map, evmasm::AssemblyItem const> callDataUnpackerEntryPoints; if (_contract.isLibrary()) { @@ -448,7 +447,7 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac CompilerUtils(m_context).loadFromMemory(0, IntegerType(CompilerUtils::dataStartOffset * 8), true, false); // stack now is: ? - vector> sortedIDs; + std::vector> sortedIDs; for (auto const& it: interfaceFunctions) { callDataUnpackerEntryPoints.emplace(it.first, m_context.newTag()); @@ -572,7 +571,7 @@ void ContractCompiler::appendReturnValuePacker(TypePointers const& _typeParamete void ContractCompiler::registerStateVariables(ContractDefinition const& _contract) { for (auto const& var: ContractType(_contract).stateVariables()) - m_context.addStateVariable(*get<0>(var), get<1>(var), get<2>(var)); + m_context.addStateVariable(*std::get<0>(var), std::get<1>(var), std::get<2>(var)); } void ContractCompiler::registerImmutableVariables(ContractDefinition const& _contract) @@ -645,7 +644,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) m_breakTags.clear(); m_continueTags.clear(); m_currentFunction = &_function; - m_modifierDepth = numeric_limits::max(); + m_modifierDepth = std::numeric_limits::max(); m_scopeStackHeight.clear(); m_context.setModifierDepth(0); @@ -662,10 +661,10 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) unsigned const c_argumentsSize = CompilerUtils::sizeOnStack(_function.parameters()); unsigned const c_returnValuesSize = CompilerUtils::sizeOnStack(_function.returnParameters()); - vector stackLayout; + std::vector stackLayout; if (!_function.isConstructor() && !_function.isFallback()) stackLayout.push_back(static_cast(c_returnValuesSize)); // target of return address - stackLayout += vector(c_argumentsSize, -1); // discard all arguments + stackLayout += std::vector(c_argumentsSize, -1); // discard all arguments for (size_t i = 0; i < c_returnValuesSize; ++i) stackLayout.push_back(static_cast(i)); @@ -684,7 +683,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) else { m_context << swapInstruction(static_cast(stackLayout.size()) - static_cast(stackLayout.back()) - 1u); - swap(stackLayout[static_cast(stackLayout.back())], stackLayout.back()); + std::swap(stackLayout[static_cast(stackLayout.back())], stackLayout.back()); } for (size_t i = 0; i < stackLayout.size(); ++i) if (stackLayout[i] != static_cast(i)) @@ -790,7 +789,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) unsigned stackDiff = static_cast(_assembly.stackHeight()) - m_context.baseStackOffsetOfVariable(*variable); if (!ref->second.suffix.empty()) { - string const& suffix = ref->second.suffix; + std::string const& suffix = ref->second.suffix; if (variable->type()->dataStoredIn(DataLocation::Storage)) { solAssert(suffix == "offset" || suffix == "slot", ""); @@ -865,7 +864,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) // lvalue context auto variable = dynamic_cast(decl); unsigned stackDiff = static_cast(_assembly.stackHeight()) - m_context.baseStackOffsetOfVariable(*variable) - 1; - string const& suffix = ref->second.suffix; + std::string const& suffix = ref->second.suffix; if (variable->type()->dataStoredIn(DataLocation::Storage)) { solAssert( @@ -928,7 +927,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) yul::AsmAnalysisInfo* analysisInfo = _inlineAssembly.annotation().analysisInfo.get(); // Only used in the scope below, but required to live outside to keep the - // shared_ptr's alive + // std::shared_ptr's alive yul::Object object = {}; // The optimiser cannot handle external references @@ -941,8 +940,8 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) solAssert(dialect, ""); // Create a modifiable copy of the code and analysis - object.code = make_shared(yul::ASTCopier().translate(*code)); - object.analysisInfo = make_shared(yul::AsmAnalyzer::analyzeStrictAssertCorrect(*dialect, object)); + object.code = std::make_shared(yul::ASTCopier().translate(*code)); + object.analysisInfo = std::make_shared(yul::AsmAnalyzer::analyzeStrictAssertCorrect(*dialect, object)); m_context.optimizeYul(object, *dialect, m_optimiserSettings); @@ -989,10 +988,10 @@ bool ContractCompiler::visit(TryStatement const& _tryStatement) TryCatchClause const& successClause = *_tryStatement.clauses().front(); if (successClause.parameters()) { - vector exprTypes{_tryStatement.externalCall().annotation().type}; + std::vector exprTypes{_tryStatement.externalCall().annotation().type}; if (auto tupleType = dynamic_cast(exprTypes.front())) exprTypes = tupleType->components(); - vector> const& params = successClause.parameters()->parameters(); + std::vector> const& params = successClause.parameters()->parameters(); solAssert(exprTypes.size() == params.size(), ""); for (size_t i = 0; i < exprTypes.size(); ++i) solAssert(params[i] && exprTypes[i] && *params[i]->annotation().type == *exprTypes[i], ""); @@ -1008,7 +1007,7 @@ bool ContractCompiler::visit(TryStatement const& _tryStatement) return false; } -void ContractCompiler::handleCatch(vector> const& _catchClauses) +void ContractCompiler::handleCatch(std::vector> const& _catchClauses) { // Stack is empty. ASTPointer error{}; @@ -1285,7 +1284,7 @@ bool ContractCompiler::visit(Return const& _return) if (Expression const* expression = _return.expression()) { solAssert(_return.annotation().functionReturnParameters, "Invalid return parameters pointer."); - vector> const& returnParameters = + std::vector> const& returnParameters = _return.annotation().functionReturnParameters->parameters(); TypePointers types; for (auto const& retVariable: returnParameters) @@ -1432,7 +1431,7 @@ void ContractCompiler::appendModifierOrFunctionCode() solAssert(m_currentFunction, ""); unsigned stackSurplus = 0; Block const* codeBlock = nullptr; - vector addedVariables; + std::vector addedVariables; m_modifierDepth++; m_context.setModifierDepth(m_modifierDepth); diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index fa94d2f58..517f49c35 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -43,7 +43,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::evmasm; using namespace solidity::frontend; @@ -242,7 +241,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& if (auto arrayType = dynamic_cast(returnTypes[i])) if (!arrayType->isByteArrayOrString()) continue; - pair const& offsets = structType->storageOffsetsOfMember(names[i]); + std::pair const& offsets = structType->storageOffsetsOfMember(names[i]); m_context << Instruction::DUP1 << u256(offsets.first) << Instruction::ADD << u256(offsets.second); Type const* memberType = structType->memberType(names[i]); StorageItem(m_context, *memberType).retrieveValue(SourceLocation(), true); @@ -370,7 +369,7 @@ bool ExpressionCompiler::visit(TupleExpression const& _tuple) ArrayType const& arrayType = dynamic_cast(*_tuple.annotation().type); solAssert(!arrayType.isDynamicallySized(), "Cannot create dynamically sized inline array."); - utils().allocateMemory(max(u256(32u), arrayType.memoryDataSize())); + utils().allocateMemory(std::max(u256(32u), arrayType.memoryDataSize())); m_context << Instruction::DUP1; for (auto const& component: _tuple.components()) @@ -383,7 +382,7 @@ bool ExpressionCompiler::visit(TupleExpression const& _tuple) } else { - vector> lvalues; + std::vector> lvalues; for (auto const& component: _tuple.components()) if (component) { @@ -395,13 +394,13 @@ bool ExpressionCompiler::visit(TupleExpression const& _tuple) } } else if (_tuple.annotation().willBeWrittenTo) - lvalues.push_back(unique_ptr()); + lvalues.push_back(std::unique_ptr()); if (_tuple.annotation().willBeWrittenTo) { if (_tuple.components().size() == 1) m_currentLValue = std::move(lvalues[0]); else - m_currentLValue = make_unique(m_context, std::move(lvalues)); + m_currentLValue = std::make_unique(m_context, std::move(lvalues)); } } return false; @@ -524,7 +523,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation) m_context << u256(0) << Instruction::SUB; break; default: - solAssert(false, "Invalid unary operator: " + string(TokenTraits::toString(_unaryOperation.getOperator()))); + solAssert(false, "Invalid unary operator: " + std::string(TokenTraits::toString(_unaryOperation.getOperator()))); } return false; } @@ -659,14 +658,14 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) TypePointers parameterTypes = functionType->parameterTypes(); - vector> const& arguments = _functionCall.sortedArguments(); + std::vector> const& arguments = _functionCall.sortedArguments(); if (functionCallKind == FunctionCallKind::StructConstructorCall) { TypeType const& type = dynamic_cast(*_functionCall.expression().annotation().type); auto const& structType = dynamic_cast(*type.actualType()); - utils().allocateMemory(max(u256(32u), structType.memoryDataSize())); + utils().allocateMemory(std::max(u256(32u), structType.memoryDataSize())); m_context << Instruction::DUP1; for (unsigned i = 0; i < arguments.size(); ++i) @@ -992,7 +991,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::Error: { _functionCall.expression().accept(*this); - vector argumentTypes; + std::vector argumentTypes; for (ASTPointer const& arg: _functionCall.sortedArguments()) { arg->accept(*this); @@ -1060,7 +1059,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::RIPEMD160: { _functionCall.expression().accept(*this); - static map const contractAddresses{ + static std::map const contractAddresses{ {FunctionType::Kind::ECRecover, 1}, {FunctionType::Kind::SHA256, 2}, {FunctionType::Kind::RIPEMD160, 3} @@ -1151,8 +1150,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::BytesConcat: { _functionCall.expression().accept(*this); - vector argumentTypes; - vector targetTypes; + std::vector argumentTypes; + std::vector targetTypes; for (auto const& argument: arguments) { argument->accept(*this); @@ -1416,7 +1415,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // stack: // load current memory, mask and combine the selector - string mask = formatNumber((u256(-1) >> 32)); + std::string mask = formatNumber((u256(-1) >> 32)); m_context.appendInlineAssembly(R"({ let data_start := add(mem_ptr, 0x20) let data := mload(data_start) @@ -1476,7 +1475,7 @@ bool ExpressionCompiler::visit(FunctionCallOptions const& _functionCallOptions) // Desired Stack: [salt], [gas], [value] enum Option { Salt, Gas, Value }; - vector