]>
git.proxmox.com Git - rustc.git/blob - src/llvm/tools/llvm-cov/CoverageFilters.h
1 //===- CoverageFilters.h - Function coverage mapping filters --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes provide filtering for function coverage mapping records.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_COV_COVERAGEFILTERS_H
15 #define LLVM_COV_COVERAGEFILTERS_H
17 #include "llvm/ProfileData/CoverageMapping.h"
23 /// \brief Matches specific functions that pass the requirement of this filter.
24 class CoverageFilter
{
26 virtual ~CoverageFilter() {}
28 /// \brief Return true if the function passes the requirements of this filter.
29 virtual bool matches(const coverage::FunctionRecord
&Function
) {
34 /// \brief Matches functions that contain a specific string in their name.
35 class NameCoverageFilter
: public CoverageFilter
{
39 NameCoverageFilter(StringRef Name
) : Name(Name
) {}
41 bool matches(const coverage::FunctionRecord
&Function
) override
;
44 /// \brief Matches functions whose name matches a certain regular expression.
45 class NameRegexCoverageFilter
: public CoverageFilter
{
49 NameRegexCoverageFilter(StringRef Regex
) : Regex(Regex
) {}
51 bool matches(const coverage::FunctionRecord
&Function
) override
;
54 /// \brief Matches numbers that pass a certain threshold.
55 template <typename T
> class StatisticThresholdFilter
{
57 enum Operation
{ LessThan
, GreaterThan
};
63 StatisticThresholdFilter(Operation Op
, T Threshold
)
64 : Op(Op
), Threshold(Threshold
) {}
66 /// \brief Return true if the given number is less than
67 /// or greater than the certain threshold.
68 bool PassesThreshold(T Value
) const {
71 return Value
< Threshold
;
73 return Value
> Threshold
;
79 /// \brief Matches functions whose region coverage percentage
80 /// is above/below a certain percentage.
81 class RegionCoverageFilter
: public CoverageFilter
,
82 public StatisticThresholdFilter
<double> {
84 RegionCoverageFilter(Operation Op
, double Threshold
)
85 : StatisticThresholdFilter(Op
, Threshold
) {}
87 bool matches(const coverage::FunctionRecord
&Function
) override
;
90 /// \brief Matches functions whose line coverage percentage
91 /// is above/below a certain percentage.
92 class LineCoverageFilter
: public CoverageFilter
,
93 public StatisticThresholdFilter
<double> {
95 LineCoverageFilter(Operation Op
, double Threshold
)
96 : StatisticThresholdFilter(Op
, Threshold
) {}
98 bool matches(const coverage::FunctionRecord
&Function
) override
;
101 /// \brief A collection of filters.
102 /// Matches functions that match any filters contained
103 /// in an instance of this class.
104 class CoverageFilters
: public CoverageFilter
{
106 std::vector
<std::unique_ptr
<CoverageFilter
>> Filters
;
109 /// \brief Append a filter to this collection.
110 void push_back(std::unique_ptr
<CoverageFilter
> Filter
);
112 bool empty() const { return Filters
.empty(); }
114 bool matches(const coverage::FunctionRecord
&Function
) override
;
117 /// \brief A collection of filters.
118 /// Matches functions that match all of the filters contained
119 /// in an instance of this class.
120 class CoverageFiltersMatchAll
: public CoverageFilters
{
122 bool matches(const coverage::FunctionRecord
&Function
) override
;
127 #endif // LLVM_COV_COVERAGEFILTERS_H