@@ -87,15 +87,15 @@ class remove_exceptionst
8787
8888 explicit remove_exceptionst (
8989 symbol_table_baset &_symbol_table,
90- const class_hierarchyt *class_hierarchy ,
90+ const class_hierarchyt *_class_hierarchy ,
9191 function_may_throwt _function_may_throw,
92- bool remove_added_instanceof ,
93- message_handlert &message_handler )
92+ bool _remove_added_instanceof ,
93+ message_handlert &_message_handler )
9494 : symbol_table(_symbol_table),
95- class_hierarchy(class_hierarchy ),
95+ class_hierarchy(_class_hierarchy ),
9696 function_may_throw(_function_may_throw),
97- remove_added_instanceof(remove_added_instanceof ),
98- message_handler(message_handler )
97+ remove_added_instanceof(_remove_added_instanceof ),
98+ message_handler(_message_handler )
9999 {
100100 if (remove_added_instanceof)
101101 {
@@ -590,27 +590,88 @@ void remove_exceptionst::operator()(goto_programt &goto_program)
590590 instrument_exceptions (goto_program);
591591}
592592
593+ // / removes throws/CATCH-POP/CATCH-PUSH
594+ void remove_exceptions_using_instanceof (
595+ symbol_table_baset &symbol_table,
596+ goto_functionst &goto_functions,
597+ message_handlert &message_handler)
598+ {
599+ const namespacet ns (symbol_table);
600+ std::map<irep_idt, std::set<irep_idt>> exceptions_map;
601+
602+ uncaught_exceptions (goto_functions, ns, exceptions_map);
603+
604+ remove_exceptionst::function_may_throwt function_may_throw =
605+ [&exceptions_map](const irep_idt &id) {
606+ return !exceptions_map[id].empty ();
607+ };
608+
609+ remove_exceptionst remove_exceptions (
610+ symbol_table, nullptr , function_may_throw, false , message_handler);
611+
612+ remove_exceptions (goto_functions);
613+ }
614+
615+ // / removes throws/CATCH-POP/CATCH-PUSH from a single GOTO program, replacing
616+ // / them with explicit exception propagation.
617+ // / Note this is somewhat less accurate than the whole-goto-model version,
618+ // / because we can't inspect other functions to determine whether they throw
619+ // / or not, and therefore must assume they do and always introduce post-call
620+ // / exception dispatch.
621+ // / \param goto_program: program to remove exceptions from
622+ // / \param symbol_table: global symbol table. The `@inflight_exception` global
623+ // / may be added if not already present. It will not be initialised; that is
624+ // / the caller's responsibility.
625+ // / \param message_handler: logging output
626+ void remove_exceptions_using_instanceof (
627+ goto_programt &goto_program,
628+ symbol_table_baset &symbol_table,
629+ message_handlert &message_handler)
630+ {
631+ remove_exceptionst::function_may_throwt any_function_may_throw =
632+ [](const irep_idt &) { return true ; };
633+
634+ remove_exceptionst remove_exceptions (
635+ symbol_table, nullptr , any_function_may_throw, false , message_handler);
636+
637+ remove_exceptions (goto_program);
638+ }
639+
640+ // / removes throws/CATCH-POP/CATCH-PUSH, replacing them with explicit exception
641+ // / propagation.
642+ // / \param goto_model: model to remove exceptions from. The
643+ // / `@inflight_exception` global may be added to its symbol table if not
644+ // / already present. It will not be initialised; that is the caller's
645+ // / responsibility.
646+ // / \param message_handler: logging output
647+ void remove_exceptions_using_instanceof (
648+ goto_modelt &goto_model,
649+ message_handlert &message_handler)
650+ {
651+ remove_exceptions_using_instanceof (
652+ goto_model.symbol_table , goto_model.goto_functions , message_handler);
653+ }
654+
593655// / removes throws/CATCH-POP/CATCH-PUSH
594656void remove_exceptions (
595657 symbol_table_baset &symbol_table,
596- const class_hierarchyt *class_hierarchy,
597658 goto_functionst &goto_functions,
598- message_handlert &message_handler ,
599- remove_exceptions_typest type )
659+ const class_hierarchyt &class_hierarchy ,
660+ message_handlert &message_handler )
600661{
601662 const namespacet ns (symbol_table);
602663 std::map<irep_idt, std::set<irep_idt>> exceptions_map;
664+
603665 uncaught_exceptions (goto_functions, ns, exceptions_map);
666+
604667 remove_exceptionst::function_may_throwt function_may_throw =
605668 [&exceptions_map](const irep_idt &id) {
606669 return !exceptions_map[id].empty ();
607670 };
671+
608672 remove_exceptionst remove_exceptions (
609- symbol_table,
610- class_hierarchy,
611- function_may_throw,
612- type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF,
613- message_handler);
673+ symbol_table, &class_hierarchy, function_may_throw, true , message_handler);
674+
614675 remove_exceptions (goto_functions);
615676}
616677
@@ -627,25 +688,22 @@ void remove_exceptions(
627688// / \param class_hierarchy: class hierarchy analysis of symbol_table.
628689// / Only needed if type == REMOVE_ADDED_INSTANCEOF; otherwise may be null.
629690// / \param message_handler: logging output
630- // / \param type: specifies whether instanceof operations generated by this pass
631- // / should be lowered to class-identifier comparisons (using
632- // / remove_instanceof).
633691void remove_exceptions (
634692 goto_programt &goto_program,
635693 symbol_table_baset &symbol_table,
636- const class_hierarchyt *class_hierarchy,
637- message_handlert &message_handler,
638- remove_exceptions_typest type)
694+ const class_hierarchyt &class_hierarchy,
695+ message_handlert &message_handler)
639696{
640697 remove_exceptionst::function_may_throwt any_function_may_throw =
641698 [](const irep_idt &) { return true ; };
642699
643700 remove_exceptionst remove_exceptions (
644701 symbol_table,
645- class_hierarchy,
702+ & class_hierarchy,
646703 any_function_may_throw,
647- type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF ,
704+ true ,
648705 message_handler);
706+
649707 remove_exceptions (goto_program);
650708}
651709
@@ -658,19 +716,14 @@ void remove_exceptions(
658716// / \param class_hierarchy: class hierarchy analysis of symbol_table.
659717// / Only needed if type == REMOVE_ADDED_INSTANCEOF; otherwise may be null.
660718// / \param message_handler: logging output
661- // / \param type: specifies whether instanceof operations generated by this pass
662- // / should be lowered to class-identifier comparisons (using
663- // / remove_instanceof).
664719void remove_exceptions (
665720 goto_modelt &goto_model,
666- const class_hierarchyt *class_hierarchy,
667- message_handlert &message_handler,
668- remove_exceptions_typest type)
721+ const class_hierarchyt &class_hierarchy,
722+ message_handlert &message_handler)
669723{
670724 remove_exceptions (
671725 goto_model.symbol_table ,
672- class_hierarchy,
673726 goto_model.goto_functions ,
674- message_handler ,
675- type );
727+ class_hierarchy ,
728+ message_handler );
676729}
0 commit comments