@@ -42,6 +42,8 @@ class java_object_factoryt:public messaget
42
42
std::set<irep_idt> recursion_set;
43
43
bool assume_non_null;
44
44
size_t max_nondet_array_length;
45
+ size_t recursion_depth;
46
+ size_t max_recursion_depth;
45
47
symbol_tablet &symbol_table;
46
48
message_handlert &message_handler;
47
49
namespacet ns;
@@ -51,11 +53,14 @@ class java_object_factoryt:public messaget
51
53
code_blockt &_init_code,
52
54
bool _assume_non_null,
53
55
size_t _max_nondet_array_length,
56
+ size_t _max_recursion_depth,
54
57
symbol_tablet &_symbol_table,
55
58
message_handlert &_message_handler):
56
59
init_code (_init_code),
57
60
assume_non_null (_assume_non_null),
58
61
max_nondet_array_length (_max_nondet_array_length),
62
+ recursion_depth (0 ),
63
+ max_recursion_depth (_max_recursion_depth),
59
64
symbol_table (_symbol_table),
60
65
message_handler (_message_handler),
61
66
ns (_symbol_table)
@@ -189,20 +194,23 @@ void java_object_factoryt::gen_nondet_init(
189
194
{
190
195
const struct_typet &struct_type=to_struct_type (subtype);
191
196
const irep_idt struct_tag=struct_type.get_tag ();
192
- // set to null if found in recursion set and not a sub-type
193
- if (recursion_set.find (struct_tag)!=recursion_set.end () &&
194
- struct_tag==class_identifier)
197
+ // set to null if found in recursion set and recursion depth allows it
198
+ if (recursion_set.find (struct_tag)!=recursion_set.end ())
195
199
{
196
- // make null
197
- null_pointer_exprt null_pointer_expr (pointer_type);
198
- code_assignt code (expr, null_pointer_expr);
199
- code.add_source_location ()=loc;
200
- init_code.copy_to_operands (code);
201
-
202
- return ;
200
+ if (recursion_depth<max_recursion_depth)
201
+ recursion_depth++;
202
+ else
203
+ {
204
+ recursion_depth=0 ;
205
+ // make null
206
+ null_pointer_exprt null_pointer_expr (pointer_type);
207
+ code_assignt code (expr, null_pointer_expr);
208
+ code.add_source_location ()=loc;
209
+ init_code.copy_to_operands (code);
210
+ return ;
211
+ }
203
212
}
204
213
}
205
-
206
214
code_labelt set_null_label;
207
215
code_labelt init_done_label;
208
216
@@ -483,12 +491,14 @@ void gen_nondet_init(
483
491
bool create_dyn_objs,
484
492
bool assume_non_null,
485
493
message_handlert &message_handler,
486
- size_t max_nondet_array_length)
494
+ size_t max_nondet_array_length,
495
+ size_t max_recursion_depth)
487
496
{
488
497
java_object_factoryt state (
489
498
init_code,
490
499
assume_non_null,
491
500
max_nondet_array_length,
501
+ max_recursion_depth,
492
502
symbol_table,
493
503
message_handler);
494
504
state.gen_nondet_init (
@@ -567,6 +577,7 @@ exprt object_factory(
567
577
bool allow_null,
568
578
symbol_tablet &symbol_table,
569
579
size_t max_nondet_array_length,
580
+ size_t max_recursion_depth,
570
581
const source_locationt &loc,
571
582
message_handlert &message_handler)
572
583
{
@@ -588,7 +599,8 @@ exprt object_factory(
588
599
false ,
589
600
!allow_null,
590
601
message_handler,
591
- max_nondet_array_length);
602
+ max_nondet_array_length,
603
+ max_recursion_depth);
592
604
593
605
return object;
594
606
}
0 commit comments