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)
@@ -537,11 +541,10 @@ union_find_replacet string_identifiers_resolution_from_equations(
537
541
// / Output a vector of equations to the given stream, used for debugging.
538
542
static void output_equations (
539
543
std::ostream &output,
540
- const std::vector<equal_exprt > &equations)
544
+ const std::vector<exprt > &equations)
541
545
{
542
546
for (std::size_t i = 0 ; i < equations.size (); ++i)
543
- output << " [" << i << " ] " << format (equations[i].lhs ())
544
- << " == " << format (equations[i].rhs ()) << std::endl;
547
+ output << " [" << i << " ] " << format (equations[i]) << std::endl;
545
548
}
546
549
#endif
547
550
@@ -630,7 +633,18 @@ decision_proceduret::resultt string_refinementt::dec_solve()
630
633
#endif
631
634
632
635
const union_find_replacet string_id_symbol_resolve =
633
- string_identifiers_resolution_from_equations (equations, ns, log.debug ());
636
+ string_identifiers_resolution_from_equations (
637
+ [&] {
638
+ std::vector<equal_exprt> equalities;
639
+ for (const auto &eq : equations)
640
+ {
641
+ if (auto equal_expr = expr_try_dynamic_cast<equal_exprt>(eq))
642
+ equalities.push_back (*equal_expr);
643
+ }
644
+ return equalities;
645
+ }(),
646
+ ns,
647
+ log.debug ());
634
648
#ifdef DEBUG
635
649
log.debug () << " symbol resolve string:" << messaget::eom;
636
650
for (const auto &pair : string_id_symbol_resolve.to_vector ())
@@ -643,7 +657,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
643
657
log.debug () << " dec_solve: Replacing string ids and simplifying arguments"
644
658
" in function applications"
645
659
<< messaget::eom;
646
- for (equal_exprt &expr : equations)
660
+ for (exprt &expr : equations)
647
661
{
648
662
auto it = expr.depth_begin ();
649
663
while (it != expr.depth_end ())
@@ -675,12 +689,12 @@ decision_proceduret::resultt string_refinementt::dec_solve()
675
689
log.debug () << " dec_solve: compute dependency graph and remove function "
676
690
<< " applications captured by the dependencies:" << messaget::eom;
677
691
std::vector<exprt> local_equations;
678
- for (const equal_exprt &eq : equations)
692
+ for (const exprt &eq : equations)
679
693
{
680
694
// Ensures that arrays that are equal, are associated to the same nodes
681
695
// 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) );
696
+ const exprt eq_with_char_array_replaced_with_representative_elements =
697
+ replace_expr_copy (symbol_resolve, eq);
684
698
const optionalt<exprt> new_equation = add_node (
685
699
dependencies,
686
700
eq_with_char_array_replaced_with_representative_elements,
0 commit comments