diff options
author | Ying Yi <maggieyi666@gmail.com> | 2016-09-06 19:31:18 +0000 |
---|---|---|
committer | Ying Yi <maggieyi666@gmail.com> | 2016-09-06 19:31:18 +0000 |
commit | f73cd14f4ac0760ec70f0917f928f1d5a23dba75 (patch) | |
tree | 85da558c192c340eb19b4e9358db5fe106aef96a /tools/llvm-cov/SourceCoverageView.cpp | |
parent | 102e8d51fad306985b9ce04ca44e0114f56a6cf1 (diff) |
[llvm-cov] Add the "Go to first unexecuted line" feature.
This patch provides easy navigation to find the zero count lines, especially useful when the source file is very large.
Differential Revision: https://reviews.llvm.org/D23277
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280739 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r-- | tools/llvm-cov/SourceCoverageView.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp index b61d7919444..323352a5174 100644 --- a/tools/llvm-cov/SourceCoverageView.cpp +++ b/tools/llvm-cov/SourceCoverageView.cpp @@ -82,6 +82,25 @@ CoveragePrinter::create(const CoverageViewOptions &Opts) { llvm_unreachable("Unknown coverage output format!"); } +unsigned SourceCoverageView::getFirstUncoveredLineNo() { + auto CheckIfUncovered = [](const coverage::CoverageSegment &S) { + return S.HasCount && S.Count == 0; + }; + // L is less than R if (1) it's an uncovered segment (has a 0 count), and (2) + // either R is not an uncovered segment, or L has a lower line number than R. + const auto MinSegIt = + std::min_element(CoverageInfo.begin(), CoverageInfo.end(), + [CheckIfUncovered](const coverage::CoverageSegment &L, + const coverage::CoverageSegment &R) { + return (CheckIfUncovered(L) && + (!CheckIfUncovered(R) || (L.Line < R.Line))); + }); + if (CheckIfUncovered(*MinSegIt)) + return (*MinSegIt).Line; + // There is no uncovered line, return zero. + return 0; +} + std::string SourceCoverageView::formatCount(uint64_t N) { std::string Number = utostr(N); int Len = Number.size(); @@ -142,8 +161,12 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, renderViewHeader(OS); + unsigned FirstUncoveredLineNo = 0; + if (WholeFile) + FirstUncoveredLineNo = getFirstUncoveredLineNo(); + if (ShowSourceName) - renderSourceName(OS, WholeFile); + renderSourceName(OS, WholeFile, FirstUncoveredLineNo); renderTableHeader(OS, ViewDepth); // We need the expansions and instantiations sorted so we can go through them |