@@ -458,55 +458,42 @@ static symbol_exprt nondet_length(
458
458
459
459
// / One of the cases in the recursive algorithm: the case where \p expr
460
460
// / represents an array.
461
- // / The length of the array is given by a symbol: \p given_length_expr if it is
462
- // / specified (this will be the case when there are two or more reference-equal
463
- // / arrays), or a fresh symbol otherwise.
464
- // / If \p given_length_expr is specified, we assume that an array with this
465
- // / symbol as its length has already been allocated and that \p expr has been
466
- // / assigned to it.
467
- // / Either way, the length symbol stores a nondet integer, and we add
468
- // / constraints on this: if "nondetLength" is specified in \p json, then the
469
- // / number of elements specified in \p json should be the minimum length of the
470
- // / array. Otherwise the number of elements should be the exact length of the
471
- // / array.
461
+ // / The length of the array is given by symbol \p given_length_expr.
462
+ // / We assume that an array with this symbol as its length has already been
463
+ // / allocated and that \p expr has been assigned to it.
464
+ // / We add constraints on the length: if "nondetLength" is specified in \p json,
465
+ // / then the number of elements specified in \p json should be smaller than the
466
+ // / length of the array. Otherwise the number of elements should be the exact
467
+ // / length of the array.
472
468
// / For the assignment of the array elements, see
473
469
// / \ref assign_array_data_component_from_json.
474
470
// / For the overall algorithm, see \ref assign_from_json_rec.
475
471
static void assign_array_from_json (
476
472
const exprt &expr,
477
473
const jsont &json,
478
- const optionalt<symbol_exprt> &given_length_expr,
474
+ const exprt &given_length_expr,
479
475
const optionalt<std::string> &type_from_array,
480
476
object_creation_infot &info)
481
477
{
482
478
PRECONDITION (is_java_array_type (expr.type ()));
483
479
const auto &element_type =
484
480
java_array_element_type (to_struct_tag_type (expr.type ().subtype ()));
485
-
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_expr, info);
492
- return length;
493
- }();
494
481
const json_arrayt json_array = get_untyped_array (json, element_type);
495
482
const auto number_of_elements =
496
483
from_integer (json_array.size (), java_int_type ());
497
484
info.block .add (code_assumet{
498
- binary_predicate_exprt{length_expr , ID_ge, number_of_elements}});
485
+ binary_predicate_exprt{given_length_expr , ID_ge, number_of_elements}});
499
486
if (has_nondet_length (json))
500
487
{
501
488
info.block .add (code_assumet{binary_predicate_exprt{
502
- length_expr ,
489
+ given_length_expr ,
503
490
ID_le,
504
491
from_integer (info.max_user_array_length , java_int_type ())}});
505
492
}
506
493
else
507
494
{
508
495
info.block .add (code_assumet{
509
- binary_predicate_exprt{length_expr , ID_le, number_of_elements}});
496
+ binary_predicate_exprt{given_length_expr , ID_le, number_of_elements}});
510
497
}
511
498
assign_array_data_component_from_json (expr, json, type_from_array, info);
512
499
}
@@ -784,8 +771,10 @@ static void assign_reference_from_json(
784
771
{
785
772
if (is_java_array_type (expr.type ()))
786
773
{
774
+ INVARIANT (
775
+ reference.array_length , " an array reference should stores its length" );
787
776
assign_array_from_json (
788
- reference.expr , json, reference.array_length , type_from_array, info);
777
+ reference.expr , json, * reference.array_length , type_from_array, info);
789
778
}
790
779
else
791
780
assign_struct_from_json (dereference_exprt (reference.expr ), json, info);
@@ -823,7 +812,12 @@ void assign_from_json_rec(
823
812
assign_reference_from_json (expr, json, type_from_array, info);
824
813
}
825
814
else if (is_java_array_type (expr.type ()))
826
- assign_array_from_json (expr, json, {}, type_from_array, info);
815
+ {
816
+ const exprt length =
817
+ nondet_length (info.allocate_objects , info.block , info.loc );
818
+ allocate_array (expr, length, info);
819
+ assign_array_from_json (expr, json, length, type_from_array, info);
820
+ }
827
821
else if (
828
822
const auto runtime_type =
829
823
::runtime_type (json, type_from_array, info.symbol_table))
0 commit comments