1 //===- CoverageFilters.cpp - 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. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "CoverageFilters.h" 15 #include "CoverageSummaryInfo.h" 16 #include "llvm/Support/Regex.h" 17 18 using namespace llvm; 19 20 bool NameCoverageFilter::matches(const FunctionCoverageMapping &Function) { 21 StringRef FuncName = Function.PrettyName; 22 return FuncName.find(Name) != StringRef::npos; 23 } 24 25 bool NameRegexCoverageFilter::matches(const FunctionCoverageMapping &Function) { 26 return llvm::Regex(Regex).match(Function.PrettyName); 27 } 28 29 bool RegionCoverageFilter::matches(const FunctionCoverageMapping &Function) { 30 return PassesThreshold(FunctionCoverageSummary::get(Function) 31 .RegionCoverage.getPercentCovered()); 32 } 33 34 bool LineCoverageFilter::matches(const FunctionCoverageMapping &Function) { 35 return PassesThreshold( 36 FunctionCoverageSummary::get(Function).LineCoverage.getPercentCovered()); 37 } 38 39 void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) { 40 Filters.push_back(std::move(Filter)); 41 } 42 43 bool CoverageFilters::matches(const FunctionCoverageMapping &Function) { 44 for (const auto &Filter : Filters) { 45 if (Filter->matches(Function)) 46 return true; 47 } 48 return false; 49 } 50 51 bool CoverageFiltersMatchAll::matches(const FunctionCoverageMapping &Function) { 52 for (const auto &Filter : Filters) { 53 if (!Filter->matches(Function)) 54 return false; 55 } 56 return true; 57 } 58