@@ -13,6 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com
13
13
#include < cctype>
14
14
15
15
#include < util/config.h>
16
+ #include < util/invariant.h>
16
17
#include < util/prefix.h>
17
18
#include < util/suffix.h>
18
19
#include < util/find_symbols.h>
@@ -99,14 +100,14 @@ void dump_ct::operator()(std::ostream &os)
99
100
if ((symbol.type .id ()==ID_union || symbol.type .id ()==ID_struct) &&
100
101
symbol.type .get (ID_tag).empty ())
101
102
{
102
- assert (symbol.is_type );
103
+ PRECONDITION (symbol.is_type );
103
104
symbol.type .set (ID_tag, ID_anonymous);
104
105
tag_added=true ;
105
106
}
106
107
else if (symbol.type .id ()==ID_c_enum &&
107
108
symbol.type .find (ID_tag).get (ID_C_base_name).empty ())
108
109
{
109
- assert (symbol.is_type );
110
+ PRECONDITION (symbol.is_type );
110
111
symbol.type .add (ID_tag).set (ID_C_base_name, ID_anonymous);
111
112
tag_added=true ;
112
113
}
@@ -150,8 +151,8 @@ void dump_ct::operator()(std::ostream &os)
150
151
if ((!tag_added || symbol.is_type ) && ignore (symbol))
151
152
continue ;
152
153
153
- if (! symbols_sorted.insert (name_str).second )
154
- assert ( false );
154
+ bool inserted= symbols_sorted.insert (name_str).second ;
155
+ CHECK_RETURN (inserted );
155
156
}
156
157
157
158
gather_global_typedefs ();
@@ -314,7 +315,7 @@ void dump_ct::convert_compound(
314
315
{
315
316
const symbolt &symbol=
316
317
ns.lookup (to_symbol_type (type).get_identifier ());
317
- assert (symbol.is_type );
318
+ DATA_INVARIANT (symbol.is_type , " symbol expected to be type symbol " );
318
319
319
320
if (!ignore (symbol))
320
321
convert_compound (symbol.type , unresolved, recursive, os);
@@ -323,7 +324,7 @@ void dump_ct::convert_compound(
323
324
{
324
325
const symbolt &symbol=
325
326
ns.lookup (to_c_enum_tag_type (type).get_identifier ());
326
- assert (symbol.is_type );
327
+ DATA_INVARIANT (symbol.is_type , " symbol expected to be type symbol " );
327
328
328
329
if (!ignore (symbol))
329
330
convert_compound (symbol.type , unresolved, recursive, os);
@@ -375,7 +376,7 @@ void dump_ct::convert_compound(
375
376
std::stringstream base_decls;
376
377
forall_irep (parent_it, bases.get_sub ())
377
378
{
378
- assert ( false ) ;
379
+ UNREACHABLE ;
379
380
/*
380
381
assert(parent_it->id() == ID_base);
381
382
assert(parent_it->get(ID_type) == ID_symbol);
@@ -446,7 +447,7 @@ void dump_ct::convert_compound(
446
447
// namespace
447
448
std::string fake_unique_name=" NO/SUCH/NS::" +id2string (comp_name);
448
449
std::string s=make_decl (fake_unique_name, comp.type ());
449
- assert (s.find (" NO/SUCH/NS" )==std::string::npos);
450
+ POSTCONDITION (s.find (" NO/SUCH/NS" )==std::string::npos);
450
451
451
452
if (comp_type.id ()==ID_c_bit_field &&
452
453
to_c_bit_field_type (comp_type).get_width ()==0 )
@@ -484,7 +485,7 @@ void dump_ct::convert_compound(
484
485
struct_body << s;
485
486
}
486
487
else
487
- assert ( false ) ;
488
+ UNREACHABLE ;
488
489
489
490
struct_body << " ;\n " ;
490
491
}
@@ -499,7 +500,7 @@ void dump_ct::convert_compound(
499
500
typedef_str=td_entry->second ;
500
501
std::pair<typedef_mapt::iterator, bool > td_map_entry=
501
502
typedef_map.insert ({typedef_str, typedef_infot (typedef_str)});
502
- assert (!td_map_entry.second );
503
+ PRECONDITION (!td_map_entry.second );
503
504
if (!td_map_entry.first ->second .early )
504
505
td_map_entry.first ->second .type_decl_str =" " ;
505
506
os << " typedef " ;
@@ -508,7 +509,7 @@ void dump_ct::convert_compound(
508
509
os << type_to_string (unresolved_clean);
509
510
if (!base_decls.str ().empty ())
510
511
{
511
- assert (language->id ()==" cpp" );
512
+ PRECONDITION (language->id ()==" cpp" );
512
513
os << " : " << base_decls.str ();
513
514
}
514
515
os << ' \n ' ;
@@ -541,7 +542,7 @@ void dump_ct::convert_compound_enum(
541
542
const typet &type,
542
543
std::ostream &os)
543
544
{
544
- assert (type.id ()==ID_c_enum);
545
+ PRECONDITION (type.id ()==ID_c_enum);
545
546
546
547
const irept &tag=type.find (ID_tag);
547
548
const irep_idt &name=tag.get (ID_C_base_name);
@@ -899,7 +900,7 @@ void dump_ct::cleanup_decl(
899
900
system_headers);
900
901
p2s ();
901
902
902
- assert (b.operands ().size ()==1 );
903
+ POSTCONDITION (b.operands ().size ()==1 );
903
904
decl.swap (b.op0 ());
904
905
}
905
906
@@ -1006,7 +1007,7 @@ void dump_ct::collect_typedefs_rec(
1006
1007
for (const auto &d : local_deps)
1007
1008
{
1008
1009
auto td_entry=typedef_map.find (d);
1009
- assert (td_entry!=typedef_map.end ());
1010
+ PRECONDITION (td_entry!=typedef_map.end ());
1010
1011
td_entry->second .early =true ;
1011
1012
}
1012
1013
}
@@ -1049,7 +1050,7 @@ void dump_ct::gather_global_typedefs()
1049
1050
symbol.location .get_function ().empty ())
1050
1051
{
1051
1052
const irep_idt &typedef_str=symbol.type .get (ID_C_typedef);
1052
- assert (!typedef_str.empty ());
1053
+ PRECONDITION (!typedef_str.empty ());
1053
1054
typedef_types[symbol.type ]=typedef_str;
1054
1055
if (ignore (symbol))
1055
1056
typedef_map.insert ({typedef_str, typedef_infot (typedef_str)});
@@ -1131,14 +1132,14 @@ void dump_ct::dump_typedefs(std::ostream &os) const
1131
1132
1132
1133
// update dependencies
1133
1134
id_sett &f_deps=f_it->second ;
1134
- assert (!f_deps.empty ());
1135
- assert (f_deps.find (t.typedef_name )!=f_deps.end ());
1135
+ PRECONDITION (!f_deps.empty ());
1136
+ PRECONDITION (f_deps.find (t.typedef_name )!=f_deps.end ());
1136
1137
f_deps.erase (t.typedef_name );
1137
1138
1138
1139
if (f_deps.empty ()) // all depenencies done now!
1139
1140
{
1140
1141
const auto td_entry=typedef_map.find (*it);
1141
- assert (td_entry!=typedef_map.end ());
1142
+ PRECONDITION (td_entry!=typedef_map.end ());
1142
1143
to_insert.insert ({id2string (*it), td_entry->second });
1143
1144
forward_deps.erase (*it);
1144
1145
it=r_deps.erase (it);
@@ -1148,7 +1149,7 @@ void dump_ct::dump_typedefs(std::ostream &os) const
1148
1149
}
1149
1150
}
1150
1151
1151
- assert (forward_deps.empty ());
1152
+ POSTCONDITION (forward_deps.empty ());
1152
1153
1153
1154
for (const auto &td : typedefs_sorted)
1154
1155
os << td.type_decl_str << ' \n ' ;
@@ -1190,8 +1191,10 @@ void dump_ct::convert_global_variable(
1190
1191
it=syms.begin ();
1191
1192
it!=syms.end ();
1192
1193
++it)
1193
- if (!symbols_sorted.insert (id2string (*it)).second )
1194
- assert (false );
1194
+ {
1195
+ bool inserted=symbols_sorted.insert (id2string (*it)).second ;
1196
+ CHECK_RETURN (inserted);
1197
+ }
1195
1198
1196
1199
for (std::set<std::string>::const_iterator
1197
1200
it=symbols_sorted.begin ();
@@ -1215,7 +1218,7 @@ void dump_ct::convert_global_variable(
1215
1218
1216
1219
std::list<irep_idt> empty_static, empty_types;
1217
1220
cleanup_decl (d, empty_static, empty_types);
1218
- assert (empty_static.empty ());
1221
+ CHECK_RETURN (empty_static.empty ());
1219
1222
os << expr_to_string (d) << ' \n ' ;
1220
1223
}
1221
1224
}
@@ -1391,7 +1394,7 @@ void dump_ct::insert_local_static_decls(
1391
1394
{
1392
1395
local_static_declst::const_iterator d_it=
1393
1396
local_static_decls.find (*it);
1394
- assert (d_it!=local_static_decls.end ());
1397
+ PRECONDITION (d_it!=local_static_decls.end ());
1395
1398
1396
1399
code_declt d=d_it->second ;
1397
1400
std::list<irep_idt> redundant;
@@ -1404,7 +1407,7 @@ void dump_ct::insert_local_static_decls(
1404
1407
// within an if(false) { ... } block
1405
1408
if (find_block_position_rec (*it, b, dest_ptr, before))
1406
1409
{
1407
- assert (dest_ptr!=0 );
1410
+ CHECK_RETURN (dest_ptr!=0 );
1408
1411
dest_ptr->operands ().insert (before, d);
1409
1412
}
1410
1413
}
@@ -1441,7 +1444,7 @@ void dump_ct::insert_local_type_decls(
1441
1444
// has been removed by cleanup operations
1442
1445
if (find_block_position_rec (*it, b, dest_ptr, before))
1443
1446
{
1444
- assert (dest_ptr!=0 );
1447
+ CHECK_RETURN (dest_ptr!=0 );
1445
1448
dest_ptr->operands ().insert (before, skip);
1446
1449
}
1447
1450
}
@@ -1465,7 +1468,7 @@ void dump_ct::cleanup_expr(exprt &expr)
1465
1468
exprt::operandst old_ops;
1466
1469
old_ops.swap (expr.operands ());
1467
1470
1468
- assert (old_components.size ()==old_ops.size ());
1471
+ PRECONDITION (old_components.size ()==old_ops.size ());
1469
1472
exprt::operandst::iterator o_it=old_ops.begin ();
1470
1473
for (struct_union_typet::componentst::const_iterator
1471
1474
it=old_components.begin ();
@@ -1507,7 +1510,7 @@ void dump_ct::cleanup_expr(exprt &expr)
1507
1510
const struct_union_typet::componentt &comp=
1508
1511
u_type_f.get_component (u.get_component_name ());
1509
1512
const typet &u_op_type=comp.type ();
1510
- assert (u_op_type.id ()==ID_pointer);
1513
+ PRECONDITION (u_op_type.id ()==ID_pointer);
1511
1514
1512
1515
typecast_exprt tc (u.op (), u_op_type);
1513
1516
expr.swap (tc);
@@ -1615,8 +1618,9 @@ void dump_ct::cleanup_type(typet &type)
1615
1618
if (type.id ()==ID_array)
1616
1619
cleanup_expr (to_array_type (type).size ());
1617
1620
1618
- assert ((type.id ()!=ID_union && type.id ()!=ID_struct) ||
1619
- !type.get (ID_tag).empty ());
1621
+ POSTCONDITION (
1622
+ (type.id ()!=ID_union && type.id ()!=ID_struct) ||
1623
+ !type.get (ID_tag).empty ());
1620
1624
}
1621
1625
1622
1626
std::string dump_ct::type_to_string (const typet &type)
0 commit comments