6
6
7
7
\*******************************************************************/
8
8
9
- #include < set >
9
+ #include < unordered_set >
10
10
#include < sstream>
11
11
12
12
#include < util/arith_tools.h>
13
13
#include < util/fresh_symbol.h>
14
14
#include < util/std_types.h>
15
15
#include < util/std_code.h>
16
16
#include < util/std_expr.h>
17
- #include < util/message.h>
18
17
#include < util/namespace.h>
19
18
#include < util/pointer_offset_size.h>
20
19
#include < util/prefix.h>
25
24
#include " java_types.h"
26
25
#include " java_utils.h"
27
26
28
- class java_object_factoryt :public messaget
27
+ /* ******************************************************************\
28
+
29
+ Function: new_tmp_symbol
30
+
31
+ Inputs:
32
+
33
+ Outputs:
34
+
35
+ Purpose:
36
+
37
+ \*******************************************************************/
38
+
39
+ static symbolt &new_tmp_symbol (
40
+ symbol_tablet &symbol_table,
41
+ const source_locationt &loc,
42
+ const typet &type,
43
+ const std::string &prefix=" tmp_object_factory" )
44
+ {
45
+ return get_fresh_aux_symbol (
46
+ type,
47
+ " " ,
48
+ prefix,
49
+ loc,
50
+ ID_java,
51
+ symbol_table);
52
+ }
53
+
54
+ /* ******************************************************************\
55
+
56
+ Function: get_nondet_bool
57
+
58
+ Inputs: Desired type (C_bool or plain bool)
59
+
60
+ Outputs: nondet expr of that type
61
+
62
+ Purpose:
63
+
64
+ \*******************************************************************/
65
+
66
+ static exprt get_nondet_bool (const typet &type)
67
+ {
68
+ // We force this to 0 and 1 and won't consider
69
+ // other values.
70
+ return typecast_exprt (side_effect_expr_nondett (bool_typet ()), type);
71
+ }
72
+
73
+ class java_object_factoryt
29
74
{
30
75
code_blockt &init_code;
31
- std::set <irep_idt> recursion_set;
76
+ std::unordered_set <irep_idt, irep_id_hash > recursion_set;
32
77
bool assume_non_null;
33
78
size_t max_nondet_array_length;
34
79
symbol_tablet &symbol_table;
35
- message_handlert &message_handler;
36
80
namespacet ns;
37
81
38
82
public:
39
83
java_object_factoryt (
40
84
code_blockt &_init_code,
41
85
bool _assume_non_null,
42
86
size_t _max_nondet_array_length,
43
- symbol_tablet &_symbol_table,
44
- message_handlert &_message_handler):
87
+ symbol_tablet &_symbol_table):
45
88
init_code (_init_code),
46
89
assume_non_null (_assume_non_null),
47
90
max_nondet_array_length (_max_nondet_array_length),
48
91
symbol_table (_symbol_table),
49
- message_handler (_message_handler),
50
92
ns (_symbol_table)
51
93
{}
52
94
@@ -209,37 +251,23 @@ void java_object_factoryt::gen_nondet_init(
209
251
code_labelt set_null_label;
210
252
code_labelt init_done_label;
211
253
212
- static size_t synthetic_constructor_count=0 ;
213
-
214
254
if (!assume_non_null)
215
255
{
216
- auto returns_null_sym=
217
- new_tmp_symbol (
218
- symbol_table,
219
- loc,
220
- c_bool_typet (1 ),
221
- " opaque_returns_null" );
222
- auto returns_null=returns_null_sym.symbol_expr ();
223
- auto assign_returns_null=
224
- code_assignt (returns_null, get_nondet_bool (returns_null_sym.type ));
225
- assign_returns_null.add_source_location ()=loc;
226
- init_code.move_to_operands (assign_returns_null);
227
-
228
256
auto set_null_inst=
229
257
code_assignt (expr, null_pointer_exprt (pointer_type));
230
258
set_null_inst.add_source_location ()=loc;
231
259
260
+ static size_t synthetic_constructor_count=0 ;
232
261
std::string fresh_label=
233
262
" post_synthetic_malloc_" +std::to_string (++synthetic_constructor_count);
234
263
set_null_label=code_labelt (fresh_label, set_null_inst);
235
264
236
265
init_done_label=code_labelt (fresh_label+" _init_done" , code_skipt ());
237
266
238
267
code_ifthenelset null_check;
239
- exprt null_return=
240
- zero_initializer (returns_null_sym.type , loc, ns, message_handler);
268
+ exprt null_return=from_integer (0 , c_bool_typet (1 ));
241
269
null_check.cond ()=
242
- notequal_exprt (returns_null , null_return);
270
+ notequal_exprt (get_nondet_bool ( c_bool_typet ( 1 )) , null_return);
243
271
null_check.then_case ()=code_gotot (fresh_label);
244
272
init_code.move_to_operands (null_check);
245
273
}
@@ -471,52 +499,6 @@ void java_object_factoryt::gen_nondet_array_init(
471
499
472
500
/* ******************************************************************\
473
501
474
- Function: new_tmp_symbol
475
-
476
- Inputs:
477
-
478
- Outputs:
479
-
480
- Purpose:
481
-
482
- \*******************************************************************/
483
-
484
- symbolt &new_tmp_symbol (
485
- symbol_tablet &symbol_table,
486
- const source_locationt &loc,
487
- const typet &type,
488
- const std::string &prefix)
489
- {
490
- return get_fresh_aux_symbol (
491
- type,
492
- " " ,
493
- prefix,
494
- loc,
495
- ID_java,
496
- symbol_table);
497
- }
498
-
499
- /* ******************************************************************\
500
-
501
- Function: get_nondet_bool
502
-
503
- Inputs: Desired type (C_bool or plain bool)
504
-
505
- Outputs: nondet expr of that type
506
-
507
- Purpose:
508
-
509
- \*******************************************************************/
510
-
511
- exprt get_nondet_bool (const typet &type)
512
- {
513
- // We force this to 0 and 1 and won't consider
514
- // other values.
515
- return typecast_exprt (side_effect_expr_nondett (bool_typet ()), type);
516
- }
517
-
518
- /* ******************************************************************\
519
-
520
502
Function: object_factory
521
503
522
504
Inputs:
@@ -533,8 +515,7 @@ exprt object_factory(
533
515
bool allow_null,
534
516
symbol_tablet &symbol_table,
535
517
size_t max_nondet_array_length,
536
- const source_locationt &loc,
537
- message_handlert &message_handler)
518
+ const source_locationt &loc)
538
519
{
539
520
if (type.id ()==ID_pointer)
540
521
{
@@ -550,8 +531,7 @@ exprt object_factory(
550
531
init_code,
551
532
!allow_null,
552
533
max_nondet_array_length,
553
- symbol_table,
554
- message_handler);
534
+ symbol_table);
555
535
state.gen_nondet_init (
556
536
object,
557
537
false ,
0 commit comments