27 if(truth && cond.
id() == ID_lt && expr.
id() == ID_lt)
33 cond_lt.op0() == expr_lt.op0() && cond_lt.op1().is_constant() &&
34 expr_lt.op1().is_constant() &&
35 cond_lt.op1().type() == expr_lt.op1().type())
52 cond_lt.op1() == expr_lt.op1() && cond_lt.op0().is_constant() &&
53 expr_lt.op0().is_constant() &&
54 cond_lt.op0().type() == expr_lt.op0().type())
98 bool no_change =
true;
108 for(
const auto &op : cond.
operands())
117 bool no_change =
true;
127 for(
const auto &op : cond.
operands())
136 bool no_change =
true;
149 bool tno_change =
true;
150 bool fno_change =
true;
152 if(cond.
id() == ID_and)
157 else if(cond.
id() == ID_or)
173 return tno_change && fno_change;
178 bool no_change =
true;
185 if(expr.
id() == ID_and)
190 for(exprt::operandst::iterator it1 = operands.begin();
191 it1 != operands.end();
194 for(exprt::operandst::iterator it2 = operands.begin();
195 it2 != operands.end();
208 no_change = tmp && no_change;
231 result.
cond() = std::move(cond.
expr);
251 if(r_cond.expr.is_constant())
258 bool swap_branches =
false;
260 if(r_cond.expr.id() == ID_not)
263 swap_branches =
true;
266#ifdef USE_LOCAL_REPLACE_MAP
270 if(r_cond.expr.id() == ID_and)
272 for(
const auto &op : r_cond.expr.operands())
274 if(op.id() == ID_not)
275 local_replace_map.insert(std::make_pair(op.op0(),
false_exprt()));
277 local_replace_map.insert(std::make_pair(op,
true_exprt()));
281 local_replace_map.insert(std::make_pair(r_cond.expr,
true_exprt()));
283 auto r_truevalue =
simplify_rec(swap_branches ? falsevalue : truevalue);
285 local_replace_map = map_before;
288 if(r_cond.expr.id() == ID_or)
290 for(
const auto &op : r_cond.expr.operands())
292 if(op.id() == ID_not)
293 local_replace_map.insert(std::make_pair(op.op0(),
true_exprt()));
295 local_replace_map.insert(std::make_pair(op,
false_exprt()));
299 local_replace_map.insert(std::make_pair(r_cond.expr,
false_exprt()));
301 auto r_falsevalue =
simplify_rec(swap_branches ? truevalue : falsevalue);
303 local_replace_map.swap(map_before);
308 r_truevalue.expr_changed = CHANGED;
309 r_falsevalue.expr_changed = CHANGED;
311 return build_if_expr(expr, r_cond, r_truevalue, r_falsevalue);
352 if(truevalue ==
true && falsevalue ==
false)
357 else if(truevalue ==
false && falsevalue ==
true)
362 else if(falsevalue ==
false)
367 else if(falsevalue ==
true)
373 else if(truevalue ==
true)
378 else if(truevalue ==
false)
387 if(truevalue == falsevalue)
392 ((truevalue.
id() == ID_struct && falsevalue.
id() == ID_struct) ||
393 (truevalue.
id() == ID_array && falsevalue.
id() == ID_array)) &&
396 exprt cond_copy = cond;
397 exprt falsevalue_copy = falsevalue;
398 exprt truevalue_copy = truevalue;
402 auto new_expr = truevalue;
405 for(
const auto &pair : range_true.zip(range_false))
407 new_expr.operands().push_back(
411 return std::move(new_expr);
Base class for all expressions.
std::vector< exprt > operandst
bool has_operands() const
Return true if there is at least one operand.
bool is_boolean() const
Return whether the expression represents a Boolean.
typet & type()
Return the type of the expression.
The Boolean constant false.
The trinary if-then-else operator.
const irep_idt & id() const
bool simplify_if_conj(exprt &expr, const exprt &cond)
bool simplify_if_disj(exprt &expr, const exprt &cond)
static resultt changed(resultt<> result)
resultt simplify_if(const if_exprt &)
bool simplify_if_recursive(exprt &expr, const exprt &cond, bool truth)
resultt simplify_rec(const exprt &)
bool simplify_if_cond(exprt &expr)
resultt simplify_boolean(const exprt &)
bool simplify_if_branch(exprt &trueexpr, exprt &falseexpr, const exprt &cond)
resultt simplify_not(const not_exprt &)
static resultt unchanged(exprt expr)
resultt simplify_if_preorder(const if_exprt &expr)
bool simplify_if_implies(exprt &expr, const exprt &cond, bool truth, bool &new_truth)
The Boolean constant true.
#define Forall_operands(it, expr)
Ranges: pair of begin and end iterators, which can be initialized from containers,...
ranget< iteratort > make_range(iteratort begin, iteratort end)
std::unordered_map< exprt, exprt, irep_hash > replace_mapt
static simplify_exprt::resultt build_if_expr(const if_exprt &expr, simplify_exprt::resultt<> cond, simplify_exprt::resultt<> truevalue, simplify_exprt::resultt<> falsevalue)
API to expression classes.
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast an exprt to a binary_relation_exprt.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.