@@ -47,6 +47,90 @@ static exprt complex_member(const exprt &expr, irep_idt id)
47
47
48
48
/* ******************************************************************\
49
49
50
+ Function: have_to_remove_complex
51
+
52
+ Inputs:
53
+
54
+ Outputs:
55
+
56
+ Purpose:
57
+
58
+ \*******************************************************************/
59
+
60
+ static bool have_to_remove_complex (const typet &type);
61
+
62
+ static bool have_to_remove_complex (const exprt &expr)
63
+ {
64
+ if (expr.id ()==ID_typecast &&
65
+ to_typecast_expr (expr).op ().type ().id ()==ID_complex &&
66
+ expr.type ().id ()!=ID_complex)
67
+ return true ;
68
+
69
+ if (expr.type ().id ()==ID_complex)
70
+ {
71
+ if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
72
+ expr.id ()==ID_mult || expr.id ()==ID_div)
73
+ return true ;
74
+ else if (expr.id ()==ID_unary_minus)
75
+ return true ;
76
+ else if (expr.id ()==ID_complex)
77
+ return true ;
78
+ else if (expr.id ()==ID_typecast)
79
+ return true ;
80
+ }
81
+
82
+ if (expr.id ()==ID_complex_real)
83
+ return true ;
84
+ else if (expr.id ()==ID_complex_imag)
85
+ return true ;
86
+
87
+ if (have_to_remove_complex (expr.type ()))
88
+ return true ;
89
+
90
+ forall_operands (it, expr)
91
+ if (have_to_remove_complex (*it))
92
+ return true ;
93
+
94
+ return false ;
95
+ }
96
+
97
+ /* ******************************************************************\
98
+
99
+ Function: have_to_remove_complex
100
+
101
+ Inputs:
102
+
103
+ Outputs:
104
+
105
+ Purpose:
106
+
107
+ \*******************************************************************/
108
+
109
+ static bool have_to_remove_complex (const typet &type)
110
+ {
111
+ if (type.id ()==ID_struct || type.id ()==ID_union)
112
+ {
113
+ const struct_union_typet &struct_union_type=
114
+ to_struct_union_type (type);
115
+ for (struct_union_typet::componentst::const_iterator
116
+ it=struct_union_type.components ().begin ();
117
+ it!=struct_union_type.components ().end ();
118
+ it++)
119
+ if (have_to_remove_complex (it->type ()))
120
+ return true ;
121
+ }
122
+ else if (type.id ()==ID_pointer ||
123
+ type.id ()==ID_vector ||
124
+ type.id ()==ID_array)
125
+ return have_to_remove_complex (type.subtype ());
126
+ else if (type.id ()==ID_complex)
127
+ return true ;
128
+
129
+ return false ;
130
+ }
131
+
132
+ /* ******************************************************************\
133
+
50
134
Function: remove_complex
51
135
52
136
Inputs:
@@ -61,6 +145,9 @@ static void remove_complex(typet &);
61
145
62
146
static void remove_complex (exprt &expr)
63
147
{
148
+ if (!have_to_remove_complex (expr))
149
+ return ;
150
+
64
151
if (expr.id ()==ID_typecast)
65
152
{
66
153
assert (expr.operands ().size ()==1 );
@@ -201,6 +288,9 @@ Purpose: removes complex data type
201
288
202
289
static void remove_complex (typet &type)
203
290
{
291
+ if (!have_to_remove_complex (type))
292
+ return ;
293
+
204
294
if (type.id ()==ID_struct || type.id ()==ID_union)
205
295
{
206
296
struct_union_typet &struct_union_type=
0 commit comments