Merge pull request #14409 from ethereum/purge-using-namespace-from-liblangutil

Purge using namespace std from liblangutil
This commit is contained in:
Nikola Matić 2023-07-12 12:10:27 +02:00 committed by GitHub
commit 1ac883b84d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 116 additions and 126 deletions

View File

@ -51,7 +51,6 @@
#include <liblangutil/CharStream.h>
#include <liblangutil/Exceptions.h>
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<size_type>(m_source.size(), size_type(_position));
using size_type = std::string::size_type;
size_type searchStart = std::min<size_type>(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<size_type>(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<size_type>(m_source.size(), size_type(_position));
int lineNumber = static_cast<int>(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<int>(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<size_t>(_location.end) <= m_source.size(), "");
return string_view{m_source}.substr(
return std::string_view{m_source}.substr(
static_cast<size_t>(_location.start),
static_cast<size_t>(_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<size_t>(_location.start) >= _sourceCode.size())
return {};
string cut = _sourceCode.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_location.end - _location.start));
std::string cut = _sourceCode.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_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<int> CharStream::translateLineColumnToPosition(LineColumn const& _lineColumn) const
std::optional<int> CharStream::translateLineColumnToPosition(LineColumn const& _lineColumn) const
{
return translateLineColumnToPosition(m_source, _lineColumn);
}
optional<int> CharStream::translateLineColumnToPosition(std::string const& _text, LineColumn const& _input)
std::optional<int> 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<size_t>(_input.column) > endOfLine)
return nullopt;
return std::nullopt;
return offset + static_cast<size_t>(_input.column);
}

View File

@ -30,7 +30,6 @@
#include <vector>
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> DebugInfoSelection::fromString(string_view _input)
std::optional<DebugInfoSelection> 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> DebugInfoSelection::fromString(string_view _input)
if (_input == "none")
return None();
return fromComponents(_input | ranges::views::split(',') | ranges::to<vector<string>>);
return fromComponents(_input | ranges::views::split(',') | ranges::to<std::vector<std::string>>);
}
optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
vector<string> const& _componentNames,
std::optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
std::vector<std::string> const& _componentNames,
bool _acceptWildcards
)
{
@ -75,16 +74,16 @@ optional<DebugInfoSelection> 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<string> selectedComponentNames;
std::vector<std::string> selectedComponentNames;
for (auto const& [name, member]: _selection.componentMap())
if (_selection.*member)
selectedComponentNames.push_back(name);

View File

@ -25,7 +25,6 @@
#include <liblangutil/SourceLocation.h>
#include <memory>
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<Error>(_errorId, _type, _description, _location));
m_errorList.push_back(std::make_shared<Error>(_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<Error>(_errorId, _type, _description, _location, _secondaryLocation));
m_errorList.push_back(std::make_shared<Error>(_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<Error>(4591_error, Error::Type::Warning, "There are more than 256 warnings. Ignoring the rest."));
m_errorList.push_back(std::make_shared<Error>(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<Error>(2833_error, Error::Type::Info, "There are more than 256 infos. Ignoring the rest."));
m_errorList.push_back(std::make_shared<Error>(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<Error>(4013_error, Error::Type::Warning, "There are more than 256 errors. Aborting."));
m_errorList.push_back(std::make_shared<Error>(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);
}

View File

@ -26,7 +26,6 @@
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/trim.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;

View File

@ -25,7 +25,6 @@
#include <liblangutil/Scanner.h>
#include <liblangutil/ErrorReporter.h>
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<size_t>(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);
}

View File

@ -61,12 +61,11 @@
#include <tuple>
#include <array>
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<pair<string_view, int>, 5> constexpr directionalSequences{
pair<string_view, int>{"\xE2\x80\xAD", 1}, // U+202D (LRO - Left-to-Right Override)
pair<string_view, int>{"\xE2\x80\xAE", 1}, // U+202E (RLO - Right-to-Left Override)
pair<string_view, int>{"\xE2\x80\xAA", 1}, // U+202A (LRE - Left-to-Right Embedding)
pair<string_view, int>{"\xE2\x80\xAB", 1}, // U+202B (RLE - Right-to-Left Embedding)
pair<string_view, int>{"\xE2\x80\xAC", -1} // U+202C (PDF - Pop Directional Formatting
static std::array<std::pair<std::string_view, int>, 5> constexpr directionalSequences{
std::pair<std::string_view, int>{"\xE2\x80\xAD", 1}, // U+202D (LRO - Left-to-Right Override)
std::pair<std::string_view, int>{"\xE2\x80\xAE", 1}, // U+202E (RLO - Right-to-Left Override)
std::pair<std::string_view, int>{"\xE2\x80\xAA", 1}, // U+202A (LRE - Left-to-Right Embedding)
std::pair<std::string_view, int>{"\xE2\x80\xAB", 1}, // U+202B (RLE - Right-to-Left Embedding)
std::pair<std::string_view, int>{"\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<int>(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<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
std::tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
{
solAssert(isIdentifierStart(m_char), "");
LiteralScope literal(this, LITERAL_TYPE_STRING);

View File

@ -29,18 +29,18 @@
#include <limits>
#include <fmt/format.h>
using namespace std;
using namespace std::string_literals;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::util;
SemVerMatchExpressionParser::SemVerMatchExpressionParser(vector<Token> _tokens, vector<string> _literals):
SemVerMatchExpressionParser::SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _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);

View File

@ -25,14 +25,13 @@
using namespace solidity;
using namespace solidity::langutil;
using namespace std;
SourceLocation solidity::langutil::parseSourceLocation(string const& _input, vector<shared_ptr<string const>> const& _sourceNames)
SourceLocation solidity::langutil::parseSourceLocation(std::string const& _input, std::vector<std::shared_ptr<std::string const>> const& _sourceNames)
{
// Expected input: "start:length:sourceindex"
enum SrcElem: size_t { Start, Length, Index };
vector<string> pos;
std::vector<std::string> pos;
boost::algorithm::split(pos, _input, boost::is_any_of(":"));

View File

@ -24,7 +24,6 @@
#include <cmath>
#include <variant>
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<errinfo_sourceLocation>(_exception);
string const* message = boost::get_error_info<util::errinfo_comment>(_exception);
std::string const* message = boost::get_error_info<util::errinfo_comment>(_exception);
SourceReference primary = extract(_charStreamProvider, location, message ? *message : "");
std::vector<SourceReference> 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<size_t>(start.column) + 35;
string::size_type const rhs = (isMultiline ? line.length() : static_cast<size_t>(end.column)) - 35;
std::string::size_type const rhs = (isMultiline ? line.length() : static_cast<size_t>(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<int>(line.length());
line = line.substr(
static_cast<size_t>(max(0, start.column - 35)),
static_cast<size_t>(min(start.column, 35)) + static_cast<size_t>(
min(locationLength + 35, len - start.column)
static_cast<size_t>(std::max(0, start.column - 35)),
static_cast<size_t>(std::min(start.column, 35)) + static_cast<size_t>(
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<int>(line.length())),
min(end.column, static_cast<int>(line.length()))
std::min(start.column, static_cast<int>(line.length())),
std::min(end.column, static_cast<int>(line.length()))
};
}

View File

@ -28,7 +28,6 @@
#include <string_view>
#include <variant>
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;

View File

@ -46,8 +46,6 @@
#include <map>
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<string, Token> const keywords({TOKEN_LIST(TOKEN, KEYWORD)});
static std::map<std::string, Token> 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<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(string const& _literal)
std::tuple<Token, unsigned int, unsigned int> 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<Token, unsigned int, unsigned int> 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<Token, unsigned int, unsigned int> 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);
}
}

View File

@ -22,6 +22,7 @@ EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??}
NAMESPACE_STD_FREE_FILES=(
libevmasm/*
liblangutil/*
)
(