1 //===- CoverageFilters.cpp - 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 #include "CoverageFilters.h"
15 #include "CoverageSummaryInfo.h"
16 #include "llvm/Support/Regex.h"
20 bool NameCoverageFilter::matches(
21 const coverage::CoverageMapping &,
22 const coverage::FunctionRecord &Function) const {
23 StringRef FuncName = Function.Name;
24 return FuncName.find(Name) != StringRef::npos;
27 bool NameRegexCoverageFilter::matches(
28 const coverage::CoverageMapping &,
29 const coverage::FunctionRecord &Function) const {
30 return llvm::Regex(Regex).match(Function.Name);
33 bool NameWhitelistCoverageFilter::matches(
34 const coverage::CoverageMapping &,
35 const coverage::FunctionRecord &Function) const {
36 return Whitelist.inSection("llvmcov", "whitelist_fun", Function.Name);
39 bool RegionCoverageFilter::matches(
40 const coverage::CoverageMapping &CM,
41 const coverage::FunctionRecord &Function) const {
42 return PassesThreshold(FunctionCoverageSummary::get(CM, Function)
43 .RegionCoverage.getPercentCovered());
46 bool LineCoverageFilter::matches(
47 const coverage::CoverageMapping &CM,
48 const coverage::FunctionRecord &Function) const {
49 return PassesThreshold(FunctionCoverageSummary::get(CM, Function)
50 .LineCoverage.getPercentCovered());
53 void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) {
54 Filters.push_back(std::move(Filter));
57 bool CoverageFilters::matches(const coverage::CoverageMapping &CM,
58 const coverage::FunctionRecord &Function) const {
59 for (const auto &Filter : Filters) {
60 if (Filter->matches(CM, Function))
66 bool CoverageFiltersMatchAll::matches(
67 const coverage::CoverageMapping &CM,
68 const coverage::FunctionRecord &Function) const {
69 for (const auto &Filter : Filters) {
70 if (!Filter->matches(CM, Function))