Skip to content

Commit 0ae5255

Browse files
Merge pull request diffblue#4515 from romainbrenguier/clean-up/parse-options-messaget
Clean up usage of messaget in *_parse_options classes
2 parents 97fd283 + f9b461a commit 0ae5255

8 files changed

+90
-82
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ Author: Daniel Kroening, [email protected]
5959

6060
janalyzer_parse_optionst::janalyzer_parse_optionst(int argc, const char **argv)
6161
: parse_options_baset(JANALYZER_OPTIONS, argc, argv, ui_message_handler),
62-
messaget(ui_message_handler),
6362
ui_message_handler(cmdline, std::string("JANALYZER ") + CBMC_VERSION)
6463
{
6564
}
@@ -260,7 +259,8 @@ void janalyzer_parse_optionst::get_command_line_options(optionst &options)
260259
if(!options.get_bool_option("domain set"))
261260
{
262261
// Default to constants as it is light-weight but useful
263-
status() << "Domain not specified, defaulting to --constants" << eom;
262+
log.status() << "Domain not specified, defaulting to --constants"
263+
<< messaget::eom;
264264
options.set_option("constants", true);
265265
}
266266
}
@@ -343,31 +343,33 @@ int janalyzer_parse_optionst::doit()
343343

344344
optionst options;
345345
get_command_line_options(options);
346-
eval_verbosity(
346+
messaget::eval_verbosity(
347347
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);
348348

349349
//
350350
// Print a banner
351351
//
352-
status() << "JANALYZER version " << CBMC_VERSION << " " << sizeof(void *) * 8
353-
<< "-bit " << config.this_architecture() << " "
354-
<< config.this_operating_system() << eom;
352+
log.status() << "JANALYZER version " << CBMC_VERSION << " "
353+
<< sizeof(void *) * 8 << "-bit " << config.this_architecture()
354+
<< " " << config.this_operating_system() << messaget::eom;
355355

356356
register_languages();
357357

358358
if(cmdline.args.size() > 1)
359359
{
360-
error() << "Only one .class, .jar or .gbf file should be directly "
361-
"specified on the command-line. To force loading another another class "
362-
"use '--java-load-class somepackage.SomeClass' or "
363-
"'--lazy-methods-extra-entry-point somepackage.SomeClass.method' along "
364-
"with '--classpath'"
365-
<< messaget::eom;
360+
log.error() << "Only one .class, .jar or .gbf file should be directly "
361+
"specified on the command-line. To force loading another "
362+
"another class "
363+
"use '--java-load-class somepackage.SomeClass' or "
364+
"'--lazy-methods-extra-entry-point "
365+
"somepackage.SomeClass.method' along "
366+
"with '--classpath'"
367+
<< messaget::eom;
366368
return CPROVER_EXIT_USAGE_ERROR;
367369
}
368370

369371
goto_model =
370-
initialize_goto_model(cmdline.args, get_message_handler(), options);
372+
initialize_goto_model(cmdline.args, log.get_message_handler(), options);
371373

372374
if(process_goto_program(options))
373375
return CPROVER_EXIT_INTERNAL_ERROR;
@@ -386,7 +388,7 @@ int janalyzer_parse_optionst::doit()
386388
{
387389
show_goto_functions(
388390
goto_model,
389-
get_message_handler(),
391+
log.get_message_handler(),
390392
get_ui(),
391393
cmdline.isset("list-goto-functions"));
392394
return CPROVER_EXIT_SUCCESS;
@@ -404,14 +406,15 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
404406

405407
if(cmdline.isset("show-taint"))
406408
{
407-
taint_analysis(goto_model, taint_file, get_message_handler(), true, "");
409+
taint_analysis(
410+
goto_model, taint_file, log.get_message_handler(), true, "");
408411
return CPROVER_EXIT_SUCCESS;
409412
}
410413
else
411414
{
412415
std::string json_file = cmdline.get_value("json");
413416
bool result = taint_analysis(
414-
goto_model, taint_file, get_message_handler(), false, json_file);
417+
goto_model, taint_file, log.get_message_handler(), false, json_file);
415418
return result ? CPROVER_EXIT_VERIFICATION_UNSAFE : CPROVER_EXIT_SUCCESS;
416419
}
417420
}
@@ -432,7 +435,8 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
432435
std::ofstream ofs(json_file);
433436
if(!ofs)
434437
{
435-
error() << "Failed to open json output `" << json_file << "'" << eom;
438+
log.error() << "Failed to open json output `" << json_file << "'"
439+
<< messaget::eom;
436440
return CPROVER_EXIT_INTERNAL_ERROR;
437441
}
438442

