@@ -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
+ DATA_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;
@@ -338,9 +326,13 @@ void goto_convertt::remove_function_call(
338
326
const irep_idt &mode,
339
327
bool result_is_used)
340
328
{
329
+ DATA_INVARIANT (
330
+ expr.operands ().size () == 2 ,
331
+ expr.find_source_location ().as_string () +
332
+ " : function_call expects two operands" );
333
+
341
334
if (!result_is_used)
342
335
{
343
- assert (expr.operands ().size ()==2 );
344
336
code_function_callt call (nil_exprt (), expr.op0 (), expr.op1 ().operands ());
345
337
call.add_source_location ()=expr.source_location ();
346
338
convert_function_call (call, dest, mode);
@@ -350,20 +342,9 @@ void goto_convertt::remove_function_call(
350
342
351
343
// get name of function, if available
352
344
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
- }
360
-
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
- }
345
+ DATA_INVARIANT (
346
+ expr.id () == ID_side_effect && expr.get (ID_statement) == ID_function_call,
347
+ expr.find_source_location ().as_string () + " : expected function call" );
367
348
368
349
std::string new_base_name = " return_value" ;
369
350
irep_idt new_symbol_mode = mode;
@@ -445,7 +426,8 @@ void goto_convertt::remove_cpp_delete(
445
426
side_effect_exprt &expr,
446
427
goto_programt &dest)
447
428
{
448
- assert (expr.operands ().size ()==1 );
429
+ DATA_INVARIANT (expr.operands ().size () == 1 ,
430
+ " cpp_delete expected one operand" );
449
431
450
432
codet tmp (expr.get_statement ());
451
433
tmp.add_source_location ()=expr.source_location ();
@@ -498,13 +480,10 @@ void goto_convertt::remove_temporary_object(
498
480
goto_programt &dest)
499
481
{
500
482
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
- }
483
+ DATA_INVARIANT (
484
+ expr.operands ().size () <= 1 ,
485
+ expr.find_source_location ().as_string () +
486
+ " : temporary_object takes zero or one operands" );
508
487
509
488
symbolt &new_symbol = new_tmp_symbol (
510
489
expr.type (), " obj" , dest, expr.find_source_location (), mode);
@@ -518,7 +497,10 @@ void goto_convertt::remove_temporary_object(
518
497
519
498
if (expr.find (ID_initializer).is_not_nil ())
520
499
{
521
- assert (expr.operands ().empty ());
500
+ INVARIANT (
501
+ expr.operands ().empty (),
502
+ expr.find_source_location ().as_string () +
503
+ " : temporary_object takes zero operands" );
522
504
exprt initializer=static_cast <const exprt &>(expr.find (ID_initializer));
523
505
replace_new_object (new_symbol.symbol_expr (), initializer);
524
506
@@ -539,19 +521,15 @@ void goto_convertt::remove_statement_expression(
539
521
// The expression is copied into a temporary before the
540
522
// scope is destroyed.
541
523
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
- }
524
+ DATA_INVARIANT (
525
+ expr.operands ().size () == 1 ,
526
+ expr.find_source_location ().as_string () +
527
+ " : statement_expression takes one operand" );
548
528
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
- }
529
+ DATA_INVARIANT (
530
+ expr.op0 ().id () == ID_code,
531
+ expr.find_source_location ().as_string () +
532
+ " : statement_expression takes code as operand" );
555
533
556
534
codet &code=to_code (expr.op0 ());
557
535
@@ -562,20 +540,15 @@ void goto_convertt::remove_statement_expression(
562
540
return ;
563
541
}
564
542
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
- }
543
+ DATA_INVARIANT (
544
+ code.get_statement () == ID_block,
545
+ code.find_source_location ().as_string () +
546
+ " : statement_expression takes block as operand" );
571
547
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
- }
548
+ DATA_INVARIANT (
549
+ !code.operands ().empty (),
550
+ expr.find_source_location ().as_string () +
551
+ " : statement_expression takes non-empty block as operand" );
579
552
580
553
// get last statement from block, following labels
581
554
codet &last=to_code_block (code).find_last_statement ();
@@ -588,7 +561,7 @@ void goto_convertt::remove_statement_expression(
588
561
symbol_exprt tmp_symbol_expr (new_symbol.name , new_symbol.type );
589
562
tmp_symbol_expr.add_source_location ()=source_location;
590
563
591
- if (last.get (ID_statement )==ID_expression)
564
+ if (last.get (ID_statement_expressionement )==ID_expression)
592
565
{
593
566
// we turn this into an assignment
594
567
exprt e=to_code_expression (last).expression ();
@@ -604,10 +577,7 @@ void goto_convertt::remove_statement_expression(
604
577
}
605
578
else
606
579
{
607
- error () << " statement_expression expects expression as "
608
- << " last statement, but got `"
609
- << last.get (ID_statement) << " '" << eom;
610
- throw 0 ;
580
+ UNREACHABLE;
611
581
}
612
582
613
583
{
@@ -683,8 +653,6 @@ void goto_convertt::remove_side_effect(
683
653
}
684
654
else
685
655
{
686
- error ().source_location =expr.find_source_location ();
687
- error () << " cannot remove side effect (" << statement << " )" << eom;
688
- throw 0 ;
656
+ UNREACHABLE;
689
657
}
690
658
}
0 commit comments