@@ -1224,18 +1224,18 @@ void debug_model(
1224
1224
1225
1225
sparse_arrayt::sparse_arrayt (const with_exprt &expr)
1226
1226
{
1227
- auto ref = std::ref (static_cast <const exprt &>(expr));
1228
- while (can_cast_expr<with_exprt>(ref .get ()))
1227
+ auto ref_to_current_expr = std::ref (static_cast <const exprt &>(expr));
1228
+ while (can_cast_expr<with_exprt>(ref_to_current_expr .get ()))
1229
1229
{
1230
- const auto &with_expr = expr_dynamic_cast<with_exprt>(ref .get ());
1230
+ const auto &with_expr = expr_dynamic_cast<with_exprt>(ref_to_current_expr .get ());
1231
1231
const auto current_index = numeric_cast_v<std::size_t >(with_expr.where ());
1232
1232
entries.emplace_back (current_index, with_expr.new_value ());
1233
- ref = with_expr.old ();
1233
+ ref_to_current_expr = with_expr.old ();
1234
1234
}
1235
1235
1236
1236
// This function only handles 'with' and 'array_of' expressions
1237
- PRECONDITION (ref .get ().id () == ID_array_of);
1238
- default_value = expr_dynamic_cast<array_of_exprt>(ref .get ()).what ();
1237
+ PRECONDITION (ref_to_current_expr .get ().id () == ID_array_of);
1238
+ default_value = expr_dynamic_cast<array_of_exprt>(ref_to_current_expr .get ()).what ();
1239
1239
}
1240
1240
1241
1241
exprt sparse_arrayt::to_if_expression (const exprt &index) const
@@ -1456,6 +1456,25 @@ static exprt substitute_array_access(
1456
1456
UNREACHABLE;
1457
1457
}
1458
1458
1459
+ // / Auxiliary function for substitute_array_access
1460
+ // / Performs the same operation but modifies the argument instead of returning
1461
+ // / the resulting expression.
1462
+ static void substitute_array_access_in_place (
1463
+ exprt &expr,
1464
+ const std::function<symbol_exprt(const irep_idt &, const typet &)>
1465
+ &symbol_generator,
1466
+ const bool left_propagate)
1467
+ {
1468
+ if (const auto index_expr = expr_try_dynamic_cast<index_exprt>(expr))
1469
+ {
1470
+ expr =
1471
+ substitute_array_access (*index_expr, symbol_generator, left_propagate);
1472
+ }
1473
+
1474
+ for (auto &op : expr.operands ())
1475
+ substitute_array_access_in_place (op, symbol_generator, left_propagate);
1476
+ }
1477
+
1459
1478
// / Create an equivalent expression where array accesses and 'with' expressions
1460
1479
// / are replaced by 'if' expressions, in particular:
1461
1480
// / * for an array access `arr[index]`, where:
@@ -1477,35 +1496,14 @@ static exprt substitute_array_access(
1477
1496
// / expressions
1478
1497
// / \return an expression containing no array access, and a Boolean which is
1479
1498
// / true if the expression is unchanged
1480
- std::pair< exprt, bool > substitute_array_access (
1481
- const exprt & expr,
1499
+ exprt substitute_array_access (
1500
+ exprt expr,
1482
1501
const std::function<symbol_exprt(const irep_idt &, const typet &)>
1483
1502
&symbol_generator,
1484
1503
const bool left_propagate)
1485
1504
{
1486
- if (const auto index_expr = expr_try_dynamic_cast<index_exprt>(expr))
1487
- {
1488
- const exprt substituted =
1489
- substitute_array_access (*index_expr, symbol_generator, left_propagate);
1490
- return {substituted, false };
1491
- }
1492
-
1493
- exprt::operandst operands;
1494
- bool unchanged = true ;
1495
- for (auto &op : expr.operands ())
1496
- {
1497
- std::pair<exprt, bool > pair =
1498
- substitute_array_access (op, symbol_generator, left_propagate);
1499
- unchanged = unchanged && pair.second ;
1500
- operands.push_back (pair.first );
1501
- }
1502
-
1503
- if (unchanged)
1504
- return {expr, true };
1505
-
1506
- exprt copy (expr);
1507
- copy.operands () = std::move (operands);
1508
- return {copy, false };
1505
+ substitute_array_access_in_place (expr, symbol_generator, left_propagate);
1506
+ return expr;
1509
1507
}
1510
1508
1511
1509
// / Negates the constraint to be fed to a solver. The intended usage is to find
@@ -1735,7 +1733,7 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
1735
1733
1736
1734
stream << indent << i << " .\n " ;
1737
1735
const exprt with_concretized_arrays =
1738
- substitute_array_access (negaxiom, gen_symbol, true ). first ;
1736
+ substitute_array_access (negaxiom, gen_symbol, true );
1739
1737
debug_check_axioms_step (
1740
1738
stream, ns, axiom, axiom_in_model, negaxiom, with_concretized_arrays);
1741
1739
@@ -1787,7 +1785,7 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
1787
1785
1788
1786
negaxiom = simplify_expr (negaxiom, ns);
1789
1787
const exprt with_concrete_arrays =
1790
- substitute_array_access (negaxiom, gen_symbol, true ). first ;
1788
+ substitute_array_access (negaxiom, gen_symbol, true );
1791
1789
1792
1790
stream << indent << i << " .\n " ;
1793
1791
debug_check_axioms_step (
0 commit comments