Skip to content

Commit f07cbb1

Browse files
Make equations of type exprt instead of equal_exprt
Accept formulas that are not equations as input. This is to make the solver more robust to different kind of formulas. In particular, formulas of the form `guard1 => result = some_string_builin_function(s)` should be accepted.
1 parent 95f599e commit f07cbb1

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/solvers/strings/string_refinement.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Author: Alberto Griggio, [email protected]
2727
#include <util/expr_iterator.h>
2828
#include <util/expr_util.h>
2929
#include <util/magic.h>
30+
#include <util/range.h>
3031
#include <util/simplify_expr.h>
3132

3233
#include "equation_symbol_mapping.h"
@@ -306,16 +307,19 @@ void string_refinementt::set_to(const exprt &expr, bool value)
306307
/// by an equation are associated to the same element
307308
static void add_equations_for_symbol_resolution(
308309
union_find_replacet &symbol_solver,
309-
const std::vector<equal_exprt> &equations,
310+
const std::vector<exprt> &equations,
310311
const namespacet &ns,
311312
messaget::mstreamt &stream)
312313
{
313314
const std::string log_message =
314315
"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)
316319
{
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();
319323
if(lhs.id() != ID_symbol)
320324
{
321325
stream << log_message << "non symbol lhs: " << format(lhs)
@@ -535,13 +539,11 @@ union_find_replacet string_identifiers_resolution_from_equations(
535539

536540
#ifdef DEBUG
537541
/// 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)
541544
{
542545
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;
545547
}
546548
#endif
547549

@@ -630,7 +632,18 @@ decision_proceduret::resultt string_refinementt::dec_solve()
630632
#endif
631633

632634
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());
634647
#ifdef DEBUG
635648
log.debug() << "symbol resolve string:" << messaget::eom;
636649
for(const auto &pair : string_id_symbol_resolve.to_vector())
@@ -643,7 +656,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
643656
log.debug() << "dec_solve: Replacing string ids and simplifying arguments"
644657
" in function applications"
645658
<< messaget::eom;
646-
for(equal_exprt &expr : equations)
659+
for(exprt &expr : equations)
647660
{
648661
auto it = expr.depth_begin();
649662
while(it != expr.depth_end())
@@ -675,12 +688,12 @@ decision_proceduret::resultt string_refinementt::dec_solve()
675688
log.debug() << "dec_solve: compute dependency graph and remove function "
676689
<< "applications captured by the dependencies:" << messaget::eom;
677690
std::vector<exprt> local_equations;
678-
for(const equal_exprt &eq : equations)
691+
for(const exprt &eq : equations)
679692
{
680693
// Ensures that arrays that are equal, are associated to the same nodes
681694
// 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);
684697
const optionalt<exprt> new_equation = add_node(
685698
dependencies,
686699
eq_with_char_array_replaced_with_representative_elements,

src/solvers/strings/string_refinement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class string_refinementt final : public bv_refinementt
111111
index_set_pairt index_sets;
112112
union_find_replacet symbol_resolve;
113113

114-
std::vector<equal_exprt> equations;
114+
std::vector<exprt> equations;
115115

116116
string_dependenciest dependencies;
117117

0 commit comments

Comments
 (0)