diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp b/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp index baf7c14..52b8ff1 100644 --- a/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -29,7 +29,8 @@ void CoveragePrinter::StreamDestructor::operator()(raw_ostream *OS) const { } std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension, - bool InToplevel, bool Relative) { + bool InToplevel, + bool Relative) const { assert(Extension.size() && "The file extension may not be empty"); SmallString<256> FullPath; @@ -46,13 +47,14 @@ std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension, auto PathFilename = (sys::path::filename(Path) + "." + Extension).str(); sys::path::append(FullPath, PathFilename); + sys::path::native(FullPath); return FullPath.str(); } Expected<CoveragePrinter::OwnedStream> CoveragePrinter::createOutputStream(StringRef Path, StringRef Extension, - bool InToplevel) { + bool InToplevel) const { if (!Opts.hasOutputDirectory()) return OwnedStream(&outs()); @@ -81,6 +83,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(); @@ -112,15 +133,22 @@ SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File, coverage::CoverageData &&CoverageInfo) { switch (Options.Format) { case CoverageViewOptions::OutputFormat::Text: - return llvm::make_unique<SourceCoverageViewText>(SourceName, File, Options, - std::move(CoverageInfo)); + return llvm::make_unique<SourceCoverageViewText>( + SourceName, File, Options, std::move(CoverageInfo)); case CoverageViewOptions::OutputFormat::HTML: - return llvm::make_unique<SourceCoverageViewHTML>(SourceName, File, Options, - std::move(CoverageInfo)); + return llvm::make_unique<SourceCoverageViewHTML>( + SourceName, File, Options, std::move(CoverageInfo)); } llvm_unreachable("Unknown coverage output format!"); } +std::string SourceCoverageView::getSourceName() const { + SmallString<128> SourceText(SourceName); + sys::path::remove_dots(SourceText, /*remove_dot_dots=*/true); + sys::path::native(SourceText); + return SourceText.str(); +} + void SourceCoverageView::addExpansion( const coverage::CounterMappingRegion &Region, std::unique_ptr<SourceCoverageView> View) { @@ -135,11 +163,17 @@ void SourceCoverageView::addInstantiation( void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, bool ShowSourceName, unsigned ViewDepth) { - if (ShowSourceName) - renderSourceName(OS); + if (WholeFile && getOptions().hasOutputDirectory()) + renderTitle(OS, "Coverage Report"); renderViewHeader(OS); + if (ShowSourceName) + renderSourceName(OS, WholeFile); + + renderTableHeader(OS, (ViewDepth > 0) ? 0 : getFirstUncoveredLineNo(), + ViewDepth); + // We need the expansions and instantiations sorted so we can go through them // while we iterate lines. std::sort(ExpansionSubViews.begin(), ExpansionSubViews.end()); @@ -182,10 +216,10 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, LineCount.addRegionStartCount(S->Count); renderLinePrefix(OS, ViewDepth); - if (getOptions().ShowLineStats) - renderLineCoverageColumn(OS, LineCount); if (getOptions().ShowLineNumbers) renderLineNumberColumn(OS, LI.line_number()); + if (getOptions().ShowLineStats) + renderLineCoverageColumn(OS, LineCount); // If there are expansion subviews, we want to highlight the first one. unsigned ExpansionColumn = 0; |