Skip to content

Commit 9630b54

Browse files
committed
Cleanup
1 parent 6d5edf8 commit 9630b54

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

libyul/AsmJsonImporter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ T AsmJsonImporter::createAsmNode(Json const& _node)
6161

6262
Json AsmJsonImporter::member(Json const& _node, string const& _name)
6363
{
64-
if (_node.find(_name) == _node.end())
64+
if (!_node.contains(_name))
6565
return Json(nullptr);
6666
return _node[_name];
6767
}
@@ -157,7 +157,7 @@ Literal AsmJsonImporter::createLiteral(Json const& _node)
157157
string kind = member(_node, "kind").get<string>();
158158

159159
solAssert(member(_node, "hexValue").is_string() || member(_node, "value").is_string(), "");
160-
if (_node.find("hexValue") != _node.end())
160+
if (_node.contains("hexValue"))
161161
lit.value = YulString{util::asString(util::fromHex(member(_node, "hexValue").get<string>()))};
162162
else
163163
lit.value = YulString{member(_node, "value").get<string>()};
@@ -215,7 +215,7 @@ Assignment AsmJsonImporter::createAssignment(Json const& _node)
215215
{
216216
auto assignment = createAsmNode<Assignment>(_node);
217217

218-
if (_node.find("variableNames") != _node.end())
218+
if (_node.contains("variableNames"))
219219
for (auto const& var: member(_node, "variableNames"))
220220
assignment.variableNames.emplace_back(createIdentifier(var));
221221

@@ -256,11 +256,11 @@ FunctionDefinition AsmJsonImporter::createFunctionDefinition(Json const& _node)
256256
auto funcDef = createAsmNode<FunctionDefinition>(_node);
257257
funcDef.name = YulString{member(_node, "name").get<string>()};
258258

259-
if (_node.find("parameters") != _node.end())
259+
if (_node.contains("parameters"))
260260
for (auto const& var: member(_node, "parameters"))
261261
funcDef.parameters.emplace_back(createTypedName(var));
262262

263-
if (_node.find("returnVariables") != _node.end())
263+
if (_node.contains("returnVariables"))
264264
for (auto const& var: member(_node, "returnVariables"))
265265
funcDef.returnVariables.emplace_back(createTypedName(var));
266266

solc/CommandLineInterface.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
252252

253253
Json methodIdentifiers = m_compiler->methodIdentifiers(_contract);
254254
string out;
255-
for (auto const& name: methodIdentifiers.items())
256-
out += methodIdentifiers[name.key()].get<string>() + ": " + name.key() + "\n";
255+
for (auto const& [name, hash]: methodIdentifiers.items())
256+
out += hash.get<string>() + ": " + name + "\n";
257257

258258
if (!m_options.output.dir.empty())
259259
createFile(m_compiler->filesystemFriendlyName(_contract) + ".signatures", out);
@@ -355,24 +355,24 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
355355
{
356356
Json externalFunctions = estimates["external"];
357357
sout() << "external:" << endl;
358-
for (auto const& name: externalFunctions.items())
358+
for (auto const& [name, gas]: externalFunctions.items())
359359
{
360-
if (name.key().empty())
360+
if (name.empty())
361361
sout() << " fallback:\t";
362362
else
363-
sout() << " " << name.key() << ":\t";
364-
sout() << externalFunctions[name.key()].get<string>() << endl;
363+
sout() << " " << name << ":\t";
364+
sout() << gas.get<string>() << endl;
365365
}
366366
}
367367

368368
if (estimates["internal"].is_object())
369369
{
370370
Json internalFunctions = estimates["internal"];
371371
sout() << "internal:" << endl;
372-
for (auto const& name: internalFunctions.items())
372+
for (auto const& [name, gas]: internalFunctions.items())
373373
{
374-
sout() << " " << name.key() << ":\t";
375-
sout() << internalFunctions[name.key()].get<string>() << endl;
374+
sout() << " " << name << ":\t";
375+
sout() << gas.get<string>() << endl;
376376
}
377377
}
378378
}
@@ -472,13 +472,13 @@ map<string, Json> CommandLineInterface::parseAstFromInput()
472472
{
473473
Json ast;
474474
astAssert(jsonParseStrict(sourceCode, ast), "Input file could not be parsed to JSON");
475-
astAssert(ast.find("sources") != ast.end(), "Invalid Format for import-JSON: Must have 'sources'-object");
475+
astAssert(ast.contains("sources"), "Invalid Format for import-JSON: Must have 'sources'-object");
476476

477477
for (auto const& [src, _]: ast["sources"].items())
478478
{
479-
std::string astKey = ast["sources"][src].count("ast") ? "ast" : "AST";
479+
std::string astKey = ast["sources"][src].contains("ast") ? "ast" : "AST";
480480

481-
astAssert(ast["sources"][src].count(astKey), "astkey is not member");
481+
astAssert(ast["sources"][src].contains(astKey), "astkey is not member");
482482
astAssert(ast["sources"][src][astKey]["nodeType"].get<string>() == "SourceUnit", "Top-level node should be a 'SourceUnit'");
483483
astAssert(sourceJsons.count(src) == 0, "All sources must have unique names");
484484
sourceJsons.emplace(src, move(ast["sources"][src][astKey]));
@@ -720,7 +720,7 @@ void CommandLineInterface::handleCombinedJSON()
720720
vector<string> contracts = m_compiler->contractNames();
721721

722722
if (!contracts.empty())
723-
output[g_strContracts] = Json(Json::object());
723+
output[g_strContracts] = Json::object();
724724
for (string const& contractName: contracts)
725725
{
726726
Json& contractData = output[g_strContracts][contractName] = Json::object();
@@ -775,19 +775,19 @@ void CommandLineInterface::handleCombinedJSON()
775775
if (needsSourceList)
776776
{
777777
// Indices into this array are used to abbreviate source names in source locations.
778-
output[g_strSourceList] = Json(Json::array());
778+
output[g_strSourceList] = Json::array();
779779

780780
for (auto const& source: m_compiler->sourceNames())
781781
output[g_strSourceList].emplace_back(source);
782782
}
783783

784784
if (m_options.compiler.combinedJsonRequests->ast)
785785
{
786-
output[g_strSources] = Json(Json::object());
786+
output[g_strSources] = Json::object();
787787
for (auto const& sourceCode: m_fileReader.sourceCodes())
788788
{
789789
ASTJsonConverter converter(m_compiler->state(), m_compiler->sourceIndices());
790-
output[g_strSources][sourceCode.first] = Json(Json::object());
790+
output[g_strSources][sourceCode.first] = Json::object();
791791
output[g_strSources][sourceCode.first]["AST"] = converter.toJson(m_compiler->ast(sourceCode.first));
792792
}
793793
}

test/libsolidity/StandardCompiler.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ langutil::Error::Severity str2Severity(string const& _cat)
6565
/// Helper to match a specific error type and message
6666
bool containsError(Json const& _compilerResult, string const& _type, string const& _message)
6767
{
68-
if (!_compilerResult.count("errors"))
68+
if (!_compilerResult.contains("errors"))
6969
return false;
7070

7171
for (auto const& error: _compilerResult["errors"])
@@ -82,7 +82,7 @@ bool containsError(Json const& _compilerResult, string const& _type, string cons
8282

8383
bool containsAtMostWarnings(Json const& _compilerResult)
8484
{
85-
if (!_compilerResult.count("errors"))
85+
if (!_compilerResult.contains("errors"))
8686
return true;
8787

8888
for (auto const& error: _compilerResult["errors"])
@@ -143,10 +143,10 @@ void expectLinkReferences(Json const& _contractResult, map<string, set<string>>
143143

144144
for (auto const& [fileName, libraries]: _expectedLinkReferences)
145145
{
146-
BOOST_TEST(linkReferenceResult.count(fileName));
146+
BOOST_TEST(linkReferenceResult.contains(fileName));
147147
BOOST_TEST(linkReferenceResult[fileName].size() == libraries.size());
148148
for (string const& libraryName: libraries)
149-
BOOST_TEST(linkReferenceResult[fileName].count(libraryName));
149+
BOOST_TEST(linkReferenceResult[fileName].contains(libraryName));
150150
}
151151
}
152152

@@ -522,7 +522,7 @@ BOOST_AUTO_TEST_CASE(compilation_error)
522522
}
523523
)";
524524
Json result = compile(input);
525-
BOOST_CHECK(result.count("errors"));
525+
BOOST_CHECK(result.contains("errors"));
526526
BOOST_CHECK(result["errors"].size() >= 1);
527527
for (auto const& error: result["errors"])
528528
{
@@ -1125,9 +1125,9 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_default_disabled)
11251125
BOOST_CHECK(util::jsonParseStrict(contract["metadata"].get<string>(), metadata));
11261126

11271127
Json const& optimizer = metadata["settings"]["optimizer"];
1128-
BOOST_CHECK(optimizer.count("enabled"));
1128+
BOOST_CHECK(optimizer.contains("enabled"));
11291129
BOOST_CHECK(optimizer["enabled"].get<bool>() == false);
1130-
BOOST_CHECK(!optimizer.count("details"));
1130+
BOOST_CHECK(!optimizer.contains("details"));
11311131
BOOST_CHECK(optimizer["runs"].get<Json::number_unsigned_t>() == 200);
11321132
}
11331133

@@ -1158,9 +1158,9 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_default_enabled)
11581158
BOOST_CHECK(util::jsonParseStrict(contract["metadata"].get<string>(), metadata));
11591159

11601160
Json const& optimizer = metadata["settings"]["optimizer"];
1161-
BOOST_CHECK(optimizer.count("enabled"));
1161+
BOOST_CHECK(optimizer.contains("enabled"));
11621162
BOOST_CHECK(optimizer["enabled"].get<bool>() == true);
1163-
BOOST_CHECK(!optimizer.count("details"));
1163+
BOOST_CHECK(!optimizer.contains("details"));
11641164
BOOST_CHECK(optimizer["runs"].get<Json::number_unsigned_t>() == 200);
11651165
}
11661166

@@ -1198,10 +1198,10 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_details_exactly_as_default_disabled)
11981198
BOOST_CHECK(util::jsonParseStrict(contract["metadata"].get<string>(), metadata));
11991199

