@@ -19,6 +19,7 @@ Date: June 2017
19
19
20
20
#include " java_bytecode_convert_class.h"
21
21
#include " java_entry_point.h"
22
+ #include " java_expr.h"
22
23
#include " java_utils.h"
23
24
24
25
class java_bytecode_instrumentt :public messaget
@@ -61,8 +62,8 @@ class java_bytecode_instrumentt:public messaget
61
62
const source_locationt &original_loc);
62
63
63
64
code_ifthenelset check_class_cast (
64
- const exprt &class1 ,
65
- const exprt &class2 ,
65
+ const exprt &tested_expr ,
66
+ const struct_tag_typet &target_type ,
66
67
const source_locationt &original_loc);
67
68
68
69
codet check_array_length (
@@ -203,22 +204,21 @@ codet java_bytecode_instrumentt::check_array_access(
203
204
// / ClassCastException/generates an assertion when necessary;
204
205
// / Exceptions are thrown when the `throw_runtime_exceptions` flag is set.
205
206
// / Otherwise, assertions are emitted.
206
- // / \param class1: the subclass
207
- // / \param class2: the super class
207
+ // / \param tested_expr: expression to test
208
+ // / \param target_type: type to test for
208
209
// / \param original_loc: source location in the original code
209
210
// / \return Based on the value of the flag `throw_runtime_exceptions`,
210
211
// / it returns code that either throws an ClassCastException or emits an
211
212
// / assertion checking the subtype relation
212
213
code_ifthenelset java_bytecode_instrumentt::check_class_cast (
213
- const exprt &class1 ,
214
- const exprt &class2 ,
214
+ const exprt &tested_expr ,
215
+ const struct_tag_typet &target_type ,
215
216
const source_locationt &original_loc)
216
217
{
217
- binary_predicate_exprt class_cast_check (
218
- class1, ID_java_instanceof, class2);
218
+ java_instanceof_exprt class_cast_check (tested_expr, target_type);
219
219
220
220
pointer_typet voidptr = pointer_type (java_void_type ());
221
- exprt null_check_op = typecast_exprt::conditional_cast (class1 , voidptr);
221
+ exprt null_check_op = typecast_exprt::conditional_cast (tested_expr , voidptr);
222
222
223
223
optionalt<codet> check_code;
224
224
if (throw_runtime_exceptions)
@@ -373,15 +373,12 @@ void java_bytecode_instrumentt::instrument_code(codet &code)
373
373
if (code_assert.assertion ().id ()==ID_java_instanceof)
374
374
{
375
375
code_blockt block;
376
+ const auto & instanceof
377
+ = to_java_instanceof_expr (code_assert.assertion ());
376
378
377
- INVARIANT (
378
- code_assert.assertion ().operands ().size ()==2 ,
379
- " Instanceof should have 2 operands" );
380
-
381
- const auto & instanceof = to_binary_expr (code_assert.assertion ());
382
-
383
- code = check_class_cast (
384
- instanceof.op0 (), instanceof.op1 (), code_assert.source_location ());
379
+ code = check_class_cast (instanceof.tested_expr (),
380
+ instanceof
381
+ .target_type (), code_assert.source_location ());
385
382
}
386
383
}
387
384
else if (statement==ID_block)
0 commit comments