Skip to content

Commit cf0f085

Browse files
Use replace_expr_copy to clarify loop in dec_solve
1 parent 00aaa6d commit cf0f085

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,15 @@ static void make_char_array_pointer_associations(
270270
}
271271
}
272272

273-
void replace_symbols_in_equations(
274-
const union_find_replacet &symbol_resolve,
275-
std::vector<equal_exprt> &equations)
273+
/// Substitute sub-expressions in equation by representative elements of
274+
/// `symbol_resolve` whenever possible.
275+
/// Similar to `symbol_resolve.replace_expr` but doesn't mutate the expression
276+
/// and returns the transformed expression instead.
277+
static exprt
278+
replace_expr_copy(const union_find_replacet &symbol_resolve, exprt expr)
276279
{
277-
for(equal_exprt &eq : equations)
278-
symbol_resolve.replace_expr(eq);
280+
symbol_resolve.replace_expr(expr);
281+
return expr;
279282
}
280283

281284
/// Record the constraints to ensure that the expression is true when
@@ -654,11 +657,15 @@ decision_proceduret::resultt string_refinementt::dec_solve()
654657
std::vector<equal_exprt> local_equations;
655658
for(const equal_exprt &eq : equations)
656659
{
657-
equal_exprt eq_copy = eq;
658-
// Char array symbols are replaced by cannonical element to ensure
659-
// equal arrays are associated to the same nodes in the graph.
660-
symbol_resolve.replace_expr(eq_copy);
661-
if(!add_node(dependencies, eq_copy, generator.array_pool))
660+
// Ensures that arrays that are equal, are associated to the same nodes
661+
// in the graph.
662+
const equal_exprt eq_with_char_array_replaced_with_representative_elements =
663+
to_equal_expr(replace_expr_copy(symbol_resolve, eq));
664+
const bool node_added = add_node(
665+
dependencies,
666+
eq_with_char_array_replaced_with_representative_elements,
667+
generator.array_pool);
668+
if(!node_added)
662669
local_equations.push_back(eq);
663670
}
664671
equations.clear();

0 commit comments

Comments
 (0)