From 6c2710f16608a278d05a4859e70fd56751a05191 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Wed, 18 Oct 2017 18:52:28 +0000 Subject: [PATCH] [llvm-cov] Pass LineCoverageStats in SourceCoverageView. NFC. Instead of copying around the wrapped segment and the list of line segments, just pass a reference to a LineCoverageStats object. This simplifies the interface. It also makes an upcoming change to suppress distracting highlights possible. llvm-svn: 316108 --- tools/llvm-cov/SourceCoverageView.cpp | 10 ++++----- tools/llvm-cov/SourceCoverageView.h | 14 ++++++------ tools/llvm-cov/SourceCoverageViewHTML.cpp | 20 +++++++++-------- tools/llvm-cov/SourceCoverageViewHTML.h | 11 ++++------ tools/llvm-cov/SourceCoverageViewText.cpp | 26 ++++++++++++++--------- tools/llvm-cov/SourceCoverageViewText.h | 11 ++++------ 6 files changed, 45 insertions(+), 47 deletions(-) diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp index 337beb821bf..6cb4a2c026b 100644 --- a/tools/llvm-cov/SourceCoverageView.cpp +++ b/tools/llvm-cov/SourceCoverageView.cpp @@ -218,12 +218,11 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, ExpansionColumn = NextESV->getStartCol(); // Display the source code for the current line. - renderLine(OS, {*LI, LI.line_number()}, LCI->getWrappedSegment(), - LCI->getLineSegments(), ExpansionColumn, ViewDepth); + renderLine(OS, {*LI, LI.line_number()}, *LCI, ExpansionColumn, ViewDepth); // Show the region markers. if (shouldRenderRegionMarkers(LCI->getLineSegments())) - renderRegionMarkers(OS, LCI->getLineSegments(), ViewDepth); + renderRegionMarkers(OS, *LCI, ViewDepth); // Show the expansions and instantiations for this line. bool RenderedSubView = false; @@ -235,9 +234,8 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, // this subview. if (RenderedSubView) { ExpansionColumn = NextESV->getStartCol(); - renderExpansionSite(OS, {*LI, LI.line_number()}, - LCI->getWrappedSegment(), LCI->getLineSegments(), - ExpansionColumn, ViewDepth); + renderExpansionSite(OS, {*LI, LI.line_number()}, *LCI, ExpansionColumn, + ViewDepth); renderViewDivider(OS, ViewDepth + 1); } diff --git a/tools/llvm-cov/SourceCoverageView.h b/tools/llvm-cov/SourceCoverageView.h index 24080284d8b..501c17d35ba 100644 --- a/tools/llvm-cov/SourceCoverageView.h +++ b/tools/llvm-cov/SourceCoverageView.h @@ -179,8 +179,7 @@ protected: /// \brief Render a source line with highlighting. virtual void renderLine(raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, + const LineCoverageStats &LCS, unsigned ExpansionCol, unsigned ViewDepth) = 0; /// \brief Render the line's execution count column. @@ -192,15 +191,14 @@ protected: /// \brief Render all the region's execution counts on a line. virtual void renderRegionMarkers(raw_ostream &OS, - CoverageSegmentArray Segments, + const LineCoverageStats &Line, unsigned ViewDepth) = 0; /// \brief Render the site of an expansion. - virtual void - renderExpansionSite(raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, - unsigned ViewDepth) = 0; + virtual void renderExpansionSite(raw_ostream &OS, LineRef L, + const LineCoverageStats &LCS, + unsigned ExpansionCol, + unsigned ViewDepth) = 0; /// \brief Render an expansion view and any nested views. virtual void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, diff --git a/tools/llvm-cov/SourceCoverageViewHTML.cpp b/tools/llvm-cov/SourceCoverageViewHTML.cpp index 3372e975e4d..626016f0e49 100644 --- a/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -468,9 +468,9 @@ void SourceCoverageViewHTML::renderViewDivider(raw_ostream &, unsigned) { // The table-based output makes view dividers unnecessary. } -void SourceCoverageViewHTML::renderLine( - raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned) { +void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L, + const LineCoverageStats &LCS, + unsigned ExpansionCol, unsigned) { StringRef Line = L.Line; unsigned LineNo = L.LineNo; @@ -482,6 +482,7 @@ void SourceCoverageViewHTML::renderLine( // at the end of the line. Both are required but may be empty. SmallVector Snippets; + CoverageSegmentArray Segments = LCS.getLineSegments(); unsigned LCol = 1; auto Snip = [&](unsigned Start, unsigned Len) { @@ -518,7 +519,7 @@ void SourceCoverageViewHTML::renderLine( return S && S->HasCount && S->Count == 0; }; - if (CheckIfUncovered(WrappedSegment)) { + if (CheckIfUncovered(LCS.getWrappedSegment())) { Color = "red"; if (!Snippets[0].empty()) Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size()); @@ -605,16 +606,17 @@ void SourceCoverageViewHTML::renderLineNumberColumn(raw_ostream &OS, } void SourceCoverageViewHTML::renderRegionMarkers(raw_ostream &, - CoverageSegmentArray, + const LineCoverageStats &Line, unsigned) { // Region markers are rendered in-line using tooltips. } -void SourceCoverageViewHTML::renderExpansionSite( - raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) { +void SourceCoverageViewHTML::renderExpansionSite(raw_ostream &OS, LineRef L, + const LineCoverageStats &LCS, + unsigned ExpansionCol, + unsigned ViewDepth) { // Render the line containing the expansion site. No extra formatting needed. - renderLine(OS, L, WrappedSegment, Segments, ExpansionCol, ViewDepth); + renderLine(OS, L, LCS, ExpansionCol, ViewDepth); } void SourceCoverageViewHTML::renderExpansionView(raw_ostream &OS, diff --git a/tools/llvm-cov/SourceCoverageViewHTML.h b/tools/llvm-cov/SourceCoverageViewHTML.h index 978a75aeced..4026aad3f73 100644 --- a/tools/llvm-cov/SourceCoverageViewHTML.h +++ b/tools/llvm-cov/SourceCoverageViewHTML.h @@ -57,14 +57,11 @@ class SourceCoverageViewHTML : public SourceCoverageView { void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override; - void renderLine(raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, - unsigned ViewDepth) override; + void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS, + unsigned ExpansionCol, unsigned ViewDepth) override; void renderExpansionSite(raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, + const LineCoverageStats &LCS, unsigned ExpansionCol, unsigned ViewDepth) override; void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, @@ -78,7 +75,7 @@ class SourceCoverageViewHTML : public SourceCoverageView { void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override; - void renderRegionMarkers(raw_ostream &OS, CoverageSegmentArray Segments, + void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line, unsigned ViewDepth) override; void renderTitle(raw_ostream &OS, StringRef Title) override; diff --git a/tools/llvm-cov/SourceCoverageViewText.cpp b/tools/llvm-cov/SourceCoverageViewText.cpp index 6990ed0f160..83d228e3670 100644 --- a/tools/llvm-cov/SourceCoverageViewText.cpp +++ b/tools/llvm-cov/SourceCoverageViewText.cpp @@ -94,12 +94,14 @@ void SourceCoverageViewText::renderViewDivider(raw_ostream &OS, OS << '\n'; } -void SourceCoverageViewText::renderLine( - raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) { +void SourceCoverageViewText::renderLine(raw_ostream &OS, LineRef L, + const LineCoverageStats &LCS, + unsigned ExpansionCol, + unsigned ViewDepth) { StringRef Line = L.Line; unsigned LineNumber = L.LineNo; + auto *WrappedSegment = LCS.getWrappedSegment(); + CoverageSegmentArray Segments = LCS.getLineSegments(); Optional Highlight; SmallVector, 2> HighlightedRanges; @@ -168,11 +170,14 @@ void SourceCoverageViewText::renderLineNumberColumn(raw_ostream &OS, OS.indent(LineNumberColumnWidth - Str.size()) << Str << '|'; } -void SourceCoverageViewText::renderRegionMarkers( - raw_ostream &OS, CoverageSegmentArray Segments, unsigned ViewDepth) { +void SourceCoverageViewText::renderRegionMarkers(raw_ostream &OS, + const LineCoverageStats &Line, + unsigned ViewDepth) { renderLinePrefix(OS, ViewDepth); OS.indent(getCombinedColumnWidth(getOptions())); + CoverageSegmentArray Segments = Line.getLineSegments(); + // Just consider the segments which start *and* end on this line. if (Segments.size() > 1) Segments = Segments.drop_back(); @@ -196,12 +201,13 @@ void SourceCoverageViewText::renderRegionMarkers( OS << '\n'; } -void SourceCoverageViewText::renderExpansionSite( - raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) { +void SourceCoverageViewText::renderExpansionSite(raw_ostream &OS, LineRef L, + const LineCoverageStats &LCS, + unsigned ExpansionCol, + unsigned ViewDepth) { renderLinePrefix(OS, ViewDepth); OS.indent(getCombinedColumnWidth(getOptions()) + (ViewDepth == 0 ? 0 : 1)); - renderLine(OS, L, WrappedSegment, Segments, ExpansionCol, ViewDepth); + renderLine(OS, L, LCS, ExpansionCol, ViewDepth); } void SourceCoverageViewText::renderExpansionView(raw_ostream &OS, diff --git a/tools/llvm-cov/SourceCoverageViewText.h b/tools/llvm-cov/SourceCoverageViewText.h index 5cf7caf79da..cf96aaf5d8d 100644 --- a/tools/llvm-cov/SourceCoverageViewText.h +++ b/tools/llvm-cov/SourceCoverageViewText.h @@ -48,14 +48,11 @@ class SourceCoverageViewText : public SourceCoverageView { void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override; - void renderLine(raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, - unsigned ViewDepth) override; + void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS, + unsigned ExpansionCol, unsigned ViewDepth) override; void renderExpansionSite(raw_ostream &OS, LineRef L, - const coverage::CoverageSegment *WrappedSegment, - CoverageSegmentArray Segments, unsigned ExpansionCol, + const LineCoverageStats &LCS, unsigned ExpansionCol, unsigned ViewDepth) override; void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, @@ -69,7 +66,7 @@ class SourceCoverageViewText : public SourceCoverageView { void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override; - void renderRegionMarkers(raw_ostream &OS, CoverageSegmentArray Segments, + void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line, unsigned ViewDepth) override; void renderTitle(raw_ostream &OS, StringRef Title) override;