Skip to content

Commit 7f868e2

Browse files
committed
Reused private code in 'remove_virtual_functions.cpp' by making it public.
1 parent 1e0ac30 commit 7f868e2

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

src/goto-programs/remove_virtual_functions.cpp

+28-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Author: Daniel Kroening, [email protected]
1111
#include <algorithm>
1212

1313
#include "remove_virtual_functions.h"
14-
#include "class_hierarchy.h"
1514
#include "class_identifier.h"
1615

1716
#include <goto-programs/resolve_concrete_function_call.h>
@@ -24,7 +23,8 @@ class remove_virtual_functionst
2423
{
2524
public:
2625
remove_virtual_functionst(
27-
const symbol_tablet &_symbol_table);
26+
const symbol_tablet &_symbol_table,
27+
const class_hierarchyt &_class_hierarchy);
2828

2929
void operator()(goto_functionst &goto_functions);
3030

@@ -40,13 +40,14 @@ class remove_virtual_functionst
4040
const namespacet ns;
4141
const symbol_tablet &symbol_table;
4242

43-
class_hierarchyt class_hierarchy;
43+
const class_hierarchyt &class_hierarchy;
4444

4545
void remove_virtual_function(
4646
goto_programt &goto_program,
4747
goto_programt::targett target);
48-
48+
public:
4949
void get_functions(const exprt &, dispatch_table_entriest &);
50+
protected:
5051
typedef std::function<
5152
resolve_concrete_function_callt::concrete_function_callt(
5253
const irep_idt &,
@@ -64,11 +65,12 @@ class remove_virtual_functionst
6465
};
6566

6667
remove_virtual_functionst::remove_virtual_functionst(
67-
const symbol_tablet &_symbol_table):
68+
const symbol_tablet &_symbol_table,
69+
const class_hierarchyt &_class_hierarchy):
6870
ns(_symbol_table),
69-
symbol_table(_symbol_table)
71+
symbol_table(_symbol_table),
72+
class_hierarchy(_class_hierarchy)
7073
{
71-
class_hierarchy(symbol_table);
7274
}
7375

7476
void remove_virtual_functionst::remove_virtual_function(
@@ -434,7 +436,9 @@ void remove_virtual_functions(
434436
const symbol_tablet &symbol_table,
435437
goto_functionst &goto_functions)
436438
{
437-
remove_virtual_functionst rvf(symbol_table);
439+
class_hierarchyt class_hierarchy;
440+
class_hierarchy(symbol_table);
441+
remove_virtual_functionst rvf(symbol_table, class_hierarchy);
438442
rvf(goto_functions);
439443
}
440444

@@ -446,7 +450,9 @@ void remove_virtual_functions(goto_modelt &goto_model)
446450

447451
void remove_virtual_functions(goto_model_functiont &function)
448452
{
449-
remove_virtual_functionst rvf(function.get_symbol_table());
453+
class_hierarchyt class_hierarchy;
454+
class_hierarchy(function.get_symbol_table());
455+
remove_virtual_functionst rvf(function.get_symbol_table(), class_hierarchy);
450456
bool changed = rvf.remove_virtual_functions(
451457
function.get_goto_function().body);
452458
// Give fresh location numbers to `function`, in case it has grown:
@@ -461,8 +467,20 @@ void remove_virtual_function(
461467
const dispatch_table_entriest &dispatch_table,
462468
virtual_dispatch_fallback_actiont fallback_action)
463469
{
464-
remove_virtual_functionst rvf(goto_model.symbol_table);
470+
class_hierarchyt class_hierarchy;
471+
class_hierarchy(goto_model.symbol_table);
472+
remove_virtual_functionst rvf(goto_model.symbol_table, class_hierarchy);
465473

466474
rvf.remove_virtual_function(
467475
goto_program, instruction, dispatch_table, fallback_action);
468476
}
477+
478+
void get_overridden_functions(
479+
const exprt &function,
480+
const symbol_tablet &symbol_table,
481+
const class_hierarchyt &class_hierarchy,
482+
dispatch_table_entriest &overridden_functions)
483+
{
484+
remove_virtual_functionst instance(symbol_table, class_hierarchy);
485+
instance.get_functions(function, overridden_functions);
486+
}

src/goto-programs/remove_virtual_functions.h

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Date: April 2016
1515
#define CPROVER_GOTO_PROGRAMS_REMOVE_VIRTUAL_FUNCTIONS_H
1616

1717
#include "goto_model.h"
18+
#include "class_hierarchy.h"
1819

1920
// remove virtual function calls
2021
// and replace by case-split
@@ -64,4 +65,19 @@ void remove_virtual_function(
6465
const dispatch_table_entriest &dispatch_table,
6566
virtual_dispatch_fallback_actiont fallback_action);
6667

68+
/// Given a function expression representing a virtual method of a class,
69+
/// the function computes all overridden methods of that virtual method.
70+
/// \param function: The virtual function expression for which the overridden
71+
/// methods will be searched for.
72+
/// \param symbol_table: A symbol table.
73+
/// \param class_hierarchy: A class hierarchy.
74+
/// \param [out] overridden_functions: Output collection into which all
75+
/// overridden functions will be stored.
76+
void get_overridden_functions(
77+
const exprt &function,
78+
const symbol_tablet &symbol_table,
79+
const class_hierarchyt &class_hierarchy,
80+
dispatch_table_entriest &overridden_functions);
81+
82+
6783
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_VIRTUAL_FUNCTIONS_H

0 commit comments

Comments
 (0)