Skip to content

Commit fe2efa7

Browse files
Style: Replace assert by appropriate macros
1 parent e36d7d8 commit fe2efa7

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

src/goto-programs/builtin_functions.cpp

+10-50
Original file line numberDiff line numberDiff line change
@@ -569,35 +569,15 @@ void goto_convertt::do_java_new(
569569
const side_effect_exprt &rhs,
570570
goto_programt &dest)
571571
{
572-
if(lhs.is_nil())
573-
{
574-
error().source_location=lhs.find_source_location();
575-
error() << "do_java_new without lhs is yet to be implemented" << eom;
576-
throw 0;
577-
}
578-
572+
PRECONDITION(!lhs.is_nil());
573+
PRECONDITION(rhs.operands().empty());
574+
PRECONDITION(rhs.type().id() == ID_pointer);
579575
source_locationt location=rhs.source_location();
580-
581-
assert(rhs.operands().empty());
582-
583-
if(rhs.type().id()!=ID_pointer)
584-
{
585-
error().source_location=rhs.find_source_location();
586-
error() << "do_java_new returns pointer" << eom;
587-
throw 0;
588-
}
589-
590576
typet object_type=rhs.type().subtype();
591577

592578
// build size expression
593579
exprt object_size=size_of_expr(object_type, ns);
594-
595-
if(object_size.is_nil())
596-
{
597-
error().source_location=rhs.find_source_location();
598-
error() << "do_java_new got nil object_size" << eom;
599-
throw 0;
600-
}
580+
CHECK_RETURN(object_size.is_not_nil());
601581

602582
// we produce a malloc side-effect, which stays
603583
side_effect_exprt malloc_expr(ID_malloc);
@@ -624,36 +604,18 @@ void goto_convertt::do_java_new_array(
624604
const side_effect_exprt &rhs,
625605
goto_programt &dest)
626606
{
627-
if(lhs.is_nil())
628-
{
629-
error().source_location=lhs.find_source_location();
630-
error() << "do_java_new_array without lhs is yet to be implemented"
631-
<< eom;
632-
throw 0;
633-
}
607+
PRECONDITION(!lhs.is_nil()); // do_java_new_array without lhs not implemented
608+
PRECONDITION(rhs.operands().size() >= 1); // one per dimension
609+
PRECONDITION(rhs.type().id() == ID_pointer);
634610

635611
source_locationt location=rhs.source_location();
636-
637-
assert(rhs.operands().size()>=1); // one per dimension
638-
639-
if(rhs.type().id()!=ID_pointer)
640-
{
641-
error().source_location=rhs.find_source_location();
642-
error() << "do_java_new_array returns pointer" << eom;
643-
throw 0;
644-
}
645-
646612
typet object_type=rhs.type().subtype();
613+
PRECONDITION(ns.follow(object_type).id() == ID_struct);
647614

648615
// build size expression
649616
exprt object_size=size_of_expr(object_type, ns);
650617

651-
if(object_size.is_nil())
652-
{
653-
error().source_location=rhs.find_source_location();
654-
error() << "do_java_new_array got nil object_size" << eom;
655-
throw 0;
656-
}
618+
CHECK_RETURN(!object_size.is_nil());
657619

658620
// we produce a malloc side-effect, which stays
659621
side_effect_exprt malloc_expr(ID_malloc);
@@ -664,9 +626,8 @@ void goto_convertt::do_java_new_array(
664626
t_n->code=code_assignt(lhs, malloc_expr);
665627
t_n->source_location=location;
666628

667-
assert(ns.follow(object_type).id()==ID_struct);
668629
const struct_typet &struct_type=to_struct_type(ns.follow(object_type));
669-
assert(struct_type.components().size()==3);
630+
PRECONDITION(struct_type.components().size() == 3);
670631

671632
// Init base class:
672633
dereference_exprt deref(lhs, object_type);
@@ -696,7 +657,6 @@ void goto_convertt::do_java_new_array(
696657
// Allocate a (struct realtype**) instead of a (void**) if possible.
697658
const irept &given_element_type=object_type.find(ID_C_element_type);
698659
typet allocate_data_type;
699-
exprt cast_data_member;
700660
if(given_element_type.is_not_nil())
701661
{
702662
allocate_data_type=

0 commit comments

Comments
 (0)