@@ -457,7 +461,8 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
457461
std::ofstream ofs(json_file);
458462
if(!ofs)
459463
{
460-
error() << "Failed to open json output `" << json_file << "'" << eom;
464+
log.error() << "Failed to open json output `" << json_file << "'"
465+
<< messaget::eom;
461466
return CPROVER_EXIT_INTERNAL_ERROR;
462467
}
463468

@@ -482,7 +487,8 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
482487
std::ofstream ofs(json_file);
483488
if(!ofs)
484489
{
485-
error() << "Failed to open json output `" << json_file << "'" << eom;
490+
log.error() << "Failed to open json output `" << json_file << "'"
491+
<< messaget::eom;
486492
return CPROVER_EXIT_INTERNAL_ERROR;
487493
}
488494

@@ -513,7 +519,7 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
513519

514520
if(cmdline.isset("show-properties"))
515521
{
516-
show_properties(goto_model, get_message_handler(), get_ui());
522+
show_properties(goto_model, log.get_message_handler(), get_ui());
517523
return CPROVER_EXIT_SUCCESS;
518524
}
519525

@@ -532,28 +538,29 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
532538

533539
if(!out)
534540
{
535-
error() << "Failed to open output file `" << outfile << "'" << eom;
541+
log.error() << "Failed to open output file `" << outfile << "'"
542+
<< messaget::eom;
536543
return CPROVER_EXIT_INTERNAL_ERROR;
537544
}
538545

539546
// Build analyzer
540-
status() << "Selecting abstract domain" << eom;
547+
log.status() << "Selecting abstract domain" << messaget::eom;
541548
namespacet ns(goto_model.symbol_table); // Must live as long as the domain.
542549
std::unique_ptr<ai_baset> analyzer(build_analyzer(options, ns));
543550

544551
if(analyzer == nullptr)
545552
{
546-
status() << "Task / Interpreter / Domain combination not supported"
547-
<< messaget::eom;
553+
log.status() << "Task / Interpreter / Domain combination not supported"
554+
<< messaget::eom;
548555
return CPROVER_EXIT_INTERNAL_ERROR;
549556
}
550557

551558
// Run
552-
status() << "Computing abstract states" << eom;
559+
log.status() << "Computing abstract states" << messaget::eom;
553560
(*analyzer)(goto_model);
554561

555562
// Perform the task
556-
status() << "Performing task" << eom;
563+
log.status() << "Performing task" << messaget::eom;
557564
bool result = true;
558565
if(options.get_bool_option("show"))
559566
{
@@ -563,12 +570,12 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
563570
else if(options.get_bool_option("verify"))
564571
{
565572
result = static_verifier(
566-
goto_model, *analyzer, options, get_message_handler(), out);
573+
goto_model, *analyzer, options, log.get_message_handler(), out);
567574
}
568575
else if(options.get_bool_option("simplify"))
569576
{
570577
result = static_simplifier(
571-
goto_model, *analyzer, options, get_message_handler(), out);
578+
goto_model, *analyzer, options, log.get_message_handler(), out);
572579
}
573580
else if(options.get_bool_option("unreachable-instructions"))
574581
{
@@ -587,7 +594,7 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
587594
}
588595
else
589596
{
590-
error() << "Unhandled task" << eom;
597+
log.error() << "Unhandled task" << messaget::eom;
591598
return CPROVER_EXIT_INTERNAL_ERROR;
592599
}
593600

