@@ -56,6 +56,10 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
56
56
{
57
57
const irep_idt &type_id=type.id ();
58
58
59
+ PRECONDITION (
60
+ type_id != ID_code,
61
+ source_location.as_string () + " : cannot initialize code type" );
62
+
59
63
if (type_id==ID_unsignedbv ||
60
64
type_id==ID_signedbv ||
61
65
type_id==ID_pointer ||
@@ -119,12 +123,6 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
119
123
result.add_source_location ()=source_location;
120
124
return result;
121
125
}
122
- else if (type_id==ID_code)
123
- {
124
- error ().source_location =source_location;
125
- error () << " cannot initialize code-type" << eom;
126
- throw 0 ;
127
- }
128
126
else if (type_id==ID_array)
129
127
{
130
128
const array_typet &array_type=to_array_type (type);
@@ -160,10 +158,15 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
160
158
if (nondet)
161
159
return side_effect_expr_nondett (type, source_location);
162
160
163
- error ().source_location =source_location;
164
- error () << " failed to zero-initialize array of non-fixed size `"
165
- << format (array_type.size ()) << " '" << eom;
166
- throw 0 ;
161
+ std::ostringstream oss;
162
+ oss << format (array_type.size ());
163
+
164
+ INVARIANT (
165
+ false ,
166
+ " non-infinite array size expression must be convertible to an "
167
+ " integer" ,
168
+ source_location.as_string () +
169
+ " : failed to zero-initialize array of size `" + oss.str () + " '" );
167
170
}
168
171
169
172
DATA_INVARIANT (
@@ -188,10 +191,14 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
188
191
if (nondet)
189
192
return side_effect_expr_nondett (type, source_location);
190
193
191
- error ().source_location =source_location;
192
- error () << " failed to zero-initialize vector of non-fixed size `"
193
- << format (vector_type.size ()) << " '" << eom;
194
- throw 0 ;
194
+ std::ostringstream oss;
195
+ oss << format (vector_type.size ());
196
+
197
+ INVARIANT (
198
+ false ,
199
+ " vector size must be convertible to an integer" ,
200
+ source_location.as_string () +
201
+ " : failed to zero-initialize vector of size `" + oss.str () + " '" );
195
202
}
196
203
197
204
DATA_INVARIANT (
@@ -323,9 +330,12 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
323
330
}
324
331
else
325
332
{
326
- error ().source_location =source_location;
327
- error () << " failed to initialize `" << format (type) << " '" << eom;
328
- throw 0 ;
333
+ std::ostringstream oss;
334
+ oss << format (type);
335
+
336
+ PRECONDITION (
337
+ false ,
338
+ source_location.as_string () + " : cannot initialize " + oss.str () + " '" );
329
339
}
330
340
}
331
341
@@ -354,35 +364,17 @@ exprt zero_initializer(
354
364
const source_locationt &source_location,
355
365
const namespacet &ns)
356
366
{
357
- std::ostringstream oss;
358
- stream_message_handlert mh (oss);
359
-
360
- try
361
- {
362
- expr_initializert<false > z_i (ns, mh);
363
- return z_i (type, source_location);
364
- }
365
- catch (int )
366
- {
367
- throw oss.str ();
368
- }
367
+ null_message_handlert null_message_handler;
368
+ expr_initializert<false > z_i (ns, null_message_handler);
369
+ return z_i (type, source_location);
369
370
}
370
371
371
372
exprt nondet_initializer (
372
373
const typet &type,
373
374
const source_locationt &source_location,
374
375
const namespacet &ns)
375
376
{
376
- std::ostringstream oss;
377
- stream_message_handlert mh (oss);
378
-
379
- try
380
- {
381
- expr_initializert<true > z_i (ns, mh);
382
- return z_i (type, source_location);
383
- }
384
- catch (int )
385
- {
386
- throw oss.str ();
387
- }
377
+ null_message_handlert null_message_handler;
378
+ expr_initializert<true > z_i (ns, null_message_handler);
379
+ return z_i (type, source_location);
388
380
}
0 commit comments