@@ -60,12 +60,10 @@ void goto_convertt::remove_assignment(
60
60
statement==ID_assign_bitxor ||
61
61
statement==ID_assign_bitor)
62
62
{
63
- if (expr.operands ().size ()!=2 )
64
- {
65
- error ().source_location =expr.find_source_location ();
66
- error () << statement << " takes two arguments" << eom;
67
- throw 0 ;
68
- }
63
+ INVARIANT (
64
+ expr.operands ().size () == 2 ,
65
+ expr.find_source_location ().as_string () + " : " + id2string (statement) +
66
+ " takes two arguments" );
69
67
70
68
irep_idt new_id;
71
69
@@ -93,10 +91,7 @@ void goto_convertt::remove_assignment(
93
91
new_id=ID_bitor;
94
92
else
95
93
{
96
- error ().source_location =expr.find_source_location ();
97
- error () << " assignment `" << statement << " ' not yet supported"
98
- << eom;
99
- throw 0 ;
94
+ UNREACHABLE;
100
95
}
101
96
102
97
exprt rhs;
@@ -143,17 +138,16 @@ void goto_convertt::remove_pre(
143
138
bool result_is_used,
144
139
const irep_idt &mode)
145
140
{
146
- if (expr.operands ().size ()!=1 )
147
- {
148
- error ().source_location =expr.find_source_location ();
149
- error () << " preincrement/predecrement must have one operand" << eom;
150
- throw 0 ;
151
- }
141
+ DATA_INVARIANT (
142
+ expr.operands ().size () == 1 ,
143
+ expr.find_source_location ().as_string () +
144
+ " : preincrement/predecrement must have one operand" );
152
145
153
146
const irep_idt statement=expr.get_statement ();
154
147
155
- assert (statement==ID_preincrement ||
156
- statement==ID_predecrement);
148
+ DATA_INVARIANT (
149
+ statement == ID_preincrement || statement == ID_predecrement,
150
+ " expected preincrement or predecrement" );
157
151
158
152
exprt rhs;
159
153
rhs.add_source_location ()=expr.source_location ();
@@ -198,9 +192,7 @@ void goto_convertt::remove_pre(
198
192
constant_type=op_type;
199
193
else
200
194
{
201
- error ().source_location =expr.find_source_location ();
202
- error () << " no constant one of type " << op_type.pretty () << eom;
203
- throw 0 ;
195
+ UNREACHABLE;
204
196
}
205
197
206
198
exprt constant=from_integer (1 , constant_type);
@@ -235,18 +227,16 @@ void goto_convertt::remove_post(
235
227
236
228
// we have ...(op++)...
237
229
238
- if (expr.operands ().size ()!=1 )
239
- {
240
- error ().source_location =expr.find_source_location ();
241
- error () << " postincrement/postdecrement must have one operand"
242
- << eom;
243
- throw 0 ;
244
- }
230
+ DATA_INVARIANT (
231
+ expr.operands ().size () == 1 ,
232
+ expr.find_source_location ().as_string () +
233
+ " : postincrement/postdecrement must have one operand" );
245
234
246
235
const irep_idt statement=expr.get_statement ();
247
236
248
- assert (statement==ID_postincrement ||
249
- statement==ID_postdecrement);
237
+ DATA_INVARIANT (
238
+ statement == ID_postincrement || statement == ID_postdecrement,
239
+ " expected postincrement or postdecrement" );
250
240
251
241
exprt rhs;
252
242
rhs.add_source_location ()=expr.source_location ();
@@ -291,9 +281,7 @@ void goto_convertt::remove_post(
291
281
constant_type=op_type;
292
282
else
293
283
{
294
- error ().source_location =expr.find_source_location ();
295
- error () << " no constant one of type " << op_type.pretty () << eom;
296
- throw 0 ;
284
+ UNREACHABLE;
297
285
}
298
286
299
287
exprt constant;
@@ -340,7 +328,10 @@ void goto_convertt::remove_function_call(
340
328
{
341
329
if (!result_is_used)
342
330
{
343
- assert (expr.operands ().size ()==2 );
331
+ DATA_INVARIANT (
332
+ expr.operands ().size () == 2 ,
333
+ expr.find_source_location ().as_string () +
334
+ " : function_call expects two operands" );
344
335
code_function_callt call (nil_exprt (), expr.op0 (), expr.op1 ().operands ());
345
336
call.add_source_location ()=expr.source_location ();
346
337
convert_function_call (call, dest, mode);
@@ -350,20 +341,14 @@ void goto_convertt::remove_function_call(
350
341
351
342
// get name of function, if available
352
343
353
- if (expr.id ()!=ID_side_effect ||
354
- expr.get (ID_statement)!=ID_function_call)
355
- {
356
- error ().source_location =expr.find_source_location ();
357
- error () << " expected function call" << eom;
358
- throw 0 ;
359
- }
344
+ DATA_INVARIANT (
345
+ expr.id () == ID_side_effect && expr.get (ID_statement) == ID_function_call,
346
+ expr.find_source_location ().as_string () + " : expected function call" );
360
347
361
- if (expr.operands ().empty ())
362
- {
363
- error ().source_location =expr.find_source_location ();
364
- error () << " function_call expects at least one operand" << eom;
365
- throw 0 ;
366
- }
348
+ DATA_INVARIANT (
349
+ !expr.operands ().empty (),
350
+ expr.find_source_location ().as_string () +
351
+ " : function_call expects at least one operand" );
367
352
368
353
std::string new_base_name = " return_value" ;
369
354
irep_idt new_symbol_mode = mode;
@@ -445,7 +430,7 @@ void goto_convertt::remove_cpp_delete(
445
430
side_effect_exprt &expr,
446
431
goto_programt &dest)
447
432
{
448
- assert (expr.operands ().size ()== 1 );
433
+ DATA_INVARIANT (expr.operands ().size () == 1 , " cpp_delete expected 1 operand " );
449
434
450
435
codet tmp (expr.get_statement ());
451
436
tmp.add_source_location ()=expr.source_location ();
@@ -498,13 +483,10 @@ void goto_convertt::remove_temporary_object(
498
483
goto_programt &dest)
499
484
{
500
485
const irep_idt &mode = expr.get (ID_mode);
501
- if (expr.operands ().size ()!=1 &&
502
- !expr.operands ().empty ())
503
- {
504
- error ().source_location =expr.find_source_location ();
505
- error () << " temporary_object takes 0 or 1 operands" << eom;
506
- throw 0 ;
507
- }
486
+ DATA_INVARIANT (
487
+ expr.operands ().size () <= 1 ,
488
+ expr.find_source_location ().as_string () +
489
+ " : temporary_object takes 0 or 1 operands" );
508
490
509
491
symbolt &new_symbol = new_tmp_symbol (
510
492
expr.type (), " obj" , dest, expr.find_source_location (), mode);
@@ -518,7 +500,10 @@ void goto_convertt::remove_temporary_object(
518
500
519
501
if (expr.find (ID_initializer).is_not_nil ())
520
502
{
521
- assert (expr.operands ().empty ());
503
+ INVARIANT (
504
+ expr.operands ().empty (),
505
+ expr.find_source_location ().as_string () +
506
+ " : temporary_object takes 0 operands" );
522
507
exprt initializer=static_cast <const exprt &>(expr.find (ID_initializer));
523
508
replace_new_object (new_symbol.symbol_expr (), initializer);
524
509
@@ -539,19 +524,15 @@ void goto_convertt::remove_statement_expression(
539
524
// The expression is copied into a temporary before the
540
525
// scope is destroyed.
541
526
542
- if (expr.operands ().size ()!=1 )
543
- {
544
- error ().source_location =expr.find_source_location ();
545
- error () << " statement_expression takes 1 operand" << eom;
546
- throw 0 ;
547
- }
527
+ DATA_INVARIANT (
528
+ expr.operands ().size () == 1 ,
529
+ expr.find_source_location ().as_string () +
530
+ " : statement_expression takes 1 operand" );
548
531
549
- if (expr.op0 ().id ()!=ID_code)
550
- {
551
- error ().source_location =expr.op0 ().find_source_location ();
552
- error () << " statement_expression takes code as operand" << eom;
553
- throw 0 ;
554
- }
532
+ DATA_INVARIANT (
533
+ expr.op0 ().id () == ID_code,
534
+ expr.find_source_location ().as_string () +
535
+ " : statement_expression takes code as operand" );
555
536
556
537
codet &code=to_code (expr.op0 ());
557
538
@@ -562,20 +543,15 @@ void goto_convertt::remove_statement_expression(
562
543
return ;
563
544
}
564
545
565
- if (code.get_statement ()!=ID_block)
566
- {
567
- error ().source_location =code.find_source_location ();
568
- error () << " statement_expression takes block as operand" << eom;
569
- throw 0 ;
570
- }
546
+ DATA_INVARIANT (
547
+ code.get_statement () == ID_block,
548
+ code.find_source_location ().as_string () +
549
+ " : statement_expression takes block as operand" );
571
550
572
- if (code.operands ().empty ())
573
- {
574
- error ().source_location =expr.find_source_location ();
575
- error () << " statement_expression takes non-empty block as operand"
576
- << eom;
577
- throw 0 ;
578
- }
551
+ DATA_INVARIANT (
552
+ !code.operands ().empty (),
553
+ expr.find_source_location ().as_string () +
554
+ " : statement_expression takes non-empty block as operand" );
579
555
580
556
// get last statement from block, following labels
581
557
codet &last=to_code_block (code).find_last_statement ();
@@ -604,10 +580,7 @@ void goto_convertt::remove_statement_expression(
604
580
}
605
581
else
606
582
{
607
- error () << " statement_expression expects expression as "
608
- << " last statement, but got `"
609
- << last.get (ID_statement) << " '" << eom;
610
- throw 0 ;
583
+ UNREACHABLE;
611
584
}
612
585
613
586
{
@@ -683,8 +656,6 @@ void goto_convertt::remove_side_effect(
683
656
}
684
657
else
685
658
{
686
- error ().source_location =expr.find_source_location ();
687
- error () << " cannot remove side effect (" << statement << " )" << eom;
688
- throw 0 ;
659
+ UNREACHABLE;
689
660
}
690
661
}
0 commit comments