Skip to content

Commit e81f2bd

Browse files
committed
Purge using namespace std from liblangutil
1 parent 8390a24 commit e81f2bd

12 files changed

+116
-126
lines changed

liblangutil/CharStream.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include <liblangutil/CharStream.h>
5252
#include <liblangutil/Exceptions.h>
5353

54-
using namespace std;
5554
using namespace solidity;
5655
using namespace solidity::langutil;
5756

@@ -79,21 +78,21 @@ char CharStream::setPosition(size_t _location)
7978
return get();
8079
}
8180

82-
string CharStream::lineAtPosition(int _position) const
81+
std::string CharStream::lineAtPosition(int _position) const
8382
{
8483
// if _position points to \n, it returns the line before the \n
85-
using size_type = string::size_type;
86-
size_type searchStart = min<size_type>(m_source.size(), size_type(_position));
84+
using size_type = std::string::size_type;
85+
size_type searchStart = std::min<size_type>(m_source.size(), size_type(_position));
8786
if (searchStart > 0)
8887
searchStart--;
8988
size_type lineStart = m_source.rfind('\n', searchStart);
90-
if (lineStart == string::npos)
89+
if (lineStart == std::string::npos)
9190
lineStart = 0;
9291
else
9392
lineStart++;
94-
string line = m_source.substr(
93+
std::string line = m_source.substr(
9594
lineStart,
96-
min(m_source.find('\n', lineStart), m_source.size()) - lineStart
95+
std::min(m_source.find('\n', lineStart), m_source.size()) - lineStart
9796
);
9897
if (!line.empty() && line.back() == '\r')
9998
line.pop_back();
@@ -102,74 +101,74 @@ string CharStream::lineAtPosition(int _position) const
102101

103102
LineColumn CharStream::translatePositionToLineColumn(int _position) const
104103
{
105-
using size_type = string::size_type;
106-
using diff_type = string::difference_type;
107-
size_type searchPosition = min<size_type>(m_source.size(), size_type(_position));
104+
using size_type = std::string::size_type;
105+
using diff_type = std::string::difference_type;
106+
size_type searchPosition = std::min<size_type>(m_source.size(), size_type(_position));
108107
int lineNumber = static_cast<int>(count(m_source.begin(), m_source.begin() + diff_type(searchPosition), '\n'));
109108
size_type lineStart;
110109
if (searchPosition == 0)
111110
lineStart = 0;
112111
else
113112
{
114113
lineStart = m_source.rfind('\n', searchPosition - 1);
115-
lineStart = lineStart == string::npos ? 0 : lineStart + 1;
114+
lineStart = lineStart == std::string::npos ? 0 : lineStart + 1;
116115
}
117116
return LineColumn{lineNumber, static_cast<int>(searchPosition - lineStart)};
118117
}
119118

120-
string_view CharStream::text(SourceLocation const& _location) const
119+
std::string_view CharStream::text(SourceLocation const& _location) const
121120
{
122121
if (!_location.hasText())
123122
return {};
124123
solAssert(_location.sourceName && *_location.sourceName == m_name, "");
125124
solAssert(static_cast<size_t>(_location.end) <= m_source.size(), "");
126-
return string_view{m_source}.substr(
125+
return std::string_view{m_source}.substr(
127126
static_cast<size_t>(_location.start),
128127
static_cast<size_t>(_location.end - _location.start)
129128
);
130129
}
131130

132-
string CharStream::singleLineSnippet(string const& _sourceCode, SourceLocation const& _location)
131+
std::string CharStream::singleLineSnippet(std::string const& _sourceCode, SourceLocation const& _location)
133132
{
134133
if (!_location.hasText())
135134
return {};
136135

137136
if (static_cast<size_t>(_location.start) >= _sourceCode.size())
138137
return {};
139138

140-
string cut = _sourceCode.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_location.end - _location.start));
139+
std::string cut = _sourceCode.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_location.end - _location.start));
141140
auto newLinePos = cut.find_first_of("\n\r");
142-
if (newLinePos != string::npos)
141+
if (newLinePos != std::string::npos)
143142
cut = cut.substr(0, newLinePos) + "...";
144143

145144
return cut;
146145
}
147146

148-
optional<int> CharStream::translateLineColumnToPosition(LineColumn const& _lineColumn) const
147+
std::optional<int> CharStream::translateLineColumnToPosition(LineColumn const& _lineColumn) const
149148
{
150149
return translateLineColumnToPosition(m_source, _lineColumn);
151150
}
152151

153-
optional<int> CharStream::translateLineColumnToPosition(std::string const& _text, LineColumn const& _input)
152+
std::optional<int> CharStream::translateLineColumnToPosition(std::string const& _text, LineColumn const& _input)
154153
{
155154
if (_input.line < 0)
156-
return nullopt;
155+
return std::nullopt;
157156

158157
size_t offset = 0;
159158
for (int i = 0; i < _input.line; i++)
160159
{
161160
offset = _text.find('\n', offset);
162161
if (offset == _text.npos)
163-
return nullopt;
162+
return std::nullopt;
164163
offset++; // Skip linefeed.
165164
}
166165

167166
size_t endOfLine = _text.find('\n', offset);
168-
if (endOfLine == string::npos)
167+
if (endOfLine == std::string::npos)
169168
endOfLine = _text.size();
170169

171170
if (offset + static_cast<size_t>(_input.column) > endOfLine)
172-
return nullopt;
171+
return std::nullopt;
173172
return offset + static_cast<size_t>(_input.column);
174173
}
175174

