Skip to content

Commit 1eb1df6

Browse files
Merge pull request #2786 from LAJW/lajw/document-remove-virtual-functions
Document remove_virtual_functions [DOC-85]
2 parents 61b202a + f14b163 commit 1eb1df6

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ remove_virtual_functionst::remove_virtual_functionst(
7272
{
7373
}
7474

75+
/// Replace specified virtual function call with a static call to its
76+
/// most derived implementation
77+
/// \param goto_program [in/out]: GOTO program to modify
78+
/// \param target iterator: to a function in the supplied GOTO program
79+
/// to replace. Must point to a virtual function call.
80+
/// \return Returns a pointer to the statement in the supplied GOTO
81+
/// program after replaced function call
7582
goto_programt::targett remove_virtual_functionst::remove_virtual_function(
7683
goto_programt &goto_program,
7784
goto_programt::targett target)
@@ -119,6 +126,21 @@ static void create_static_function_call(
119126
call.arguments()[0].make_typecast(need_type);
120127
}
121128

129+
/// Replace virtual function call with a static function call
130+
/// Achieved by substituting a virtual function with its most derived
131+
/// implementation. If there's a type mismatch between implementation
132+
/// and the instance type or if fallback_action is set to
133+
/// ASSUME_FALSE, then function is substituted with a call to ASSUME(false)
134+
/// \param goto_program [in/out]: GOTO program to modify
135+
/// \param target: Iterator to the GOTO instruction in the supplied
136+
/// GOTO program to be removed. Must point to a function call
137+
/// \param functions: Dispatch table - all possible implementations of
138+
/// this function sorted from the least to the most derived
139+
/// \param fallback_action: - ASSUME_FALSE to replace virtual function
140+
/// calls with ASSUME(false) or CALL_LAST_FUNCTION to replace them
141+
/// with the most derived matching call
142+
/// \return Returns a pointer to the statement in the supplied GOTO
143+
/// program after replaced function call
122144
goto_programt::targett remove_virtual_functionst::remove_virtual_function(
123145
goto_programt &goto_program,
124146
goto_programt::targett target,
@@ -223,9 +245,9 @@ goto_programt::targett remove_virtual_functionst::remove_virtual_function(
223245
// No definition for this type; shouldn't be possible...
224246
t1->make_assertion(false_exprt());
225247
t1->source_location.set_comment(
226-
("cannot find calls for " +
227-
id2string(code.function().get(ID_identifier)) + " dispatching " +
228-
id2string(fun.class_id)));
248+
"cannot find calls for " +
249+
id2string(code.function().get(ID_identifier)) + " dispatching " +
250+
id2string(fun.class_id));
229251
}
230252
insertit.first->second=t1;
231253
// goto final
@@ -465,6 +487,11 @@ void remove_virtual_functionst::get_functions(
465487
});
466488
}
467489

490+
/// Returns symbol pointing to a specified method in a specified class
491+
/// \param class_id: Class identifier to look up
492+
/// \param component_name: Name of the function to look up
493+
/// \return nil_exprt instance on error and a symbol_exprt pointing to
494+
/// the method on success
468495
exprt remove_virtual_functionst::get_method(
469496
const irep_idt &class_id,
470497
const irep_idt &component_name) const
@@ -480,6 +507,9 @@ exprt remove_virtual_functionst::get_method(
480507
return symbol->symbol_expr();
481508
}
482509

510+
/// Remove all virtual function calls in a GOTO program and replace
511+
/// them with calls to their most derived implementations. Returns
512+
/// true if at least one function has been replaced.
483513
bool remove_virtual_functionst::remove_virtual_functions(
484514
goto_programt &goto_program)
485515
{
@@ -512,6 +542,8 @@ bool remove_virtual_functionst::remove_virtual_functions(
512542
return did_something;
513543
}
514544

545+
/// Remove virtual function calls from all functions in the specified
546+
/// list and replace them with their most derived implementations
515547
void remove_virtual_functionst::operator()(goto_functionst &functions)
516548
{
517549
bool did_something=false;
@@ -531,6 +563,8 @@ void remove_virtual_functionst::operator()(goto_functionst &functions)
531563
functions.compute_location_numbers();
532564
}
533565

566+
/// Remove virtual function calls from all functions in the specified
567+
/// list and replace them with their most derived implementations
534568
void remove_virtual_functions(
535569
const symbol_table_baset &symbol_table,
536570
goto_functionst &goto_functions)
@@ -541,12 +575,14 @@ void remove_virtual_functions(
541575
rvf(goto_functions);
542576
}
543577

578+
/// Remove virtual function calls from the specified model
544579
void remove_virtual_functions(goto_modelt &goto_model)
545580
{
546581
remove_virtual_functions(
547582
goto_model.symbol_table, goto_model.goto_functions);
548583
}
549584

585+
/// Remove virtual function calls from the specified model function
550586
void remove_virtual_functions(goto_model_functiont &function)
551587
{
552588
class_hierarchyt class_hierarchy;
@@ -555,6 +591,22 @@ void remove_virtual_functions(goto_model_functiont &function)
555591
rvf.remove_virtual_functions(function.get_goto_function().body);
556592
}
557593

594+
/// Replace virtual function call with a static function call
595+
/// Achieved by substituting a virtual function with its most derived
596+
/// implementation. If there's a type mismatch between implementation
597+
/// and the instance type or if fallback_action is set to
598+
/// ASSUME_FALSE, then function is substituted with a call to ASSUME(false)
599+
/// \param symbol_table: Symbol table
600+
/// \param goto_program [in/out]: GOTO program to modify
601+
/// \param instruction: Iterator to the GOTO instruction in the supplied
602+
/// GOTO program to be removed. Must point to a function call
603+
/// \param dispatch_table: Dispatch table - all possible implementations of
604+
/// this function sorted from the least to the most derived
605+
/// \param fallback_action: - ASSUME_FALSE to replace virtual function
606+
/// calls with ASSUME(false) or CALL_LAST_FUNCTION to replace them
607+
/// with the most derived matching call
608+
/// \return Returns a pointer to the statement in the supplied GOTO
609+
/// program after replaced function call
558610
goto_programt::targett remove_virtual_function(
559611
symbol_tablet &symbol_table,
560612
goto_programt &goto_program,

src/goto-programs/remove_virtual_functions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Date: April 2016
99
\*******************************************************************/
1010

1111
/// \file
12-
/// Remove Virtual Function (Method) Calls
12+
/// Functions for replacing virtual function call with a static
13+
/// function calls in functions, groups of functions and goto programs
1314

1415
#ifndef CPROVER_GOTO_PROGRAMS_REMOVE_VIRTUAL_FUNCTIONS_H
1516
#define CPROVER_GOTO_PROGRAMS_REMOVE_VIRTUAL_FUNCTIONS_H
@@ -24,8 +25,6 @@ class goto_model_functiont;
2425
class goto_modelt;
2526
class symbol_table_baset;
2627

27-
// remove virtual function calls
28-
// and replace by case-split
2928
void remove_virtual_functions(
3029
goto_modelt &goto_model);
3130

0 commit comments

Comments
 (0)