Skip to content

Commit 8960b8a

Browse files
author
martin
committed
Convert assertions to invariants.
1 parent 2459be5 commit 8960b8a

11 files changed

+53
-51
lines changed

src/analyses/variable-sensitivity/abstract_enviroment.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Function: abstract_environmentt::assign
159159
bool abstract_environmentt::assign(
160160
const exprt &expr, const abstract_object_pointert value, const namespacet &ns)
161161
{
162-
assert(value);
162+
PRECONDITION(value);
163163

164164
if(value->is_bottom())
165165
{
@@ -189,7 +189,7 @@ bool abstract_environmentt::assign(
189189

190190
if(!lhs_value)
191191
{
192-
assert(s.id()==ID_symbol);
192+
INVARIANT(s.id()==ID_symbol, "Have a symbol or a stack");
193193
const symbol_exprt &symbol_expr(to_symbol_expr(s));
194194
if(map.find(symbol_expr)==map.end())
195195
{
@@ -230,7 +230,7 @@ bool abstract_environmentt::assign(
230230
const typet &rhs_type=ns.follow(final_value->type());
231231

232232
// Write the value for the root symbol back into the map
233-
assert(lhs_type==rhs_type);
233+
INVARIANT(lhs_type==rhs_type, "Assignment types must match");
234234
// If LHS was directly the symbol
235235
if(s.id()==ID_symbol)
236236
{
@@ -276,7 +276,7 @@ abstract_object_pointert abstract_environmentt::write(
276276
const namespacet &ns,
277277
bool merge_write)
278278
{
279-
assert(!remaining_stack.empty());
279+
PRECONDITION(!remaining_stack.empty());
280280
const exprt & next_expr=remaining_stack.top();
281281
remaining_stack.pop();
282282

@@ -305,7 +305,7 @@ abstract_object_pointert abstract_environmentt::write(
305305
}
306306
else
307307
{
308-
assert(0);
308+
UNREACHABLE;
309309
return nullptr;
310310
}
311311
}
@@ -332,7 +332,7 @@ bool abstract_environmentt::assume(const exprt &expr, const namespacet &ns)
332332
// This should be enforced by the well-structured-ness of the
333333
// goto-program and the way assume is used.
334334

335-
assert(expr.type().id()==ID_bool);
335+
PRECONDITION(expr.type().id()==ID_bool);
336336

337337
// Evaluate the expression
338338
abstract_object_pointert res = eval(expr, ns);
@@ -342,7 +342,7 @@ bool abstract_environmentt::assume(const exprt &expr, const namespacet &ns)
342342
if(possibly_constant.id()!=ID_nil) // I.E. actually a value
343343
{
344344
// Should be of the right type
345-
assert(possibly_constant.type().id()==ID_bool);
345+
INVARIANT(possibly_constant.type().id()==ID_bool, "simplication preserves type");
346346

347347
if(possibly_constant.is_false())
348348
{

src/analyses/variable-sensitivity/abstract_object.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Function: abstract_objectt::abstract_objectt
5454
abstract_objectt::abstract_objectt(const typet &type, bool top, bool bottom):
5555
t(type), bottom(bottom), top(top)
5656
{
57-
assert(!(top && bottom));
57+
PRECONDITION(!(top && bottom));
5858
}
5959

6060
/*******************************************************************\

src/analyses/variable-sensitivity/array_abstract_object.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Function: array_abstract_objectt::array_abstract_objectt
2828
array_abstract_objectt::array_abstract_objectt(const typet &t):
2929
abstract_objectt(t)
3030
{
31-
assert(t.id()==ID_array);
31+
PRECONDITION(t.id()==ID_array);
3232
}
3333

3434
/*******************************************************************\
@@ -51,7 +51,7 @@ array_abstract_objectt::array_abstract_objectt(
5151
const typet &t, bool tp, bool bttm):
5252
abstract_objectt(t, tp, bttm)
5353
{
54-
assert(t.id()==ID_array);
54+
PRECONDITION(t.id()==ID_array);
5555
}
5656

5757
/*******************************************************************\
@@ -75,7 +75,7 @@ array_abstract_objectt::array_abstract_objectt(
7575
const namespacet &ns):
7676
abstract_objectt(e, environment, ns)
7777
{
78-
assert(e.type().id()==ID_array);
78+
PRECONDITION(e.type().id()==ID_array);
7979
}
8080

8181
/**

src/analyses/variable-sensitivity/constant_array_abstract_object.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ abstract_object_pointert constant_array_abstract_objectt::constant_array_merge(
154154

155155
result->map=merged_map;
156156

157-
assert(!result->is_top());
158-
assert(!result->is_bottom());
157+
INVARIANT(!result->is_top(), "merge of maps doesn't generate top");
158+
INVARIANT(!result->is_bottom(), "merge of maps doesn't generate bottom");
159159
return result;
160160
}
161161
}
@@ -277,7 +277,7 @@ abstract_object_pointert constant_array_abstract_objectt::read_index(
277277
}
278278
else
279279
{
280-
assert(!is_bottom());
280+
PRECONDITION(!is_bottom());
281281
mp_integer index_value;
282282
if(eval_index(index, env, ns, index_value))
283283
{

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
3131
const typet &t):
3232
pointer_abstract_objectt(t)
3333
{
34-
assert(t.id()==ID_pointer);
34+
PRECONDITION(t.id()==ID_pointer);
3535
}
3636

3737
/*******************************************************************\
@@ -54,7 +54,7 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
5454
const typet &t, bool tp, bool bttm):
5555
pointer_abstract_objectt(t, tp, bttm)
5656
{
57-
assert(t.id()==ID_pointer);
57+
PRECONDITION(t.id()==ID_pointer);
5858
}
5959

6060
/*******************************************************************\
@@ -95,7 +95,7 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
9595
pointer_abstract_objectt(e, environment, ns),
9696
value_stack(e, environment, ns)
9797
{
98-
assert(e.type().id()==ID_pointer);
98+
PRECONDITION(e.type().id()==ID_pointer);
9999
if(value_stack.is_top_value())
100100
{
101101
make_top();
@@ -328,7 +328,7 @@ sharing_ptrt<pointer_abstract_objectt>
328328
if(stack.empty())
329329
{
330330
// We should not be changing the type of an abstract object
331-
assert(new_value->type()==type().subtype());
331+
PRECONDITION(new_value->type()==type().subtype());
332332

333333
// Get an expression that we can assign to
334334
exprt value=value_stack.to_expression().op0();

src/analyses/variable-sensitivity/full_struct_abstract_object.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Function: full_struct_abstract_objectt::struct_abstract_objectt
3636
full_struct_abstract_objectt::full_struct_abstract_objectt(const typet &t):
3737
struct_abstract_objectt(t)
3838
{
39-
assert(t.id()==ID_struct);
40-
assert(verify());
39+
PRECONDITION(t.id()==ID_struct);
40+
DATA_INVARIANT(verify(), "Structural invariants maintained");
4141
}
4242

4343
/*******************************************************************\
@@ -60,8 +60,8 @@ full_struct_abstract_objectt::full_struct_abstract_objectt(
6060
const typet &t, bool top, bool bottom):
6161
struct_abstract_objectt(t, top, bottom)
6262
{
63-
assert(t.id()==ID_struct);
64-
assert(verify());
63+
PRECONDITION(t.id()==ID_struct);
64+
DATA_INVARIANT(verify(), "Structural invariants maintained");
6565
}
6666

6767
/*******************************************************************\
@@ -84,7 +84,7 @@ full_struct_abstract_objectt::full_struct_abstract_objectt(
8484
const namespacet &ns):
8585
struct_abstract_objectt(e, environment, ns)
8686
{
87-
assert(verify());
87+
DATA_INVARIANT(verify(), "Structural invariants maintained");
8888
}
8989

9090
/*******************************************************************\
@@ -122,7 +122,7 @@ abstract_object_pointert full_struct_abstract_objectt::read_component(
122122
}
123123
else
124124
{
125-
assert(!is_bottom());
125+
PRECONDITION(!is_bottom());
126126

127127
irep_idt c=member_expr.get_component_name();
128128

@@ -203,7 +203,7 @@ sharing_ptrt<struct_abstract_objectt>
203203
copy->map[c]=
204204
environment.write(starting_value, value, stack, ns, merging_write);
205205
copy->clear_top();
206-
assert(copy->verify());
206+
DATA_INVARIANT(copy->verify(), "Structural invariants maintained");;
207207
return copy;
208208
}
209209
else
@@ -219,19 +219,19 @@ sharing_ptrt<struct_abstract_objectt>
219219
{
220220
if(is_top()) // struct is top
221221
{
222-
assert(copy->verify());
222+
DATA_INVARIANT(copy->verify(), "Structural invariants maintained");;
223223
return copy;
224224
}
225225

226-
assert(!copy->map.empty());
226+
INVARIANT(!copy->map.empty(), "If not top, map cannot be empty");
227227

228228
struct_mapt &m=copy->map;
229229

230230
struct_mapt::iterator it=m.find(c);
231231

232232
if(it==m.end()) // component is top
233233
{
234-
assert(copy->verify());
234+
DATA_INVARIANT(copy->verify(), "Structural invariants maintained");;
235235
return copy;
236236
}
237237

@@ -243,10 +243,10 @@ sharing_ptrt<struct_abstract_objectt>
243243
{
244244
copy->map[c]=value;
245245
copy->clear_top();
246-
assert(!copy->is_bottom());
246+
INVARIANT(!copy->is_bottom(), "top != bottom");
247247
}
248248

249-
assert(copy->verify());
249+
DATA_INVARIANT(copy->verify(), "Structural invariants maintained");;
250250
return copy;
251251
}
252252
}
@@ -367,7 +367,7 @@ abstract_object_pointert full_struct_abstract_objectt::merge_constant_structs(
367367
abstract_objectt::merge_maps<irep_idt>(map, other->map, merged_map);
368368
if(!modified)
369369
{
370-
assert(verify());
370+
DATA_INVARIANT(verify(), "Structural invariants maintained");
371371
return shared_from_this();
372372
}
373373
else
@@ -378,9 +378,9 @@ abstract_object_pointert full_struct_abstract_objectt::merge_constant_structs(
378378

379379
result->map=merged_map;
380380

381-
assert(!result->is_top());
382-
assert(!result->is_bottom());
383-
assert(result->verify());
381+
INVARIANT(!result->is_top(), "Merge of maps will not generate top");
382+
INVARIANT(!result->is_bottom(), "Merge of maps will not generate bottom");
383+
DATA_INVARIANT(result->verify(), "Structural invariants maintained");
384384
return result;
385385
}
386386
}

src/analyses/variable-sensitivity/pointer_abstract_object.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Function: pointer_abstract_objectt::pointer_abstract_objectt
2929
pointer_abstract_objectt::pointer_abstract_objectt(const typet &t):
3030
abstract_objectt(t)
3131
{
32-
assert(t.id()==ID_pointer);
32+
PRECONDITION(t.id()==ID_pointer);
3333
}
3434

3535
/*******************************************************************\
@@ -52,7 +52,7 @@ pointer_abstract_objectt::pointer_abstract_objectt(
5252
const typet &t, bool tp, bool bttm):
5353
abstract_objectt(t, tp, bttm)
5454
{
55-
assert(t.id()==ID_pointer);
55+
PRECONDITION(t.id()==ID_pointer);
5656
}
5757

5858
/*******************************************************************\
@@ -74,7 +74,7 @@ pointer_abstract_objectt::pointer_abstract_objectt(
7474
const namespacet &ns):
7575
abstract_objectt(e, environment, ns)
7676
{
77-
assert(e.type().id()==ID_pointer);
77+
PRECONDITION(e.type().id()==ID_pointer);
7878
}
7979

8080
/**

src/analyses/variable-sensitivity/struct_abstract_object.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Function: struct_abstract_objectt::struct_abstract_objectt
3030
struct_abstract_objectt::struct_abstract_objectt(const typet &t):
3131
abstract_objectt(t)
3232
{
33-
assert(t.id()==ID_struct);
33+
PRECONDITION(t.id()==ID_struct);
3434
}
3535

3636
/*******************************************************************\
@@ -53,7 +53,7 @@ struct_abstract_objectt::struct_abstract_objectt(
5353
const typet &t, bool tp, bool bttm):
5454
abstract_objectt(t, tp, bttm)
5555
{
56-
assert(t.id()==ID_struct);
56+
PRECONDITION(t.id()==ID_struct);
5757
}
5858

5959
/*******************************************************************\
@@ -75,7 +75,7 @@ struct_abstract_objectt::struct_abstract_objectt(
7575
const namespacet &ns):
7676
abstract_objectt(e, environment, ns)
7777
{
78-
assert(ns.follow(e.type()).id()==ID_struct);
78+
PRECONDITION(ns.follow(e.type()).id()==ID_struct);
7979
}
8080

8181
/**

src/analyses/variable-sensitivity/union_abstract_object.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Function: union_abstract_objectt::union_abstract_objectt
2929
union_abstract_objectt::union_abstract_objectt(const typet &type):
3030
abstract_objectt(type)
3131
{
32-
assert(type.id()==ID_union);
32+
PRECONDITION(type.id()==ID_union);
3333
}
3434

3535
/*******************************************************************\
@@ -52,7 +52,7 @@ union_abstract_objectt::union_abstract_objectt(
5252
const typet &type, bool top, bool bottom):
5353
abstract_objectt(type, top, bottom)
5454
{
55-
assert(type.id()==ID_union);
55+
PRECONDITION(type.id()==ID_union);
5656
}
5757

5858
/*******************************************************************\
@@ -74,7 +74,7 @@ union_abstract_objectt::union_abstract_objectt(
7474
const namespacet &ns):
7575
abstract_objectt(expr, environment, ns)
7676
{
77-
assert(ns.follow(expr.type()).id()==ID_union);
77+
PRECONDITION(ns.follow(expr.type()).id()==ID_union);
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)