[llvm] r316108 - [llvm-cov] Pass LineCoverageStats in SourceCoverageView. NFC.

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 11:52:29 PDT 2017


Author: vedantk
Date: Wed Oct 18 11:52:28 2017
New Revision: 316108

URL: http://llvm.org/viewvc/llvm-project?rev=316108&view=rev
Log:
[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.

Modified:
    llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.h
    llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h
    llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=316108&r1=316107&r2=316108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Wed Oct 18 11:52:28 2017
@@ -218,12 +218,11 @@ void SourceCoverageView::print(raw_ostre
       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_ostre
       // 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);
       }
 

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=316108&r1=316107&r2=316108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Wed Oct 18 11:52:28 2017
@@ -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,

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp?rev=316108&r1=316107&r2=316108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp Wed Oct 18 11:52:28 2017
@@ -468,9 +468,9 @@ void SourceCoverageViewHTML::renderViewD
   // 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<std::string, 8> 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::renderLineN
 }
 
 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,

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h?rev=316108&r1=316107&r2=316108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h Wed Oct 18 11:52:28 2017
@@ -57,14 +57,11 @@ class SourceCoverageViewHTML : public So
 
   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 So
 
   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;

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp?rev=316108&r1=316107&r2=316108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp Wed Oct 18 11:52:28 2017
@@ -94,12 +94,14 @@ void SourceCoverageViewText::renderViewD
   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<raw_ostream::Colors> Highlight;
   SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
@@ -168,11 +170,14 @@ void SourceCoverageViewText::renderLineN
   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::renderRegio
   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,

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h?rev=316108&r1=316107&r2=316108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h Wed Oct 18 11:52:28 2017
@@ -48,14 +48,11 @@ class SourceCoverageViewText : public So
 
   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 So
 
   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;




More information about the llvm-commits mailing list