12001200
Json const& optimizer = metadata["settings"]["optimizer"];
1201-
BOOST_CHECK(optimizer.count("enabled"));
1201+
BOOST_CHECK(optimizer.contains("enabled"));
12021202
// enabled is switched to false instead!
12031203
BOOST_CHECK(optimizer["enabled"].get<bool>() == false);
1204-
BOOST_CHECK(!optimizer.count("details"));
1204+
BOOST_CHECK(!optimizer.contains("details"));
12051205
BOOST_CHECK(optimizer["runs"].get<Json::number_unsigned_t>() == 200);
12061206
}
12071207

@@ -1241,8 +1241,8 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_details_different)
12411241
BOOST_CHECK(util::jsonParseStrict(contract["metadata"].get<string>(), metadata));
12421242

12431243
Json const& optimizer = metadata["settings"]["optimizer"];
1244-
BOOST_CHECK(!optimizer.count("enabled"));
1245-
BOOST_CHECK(optimizer.count("details"));
1244+
BOOST_CHECK(!optimizer.contains("enabled"));
1245+
BOOST_CHECK(optimizer.contains("details"));
12461246
BOOST_CHECK(optimizer["details"]["constantOptimizer"].get<bool>() == true);
12471247
BOOST_CHECK(optimizer["details"]["cse"].get<bool>() == false);
12481248
BOOST_CHECK(optimizer["details"]["deduplicate"].get<bool>() == true);

test/tools/fuzzer_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void FuzzerUtil::runCompiler(string const& _input, bool _quiet)
152152
cout << msg << endl;
153153
BOOST_THROW_EXCEPTION(std::runtime_error(std::move(msg)));
154154
}
155-
if (output.count("errors"))
155+
if (output.contains("errors"))
156156
for (auto const& error: output["errors"])
157157
{
158158
string invalid = findAnyOf(error["type"].get<string>(), vector<string>{

0 commit comments

Comments
 (0)