CBMC
cover_filter.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Coverage Instrumentation
4 
5 Author: Daniel Kroening
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_INSTRUMENT_COVER_FILTER_H
13 #define CPROVER_GOTO_INSTRUMENT_COVER_FILTER_H
14 
15 #include <regex>
16 #include <memory>
17 
19 
20 class symbolt;
21 
24 {
25 public:
27  {
28  }
29 
31  virtual bool operator()(
32  const symbolt &identifier,
33  const goto_functionst::goto_functiont &goto_function) const = 0;
34 
37  virtual void report_anomalies() const
38  {
39  // do nothing by default
40  }
41 };
42 
45 {
46 public:
48  {
49  }
50 
52  virtual bool operator()(const source_locationt &) const = 0;
53 
56  virtual void report_anomalies() const
57  {
58  // do nothing by default
59  }
60 };
61 
64 {
65 public:
68  void add(std::unique_ptr<function_filter_baset> filter)
69  {
70  filters.push_back(std::move(filter));
71  }
72 
76  bool operator()(
77  const symbolt &identifier,
78  const goto_functionst::goto_functiont &goto_function) const
79  {
80  for(const auto &filter : filters)
81  if(!(*filter)(identifier, goto_function))
82  return false;
83 
84  return true;
85  }
86 
89  void report_anomalies() const
90  {
91  for(const auto &filter : filters)
92  filter->report_anomalies();
93  }
94 
95 private:
96  std::vector<std::unique_ptr<function_filter_baset>> filters;
97 };
98 
101 {
102 public:
105  void add(std::unique_ptr<goal_filter_baset> filter)
106  {
107  filters.push_back(std::move(filter));
108  }
109 
112  bool operator()(const source_locationt &source_location) const
113  {
114  for(const auto &filter : filters)
115  if(!(*filter)(source_location))
116  return false;
117 
118  return true;
119  }
120 
123  void report_anomalies() const
124  {
125  for(const auto &filter : filters)
126  filter->report_anomalies();
127  }
128 
129 private:
130  std::vector<std::unique_ptr<goal_filter_baset>> filters;
131 };
132 
135 {
136 public:
137  bool operator()(
138  const symbolt &identifier,
139  const goto_functionst::goto_functiont &goto_function) const override;
140 };
141 
143 {
144 public:
146  {
147  }
148 
149  bool operator()(
150  const symbolt &identifier,
151  const goto_functionst::goto_functiont &goto_function) const override;
152 
153 private:
155 };
156 
158 {
159 public:
162  {
163  }
164 
165  bool operator()(
166  const symbolt &identifier,
167  const goto_functionst::goto_functiont &goto_function) const override;
168 
169 private:
171 };
172 
175 {
176 public:
177  explicit include_pattern_filtert(const std::string &cover_include_pattern)
178  : regex_matcher(cover_include_pattern)
179  {
180  }
181 
182  bool operator()(
183  const symbolt &identifier,
184  const goto_functionst::goto_functiont &goto_function) const override;
185 
186 private:
187  std::regex regex_matcher;
188 };
189 
192 {
193 public:
194  bool operator()(
195  const symbolt &identifier,
196  const goto_functionst::goto_functiont &goto_function) const override;
197 };
198 
201 {
202 public:
203  bool operator()(const source_locationt &) const override;
204 };
205 
206 #endif // CPROVER_GOTO_INSTRUMENT_COVER_FILTER_H
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
file_filtert(const irep_idt &file_id)
Definition: cover_filter.h:145
bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const override
Filter out all functions except those defined in the file that is given in the constructor.
irep_idt file_id
Definition: cover_filter.h:154
Base class for filtering functions.
Definition: cover_filter.h:24
virtual void report_anomalies() const
Can be called after final filter application to report on unexpected situations encountered.
Definition: cover_filter.h:37
virtual ~function_filter_baset()
Definition: cover_filter.h:26
virtual bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const =0
Returns true if the function passes the filter criteria.
A collection of function filters to be applied in conjunction.
Definition: cover_filter.h:64
void add(std::unique_ptr< function_filter_baset > filter)
Adds a function filter.
Definition: cover_filter.h:68
bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const
Applies the filters to the given function.
Definition: cover_filter.h:76
void report_anomalies() const
Can be called after final filter application to report on unexpected situations encountered.
Definition: cover_filter.h:89
std::vector< std::unique_ptr< function_filter_baset > > filters
Definition: cover_filter.h:96
Base class for filtering goals.
Definition: cover_filter.h:45
virtual bool operator()(const source_locationt &) const =0
Returns true if the goal passes the filter criteria.
virtual void report_anomalies() const
Can be called after final filter application to report on unexpected situations encountered.
Definition: cover_filter.h:56
virtual ~goal_filter_baset()
Definition: cover_filter.h:47
A collection of goal filters to be applied in conjunction.
Definition: cover_filter.h:101
void add(std::unique_ptr< goal_filter_baset > filter)
Adds a function filter.
Definition: cover_filter.h:105
std::vector< std::unique_ptr< goal_filter_baset > > filters
Definition: cover_filter.h:130
void report_anomalies() const
Can be called after final filter application to report on unexpected situations encountered.
Definition: cover_filter.h:123
bool operator()(const source_locationt &source_location) const
Applies the filters to the given source location.
Definition: cover_filter.h:112
::goto_functiont goto_functiont
Filters functions that match the provided pattern.
Definition: cover_filter.h:175
include_pattern_filtert(const std::string &cover_include_pattern)
Definition: cover_filter.h:177
bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const override
Filter functions whose name matches the regex.
Filters out CPROVER internal functions.
Definition: cover_filter.h:135
bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const override
Filter out functions that are not considered provided by the user.
Filters out goals with source locations considered internal.
Definition: cover_filter.h:201
bool operator()(const source_locationt &) const override
Filter goals at source locations considered internal.
single_function_filtert(const irep_idt &function_id)
Definition: cover_filter.h:160
bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const override
Filter out all functions except for one particular function given in the constructor.
Symbol table entry.
Definition: symbol.h:28
Filters out trivial functions.
Definition: cover_filter.h:192
bool operator()(const symbolt &identifier, const goto_functionst::goto_functiont &goto_function) const override
Call a goto_program non-trivial if it has:
Goto Programs with Functions.