@@ -14,15 +14,11 @@ Date: June 2017
14
14
#include < util/fresh_symbol.h>
15
15
#include < util/std_code.h>
16
16
#include < util/std_expr.h>
17
- #include < util/symbol_table.h>
18
17
#include < util/c_types.h>
19
18
20
19
#include < goto-programs/goto_functions.h>
21
20
22
21
#include " java_bytecode_convert_class.h"
23
- #include " java_entry_point.h"
24
- #include " java_root_class.h"
25
- #include " java_types.h"
26
22
#include " java_utils.h"
27
23
28
24
class java_bytecode_instrumentt :public messaget
@@ -39,7 +35,7 @@ class java_bytecode_instrumentt:public messaget
39
35
{
40
36
}
41
37
42
- void operator ()(exprt &expr );
38
+ void operator ()(codet &code );
43
39
44
40
protected:
45
41
symbol_table_baset &symbol_table;
@@ -73,29 +69,26 @@ class java_bytecode_instrumentt:public messaget
73
69
const exprt &length,
74
70
const source_locationt &original_loc);
75
71
76
- void instrument_code (exprt &expr );
72
+ void instrument_code (codet &code );
77
73
void add_expr_instrumentation (code_blockt &block, const exprt &expr);
78
74
void prepend_instrumentation (codet &code, code_blockt &instrumentation);
79
- codet instrument_expr (const exprt &expr);
75
+ optionalt< codet> instrument_expr (const exprt &expr);
80
76
};
81
77
82
-
83
- const std::vector<irep_idt> exception_needed_classes =
84
- {
78
+ const std::vector<std::string> exception_needed_classes = { // NOLINT
85
79
" java.lang.ArithmeticException" ,
86
80
" java.lang.ArrayIndexOutOfBoundsException" ,
87
81
" java.lang.ClassCastException" ,
88
82
" java.lang.NegativeArraySizeException" ,
89
- " java.lang.NullPointerException"
90
- };
83
+ " java.lang.NullPointerException" };
91
84
92
85
// / Creates a class stub for exc_name and generates a
93
86
// / conditional GOTO such that exc_name is thrown when
94
87
// / cond is met.
95
- // / \par parameters: ` cond` : condition to be met in order
88
+ // / \param cond: condition to be met in order
96
89
// / to throw an exception
97
- // / ` original_loc` : source location in the original program
98
- // / ` exc_name` : the name of the exception to be thrown
90
+ // / \param original_loc: source location in the original program
91
+ // / \param exc_name: the name of the exception to be thrown
99
92
// / \return Returns the code initialising the throwing the
100
93
// / exception
101
94
codet java_bytecode_instrumentt::throw_exception (
@@ -178,9 +171,9 @@ codet java_bytecode_instrumentt::check_arithmetic_exception(
178
171
// / and throws ArrayIndexOutofBoundsException/generates an assertion
179
172
// / if necessary; Exceptions are thrown when the `throw_runtime_exceptions`
180
173
// / flag is set. Otherwise, assertions are emitted.
181
- // / \par parameters: ` array_struct`: the array being accessed
182
- // / ` idx` : index into the array
183
- // / ` original_loc: source location in the original code
174
+ // / \param array_struct: array being accessed
175
+ // / \param idx: index into the array
176
+ // / \param original_loc: source location in the original code
184
177
// / \return Based on the value of the flag `throw_runtime_exceptions`,
185
178
// / it returns code that either throws an ArrayIndexOutPfBoundsException
186
179
// / or emits an assertion checking the array access
@@ -223,9 +216,9 @@ codet java_bytecode_instrumentt::check_array_access(
223
216
// / ClassCastException/generates an assertion when necessary;
224
217
// / Exceptions are thrown when the `throw_runtime_exceptions` flag is set.
225
218
// / Otherwise, assertions are emitted.
226
- // / \par parameters: ` class1` : the subclass
227
- // / ` class2` : the super class
228
- // / ` original_loc: source location in the original code
219
+ // / \param class1: the subclass
220
+ // / \param class2: the super class
221
+ // / \param original_loc: source location in the original code
229
222
// / \return Based on the value of the flag `throw_runtime_exceptions`,
230
223
// / it returns code that either throws an ClassCastException or emits an
231
224
// / assertion checking the subtype relation
@@ -272,7 +265,7 @@ codet java_bytecode_instrumentt::check_class_cast(
272
265
// / generates an assertion when necessary;
273
266
// / Exceptions are thrown when the `throw_runtime_exceptions` flag is set.
274
267
// / Otherwise, assertions are emitted.
275
- // / \par parameters: ` expr` : the checked expression
268
+ // / \param expr: the checked expression
276
269
// / `original_loc: source location in the original code
277
270
// / \return Based on the value of the flag `throw_runtime_exceptions`,
278
271
// / it returns code that either throws an NullPointerException or emits an
@@ -302,8 +295,8 @@ codet java_bytecode_instrumentt::check_null_dereference(
302
295
// / generates an assertion when necessary;
303
296
// / Exceptions are thrown when the `throw_runtime_exceptions` flag is set.
304
297
// / Otherwise, assertions are emitted.
305
- // / \par parameters: ` length` : the checked length
306
- // / ` original_loc: source location in the original code
298
+ // / \param length: the checked length
299
+ // / \param original_loc: source location in the original code
307
300
// / \return Based on the value of the flag `throw_runtime_exceptions`,
308
301
// / it returns code that either throws an NegativeArraySizeException
309
302
// / or emits an assertion checking the subtype relation
@@ -335,13 +328,12 @@ void java_bytecode_instrumentt::add_expr_instrumentation(
335
328
code_blockt &block,
336
329
const exprt &expr)
337
330
{
338
- codet expr_instrumentation=instrument_expr (expr);
339
- if (expr_instrumentation!=code_skipt ())
331
+ if (optionalt<codet> expr_instrumentation = instrument_expr (expr))
340
332
{
341
- if (expr_instrumentation. get_statement ()== ID_block)
342
- block.append (to_code_block (expr_instrumentation));
333
+ if (expr_instrumentation-> get_statement () == ID_block)
334
+ block.append (to_code_block (* expr_instrumentation));
343
335
else
344
- block.move_to_operands (expr_instrumentation);
336
+ block.move_to_operands (* expr_instrumentation);
345
337
}
346
338
}
347
339
@@ -365,10 +357,9 @@ void java_bytecode_instrumentt::prepend_instrumentation(
365
357
366
358
// / Augments `expr` with instrumentation in the form of either
367
359
// / assertions or runtime exceptions
368
- // / \par parameters: `expr`: the expression to be instrumented
369
- void java_bytecode_instrumentt::instrument_code (exprt &expr )
360
+ // / \param `expr` the expression to be instrumented
361
+ void java_bytecode_instrumentt::instrument_code (codet &code )
370
362
{
371
- codet &code=to_code (expr);
372
363
source_locationt old_source_location=code.source_location ();
373
364
374
365
const irep_idt &statement=code.get_statement ();
@@ -480,19 +471,17 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
480
471
481
472
// / Computes the instrumentation for `expr` in the form of
482
473
// / either assertions or runtime exceptions.
483
- // / \par parameters: ` expr` : the expression for which we compute
474
+ // / \param expr: the expression for which we compute
484
475
// / instrumentation
485
- // / \return: The instrumentation required for `expr`
486
- codet java_bytecode_instrumentt::instrument_expr (
487
- const exprt &expr)
476
+ // / \return: The instrumentation for `expr` if required
477
+ optionalt<codet> java_bytecode_instrumentt::instrument_expr (const exprt &expr)
488
478
{
489
479
code_blockt result;
490
480
// First check our operands:
491
481
forall_operands (it, expr)
492
482
{
493
- codet op_result=instrument_expr (*it);
494
- if (op_result!=code_skipt ())
495
- result.move_to_operands (op_result);
483
+ if (optionalt<codet> op_result = instrument_expr (*it))
484
+ result.move_to_operands (*op_result);
496
485
}
497
486
498
487
// Add any check due at this node:
@@ -524,7 +513,7 @@ codet java_bytecode_instrumentt::instrument_expr(
524
513
const irep_idt &statement=side_effect_expr.get_statement ();
525
514
if (statement==ID_throw)
526
515
{
527
- // this corresponds to athrow and so we check that
516
+ // this corresponds to a throw and so we check that
528
517
// we don't throw null
529
518
result.copy_to_operands (
530
519
check_null_dereference (
@@ -533,7 +522,7 @@ codet java_bytecode_instrumentt::instrument_expr(
533
522
}
534
523
else if (statement==ID_java_new_array)
535
524
{
536
- // this correpond to new array so we check that
525
+ // this corresponds to new array so we check that
537
526
// length is >=0
538
527
result.copy_to_operands (
539
528
check_array_length (
@@ -563,16 +552,16 @@ codet java_bytecode_instrumentt::instrument_expr(
563
552
}
564
553
565
554
if (result==code_blockt ())
566
- return code_skipt () ;
555
+ return {} ;
567
556
else
568
557
return result;
569
558
}
570
559
571
560
// / Instruments `expr`
572
- // / \par parameters: ` expr` : the expression to be instrumented
573
- void java_bytecode_instrumentt::operator ()(exprt &expr )
561
+ // / \param expr: the expression to be instrumented
562
+ void java_bytecode_instrumentt::operator ()(codet &code )
574
563
{
575
- instrument_code (expr );
564
+ instrument_code (code );
576
565
}
577
566
578
567
// / Instruments the code attached to `symbol` with
@@ -601,7 +590,7 @@ void java_bytecode_instrument_symbol(
601
590
" java_bytecode_instrument expects a code-typed symbol but was called with"
602
591
" " + id2string (symbol.name ) + " which has a value with an id of " +
603
592
id2string (symbol.value .id ()));
604
- instrument (symbol.value );
593
+ instrument (to_code ( symbol.value ) );
605
594
}
606
595
607
596
// / Instruments all the code in the symbol_table with
@@ -634,5 +623,5 @@ void java_bytecode_instrument(
634
623
// instrument(...) can add symbols to the table, so it's
635
624
// not safe to hold a reference to a symbol across a call.
636
625
for (const auto &symbol : symbols_to_instrument)
637
- instrument (symbol_table.get_writeable_ref (symbol).value );
626
+ instrument (to_code ( symbol_table.get_writeable_ref (symbol).value ) );
638
627
}
0 commit comments