[yul-phaser] Don't return exit code from Phaser::main() and just assume 0 if it does not throw.

This commit is contained in:
Kamil Śliwak 2020-02-28 03:58:26 +01:00
parent d86b5019dc
commit 760e7c3cc5
3 changed files with 14 additions and 19 deletions

View File

@ -142,16 +142,15 @@ CharStream ProgramFactory::loadSource(string const& _sourcePath)
return CharStream(sourceCode, _sourcePath); return CharStream(sourceCode, _sourcePath);
} }
int Phaser::main(int _argc, char** _argv) void Phaser::main(int _argc, char** _argv)
{ {
CommandLineParsingResult parsingResult = parseCommandLine(_argc, _argv); optional<po::variables_map> arguments = parseCommandLine(_argc, _argv);
if (parsingResult.exitCode != 0) if (!arguments.has_value())
return parsingResult.exitCode; return;
initialiseRNG(parsingResult.arguments); initialiseRNG(arguments.value());
runAlgorithm(parsingResult.arguments); runAlgorithm(arguments.value());
return 0;
} }
Phaser::CommandLineDescription Phaser::buildCommandLineDescription() Phaser::CommandLineDescription Phaser::buildCommandLineDescription()
@ -198,7 +197,7 @@ Phaser::CommandLineDescription Phaser::buildCommandLineDescription()
return {keywordDescription, positionalDescription}; return {keywordDescription, positionalDescription};
} }
Phaser::CommandLineParsingResult Phaser::parseCommandLine(int _argc, char** _argv) optional<po::variables_map> Phaser::parseCommandLine(int _argc, char** _argv)
{ {
auto [keywordDescription, positionalDescription] = buildCommandLineDescription(); auto [keywordDescription, positionalDescription] = buildCommandLineDescription();
@ -212,13 +211,13 @@ Phaser::CommandLineParsingResult Phaser::parseCommandLine(int _argc, char** _arg
if (arguments.count("help") > 0) if (arguments.count("help") > 0)
{ {
cout << keywordDescription << endl; cout << keywordDescription << endl;
return {0, move(arguments)}; return nullopt;
} }
if (arguments.count("input-file") == 0) if (arguments.count("input-file") == 0)
assertThrow(false, NoInputFiles, "Missing argument: input-file."); assertThrow(false, NoInputFiles, "Missing argument: input-file.");
return {0, arguments}; return arguments;
} }
void Phaser::initialiseRNG(po::variables_map const& _arguments) void Phaser::initialiseRNG(po::variables_map const& _arguments)

View File

@ -25,6 +25,7 @@
#include <istream> #include <istream>
#include <memory> #include <memory>
#include <optional>
#include <ostream> #include <ostream>
#include <string> #include <string>
@ -128,7 +129,7 @@ private:
class Phaser class Phaser
{ {
public: public:
static int main(int argc, char** argv); static void main(int argc, char** argv);
private: private:
struct CommandLineDescription struct CommandLineDescription
@ -137,14 +138,8 @@ private:
boost::program_options::positional_options_description positionalDescription; boost::program_options::positional_options_description positionalDescription;
}; };
struct CommandLineParsingResult
{
int exitCode;
boost::program_options::variables_map arguments;
};
static CommandLineDescription buildCommandLineDescription(); static CommandLineDescription buildCommandLineDescription();
static CommandLineParsingResult parseCommandLine(int _argc, char** _argv); static std::optional<boost::program_options::variables_map> parseCommandLine(int _argc, char** _argv);
static void initialiseRNG(boost::program_options::variables_map const& _arguments); static void initialiseRNG(boost::program_options::variables_map const& _arguments);
static void runAlgorithm(boost::program_options::variables_map const& _arguments); static void runAlgorithm(boost::program_options::variables_map const& _arguments);

View File

@ -26,7 +26,8 @@ int main(int argc, char** argv)
{ {
try try
{ {
return solidity::phaser::Phaser::main(argc, argv); solidity::phaser::Phaser::main(argc, argv);
return 0;
} }
catch (boost::program_options::error const& exception) catch (boost::program_options::error const& exception)
{ {