@@ -596,7 +603,8 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
596603
}
597604

598605
// Final defensive error case
599-
error() << "no analysis option given -- consider reading --help" << eom;
606+
log.error() << "no analysis option given -- consider reading --help"
607+
<< messaget::eom;
600608
return CPROVER_EXIT_USAGE_ERROR;
601609
}
602610

@@ -605,23 +613,24 @@ bool janalyzer_parse_optionst::process_goto_program(const optionst &options)
605613
try
606614
{
607615
// remove function pointers
608-
status() << "Removing function pointers and virtual functions" << eom;
616+
log.status() << "Removing function pointers and virtual functions"
617+
<< messaget::eom;
609618
remove_function_pointers(
610-
get_message_handler(), goto_model, cmdline.isset("pointer-check"));
619+
log.get_message_handler(), goto_model, cmdline.isset("pointer-check"));
611620

612621
// Java virtual functions -> explicit dispatch tables:
613622
remove_virtual_functions(goto_model);
614623

615624
// remove Java throw and catch
616625
// This introduces instanceof, so order is important:
617-
remove_exceptions_using_instanceof(goto_model, get_message_handler());
626+
remove_exceptions_using_instanceof(goto_model, log.get_message_handler());
618627

619628
// Java instanceof -> clsid comparison:
620629
class_hierarchyt class_hierarchy(goto_model.symbol_table);
621-
remove_instanceof(goto_model, class_hierarchy, get_message_handler());
630+
remove_instanceof(goto_model, class_hierarchy, log.get_message_handler());
622631

623632
// do partial inlining
624-
status() << "Partial Inlining" << eom;
633+
log.status() << "Partial Inlining" << messaget::eom;
625634
goto_partial_inline(goto_model, ui_message_handler);
626635

627636
// remove returns, gcc vectors, complex
@@ -630,7 +639,7 @@ bool janalyzer_parse_optionst::process_goto_program(const optionst &options)
630639
remove_complex(goto_model);
631640

632641
// add generic checks
633-
status() << "Generic Property Instrumentation" << eom;
642+
log.status() << "Generic Property Instrumentation" << messaget::eom;
634643
goto_check(options, goto_model);
635644

636645
// recalculate numbers, etc.
@@ -642,13 +651,13 @@ bool janalyzer_parse_optionst::process_goto_program(const optionst &options)
642651

643652
catch(const char *e)
644653
{
645-
error() << e << eom;
654+
log.error() << e << messaget::eom;
646655
return true;
647656
}
648657

649658
catch(const std::string &e)
650659
{
651-
error() << e << eom;
660+
log.error() << e << messaget::eom;
652661
return true;
653662
}
654663

@@ -659,7 +668,7 @@ bool janalyzer_parse_optionst::process_goto_program(const optionst &options)
659668

660669
catch(const std::bad_alloc &)
661670
{
662-
error() << "Out of memory" << eom;
671+
log.error() << "Out of memory" << messaget::eom;
663672
return true;
664673
}
665674

jbmc/src/janalyzer/janalyzer_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class optionst;
150150
JAVA_BYTECODE_LANGUAGE_OPTIONS
151151
// clang-format on
152152

