@@ -99,31 +99,13 @@ void goto_convertt::remove_assignment(
99
99
100
100
const typet &op0_type = expr.op0 ().type ();
101
101
102
- if (op0_type.id ()==ID_c_bool)
103
- {
104
- // C/C++ Booleans get very special treatment.
105
- binary_exprt tmp (expr.op0 (), new_id, expr.op1 (), expr.op1 ().type ());
106
- tmp.op0 ().make_typecast (expr.op1 ().type ());
107
- rhs=typecast_exprt (is_not_zero (tmp, ns), expr.op0 ().type ());
108
- }
109
- else if (op0_type.id () == ID_c_enum_tag)
110
- {
111
- // We convert c_enums to their underlying type, do the
112
- // operation, and then convert back
113
- const auto &enum_type = ns.follow_tag (to_c_enum_tag_type (op0_type));
114
- auto underlying_type = enum_type.subtype ();
115
- auto op0 = typecast_exprt (expr.op0 (), underlying_type);
116
- auto op1 = typecast_exprt (expr.op1 (), underlying_type);
117
- binary_exprt tmp (op0, new_id, op1, underlying_type);
118
- rhs = typecast_exprt (tmp, expr.op0 ().type ());
119
- }
120
- else
121
- {
122
- rhs.id (new_id);
123
- rhs.copy_to_operands (expr.op0 (), expr.op1 ());
124
- rhs.type ()=expr.op0 ().type ();
125
- rhs.add_source_location ()=expr.source_location ();
126
- }
102
+ PRECONDITION (
103
+ op0_type.id () != ID_c_enum_tag && op0_type.id () != ID_c_enum &&
104
+ op0_type.id () != ID_c_bool && op0_type.id () != ID_bool);
105
+ rhs.id (new_id);
106
+ rhs.copy_to_operands (expr.op0 (), expr.op1 ());
107
+ rhs.type () = expr.op0 ().type ();
108
+ rhs.add_source_location () = expr.source_location ();
127
109
128
110
code_assignt assignment (expr.op0 (), rhs);
129
111
assignment.add_source_location ()=expr.source_location ();
@@ -171,20 +153,19 @@ void goto_convertt::remove_pre(
171
153
172
154
const typet &op_type = expr.op0 ().type ();
173
155
174
- if (op_type.id ()==ID_bool)
175
- {
176
- rhs.copy_to_operands (expr.op0 (), from_integer (1 , signed_int_type ()));
177
- rhs.op0 ().make_typecast (signed_int_type ());
178
- rhs.type ()=signed_int_type ();
179
- rhs=is_not_zero (rhs, ns);
180
- }
181
- else if (op_type.id ()==ID_c_bool)
156
+ PRECONDITION (
157
+ op_type.id () != ID_c_enum_tag && op_type.id () != ID_c_enum &&
158
+ op_type.id () != ID_c_bool && op_type.id () != ID_bool);
159
+
160
+ typet constant_type;
161
+
162
+ if (op_type.id () == ID_pointer)
163
+ constant_type = index_type ();
164
+ else if (is_number (op_type))
165
+ constant_type = op_type;
166
+ else
182
167
{
183
- rhs.copy_to_operands (expr.op0 (), from_integer (1 , signed_int_type ()));
184
- rhs.op0 ().make_typecast (signed_int_type ());
185
- rhs.type ()=signed_int_type ();
186
- rhs=is_not_zero (rhs, ns);
187
- rhs.make_typecast (op_type);
168
+ UNREACHABLE;
188
169
}
189
170
else if (op_type.id ()==ID_c_enum ||
190
171
op_type.id ()==ID_c_enum_tag)
@@ -257,56 +238,34 @@ void goto_convertt::remove_post(
257
238
258
239
const typet &op_type = expr.op0 ().type ();
259
240
260
- if (op_type.id ()==ID_bool)
261
- {
262
- rhs.copy_to_operands (expr.op0 (), from_integer (1 , signed_int_type ()));
263
- rhs.op0 ().make_typecast (signed_int_type ());
264
- rhs.type ()=signed_int_type ();
265
- rhs=is_not_zero (rhs, ns);
266
- }
267
- else if (op_type.id ()==ID_c_bool)
241
+ PRECONDITION (
242
+ op_type.id () != ID_c_enum_tag && op_type.id () != ID_c_enum &&
243
+ op_type.id () != ID_c_bool && op_type.id () != ID_bool);
244
+
245
+ typet constant_type;
246
+
247
+ if (op_type.id () == ID_pointer)
248
+ constant_type = index_type ();
249
+ else if (is_number (op_type))
250
+ constant_type = op_type;
251
+ else
268
252
{
269
- rhs.copy_to_operands (expr.op0 (), from_integer (1 , signed_int_type ()));
270
- rhs.op0 ().make_typecast (signed_int_type ());
271
- rhs.type ()=signed_int_type ();
272
- rhs=is_not_zero (rhs, ns);
273
- rhs.make_typecast (op_type);
253
+ UNREACHABLE;
274
254
}
275
- else if (op_type.id ()==ID_c_enum ||
276
- op_type.id ()==ID_c_enum_tag)
255
+
256
+ exprt constant;
257
+
258
+ if (constant_type.id () == ID_complex)
277
259
{
278
- rhs.copy_to_operands (expr.op0 (), from_integer (1 , signed_int_type ()));
279
- rhs.op0 ().make_typecast (signed_int_type ());
280
- rhs.type ()=signed_int_type ();
281
- rhs.make_typecast (op_type);
260
+ exprt real = from_integer (1 , constant_type.subtype ());
261
+ exprt imag = from_integer (0 , constant_type.subtype ());
262
+ constant = complex_exprt (real, imag, to_complex_type (constant_type));
282
263
}
283
264
else
284
- {
285
- typet constant_type;
265
+ constant = from_integer (1 , constant_type);
286
266
287
- if (op_type.id ()==ID_pointer)
288
- constant_type=index_type ();
289
- else if (is_number (op_type) || op_type.id ()==ID_c_bool)
290
- constant_type=op_type;
291
- else
292
- {
293
- UNREACHABLE;
294
- }
295
-
296
- exprt constant;
297
-
298
- if (constant_type.id ()==ID_complex)
299
- {
300
- exprt real=from_integer (1 , constant_type.subtype ());
301
- exprt imag=from_integer (0 , constant_type.subtype ());
302
- constant=complex_exprt (real, imag, to_complex_type (constant_type));
303
- }
304
- else
305
- constant=from_integer (1 , constant_type);
306
-
307
- rhs.add_to_operands (expr.op0 (), std::move (constant));
308
- rhs.type ()=expr.op0 ().type ();
309
- }
267
+ rhs.add_to_operands (expr.op0 (), std::move (constant));
268
+ rhs.type () = expr.op0 ().type ();
310
269
311
270
code_assignt assignment (expr.op0 (), rhs);
312
271
assignment.add_source_location ()=expr.find_source_location ();
0 commit comments