2525
2626#include " parse_float.h"
2727
28+ // / build an expression from a floating-point literal
29+ // / \returns either a constant_exprt or a complex_exprt
2830exprt convert_float_literal (const std::string &src)
2931{
3032 parse_floatt parsed_float (src);
3133
32- exprt result=exprt (ID_constant);
33-
3434 // 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;
3940
4041 if (parsed_float.is_float )
41- result. type ()= float_type ();
42+ type = float_type ();
4243 else if (parsed_float.is_long )
43- result. type ()= long_double_type ();
44+ type = long_double_type ();
4445 else if (parsed_float.is_float16 )
45- result. type ()= gcc_float16_type ();
46+ type = gcc_float16_type ();
4647 else if (parsed_float.is_float32 )
47- result. type ()= gcc_float32_type ();
48+ type = gcc_float32_type ();
4849 else if (parsed_float.is_float32x )
49- result. type ()= gcc_float32x_type ();
50+ type = gcc_float32x_type ();
5051 else if (parsed_float.is_float64 )
51- result. type ()= gcc_float64_type ();
52+ type = gcc_float64_type ();
5253 else if (parsed_float.is_float64x )
53- result. type ()= gcc_float64x_type ();
54+ type = gcc_float64x_type ();
5455 else if (parsed_float.is_float80 )
5556 {
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);
5859 }
5960 else if (parsed_float.is_float128 )
60- result. type ()= gcc_float128_type ();
61+ type = gcc_float128_type ();
6162 else if (parsed_float.is_float128x )
62- result. type ()= gcc_float128x_type ();
63+ type = gcc_float128x_type ();
6364 else
6465 {
6566 // default
6667 if (config.ansi_c .single_precision_constant )
67- result. type ()= float_type (); // default
68+ type = float_type (); // default
6869 else
69- result. type ()= double_type (); // default
70+ type = double_type (); // default
7071 }
7172
7273 if (parsed_float.is_decimal )
@@ -75,7 +76,7 @@ exprt convert_float_literal(const std::string &src)
7576 // but these aren't handled anywhere
7677 }
7778
78- ieee_floatt a (to_floatbv_type (result. type ()) );
79+ ieee_floatt a (type);
7980
8081 if (parsed_float.exponent_base ==10 )
8182 a.from_base10 (parsed_float.significand , parsed_float.exponent );
@@ -84,14 +85,12 @@ exprt convert_float_literal(const std::string &src)
8485 else
8586 UNREACHABLE;
8687
87- result.set (
88- ID_value,
89- integer2binary (a.pack (), a.spec .width ()));
88+ constant_exprt result (integer2bv (a.pack (), a.spec .width ()), type);
9089
9190 if (parsed_float.is_imaginary )
9291 {
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);
9594 }
9695
9796 return result;
0 commit comments