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 matches(const coverage::FunctionRecord & Function)20bool NameCoverageFilter::matches(const coverage::FunctionRecord &Function) { 21 StringRef FuncName = Function.Name; 22 return FuncName.find(Name) != StringRef::npos; 23 } 24 25 bool matches(const coverage::FunctionRecord & Function)26NameRegexCoverageFilter::matches(const coverage::FunctionRecord &Function) { 27 return llvm::Regex(Regex).match(Function.Name); 28 } 29 matches(const coverage::FunctionRecord & Function)30bool RegionCoverageFilter::matches(const coverage::FunctionRecord &Function) { 31 return PassesThreshold(FunctionCoverageSummary::get(Function) 32 .RegionCoverage.getPercentCovered()); 33 } 34 matches(const coverage::FunctionRecord & Function)35bool LineCoverageFilter::matches(const coverage::FunctionRecord &Function) { 36 return PassesThreshold( 37 FunctionCoverageSummary::get(Function).LineCoverage.getPercentCovered()); 38 } 39 push_back(std::unique_ptr<CoverageFilter> Filter)40void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) { 41 Filters.push_back(std::move(Filter)); 42 } 43 matches(const coverage::FunctionRecord & Function)44bool CoverageFilters::matches(const coverage::FunctionRecord &Function) { 45 for (const auto &Filter : Filters) { 46 if (Filter->matches(Function)) 47 return true; 48 } 49 return false; 50 } 51 52 bool matches(const coverage::FunctionRecord & Function)53CoverageFiltersMatchAll::matches(const coverage::FunctionRecord &Function) { 54 for (const auto &Filter : Filters) { 55 if (!Filter->matches(Function)) 56 return false; 57 } 58 return true; 59 } 60