@@ -9,6 +9,7 @@ Date: June 2017
9
9
\*******************************************************************/
10
10
11
11
#include < util/arith_tools.h>
12
+ #include < util/fresh_symbol.h>
12
13
#include < util/std_code.h>
13
14
#include < util/std_expr.h>
14
15
#include < util/symbol_table.h>
@@ -18,7 +19,6 @@ Date: June 2017
18
19
#include " java_bytecode_convert_class.h"
19
20
#include " java_bytecode_instrument.h"
20
21
#include " java_entry_point.h"
21
- #include " java_object_factory.h"
22
22
#include " java_root_class.h"
23
23
#include " java_types.h"
24
24
#include " java_utils.h"
@@ -90,47 +90,46 @@ codet java_bytecode_instrumentt::throw_exception(
90
90
const source_locationt &original_loc,
91
91
const irep_idt &exc_name)
92
92
{
93
- exprt exc;
94
- code_blockt init_code;
95
- const irep_idt &exc_obj_name=
96
- id2string (goto_functionst::entry_point ())+
97
- " ::" +id2string (exc_name);
93
+ irep_idt exc_class_name (" java::" +id2string (exc_name));
98
94
99
- if (!symbol_table.has_symbol (exc_obj_name ))
95
+ if (!symbol_table.has_symbol (exc_class_name ))
100
96
{
101
97
generate_class_stub (
102
98
exc_name,
103
99
symbol_table,
104
100
get_message_handler ());
105
- const symbolt &exc_symbol=symbol_table.lookup (
106
- " java::" +id2string (exc_name));
107
-
108
- // create the exception object
109
- exc=object_factory (
110
- pointer_typet (exc_symbol.type ),
111
- exc_name,
112
- init_code,
113
- false ,
114
- symbol_table,
115
- max_array_length,
116
- allocation_typet::LOCAL,
117
- original_loc);
118
101
}
119
- else
120
- exc=symbol_table.lookup (exc_obj_name).symbol_expr ();
102
+
103
+ pointer_typet exc_ptr_type;
104
+ exc_ptr_type.subtype ()=symbol_typet (exc_class_name);
105
+
106
+ // Allocate and throw an instance of the exception class:
107
+
108
+ symbolt &new_symbol=
109
+ get_fresh_aux_symbol (
110
+ exc_ptr_type,
111
+ " new_exception" ,
112
+ " new_exception" ,
113
+ original_loc,
114
+ ID_java,
115
+ symbol_table);
116
+
117
+ side_effect_exprt new_instance (ID_java_new, exc_ptr_type);
118
+ code_assignt assign_new (new_symbol.symbol_expr (), new_instance);
121
119
122
120
side_effect_expr_throwt throw_expr;
123
- throw_expr.add_source_location ()=original_loc;
124
- throw_expr.move_to_operands (exc);
121
+ throw_expr.copy_to_operands (new_symbol.symbol_expr ());
122
+
123
+ code_blockt throw_code;
124
+ throw_code.move_to_operands (assign_new);
125
+ throw_code.copy_to_operands (code_expressiont (throw_expr));
125
126
126
127
code_ifthenelset if_code;
127
128
if_code.add_source_location ()=original_loc;
128
129
if_code.cond ()=cond;
129
- if_code.then_case ()=code_expressiont (throw_expr);
130
-
131
- init_code.move_to_operands (if_code);
130
+ if_code.then_case ()=throw_code;
132
131
133
- return init_code ;
132
+ return if_code ;
134
133
}
135
134
136
135
// / Checks whether the array access array_struct[idx] is out-of-bounds,
@@ -209,7 +208,7 @@ codet java_bytecode_instrumentt::check_class_cast(
209
208
throw_exception (
210
209
not_exprt (class_cast_check),
211
210
original_loc,
212
- " ClassCastException" );
211
+ " java.lang. ClassCastException" );
213
212
}
214
213
else
215
214
{
0 commit comments