Skip to content

Commit 8ae5cca

Browse files
committed
remove_complex: modify expressions only when necessary
1 parent ac0b12a commit 8ae5cca

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

src/goto-programs/remove_complex.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,90 @@ static exprt complex_member(const exprt &expr, irep_idt id)
4747

4848
/*******************************************************************\
4949
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+
50134
Function: remove_complex
51135
52136
Inputs:
@@ -61,6 +145,9 @@ static void remove_complex(typet &);
61145

62146
static void remove_complex(exprt &expr)
63147
{
148+
if(!have_to_remove_complex(expr))
149+
return;
150+
64151
if(expr.id()==ID_typecast)
65152
{
66153
assert(expr.operands().size()==1);
@@ -201,6 +288,9 @@ Purpose: removes complex data type
201288

202289
static void remove_complex(typet &type)
203290
{
291+
if(!have_to_remove_complex(type))
292+
return;
293+
204294
if(type.id()==ID_struct || type.id()==ID_union)
205295
{
206296
struct_union_typet &struct_union_type=

0 commit comments

Comments
 (0)