Skip to content

Commit 25c4445

Browse files
committed
fixup! Replace assert(...) by macros from invariant.h
1 parent 5911a93 commit 25c4445

6 files changed

+76
-77
lines changed

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,18 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
356356
// copy the value, we may need to adjust it
357357
exprt value=*init_it;
358358

359-
assert(!designator.empty());
359+
PRECONDITION(!designator.empty());
360360

361361
if(value.id()==ID_designated_initializer)
362362
{
363-
assert(value.operands().size()==1);
363+
PRECONDITION(value.operands().size()==1);
364364

365365
designator=
366366
make_designator(
367367
designator.front().type,
368368
static_cast<const exprt &>(value.find(ID_designator)));
369369

370-
assert(!designator.empty());
370+
CHECK_RETURN(!designator.empty());
371371

372372
// discard the return value
373373
do_designated_initializer(
@@ -587,7 +587,7 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
587587
else
588588
*dest=do_initializer_rec(value, type, force_constant);
589589

590-
assert(full_type==follow(dest->type()));
590+
DATA_INVARIANT(full_type==follow(dest->type()), "matching types");
591591

592592
return ++init_it; // done
593593
}
@@ -655,10 +655,10 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
655655
}
656656
}
657657

658-
assert(full_type.id()==ID_struct ||
658+
DATA_INVARIANT(full_type.id()==ID_struct ||
659659
full_type.id()==ID_union ||
660660
full_type.id()==ID_array ||
661-
full_type.id()==ID_vector);
661+
full_type.id()==ID_vector, "full type must be composite");
662662

663663
// we are initializing a compound type, and enter it!
664664
// this may change the type, full_type might not be valid any more
@@ -709,7 +709,7 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
709709

710710
void c_typecheck_baset::increment_designator(designatort &designator)
711711
{
712-
assert(!designator.empty());
712+
PRECONDITION(!designator.empty());
713713

714714
while(true)
715715
{
@@ -730,7 +730,7 @@ void c_typecheck_baset::increment_designator(designatort &designator)
730730
to_struct_type(full_type);
731731
const struct_typet::componentst &components=
732732
struct_type.components();
733-
assert(components.size()==entry.size);
733+
DATA_INVARIANT(components.size()==entry.size, "matching component numbers");
734734

735735
// we skip over any padding or code
736736
// we also skip over anonymous members
@@ -757,15 +757,15 @@ void c_typecheck_baset::increment_designator(designatort &designator)
757757
// pop entry
758758
designator.pop_entry();
759759

760-
assert(!designator.empty());
760+
INVARIANT(!designator.empty(), "designator had more than one entry");
761761
}
762762
}
763763

