27
27
#include < util/expr_iterator.h>
28
28
#include < util/expr_util.h>
29
29
#include < util/magic.h>
30
+ #include < util/range.h>
30
31
#include < util/simplify_expr.h>
31
32
32
33
#include " equation_symbol_mapping.h"
@@ -306,16 +307,19 @@ void string_refinementt::set_to(const exprt &expr, bool value)
306
307
// / by an equation are associated to the same element
307
308
static void add_equations_for_symbol_resolution (
308
309
union_find_replacet &symbol_solver,
309
- const std::vector<equal_exprt > &equations,
310
+ const std::vector<exprt > &equations,
310
311
const namespacet &ns,
311
312
messaget::mstreamt &stream)
312
313
{
313
314
const std::string log_message =
314
315
" WARNING string_refinement.cpp generate_symbol_resolution_from_equations:" ;
315
- for (const equal_exprt &eq : equations)
316
+ auto equalities = make_range (equations).filter (
317
+ [&](const exprt &e) { return can_cast_expr<equal_exprt>(e); });
318
+ for (const exprt &e : equalities)
316
319
{
317
- const exprt &lhs = eq.lhs ();
318
- const exprt &rhs = eq.rhs ();
320
+ const equal_exprt &eq = to_equal_expr (e);
321
+ const exprt &lhs = to_equal_expr (eq).lhs ();
322
+ const exprt &rhs = to_equal_expr (eq).rhs ();
319
323
if (lhs.id () != ID_symbol)
320
324
{
321
325
stream << log_message << " non symbol lhs: " << format (lhs)
@@ -535,13 +539,11 @@ union_find_replacet string_identifiers_resolution_from_equations(
535
539
536
540
#ifdef DEBUG
537
541
// / Output a vector of equations to the given stream, used for debugging.
538
- static void output_equations (
539
- std::ostream &output,
540
- const std::vector<equal_exprt> &equations)
542
+ static void
543
+ output_equations (std::ostream &output, const std::vector<exprt> &equations)
541
544
{
542
545
for (std::size_t i = 0 ; i < equations.size (); ++i)
543
- output << " [" << i << " ] " << format (equations[i].lhs ())
544
- << " == " << format (equations[i].rhs ()) << std::endl;
546
+ output << " [" << i << " ] " << format (equations[i]) << std::endl;
545
547
}
546
548
#endif
547
549
@@ -630,7 +632,18 @@ decision_proceduret::resultt string_refinementt::dec_solve()
630
632
#endif
631
633
632
634
const union_find_replacet string_id_symbol_resolve =
633
- string_identifiers_resolution_from_equations (equations, ns, log.debug ());
635
+ string_identifiers_resolution_from_equations (
636
+ [&] {
637
+ std::vector<equal_exprt> equalities;
638
+ for (const auto &eq : equations)
639
+ {
640
+ if (auto equal_expr = expr_try_dynamic_cast<equal_exprt>(eq))
641
+ equalities.push_back (*equal_expr);
642
+ }
643
+ return equalities;
644
+ }(),
645
+ ns,
646
+ log.debug ());
634
647
#ifdef DEBUG
635
648
log.debug () << " symbol resolve string:" << messaget::eom;
636
649
for (const auto &pair : string_id_symbol_resolve.to_vector ())
@@ -643,7 +656,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
643
656
log.debug () << " dec_solve: Replacing string ids and simplifying arguments"
644
657
" in function applications"
645
658
<< messaget::eom;
646
- for (equal_exprt &expr : equations)
659
+ for (exprt &expr : equations)
647
660
{
648
661
auto it = expr.depth_begin ();
649
662
while (it != expr.depth_end ())
@@ -675,12 +688,12 @@ decision_proceduret::resultt string_refinementt::dec_solve()
675
688
log.debug () << " dec_solve: compute dependency graph and remove function "
676
689
<< " applications captured by the dependencies:" << messaget::eom;
677
690
std::vector<exprt> local_equations;
678
- for (const equal_exprt &eq : equations)
691
+ for (const exprt &eq : equations)
679
692
{
680
693
// Ensures that arrays that are equal, are associated to the same nodes
681
694
// in the graph.
682
- const equal_exprt eq_with_char_array_replaced_with_representative_elements =
683
- to_equal_expr ( replace_expr_copy (symbol_resolve, eq) );
695
+ const exprt eq_with_char_array_replaced_with_representative_elements =
696
+ replace_expr_copy (symbol_resolve, eq);
684
697
const optionalt<exprt> new_equation = add_node (
685
698
dependencies,
686
699
eq_with_char_array_replaced_with_representative_elements,
0 commit comments