Skip to content

Commit 11c93bb

Browse files
Vojtech Forejtforejtv
Vojtech Forejt
authored andcommitted
Refactor function filter for coverage instrumentation.
This will make it possible to create filters that depend on more elaborate properties of functions, as opposed to the current behaviour when we could basically just filter using function's name.
1 parent 3a577d7 commit 11c93bb

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

src/goto-instrument/cover.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ std::unique_ptr<cover_configt> get_cover_config(
253253

254254
/// Instruments a single goto program based on the given configuration
255255
/// \param cover_config: configuration, produced using get_cover_config
256-
/// \param function_id: function name
256+
/// \param function_symbol: symbol of the function to be instrumented
257257
/// \param function: function to instrument
258258
/// \param message_handler: log output
259259
static void instrument_cover_goals(
260260
const cover_configt &cover_config,
261-
const irep_idt &function_id,
261+
const symbolt &function_symbol,
262262
goto_functionst::goto_functiont &function,
263263
message_handlert &message_handler)
264264
{
@@ -284,10 +284,10 @@ static void instrument_cover_goals(
284284

285285
bool changed = false;
286286

287-
if(cover_config.function_filters(function_id, function))
287+
if(cover_config.function_filters(function_symbol, function))
288288
{
289289
instrument_cover_goals(
290-
function_id,
290+
function_symbol.name,
291291
function.body,
292292
cover_config.cover_instrumenters,
293293
cover_config.mode,
@@ -297,9 +297,9 @@ static void instrument_cover_goals(
297297

298298
if(
299299
cover_config.traces_must_terminate &&
300-
function_id == goto_functionst::entry_point())
300+
function_symbol.name == goto_functionst::entry_point())
301301
{
302-
cover_instrument_end_of_function(function_id, function.body);
302+
cover_instrument_end_of_function(function_symbol.name, function.body);
303303
changed = true;
304304
}
305305

@@ -316,9 +316,11 @@ void instrument_cover_goals(
316316
goto_model_functiont &function,
317317
message_handlert &message_handler)
318318
{
319+
const symbolt function_symbol =
320+
function.get_symbol_table().lookup_ref(function.get_function_id());
319321
instrument_cover_goals(
320322
cover_config,
321-
function.get_function_id(),
323+
function_symbol,
322324
function.get_goto_function(),
323325
message_handler);
324326

@@ -356,9 +358,10 @@ bool instrument_cover_goals(
356358

357359
Forall_goto_functions(f_it, goto_functions)
358360
{
359-
cover_config->mode = symbol_table.lookup(f_it->first)->mode;
361+
const symbolt function_symbol = symbol_table.lookup_ref(f_it->first);
362+
cover_config->mode = function_symbol.mode;
360363
instrument_cover_goals(
361-
*cover_config, f_it->first, f_it->second, message_handler);
364+
*cover_config, function_symbol, f_it->second, message_handler);
362365
}
363366
goto_functions.compute_location_numbers();
364367

src/goto-instrument/cover_filter.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ Author: Peter Schrammel
1616
#include <linking/static_lifetime_init.h>
1717

1818
/// Filter out functions that are not considered provided by the user
19-
/// \param function_id: a function name
19+
/// \param function: the function under consideration
2020
/// \param goto_function: a goto function
2121
/// \return returns true if function is considered user-provided
2222
bool internal_functions_filtert::operator()(
23-
const irep_idt &function_id,
23+
const symbolt &function,
2424
const goto_functionst::goto_functiont &goto_function) const
2525
{
26-
if(function_id == goto_functionst::entry_point())
26+
if(function.name == goto_functionst::entry_point())
2727
return false;
2828

29-
if(function_id == INITIALIZE_FUNCTION)
29+
if(function.name == INITIALIZE_FUNCTION)
3030
return false;
3131

3232
if(goto_function.is_hidden())
3333
return false;
3434

3535
// ignore Java built-ins (synthetic functions)
36-
if(has_prefix(id2string(function_id), "java::array["))
36+
if(has_prefix(id2string(function.name), "java::array["))
3737
return false;
3838

3939
// ignore if built-in library
@@ -45,33 +45,34 @@ bool internal_functions_filtert::operator()(
4545
return true;
4646
}
4747

48-
/// Filter functions whose name match the regex
49-
/// \param function_id: a function name
48+
/// Filter functions whose name matches the regex
49+
/// \param function: the function under consideration
5050
/// \param goto_function: a goto function
5151
/// \return returns true if the function name matches
5252
bool include_pattern_filtert::operator()(
53-
const irep_idt &function_id,
53+
const symbolt &function,
5454
const goto_functionst::goto_functiont &goto_function) const
5555
{
5656
(void)goto_function; // unused parameter
5757
std::smatch string_matcher;
5858
return std::regex_match(
59-
id2string(function_id), string_matcher, regex_matcher);
59+
id2string(function.name), string_matcher, regex_matcher);
6060
}
6161

6262
/// Call a goto_program non-trivial if it has:
6363
/// * Any declarations
6464
/// * At least 2 branches
6565
/// * At least 5 assignments
6666
/// These criteria are arbitrarily chosen.
67-
/// \param function_id: name of \p goto_function
67+
/// \param function: function symbol for function corresponding
68+
/// to \p goto_function
6869
/// \param goto_function: a goto function
6970
/// \return returns true if non-trivial
7071
bool trivial_functions_filtert::operator()(
71-
const irep_idt &function_id,
72+
const symbolt &function,
7273
const goto_functionst::goto_functiont &goto_function) const
7374
{
74-
(void)function_id; // unused parameter
75+
(void)function; // unused parameter
7576
unsigned long count_assignments = 0, count_goto = 0;
7677
forall_goto_program_instructions(i_it, goto_function.body)
7778
{

src/goto-instrument/cover_filter.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Author: Daniel Kroening
1515
#include <regex>
1616
#include <memory>
1717

18-
#include <util/message.h>
1918
#include <util/invariant.h>
19+
#include <util/message.h>
20+
#include <util/symbol.h>
2021

2122
#include <goto-programs/goto_model.h>
2223

@@ -35,7 +36,7 @@ class function_filter_baset : public messaget
3536

3637
/// Returns true if the function passes the filter criteria
3738
virtual bool operator()(
38-
const irep_idt &identifier,
39+
const symbolt &identifier,
3940
const goto_functionst::goto_functiont &goto_function) const = 0;
4041

4142
/// Can be called after final filter application to report
@@ -85,7 +86,7 @@ class function_filterst
8586
/// \param identifier: function name
8687
/// \param goto_function: goto function
8788
bool operator()(
88-
const irep_idt &identifier,
89+
const symbolt &identifier,
8990
const goto_functionst::goto_functiont &goto_function) const
9091
{
9192
for(const auto &filter : filters)
@@ -151,7 +152,7 @@ class internal_functions_filtert : public function_filter_baset
151152
}
152153

153154
bool operator()(
154-
const irep_idt &identifier,
155+
const symbolt &identifier,
155156
const goto_functionst::goto_functiont &goto_function) const override;
156157
};
157158

@@ -168,7 +169,7 @@ class include_pattern_filtert : public function_filter_baset
168169
}
169170

170171
bool operator()(
171-
const irep_idt &identifier,
172+
const symbolt &identifier,
172173
const goto_functionst::goto_functiont &goto_function) const override;
173174

174175
private:
@@ -185,7 +186,7 @@ class trivial_functions_filtert : public function_filter_baset
185186
}
186187

187188
bool operator()(
188-
const irep_idt &identifier,
189+
const symbolt &identifier,
189190
const goto_functionst::goto_functiont &goto_function) const override;
190191
};
191192

0 commit comments

Comments
 (0)