@@ -22,6 +22,7 @@ Author: Peter Schrammel
22
22
#include < util/cprover_prefix.h>
23
23
24
24
#include < langapi/language_util.h>
25
+ #include < goto-programs/adjust_float_expressions.h>
25
26
26
27
void constant_propagator_domaint::assign_rec (
27
28
valuest &values,
@@ -35,8 +36,7 @@ void constant_propagator_domaint::assign_rec(
35
36
const symbol_exprt &s=to_symbol_expr (lhs);
36
37
37
38
exprt tmp=rhs;
38
- values.replace_const (tmp);
39
- simplify (tmp, ns);
39
+ try_evaluate (tmp, ns);
40
40
41
41
if (tmp.is_constant ())
42
42
values.set_to (s, tmp);
@@ -99,10 +99,10 @@ void constant_propagator_domaint::transform(
99
99
// Comparing iterators is safe as the target must be within the same list
100
100
// of instructions because this is a GOTO.
101
101
if (from->get_target ()==to)
102
- g= simplify_expr ( from->guard , ns) ;
102
+ g = from->guard ;
103
103
else
104
- g= simplify_expr ( not_exprt (from->guard ), ns );
105
-
104
+ g = not_exprt (from->guard );
105
+ try_evaluate (g, ns);
106
106
if (g.is_false ())
107
107
values.set_to_bottom ();
108
108
else
@@ -269,10 +269,7 @@ bool constant_propagator_domaint::ai_simplify(
269
269
exprt &condition,
270
270
const namespacet &ns) const
271
271
{
272
- bool b=values.replace_const .replace (condition);
273
- b&=simplify (condition, ns);
274
-
275
- return b;
272
+ return try_evaluate (condition, ns);
276
273
}
277
274
278
275
@@ -504,6 +501,21 @@ bool constant_propagator_domaint::merge(
504
501
return values.merge (other.values );
505
502
}
506
503
504
+ // / Attempt to evaluate expression using domain knowledge
505
+ // / This function changes the expression that is passed into it.
506
+ // / \param expr The expression to evaluate
507
+ // / \param ns The namespace for symbols in the expression
508
+ // / \return True if the expression is unchanged, false otherwise
509
+ bool constant_propagator_domaint::try_evaluate (
510
+ exprt &expr,
511
+ const namespacet &ns) const
512
+ {
513
+ adjust_float_expressions (expr, ns);
514
+ bool did_not_change_anything = values.replace_const .replace (expr);
515
+ did_not_change_anything &= simplify (expr, ns);
516
+ return did_not_change_anything;
517
+ }
518
+
507
519
void constant_propagator_ait::replace (
508
520
goto_functionst &goto_functions,
509
521
const namespacet &ns)
@@ -529,38 +541,34 @@ void constant_propagator_ait::replace(
529
541
530
542
if (it->is_goto () || it->is_assume () || it->is_assert ())
531
543
{
532
- s_it->second .values .replace_const (it->guard );
533
- simplify (it->guard , ns);
544
+ s_it->second .try_evaluate (it->guard , ns);
534
545
}
535
546
else if (it->is_assign ())
536
547
{
537
548
exprt &rhs=to_code_assign (it->code ).rhs ();
538
- s_it->second .values .replace_const (rhs);
539
- simplify (rhs, ns);
549
+ s_it->second .try_evaluate (rhs, ns);
540
550
if (rhs.id ()==ID_constant)
541
551
rhs.add_source_location ()=it->code .op0 ().source_location ();
542
552
}
543
553
else if (it->is_function_call ())
544
554
{
545
- s_it->second .values .replace_const (
546
- to_code_function_call (it->code ).function ());
547
-
548
- simplify (to_code_function_call (it->code ).function (), ns);
555
+ exprt &function = to_code_function_call (it->code ).function ();
556
+ s_it->second .try_evaluate (function, ns);
549
557
550
558
exprt::operandst &args=
551
559
to_code_function_call (it->code ).arguments ();
552
560
553
- for (exprt::operandst::iterator o_it=args.begin ();
554
- o_it!=args.end (); ++o_it)
561
+ for (auto &arg : args)
555
562
{
556
- s_it->second .values .replace_const (*o_it);
557
- simplify (*o_it, ns);
563
+ s_it->second .try_evaluate (arg, ns);
558
564
}
559
565
}
560
566
else if (it->is_other ())
561
567
{
562
568
if (it->code .get_statement ()==ID_expression)
563
- s_it->second .values .replace_const (it->code );
569
+ {
570
+ s_it->second .try_evaluate (it->code , ns);
571
+ }
564
572
}
565
573
}
566
574
}
0 commit comments