764764
designatort c_typecheck_baset::make_designator(
765765
const typet &src_type,
766766
const exprt &src)
767767
{
768-
assert(!src.operands().empty());
768+
PRECONDITION(!src.operands().empty());
769769

770770
typet type=src_type;
771771
designatort designator;
@@ -904,7 +904,7 @@ designatort c_typecheck_baset::make_designator(
904904
designator.push_entry(entry);
905905
}
906906

907-
assert(!designator.empty());
907+
INVARIANT(!designator.empty(), "expected an entry to be added");
908908

909909
return designator;
910910
}
@@ -914,7 +914,7 @@ exprt c_typecheck_baset::do_initializer_list(
914914
const typet &type,
915915
bool force_constant)
916916
{
917-
assert(value.id()==ID_initializer_list);
917+
PRECONDITION(value.id()==ID_initializer_list);
918918

919919
const typet &full_type=follow(type);
920920

src/cpp/cpp_instantiate_template.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const symbolt &cpp_typecheckt::class_template_symbol(
152152
const cpp_template_args_tct &full_template_args)
153153
{
154154
// we should never get 'unassigned' here
155-
assert(!full_template_args.has_unassigned());
155+
PRECONDITION(!full_template_args.has_unassigned());
156156

157157
// do we have args?
158158
if(full_template_args.arguments().empty())
@@ -283,8 +283,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
283283
bool specialization_given=specialization.is_not_nil();
284284

285285
// we should never get 'unassigned' here
286-
assert(!specialization_template_args.has_unassigned());
287-
assert(!full_template_args.has_unassigned());
286+
DATA_INVARIANT(!specialization_template_args.has_unassigned(), "should never get 'unassigned' here");
287+
DATA_INVARIANT(!full_template_args.has_unassigned(), "should never get 'unassigned' here");
288288

289289
#ifdef DEBUG
290290
std::cout << "A: <";
@@ -368,8 +368,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
368368
// It has already been instantiated!
369369
const cpp_idt &cpp_id = **id_set.begin();
370370

371-
assert(cpp_id.id_class == cpp_idt::id_classt::CLASS ||
372-
cpp_id.id_class == cpp_idt::id_classt::SYMBOL);
371+
DATA_INVARIANT(cpp_id.id_class == cpp_idt::id_classt::CLASS ||
372+
cpp_id.id_class == cpp_idt::id_classt::SYMBOL, "id must be class or symbol");
373373

374374
const symbolt &symb=lookup(cpp_id.identifier);
375375

@@ -482,7 +482,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
482482
{
483483
symbolt &symb = symbol_table.get_writeable_ref(class_name);
484484

485-
assert(new_decl.declarators().size() == 1);
485+
PRECONDITION(new_decl.declarators().size() == 1);
486486

487487
if(new_decl.member_spec().is_virtual())
488488
{
@@ -513,8 +513,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
513513
bool is_static=new_decl.storage_spec().is_static();
514514
irep_idt access = new_decl.get(ID_C_access);
515515

516-
assert(!access.empty());
517-
assert(symb.type.id()==ID_struct);
516+
CHECK_RETURN(!access.empty());
517+
PRECONDITION(symb.type.id()==ID_struct);
518518

519519
typecheck_compound_declarator(
520520
symb,
@@ -532,7 +532,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
532532
// not a class template, not a class template method,
533533
// it must be a function template!
534534

535-
assert(new_decl.declarators().size()==1);
535+
PRECONDITION(new_decl.declarators().size()==1);
536536

537537
convert_non_template_declaration(new_decl);
538538

src/cpp/cpp_typecheck.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ const struct_typet &cpp_typecheckt::this_struct_type()
6767
const exprt &this_expr=
6868
cpp_scopes.current_scope().this_expr;
6969

70-
assert(this_expr.is_not_nil());
71-
assert(this_expr.type().id()==ID_pointer);
70+
CHECK_RETURN(this_expr.is_not_nil());
71+
CHECK_RETURN(this_expr.type().id()==ID_pointer);
7272

7373
const typet &t = follow(to_pointer_type(this_expr.type()).base_type());
74-
assert(t.id()==ID_struct);
74+
CHECK_RETURN(t.id()==ID_struct);
7575
return to_struct_type(t);
7676
}
7777

@@ -164,9 +164,9 @@ void cpp_typecheckt::static_and_dynamic_initialization()
164164
if(cpp_is_pod(symbol.type))
165165
continue;
166166

167-
assert(symbol.is_static_lifetime);
168-
assert(!symbol.is_type);
169-
assert(symbol.type.id()!=ID_code);
167+
DATA_INVARIANT(symbol.is_static_lifetime, "should be static");
168+
DATA_INVARIANT(!symbol.is_type, "should not be a type");
169+
DATA_INVARIANT(symbol.type.id()!=ID_code, "should not be code");
170170

171171
exprt symbol_expr=cpp_symbol_expr(symbol);
172172

@@ -228,7 +228,7 @@ void cpp_typecheckt::do_not_typechecked()
228228
symbol.value.id() == ID_cpp_not_typechecked &&
229229
symbol.value.get_bool(ID_is_used))
230230
{
231-
assert(symbol.type.id()==ID_code);
231+
DATA_INVARIANT(symbol.type.id()==ID_code, "must be code");
232232
exprt value = symbol.value;
233233

234234
if(symbol.base_name=="operator=")

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
312312

313313
if(is_cast_operator)
314314
{
315-
assert(declarator.name().get_sub().size()==2 &&
315+
PRECONDITION(declarator.name().get_sub().size()==2 &&
316316
declarator.name().get_sub().front().id()==ID_operator);
317317

318318
typet type=static_cast<typet &>(declarator.name().get_sub()[1]);
@@ -522,9 +522,9 @@ void cpp_typecheckt::typecheck_compound_declarator(
522522
{
523523
is_virtual=true;
524524
const code_typet &code_type=to_code_type(comp.type());
525-
assert(!code_type.parameters().empty());
525+
DATA_INVARIANT(!code_type.parameters().empty(), "must have parameters");
526526
const typet &pointer_type=code_type.parameters()[0].type();
527-
assert(pointer_type.id()==ID_pointer);
527+
DATA_INVARIANT(pointer_type.id()==ID_pointer, "this must be pointer");
528528
virtual_bases.insert(
529529
to_pointer_type(pointer_type).base_type().get(ID_identifier));
530530
}
@@ -951,7 +951,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
951951
// enter scope of compound
952952
cpp_scopes.set_scope(symbol.name);
953953

954-
assert(symbol.type.id()==ID_struct ||
954+
PRECONDITION(symbol.type.id()==ID_struct ||
955955
symbol.type.id()==ID_union);
956956

957957
struct_union_typet &type=
@@ -1195,7 +1195,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
11951195
// build declaration
11961196
cpp_declarationt cpctor;
11971197
default_cpctor(symbol, cpctor);
1198-
assert(cpctor.declarators().size()==1);
1198+
CHECK_RETURN(cpctor.declarators().size()==1);
11991199

12001200
exprt value(ID_cpp_not_typechecked);
12011201
value.copy_to_operands(cpctor.declarators()[0].value());
@@ -1213,7 +1213,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
12131213
// build declaration
12141214
cpp_declarationt assignop;
12151215
default_assignop(symbol, assignop);
1216-
assert(assignop.declarators().size()==1);
1216+
CHECK_RETURN(assignop.declarators().size()==1);
12171217

12181218
// The value will be typechecked only if the operator
12191219
// is actually used
@@ -1497,7 +1497,7 @@ bool cpp_typecheckt::get_component(
14971497
{
14981498
const typet &followed_type=follow(object.type());
14991499

1500-
assert(followed_type.id()==ID_struct ||
1500+
PRECONDITION(followed_type.id()==ID_struct ||
15011501
followed_type.id()==ID_union);
15021502

15031503
struct_union_typet final_type=
@@ -1599,7 +1599,7 @@ bool cpp_typecheckt::check_component_access(
15991599
if(access==ID_public)
16001600
return false; // ok
16011601

1602-
assert(access==ID_private ||
1602+
PRECONDITION(access==ID_private ||
16031603
access==ID_protected);
16041604

16051605
const irep_idt &struct_identifier=
@@ -1703,8 +1703,8 @@ void cpp_typecheckt::make_ptr_typecast(
17031703
{
17041704
typet src_type=expr.type();
17051705

1706-
assert(src_type.id()== ID_pointer);
1707-
assert(dest_type.id()== ID_pointer);
1706+
PRECONDITION(src_type.id()== ID_pointer);
1707+
PRECONDITION(dest_type.id()== ID_pointer);
17081708

17091709
const struct_typet &src_struct = to_struct_type(
17101710
static_cast<const typet &>(follow(to_pointer_type(src_type).base_type())));

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool cpp_typecheckt::standard_conversion_lvalue_to_rvalue(
4949
const exprt &expr,
5050
exprt &new_expr) const
5151
{
52-
assert(expr.get_bool(ID_C_lvalue));
52+
PRECONDITION(expr.get_bool(ID_C_lvalue));
5353

5454
if(expr.type().id() == ID_code)
5555
return false;
@@ -80,7 +80,7 @@ bool cpp_typecheckt::standard_conversion_array_to_pointer(
8080
const exprt &expr,
8181
exprt &new_expr) const
8282
{
83-
assert(expr.type().id()==ID_array);
83+
PRECONDITION(expr.type().id()==ID_array);
8484

8585
index_exprt index(expr, from_integer(0, c_index_type()));
8686

@@ -577,13 +577,13 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
577577
to_pointer_type(expr.type()).base_type().id() == ID_code)
578578
{
579579
code_typet code1=to_code_type(expr.type().subtype());
580-
assert(!code1.parameters().empty());
580+
DATA_INVARIANT(!code1.parameters().empty(), "must have parameters");
581581
code_typet::parametert this1=code1.parameters()[0];
582582
INVARIANT(this1.get_this(), "first parameter should be `this'");
583583
code1.parameters().erase(code1.parameters().begin());
584584

585585
code_typet code2=to_code_type(type.subtype());
586-
assert(!code2.parameters().empty());
586+
DATA_INVARIANT(!code2.parameters().empty(), "must have parameters");
587587
code_typet::parametert this2=code2.parameters()[0];
588588
INVARIANT(this2.get_this(), "first parameter should be `this'");
589589
code2.parameters().erase(code2.parameters().begin());
@@ -683,7 +683,7 @@ bool cpp_typecheckt::standard_conversion_sequence(
683683
exprt &new_expr,
684684
unsigned &rank)
685685
{
686-
assert(!is_reference(expr.type()) && !is_reference(type));
686+
PRECONDITION(!is_reference(expr.type()) && !is_reference(type));
687687

688688
exprt curr_expr=expr;
689689

@@ -859,8 +859,8 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
859859
exprt &new_expr,
860860
unsigned &rank)
861861
{
862-
assert(!is_reference(expr.type()));
863-
assert(!is_reference(type));
862+
PRECONDITION(!is_reference(expr.type()));
863+
PRECONDITION(!is_reference(type));
864864

865865
const typet &from=follow(expr.type());
866866
const typet &to=follow(type);
@@ -982,9 +982,9 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
982982
uninitialized_typet{},
983983
expr.source_location());
984984
typecheck_side_effect_function_call(ctor_expr);
985+
CHECK_RETURN(ctor_expr.get(ID_statement)==ID_temporary_object);
985986

986987
new_expr.swap(ctor_expr);
987-
assert(new_expr.get(ID_statement)==ID_temporary_object);
988988

989989
if(to.get_bool(ID_C_constant))
990990
new_expr.type().set(ID_C_constant, true);
@@ -1116,8 +1116,8 @@ bool cpp_typecheckt::reference_related(
11161116
const exprt &expr,
11171117
const typet &type) const
11181118
{
1119-
assert(is_reference(type));
1120-
assert(!is_reference(expr.type()));
1119+
PRECONDITION(is_reference(type));
1120+
PRECONDITION(!is_reference(expr.type()));
11211121

11221122
typet from=follow(expr.type());
11231123
typet to=follow(type.subtype());
@@ -1154,8 +1154,8 @@ bool cpp_typecheckt::reference_compatible(
11541154
const typet &type,
11551155
unsigned &rank) const
11561156
{
1157-
assert(is_reference(type));
1158-
assert(!is_reference(expr.type()));
1157+
PRECONDITION(is_reference(type));
1158+
PRECONDITION(!is_reference(expr.type()));
11591159

11601160
if(!reference_related(expr, type))
11611161
return false;
@@ -1218,8 +1218,8 @@ bool cpp_typecheckt::reference_binding(
12181218
exprt &new_expr,
12191219
unsigned &rank)
12201220
{
1221-
assert(is_reference(type));
1222-
assert(!is_reference(expr.type()));
1221+
PRECONDITION(is_reference(type));
1222+
PRECONDITION(!is_reference(expr.type()));
12231223

12241224
unsigned backup_rank=rank;
12251225

@@ -1298,7 +1298,7 @@ bool cpp_typecheckt::reference_binding(
12981298
if(!is_reference(component_type.return_type()))
12991299
continue;
13001300

1301-
assert(component_type.parameters().size()==1);
1301+
DATA_INVARIANT(component_type.parameters().size()==1, "exactly one parameter");
13021302

13031303
typet this_type =
13041304
component_type.parameters().front().type();
@@ -1552,7 +1552,7 @@ void cpp_typecheckt::reference_initializer(
15521552
exprt &expr,
15531553
const typet &type)
15541554
{
1555-
assert(is_reference(type));
1555+
PRECONDITION(is_reference(type));
15561556
add_implicit_dereference(expr);
15571557

15581558
unsigned rank=0;
@@ -1572,7 +1572,7 @@ bool cpp_typecheckt::cast_away_constness(
15721572
const typet &t1,
15731573
const typet &t2) const
15741574
{
1575-
assert(t1.id()==ID_pointer && t2.id()==ID_pointer);
1575+
PRECONDITION(t1.id()==ID_pointer && t2.id()==ID_pointer);
15761576
typet nt1=t1;
15771577
typet nt2=t2;
15781578

0 commit comments

Comments
 (0)