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 "FunctionCoverageMapping.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 FunctionCoverageMapping &Function) { return true; }
32 /// \brief Matches functions that contain a specific string in their name.
33 class NameCoverageFilter : public CoverageFilter {
37 NameCoverageFilter(StringRef Name) : Name(Name) {}
39 bool matches(const FunctionCoverageMapping &Function) override;
42 /// \brief Matches functions whose name matches a certain regular expression.
43 class NameRegexCoverageFilter : public CoverageFilter {
47 NameRegexCoverageFilter(StringRef Regex) : Regex(Regex) {}
49 bool matches(const FunctionCoverageMapping &Function) override;
52 /// \brief Matches numbers that pass a certain threshold.
53 template <typename T> class StatisticThresholdFilter {
55 enum Operation { LessThan, GreaterThan };
61 StatisticThresholdFilter(Operation Op, T Threshold)
62 : Op(Op), Threshold(Threshold) {}
64 /// \brief Return true if the given number is less than
65 /// or greater than the certain threshold.
66 bool PassesThreshold(T Value) const {
69 return Value < Threshold;
71 return Value > Threshold;
77 /// \brief Matches functions whose region coverage percentage
78 /// is above/below a certain percentage.
79 class RegionCoverageFilter : public CoverageFilter,
80 public StatisticThresholdFilter<double> {
82 RegionCoverageFilter(Operation Op, double Threshold)
83 : StatisticThresholdFilter(Op, Threshold) {}
85 bool matches(const FunctionCoverageMapping &Function) override;
88 /// \brief Matches functions whose line coverage percentage
89 /// is above/below a certain percentage.
90 class LineCoverageFilter : public CoverageFilter,
91 public StatisticThresholdFilter<double> {
93 LineCoverageFilter(Operation Op, double Threshold)
94 : StatisticThresholdFilter(Op, Threshold) {}
96 bool matches(const FunctionCoverageMapping &Function) override;
99 /// \brief A collection of filters.
100 /// Matches functions that match any filters contained
101 /// in an instance of this class.
102 class CoverageFilters : public CoverageFilter {
104 std::vector<std::unique_ptr<CoverageFilter>> Filters;
107 /// \brief Append a filter to this collection.
108 void push_back(std::unique_ptr<CoverageFilter> Filter);
110 bool empty() const { return Filters.empty(); }
112 bool matches(const FunctionCoverageMapping &Function) override;
115 /// \brief A collection of filters.
116 /// Matches functions that match all of the filters contained
117 /// in an instance of this class.
118 class CoverageFiltersMatchAll : public CoverageFilters {
120 bool matches(const FunctionCoverageMapping &Function) override;
125 #endif // LLVM_COV_COVERAGEFILTERS_H