8
8
9
9
#include " arrays.h"
10
10
11
- #include < cassert>
12
- #include < iostream>
13
-
14
11
#include < langapi/language_util.h>
15
12
16
13
#include < util/std_expr.h>
21
18
22
19
#include < solvers/prop/prop.h>
23
20
21
+ #ifdef DEBUG
22
+ #include < iostream>
23
+ #endif
24
+
24
25
arrayst::arrayst (
25
26
const namespacet &_ns,
26
27
propt &_prop):equalityt(_ns, _prop)
@@ -48,11 +49,15 @@ literalt arrayst::record_array_equality(
48
49
// check types
49
50
if (!base_type_eq (op0.type (), op1.type (), ns))
50
51
{
51
- std::cout << equality.pretty () << ' \n ' ;
52
- throw " record_array_equality got equality without matching types" ;
52
+ prop.error () << equality.pretty () << messaget::eom;
53
+ DATA_INVARIANT (
54
+ false ,
55
+ " record_array_equality got equality without matching types" );
53
56
}
54
57
55
- assert (ns.follow (op0.type ()).id ()==ID_array);
58
+ DATA_INVARIANT (
59
+ ns.follow (op0.type ()).id ()==ID_array,
60
+ " record_array_equality parameter should be array-typed" );
56
61
57
62
array_equalities.push_back (array_equalityt ());
58
63
@@ -113,8 +118,8 @@ void arrayst::collect_arrays(const exprt &a)
113
118
// check types
114
119
if (!base_type_eq (array_type, with_expr.old ().type (), ns))
115
120
{
116
- std::cout << a.pretty () << ' \n ' ;
117
- throw " collect_arrays got 'with' without matching types" ;
121
+ prop. error () << a.pretty () << messaget::eom ;
122
+ DATA_INVARIANT ( false , " collect_arrays got 'with' without matching types" ) ;
118
123
}
119
124
120
125
arrays.make_union (a, with_expr.old ());
@@ -131,8 +136,10 @@ void arrayst::collect_arrays(const exprt &a)
131
136
// check types
132
137
if (!base_type_eq (array_type, update_expr.old ().type (), ns))
133
138
{
134
- std::cout << a.pretty () << ' \n ' ;
135
- throw " collect_arrays got 'update' without matching types" ;
139
+ prop.error () << a.pretty () << messaget::eom;
140
+ DATA_INVARIANT (
141
+ false ,
142
+ " collect_arrays got 'update' without matching types" );
136
143
}
137
144
138
145
arrays.make_union (a, update_expr.old ());
@@ -151,15 +158,15 @@ void arrayst::collect_arrays(const exprt &a)
151
158
// check types
152
159
if (!base_type_eq (array_type, if_expr.true_case ().type (), ns))
153
160
{
154
- std::cout << a.pretty () << ' \n ' ;
155
- throw " collect_arrays got if without matching types" ;
161
+ prop. error () << a.pretty () << messaget::eom ;
162
+ DATA_INVARIANT ( false , " collect_arrays got if without matching types" ) ;
156
163
}
157
164
158
165
// check types
159
166
if (!base_type_eq (array_type, if_expr.false_case ().type (), ns))
160
167
{
161
- std::cout << a.pretty () << ' \n ' ;
162
- throw " collect_arrays got if without matching types" ;
168
+ prop. error () << a.pretty () << messaget::eom ;
169
+ DATA_INVARIANT ( false , " collect_arrays got if without matching types" ) ;
163
170
}
164
171
165
172
arrays.make_union (a, if_expr.true_case ());
@@ -175,9 +182,10 @@ void arrayst::collect_arrays(const exprt &a)
175
182
}
176
183
else if (a.id ()==ID_member)
177
184
{
178
- if (to_member_expr (a).struct_op ().id ()!=ID_symbol)
179
- throw
180
- " unexpected array expression: member with `" +a.op0 ().id_string ()+" '" ;
185
+ DATA_INVARIANT (
186
+ to_member_expr (a).struct_op ().id ()==ID_symbol,
187
+ (" unexpected array expression: member with `" +
188
+ a.op0 ().id_string ()+" '" ).c_str ());
181
189
}
182
190
else if (a.id ()==ID_constant ||
183
191
a.id ()==ID_array ||
@@ -190,20 +198,24 @@ void arrayst::collect_arrays(const exprt &a)
190
198
else if (a.id ()==ID_byte_update_little_endian ||
191
199
a.id ()==ID_byte_update_big_endian)
192
200
{
193
- assert (0 );
201
+ DATA_INVARIANT (
202
+ false ,
203
+ " byte_update should be removed before collect_arrays" );
194
204
}
195
205
else if (a.id ()==ID_typecast)
196
206
{
197
207
// cast between array types?
198
- assert (a.operands ().size ()==1 );
208
+ DATA_INVARIANT (
209
+ a.operands ().size ()==1 ,
210
+ " typecast must have one operand" );
199
211
200
- if (a. op0 (). type (). id ()==ID_array)
201
- {
202
- arrays. make_union (a, a. op0 ());
203
- collect_arrays ( a.op0 ());
204
- }
205
- else
206
- throw " unexpected array type cast from " + a.op0 (). type (). id_string ( );
212
+ DATA_INVARIANT (
213
+ a. op0 (). type (). id ()==ID_array,
214
+ ( " unexpected array type cast from " +
215
+ a.op0 (). type (). id_string ()). c_str ());
216
+
217
+ arrays. make_union (a, a. op0 ());
218
+ collect_arrays ( a.op0 ());
207
219
}
208
220
else if (a.id ()==ID_index)
209
221
{
@@ -212,7 +224,12 @@ void arrayst::collect_arrays(const exprt &a)
212
224
collect_arrays (a.op0 ());
213
225
}
214
226
else
215
- throw " unexpected array expression (collect_arrays): `" +a.id_string ()+" '" ;
227
+ {
228
+ DATA_INVARIANT (
229
+ false ,
230
+ (" unexpected array expression (collect_arrays): `" +
231
+ a.id_string ()+" '" ).c_str ());
232
+ }
216
233
}
217
234
218
235
// / adds array constraints (refine=true...lazily for the refinement loop)
@@ -280,7 +297,7 @@ void arrayst::add_array_Ackermann_constraints()
280
297
{
281
298
// this is quadratic!
282
299
283
- #if 0
300
+ #ifdef DEBUG
284
301
std::cout << " arrays.size(): " << arrays.size () << ' \n ' ;
285
302
#endif
286
303
@@ -289,7 +306,7 @@ void arrayst::add_array_Ackermann_constraints()
289
306
{
290
307
const index_sett &index_set=index_map[arrays.find_number (i)];
291
308
292
- #if 0
309
+ #ifdef DEBUG
293
310
std::cout << " index_set.size(): " << index_set.size () << ' \n ' ;
294
311
#endif
295
312
@@ -349,7 +366,7 @@ void arrayst::update_index_map(std::size_t i)
349
366
return ;
350
367
351
368
std::size_t root_number=arrays.find_number (i);
352
- assert (root_number!=i);
369
+ INVARIANT (root_number!=i, " is_root_number incorrect? " );
353
370
354
371
index_sett &root_index_set=index_map[root_number];
355
372
index_sett &index_set=index_map[i];
@@ -407,7 +424,9 @@ void arrayst::add_array_constraints_equality(
407
424
const typet &subtype2=ns.follow (array_equality.f2 .type ()).subtype ();
408
425
index_exprt index_expr2 (array_equality.f2 , index , subtype2);
409
426
410
- assert (index_expr1.type ()==index_expr2.type ());
427
+ DATA_INVARIANT (
428
+ index_expr1.type ()==index_expr2.type (),
429
+ " array elements should all have same type" );
411
430
412
431
array_equalityt equal;
413
432
equal.f1 = index_expr1;
@@ -449,12 +468,14 @@ void arrayst::add_array_constraints(
449
468
else if (expr.id ()==ID_byte_update_little_endian ||
450
469
expr.id ()==ID_byte_update_big_endian)
451
470
{
452
- assert ( 0 );
471
+ INVARIANT ( false , " byte_update should be removed before arrayst " );
453
472
}
454
473
else if (expr.id ()==ID_typecast)
455
474
{
456
475
// we got a=(type[])b
457
- assert (expr.operands ().size ()==1 );
476
+ DATA_INVARIANT (
477
+ expr.operands ().size ()==1 ,
478
+ " typecast should have one operand" );
458
479
459
480
// add a[i]=b[i]
460
481
for (const auto &index : index_set)
@@ -463,7 +484,9 @@ void arrayst::add_array_constraints(
463
484
index_exprt index_expr1 (expr, index , subtype);
464
485
index_exprt index_expr2 (expr.op0 (), index , subtype);
465
486
466
- assert (index_expr1.type ()==index_expr2.type ());
487
+ DATA_INVARIANT (
488
+ index_expr1.type ()==index_expr2.type (),
489
+ " array elements should all have same type" );
467
490
468
491
// add constraint
469
492
lazy_constraintt lazy (lazy_typet::ARRAY_TYPECAST,
@@ -475,9 +498,12 @@ void arrayst::add_array_constraints(
475
498
{
476
499
}
477
500
else
478
- throw
479
- " unexpected array expression (add_array_constraints): `" +
480
- expr.id_string ()+" '" ;
501
+ {
502
+ DATA_INVARIANT (
503
+ false ,
504
+ (" unexpected array expression (add_array_constraints): `" +
505
+ expr.id_string ()+" '" ).c_str ());
506
+ }
481
507
}
482
508
483
509
void arrayst::add_array_constraints_with (
@@ -495,8 +521,10 @@ void arrayst::add_array_constraints_with(
495
521
496
522
if (index_expr.type ()!=value.type ())
497
523
{
498
- std::cout << expr.pretty () << ' \n ' ;
499
- assert (false );
524
+ prop.error () << expr.pretty () << messaget::eom;
525
+ DATA_INVARIANT (
526
+ false ,
527
+ " with-expression operand should match array element type" );
500
528
}
501
529
502
530
lazy_constraintt lazy (
@@ -563,8 +591,10 @@ void arrayst::add_array_constraints_update(
563
591
564
592
if(index_expr.type()!=value.type())
565
593
{
566
- std::cout << expr.pretty() << '\n';
567
- assert(false);
594
+ prop.error() << expr.pretty() << messaget::eom;
595
+ DATA_INVARIANT(
596
+ false,
597
+ "update operand should match array element type");
568
598
}
569
599
570
600
set_to_true(equal_exprt(index_expr, value));
@@ -619,7 +649,9 @@ void arrayst::add_array_constraints_array_of(
619
649
const typet &subtype=ns.follow (expr.type ()).subtype ();
620
650
index_exprt index_expr (expr, index , subtype);
621
651
622
- assert (base_type_eq (index_expr.type (), expr.op0 ().type (), ns));
652
+ DATA_INVARIANT (
653
+ base_type_eq (index_expr.type (), expr.op0 ().type (), ns),
654
+ " array_of operand type should match array element type" );
623
655
624
656
// add constraint
625
657
lazy_constraintt lazy (
0 commit comments