CoverageFilters.cpp 1.8 KB

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