Skip to content

Commit 72671d6

Browse files
authored
Merge pull request #14581 from ethereum/purge-using-namespace-std-from-test-libsolidity-util
Purge using namespace std from test/libsolidity/util
2 parents 2ba536f + fa39401 commit 72671d6

File tree

9 files changed

+204
-211
lines changed

9 files changed

+204
-211
lines changed

scripts/check_style.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ NAMESPACE_STD_FREE_FILES=(
4545
test/libsolidity/*
4646
test/libsolidity/analysis/*
4747
test/libsolidity/interface/*
48+
test/libsolidity/util/*
4849
)
4950

5051
(

test/libsolidity/util/BytesUtils.cpp

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ using namespace solidity;
3737
using namespace solidity::util;
3838
using namespace solidity::frontend;
3939
using namespace solidity::frontend::test;
40-
using namespace std;
4140

4241
bytes BytesUtils::alignLeft(bytes _bytes)
4342
{
@@ -73,7 +72,7 @@ bytes BytesUtils::applyAlign(
7372
}
7473
}
7574

76-
bytes BytesUtils::convertBoolean(string const& _literal)
75+
bytes BytesUtils::convertBoolean(std::string const& _literal)
7776
{
7877
if (_literal == "true")
7978
return bytes{true};
@@ -83,7 +82,7 @@ bytes BytesUtils::convertBoolean(string const& _literal)
8382
BOOST_THROW_EXCEPTION(TestParserError("Boolean literal invalid."));
8483
}
8584

86-
bytes BytesUtils::convertNumber(string const& _literal)
85+
bytes BytesUtils::convertNumber(std::string const& _literal)
8786
{
8887
try
8988
{
@@ -95,13 +94,13 @@ bytes BytesUtils::convertNumber(string const& _literal)
9594
}
9695
}
9796

98-
bytes BytesUtils::convertFixedPoint(string const& _literal, size_t& o_fractionalDigits)
97+
bytes BytesUtils::convertFixedPoint(std::string const& _literal, size_t& o_fractionalDigits)
9998
{
10099
size_t dotPos = _literal.find('.');
101100
o_fractionalDigits = dotPos < _literal.size() ? _literal.size() - dotPos : 0;
102101
bool negative = !_literal.empty() && _literal.at(0) == '-';
103102
// remove decimal point
104-
string valueInteger = _literal.substr(0, dotPos) + _literal.substr(dotPos + 1);
103+
std::string valueInteger = _literal.substr(0, dotPos) + _literal.substr(dotPos + 1);
105104
// erase leading zeros to avoid parsing as octal.
106105
while (!valueInteger.empty() && (valueInteger.at(0) == '0' || valueInteger.at(0) == '-'))
107106
valueInteger.erase(valueInteger.begin());
@@ -120,7 +119,7 @@ bytes BytesUtils::convertFixedPoint(string const& _literal, size_t& o_fractional
120119
}
121120
}
122121

123-
bytes BytesUtils::convertHexNumber(string const& _literal)
122+
bytes BytesUtils::convertHexNumber(std::string const& _literal)
124123
{
125124
try
126125
{
@@ -132,7 +131,7 @@ bytes BytesUtils::convertHexNumber(string const& _literal)
132131
}
133132
}
134133

135-
bytes BytesUtils::convertString(string const& _literal)
134+
bytes BytesUtils::convertString(std::string const& _literal)
136135
{
137136
try
138137
{
@@ -144,18 +143,18 @@ bytes BytesUtils::convertString(string const& _literal)
144143
}
145144
}
146145

147-
string BytesUtils::formatUnsigned(bytes const& _bytes)
146+
std::string BytesUtils::formatUnsigned(bytes const& _bytes)
148147
{
149-
stringstream os;
148+
std::stringstream os;
150149

151150
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
152151

153152
return fromBigEndian<u256>(_bytes).str();
154153
}
155154

156-
string BytesUtils::formatSigned(bytes const& _bytes)
155+
std::string BytesUtils::formatSigned(bytes const& _bytes)
157156
{
158-
stringstream os;
157+
std::stringstream os;
159158

160159
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
161160

@@ -167,9 +166,9 @@ string BytesUtils::formatSigned(bytes const& _bytes)
167166
return os.str();
168167
}
169168

170-
string BytesUtils::formatBoolean(bytes const& _bytes)
169+
std::string BytesUtils::formatBoolean(bytes const& _bytes)
171170
{
172-
stringstream os;
171+
std::stringstream os;
173172
u256 result = fromBigEndian<u256>(_bytes);
174173

175174
if (result == 0)
@@ -182,32 +181,32 @@ string BytesUtils::formatBoolean(bytes const& _bytes)
182181
return os.str();
183182
}
184183

185-
string BytesUtils::formatHex(bytes const& _bytes, bool _shorten)
184+
std::string BytesUtils::formatHex(bytes const& _bytes, bool _shorten)
186185
{
187186
soltestAssert(!_bytes.empty() && _bytes.size() <= 32, "");
188187
u256 value = fromBigEndian<u256>(_bytes);
189-
string output = toCompactHexWithPrefix(value);
188+
std::string output = toCompactHexWithPrefix(value);
190189

191190
if (_shorten)
192191
return output.substr(0, output.size() - countRightPaddedZeros(_bytes) * 2);
193192
return output;
194193
}
195194

196-
string BytesUtils::formatHexString(bytes const& _bytes)
195+
std::string BytesUtils::formatHexString(bytes const& _bytes)
197196
{
198-
stringstream os;
197+
std::stringstream os;
199198

200199
os << "hex\"" << util::toHex(_bytes) << "\"";
201200

202201
return os.str();
203202
}
204203

205-
string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
204+
std::string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
206205
{
207-
stringstream os;
206+
std::stringstream os;
208207

209208
os << "\"";
210-
for (size_t i = 0; i < min(_cutOff, _bytes.size()); ++i)
209+
for (size_t i = 0; i < std::min(_cutOff, _bytes.size()); ++i)
211210
{
212211
auto const v = _bytes[i];
213212
switch (v)
@@ -232,7 +231,7 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
232231

233232
std::string BytesUtils::formatFixedPoint(bytes const& _bytes, bool _signed, size_t _fractionalDigits)
234233
{
235-
string decimal;
234+
std::string decimal;
236235
bool negative = false;
237236
if (_signed)
238237
{
@@ -246,19 +245,19 @@ std::string BytesUtils::formatFixedPoint(bytes const& _bytes, bool _signed, size
246245
{
247246
size_t numDigits = decimal.length() - (negative ? 1 : 0);
248247
if (_fractionalDigits >= numDigits)
249-
decimal.insert(negative ? 1 : 0, string(_fractionalDigits + 1 - numDigits, '0'));
248+
decimal.insert(negative ? 1 : 0, std::string(_fractionalDigits + 1 - numDigits, '0'));
250249
decimal.insert(decimal.length() - _fractionalDigits, ".");
251250
}
252251
return decimal;
253252
}
254253

255-
string BytesUtils::formatRawBytes(
254+
std::string BytesUtils::formatRawBytes(
256255
bytes const& _bytes,
257256
solidity::frontend::test::ParameterList const& _parameters,
258-
string _linePrefix
257+
std::string _linePrefix
259258
)
260259
{
261-
stringstream os;
260+
std::stringstream os;
262261
ParameterList parameters;
263262
auto it = _bytes.begin();
264263

@@ -283,7 +282,7 @@ string BytesUtils::formatRawBytes(
283282

284283
for (auto const& parameter: parameters)
285284
{
286-
long actualSize = min(
285+
long actualSize = std::min(
287286
distance(it, _bytes.end()),
288287
static_cast<ParameterList::difference_type>(parameter.abiType.size)
289288
);
@@ -292,20 +291,20 @@ string BytesUtils::formatRawBytes(
292291

293292
os << _linePrefix << byteRange;
294293
if (&parameter != &parameters.back())
295-
os << endl;
294+
os << std::endl;
296295

297296
it += actualSize;
298297
}
299298

300299
return os.str();
301300
}
302301

303-
string BytesUtils::formatBytes(
302+
std::string BytesUtils::formatBytes(
304303
bytes const& _bytes,
305304
ABIType const& _abiType
306305
)
307306
{
308-
stringstream os;
307+
std::stringstream os;
309308

310309
switch (_abiType.type)
311310
{
@@ -330,7 +329,7 @@ string BytesUtils::formatBytes(
330329
{
331330
auto entropy = [](std::string const& str) -> double {
332331
double result = 0;
333-
map<char, double> frequencies;
332+
std::map<char, double> frequencies;
334333
for (char c: str)
335334
frequencies[c]++;
336335
for (auto p: frequencies)
@@ -376,13 +375,13 @@ string BytesUtils::formatBytes(
376375
return os.str();
377376
}
378377

379-
string BytesUtils::formatBytesRange(
378+
std::string BytesUtils::formatBytesRange(
380379
bytes _bytes,
381380
solidity::frontend::test::ParameterList const& _parameters,
382381
bool _highlight
383382
)
384383
{
385-
stringstream os;
384+
std::stringstream os;
386385
ParameterList parameters;
387386
auto it = _bytes.begin();
388387

@@ -407,7 +406,7 @@ string BytesUtils::formatBytesRange(
407406

408407
for (auto const& parameter: parameters)
409408
{
410-
long actualSize = min(
409+
long actualSize = std::min(
411410
distance(it, _bytes.end()),
412411
static_cast<ParameterList::difference_type>(parameter.abiType.size)
413412
);

test/libsolidity/util/BytesUtilsTests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include <libsolutil/CommonData.h>
2424

25-
using namespace std;
2625
using namespace solidity::util;
2726
using namespace solidity::test;
2827

test/libsolidity/util/Common.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@
2020

2121
#include <regex>
2222

23-
using namespace std;
2423
using namespace solidity;
2524
using namespace solidity::frontend;
2625

27-
string test::withPreamble(string const& _sourceCode, bool _addAbicoderV1Pragma)
26+
std::string test::withPreamble(std::string const& _sourceCode, bool _addAbicoderV1Pragma)
2827
{
29-
static string const versionPragma = "pragma solidity >=0.0;\n";
30-
static string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n";
31-
static string const abicoderPragma = "pragma abicoder v1;\n";
28+
static std::string const versionPragma = "pragma solidity >=0.0;\n";
29+
static std::string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n";
30+
static std::string const abicoderPragma = "pragma abicoder v1;\n";
3231

3332
// NOTE: These checks are intentionally loose to match weird cases.
3433
// We can manually adjust a test case where this causes problem.
35-
bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == string::npos;
34+
bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == std::string::npos;
3635
bool abicoderMissing =
37-
_sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos &&
38-
_sourceCode.find("pragma abicoder") == string::npos;
36+
_sourceCode.find("pragma experimental ABIEncoderV2;") == std::string::npos &&
37+
_sourceCode.find("pragma abicoder") == std::string::npos;
3938

4039
return
4140
versionPragma +
@@ -52,16 +51,16 @@ StringMap test::withPreamble(StringMap _sources, bool _addAbicoderV1Pragma)
5251
return _sources;
5352
}
5453

55-
string test::stripPreReleaseWarning(string const& _stderrContent)
54+
std::string test::stripPreReleaseWarning(std::string const& _stderrContent)
5655
{
57-
static regex const preReleaseWarningRegex{
56+
static std::regex const preReleaseWarningRegex{
5857
R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)"
5958
R"((\n)?)"
6059
};
61-
static regex const noOutputRegex{
60+
static std::regex const noOutputRegex{
6261
R"(Compiler run successful, no output requested\.\n)"
6362
};
6463

65-
string output = regex_replace(_stderrContent, preReleaseWarningRegex, "");
66-
return regex_replace(std::move(output), noOutputRegex, "");
64+
std::string output = std::regex_replace(_stderrContent, preReleaseWarningRegex, "");
65+
return std::regex_replace(std::move(output), noOutputRegex, "");
6766
}

0 commit comments

Comments
 (0)