Skip to content

Commit 1c4145d

Browse files
committed
CommandLineParser: Remove any_of / none_of.
1 parent 7b644c5 commit 1c4145d

File tree

3 files changed

+20
-63
lines changed

3 files changed

+20
-63
lines changed

solc/CommandLineInterface.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ using namespace solidity::langutil;
9292
namespace
9393
{
9494

95-
std::vector<frontend::InputMode> ValidInputModes{
95+
std::set<frontend::InputMode> ValidInputModes{
9696
frontend::InputMode::Compiler,
9797
frontend::InputMode::CompilerWithASTImport,
9898
frontend::InputMode::CompilerWithEvmAssemblyJsonImport
@@ -172,7 +172,7 @@ static bool coloredOutput(CommandLineOptions const& _options)
172172

173173
void CommandLineInterface::handleBinary(string const& _contract)
174174
{
175-
solAssert(any_of(m_options.input.mode, ValidInputModes));
175+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
176176

177177
if (m_options.compiler.outputs.binary)
178178
{
@@ -198,7 +198,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
198198

199199
void CommandLineInterface::handleOpcode(string const& _contract)
200200
{
201-
solAssert(any_of(m_options.input.mode, ValidInputModes));
201+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
202202

203203
if (!m_options.output.dir.empty())
204204
createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", evmasm::disassemble(m_compiler->object(_contract).bytecode));
@@ -212,7 +212,7 @@ void CommandLineInterface::handleOpcode(string const& _contract)
212212

213213
void CommandLineInterface::handleIR(string const& _contractName)
214214
{
215-
solAssert(any_of(m_options.input.mode, ValidInputModes));
215+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
216216

217217
if (!m_options.compiler.outputs.ir)
218218
return;
@@ -228,7 +228,7 @@ void CommandLineInterface::handleIR(string const& _contractName)
228228

229229
void CommandLineInterface::handleIROptimized(string const& _contractName)
230230
{
231-
solAssert(any_of(m_options.input.mode, ValidInputModes));
231+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
232232

233233
if (!m_options.compiler.outputs.irOptimized)
234234
return;
@@ -244,7 +244,7 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
244244

245245
void CommandLineInterface::handleEwasm(string const& _contractName)
246246
{
247-
solAssert(any_of(m_options.input.mode, ValidInputModes));
247+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
248248

249249
if (!m_options.compiler.outputs.ewasm)
250250
return;
@@ -267,7 +267,7 @@ void CommandLineInterface::handleEwasm(string const& _contractName)
267267

268268
void CommandLineInterface::handleBytecode(string const& _contract)
269269
{
270-
solAssert(any_of(m_options.input.mode, ValidInputModes));
270+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
271271

272272
if (m_options.compiler.outputs.opcodes)
273273
handleOpcode(_contract);
@@ -277,7 +277,7 @@ void CommandLineInterface::handleBytecode(string const& _contract)
277277

278278
void CommandLineInterface::handleSignatureHashes(string const& _contract)
279279
{
280-
solAssert(any_of(m_options.input.mode, ValidInputModes));
280+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
281281

282282
if (!m_options.compiler.outputs.signatureHashes)
283283
return;
@@ -309,7 +309,7 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
309309

310310
void CommandLineInterface::handleMetadata(string const& _contract)
311311
{
312-
solAssert(any_of(m_options.input.mode, ValidInputModes));
312+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
313313

314314
if (!m_options.compiler.outputs.metadata)
315315
return;
@@ -323,7 +323,7 @@ void CommandLineInterface::handleMetadata(string const& _contract)
323323

324324
void CommandLineInterface::handleABI(string const& _contract)
325325
{
326-
solAssert(any_of(m_options.input.mode, ValidInputModes));
326+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
327327

328328
if (!m_options.compiler.outputs.abi)
329329
return;
@@ -337,7 +337,7 @@ void CommandLineInterface::handleABI(string const& _contract)
337337

338338
void CommandLineInterface::handleStorageLayout(string const& _contract)
339339
{
340-
solAssert(any_of(m_options.input.mode, ValidInputModes));
340+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
341341

342342
if (!m_options.compiler.outputs.storageLayout)
343343
return;
@@ -351,7 +351,7 @@ void CommandLineInterface::handleStorageLayout(string const& _contract)
351351

352352
void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contract)
353353
{
354-
solAssert(any_of(m_options.input.mode, ValidInputModes));
354+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
355355

356356
bool enabled = false;
357357
std::string suffix;
@@ -394,7 +394,7 @@ void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contra
394394

395395
void CommandLineInterface::handleGasEstimation(string const& _contract)
396396
{
397-
solAssert(any_of(m_options.input.mode, ValidInputModes));
397+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
398398

399399
Json::Value estimates = m_compiler->gasEstimates(_contract);
400400
sout() << "Gas estimation:" << endl;
@@ -438,7 +438,7 @@ void CommandLineInterface::readInputFiles()
438438
{
439439
solAssert(!m_standardJsonInput.has_value());
440440

441-
if (any_of(m_options.input.mode, {InputMode::Help, InputMode::License, InputMode::Version}))
441+
if (std::set<InputMode>{InputMode::Help, InputMode::License, InputMode::Version}.count(m_options.input.mode) == 1)
442442
return;
443443

444444
m_fileReader.setBasePath(m_options.input.basePath);
@@ -706,7 +706,7 @@ void CommandLineInterface::printLicense()
706706

707707
void CommandLineInterface::compile()
708708
{
709-
solAssert(any_of(m_options.input.mode, ValidInputModes));
709+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
710710

711711
m_compiler = make_unique<CompilerStack>(m_fileReader.reader());
712712

@@ -824,7 +824,7 @@ void CommandLineInterface::compile()
824824

825825
void CommandLineInterface::handleCombinedJSON()
826826
{
827-
solAssert(any_of(m_options.input.mode, ValidInputModes));
827+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
828828

829829
if (!m_options.compiler.combinedJsonRequests.has_value())
830830
return;
@@ -916,7 +916,7 @@ void CommandLineInterface::handleCombinedJSON()
916916

917917
void CommandLineInterface::handleAst()
918918
{
919-
solAssert(any_of(m_options.input.mode, ValidInputModes));
919+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
920920

921921
if (!m_options.compiler.outputs.astCompactJson)
922922
return;
@@ -1141,7 +1141,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
11411141
serr() << "No binary representation found." << endl;
11421142
}
11431143

1144-
solAssert(any_of(_targetMachine, {yul::YulStack::Machine::Ewasm, yul::YulStack::Machine::EVM}));
1144+
solAssert(_targetMachine == yul::YulStack::Machine::Ewasm || _targetMachine == yul::YulStack::Machine::EVM, "");
11451145
if (
11461146
(_targetMachine == yul::YulStack::Machine::EVM && m_options.compiler.outputs.asm_) ||
11471147
(_targetMachine == yul::YulStack::Machine::Ewasm && m_options.compiler.outputs.ewasm)
@@ -1158,7 +1158,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
11581158

11591159
void CommandLineInterface::outputCompilationResults()
11601160
{
1161-
solAssert(any_of(m_options.input.mode, ValidInputModes));
1161+
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
11621162

11631163
handleCombinedJSON();
11641164

solc/CommandLineParser.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,4 @@ class CommandLineParser
294294
boost::program_options::variables_map m_args;
295295
};
296296

297-
template<typename T>
298-
bool any_of(T& _what, std::vector<T> _elements)
299-
{
300-
for (auto const& element: _elements)
301-
if (_what == element)
302-
return true;
303-
return false;
304-
}
305-
306-
template<typename T>
307-
bool none_of(T& _what, std::vector<T> _elements)
308-
{
309-
return !any_of(_what, _elements);
310-
}
311-
312-
}
297+
} // namespace solidity::frontend

test/solc/CommandLineParser.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -224,34 +224,6 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
224224
}
225225
}
226226

227-
BOOST_AUTO_TEST_CASE(CommandLineOptions_any_of)
228-
{
229-
std::vector<InputMode> help_license{InputMode::Help, InputMode::License};
230-
CommandLineOptions help = parseCommandLine({"solc", "--help"});
231-
CommandLineOptions license = parseCommandLine({"solc", "--license"});
232-
CommandLineOptions version = parseCommandLine({"solc", "--version"});
233-
BOOST_TEST(any_of(help.input.mode, {InputMode::Help, InputMode::License}));
234-
BOOST_TEST(any_of(license.input.mode, {InputMode::Help, InputMode::License}));
235-
BOOST_TEST(any_of(help.input.mode, help_license));
236-
BOOST_TEST(any_of(license.input.mode, help_license));
237-
BOOST_TEST(!any_of(version.input.mode, help_license));
238-
BOOST_TEST(any_of(version.input.mode, {InputMode::Version}));
239-
}
240-
241-
BOOST_AUTO_TEST_CASE(CommandLineOptions_none_of)
242-
{
243-
std::vector<InputMode> help_license{InputMode::Help, InputMode::License};
244-
CommandLineOptions help = parseCommandLine({"solc", "--help"});
245-
CommandLineOptions license = parseCommandLine({"solc", "--license"});
246-
CommandLineOptions version = parseCommandLine({"solc", "--version"});
247-
BOOST_TEST(!none_of(help.input.mode, {InputMode::Help, InputMode::License}));
248-
BOOST_TEST(!none_of(license.input.mode, {InputMode::Help, InputMode::License}));
249-
BOOST_TEST(!none_of(help.input.mode, help_license));
250-
BOOST_TEST(!none_of(license.input.mode, help_license));
251-
BOOST_TEST(none_of(version.input.mode, help_license));
252-
BOOST_TEST(!none_of(version.input.mode, {InputMode::Version}));
253-
}
254-
255227
BOOST_AUTO_TEST_CASE(via_ir_options)
256228
{
257229
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);

0 commit comments

Comments
 (0)