liblangutil/DebugInfoSelection.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include <vector>
3232

33-
using namespace std;
3433
using namespace solidity;
3534
using namespace solidity::langutil;
3635
using namespace solidity::util;
@@ -50,7 +49,7 @@ DebugInfoSelection const DebugInfoSelection::Only(bool DebugInfoSelection::* _me
5049
return result;
5150
}
5251

53-
optional<DebugInfoSelection> DebugInfoSelection::fromString(string_view _input)
52+
std::optional<DebugInfoSelection> DebugInfoSelection::fromString(std::string_view _input)
5453
{
5554
// TODO: Make more stuff constexpr and make it a static_assert().
5655
solAssert(componentMap().count("all") == 0, "");
@@ -61,11 +60,11 @@ optional<DebugInfoSelection> DebugInfoSelection::fromString(string_view _input)
6160
if (_input == "none")
6261
return None();
6362

64-
return fromComponents(_input | ranges::views::split(',') | ranges::to<vector<string>>);
63+
return fromComponents(_input | ranges::views::split(',') | ranges::to<std::vector<std::string>>);
6564
}
6665

67-
optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
68-
vector<string> const& _componentNames,
66+
std::optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
67+
std::vector<std::string> const& _componentNames,
6968
bool _acceptWildcards
7069
)
7170
{
@@ -75,16 +74,16 @@ optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
7574
for (auto const& component: _componentNames)
7675
{
7776
if (component == "*")
78-
return (_acceptWildcards ? make_optional(DebugInfoSelection::All()) : nullopt);
77+
return (_acceptWildcards ? std::make_optional(DebugInfoSelection::All()) : std::nullopt);
7978

8079
if (!selection.enable(component))
81-
return nullopt;
80+
return std::nullopt;
8281
}
8382

8483
return selection;
8584
}
8685

87-
bool DebugInfoSelection::enable(string _component)
86+
bool DebugInfoSelection::enable(std::string _component)
8887
{
8988
auto memberIt = componentMap().find(boost::trim_copy(_component));
9089
if (memberIt == componentMap().end())
@@ -146,9 +145,9 @@ bool DebugInfoSelection::operator==(DebugInfoSelection const& _other) const noex
146145
return true;
147146
}
148147

149-
ostream& langutil::operator<<(ostream& _stream, DebugInfoSelection const& _selection)
148+
std::ostream& langutil::operator<<(std::ostream& _stream, DebugInfoSelection const& _selection)
150149
{
151-
vector<string> selectedComponentNames;
150+
std::vector<std::string> selectedComponentNames;
152151
for (auto const& [name, member]: _selection.componentMap())
153152
if (_selection.*member)
154153
selectedComponentNames.push_back(name);

liblangutil/ErrorReporter.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <liblangutil/SourceLocation.h>
2626
#include <memory>
2727

28-
using namespace std;
2928
using namespace solidity;
3029
using namespace solidity::langutil;
3130

@@ -37,15 +36,15 @@ ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter)
3736
return *this;
3837
}
3938

40-
void ErrorReporter::warning(ErrorId _error, string const& _description)
39+
void ErrorReporter::warning(ErrorId _error, std::string const& _description)
4140
{
4241
error(_error, Error::Type::Warning, SourceLocation(), _description);
4342
}
4443

4544
void ErrorReporter::warning(
4645
ErrorId _error,
4746
SourceLocation const& _location,
48-
string const& _description
47+
std::string const& _description
4948
)
5049
{
5150
error(_error, Error::Type::Warning, _location, _description);
@@ -54,27 +53,27 @@ void ErrorReporter::warning(
5453
void ErrorReporter::warning(
5554
ErrorId _error,
5655
SourceLocation const& _location,
57-
string const& _description,
56+
std::string const& _description,
5857
SecondarySourceLocation const& _secondaryLocation
5958
)
6059
{
6160
error(_error, Error::Type::Warning, _location, _secondaryLocation, _description);
6261
}
6362

64-
void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, string const& _description)
63+
void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, std::string const& _description)
6564
{
6665
if (checkForExcessiveErrors(_type))
6766
return;
6867

69-
m_errorList.push_back(make_shared<Error>(_errorId, _type, _description, _location));
68+
m_errorList.push_back(std::make_shared<Error>(_errorId, _type, _description, _location));
7069
}
7170

72-
void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
71+
void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description)
7372
{
7473
if (checkForExcessiveErrors(_type))
7574
return;
7675

77-
m_errorList.push_back(make_shared<Error>(_errorId, _type, _description, _location, _secondaryLocation));
76+
m_errorList.push_back(std::make_shared<Error>(_errorId, _type, _description, _location, _secondaryLocation));
7877
}
7978

