Skip to content

Commit e2d44c9

Browse files
authored
Merge pull request #4466 from smowton/smowton/cleanup/allow-collect-callees-const-symbol-table
Constify collect_virtual_function_callees
2 parents bfc11dc + 9bc196b commit e2d44c9

File tree

2 files changed

+56
-40
lines changed

2 files changed

+56
-40
lines changed

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,26 @@ Author: Daniel Kroening, [email protected]
2222
#include "remove_skip.h"
2323
#include "resolve_inherited_component.h"
2424

25-
class remove_virtual_functionst
25+
class get_virtual_calleest
2626
{
2727
public:
28-
remove_virtual_functionst(
29-
symbol_table_baset &_symbol_table,
30-
const class_hierarchyt &_class_hierarchy);
31-
32-
void operator()(goto_functionst &goto_functions);
33-
34-
bool remove_virtual_functions(
35-
const irep_idt &function_id,
36-
goto_programt &goto_program);
37-
38-
goto_programt::targett remove_virtual_function(
39-
const irep_idt &function_id,
40-
goto_programt &goto_program,
41-
goto_programt::targett target,
42-
const dispatch_table_entriest &functions,
43-
virtual_dispatch_fallback_actiont fallback_action);
28+
get_virtual_calleest(
29+
const symbol_table_baset &_symbol_table,
30+
const class_hierarchyt &_class_hierarchy)
31+
: ns(_symbol_table),
32+
symbol_table(_symbol_table),
33+
class_hierarchy(_class_hierarchy)
34+
{
35+
}
4436

45-
void get_functions(const exprt &, dispatch_table_entriest &);
37+
void get_functions(const exprt &, dispatch_table_entriest &) const;
4638

47-
protected:
39+
private:
4840
const namespacet ns;
49-
symbol_table_baset &symbol_table;
41+
const symbol_table_baset &symbol_table;
5042

5143
const class_hierarchyt &class_hierarchy;
5244

53-
goto_programt::targett remove_virtual_function(
54-
const irep_idt &function_id,
55-
goto_programt &goto_program,
56-
goto_programt::targett target);
5745
typedef std::function<
5846
optionalt<resolve_inherited_componentt::inherited_componentt>(
5947
const irep_idt &,
@@ -70,14 +58,41 @@ class remove_virtual_functionst
7058
get_method(const irep_idt &class_id, const irep_idt &component_name) const;
7159
};
7260

73-
remove_virtual_functionst::remove_virtual_functionst(
74-
symbol_table_baset &_symbol_table,
75-
const class_hierarchyt &_class_hierarchy)
76-
: ns(_symbol_table),
77-
symbol_table(_symbol_table),
78-
class_hierarchy(_class_hierarchy)
61+
class remove_virtual_functionst
7962
{
80-
}
63+
public:
64+
remove_virtual_functionst(
65+
symbol_table_baset &_symbol_table,
66+
const class_hierarchyt &_class_hierarchy)
67+
: class_hierarchy(_class_hierarchy),
68+
symbol_table(_symbol_table),
69+
ns(symbol_table)
70+
{
71+
}
72+
73+
void operator()(goto_functionst &functions);
74+
75+
bool remove_virtual_functions(
76+
const irep_idt &function_id,
77+
goto_programt &goto_program);
78+
79+
goto_programt::targett remove_virtual_function(
80+
const irep_idt &function_id,
81+
goto_programt &goto_program,
82+
goto_programt::targett target,
83+
const dispatch_table_entriest &functions,
84+
virtual_dispatch_fallback_actiont fallback_action);
85+
86+
private:
87+
const class_hierarchyt &class_hierarchy;
88+
symbol_table_baset &symbol_table;
89+
namespacet ns;
90+
91+
goto_programt::targett remove_virtual_function(
92+
const irep_idt &function_id,
93+
goto_programt &goto_program,
94+
goto_programt::targett target);
95+
};
8196

8297
/// Replace specified virtual function call with a static call to its
8398
/// most derived implementation
@@ -103,8 +118,9 @@ goto_programt::targett remove_virtual_functionst::remove_virtual_function(
103118
!code.arguments().empty(),
104119
"virtual function calls must have at least a this-argument");
105120

121+
get_virtual_calleest get_callees(symbol_table, class_hierarchy);
106122
dispatch_table_entriest functions;
107-
get_functions(function, functions);
123+
get_callees.get_functions(function, functions);
108124

109125
return remove_virtual_function(
110126
function_id,
@@ -497,7 +513,7 @@ goto_programt::targett remove_virtual_functionst::remove_virtual_function(
497513
/// -> [{"C", C.f}, {"B", C.f}, {"A", A.f}]
498514
/// \param entry_map: map of class identifiers to dispatch table entries
499515
/// \param resolve_function_call`: function to resolve abstract method call
500-
void remove_virtual_functionst::get_child_functions_rec(
516+
void get_virtual_calleest::get_child_functions_rec(
501517
const irep_idt &this_id,
502518
const optionalt<symbol_exprt> &last_method_defn,
503519
const irep_idt &component_name,
@@ -565,9 +581,9 @@ void remove_virtual_functionst::get_child_functions_rec(
565581
/// \param function: function that should be called
566582
/// \param [out] functions: is assigned a list of dispatch entries, i.e., pairs
567583
/// of class names and function symbol to call when encountering the class.
568-
void remove_virtual_functionst::get_functions(
584+
void get_virtual_calleest::get_functions(
569585
const exprt &function,
570-
dispatch_table_entriest &functions)
586+
dispatch_table_entriest &functions) const
571587
{
572588
// class part of function to call
573589
const irep_idt class_id=function.get(ID_C_class);
@@ -650,7 +666,7 @@ void remove_virtual_functionst::get_functions(
650666
/// \param component_name: Name of the function to look up
651667
/// \return nil_exprt instance on error and a symbol_exprt pointing to
652668
/// the method on success
653-
exprt remove_virtual_functionst::get_method(
669+
exprt get_virtual_calleest::get_method(
654670
const irep_idt &class_id,
655671
const irep_idt &component_name) const
656672
{
@@ -808,10 +824,10 @@ goto_programt::targett remove_virtual_function(
808824

809825
void collect_virtual_function_callees(
810826
const exprt &function,
811-
symbol_table_baset &symbol_table,
827+
const symbol_table_baset &symbol_table,
812828
const class_hierarchyt &class_hierarchy,
813829
dispatch_table_entriest &overridden_functions)
814830
{
815-
remove_virtual_functionst instance(symbol_table, class_hierarchy);
816-
instance.get_functions(function, overridden_functions);
831+
get_virtual_calleest get_callees(symbol_table, class_hierarchy);
832+
get_callees.get_functions(function, overridden_functions);
817833
}

src/goto-programs/remove_virtual_functions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ goto_programt::targett remove_virtual_function(
114114
/// overridden functions will be stored.
115115
void collect_virtual_function_callees(
116116
const exprt &function,
117-
symbol_tablet &symbol_table,
117+
const symbol_table_baset &symbol_table,
118118
const class_hierarchyt &class_hierarchy,
119119
dispatch_table_entriest &overridden_functions);
120120

0 commit comments

Comments
 (0)