@@ -87,15 +87,15 @@ class remove_exceptionst
87
87
88
88
explicit remove_exceptionst (
89
89
symbol_table_baset &_symbol_table,
90
- const class_hierarchyt *class_hierarchy ,
90
+ const class_hierarchyt *_class_hierarchy ,
91
91
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 )
94
94
: symbol_table(_symbol_table),
95
- class_hierarchy(class_hierarchy ),
95
+ class_hierarchy(_class_hierarchy ),
96
96
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 )
99
99
{
100
100
if (remove_added_instanceof)
101
101
{
@@ -590,27 +590,88 @@ void remove_exceptionst::operator()(goto_programt &goto_program)
590
590
instrument_exceptions (goto_program);
591
591
}
592
592
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
+
593
655
// / removes throws/CATCH-POP/CATCH-PUSH
594
656
void remove_exceptions (
595
657
symbol_table_baset &symbol_table,
596
- const class_hierarchyt *class_hierarchy,
597
658
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 )
600
661
{
601
662
const namespacet ns (symbol_table);
602
663
std::map<irep_idt, std::set<irep_idt>> exceptions_map;
664
+
603
665
uncaught_exceptions (goto_functions, ns, exceptions_map);
666
+
604
667
remove_exceptionst::function_may_throwt function_may_throw =
605
668
[&exceptions_map](const irep_idt &id) {
606
669
return !exceptions_map[id].empty ();
607
670
};
671
+
608
672
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
+
614
675
remove_exceptions (goto_functions);
615
676
}
616
677
@@ -627,25 +688,22 @@ void remove_exceptions(
627
688
// / \param class_hierarchy: class hierarchy analysis of symbol_table.
628
689
// / Only needed if type == REMOVE_ADDED_INSTANCEOF; otherwise may be null.
629
690
// / \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).
633
691
void remove_exceptions (
634
692
goto_programt &goto_program,
635
693
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)
639
696
{
640
697
remove_exceptionst::function_may_throwt any_function_may_throw =
641
698
[](const irep_idt &) { return true ; };
642
699
643
700
remove_exceptionst remove_exceptions (
644
701
symbol_table,
645
- class_hierarchy,
702
+ & class_hierarchy,
646
703
any_function_may_throw,
647
- type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF ,
704
+ true ,
648
705
message_handler);
706
+
649
707
remove_exceptions (goto_program);
650
708
}
651
709
@@ -658,19 +716,14 @@ void remove_exceptions(
658
716
// / \param class_hierarchy: class hierarchy analysis of symbol_table.
659
717
// / Only needed if type == REMOVE_ADDED_INSTANCEOF; otherwise may be null.
660
718
// / \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).
664
719
void remove_exceptions (
665
720
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)
669
723
{
670
724
remove_exceptions (
671
725
goto_model.symbol_table ,
672
- class_hierarchy,
673
726
goto_model.goto_functions ,
674
- message_handler ,
675
- type );
727
+ class_hierarchy ,
728
+ message_handler );
676
729
}
0 commit comments