Skip to content

Commit 5ceaec0

Browse files
committed
WIP
1 parent bb48aa4 commit 5ceaec0

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/solvers/strings/string_refinement.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,34 @@ decision_proceduret::resultt string_refinementt::dec_solve()
854854
return resultt::D_ERROR;
855855
}
856856

857+
static exprt simplify_if_recursive(exprt expr, const namespacet &ns)
858+
{
859+
for(auto it = expr.depth_begin(); it != expr.depth_end(); )
860+
{
861+
if(it->id() == ID_if)
862+
{
863+
if_exprt if_expr = to_if_expr(*it);
864+
const exprt simp_cond = simplify_expr(if_expr.cond(), ns);
865+
if(simp_cond.is_true())
866+
{
867+
it.mutate() = simplify_if_recursive(if_expr.true_case(), ns);
868+
it.next_sibling_or_parent();
869+
}
870+
else if(simp_cond.is_false())
871+
{
872+
it.mutate() = simplify_if_recursive(if_expr.false_case(), ns);
873+
it.next_sibling_or_parent();
874+
}
875+
else
876+
++it;
877+
}
878+
else
879+
++it;
880+
}
881+
882+
return expr;
883+
}
884+
857885
/// Add the given lemma to the solver.
858886
/// \param lemma: a Boolean expression
859887
/// \param simplify_lemma: whether the lemma should be simplified before being
@@ -869,7 +897,10 @@ void string_refinementt::add_lemma(
869897

870898
exprt simple_lemma = lemma;
871899
if(simplify_lemma)
900+
{
901+
simple_lemma = simplify_if_recursive(std::move(simple_lemma), ns);
872902
simplify(simple_lemma, ns);
903+
}
873904

874905
if(simple_lemma.is_true())
875906
{

src/util/simplify_expr.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Author: Daniel Kroening, [email protected]
3131

3232
// #define DEBUGX
3333

34-
#ifdef DEBUGX
34+
//#ifdef DEBUGX
3535
#include "format_expr.h"
3636
#include <iostream>
37-
#endif
37+
//#endif
3838

3939
#include "simplify_expr_class.h"
4040

@@ -2542,6 +2542,12 @@ bool simplify_exprt::simplify_rec(exprt &expr)
25422542

25432543
if(!result)
25442544
{
2545+
if(tmp.type() != expr.type())
2546+
{
2547+
std::cerr << format(tmp) << std::endl;
2548+
std::cerr << format(expr) << std::endl;
2549+
std::cerr << expr.type().pretty() << std::endl;
2550+
}
25452551
POSTCONDITION(tmp.type() == expr.type());
25462552
expr.swap(tmp);
25472553

0 commit comments

Comments
 (0)