@@ -32,10 +32,10 @@ static exprt complex_member(const exprt &expr, irep_idt id)
32
32
}
33
33
else
34
34
{
35
- assert (expr.type ().id ()== ID_struct);
35
+ PRECONDITION (expr.type ().id () == ID_struct);
36
36
const struct_typet &struct_type=
37
37
to_struct_type (expr.type ());
38
- assert (struct_type.components ().size ()== 2 );
38
+ PRECONDITION (struct_type.components ().size () == 2 );
39
39
return member_exprt (expr, id, struct_type.components ().front ().type ());
40
40
}
41
41
}
@@ -110,20 +110,22 @@ static void remove_complex(exprt &expr)
110
110
111
111
if (expr.id ()==ID_typecast)
112
112
{
113
- assert (expr. operands (). size ()== 1 );
114
- if (expr. op0 ().type ().id ()== ID_complex)
113
+ auto const &typecast_expr = to_typecast_expr (expr);
114
+ if (typecast_expr. op ().type ().id () == ID_complex)
115
115
{
116
- if (expr .type ().id ()== ID_complex)
116
+ if (typecast_expr .type ().id () == ID_complex)
117
117
{
118
118
// complex to complex
119
119
}
120
120
else
121
121
{
122
122
// cast complex to non-complex is (T)__real__ x
123
123
unary_exprt tmp (
124
- ID_complex_real, expr.op0 (), expr.op0 ().type ().subtype ());
124
+ ID_complex_real,
125
+ typecast_expr.op (),
126
+ typecast_expr.op ().type ().subtype ());
125
127
126
- expr= typecast_exprt (tmp, expr .type ());
128
+ expr = typecast_exprt (tmp, typecast_expr .type ());
127
129
}
128
130
}
129
131
}
@@ -136,7 +138,8 @@ static void remove_complex(exprt &expr)
136
138
if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
137
139
expr.id ()==ID_mult || expr.id ()==ID_div)
138
140
{
139
- assert (expr.operands ().size ()==2 );
141
+ DATA_INVARIANT (
142
+ expr.operands ().size () == 2 , " binary operators have 2 arguments" );
140
143
// do component-wise:
141
144
// x+y -> complex(x.r+y.r,x.i+y.i)
142
145
struct_exprt struct_expr (expr.type ());
@@ -158,62 +161,66 @@ static void remove_complex(exprt &expr)
158
161
}
159
162
else if (expr.id ()==ID_unary_minus)
160
163
{
161
- assert (expr. operands (). size ()== 1 );
164
+ auto const &unary_minus_expr = to_unary_minus_expr (expr);
162
165
// do component-wise:
163
166
// -x -> complex(-x.r,-x.i)
164
- struct_exprt struct_expr (expr .type ());
167
+ struct_exprt struct_expr (unary_minus_expr .type ());
165
168
struct_expr.operands ().resize (2 );
166
169
167
- struct_expr.op0 ()=
168
- unary_minus_exprt (complex_member (expr. op0 (), ID_real));
170
+ struct_expr.op0 () =
171
+ unary_minus_exprt (complex_member (unary_minus_expr. op (), ID_real));
169
172
170
- struct_expr.op0 ().add_source_location ()=expr.source_location ();
173
+ struct_expr.op0 ().add_source_location () =
174
+ unary_minus_expr.source_location ();
171
175
172
- struct_expr.op1 ()=
173
- unary_minus_exprt (complex_member (expr. op0 (), ID_imag));
176
+ struct_expr.op1 () =
177
+ unary_minus_exprt (complex_member (unary_minus_expr. op (), ID_imag));
174
178
175
- struct_expr.op1 ().add_source_location ()=expr.source_location ();
179
+ struct_expr.op1 ().add_source_location () =
180
+ unary_minus_expr.source_location ();
176
181
177
182
expr=struct_expr;
178
183
}
179
184
else if (expr.id ()==ID_complex)
180
185
{
181
- assert (expr. operands (). size ()== 2 );
186
+ static_cast < void >( to_complex_expr (expr) );
182
187
expr.id (ID_struct);
183
188
}
184
189
else if (expr.id ()==ID_typecast)
185
190
{
186
- assert (expr. operands (). size ()== 1 );
187
- typet subtype=expr .type ().subtype ();
191
+ auto const &typecast_expr = to_typecast_expr (expr);
192
+ typet subtype = typecast_expr .type ().subtype ();
188
193
189
- if (expr. op0 ().type ().id ()== ID_struct)
194
+ if (typecast_expr. op ().type ().id () == ID_struct)
190
195
{
191
196
// complex to complex -- do typecast per component
192
197
193
- struct_exprt struct_expr (expr .type ());
198
+ struct_exprt struct_expr (typecast_expr .type ());
194
199
struct_expr.operands ().resize (2 );
195
200
196
- struct_expr.op0 ()=
197
- typecast_exprt (complex_member (expr. op0 (), ID_real), subtype);
201
+ struct_expr.op0 () =
202
+ typecast_exprt (complex_member (typecast_expr. op (), ID_real), subtype);
198
203
199
- struct_expr.op0 ().add_source_location ()=expr.source_location ();
204
+ struct_expr.op0 ().add_source_location () =
205
+ typecast_expr.source_location ();
200
206
201
- struct_expr.op1 ()=
202
- typecast_exprt (complex_member (expr. op0 (), ID_imag), subtype);
207
+ struct_expr.op1 () =
208
+ typecast_exprt (complex_member (typecast_expr. op (), ID_imag), subtype);
203
209
204
- struct_expr.op1 ().add_source_location ()=expr.source_location ();
210
+ struct_expr.op1 ().add_source_location () =
211
+ typecast_expr.source_location ();
205
212
206
213
expr=struct_expr;
207
214
}
208
215
else
209
216
{
210
217
// non-complex to complex
211
- struct_exprt struct_expr (expr .type ());
218
+ struct_exprt struct_expr (typecast_expr .type ());
212
219
struct_expr.operands ().resize (2 );
213
220
214
- struct_expr.op0 ()= typecast_exprt (expr. op0 (), subtype);
221
+ struct_expr.op0 () = typecast_exprt (typecast_expr. op (), subtype);
215
222
struct_expr.op1 ()=from_integer (0 , subtype);
216
- struct_expr.add_source_location ()=expr .source_location ();
223
+ struct_expr.add_source_location () = typecast_expr .source_location ();
217
224
218
225
expr=struct_expr;
219
226
}
@@ -222,12 +229,12 @@ static void remove_complex(exprt &expr)
222
229
223
230
if (expr.id ()==ID_complex_real)
224
231
{
225
- assert (expr. operands (). size ()== 1 );
232
+ static_cast < void >( to_complex_real_expr (expr) );
226
233
expr=complex_member (expr.op0 (), ID_real);
227
234
}
228
235
else if (expr.id ()==ID_complex_imag)
229
236
{
230
- assert (expr. operands (). size ()== 1 );
237
+ static_cast < void >( to_complex_imag_expr (expr) );
231
238
expr=complex_member (expr.op0 (), ID_imag);
232
239
}
233
240
0 commit comments