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