@@ -12,6 +12,7 @@ Date: December 2016
12
12
// / Remove exception handling
13
13
14
14
#include " remove_exceptions.h"
15
+ #include " remove_instanceof.h"
15
16
16
17
#ifdef DEBUG
17
18
#include < iostream>
@@ -43,8 +44,9 @@ Date: December 2016
43
44
// / (in instruction->code.exception_list()) and a corresponding GOTO program
44
45
// / target for each (in instruction->targets).
45
46
// / Thrown instructions are currently always matched to tags using
46
- // / java_instanceof, so a language frontend wanting to use this class
47
- // / must use exceptions with a Java-compatible structure.
47
+ // / java_instanceof, optionally lowered to a check on the @class_identifier
48
+ // / field, so a language frontend wanting to use this class must use
49
+ // / exceptions with a Java-compatible structure.
48
50
// /
49
51
// / CATCH with a code_pop_catcht operand terminates a try-block begun by
50
52
// / a code_push_catcht. At present the try block consists of the instructions
@@ -72,9 +74,6 @@ Date: December 2016
72
74
// / instructions copy back to an ordinary local variable (or other expression)
73
75
// / and set \#exception_value back to null, indicating the exception has been
74
76
// / caught and normal control flow resumed.
75
- // /
76
- // / Note that remove_exceptions introduces java_instanceof comparisons at
77
- // / present, so a remove_instanceof may be necessary after it completes.
78
77
class remove_exceptionst
79
78
{
80
79
typedef std::vector<std::pair<
@@ -84,9 +83,11 @@ class remove_exceptionst
84
83
public:
85
84
explicit remove_exceptionst (
86
85
symbol_tablet &_symbol_table,
87
- std::map<irep_idt, std::set<irep_idt>> &_exceptions_map):
88
- symbol_table(_symbol_table),
89
- exceptions_map(_exceptions_map)
86
+ std::map<irep_idt, std::set<irep_idt>> &_exceptions_map,
87
+ bool remove_added_instanceof)
88
+ : symbol_table(_symbol_table),
89
+ exceptions_map(_exceptions_map),
90
+ remove_added_instanceof(remove_added_instanceof)
90
91
{
91
92
}
92
93
@@ -95,6 +96,7 @@ class remove_exceptionst
95
96
protected:
96
97
symbol_tablet &symbol_table;
97
98
std::map<irep_idt, std::set<irep_idt>> &exceptions_map;
99
+ bool remove_added_instanceof;
98
100
99
101
void add_exceptional_returns (
100
102
const irep_idt &function_id,
@@ -346,6 +348,9 @@ void remove_exceptionst::add_exception_dispatch_sequence(
346
348
347
349
binary_predicate_exprt check (exc_thrown, ID_java_instanceof, expr);
348
350
t_exc->guard =check;
351
+
352
+ if (remove_added_instanceof)
353
+ remove_instanceof (t_exc, goto_program, symbol_table);
349
354
}
350
355
}
351
356
}
@@ -575,17 +580,21 @@ void remove_exceptionst::operator()(goto_functionst &goto_functions)
575
580
// / removes throws/CATCH-POP/CATCH-PUSH
576
581
void remove_exceptions (
577
582
symbol_tablet &symbol_table,
578
- goto_functionst &goto_functions)
583
+ goto_functionst &goto_functions,
584
+ remove_exceptions_typest type)
579
585
{
580
586
const namespacet ns (symbol_table);
581
587
std::map<irep_idt, std::set<irep_idt>> exceptions_map;
582
588
uncaught_exceptions (goto_functions, ns, exceptions_map);
583
- remove_exceptionst remove_exceptions (symbol_table, exceptions_map);
589
+ remove_exceptionst remove_exceptions (
590
+ symbol_table,
591
+ exceptions_map,
592
+ type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
584
593
remove_exceptions (goto_functions);
585
594
}
586
595
587
596
// / removes throws/CATCH-POP/CATCH-PUSH
588
- void remove_exceptions (goto_modelt &goto_model)
597
+ void remove_exceptions (goto_modelt &goto_model, remove_exceptions_typest type )
589
598
{
590
- remove_exceptions (goto_model.symbol_table , goto_model.goto_functions );
599
+ remove_exceptions (goto_model.symbol_table , goto_model.goto_functions , type );
591
600
}
0 commit comments