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(const FunctionCoverageMapping &Function) {
21 StringRef FuncName = Function.Name;
22 return FuncName.find(Name) != StringRef::npos;
25 bool NameRegexCoverageFilter::matches(const FunctionCoverageMapping &Function) {
26 return llvm::Regex(Regex).match(Function.Name);
29 bool RegionCoverageFilter::matches(const FunctionCoverageMapping &Function) {
30 return PassesThreshold(FunctionCoverageSummary::get(Function)
31 .RegionCoverage.getPercentCovered());
34 bool LineCoverageFilter::matches(const FunctionCoverageMapping &Function) {
35 return PassesThreshold(
36 FunctionCoverageSummary::get(Function).LineCoverage.getPercentCovered());
39 void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) {
40 Filters.push_back(std::move(Filter));
43 bool CoverageFilters::matches(const FunctionCoverageMapping &Function) {
44 for (const auto &Filter : Filters) {
45 if (Filter->matches(Function))
51 bool CoverageFiltersMatchAll::matches(const FunctionCoverageMapping &Function) {
52 for (const auto &Filter : Filters) {
53 if (!Filter->matches(Function))