153-
class janalyzer_parse_optionst : public parse_options_baset, public messaget
153+
class janalyzer_parse_optionst : public parse_options_baset
154154
{
155155
public:
156156
virtual int doit() override;

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ Author: Peter Schrammel
6363

6464
jdiff_parse_optionst::jdiff_parse_optionst(int argc, const char **argv)
6565
: parse_options_baset(JDIFF_OPTIONS, argc, argv, ui_message_handler),
66-
messaget(ui_message_handler),
6766
ui_message_handler(cmdline, std::string("JDIFF ") + CBMC_VERSION)
6867
{
6968
}
@@ -186,19 +185,19 @@ int jdiff_parse_optionst::doit()
186185

187186
optionst options;
188187
get_command_line_options(options);
189-
eval_verbosity(
188+
messaget::eval_verbosity(
190189
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);
191190

192191
//
193192
// Print a banner
194193
//
195-
status() << "JDIFF version " << CBMC_VERSION << " " << sizeof(void *) * 8
196-
<< "-bit " << config.this_architecture() << " "
197-
<< config.this_operating_system() << eom;
194+
log.status() << "JDIFF version " << CBMC_VERSION << " " << sizeof(void *) * 8
195+
<< "-bit " << config.this_architecture() << " "
196+
<< config.this_operating_system() << messaget::eom;
198197

199198
if(cmdline.args.size() != 2)
200199
{
201-
error() << "Please provide two programs to compare" << eom;
200+
log.error() << "Please provide two programs to compare" << messaget::eom;
202201
return CPROVER_EXIT_INCORRECT_TASK;
203202
}
204203

@@ -226,12 +225,12 @@ int jdiff_parse_optionst::doit()
226225
{
227226
show_goto_functions(
228227
goto_model1,
229-
get_message_handler(),
228+
log.get_message_handler(),
230229
ui_message_handler.get_ui(),
231230
cmdline.isset("list-goto-functions"));
232231
show_goto_functions(
233232
goto_model2,
234-
get_message_handler(),
233+
log.get_message_handler(),
235234
ui_message_handler.get_ui(),
236235
cmdline.isset("list-goto-functions"));
237236
return CPROVER_EXIT_SUCCESS;
@@ -275,20 +274,21 @@ bool jdiff_parse_optionst::process_goto_program(
275274
{
276275
{
277276
// remove function pointers
278-
status() << "Removing function pointers and virtual functions" << eom;
277+
log.status() << "Removing function pointers and virtual functions"
278+
<< messaget::eom;
279279
remove_function_pointers(
280-
get_message_handler(), goto_model, cmdline.isset("pointer-check"));
280+
log.get_message_handler(), goto_model, cmdline.isset("pointer-check"));
281281

282282
// Java virtual functions -> explicit dispatch tables:
283283
remove_virtual_functions(goto_model);
284284

285285
// remove Java throw and catch
286286
// This introduces instanceof, so order is important:
287-
remove_exceptions_using_instanceof(goto_model, get_message_handler());
287+
remove_exceptions_using_instanceof(goto_model, log.get_message_handler());
288288

289289
// Java instanceof -> clsid comparison:
290290
class_hierarchyt class_hierarchy(goto_model.symbol_table);
291-
remove_instanceof(goto_model, class_hierarchy, get_message_handler());
291+
remove_instanceof(goto_model, class_hierarchy, log.get_message_handler());
292292

293293
mm_io(goto_model);
294294

@@ -302,7 +302,7 @@ bool jdiff_parse_optionst::process_goto_program(
302302
rewrite_union(goto_model);
303303

304304
// add generic checks
305-
status() << "Generic Property Instrumentation" << eom;
305+
log.status() << "Generic Property Instrumentation" << messaget::eom;
306306
goto_check(options, goto_model);
307307

308308
// checks don't know about adjusted float expressions
@@ -322,9 +322,9 @@ bool jdiff_parse_optionst::process_goto_program(
322322
if(cmdline.isset("cover"))
323323
{
324324
const auto cover_config = get_cover_config(
325-
options, goto_model.symbol_table, get_message_handler());
325+
options, goto_model.symbol_table, log.get_message_handler());
326326
if(instrument_cover_goals(
327-
cover_config, goto_model, get_message_handler()))
327+
cover_config, goto_model, log.get_message_handler()))
328328
return true;
329329
}
330330

jbmc/src/jdiff/jdiff_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class goto_modelt;
4040
"(compact-output)"
4141
// clang-format on
4242

43-
class jdiff_parse_optionst : public parse_options_baset, public messaget
43+
class jdiff_parse_optionst : public parse_options_baset
4444
{
4545
public:
4646
virtual int doit();

0 commit comments

Comments
 (0)