@@ -12,9 +12,6 @@ Date: September 2014
1212
1313#include " remove_complex.h"
1414
15- void remove_complex (typet &);
16- void remove_complex (exprt &);
17-
1815/* ******************************************************************\
1916
2017Function: complex_member
@@ -27,7 +24,7 @@ Function: complex_member
2724
2825\*******************************************************************/
2926
30- exprt complex_member (const exprt &expr, irep_idt id)
27+ static exprt complex_member (const exprt &expr, irep_idt id)
3128{
3229 if (expr.id ()==ID_struct && expr.operands ().size ()==2 )
3330 {
@@ -50,6 +47,90 @@ exprt complex_member(const exprt &expr, irep_idt id)
5047
5148/* ******************************************************************\
5249
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+
53134Function: remove_complex
54135
55136Inputs:
@@ -60,8 +141,13 @@ Purpose: removes complex data type
60141
61142\*******************************************************************/
62143
63- void remove_complex (exprt &expr)
144+ static void remove_complex (typet &);
145+
146+ static void remove_complex (exprt &expr)
64147{
148+ if (!have_to_remove_complex (expr))
149+ return ;
150+
65151 if (expr.id ()==ID_typecast)
66152 {
67153 assert (expr.operands ().size ()==1 );
@@ -200,8 +286,11 @@ Purpose: removes complex data type
200286
201287\*******************************************************************/
202288
203- void remove_complex (typet &type)
289+ static void remove_complex (typet &type)
204290{
291+ if (!have_to_remove_complex (type))
292+ return ;
293+
205294 if (type.id ()==ID_struct || type.id ()==ID_union)
206295 {
207296 struct_union_typet &struct_union_type=
@@ -250,7 +339,7 @@ Purpose: removes complex data type
250339
251340\*******************************************************************/
252341
253- void remove_complex (symbolt &symbol)
342+ static void remove_complex (symbolt &symbol)
254343{
255344 remove_complex (symbol.value );
256345 remove_complex (symbol.type );
@@ -286,7 +375,8 @@ Purpose: removes complex data type
286375
287376\*******************************************************************/
288377
289- void remove_complex (goto_functionst::goto_functiont &goto_function)
378+ static void remove_complex (
379+ goto_functionst::goto_functiont &goto_function)
290380{
291381 remove_complex (goto_function.type );
292382
@@ -309,7 +399,7 @@ Purpose: removes complex data type
309399
310400\*******************************************************************/
311401
312- void remove_complex (goto_functionst &goto_functions)
402+ static void remove_complex (goto_functionst &goto_functions)
313403{
314404 Forall_goto_functions (it, goto_functions)
315405 remove_complex (it->second );
0 commit comments