[llvm-objcopy] [COFF] Fix warnings abuilt missing field initialization. NFC.
[llvm-complete.git] / tools / llvm-cov / CoverageFilters.h
blob6424ca5a8081d283570f9ac4f86a329323945261
1 //===- CoverageFilters.h - Function coverage mapping filters --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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 "CoverageSummaryInfo.h"
18 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
19 #include "llvm/Support/SpecialCaseList.h"
20 #include <memory>
21 #include <vector>
23 namespace llvm {
25 /// Matches specific functions that pass the requirement of this filter.
26 class CoverageFilter {
27 public:
28 virtual ~CoverageFilter() {}
30 /// Return true if the function passes the requirements of this filter.
31 virtual bool matches(const coverage::CoverageMapping &CM,
32 const coverage::FunctionRecord &Function) const {
33 return true;
36 /// Return true if the filename passes the requirements of this filter.
37 virtual bool matchesFilename(StringRef Filename) const {
38 return true;
42 /// Matches functions that contain a specific string in their name.
43 class NameCoverageFilter : public CoverageFilter {
44 StringRef Name;
46 public:
47 NameCoverageFilter(StringRef Name) : Name(Name) {}
49 bool matches(const coverage::CoverageMapping &CM,
50 const coverage::FunctionRecord &Function) const override;
53 /// Matches functions whose name matches a certain regular expression.
54 class NameRegexCoverageFilter : public CoverageFilter {
55 StringRef Regex;
57 public:
58 NameRegexCoverageFilter(StringRef Regex) : Regex(Regex) {}
60 bool matches(const coverage::CoverageMapping &CM,
61 const coverage::FunctionRecord &Function) const override;
63 bool matchesFilename(StringRef Filename) const override;
66 /// Matches functions whose name appears in a SpecialCaseList in the
67 /// whitelist_fun section.
68 class NameWhitelistCoverageFilter : public CoverageFilter {
69 const SpecialCaseList &Whitelist;
71 public:
72 NameWhitelistCoverageFilter(const SpecialCaseList &Whitelist)
73 : Whitelist(Whitelist) {}
75 bool matches(const coverage::CoverageMapping &CM,
76 const coverage::FunctionRecord &Function) const override;
79 /// Matches numbers that pass a certain threshold.
80 template <typename T> class StatisticThresholdFilter {
81 public:
82 enum Operation { LessThan, GreaterThan };
84 protected:
85 Operation Op;
86 T Threshold;
88 StatisticThresholdFilter(Operation Op, T Threshold)
89 : Op(Op), Threshold(Threshold) {}
91 /// Return true if the given number is less than
92 /// or greater than the certain threshold.
93 bool PassesThreshold(T Value) const {
94 switch (Op) {
95 case LessThan:
96 return Value < Threshold;
97 case GreaterThan:
98 return Value > Threshold;
100 return false;
104 /// Matches functions whose region coverage percentage
105 /// is above/below a certain percentage.
106 class RegionCoverageFilter : public CoverageFilter,
107 public StatisticThresholdFilter<double> {
108 public:
109 RegionCoverageFilter(Operation Op, double Threshold)
110 : StatisticThresholdFilter(Op, Threshold) {}
112 bool matches(const coverage::CoverageMapping &CM,
113 const coverage::FunctionRecord &Function) const override;
116 /// Matches functions whose line coverage percentage
117 /// is above/below a certain percentage.
118 class LineCoverageFilter : public CoverageFilter,
119 public StatisticThresholdFilter<double> {
120 public:
121 LineCoverageFilter(Operation Op, double Threshold)
122 : StatisticThresholdFilter(Op, Threshold) {}
124 bool matches(const coverage::CoverageMapping &CM,
125 const coverage::FunctionRecord &Function) const override;
128 /// A collection of filters.
129 /// Matches functions that match any filters contained
130 /// in an instance of this class.
131 class CoverageFilters : public CoverageFilter {
132 protected:
133 std::vector<std::unique_ptr<CoverageFilter>> Filters;
135 public:
136 /// Append a filter to this collection.
137 void push_back(std::unique_ptr<CoverageFilter> Filter);
139 bool empty() const { return Filters.empty(); }
141 bool matches(const coverage::CoverageMapping &CM,
142 const coverage::FunctionRecord &Function) const override;
144 bool matchesFilename(StringRef Filename) const override;
147 /// A collection of filters.
148 /// Matches functions that match all of the filters contained
149 /// in an instance of this class.
150 class CoverageFiltersMatchAll : public CoverageFilters {
151 public:
152 bool matches(const coverage::CoverageMapping &CM,
153 const coverage::FunctionRecord &Function) const override;
156 } // namespace llvm
158 #endif // LLVM_COV_COVERAGEFILTERS_H