#ifndef LLVM_COV_COVERAGEFILTERS_H
#define LLVM_COV_COVERAGEFILTERS_H
#include "llvm/ProfileData/CoverageMapping.h"
#include <vector>
#include <memory>
namespace llvm {
class CoverageFilter {
public:
virtual ~CoverageFilter() {}
virtual bool matches(const coverage::FunctionRecord &Function) {
return true;
}
};
class NameCoverageFilter : public CoverageFilter {
StringRef Name;
public:
NameCoverageFilter(StringRef Name) : Name(Name) {}
bool matches(const coverage::FunctionRecord &Function) override;
};
class NameRegexCoverageFilter : public CoverageFilter {
StringRef Regex;
public:
NameRegexCoverageFilter(StringRef Regex) : Regex(Regex) {}
bool matches(const coverage::FunctionRecord &Function) override;
};
template <typename T> class StatisticThresholdFilter {
public:
enum Operation { LessThan, GreaterThan };
protected:
Operation Op;
T Threshold;
StatisticThresholdFilter(Operation Op, T Threshold)
: Op(Op), Threshold(Threshold) {}
bool PassesThreshold(T Value) const {
switch (Op) {
case LessThan:
return Value < Threshold;
case GreaterThan:
return Value > Threshold;
}
return false;
}
};
class RegionCoverageFilter : public CoverageFilter,
public StatisticThresholdFilter<double> {
public:
RegionCoverageFilter(Operation Op, double Threshold)
: StatisticThresholdFilter(Op, Threshold) {}
bool matches(const coverage::FunctionRecord &Function) override;
};
class LineCoverageFilter : public CoverageFilter,
public StatisticThresholdFilter<double> {
public:
LineCoverageFilter(Operation Op, double Threshold)
: StatisticThresholdFilter(Op, Threshold) {}
bool matches(const coverage::FunctionRecord &Function) override;
};
class CoverageFilters : public CoverageFilter {
protected:
std::vector<std::unique_ptr<CoverageFilter>> Filters;
public:
void push_back(std::unique_ptr<CoverageFilter> Filter);
bool empty() const { return Filters.empty(); }
bool matches(const coverage::FunctionRecord &Function) override;
};
class CoverageFiltersMatchAll : public CoverageFilters {
public:
bool matches(const coverage::FunctionRecord &Function) override;
};
}
#endif // LLVM_COV_COVERAGEFILTERS_H