[llvm] r273634 - [llvm-cov] Add SourceNames to SourceCoverageViews, NFC

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 23 17:34:51 PDT 2016


Author: vedantk
Date: Thu Jun 23 19:34:51 2016
New Revision: 273634

URL: http://llvm.org/viewvc/llvm-project?rev=273634&view=rev
Log:
[llvm-cov] Add SourceNames to SourceCoverageViews, NFC

A SourceName can be a file or a function. It makes sense to attach this
information to a SourceCoverageView, seeing as views (1) already point
to the text corresponding to the relevant source code and (2) are
already used to render that text along with the SourceNames.

This is a nice cleanup which is independent of the upcoming html patch.

While we're at it, document the fields in SourceCoverageView.

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

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=273634&r1=273633&r2=273634&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Thu Jun 23 19:34:51 2016
@@ -133,7 +133,8 @@ CodeCoverageTool::attachExpansionSubView
 
     auto SubViewExpansions = ExpansionCoverage.getExpansions();
     auto SubView = llvm::make_unique<SourceCoverageView>(
-        SourceBuffer.get(), ViewOpts, std::move(ExpansionCoverage));
+        Expansion.Function.Name, SourceBuffer.get(), ViewOpts,
+        std::move(ExpansionCoverage));
     attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
     View.addExpansion(Expansion.Region, std::move(SubView));
   }
@@ -151,7 +152,7 @@ CodeCoverageTool::createFunctionView(con
 
   auto Expansions = FunctionCoverage.getExpansions();
   auto View = llvm::make_unique<SourceCoverageView>(
-      SourceBuffer.get(), ViewOpts, std::move(FunctionCoverage));
+      Function.Name, SourceBuffer.get(), ViewOpts, std::move(FunctionCoverage));
   attachExpansionSubViews(*View, Expansions, Coverage);
 
   return View;
@@ -169,14 +170,15 @@ CodeCoverageTool::createSourceFileView(S
 
   auto Expansions = FileCoverage.getExpansions();
   auto View = llvm::make_unique<SourceCoverageView>(
-      SourceBuffer.get(), ViewOpts, std::move(FileCoverage));
+      SourceFile, SourceBuffer.get(), ViewOpts, std::move(FileCoverage));
   attachExpansionSubViews(*View, Expansions, Coverage);
 
   for (auto Function : Coverage.getInstantiations(SourceFile)) {
     auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
     auto SubViewExpansions = SubViewCoverage.getExpansions();
     auto SubView = llvm::make_unique<SourceCoverageView>(
-        SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
+        Function->Name, SourceBuffer.get(), ViewOpts,
+        std::move(SubViewCoverage));
     attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
 
     if (SubView) {
@@ -426,9 +428,7 @@ int CodeCoverageTool::show(int argc, con
         outs() << "\n";
         continue;
       }
-      ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << Function.Name
-                                                          << ":";
-      outs() << "\n";
+      mainView->renderSourceName(outs());
       mainView->render(outs(), /*WholeFile=*/false);
       outs() << "\n";
     }
@@ -452,10 +452,9 @@ int CodeCoverageTool::show(int argc, con
       continue;
     }
 
-    if (ShowFilenames) {
-      ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << SourceFile << ":";
-      outs() << "\n";
-    }
+    if (ShowFilenames)
+      mainView->renderSourceName(outs());
+
     mainView->render(outs(), /*Wholefile=*/true);
     if (SourceFiles.size() > 1)
       outs() << "\n";

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=273634&r1=273633&r2=273634&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Thu Jun 23 19:34:51 2016
@@ -250,9 +250,7 @@ void SourceCoverageView::render(raw_ostr
       OS << "\n";
       renderIndent(OS, NestedIndent);
       OS << ' ';
-      Options.colored_ostream(OS, raw_ostream::CYAN) << NextISV->FunctionName
-                                                     << ":";
-      OS << "\n";
+      NextISV->View->renderSourceName(OS);
       NextISV->View->render(OS, false, NestedIndent);
       RenderedSubView = true;
     }
@@ -262,3 +260,8 @@ void SourceCoverageView::render(raw_ostr
     }
   }
 }
+
+void SourceCoverageView::renderSourceName(raw_ostream &OS) {
+  getOptions().colored_ostream(OS, raw_ostream::CYAN) << getSourceName()
+                                                      << ":\n";
+}

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=273634&r1=273633&r2=273634&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Thu Jun 23 19:34:51 2016
@@ -101,10 +101,23 @@ struct LineCoverageStats {
 /// It can have embedded coverage views.
 class SourceCoverageView {
 private:
+  /// A function or file name.
+  StringRef SourceName;
+
+  /// A memory buffer backing the source on display.
   const MemoryBuffer &File;
+
+  /// Various options to guide the coverage renderer.
   const CoverageViewOptions &Options;
+
+  /// Complete coverage information about the source on display.
   coverage::CoverageData CoverageInfo;
+
+  /// A container for all expansions (e.g macros) in the source on display.
   std::vector<ExpansionView> ExpansionSubViews;
+
+  /// A container for all instantiations (e.g template functions) in the source
+  /// on display.
   std::vector<InstantiationView> InstantiationSubViews;
 
   /// \brief Render a source line with highlighting.
@@ -132,10 +145,13 @@ private:
   static const unsigned LineNumberColumnWidth = 5;
 
 public:
-  SourceCoverageView(const MemoryBuffer &File,
+  SourceCoverageView(StringRef SourceName, const MemoryBuffer &File,
                      const CoverageViewOptions &Options,
                      coverage::CoverageData &&CoverageInfo)
-      : File(File), Options(Options), CoverageInfo(std::move(CoverageInfo)) {}
+      : SourceName(SourceName), File(File), Options(Options),
+        CoverageInfo(std::move(CoverageInfo)) {}
+
+  StringRef getSourceName() const { return SourceName; }
 
   const CoverageViewOptions &getOptions() const { return Options; }
 
@@ -154,6 +170,9 @@ public:
   /// \brief Print the code coverage information for a specific
   /// portion of a source file to the output stream.
   void render(raw_ostream &OS, bool WholeFile, unsigned IndentLevel = 0);
+
+  /// \brief Print the source name corresponding to this view.
+  void renderSourceName(raw_ostream &OS);
 };
 
 } // namespace llvm




More information about the llvm-commits mailing list