diff --git a/liblangutil/CharStream.cpp b/liblangutil/CharStream.cpp index 6ecd85bfe..c6b58ef64 100644 --- a/liblangutil/CharStream.cpp +++ b/liblangutil/CharStream.cpp @@ -51,7 +51,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; @@ -79,21 +78,21 @@ char CharStream::setPosition(size_t _location) return get(); } -string CharStream::lineAtPosition(int _position) const +std::string CharStream::lineAtPosition(int _position) const { // if _position points to \n, it returns the line before the \n - using size_type = string::size_type; - size_type searchStart = min(m_source.size(), size_type(_position)); + using size_type = std::string::size_type; + size_type searchStart = std::min(m_source.size(), size_type(_position)); if (searchStart > 0) searchStart--; size_type lineStart = m_source.rfind('\n', searchStart); - if (lineStart == string::npos) + if (lineStart == std::string::npos) lineStart = 0; else lineStart++; - string line = m_source.substr( + std::string line = m_source.substr( lineStart, - min(m_source.find('\n', lineStart), m_source.size()) - lineStart + std::min(m_source.find('\n', lineStart), m_source.size()) - lineStart ); if (!line.empty() && line.back() == '\r') line.pop_back(); @@ -102,9 +101,9 @@ string CharStream::lineAtPosition(int _position) const LineColumn CharStream::translatePositionToLineColumn(int _position) const { - using size_type = string::size_type; - using diff_type = string::difference_type; - size_type searchPosition = min(m_source.size(), size_type(_position)); + using size_type = std::string::size_type; + using diff_type = std::string::difference_type; + size_type searchPosition = std::min(m_source.size(), size_type(_position)); int lineNumber = static_cast(count(m_source.begin(), m_source.begin() + diff_type(searchPosition), '\n')); size_type lineStart; if (searchPosition == 0) @@ -112,24 +111,24 @@ LineColumn CharStream::translatePositionToLineColumn(int _position) const else { lineStart = m_source.rfind('\n', searchPosition - 1); - lineStart = lineStart == string::npos ? 0 : lineStart + 1; + lineStart = lineStart == std::string::npos ? 0 : lineStart + 1; } return LineColumn{lineNumber, static_cast(searchPosition - lineStart)}; } -string_view CharStream::text(SourceLocation const& _location) const +std::string_view CharStream::text(SourceLocation const& _location) const { if (!_location.hasText()) return {}; solAssert(_location.sourceName && *_location.sourceName == m_name, ""); solAssert(static_cast(_location.end) <= m_source.size(), ""); - return string_view{m_source}.substr( + return std::string_view{m_source}.substr( static_cast(_location.start), static_cast(_location.end - _location.start) ); } -string CharStream::singleLineSnippet(string const& _sourceCode, SourceLocation const& _location) +std::string CharStream::singleLineSnippet(std::string const& _sourceCode, SourceLocation const& _location) { if (!_location.hasText()) return {}; @@ -137,39 +136,39 @@ string CharStream::singleLineSnippet(string const& _sourceCode, SourceLocation c if (static_cast(_location.start) >= _sourceCode.size()) return {}; - string cut = _sourceCode.substr(static_cast(_location.start), static_cast(_location.end - _location.start)); + std::string cut = _sourceCode.substr(static_cast(_location.start), static_cast(_location.end - _location.start)); auto newLinePos = cut.find_first_of("\n\r"); - if (newLinePos != string::npos) + if (newLinePos != std::string::npos) cut = cut.substr(0, newLinePos) + "..."; return cut; } -optional CharStream::translateLineColumnToPosition(LineColumn const& _lineColumn) const +std::optional CharStream::translateLineColumnToPosition(LineColumn const& _lineColumn) const { return translateLineColumnToPosition(m_source, _lineColumn); } -optional CharStream::translateLineColumnToPosition(std::string const& _text, LineColumn const& _input) +std::optional CharStream::translateLineColumnToPosition(std::string const& _text, LineColumn const& _input) { if (_input.line < 0) - return nullopt; + return std::nullopt; size_t offset = 0; for (int i = 0; i < _input.line; i++) { offset = _text.find('\n', offset); if (offset == _text.npos) - return nullopt; + return std::nullopt; offset++; // Skip linefeed. } size_t endOfLine = _text.find('\n', offset); - if (endOfLine == string::npos) + if (endOfLine == std::string::npos) endOfLine = _text.size(); if (offset + static_cast(_input.column) > endOfLine) - return nullopt; + return std::nullopt; return offset + static_cast(_input.column); } diff --git a/liblangutil/DebugInfoSelection.cpp b/liblangutil/DebugInfoSelection.cpp index 6ff023c01..88e09cdb7 100644 --- a/liblangutil/DebugInfoSelection.cpp +++ b/liblangutil/DebugInfoSelection.cpp @@ -30,7 +30,6 @@ #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::util; @@ -50,7 +49,7 @@ DebugInfoSelection const DebugInfoSelection::Only(bool DebugInfoSelection::* _me return result; } -optional DebugInfoSelection::fromString(string_view _input) +std::optional DebugInfoSelection::fromString(std::string_view _input) { // TODO: Make more stuff constexpr and make it a static_assert(). solAssert(componentMap().count("all") == 0, ""); @@ -61,11 +60,11 @@ optional DebugInfoSelection::fromString(string_view _input) if (_input == "none") return None(); - return fromComponents(_input | ranges::views::split(',') | ranges::to>); + return fromComponents(_input | ranges::views::split(',') | ranges::to>); } -optional DebugInfoSelection::fromComponents( - vector const& _componentNames, +std::optional DebugInfoSelection::fromComponents( + std::vector const& _componentNames, bool _acceptWildcards ) { @@ -75,16 +74,16 @@ optional DebugInfoSelection::fromComponents( for (auto const& component: _componentNames) { if (component == "*") - return (_acceptWildcards ? make_optional(DebugInfoSelection::All()) : nullopt); + return (_acceptWildcards ? std::make_optional(DebugInfoSelection::All()) : std::nullopt); if (!selection.enable(component)) - return nullopt; + return std::nullopt; } return selection; } -bool DebugInfoSelection::enable(string _component) +bool DebugInfoSelection::enable(std::string _component) { auto memberIt = componentMap().find(boost::trim_copy(_component)); if (memberIt == componentMap().end()) @@ -146,9 +145,9 @@ bool DebugInfoSelection::operator==(DebugInfoSelection const& _other) const noex return true; } -ostream& langutil::operator<<(ostream& _stream, DebugInfoSelection const& _selection) +std::ostream& langutil::operator<<(std::ostream& _stream, DebugInfoSelection const& _selection) { - vector selectedComponentNames; + std::vector selectedComponentNames; for (auto const& [name, member]: _selection.componentMap()) if (_selection.*member) selectedComponentNames.push_back(name); diff --git a/liblangutil/ErrorReporter.cpp b/liblangutil/ErrorReporter.cpp index f99247b32..298e4f630 100644 --- a/liblangutil/ErrorReporter.cpp +++ b/liblangutil/ErrorReporter.cpp @@ -25,7 +25,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; @@ -37,7 +36,7 @@ ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter) return *this; } -void ErrorReporter::warning(ErrorId _error, string const& _description) +void ErrorReporter::warning(ErrorId _error, std::string const& _description) { error(_error, Error::Type::Warning, SourceLocation(), _description); } @@ -45,7 +44,7 @@ void ErrorReporter::warning(ErrorId _error, string const& _description) void ErrorReporter::warning( ErrorId _error, SourceLocation const& _location, - string const& _description + std::string const& _description ) { error(_error, Error::Type::Warning, _location, _description); @@ -54,27 +53,27 @@ void ErrorReporter::warning( void ErrorReporter::warning( ErrorId _error, SourceLocation const& _location, - string const& _description, + std::string const& _description, SecondarySourceLocation const& _secondaryLocation ) { error(_error, Error::Type::Warning, _location, _secondaryLocation, _description); } -void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, string const& _description) +void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, std::string const& _description) { if (checkForExcessiveErrors(_type)) return; - m_errorList.push_back(make_shared(_errorId, _type, _description, _location)); + m_errorList.push_back(std::make_shared(_errorId, _type, _description, _location)); } -void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) +void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description) { if (checkForExcessiveErrors(_type)) return; - m_errorList.push_back(make_shared(_errorId, _type, _description, _location, _secondaryLocation)); + m_errorList.push_back(std::make_shared(_errorId, _type, _description, _location, _secondaryLocation)); } bool ErrorReporter::hasExcessiveErrors() const @@ -89,7 +88,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type) m_warningCount++; if (m_warningCount == c_maxWarningsAllowed) - m_errorList.push_back(make_shared(4591_error, Error::Type::Warning, "There are more than 256 warnings. Ignoring the rest.")); + m_errorList.push_back(std::make_shared(4591_error, Error::Type::Warning, "There are more than 256 warnings. Ignoring the rest.")); if (m_warningCount >= c_maxWarningsAllowed) return true; @@ -99,7 +98,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type) m_infoCount++; if (m_infoCount == c_maxInfosAllowed) - m_errorList.push_back(make_shared(2833_error, Error::Type::Info, "There are more than 256 infos. Ignoring the rest.")); + m_errorList.push_back(std::make_shared(2833_error, Error::Type::Info, "There are more than 256 infos. Ignoring the rest.")); if (m_infoCount >= c_maxInfosAllowed) return true; @@ -110,7 +109,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type) if (m_errorCount > c_maxErrorsAllowed) { - m_errorList.push_back(make_shared(4013_error, Error::Type::Warning, "There are more than 256 errors. Aborting.")); + m_errorList.push_back(std::make_shared(4013_error, Error::Type::Warning, "There are more than 256 errors. Aborting.")); BOOST_THROW_EXCEPTION(FatalError()); } } @@ -118,13 +117,13 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type) return false; } -void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) +void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description) { error(_error, _type, _location, _secondaryLocation, _description); BOOST_THROW_EXCEPTION(FatalError()); } -void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, string const& _description) +void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, std::string const& _description) { error(_error, _type, _location, _description); BOOST_THROW_EXCEPTION(FatalError()); @@ -140,7 +139,7 @@ void ErrorReporter::clear() m_errorList.clear(); } -void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) +void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description) { error( _error, @@ -151,7 +150,7 @@ void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _loca ); } -void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { error( _error, @@ -170,7 +169,7 @@ void ErrorReporter::fatalDeclarationError(ErrorId _error, SourceLocation const& _description); } -void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { error( _error, @@ -180,7 +179,7 @@ void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, ); } -void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { fatalError( _error, @@ -190,7 +189,7 @@ void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _loca ); } -void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { error( _error, @@ -200,7 +199,7 @@ void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, ); } -void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) +void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description) { error( _error, @@ -211,7 +210,7 @@ void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, S ); } -void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { error( _error, @@ -222,7 +221,7 @@ void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, s } -void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description) +void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description) { fatalError( _error, @@ -233,7 +232,7 @@ void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _locati ); } -void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { fatalError( _error, @@ -243,7 +242,7 @@ void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _locati ); } -void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { error( _error, @@ -256,13 +255,13 @@ void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& void ErrorReporter::info( ErrorId _error, SourceLocation const& _location, - string const& _description + std::string const& _description ) { error(_error, Error::Type::Info, _location, _description); } -void ErrorReporter::info(ErrorId _error, string const& _description) +void ErrorReporter::info(ErrorId _error, std::string const& _description) { error(_error, Error::Type::Info, SourceLocation(), _description); } diff --git a/liblangutil/Exceptions.cpp b/liblangutil/Exceptions.cpp index 92fe2589a..118720b74 100644 --- a/liblangutil/Exceptions.cpp +++ b/liblangutil/Exceptions.cpp @@ -26,7 +26,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; diff --git a/liblangutil/ParserBase.cpp b/liblangutil/ParserBase.cpp index 91f67861a..12a00d04f 100644 --- a/liblangutil/ParserBase.cpp +++ b/liblangutil/ParserBase.cpp @@ -25,7 +25,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; @@ -44,7 +43,7 @@ Token ParserBase::peekNextToken() const return m_scanner->peekNextToken(); } -string ParserBase::currentLiteral() const +std::string ParserBase::currentLiteral() const { return m_scanner->currentLiteral(); } @@ -54,7 +53,7 @@ Token ParserBase::advance() return m_scanner->next(); } -string ParserBase::tokenName(Token _token) +std::string ParserBase::tokenName(Token _token) { if (_token == Token::Identifier) return "identifier"; @@ -76,7 +75,7 @@ void ParserBase::expectToken(Token _value, bool _advance) Token tok = m_scanner->currentToken(); if (tok != _value) { - string const expectedToken = ParserBase::tokenName(_value); + std::string const expectedToken = ParserBase::tokenName(_value); if (m_parserErrorRecovery) parserError(6635_error, "Expected " + expectedToken + " but got " + tokenName(tok)); else @@ -92,7 +91,7 @@ void ParserBase::expectToken(Token _value, bool _advance) advance(); } -void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentNodeName, bool _advance) +void ParserBase::expectTokenOrConsumeUntil(Token _value, std::string const& _currentNodeName, bool _advance) { solAssert(m_inParserRecovery, "The function is supposed to be called during parser recovery only."); @@ -104,12 +103,12 @@ void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentN while (m_scanner->currentToken() != _value && m_scanner->currentToken() != Token::EOS) advance(); - string const expectedToken = ParserBase::tokenName(_value); + std::string const expectedToken = ParserBase::tokenName(_value); if (m_scanner->currentToken() == Token::EOS) { // rollback to where the token started, and raise exception to be caught at a higher level. m_scanner->setPosition(static_cast(startPosition)); - string const msg = "In " + _currentNodeName + ", " + expectedToken + "is expected; got " + ParserBase::tokenName(tok) + " instead."; + std::string const msg = "In " + _currentNodeName + ", " + expectedToken + "is expected; got " + ParserBase::tokenName(tok) + " instead."; fatalParserError(1957_error, errorLoc, msg); } else @@ -120,7 +119,7 @@ void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentN } else { - string expectedToken = ParserBase::tokenName(_value); + std::string expectedToken = ParserBase::tokenName(_value); parserWarning(3347_error, "Recovered in " + _currentNodeName + " at " + expectedToken + "."); m_inParserRecovery = false; } @@ -142,32 +141,32 @@ void ParserBase::decreaseRecursionDepth() m_recursionDepth--; } -void ParserBase::parserWarning(ErrorId _error, string const& _description) +void ParserBase::parserWarning(ErrorId _error, std::string const& _description) { m_errorReporter.warning(_error, currentLocation(), _description); } -void ParserBase::parserWarning(ErrorId _error, SourceLocation const& _location, string const& _description) +void ParserBase::parserWarning(ErrorId _error, SourceLocation const& _location, std::string const& _description) { m_errorReporter.warning(_error, _location, _description); } -void ParserBase::parserError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ParserBase::parserError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { m_errorReporter.parserError(_error, _location, _description); } -void ParserBase::parserError(ErrorId _error, string const& _description) +void ParserBase::parserError(ErrorId _error, std::string const& _description) { parserError(_error, currentLocation(), _description); } -void ParserBase::fatalParserError(ErrorId _error, string const& _description) +void ParserBase::fatalParserError(ErrorId _error, std::string const& _description) { fatalParserError(_error, currentLocation(), _description); } -void ParserBase::fatalParserError(ErrorId _error, SourceLocation const& _location, string const& _description) +void ParserBase::fatalParserError(ErrorId _error, SourceLocation const& _location, std::string const& _description) { m_errorReporter.fatalParserError(_error, _location, _description); } diff --git a/liblangutil/Scanner.cpp b/liblangutil/Scanner.cpp index 1b9b2afac..2d5607607 100644 --- a/liblangutil/Scanner.cpp +++ b/liblangutil/Scanner.cpp @@ -61,12 +61,11 @@ #include #include -using namespace std; namespace solidity::langutil { -string to_string(ScannerError _errorCode) +std::string to_string(ScannerError _errorCode) { switch (_errorCode) { @@ -92,7 +91,7 @@ string to_string(ScannerError _errorCode) } -ostream& operator<<(ostream& os, ScannerError _errorCode) +std::ostream& operator<<(std::ostream& os, ScannerError _errorCode) { return os << to_string(_errorCode); } @@ -275,12 +274,12 @@ namespace /// to the user. static ScannerError validateBiDiMarkup(CharStream& _stream, size_t _startPosition) { - static array, 5> constexpr directionalSequences{ - pair{"\xE2\x80\xAD", 1}, // U+202D (LRO - Left-to-Right Override) - pair{"\xE2\x80\xAE", 1}, // U+202E (RLO - Right-to-Left Override) - pair{"\xE2\x80\xAA", 1}, // U+202A (LRE - Left-to-Right Embedding) - pair{"\xE2\x80\xAB", 1}, // U+202B (RLE - Right-to-Left Embedding) - pair{"\xE2\x80\xAC", -1} // U+202C (PDF - Pop Directional Formatting + static std::array, 5> constexpr directionalSequences{ + std::pair{"\xE2\x80\xAD", 1}, // U+202D (LRO - Left-to-Right Override) + std::pair{"\xE2\x80\xAE", 1}, // U+202E (RLO - Right-to-Left Override) + std::pair{"\xE2\x80\xAA", 1}, // U+202A (LRE - Left-to-Right Embedding) + std::pair{"\xE2\x80\xAB", 1}, // U+202B (RLE - Right-to-Left Embedding) + std::pair{"\xE2\x80\xAC", -1} // U+202C (PDF - Pop Directional Formatting }; size_t endPosition = _stream.position(); @@ -712,7 +711,7 @@ void Scanner::scanToken() default: if (isIdentifierStart(m_char)) { - tie(token, m, n) = scanIdentifierOrKeyword(); + std::tie(token, m, n) = scanIdentifierOrKeyword(); // Special case for hexadecimal literals if (token == Token::Hex) @@ -757,7 +756,7 @@ void Scanner::scanToken() m_tokens[NextNext].location.end = static_cast(sourcePos()); m_tokens[NextNext].location.sourceName = m_sourceName; m_tokens[NextNext].token = token; - m_tokens[NextNext].extendedTokenInfo = make_tuple(m, n); + m_tokens[NextNext].extendedTokenInfo = std::make_tuple(m, n); } bool Scanner::scanEscape() @@ -1011,7 +1010,7 @@ Token Scanner::scanNumber(char _charSeen) return Token::Number; } -tuple Scanner::scanIdentifierOrKeyword() +std::tuple Scanner::scanIdentifierOrKeyword() { solAssert(isIdentifierStart(m_char), ""); LiteralScope literal(this, LITERAL_TYPE_STRING); diff --git a/liblangutil/SemVerHandler.cpp b/liblangutil/SemVerHandler.cpp index 6e85e2609..2358eec5e 100644 --- a/liblangutil/SemVerHandler.cpp +++ b/liblangutil/SemVerHandler.cpp @@ -29,18 +29,18 @@ #include #include -using namespace std; +using namespace std::string_literals; using namespace solidity; using namespace solidity::langutil; using namespace solidity::util; -SemVerMatchExpressionParser::SemVerMatchExpressionParser(vector _tokens, vector _literals): +SemVerMatchExpressionParser::SemVerMatchExpressionParser(std::vector _tokens, std::vector _literals): m_tokens(std::move(_tokens)), m_literals(std::move(_literals)) { solAssert(m_tokens.size() == m_literals.size(), ""); } -SemVerVersion::SemVerVersion(string const& _versionString) +SemVerVersion::SemVerVersion(std::string const& _versionString) { auto i = _versionString.begin(); auto end = _versionString.end(); @@ -63,13 +63,13 @@ SemVerVersion::SemVerVersion(string const& _versionString) { auto prereleaseStart = ++i; while (i != end && *i != '+') ++i; - prerelease = string(prereleaseStart, i); + prerelease = std::string(prereleaseStart, i); } if (i != end && *i == '+') { auto buildStart = ++i; while (i != end) ++i; - build = string(buildStart, i); + build = std::string(buildStart, i); } if (i != end) solThrow(SemVerError, "Invalid versionString "s + _versionString); diff --git a/liblangutil/SourceLocation.cpp b/liblangutil/SourceLocation.cpp index 72f2506e8..61fe40f92 100644 --- a/liblangutil/SourceLocation.cpp +++ b/liblangutil/SourceLocation.cpp @@ -25,14 +25,13 @@ using namespace solidity; using namespace solidity::langutil; -using namespace std; -SourceLocation solidity::langutil::parseSourceLocation(string const& _input, vector> const& _sourceNames) +SourceLocation solidity::langutil::parseSourceLocation(std::string const& _input, std::vector> const& _sourceNames) { // Expected input: "start:length:sourceindex" enum SrcElem: size_t { Start, Length, Index }; - vector pos; + std::vector pos; boost::algorithm::split(pos, _input, boost::is_any_of(":")); diff --git a/liblangutil/SourceReferenceExtractor.cpp b/liblangutil/SourceReferenceExtractor.cpp index 01f22a1f7..9389a77aa 100644 --- a/liblangutil/SourceReferenceExtractor.cpp +++ b/liblangutil/SourceReferenceExtractor.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; @@ -36,7 +35,7 @@ SourceReferenceExtractor::Message SourceReferenceExtractor::extract( { SourceLocation const* location = boost::get_error_info(_exception); - string const* message = boost::get_error_info(_exception); + std::string const* message = boost::get_error_info(_exception); SourceReference primary = extract(_charStreamProvider, location, message ? *message : ""); std::vector secondary; @@ -45,7 +44,7 @@ SourceReferenceExtractor::Message SourceReferenceExtractor::extract( for (auto const& info: secondaryLocation->infos) secondary.emplace_back(extract(_charStreamProvider, &info.second, info.first)); - return Message{std::move(primary), _typeOrSeverity, std::move(secondary), nullopt}; + return Message{std::move(primary), _typeOrSeverity, std::move(secondary), std::nullopt}; } SourceReferenceExtractor::Message SourceReferenceExtractor::extract( @@ -78,7 +77,7 @@ SourceReference SourceReferenceExtractor::extract( LineColumn end = charStream.translatePositionToLineColumn(_location->end); bool const isMultiline = start.line != end.line; - string line = charStream.lineAtPosition(_location->start); + std::string line = charStream.lineAtPosition(_location->start); int locationLength = isMultiline ? @@ -88,7 +87,7 @@ SourceReference SourceReferenceExtractor::extract( if (locationLength > 150) { auto const lhs = static_cast(start.column) + 35; - string::size_type const rhs = (isMultiline ? line.length() : static_cast(end.column)) - 35; + std::string::size_type const rhs = (isMultiline ? line.length() : static_cast(end.column)) - 35; line = line.substr(0, lhs) + " ... " + line.substr(rhs); end.column = start.column + 75; locationLength = 75; @@ -98,9 +97,9 @@ SourceReference SourceReferenceExtractor::extract( { int const len = static_cast(line.length()); line = line.substr( - static_cast(max(0, start.column - 35)), - static_cast(min(start.column, 35)) + static_cast( - min(locationLength + 35, len - start.column) + static_cast(std::max(0, start.column - 35)), + static_cast(std::min(start.column, 35)) + static_cast( + std::min(locationLength + 35, len - start.column) ) ); if (start.column + locationLength + 35 < len) @@ -119,7 +118,7 @@ SourceReference SourceReferenceExtractor::extract( interest, isMultiline, line, - min(start.column, static_cast(line.length())), - min(end.column, static_cast(line.length())) + std::min(start.column, static_cast(line.length())), + std::min(end.column, static_cast(line.length())) }; } diff --git a/liblangutil/SourceReferenceFormatter.cpp b/liblangutil/SourceReferenceFormatter.cpp index 4765b9fb2..76cb1df61 100644 --- a/liblangutil/SourceReferenceFormatter.cpp +++ b/liblangutil/SourceReferenceFormatter.cpp @@ -28,7 +28,6 @@ #include #include -using namespace std; using namespace solidity; using namespace solidity::langutil; using namespace solidity::util; @@ -114,15 +113,15 @@ void SourceReferenceFormatter::printSourceLocation(SourceReference const& _ref) return; // No line available, nothing else to print } - string line = std::to_string(_ref.position.line + 1); // one-based line number as string - string leftpad = string(line.size(), ' '); + std::string line = std::to_string(_ref.position.line + 1); // one-based line number as string + std::string leftpad = std::string(line.size(), ' '); // line 0: source name m_stream << leftpad; frameColored() << "-->"; m_stream << ' ' << _ref.sourceName << ':' << line << ':' << (_ref.position.column + 1) << ":\n"; - string_view text = _ref.text; + std::string_view text = _ref.text; if (m_charStreamProvider.charStream(_ref.sourceName).isImportedFromAST()) return; diff --git a/liblangutil/Token.cpp b/liblangutil/Token.cpp index 60b8aa798..8a860791f 100644 --- a/liblangutil/Token.cpp +++ b/liblangutil/Token.cpp @@ -46,8 +46,6 @@ #include -using namespace std; - namespace solidity::langutil { @@ -71,25 +69,25 @@ std::string ElementaryTypeNameToken::toString(bool const& tokenValue) const void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second) { - solAssert(TokenTraits::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(TokenTraits::toString(_baseType))); + solAssert(TokenTraits::isElementaryTypeName(_baseType), "Expected elementary type name: " + std::string(TokenTraits::toString(_baseType))); if (_baseType == Token::BytesM) { solAssert(_second == 0, "There should not be a second size argument to type bytesM."); - solAssert(_first <= 32, "No elementary type bytes" + to_string(_first) + "."); + solAssert(_first <= 32, "No elementary type bytes" + std::to_string(_first) + "."); } else if (_baseType == Token::UIntM || _baseType == Token::IntM) { - solAssert(_second == 0, "There should not be a second size argument to type " + string(TokenTraits::toString(_baseType)) + "."); + solAssert(_second == 0, "There should not be a second size argument to type " + std::string(TokenTraits::toString(_baseType)) + "."); solAssert( _first <= 256 && _first % 8 == 0, - "No elementary type " + string(TokenTraits::toString(_baseType)) + to_string(_first) + "." + "No elementary type " + std::string(TokenTraits::toString(_baseType)) + std::to_string(_first) + "." ); } else if (_baseType == Token::UFixedMxN || _baseType == Token::FixedMxN) { solAssert( _first >= 8 && _first <= 256 && _first % 8 == 0 && _second <= 80, - "No elementary type " + string(TokenTraits::toString(_baseType)) + to_string(_first) + "x" + to_string(_second) + "." + "No elementary type " + std::string(TokenTraits::toString(_baseType)) + std::to_string(_first) + "x" + std::to_string(_second) + "." ); } else @@ -136,29 +134,29 @@ std::string friendlyName(Token tok) } -static Token keywordByName(string const& _name) +static Token keywordByName(std::string const& _name) { // The following macros are used inside TOKEN_LIST and cause non-keyword tokens to be ignored // and keywords to be put inside the keywords variable. #define KEYWORD(name, string, precedence) {string, Token::name}, #define TOKEN(name, string, precedence) - static map const keywords({TOKEN_LIST(TOKEN, KEYWORD)}); + static std::map const keywords({TOKEN_LIST(TOKEN, KEYWORD)}); #undef KEYWORD #undef TOKEN auto it = keywords.find(_name); return it == keywords.end() ? Token::Identifier : it->second; } -bool isYulKeyword(string const& _literal) +bool isYulKeyword(std::string const& _literal) { return _literal == "leave" || isYulKeyword(keywordByName(_literal)); } -tuple fromIdentifierOrKeyword(string const& _literal) +std::tuple fromIdentifierOrKeyword(std::string const& _literal) { // Used for `bytesM`, `uintM`, `intM`, `fixedMxN`, `ufixedMxN`. // M/N must be shortest representation. M can never be 0. N can be zero. - auto parseSize = [](string::const_iterator _begin, string::const_iterator _end) -> int + auto parseSize = [](std::string::const_iterator _begin, std::string::const_iterator _end) -> int { // No number. if (distance(_begin, _end) == 0) @@ -185,23 +183,23 @@ tuple fromIdentifierOrKeyword(string const& _ auto positionM = find_if(_literal.begin(), _literal.end(), util::isDigit); if (positionM != _literal.end()) { - string baseType(_literal.begin(), positionM); + std::string baseType(_literal.begin(), positionM); auto positionX = find_if_not(positionM, _literal.end(), util::isDigit); int m = parseSize(positionM, positionX); Token keyword = keywordByName(baseType); if (keyword == Token::Bytes) { if (0 < m && m <= 32 && positionX == _literal.end()) - return make_tuple(Token::BytesM, m, 0); + return std::make_tuple(Token::BytesM, m, 0); } else if (keyword == Token::UInt || keyword == Token::Int) { if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end()) { if (keyword == Token::UInt) - return make_tuple(Token::UIntM, m, 0); + return std::make_tuple(Token::UIntM, m, 0); else - return make_tuple(Token::IntM, m, 0); + return std::make_tuple(Token::IntM, m, 0); } } else if (keyword == Token::UFixed || keyword == Token::Fixed) @@ -218,16 +216,16 @@ tuple fromIdentifierOrKeyword(string const& _ 0 <= n && n <= 80 ) { if (keyword == Token::UFixed) - return make_tuple(Token::UFixedMxN, m, n); + return std::make_tuple(Token::UFixedMxN, m, n); else - return make_tuple(Token::FixedMxN, m, n); + return std::make_tuple(Token::FixedMxN, m, n); } } } - return make_tuple(Token::Identifier, 0, 0); + return std::make_tuple(Token::Identifier, 0, 0); } - return make_tuple(keywordByName(_literal), 0, 0); + return std::make_tuple(keywordByName(_literal), 0, 0); } } diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 0d5fe1826..bd9fbf005 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -22,6 +22,7 @@ EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??} NAMESPACE_STD_FREE_FILES=( libevmasm/* + liblangutil/* ) (