Skip to content

Commit 29be3b3

Browse files
NlightNFotisdanpoe
authored andcommitted
Add a parse_options class for a better suited exception handling location
1 parent 2c71eb8 commit 29be3b3

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

src/cbmc/cbmc_main.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ int wmain(int argc, const wchar_t **argv_wide)
4141
int main(int argc, const char **argv)
4242
{
4343
#endif
44-
try
45-
{
46-
cbmc_parse_optionst parse_options(argc, argv);
44+
cbmc_parse_optionst parse_options(argc, argv);
4745

48-
int res = parse_options.main();
46+
int res = parse_options.main();
4947

5048
#ifdef IREP_HASH_STATS
5149
std::cout << "IREP_HASH_CNT=" << irep_hash_cnt << '\n';
@@ -54,9 +52,4 @@ int main(int argc, const char **argv)
5452
#endif
5553

5654
return res;
57-
}
58-
catch(invalid_user_input_exceptiont &e)
59-
{
60-
std::cerr << e.what() << std::endl;
61-
}
6255
}

src/cbmc/cbmc_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Author: Daniel Kroening, [email protected]
6666
#include "xml_interface.h"
6767

6868
cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
69-
: parse_options_baset(CBMC_OPTIONS, argc, argv),
69+
: parse_optionst(CBMC_OPTIONS, argc, argv),
7070
xml_interfacet(cmdline),
7171
messaget(ui_message_handler),
7272
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION),
@@ -78,7 +78,7 @@ ::cbmc_parse_optionst::cbmc_parse_optionst(
7878
int argc,
7979
const char **argv,
8080
const std::string &extra_options)
81-
: parse_options_baset(CBMC_OPTIONS + extra_options, argc, argv),
81+
: parse_optionst(CBMC_OPTIONS + extra_options, argc, argv),
8282
xml_interfacet(cmdline),
8383
messaget(ui_message_handler),
8484
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION),

src/cbmc/cbmc_parse_options.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ class optionst;
7676
"(claim):(show-claims)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
7777
// clang-format on
7878

79-
class cbmc_parse_optionst:
80-
public parse_options_baset,
81-
public xml_interfacet,
82-
public messaget
79+
class cbmc_parse_optionst : public parse_optionst,
80+
public xml_interfacet,
81+
public messaget
8382
{
8483
public:
8584
virtual int doit() override;

src/util/parse_options.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected]
1818
#endif
1919

2020
#include "cmdline.h"
21+
#include "exception_utils.h"
22+
#include "exit_codes.h"
2123
#include "signal_catcher.h"
2224

2325
parse_options_baset::parse_options_baset(
@@ -82,3 +84,19 @@ banner_string(const std::string &front_end, const std::string &version)
8284
return "* *" + std::string(left_padding, ' ') + version_str +
8385
std::string(right_padding, ' ') + "* *";
8486
}
87+
88+
int parse_optionst::main()
89+
{
90+
// catch all exceptions here so that this code is not duplicated
91+
// for each tool
92+
try
93+
{
94+
return parse_options_baset::main();
95+
}
96+
catch(invalid_user_input_exceptiont &e)
97+
{
98+
std::cerr << e.what() << "\n";
99+
return CPROVER_EXIT_EXCEPTION;
100+
}
101+
return CPROVER_EXIT_SUCCESS;
102+
}

src/util/parse_options.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ class parse_options_baset
3535
bool parse_result;
3636
};
3737

38+
class parse_optionst : public parse_options_baset
39+
{
40+
public:
41+
parse_optionst(const std::string &optstring, int argc, const char **argv)
42+
: parse_options_baset(optstring, argc, argv)
43+
{
44+
}
45+
46+
int main() override;
47+
};
48+
3849
std::string
3950
banner_string(const std::string &front_end, const std::string &version);
4051

0 commit comments

Comments
 (0)