@@ -437,6 +437,25 @@ static void allocate_array(
437
437
info.block .add (assign);
438
438
}
439
439
440
+ // / Declare a non-deterministic length expression
441
+ // / \param[out] allocate: allocation functor
442
+ // / \param[out] code: code block to which code will get appended
443
+ // / \param loc: location for the created code
444
+ // / \return the length expression that has been non-deterministically created
445
+ static symbol_exprt nondet_length (
446
+ allocate_objectst &allocate,
447
+ code_blockt &code,
448
+ source_locationt loc)
449
+ {
450
+ const symbol_exprt length_expr = allocate.allocate_automatic_local_object (
451
+ java_int_type (), " user_specified_array_length" );
452
+ code.add (code_assignt{
453
+ length_expr, side_effect_expr_nondett{java_int_type (), std::move (loc)}});
454
+ code.add (code_assumet{binary_predicate_exprt{
455
+ length_expr, ID_ge, from_integer (0 , java_int_type ())}});
456
+ return length_expr;
457
+ }
458
+
440
459
// / One of the cases in the recursive algorithm: the case where \p expr
441
460
// / represents an array.
442
461
// / The length of the array is given by a symbol: \p given_length_expr if it is
@@ -464,19 +483,14 @@ static void assign_array_from_json(
464
483
const auto &element_type =
465
484
java_array_element_type (to_struct_tag_type (expr.type ().subtype ()));
466
485
467
- exprt length_expr;
468
- if (given_length_expr)
469
- length_expr = *given_length_expr;
470
- else
471
- {
472
- length_expr = info.allocate_objects .allocate_automatic_local_object (
473
- java_int_type (), " user_specified_array_length" );
474
- info.block .add (code_assignt{
475
- length_expr, side_effect_expr_nondett{java_int_type (), info.loc }});
476
- info.block .add (code_assumet{binary_predicate_exprt{
477
- length_expr, ID_ge, from_integer (0 , java_int_type ())}});
478
- allocate_array (expr, length_expr, info);
479
- }
486
+ const exprt length_expr = [&] {
487
+ if (given_length_expr)
488
+ return *given_length_expr;
489
+ const symbol_exprt length =
490
+ nondet_length (info.allocate_objects , info.block , info.loc );
491
+ allocate_array (expr, length, info);
492
+ return length;
493
+ }();
480
494
const json_arrayt json_array = get_untyped_array (json, element_type);
481
495
const auto number_of_elements =
482
496
from_integer (json_array.size (), java_int_type ());
0 commit comments