17
17
18
18
#include < cassert>
19
19
20
- #include < util/prefix.h>
21
- #include < util/cprover_prefix.h>
22
20
#include < util/base_type.h>
21
+ #include < util/cprover_prefix.h>
22
+ #include < util/expr_util.h>
23
+ #include < util/invariant.h>
24
+ #include < util/prefix.h>
23
25
#include < util/std_code.h>
24
26
#include < util/std_expr.h>
25
- #include < util/expr_util.h>
26
27
27
28
#include " remove_skip.h"
28
29
#include " goto_inline.h"
@@ -34,8 +35,8 @@ void goto_inlinet::parameter_assignments(
34
35
const exprt::operandst &arguments, // arguments of call
35
36
goto_programt &dest)
36
37
{
37
- assert (target->is_function_call ());
38
- assert (dest.empty ());
38
+ PRECONDITION (target->is_function_call ());
39
+ PRECONDITION (dest.empty ());
39
40
40
41
const source_locationt &source_location=target->source_location ;
41
42
@@ -160,8 +161,8 @@ void goto_inlinet::parameter_destruction(
160
161
const code_typet &code_type, // type of called function
161
162
goto_programt &dest)
162
163
{
163
- assert (target->is_function_call ());
164
- assert (dest.empty ());
164
+ PRECONDITION (target->is_function_call ());
165
+ PRECONDITION (dest.empty ());
165
166
166
167
const source_locationt &source_location=target->source_location ;
167
168
@@ -204,51 +205,6 @@ void goto_inlinet::replace_return(
204
205
{
205
206
if (it->is_return ())
206
207
{
207
- #if 0
208
- if(lhs.is_not_nil())
209
- {
210
- if(it->code.operands().size()!=1)
211
- {
212
- error().source_location=it->code.find_source_location();
213
- str << "return expects one operand!";
214
- warning_msg();
215
- continue;
216
- }
217
-
218
- goto_programt tmp;
219
- goto_programt::targett assignment=tmp.add_instruction(ASSIGN);
220
-
221
- code_assignt code_assign(lhs, it->code.op0());
222
-
223
- // this may happen if the declared return type at the call site
224
- // differs from the defined return type
225
- if(code_assign.lhs().type()!=
226
- code_assign.rhs().type())
227
- code_assign.rhs().make_typecast(code_assign.lhs().type());
228
-
229
- assignment->code=code_assign;
230
- assignment->source_location=it->source_location;
231
- assignment->function=it->function;
232
-
233
- dest.insert_before_swap(it, *assignment);
234
- it++;
235
- }
236
- else if(!it->code.operands().empty())
237
- {
238
- goto_programt tmp;
239
- goto_programt::targett expression=tmp.add_instruction(OTHER);
240
-
241
- expression->code=codet(ID_expression);
242
- expression->code.move_to_operands(it->code.op0());
243
- expression->source_location=it->source_location;
244
- expression->function=it->function;
245
-
246
- dest.insert_before_swap(it, *expression);
247
- it++;
248
- }
249
-
250
- it->make_goto(--dest.instructions.end());
251
- #else
252
208
if (lhs.is_not_nil ())
253
209
{
254
210
if (it->code .operands ().size ()!=1 )
@@ -280,7 +236,6 @@ void goto_inlinet::replace_return(
280
236
it->type =OTHER;
281
237
it++;
282
238
}
283
- #endif
284
239
}
285
240
}
286
241
}
@@ -327,9 +282,9 @@ void goto_inlinet::insert_function_body(
327
282
const symbol_exprt &function,
328
283
const exprt::operandst &arguments)
329
284
{
330
- assert (target->is_function_call ());
331
- assert (!dest.empty ());
332
- assert (goto_function.body_available ());
285
+ PRECONDITION (target->is_function_call ());
286
+ PRECONDITION (!dest.empty ());
287
+ PRECONDITION (goto_function.body_available ());
333
288
334
289
const irep_idt identifier=function.get_identifier ();
335
290
@@ -338,7 +293,9 @@ void goto_inlinet::insert_function_body(
338
293
inline_log.copy_from (goto_function.body , body);
339
294
340
295
goto_programt::instructiont &end=body.instructions .back ();
341
- assert (end.is_end_function ());
296
+ DATA_INVARIANT (
297
+ end.is_end_function (),
298
+ " final instruction of a function must be an END_FUNCTION" );
342
299
end.type =LOCATION;
343
300
344
301
if (adjust_function)
@@ -367,7 +324,9 @@ void goto_inlinet::insert_function_body(
367
324
t_it=goto_function.body .instructions .begin ();
368
325
unsigned begin_location_number=t_it->location_number ;
369
326
t_it=--goto_function.body .instructions .end ();
370
- assert (t_it->is_end_function ());
327
+ DATA_INVARIANT (
328
+ t_it->is_end_function (),
329
+ " final instruction of a function must be an END_FUNCTION" );
371
330
unsigned end_location_number=t_it->location_number ;
372
331
373
332
unsigned call_location_number=target->location_number ;
@@ -426,8 +385,8 @@ void goto_inlinet::insert_function_nobody(
426
385
const symbol_exprt &function,
427
386
const exprt::operandst &arguments)
428
387
{
429
- assert (target->is_function_call ());
430
- assert (!dest.empty ());
388
+ PRECONDITION (target->is_function_call ());
389
+ PRECONDITION (!dest.empty ());
431
390
432
391
const irep_idt identifier=function.get_identifier ();
433
392
@@ -479,9 +438,9 @@ void goto_inlinet::expand_function_call(
479
438
const bool force_full,
480
439
goto_programt::targett target)
481
440
{
482
- assert (target->is_function_call ());
483
- assert (!dest.empty ());
484
- assert (!transitive || inline_map.empty ());
441
+ PRECONDITION (target->is_function_call ());
442
+ PRECONDITION (!dest.empty ());
443
+ PRECONDITION (!transitive || inline_map.empty ());
485
444
486
445
#ifdef DEBUG
487
446
std::cout << " Expanding call:\n " ;
@@ -600,7 +559,7 @@ void goto_inlinet::get_call(
600
559
exprt &function,
601
560
exprt::operandst &arguments)
602
561
{
603
- assert (it->is_function_call ());
562
+ PRECONDITION (it->is_function_call ());
604
563
605
564
const code_function_callt &call=to_code_function_call (it->code );
606
565
@@ -613,12 +572,12 @@ void goto_inlinet::goto_inline(
613
572
const inline_mapt &inline_map,
614
573
const bool force_full)
615
574
{
616
- assert (check_inline_map (inline_map));
575
+ PRECONDITION (check_inline_map (inline_map));
617
576
618
577
Forall_goto_functions (f_it, goto_functions)
619
578
{
620
579
const irep_idt identifier=f_it->first ;
621
- assert (!identifier.empty ());
580
+ DATA_INVARIANT (!identifier.empty (), " function name must not be empty " );
622
581
goto_functiont &goto_function=f_it->second ;
623
582
624
583
if (!goto_function.body_available ())
@@ -649,14 +608,14 @@ void goto_inlinet::goto_inline_nontransitive(
649
608
const inline_mapt &inline_map,
650
609
const bool force_full)
651
610
{
652
- assert (goto_function.body_available ());
611
+ PRECONDITION (goto_function.body_available ());
653
612
654
613
finished_sett::const_iterator f_it=finished_set.find (identifier);
655
614
656
615
if (f_it!=finished_set.end ())
657
616
return ;
658
617
659
- assert (check_inline_map (identifier, inline_map));
618
+ PRECONDITION (check_inline_map (identifier, inline_map));
660
619
661
620
goto_programt &goto_program=goto_function.body ;
662
621
@@ -700,19 +659,23 @@ const goto_inlinet::goto_functiont &goto_inlinet::goto_inline_transitive(
700
659
const goto_functiont &goto_function,
701
660
const bool force_full)
702
661
{
703
- assert (goto_function.body_available ());
662
+ PRECONDITION (goto_function.body_available ());
704
663
705
664
cachet::const_iterator c_it=cache.find (identifier);
706
665
707
666
if (c_it!=cache.end ())
708
667
{
709
668
const goto_functiont &cached=c_it->second ;
710
- assert (cached.body_available ());
669
+ DATA_INVARIANT (
670
+ cached.body_available (),
671
+ " body of cached functions must be available" );
711
672
return cached;
712
673
}
713
674
714
675
goto_functiont &cached=cache[identifier];
715
- assert (cached.body .empty ());
676
+ INVARIANT (
677
+ cached.body .empty (),
678
+ " body of new function in cache must be empty" );
716
679
717
680
progress () << " Creating copy of " << identifier << eom;
718
681
progress () << " Number of instructions: "
@@ -772,7 +735,7 @@ bool goto_inlinet::check_inline_map(
772
735
goto_functionst::function_mapt::const_iterator f_it=
773
736
goto_functions.function_map .find (identifier);
774
737
775
- assert (f_it!=goto_functions.function_map .end ());
738
+ PRECONDITION (f_it!=goto_functions.function_map .end ());
776
739
777
740
inline_mapt::const_iterator im_it=inline_map.find (identifier);
778
741
@@ -824,11 +787,11 @@ void goto_inlinet::output_inline_map(
824
787
std::ostream &out,
825
788
const inline_mapt &inline_map)
826
789
{
827
- assert (check_inline_map (inline_map));
790
+ PRECONDITION (check_inline_map (inline_map));
828
791
829
792
for (const auto &it : inline_map)
830
793
{
831
- const irep_idt id=it.first ;
794
+ const irep_idt & id=it.first ;
832
795
const call_listt &call_list=it.second ;
833
796
834
797
out << " Function: " << id << " \n " ;
@@ -842,7 +805,7 @@ void goto_inlinet::output_inline_map(
842
805
!call_list.empty ())
843
806
{
844
807
const goto_functiont &goto_function=f_it->second ;
845
- assert (goto_function.body_available ());
808
+ PRECONDITION (goto_function.body_available ());
846
809
847
810
const goto_programt &goto_program=goto_function.body ;
848
811
@@ -903,12 +866,12 @@ void goto_inlinet::goto_inline_logt::add_segment(
903
866
const unsigned call_location_number,
904
867
const irep_idt function)
905
868
{
906
- assert (!goto_program.empty ());
907
- assert (!function.empty ());
908
- assert (end_location_number>=begin_location_number);
869
+ PRECONDITION (!goto_program.empty ());
870
+ PRECONDITION (!function.empty ());
871
+ PRECONDITION (end_location_number>=begin_location_number);
909
872
910
873
goto_programt::const_targett start=goto_program.instructions .begin ();
911
- assert (log_map.find (start)==log_map.end ());
874
+ PRECONDITION (log_map.find (start)==log_map.end ());
912
875
913
876
goto_programt::const_targett end=goto_program.instructions .end ();
914
877
end--;
@@ -927,7 +890,7 @@ void goto_inlinet::goto_inline_logt::copy_from(
927
890
const goto_programt &from,
928
891
const goto_programt &to)
929
892
{
930
- assert (from.instructions .size ()==to.instructions .size ());
893
+ PRECONDITION (from.instructions .size ()==to.instructions .size ());
931
894
932
895
goto_programt::const_targett it1=from.instructions .begin ();
933
896
goto_programt::const_targett it2=to.instructions .begin ();
0 commit comments