mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
CommandLineParser: Remove any_of / none_of.
This commit is contained in:
parent
145152038c
commit
1774de0b3f
@ -92,7 +92,7 @@ using namespace solidity::langutil;
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<frontend::InputMode> ValidInputModes{
|
std::set<frontend::InputMode> ValidInputModes{
|
||||||
frontend::InputMode::Compiler,
|
frontend::InputMode::Compiler,
|
||||||
frontend::InputMode::CompilerWithASTImport,
|
frontend::InputMode::CompilerWithASTImport,
|
||||||
frontend::InputMode::CompilerWithEvmAssemblyJsonImport
|
frontend::InputMode::CompilerWithEvmAssemblyJsonImport
|
||||||
@ -172,7 +172,7 @@ static bool coloredOutput(CommandLineOptions const& _options)
|
|||||||
|
|
||||||
void CommandLineInterface::handleBinary(string const& _contract)
|
void CommandLineInterface::handleBinary(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (m_options.compiler.outputs.binary)
|
if (m_options.compiler.outputs.binary)
|
||||||
{
|
{
|
||||||
@ -198,7 +198,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleOpcode(string const& _contract)
|
void CommandLineInterface::handleOpcode(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.output.dir.empty())
|
if (!m_options.output.dir.empty())
|
||||||
createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", evmasm::disassemble(m_compiler->object(_contract).bytecode));
|
createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", evmasm::disassemble(m_compiler->object(_contract).bytecode));
|
||||||
@ -212,7 +212,7 @@ void CommandLineInterface::handleOpcode(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleIR(string const& _contractName)
|
void CommandLineInterface::handleIR(string const& _contractName)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.ir)
|
if (!m_options.compiler.outputs.ir)
|
||||||
return;
|
return;
|
||||||
@ -228,7 +228,7 @@ void CommandLineInterface::handleIR(string const& _contractName)
|
|||||||
|
|
||||||
void CommandLineInterface::handleIROptimized(string const& _contractName)
|
void CommandLineInterface::handleIROptimized(string const& _contractName)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.irOptimized)
|
if (!m_options.compiler.outputs.irOptimized)
|
||||||
return;
|
return;
|
||||||
@ -244,7 +244,7 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
|
|||||||
|
|
||||||
void CommandLineInterface::handleEwasm(string const& _contractName)
|
void CommandLineInterface::handleEwasm(string const& _contractName)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.ewasm)
|
if (!m_options.compiler.outputs.ewasm)
|
||||||
return;
|
return;
|
||||||
@ -267,7 +267,7 @@ void CommandLineInterface::handleEwasm(string const& _contractName)
|
|||||||
|
|
||||||
void CommandLineInterface::handleBytecode(string const& _contract)
|
void CommandLineInterface::handleBytecode(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (m_options.compiler.outputs.opcodes)
|
if (m_options.compiler.outputs.opcodes)
|
||||||
handleOpcode(_contract);
|
handleOpcode(_contract);
|
||||||
@ -277,7 +277,7 @@ void CommandLineInterface::handleBytecode(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleSignatureHashes(string const& _contract)
|
void CommandLineInterface::handleSignatureHashes(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.signatureHashes)
|
if (!m_options.compiler.outputs.signatureHashes)
|
||||||
return;
|
return;
|
||||||
@ -309,7 +309,7 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleMetadata(string const& _contract)
|
void CommandLineInterface::handleMetadata(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.metadata)
|
if (!m_options.compiler.outputs.metadata)
|
||||||
return;
|
return;
|
||||||
@ -323,7 +323,7 @@ void CommandLineInterface::handleMetadata(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleABI(string const& _contract)
|
void CommandLineInterface::handleABI(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.abi)
|
if (!m_options.compiler.outputs.abi)
|
||||||
return;
|
return;
|
||||||
@ -337,7 +337,7 @@ void CommandLineInterface::handleABI(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleStorageLayout(string const& _contract)
|
void CommandLineInterface::handleStorageLayout(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.storageLayout)
|
if (!m_options.compiler.outputs.storageLayout)
|
||||||
return;
|
return;
|
||||||
@ -351,7 +351,7 @@ void CommandLineInterface::handleStorageLayout(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contract)
|
void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
std::string suffix;
|
std::string suffix;
|
||||||
@ -394,7 +394,7 @@ void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contra
|
|||||||
|
|
||||||
void CommandLineInterface::handleGasEstimation(string const& _contract)
|
void CommandLineInterface::handleGasEstimation(string const& _contract)
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
Json::Value estimates = m_compiler->gasEstimates(_contract);
|
Json::Value estimates = m_compiler->gasEstimates(_contract);
|
||||||
sout() << "Gas estimation:" << endl;
|
sout() << "Gas estimation:" << endl;
|
||||||
@ -438,7 +438,7 @@ void CommandLineInterface::readInputFiles()
|
|||||||
{
|
{
|
||||||
solAssert(!m_standardJsonInput.has_value());
|
solAssert(!m_standardJsonInput.has_value());
|
||||||
|
|
||||||
if (any_of(m_options.input.mode, {InputMode::Help, InputMode::License, InputMode::Version}))
|
if (std::set<InputMode>{InputMode::Help, InputMode::License, InputMode::Version}.count(m_options.input.mode) == 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_fileReader.setBasePath(m_options.input.basePath);
|
m_fileReader.setBasePath(m_options.input.basePath);
|
||||||
@ -706,7 +706,7 @@ void CommandLineInterface::printLicense()
|
|||||||
|
|
||||||
void CommandLineInterface::compile()
|
void CommandLineInterface::compile()
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
m_compiler = make_unique<CompilerStack>(m_fileReader.reader());
|
m_compiler = make_unique<CompilerStack>(m_fileReader.reader());
|
||||||
|
|
||||||
@ -824,7 +824,7 @@ void CommandLineInterface::compile()
|
|||||||
|
|
||||||
void CommandLineInterface::handleCombinedJSON()
|
void CommandLineInterface::handleCombinedJSON()
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.combinedJsonRequests.has_value())
|
if (!m_options.compiler.combinedJsonRequests.has_value())
|
||||||
return;
|
return;
|
||||||
@ -916,7 +916,7 @@ void CommandLineInterface::handleCombinedJSON()
|
|||||||
|
|
||||||
void CommandLineInterface::handleAst()
|
void CommandLineInterface::handleAst()
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.astCompactJson)
|
if (!m_options.compiler.outputs.astCompactJson)
|
||||||
return;
|
return;
|
||||||
@ -1141,7 +1141,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
|
|||||||
serr() << "No binary representation found." << endl;
|
serr() << "No binary representation found." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
solAssert(any_of(_targetMachine, {yul::YulStack::Machine::Ewasm, yul::YulStack::Machine::EVM}));
|
solAssert(_targetMachine == yul::YulStack::Machine::Ewasm || _targetMachine == yul::YulStack::Machine::EVM, "");
|
||||||
if (
|
if (
|
||||||
(_targetMachine == yul::YulStack::Machine::EVM && m_options.compiler.outputs.asm_) ||
|
(_targetMachine == yul::YulStack::Machine::EVM && m_options.compiler.outputs.asm_) ||
|
||||||
(_targetMachine == yul::YulStack::Machine::Ewasm && m_options.compiler.outputs.ewasm)
|
(_targetMachine == yul::YulStack::Machine::Ewasm && m_options.compiler.outputs.ewasm)
|
||||||
@ -1158,7 +1158,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
|
|||||||
|
|
||||||
void CommandLineInterface::outputCompilationResults()
|
void CommandLineInterface::outputCompilationResults()
|
||||||
{
|
{
|
||||||
solAssert(any_of(m_options.input.mode, ValidInputModes));
|
solAssert(ValidInputModes.count(m_options.input.mode) == 1);
|
||||||
|
|
||||||
handleCombinedJSON();
|
handleCombinedJSON();
|
||||||
|
|
||||||
|
@ -294,19 +294,4 @@ private:
|
|||||||
boost::program_options::variables_map m_args;
|
boost::program_options::variables_map m_args;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
} // namespace solidity::frontend
|
||||||
bool any_of(T& _what, std::vector<T> _elements)
|
|
||||||
{
|
|
||||||
for (auto const& element: _elements)
|
|
||||||
if (_what == element)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool none_of(T& _what, std::vector<T> _elements)
|
|
||||||
{
|
|
||||||
return !any_of(_what, _elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -224,34 +224,6 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(CommandLineOptions_any_of)
|
|
||||||
{
|
|
||||||
std::vector<InputMode> help_license{InputMode::Help, InputMode::License};
|
|
||||||
CommandLineOptions help = parseCommandLine({"solc", "--help"});
|
|
||||||
CommandLineOptions license = parseCommandLine({"solc", "--license"});
|
|
||||||
CommandLineOptions version = parseCommandLine({"solc", "--version"});
|
|
||||||
BOOST_TEST(any_of(help.input.mode, {InputMode::Help, InputMode::License}));
|
|
||||||
BOOST_TEST(any_of(license.input.mode, {InputMode::Help, InputMode::License}));
|
|
||||||
BOOST_TEST(any_of(help.input.mode, help_license));
|
|
||||||
BOOST_TEST(any_of(license.input.mode, help_license));
|
|
||||||
BOOST_TEST(!any_of(version.input.mode, help_license));
|
|
||||||
BOOST_TEST(any_of(version.input.mode, {InputMode::Version}));
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(CommandLineOptions_none_of)
|
|
||||||
{
|
|
||||||
std::vector<InputMode> help_license{InputMode::Help, InputMode::License};
|
|
||||||
CommandLineOptions help = parseCommandLine({"solc", "--help"});
|
|
||||||
CommandLineOptions license = parseCommandLine({"solc", "--license"});
|
|
||||||
CommandLineOptions version = parseCommandLine({"solc", "--version"});
|
|
||||||
BOOST_TEST(!none_of(help.input.mode, {InputMode::Help, InputMode::License}));
|
|
||||||
BOOST_TEST(!none_of(license.input.mode, {InputMode::Help, InputMode::License}));
|
|
||||||
BOOST_TEST(!none_of(help.input.mode, help_license));
|
|
||||||
BOOST_TEST(!none_of(license.input.mode, help_license));
|
|
||||||
BOOST_TEST(none_of(version.input.mode, help_license));
|
|
||||||
BOOST_TEST(!none_of(version.input.mode, {InputMode::Version}));
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(via_ir_options)
|
BOOST_AUTO_TEST_CASE(via_ir_options)
|
||||||
{
|
{
|
||||||
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);
|
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);
|
||||||
|
Loading…
Reference in New Issue
Block a user