@@ -87,14 +87,14 @@ 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 ,
92
+ bool _remove_added_instanceof ,
93
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 ),
97
+ remove_added_instanceof(_remove_added_instanceof ),
98
98
message_handler(message_handler)
99
99
{
100
100
if (remove_added_instanceof)
@@ -593,24 +593,85 @@ void remove_exceptionst::operator()(goto_programt &goto_program)
593
593
// / removes throws/CATCH-POP/CATCH-PUSH
594
594
void remove_exceptions (
595
595
symbol_table_baset &symbol_table,
596
- const class_hierarchyt *class_hierarchy,
597
596
goto_functionst &goto_functions,
598
- message_handlert &message_handler,
599
- remove_exceptions_typest type)
597
+ message_handlert &message_handler)
600
598
{
601
599
const namespacet ns (symbol_table);
602
600
std::map<irep_idt, std::set<irep_idt>> exceptions_map;
601
+
603
602
uncaught_exceptions (goto_functions, ns, exceptions_map);
603
+
604
604
remove_exceptionst::function_may_throwt function_may_throw =
605
605
[&exceptions_map](const irep_idt &id) {
606
606
return !exceptions_map[id].empty ();
607
607
};
608
+
608
609
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);
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 (
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 (
648
+ goto_modelt &goto_model,
649
+ message_handlert &message_handler)
650
+ {
651
+ remove_exceptions (
652
+ goto_model.symbol_table , goto_model.goto_functions , message_handler);
653
+ }
654
+
655
+ // / removes throws/CATCH-POP/CATCH-PUSH
656
+ void remove_exceptions_and_instanceof (
657
+ symbol_table_baset &symbol_table,
658
+ goto_functionst &goto_functions,
659
+ const class_hierarchyt &class_hierarchy,
660
+ message_handlert &message_handler)
661
+ {
662
+ const namespacet ns (symbol_table);
663
+ std::map<irep_idt, std::set<irep_idt>> exceptions_map;
664
+
665
+ uncaught_exceptions (goto_functions, ns, exceptions_map);
666
+
667
+ remove_exceptionst::function_may_throwt function_may_throw =
668
+ [&exceptions_map](const irep_idt &id) {
669
+ return !exceptions_map[id].empty ();
670
+ };
671
+
672
+ remove_exceptionst remove_exceptions (
673
+ symbol_table, &class_hierarchy, function_may_throw, true , message_handler);
674
+
614
675
remove_exceptions (goto_functions);
615
676
}
616
677
@@ -630,22 +691,22 @@ void remove_exceptions(
630
691
// / \param type: specifies whether instanceof operations generated by this pass
631
692
// / should be lowered to class-identifier comparisons (using
632
693
// / remove_instanceof).
633
- void remove_exceptions (
694
+ void remove_exceptions_and_instanceof (
634
695
goto_programt &goto_program,
635
696
symbol_table_baset &symbol_table,
636
- const class_hierarchyt *class_hierarchy,
637
- message_handlert &message_handler,
638
- remove_exceptions_typest type)
697
+ const class_hierarchyt &class_hierarchy,
698
+ message_handlert &message_handler)
639
699
{
640
700
remove_exceptionst::function_may_throwt any_function_may_throw =
641
701
[](const irep_idt &) { return true ; };
642
702
643
703
remove_exceptionst remove_exceptions (
644
704
symbol_table,
645
- class_hierarchy,
705
+ & class_hierarchy,
646
706
any_function_may_throw,
647
- type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF ,
707
+ true ,
648
708
message_handler);
709
+
649
710
remove_exceptions (goto_program);
650
711
}
651
712
@@ -661,16 +722,14 @@ void remove_exceptions(
661
722
// / \param type: specifies whether instanceof operations generated by this pass
662
723
// / should be lowered to class-identifier comparisons (using
663
724
// / remove_instanceof).
664
- void remove_exceptions (
725
+ void remove_exceptions_and_instanceof (
665
726
goto_modelt &goto_model,
666
- const class_hierarchyt *class_hierarchy,
667
- message_handlert &message_handler,
668
- remove_exceptions_typest type)
727
+ const class_hierarchyt &class_hierarchy,
728
+ message_handlert &message_handler)
669
729
{
670
- remove_exceptions (
730
+ remove_exceptions_and_instanceof (
671
731
goto_model.symbol_table ,
672
- class_hierarchy,
673
732
goto_model.goto_functions ,
674
- message_handler ,
675
- type );
733
+ class_hierarchy ,
734
+ message_handler );
676
735
}
0 commit comments