13
13
#include " remove_virtual_functions.h"
14
14
#include " class_hierarchy.h"
15
15
#include " class_identifier.h"
16
-
17
- #include < goto-programs/ resolve_inherited_component.h>
16
+ # include " remove_skip.h "
17
+ #include " resolve_inherited_component.h"
18
18
19
19
#include < util/c_types.h>
20
20
#include < util/prefix.h>
@@ -31,7 +31,7 @@ class remove_virtual_functionst
31
31
32
32
bool remove_virtual_functions (goto_programt &goto_program);
33
33
34
- void remove_virtual_function (
34
+ goto_programt::targett remove_virtual_function (
35
35
goto_programt &goto_program,
36
36
goto_programt::targett target,
37
37
const dispatch_table_entriest &functions,
@@ -45,7 +45,7 @@ class remove_virtual_functionst
45
45
46
46
const class_hierarchyt &class_hierarchy;
47
47
48
- void remove_virtual_function (
48
+ goto_programt::targett remove_virtual_function (
49
49
goto_programt &goto_program,
50
50
goto_programt::targett target);
51
51
typedef std::function<
@@ -73,7 +73,7 @@ remove_virtual_functionst::remove_virtual_functionst(
73
73
{
74
74
}
75
75
76
- void remove_virtual_functionst::remove_virtual_function (
76
+ goto_programt::targett remove_virtual_functionst::remove_virtual_function (
77
77
goto_programt &goto_program,
78
78
goto_programt::targett target)
79
79
{
@@ -91,7 +91,7 @@ void remove_virtual_functionst::remove_virtual_function(
91
91
dispatch_table_entriest functions;
92
92
get_functions (function, functions);
93
93
94
- remove_virtual_function (
94
+ return remove_virtual_function (
95
95
goto_program,
96
96
target,
97
97
functions,
@@ -120,7 +120,7 @@ static void create_static_function_call(
120
120
call.arguments ()[0 ].make_typecast (need_type);
121
121
}
122
122
123
- void remove_virtual_functionst::remove_virtual_function (
123
+ goto_programt::targett remove_virtual_functionst::remove_virtual_function (
124
124
goto_programt &goto_program,
125
125
goto_programt::targett target,
126
126
const dispatch_table_entriest &functions,
@@ -132,24 +132,30 @@ void remove_virtual_functionst::remove_virtual_function(
132
132
const code_function_callt &code=
133
133
to_code_function_call (target->code );
134
134
135
+ goto_programt::targett next_target = std::next (target);
136
+
135
137
if (functions.empty ())
136
138
{
137
139
target->make_skip ();
138
- return ; // give up
140
+ remove_skip (goto_program, target, next_target);
141
+ return next_target; // give up
139
142
}
140
143
141
144
// only one option?
142
145
if (functions.size ()==1 &&
143
146
fallback_action==virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION)
144
147
{
145
148
if (functions.begin ()->symbol_expr ==symbol_exprt ())
149
+ {
146
150
target->make_skip ();
151
+ remove_skip (goto_program, target, next_target);
152
+ }
147
153
else
148
154
{
149
155
create_static_function_call (
150
156
to_code_function_call (target->code ), functions.front ().symbol_expr , ns);
151
157
}
152
- return ;
158
+ return next_target ;
153
159
}
154
160
155
161
const auto &vcall_source_loc=target->source_location ;
@@ -283,13 +289,14 @@ void remove_virtual_functionst::remove_virtual_function(
283
289
it->source_location .set_comment (comment);
284
290
}
285
291
286
- goto_programt::targett next_target=target;
287
- next_target++;
288
-
289
292
goto_program.destructive_insert (next_target, new_code);
290
293
291
294
// finally, kill original invocation
292
295
target->make_skip ();
296
+
297
+ remove_skip (goto_program, target, next_target);
298
+
299
+ return next_target;
293
300
}
294
301
295
302
// / Used by get_functions to track the most-derived parent that provides an
@@ -472,23 +479,29 @@ bool remove_virtual_functionst::remove_virtual_functions(
472
479
{
473
480
bool did_something=false ;
474
481
475
- Forall_goto_program_instructions (target, goto_program)
482
+ for (goto_programt::instructionst::iterator
483
+ target = goto_program.instructions .begin ();
484
+ target != goto_program.instructions .end ();
485
+ ) // no ++target
486
+ {
476
487
if (target->is_function_call ())
477
488
{
478
489
const code_function_callt &code=
479
490
to_code_function_call (target->code );
480
491
481
492
if (code.function ().id ()==ID_virtual_function)
482
493
{
483
- remove_virtual_function (goto_program, target);
494
+ target = remove_virtual_function (goto_program, target);
484
495
did_something=true ;
496
+ continue ;
485
497
}
486
498
}
487
499
500
+ ++target;
501
+ }
502
+
488
503
if (did_something)
489
- {
490
504
goto_program.update ();
491
- }
492
505
493
506
return did_something;
494
507
}
@@ -536,7 +549,7 @@ void remove_virtual_functions(goto_model_functiont &function)
536
549
rvf.remove_virtual_functions (function.get_goto_function ().body );
537
550
}
538
551
539
- void remove_virtual_function (
552
+ goto_programt::targett remove_virtual_function (
540
553
symbol_tablet &symbol_table,
541
554
goto_programt &goto_program,
542
555
goto_programt::targett instruction,
@@ -547,18 +560,22 @@ void remove_virtual_function(
547
560
class_hierarchy (symbol_table);
548
561
remove_virtual_functionst rvf (symbol_table, class_hierarchy);
549
562
550
- rvf.remove_virtual_function (
563
+ goto_programt::targett next = rvf.remove_virtual_function (
551
564
goto_program, instruction, dispatch_table, fallback_action);
565
+
566
+ goto_program.update ();
567
+
568
+ return next;
552
569
}
553
570
554
- void remove_virtual_function (
571
+ goto_programt::targett remove_virtual_function (
555
572
goto_modelt &goto_model,
556
573
goto_programt &goto_program,
557
574
goto_programt::targett instruction,
558
575
const dispatch_table_entriest &dispatch_table,
559
576
virtual_dispatch_fallback_actiont fallback_action)
560
577
{
561
- remove_virtual_function (
578
+ return remove_virtual_function (
562
579
goto_model.symbol_table ,
563
580
goto_program,
564
581
instruction,
0 commit comments