Skip to content

Commit 7c43d46

Browse files
committed
Add overloads of remove_virtual_functions that take a pre-computed class_hierarchyt
This allows driver programs to avoid pointless recomputation. In the process sort out the function documentation, moving it to the implementation site per convention and documenting parameters.
1 parent 8bfb45f commit 7c43d46

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ void remove_virtual_functionst::operator()(goto_functionst &functions)
737737

738738
/// Remove virtual function calls from all functions in the specified
739739
/// list and replace them with their most derived implementations
740+
/// \param symbol_table: symbol table associated with \p goto_functions
741+
/// \param goto_functions: functions from which to remove virtual function calls
740742
void remove_virtual_functions(
741743
symbol_table_baset &symbol_table,
742744
goto_functionst &goto_functions)
@@ -747,14 +749,47 @@ void remove_virtual_functions(
747749
rvf(goto_functions);
748750
}
749751

752+
/// Remove virtual function calls from all functions in the specified
753+
/// list and replace them with their most derived implementations
754+
/// \param symbol_table: symbol table associated with \p goto_functions
755+
/// \param goto_functions: functions from which to remove virtual function calls
756+
/// \param class_hierarchy: class hierarchy derived from symbol_table
757+
/// This should already be populated (i.e. class_hierarchyt::operator() has
758+
/// already been called)
759+
void remove_virtual_functions(
760+
symbol_table_baset &symbol_table,
761+
goto_functionst &goto_functions,
762+
const class_hierarchyt &class_hierarchy)
763+
{
764+
remove_virtual_functionst rvf(symbol_table, class_hierarchy);
765+
rvf(goto_functions);
766+
}
767+
750768
/// Remove virtual function calls from the specified model
769+
/// \param goto_model: model from which to remove virtual functions
751770
void remove_virtual_functions(goto_modelt &goto_model)
752771
{
753772
remove_virtual_functions(
754773
goto_model.symbol_table, goto_model.goto_functions);
755774
}
756775

776+
/// Remove virtual function calls from the specified model
777+
/// \param goto_model: model from which to remove virtual functions
778+
/// \param class_hierarchy: class hierarchy derived from model.symbol_table
779+
/// This should already be populated (i.e. class_hierarchyt::operator() has
780+
/// already been called)
781+
void remove_virtual_functions(
782+
goto_modelt &goto_model,
783+
const class_hierarchyt &class_hierarchy)
784+
{
785+
remove_virtual_functions(
786+
goto_model.symbol_table, goto_model.goto_functions, class_hierarchy);
787+
}
788+
757789
/// Remove virtual function calls from the specified model function
790+
/// May change the location numbers in `function`.
791+
/// \param function: function from which virtual functions should be converted
792+
/// to explicit dispatch tables.
758793
void remove_virtual_functions(goto_model_functiont &function)
759794
{
760795
class_hierarchyt class_hierarchy;
@@ -764,6 +799,22 @@ void remove_virtual_functions(goto_model_functiont &function)
764799
function.get_function_id(), function.get_goto_function().body);
765800
}
766801

802+
/// Remove virtual function calls from the specified model function
803+
/// May change the location numbers in `function`.
804+
/// \param function: function from which virtual functions should be converted
805+
/// to explicit dispatch tables.
806+
/// \param class_hierarchy: class hierarchy derived from function.symbol_table
807+
/// This should already be populated (i.e. class_hierarchyt::operator() has
808+
/// already been called)
809+
void remove_virtual_functions(
810+
goto_model_functiont &function,
811+
const class_hierarchyt &class_hierarchy)
812+
{
813+
remove_virtual_functionst rvf(function.get_symbol_table(), class_hierarchy);
814+
rvf.remove_virtual_functions(
815+
function.get_function_id(), function.get_goto_function().body);
816+
}
817+
767818
/// Replace virtual function call with a static function call
768819
/// Achieved by substituting a virtual function with its most derived
769820
/// implementation. If there's a type mismatch between implementation

src/goto-programs/remove_virtual_functions.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,32 @@ class goto_model_functiont;
2626
class goto_modelt;
2727
class symbol_table_baset;
2828

29+
// For all of the following the class-hierarchy and non-class-hierarchy
30+
// overloads are equivalent, but the class-hierarchy-taking one saves time if
31+
// you already have a class-hierarchy object available.
32+
2933
void remove_virtual_functions(
3034
goto_modelt &goto_model);
3135

36+
void remove_virtual_functions(
37+
goto_modelt &goto_model,
38+
const class_hierarchyt &class_hierarchy);
39+
3240
void remove_virtual_functions(
3341
symbol_table_baset &symbol_table,
3442
goto_functionst &goto_functions);
3543

36-
/// Remove virtual functions from one function.
37-
/// May change the location numbers in `function`.
38-
/// \param function: function from which virtual functions should be converted
39-
/// to explicit dispatch tables.
44+
void remove_virtual_functions(
45+
symbol_table_baset &symbol_table,
46+
goto_functionst &goto_functions,
47+
const class_hierarchyt &class_hierarchy);
48+
4049
void remove_virtual_functions(goto_model_functiont &function);
4150

51+
void remove_virtual_functions(
52+
goto_model_functiont &function,
53+
const class_hierarchyt &class_hierarchy);
54+
4255
/// Specifies remove_virtual_function's behaviour when the actual supplied
4356
/// parameter does not match any of the possible callee types
4457
enum class virtual_dispatch_fallback_actiont

0 commit comments

Comments
 (0)