@@ -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_WITH_DIAGNOSTICS (
64
+ expr.operands ().size () == 2 ,
65
+ id2string (statement) + " expects two arguments" ,
66
+ expr.find_source_location ());
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;
@@ -154,17 +149,16 @@ void goto_convertt::remove_pre(
154
149
bool result_is_used,
155
150
const irep_idt &mode)
156
151
{
157
- if (expr.operands ().size ()!=1 )
158
- {
159
- error ().source_location =expr.find_source_location ();
160
- error () << " preincrement/predecrement must have one operand" << eom;
161
- throw 0 ;
162
- }
152
+ INVARIANT_WITH_DIAGNOSTICS (
153
+ expr.operands ().size () == 1 ,
154
+ " preincrement/predecrement must have one operand" ,
155
+ expr.find_source_location ());
163
156
164
157
const irep_idt statement=expr.get_statement ();
165
158
166
- assert (statement==ID_preincrement ||
167
- statement==ID_predecrement);
159
+ DATA_INVARIANT (
160
+ statement == ID_preincrement || statement == ID_predecrement,
161
+ " expects preincrement or predecrement" );
168
162
169
163
exprt rhs;
170
164
rhs.add_source_location ()=expr.source_location ();
@@ -209,9 +203,7 @@ void goto_convertt::remove_pre(
209
203
constant_type=op_type;
210
204
else
211
205
{
212
- error ().source_location =expr.find_source_location ();
213
- error () << " no constant one of type " << op_type.pretty () << eom;
214
- throw 0 ;
206
+ UNREACHABLE;
215
207
}
216
208
217
209
exprt constant=from_integer (1 , constant_type);
@@ -246,18 +238,16 @@ void goto_convertt::remove_post(
246
238
247
239
// we have ...(op++)...
248
240
249
- if (expr.operands ().size ()!=1 )
250
- {
251
- error ().source_location =expr.find_source_location ();
252
- error () << " postincrement/postdecrement must have one operand"
253
- << eom;
254
- throw 0 ;
255
- }
241
+ INVARIANT_WITH_DIAGNOSTICS (
242
+ expr.operands ().size () == 1 ,
243
+ " postincrement/postdecrement must have one operand" ,
244
+ expr.find_source_location ());
256
245
257
246
const irep_idt statement=expr.get_statement ();
258
247
259
- assert (statement==ID_postincrement ||
260
- statement==ID_postdecrement);
248
+ DATA_INVARIANT (
249
+ statement == ID_postincrement || statement == ID_postdecrement,
250
+ " expects postincrement or postdecrement" );
261
251
262
252
exprt rhs;
263
253
rhs.add_source_location ()=expr.source_location ();
@@ -302,9 +292,7 @@ void goto_convertt::remove_post(
302
292
constant_type=op_type;
303
293
else
304
294
{
305
- error ().source_location =expr.find_source_location ();
306
- error () << " no constant one of type " << op_type.pretty () << eom;
307
- throw 0 ;
295
+ UNREACHABLE;
308
296
}
309
297
310
298
exprt constant;
@@ -349,9 +337,13 @@ void goto_convertt::remove_function_call(
349
337
const irep_idt &mode,
350
338
bool result_is_used)
351
339
{
340
+ INVARIANT_WITH_DIAGNOSTICS (
341
+ expr.operands ().size () == 2 ,
342
+ " function_call expects two operands" ,
343
+ expr.find_source_location ());
344
+
352
345
if (!result_is_used)
353
346
{
354
- assert (expr.operands ().size ()==2 );
355
347
code_function_callt call (nil_exprt (), expr.op0 (), expr.op1 ().operands ());
356
348
call.add_source_location ()=expr.source_location ();
357
349
convert_function_call (call, dest, mode);
@@ -361,20 +353,10 @@ void goto_convertt::remove_function_call(
361
353
362
354
// get name of function, if available
363
355
364
- if (expr.id ()!=ID_side_effect ||
365
- expr.get (ID_statement)!=ID_function_call)
366
- {
367
- error ().source_location =expr.find_source_location ();
368
- error () << " expected function call" << eom;
369
- throw 0 ;
370
- }
371
-
372
- if (expr.operands ().empty ())
373
- {
374
- error ().source_location =expr.find_source_location ();
375
- error () << " function_call expects at least one operand" << eom;
376
- throw 0 ;
377
- }
356
+ INVARIANT_WITH_DIAGNOSTICS (
357
+ expr.id () == ID_side_effect && expr.get (ID_statement) == ID_function_call,
358
+ " expects function call" ,
359
+ expr.find_source_location ());
378
360
379
361
std::string new_base_name = " return_value" ;
380
362
irep_idt new_symbol_mode = mode;
@@ -456,7 +438,7 @@ void goto_convertt::remove_cpp_delete(
456
438
side_effect_exprt &expr,
457
439
goto_programt &dest)
458
440
{
459
- assert (expr.operands ().size ()== 1 );
441
+ DATA_INVARIANT (expr.operands ().size () == 1 , " cpp_delete expects one operand " );
460
442
461
443
codet tmp (expr.get_statement ());
462
444
tmp.add_source_location ()=expr.source_location ();
@@ -509,13 +491,10 @@ void goto_convertt::remove_temporary_object(
509
491
goto_programt &dest)
510
492
{
511
493
const irep_idt &mode = expr.get (ID_mode);
512
- if (expr.operands ().size ()!=1 &&
513
- !expr.operands ().empty ())
514
- {
515
- error ().source_location =expr.find_source_location ();
516
- error () << " temporary_object takes 0 or 1 operands" << eom;
517
- throw 0 ;
518
- }
494
+ INVARIANT_WITH_DIAGNOSTICS (
495
+ expr.operands ().size () <= 1 ,
496
+ " temporary_object takes zero or one operands" ,
497
+ expr.find_source_location ());
519
498
520
499
symbolt &new_symbol = new_tmp_symbol (
521
500
expr.type (), " obj" , dest, expr.find_source_location (), mode);
@@ -529,7 +508,10 @@ void goto_convertt::remove_temporary_object(
529
508
530
509
if (expr.find (ID_initializer).is_not_nil ())
531
510
{
532
- assert (expr.operands ().empty ());
511
+ INVARIANT_WITH_DIAGNOSTICS (
512
+ expr.operands ().empty (),
513
+ " temporary_object takes zero operands" ,
514
+ expr.find_source_location ());
533
515
exprt initializer=static_cast <const exprt &>(expr.find (ID_initializer));
534
516
replace_new_object (new_symbol.symbol_expr (), initializer);
535
517
@@ -550,19 +532,15 @@ void goto_convertt::remove_statement_expression(
550
532
// The expression is copied into a temporary before the
551
533
// scope is destroyed.
552
534
553
- if (expr.operands ().size ()!=1 )
554
- {
555
- error ().source_location =expr.find_source_location ();
556
- error () << " statement_expression takes 1 operand" << eom;
557
- throw 0 ;
558
- }
535
+ INVARIANT_WITH_DIAGNOSTICS (
536
+ expr.operands ().size () == 1 ,
537
+ " statement_expression takes one operand" ,
538
+ expr.find_source_location ());
559
539
560
- if (expr.op0 ().id ()!=ID_code)
561
- {
562
- error ().source_location =expr.op0 ().find_source_location ();
563
- error () << " statement_expression takes code as operand" << eom;
564
- throw 0 ;
565
- }
540
+ INVARIANT_WITH_DIAGNOSTICS (
541
+ expr.op0 ().id () == ID_code,
542
+ " statement_expression takes code as operand" ,
543
+ expr.find_source_location ());
566
544
567
545
codet &code=to_code (expr.op0 ());
568
546
@@ -573,20 +551,15 @@ void goto_convertt::remove_statement_expression(
573
551
return ;
574
552
}
575
553
576
- if (code.get_statement ()!=ID_block)
577
- {
578
- error ().source_location =code.find_source_location ();
579
- error () << " statement_expression takes block as operand" << eom;
580
- throw 0 ;
581
- }
554
+ INVARIANT_WITH_DIAGNOSTICS (
555
+ code.get_statement () == ID_block,
556
+ " statement_expression takes block as operand" ,
557
+ code.find_source_location ());
582
558
583
- if (code.operands ().empty ())
584
- {
585
- error ().source_location =expr.find_source_location ();
586
- error () << " statement_expression takes non-empty block as operand"
587
- << eom;
588
- throw 0 ;
589
- }
559
+ INVARIANT_WITH_DIAGNOSTICS (
560
+ !code.operands ().empty (),
561
+ " statement_expression takes non-empty block as operand" ,
562
+ expr.find_source_location ());
590
563
591
564
// get last statement from block, following labels
592
565
codet &last=to_code_block (code).find_last_statement ();
@@ -615,10 +588,7 @@ void goto_convertt::remove_statement_expression(
615
588
}
616
589
else
617
590
{
618
- error () << " statement_expression expects expression as "
619
- << " last statement, but got `"
620
- << last.get (ID_statement) << " '" << eom;
621
- throw 0 ;
591
+ UNREACHABLE;
622
592
}
623
593
624
594
{
@@ -694,8 +664,6 @@ void goto_convertt::remove_side_effect(
694
664
}
695
665
else
696
666
{
697
- error ().source_location =expr.find_source_location ();
698
- error () << " cannot remove side effect (" << statement << " )" << eom;
699
- throw 0 ;
667
+ UNREACHABLE;
700
668
}
701
669
}
0 commit comments