20
20
21
21
#include " goto_model.h"
22
22
23
- static bool have_to_adjust_float_expressions (
24
- const exprt &expr,
25
- const namespacet &ns)
23
+ static bool have_to_adjust_float_expressions (const exprt &expr)
26
24
{
27
25
if (expr.id ()==ID_floatbv_plus ||
28
26
expr.id ()==ID_floatbv_minus ||
@@ -33,11 +31,11 @@ static bool have_to_adjust_float_expressions(
33
31
expr.id ()==ID_floatbv_typecast)
34
32
return false ;
35
33
36
- const typet &type=ns. follow ( expr.type () );
34
+ const typet &type=expr.type ();
37
35
38
36
if (type.id ()==ID_floatbv ||
39
37
(type.id ()==ID_complex &&
40
- ns. follow ( type.subtype () ).id ()==ID_floatbv))
38
+ type.subtype ().id ()==ID_floatbv))
41
39
{
42
40
if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
43
41
expr.id ()==ID_mult || expr.id ()==ID_div ||
@@ -69,7 +67,7 @@ static bool have_to_adjust_float_expressions(
69
67
}
70
68
71
69
forall_operands (it, expr)
72
- if (have_to_adjust_float_expressions (*it, ns ))
70
+ if (have_to_adjust_float_expressions (*it))
73
71
return true ;
74
72
75
73
return false ;
@@ -79,25 +77,21 @@ static bool have_to_adjust_float_expressions(
79
77
// / vectors and complex numbers.
80
78
void adjust_float_expressions (
81
79
exprt &expr,
82
- const namespacet &ns )
80
+ const exprt &rounding_mode )
83
81
{
84
- if (!have_to_adjust_float_expressions (expr, ns ))
82
+ if (!have_to_adjust_float_expressions (expr))
85
83
return ;
86
84
87
- Forall_operands (it, expr)
88
- adjust_float_expressions (*it, ns);
85
+ // recursive call
86
+ for (auto &op : expr.operands ())
87
+ adjust_float_expressions (op, rounding_mode);
89
88
90
- const typet &type=ns. follow ( expr.type () );
89
+ const typet &type=expr.type ();
91
90
92
91
if (type.id ()==ID_floatbv ||
93
92
(type.id ()==ID_complex &&
94
- ns. follow ( type.subtype () ).id ()==ID_floatbv))
93
+ type.subtype ().id ()==ID_floatbv))
95
94
{
96
- symbol_exprt rounding_mode=
97
- ns.lookup (CPROVER_PREFIX " rounding_mode" ).symbol_expr ();
98
-
99
- rounding_mode.add_source_location ()=expr.source_location ();
100
-
101
95
if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
102
96
expr.id ()==ID_mult || expr.id ()==ID_div ||
103
97
expr.id ()==ID_rem)
@@ -128,11 +122,6 @@ void adjust_float_expressions(
128
122
const typet &src_type=typecast_expr.op ().type ();
129
123
const typet &dest_type=typecast_expr.type ();
130
124
131
- symbol_exprt rounding_mode=
132
- ns.lookup (CPROVER_PREFIX " rounding_mode" ).symbol_expr ();
133
-
134
- rounding_mode.add_source_location ()=expr.source_location ();
135
-
136
125
if (dest_type.id ()==ID_floatbv &&
137
126
src_type.id ()==ID_floatbv)
138
127
{
@@ -179,6 +168,23 @@ void adjust_float_expressions(
179
168
}
180
169
}
181
170
171
+ // / This adds the rounding mode to floating-point operations, including those in
172
+ // / vectors and complex numbers.
173
+ void adjust_float_expressions (
174
+ exprt &expr,
175
+ const namespacet &ns)
176
+ {
177
+ if (!have_to_adjust_float_expressions (expr))
178
+ return ;
179
+
180
+ symbol_exprt rounding_mode=
181
+ ns.lookup (CPROVER_PREFIX " rounding_mode" ).symbol_expr ();
182
+
183
+ rounding_mode.add_source_location ()=expr.source_location ();
184
+
185
+ adjust_float_expressions (expr, rounding_mode);
186
+ }
187
+
182
188
void adjust_float_expressions (
183
189
goto_functionst::goto_functiont &goto_function,
184
190
const namespacet &ns)
0 commit comments