8079
bool ErrorReporter::hasExcessiveErrors() const
@@ -89,7 +88,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
8988
m_warningCount++;
9089

9190
if (m_warningCount == c_maxWarningsAllowed)
92-
m_errorList.push_back(make_shared<Error>(4591_error, Error::Type::Warning, "There are more than 256 warnings. Ignoring the rest."));
91+
m_errorList.push_back(std::make_shared<Error>(4591_error, Error::Type::Warning, "There are more than 256 warnings. Ignoring the rest."));
9392

9493
if (m_warningCount >= c_maxWarningsAllowed)
9594
return true;
@@ -99,7 +98,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
9998
m_infoCount++;
10099

101100
if (m_infoCount == c_maxInfosAllowed)
102-
m_errorList.push_back(make_shared<Error>(2833_error, Error::Type::Info, "There are more than 256 infos. Ignoring the rest."));
101+
m_errorList.push_back(std::make_shared<Error>(2833_error, Error::Type::Info, "There are more than 256 infos. Ignoring the rest."));
103102

104103
if (m_infoCount >= c_maxInfosAllowed)
105104
return true;
@@ -110,21 +109,21 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
110109

111110
if (m_errorCount > c_maxErrorsAllowed)
112111
{
113-
m_errorList.push_back(make_shared<Error>(4013_error, Error::Type::Warning, "There are more than 256 errors. Aborting."));
112+
m_errorList.push_back(std::make_shared<Error>(4013_error, Error::Type::Warning, "There are more than 256 errors. Aborting."));
114113
BOOST_THROW_EXCEPTION(FatalError());
115114
}
116115
}
117116

118117
return false;
119118
}
120119

121-
void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
120+
void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description)
122121
{
123122
error(_error, _type, _location, _secondaryLocation, _description);
124123
BOOST_THROW_EXCEPTION(FatalError());
125124
}
126125

127-
void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, string const& _description)
126+
void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, std::string const& _description)
128127
{
129128
error(_error, _type, _location, _description);
130129
BOOST_THROW_EXCEPTION(FatalError());
@@ -140,7 +139,7 @@ void ErrorReporter::clear()
140139
m_errorList.clear();
141140
}
142141

143-
void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
142+
void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description)
144143
{
145144
error(
146145
_error,
@@ -151,7 +150,7 @@ void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _loca
151150
);
152151
}
153152

154-
void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, string const& _description)
153+
void ErrorReporter::declarationError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
155154
{
156155
error(
157156
_error,
@@ -170,7 +169,7 @@ void ErrorReporter::fatalDeclarationError(ErrorId _error, SourceLocation const&
170169
_description);
171170
}
172171

173-
void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, string const& _description)
172+
void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
174173
{
175174
error(
176175
_error,
@@ -180,7 +179,7 @@ void ErrorReporter::parserError(ErrorId _error, SourceLocation const& _location,
180179
);
181180
}
182181

183-
void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _location, string const& _description)
182+
void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
184183
{
185184
fatalError(
186185
_error,
@@ -190,7 +189,7 @@ void ErrorReporter::fatalParserError(ErrorId _error, SourceLocation const& _loca
190189
);
191190
}
192191

193-
void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, string const& _description)
192+
void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
194193
{
195194
error(
196195
_error,
@@ -200,7 +199,7 @@ void ErrorReporter::syntaxError(ErrorId _error, SourceLocation const& _location,
200199
);
201200
}
202201

203-
void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
202+
void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description)
204203
{
205204
error(
206205
_error,
@@ -211,7 +210,7 @@ void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, S
211210
);
212211
}
213212

214-
void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, string const& _description)
213+
void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
215214
{
216215
error(
217216
_error,
@@ -222,7 +221,7 @@ void ErrorReporter::typeError(ErrorId _error, SourceLocation const& _location, s
222221
}
223222

224223

225-
void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
224+
void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description)
226225
{
227226
fatalError(
228227
_error,
@@ -233,7 +232,7 @@ void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _locati
233232
);
234233
}
235234

236-
void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, string const& _description)
235+
void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
237236
{
238237
fatalError(
239238
_error,
@@ -243,7 +242,7 @@ void ErrorReporter::fatalTypeError(ErrorId _error, SourceLocation const& _locati
243242
);
244243
}
245244

246-
void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& _location, string const& _description)
245+
void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const& _location, std::string const& _description)
247246
{
248247
error(
249248
_error,
@@ -256,13 +255,13 @@ void ErrorReporter::docstringParsingError(ErrorId _error, SourceLocation const&
256255
void ErrorReporter::info(
257256
ErrorId _error,
258257
SourceLocation const& _location,
259-
string const& _description
258+
std::string const& _description
260259
)
261260
{
262261
error(_error, Error::Type::Info, _location, _description);
263262
}
264263

265-
void ErrorReporter::info(ErrorId _error, string const& _description)
264+
void ErrorReporter::info(ErrorId _error, std::string const& _description)
266265
{
267266
error(_error, Error::Type::Info, SourceLocation(), _description);
268267
}

0 commit comments

Comments
 (0)