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
- if (type. id ()==ID_floatbv ||
39
- ( type.id ()==ID_complex &&
40
- ns. follow ( type.subtype ()) .id ()== ID_floatbv))
36
+ if (
37
+ type.id () == ID_floatbv ||
38
+ (type. id () == ID_complex && 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,35 +67,29 @@ 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 ;
76
74
}
77
75
78
76
// / This adds the rounding mode to floating-point operations, including those in
79
77
// / vectors and complex numbers.
80
- void adjust_float_expressions (
81
- exprt &expr,
82
- const namespacet &ns)
78
+ void adjust_float_expressions (exprt &expr, const exprt &rounding_mode)
83
79
{
84
- if (!have_to_adjust_float_expressions (expr, ns ))
80
+ if (!have_to_adjust_float_expressions (expr))
85
81
return ;
86
82
87
- Forall_operands (it, expr)
88
- adjust_float_expressions (*it, ns);
83
+ // recursive call
84
+ for (auto &op : expr.operands ())
85
+ adjust_float_expressions (op, rounding_mode);
89
86
90
- const typet &type=ns. follow ( expr.type () );
87
+ const typet &type = expr.type ();
91
88
92
- if (type. id ()==ID_floatbv ||
93
- ( type.id ()==ID_complex &&
94
- ns. follow ( type.subtype ()) .id ()== ID_floatbv))
89
+ if (
90
+ type.id () == ID_floatbv ||
91
+ (type. id () == ID_complex && type.subtype ().id () == ID_floatbv))
95
92
{
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
93
if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
102
94
expr.id ()==ID_mult || expr.id ()==ID_div ||
103
95
expr.id ()==ID_rem)
@@ -128,11 +120,6 @@ void adjust_float_expressions(
128
120
const typet &src_type=typecast_expr.op ().type ();
129
121
const typet &dest_type=typecast_expr.type ();
130
122
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
123
if (dest_type.id ()==ID_floatbv &&
137
124
src_type.id ()==ID_floatbv)
138
125
{
@@ -179,6 +166,21 @@ void adjust_float_expressions(
179
166
}
180
167
}
181
168
169
+ // / This adds the rounding mode to floating-point operations, including those in
170
+ // / vectors and complex numbers.
171
+ void adjust_float_expressions (exprt &expr, const namespacet &ns)
172
+ {
173
+ if (!have_to_adjust_float_expressions (expr))
174
+ return ;
175
+
176
+ symbol_exprt rounding_mode =
177
+ ns.lookup (CPROVER_PREFIX " rounding_mode" ).symbol_expr ();
178
+
179
+ rounding_mode.add_source_location () = expr.source_location ();
180
+
181
+ adjust_float_expressions (expr, rounding_mode);
182
+ }
183
+
182
184
void adjust_float_expressions (
183
185
goto_functionst::goto_functiont &goto_function,
184
186
const namespacet &ns)
0 commit comments