25
25
26
26
#include " parse_float.h"
27
27
28
+ // / build an expression from a floating-point literal
29
+ // / \returns either a constant_exprt or a complex_exprt
28
30
exprt convert_float_literal (const std::string &src)
29
31
{
30
32
parse_floatt parsed_float (src);
31
33
32
- exprt result=exprt (ID_constant);
33
-
34
34
// In ANSI-C, float literals are double by default,
35
- // unless marked with 'f'.
36
- // All of these can be complex as well.
37
- // This can be overridden with
38
- // config.ansi_c.single_precision_constant.
35
+ // unless marked with 'f' (this can be overridden with
36
+ // config.ansi_c.single_precision_constant).
37
+ // Furthermore, floating-point literals can be complex.
38
+
39
+ floatbv_typet type;
39
40
40
41
if (parsed_float.is_float )
41
- result. type ()= float_type ();
42
+ type = float_type ();
42
43
else if (parsed_float.is_long )
43
- result. type ()= long_double_type ();
44
+ type = long_double_type ();
44
45
else if (parsed_float.is_float16 )
45
- result. type ()= gcc_float16_type ();
46
+ type = gcc_float16_type ();
46
47
else if (parsed_float.is_float32 )
47
- result. type ()= gcc_float32_type ();
48
+ type = gcc_float32_type ();
48
49
else if (parsed_float.is_float32x )
49
- result. type ()= gcc_float32x_type ();
50
+ type = gcc_float32x_type ();
50
51
else if (parsed_float.is_float64 )
51
- result. type ()= gcc_float64_type ();
52
+ type = gcc_float64_type ();
52
53
else if (parsed_float.is_float64x )
53
- result. type ()= gcc_float64x_type ();
54
+ type = gcc_float64x_type ();
54
55
else if (parsed_float.is_float80 )
55
56
{
56
- result. type ()= ieee_float_spect (64 , 15 ).to_type ();
57
- result. type () .set (ID_C_c_type, ID_long_double);
57
+ type = ieee_float_spect (64 , 15 ).to_type ();
58
+ type.set (ID_C_c_type, ID_long_double);
58
59
}
59
60
else if (parsed_float.is_float128 )
60
- result. type ()= gcc_float128_type ();
61
+ type = gcc_float128_type ();
61
62
else if (parsed_float.is_float128x )
62
- result. type ()= gcc_float128x_type ();
63
+ type = gcc_float128x_type ();
63
64
else
64
65
{
65
66
// default
66
67
if (config.ansi_c .single_precision_constant )
67
- result. type ()= float_type (); // default
68
+ type = float_type (); // default
68
69
else
69
- result. type ()= double_type (); // default
70
+ type = double_type (); // default
70
71
}
71
72
72
73
if (parsed_float.is_decimal )
@@ -75,7 +76,7 @@ exprt convert_float_literal(const std::string &src)
75
76
// but these aren't handled anywhere
76
77
}
77
78
78
- ieee_floatt a (to_floatbv_type (result. type ()) );
79
+ ieee_floatt a (type);
79
80
80
81
if (parsed_float.exponent_base ==10 )
81
82
a.from_base10 (parsed_float.significand , parsed_float.exponent );
@@ -84,14 +85,12 @@ exprt convert_float_literal(const std::string &src)
84
85
else
85
86
UNREACHABLE;
86
87
87
- result.set (
88
- ID_value,
89
- integer2binary (a.pack (), a.spec .width ()));
88
+ constant_exprt result (integer2bv (a.pack (), a.spec .width ()), type);
90
89
91
90
if (parsed_float.is_imaginary )
92
91
{
93
- const complex_typet complex_type (result. type () );
94
- return complex_exprt (from_integer (0 , result. type () ), result, complex_type);
92
+ const complex_typet complex_type (type);
93
+ return complex_exprt (from_integer (0 , type), result, complex_type);
95
94
}
96
95
97
96
return result;
0 commit comments