7
7
\*******************************************************************/
8
8
9
9
10
- #include < cassert>
11
10
#include < iostream>
12
11
13
12
#include < langapi/language_util.h>
@@ -50,10 +49,12 @@ literalt arrayst::record_array_equality(
50
49
if (!base_type_eq (op0.type (), op1.type (), ns))
51
50
{
52
51
prop.error () << equality.pretty () << messaget::eom;
53
- throw " record_array_equality got equality without matching types" ;
52
+ DATA_INVARIANT ( false , " record_array_equality got equality without matching types" ) ;
54
53
}
55
54
56
- assert (ns.follow (op0.type ()).id ()==ID_array);
55
+ DATA_INVARIANT (
56
+ ns.follow (op0.type ()).id ()==ID_array,
57
+ " record_array_equality parameter should be array-typed" );
57
58
58
59
array_equalities.push_back (array_equalityt ());
59
60
@@ -109,14 +110,15 @@ void arrayst::collect_arrays(const exprt &a)
109
110
110
111
if (a.id ()==ID_with)
111
112
{
112
- if (a.operands ().size ()!=3 )
113
- throw " with expected to have three operands" ;
113
+ DATA_INVARIANT (
114
+ a.operands ().size ()==3 ,
115
+ " with expected to have three operands" );
114
116
115
117
// check types
116
118
if (!base_type_eq (array_type, a.op0 ().type (), ns))
117
119
{
118
120
prop.error () << a.pretty () << messaget::eom;
119
- throw " collect_arrays got 'with' without matching types" ;
121
+ DATA_INVARIANT ( false , " collect_arrays got 'with' without matching types" ) ;
120
122
}
121
123
122
124
arrays.make_union (a, a.op0 ());
@@ -131,14 +133,15 @@ void arrayst::collect_arrays(const exprt &a)
131
133
}
132
134
else if (a.id ()==ID_update) // TODO: is this obsolete?
133
135
{
134
- if (a.operands ().size ()!=3 )
135
- throw " update expected to have three operands" ;
136
+ DATA_INVARIANT (
137
+ a.operands ().size ()==3 ,
138
+ " update expected to have three operands" );
136
139
137
140
// check types
138
141
if (!base_type_eq (array_type, a.op0 ().type (), ns))
139
142
{
140
143
prop.error () << a.pretty () << messaget::eom;
141
- throw " collect_arrays got 'update' without matching types" ;
144
+ DATA_INVARIANT ( false , " collect_arrays got 'update' without matching types" ) ;
142
145
}
143
146
144
147
arrays.make_union (a, a.op0 ());
@@ -155,21 +158,22 @@ void arrayst::collect_arrays(const exprt &a)
155
158
}
156
159
else if (a.id ()==ID_if)
157
160
{
158
- if (a.operands ().size ()!=3 )
159
- throw " if expected to have three operands" ;
161
+ DATA_INVARIANT (
162
+ a.operands ().size ()==3 ,
163
+ " if expected to have three operands" );
160
164
161
165
// check types
162
166
if (!base_type_eq (array_type, a.op1 ().type (), ns))
163
167
{
164
168
prop.error () << a.pretty () << messaget::eom;
165
- throw " collect_arrays got if without matching types" ;
169
+ DATA_INVARIANT ( false , " collect_arrays got if without matching types" ) ;
166
170
}
167
171
168
172
// check types
169
173
if (!base_type_eq (array_type, a.op2 ().type (), ns))
170
174
{
171
175
prop.error () << a.pretty () << messaget::eom;
172
- throw " collect_arrays got if without matching types" ;
176
+ DATA_INVARIANT ( false , " collect_arrays got if without matching types" ) ;
173
177
}
174
178
175
179
arrays.make_union (a, a.op1 ());
@@ -185,9 +189,10 @@ void arrayst::collect_arrays(const exprt &a)
185
189
}
186
190
else if (a.id ()==ID_member)
187
191
{
188
- if (to_member_expr (a).struct_op ().id ()!=ID_symbol)
189
- throw
190
- " unexpected array expression: member with `" +a.op0 ().id_string ()+" '" ;
192
+ DATA_INVARIANT (
193
+ to_member_expr (a).struct_op ().id ()==ID_symbol,
194
+ (" unexpected array expression: member with `" +
195
+ a.op0 ().id_string ()+" '" ).c_str ());
191
196
}
192
197
else if (a.id ()==ID_constant ||
193
198
a.id ()==ID_array ||
@@ -200,20 +205,24 @@ void arrayst::collect_arrays(const exprt &a)
200
205
else if (a.id ()==ID_byte_update_little_endian ||
201
206
a.id ()==ID_byte_update_big_endian)
202
207
{
203
- assert (0 );
208
+ DATA_INVARIANT (
209
+ false ,
210
+ " byte_update should be removed before collect_arrays" );
204
211
}
205
212
else if (a.id ()==ID_typecast)
206
213
{
207
214
// cast between array types?
208
- assert (a.operands ().size ()==1 );
215
+ DATA_INVARIANT (
216
+ a.operands ().size ()==1 ,
217
+ " typecast must have one operand" );
209
218
210
- if (a. op0 (). type (). id ()==ID_array)
211
- {
212
- arrays. make_union (a, a. op0 ());
213
- collect_arrays ( a.op0 ());
214
- }
215
- else
216
- throw " unexpected array type cast from " + a.op0 (). type (). id_string ( );
219
+ DATA_INVARIANT (
220
+ a. op0 (). type (). id ()==ID_array,
221
+ ( " unexpected array type cast from " +
222
+ a.op0 (). type (). id_string ()). c_str ());
223
+
224
+ arrays. make_union (a, a. op0 ());
225
+ collect_arrays ( a.op0 ());
217
226
}
218
227
else if (a.id ()==ID_index)
219
228
{
@@ -222,7 +231,12 @@ void arrayst::collect_arrays(const exprt &a)
222
231
collect_arrays (a.op0 ());
223
232
}
224
233
else
225
- throw " unexpected array expression (collect_arrays): `" +a.id_string ()+" '" ;
234
+ {
235
+ DATA_INVARIANT (
236
+ false ,
237
+ (" unexpected array expression (collect_arrays): `" +
238
+ a.id_string ()+" '" ).c_str ());
239
+ }
226
240
}
227
241
228
242
// / adds array constraints (refine=true...lazily for the refinement loop)
@@ -364,7 +378,7 @@ void arrayst::update_index_map(std::size_t i)
364
378
return ;
365
379
366
380
std::size_t root_number=arrays.find_number (i);
367
- assert (root_number!=i);
381
+ INVARIANT (root_number!=i, " is_root_number incorrect? " );
368
382
369
383
index_sett &root_index_set=index_map[root_number];
370
384
index_sett &index_set=index_map[i];
@@ -435,7 +449,9 @@ void arrayst::add_array_constraints(
435
449
index_expr2.array ()=array_equality.f2 ;
436
450
index_expr2.index ()=*it;
437
451
438
- assert (index_expr1.type ()==index_expr2.type ());
452
+ DATA_INVARIANT (
453
+ index_expr1.type ()==index_expr2.type (),
454
+ " array elements should all have same type" );
439
455
440
456
array_equalityt equal;
441
457
equal.f1 = index_expr1;
@@ -477,12 +493,14 @@ void arrayst::add_array_constraints(
477
493
else if (expr.id ()==ID_byte_update_little_endian ||
478
494
expr.id ()==ID_byte_update_big_endian)
479
495
{
480
- assert ( 0 );
496
+ INVARIANT ( false , " byte_update should be removed before arrayst " );
481
497
}
482
498
else if (expr.id ()==ID_typecast)
483
499
{
484
500
// we got a=(type[])b
485
- assert (expr.operands ().size ()==1 );
501
+ DATA_INVARIANT (
502
+ expr.operands ().size ()==1 ,
503
+ " typecast should have one operand" );
486
504
487
505
// add a[i]=b[i]
488
506
for (index_sett::const_iterator
@@ -500,7 +518,9 @@ void arrayst::add_array_constraints(
500
518
index_expr2.array ()=expr.op0 ();
501
519
index_expr2.index ()=*it;
502
520
503
- assert (index_expr1.type ()==index_expr2.type ());
521
+ DATA_INVARIANT (
522
+ index_expr1.type ()==index_expr2.type (),
523
+ " array elements should all have same type" );
504
524
505
525
// add constraint
506
526
lazy_constraintt lazy (lazy_typet::ARRAY_TYPECAST,
@@ -512,9 +532,12 @@ void arrayst::add_array_constraints(
512
532
{
513
533
}
514
534
else
515
- throw
516
- " unexpected array expression (add_array_constraints): `" +
517
- expr.id_string ()+" '" ;
535
+ {
536
+ DATA_INVARIANT (
537
+ false ,
538
+ (" unexpected array expression (add_array_constraints): `" +
539
+ expr.id_string ()+" '" ).c_str ());
540
+ }
518
541
}
519
542
520
543
void arrayst::add_array_constraints_with (
@@ -536,7 +559,9 @@ void arrayst::add_array_constraints_with(
536
559
if (index_expr.type ()!=value.type ())
537
560
{
538
561
prop.error () << expr.pretty () << messaget::eom;
539
- throw " index_expr and value types should match" ;
562
+ DATA_INVARIANT (
563
+ false ,
564
+ " with-expression operand should match array element type" );
540
565
}
541
566
542
567
lazy_constraintt lazy (
@@ -575,7 +600,9 @@ void arrayst::add_array_constraints_with(
575
600
index_expr2.array ()=expr.op0 ();
576
601
index_expr2.index ()=other_index;
577
602
578
- assert (index_expr1.type ()==index_expr2.type ());
603
+ DATA_INVARIANT (
604
+ index_expr1.type ()==index_expr2.type (),
605
+ " array elements should all have same type" );
579
606
580
607
equal_exprt equality_expr (index_expr1, index_expr2);
581
608
@@ -620,7 +647,9 @@ void arrayst::add_array_constraints_update(
620
647
if(index_expr.type()!=value.type())
621
648
{
622
649
prop.error() << expr.pretty() << messaget::eom;
623
- throw "index_expr and value types should match";
650
+ DATA_INVARIANT(
651
+ false,
652
+ "update operand should match array element type");
624
653
}
625
654
626
655
set_to_true(equal_exprt(index_expr, value));
@@ -657,7 +686,9 @@ void arrayst::add_array_constraints_update(
657
686
index_expr2.array()=expr.op0();
658
687
index_expr2.index()=other_index;
659
688
660
- assert(index_expr1.type()==index_expr2.type());
689
+ DATA_INVARIANT(
690
+ index_expr1.type()==index_expr2.type(),
691
+ "array elements should all have same type");
661
692
662
693
equal_exprt equality_expr(index_expr1, index_expr2);
663
694
@@ -693,7 +724,9 @@ void arrayst::add_array_constraints_array_of(
693
724
index_expr.array ()=expr;
694
725
index_expr.index ()=*it;
695
726
696
- assert (base_type_eq (index_expr.type (), expr.op0 ().type (), ns));
727
+ DATA_INVARIANT (
728
+ base_type_eq (index_expr.type (), expr.op0 ().type (), ns),
729
+ " array_of operand type should match array element type" );
697
730
698
731
// add constraint
699
732
lazy_constraintt lazy (
@@ -730,7 +763,9 @@ void arrayst::add_array_constraints_if(
730
763
index_expr2.array ()=expr.true_case ();
731
764
index_expr2.index ()=*it;
732
765
733
- assert (index_expr1.type ()==index_expr2.type ());
766
+ DATA_INVARIANT (
767
+ index_expr1.type ()==index_expr2.type (),
768
+ " array elements should all have same type" );
734
769
735
770
// add implication
736
771
lazy_constraintt lazy (lazy_typet::ARRAY_IF,
@@ -759,7 +794,9 @@ void arrayst::add_array_constraints_if(
759
794
index_expr2.array ()=expr.false_case ();
760
795
index_expr2.index ()=*it;
761
796
762
- assert (index_expr1.type ()==index_expr2.type ());
797
+ DATA_INVARIANT (
798
+ index_expr1.type ()==index_expr2.type (),
799
+ " array elements should all have same type" );
763
800
764
801
// add implication
765
802
lazy_constraintt lazy (
0 commit comments