diff --git a/test/tools/llvm-cov/showProjectSummary.cpp b/test/tools/llvm-cov/showProjectSummary.cpp index a2c1dee0d3f..b3329145743 100644 --- a/test/tools/llvm-cov/showProjectSummary.cpp +++ b/test/tools/llvm-cov/showProjectSummary.cpp @@ -36,11 +36,8 @@ int main(int argc, char ** argv) { // HTML: Code Coverage Report // HTML:
Source: -// HTML-FILE: showProjectSummary.cpp-// HTML-FILE:
Binary: -// HTML-FILE: showProjectSummary.covmapping-// HTML-FUNCTION:
Function: main+// HTML-FILE:
Source: {{.*}}showProjectSummary.cpp (Binary: showProjectSummary.covmapping)+// HTML-FUNCTION:
main// HTML-UNCOVEREDLINE: Go to first unexecuted line // HTML-HEADER:
Line No.
Count
[[@LINE-44]]
0
// HTML-ALL: [[@LINE-44]] 2 } -// HTML-SHARED:+// HTML-SHARED:Function: _Z4funcIbEiT_// HTML-SHARED:_Z4funcIbEiT_ [[@LINE-53]] 1 int func(T x) { // HTML-SHARED: [[@LINE-53]] 1 if(x) // HTML-SHARED: [[@LINE-53]] 1 ret @@ -65,7 +65,7 @@ int main() { // ALL: [[@LINE]]| 1|int main() { // HTML-SHARED: [[@LINE-53]] 0 // HTML-SHARED: [[@LINE-53]] 1 } -// HTML-ALL:+// HTML-ALL:Function: _Z4funcIiEiT_// HTML-FILTER-NOT:_Z4funcIiEiT__Z4funcIiEiT_// HTML-ALL:
[[@LINE-63]] 1 int func(T x) { // HTML-ALL: [[@LINE-63]] 1 if(x) diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index 9755b6008d5..e5b9b69b0e3 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -210,9 +210,9 @@ CodeCoverageTool::createFunctionView(const FunctionRecord &Function, return nullptr; auto Expansions = FunctionCoverage.getExpansions(); - auto View = SourceCoverageView::create( - getSymbolForHumans(Function.Name), SourceBuffer.get(), ViewOpts, - std::move(FunctionCoverage), /*FunctionView=*/true); + auto View = SourceCoverageView::create(getSymbolForHumans(Function.Name), + SourceBuffer.get(), ViewOpts, + std::move(FunctionCoverage)); attachExpansionSubViews(*View, Expansions, Coverage); return View; @@ -238,7 +238,7 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile, auto SubViewExpansions = SubViewCoverage.getExpansions(); auto SubView = SourceCoverageView::create( getSymbolForHumans(Function->Name), SourceBuffer.get(), ViewOpts, - std::move(SubViewCoverage), /*FunctionView=*/true); + std::move(SubViewCoverage)); attachExpansionSubViews(*SubView, SubViewExpansions, Coverage); if (SubView) { diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp index 47980ab0952..cfcaf2e042e 100644 --- a/tools/llvm-cov/SourceCoverageView.cpp +++ b/tools/llvm-cov/SourceCoverageView.cpp @@ -129,26 +129,28 @@ bool SourceCoverageView::hasSubViews() const { std::unique_ptrSourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File, const CoverageViewOptions &Options, - coverage::CoverageData &&CoverageInfo, - bool FunctionView) { + coverage::CoverageData &&CoverageInfo) { switch (Options.Format) { case CoverageViewOptions::OutputFormat::Text: return llvm::make_unique ( - SourceName, File, Options, std::move(CoverageInfo), FunctionView); + SourceName, File, Options, std::move(CoverageInfo)); case CoverageViewOptions::OutputFormat::HTML: return llvm::make_unique ( - SourceName, File, Options, std::move(CoverageInfo), FunctionView); + SourceName, File, Options, std::move(CoverageInfo)); } llvm_unreachable("Unknown coverage output format!"); } -std::string SourceCoverageView::getNativeSourceName() const { - std::string SourceFile = isFunctionView() ? "Function: " : "Source: "; - SourceFile += getSourceName().str(); - SmallString<128> SourceText(SourceFile); +std::string SourceCoverageView::getSourceName() const { + SmallString<128> SourceText(SourceName); sys::path::remove_dots(SourceText, /*remove_dot_dots=*/true); sys::path::native(SourceText); - return SourceText.c_str(); + return SourceText.str(); +} + +std::string SourceCoverageView::getVerboseSourceName() const { + return "Source: " + getSourceName() + " (Binary: " + + sys::path::filename(getOptions().ObjectFilename).str() + ")"; } void SourceCoverageView::addExpansion( diff --git a/tools/llvm-cov/SourceCoverageView.h b/tools/llvm-cov/SourceCoverageView.h index 63c5b65a207..f2d5d6142cf 100644 --- a/tools/llvm-cov/SourceCoverageView.h +++ b/tools/llvm-cov/SourceCoverageView.h @@ -172,9 +172,6 @@ class SourceCoverageView { /// on display. std::vector InstantiationSubViews; - /// Specifies whether or not the view is a function view. - bool FunctionView; - /// Get the first uncovered line number for the source file. unsigned getFirstUncoveredLineNo(); @@ -264,24 +261,24 @@ protected: SourceCoverageView(StringRef SourceName, const MemoryBuffer &File, const CoverageViewOptions &Options, - coverage::CoverageData &&CoverageInfo, bool FunctionView) + coverage::CoverageData &&CoverageInfo) : SourceName(SourceName), File(File), Options(Options), - CoverageInfo(std::move(CoverageInfo)), FunctionView(FunctionView) {} + CoverageInfo(std::move(CoverageInfo)) {} public: static std::unique_ptr create(StringRef SourceName, const MemoryBuffer &File, const CoverageViewOptions &Options, - coverage::CoverageData &&CoverageInfo, bool FucntionView = false); + coverage::CoverageData &&CoverageInfo); virtual ~SourceCoverageView() {} - StringRef getSourceName() const { return SourceName; } - /// \brief Return the source name formatted for the host OS. - std::string getNativeSourceName() const; + std::string getSourceName() const; - bool isFunctionView() const { return FunctionView; } + /// \brief Return a verbose description of the source name and the binary it + /// corresponds to. + std::string getVerboseSourceName() const; const CoverageViewOptions &getOptions() const { return Options; } diff --git a/tools/llvm-cov/SourceCoverageViewHTML.cpp b/tools/llvm-cov/SourceCoverageViewHTML.cpp index 52e594f5ff1..ca3f350ff7a 100644 --- a/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -341,12 +341,10 @@ void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) { void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile, unsigned FirstUncoveredLineNo) { OS << BeginSourceNameDiv; - // Render the source name for the view. - OS << tag("pre", escape(getNativeSourceName(), getOptions())); + std::string ViewInfo = escape( + WholeFile ? getVerboseSourceName() : getSourceName(), getOptions()); + OS << tag("pre", ViewInfo); if (WholeFile) { - // Render the object file name for the view. - OS << tag("pre", - escape("Binary: " + getOptions().ObjectFilename, getOptions())); // Render the "Go to first unexecuted line" link for the view. if (FirstUncoveredLineNo != 0) { // The file is not fully covered std::string LinkText = diff --git a/tools/llvm-cov/SourceCoverageViewHTML.h b/tools/llvm-cov/SourceCoverageViewHTML.h index 42fec6fd31f..edbe7c41f25 100644 --- a/tools/llvm-cov/SourceCoverageViewHTML.h +++ b/tools/llvm-cov/SourceCoverageViewHTML.h @@ -78,10 +78,9 @@ class SourceCoverageViewHTML : public SourceCoverageView { public: SourceCoverageViewHTML(StringRef SourceName, const MemoryBuffer &File, const CoverageViewOptions &Options, - coverage::CoverageData &&CoverageInfo, - bool FunctionView) - : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo), - FunctionView) {} + coverage::CoverageData &&CoverageInfo) + : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) { + } }; } // namespace llvm diff --git a/tools/llvm-cov/SourceCoverageViewText.cpp b/tools/llvm-cov/SourceCoverageViewText.cpp index 6dec4c7aed5..3d2c067d0a4 100644 --- a/tools/llvm-cov/SourceCoverageViewText.cpp +++ b/tools/llvm-cov/SourceCoverageViewText.cpp @@ -65,12 +65,8 @@ void SourceCoverageViewText::renderViewFooter(raw_ostream &) {} void SourceCoverageViewText::renderSourceName(raw_ostream &OS, bool WholeFile, unsigned FirstUncoveredLineNo) { - getOptions().colored_ostream(OS, raw_ostream::CYAN) << getNativeSourceName() - << ":\n"; - if (WholeFile) { - getOptions().colored_ostream(OS, raw_ostream::CYAN) - << "Binary: " << getOptions().ObjectFilename << ":\n"; - } + std::string ViewInfo = WholeFile ? getVerboseSourceName() : getSourceName(); + getOptions().colored_ostream(OS, raw_ostream::CYAN) << ViewInfo << ":\n"; } void SourceCoverageViewText::renderLinePrefix(raw_ostream &OS, diff --git a/tools/llvm-cov/SourceCoverageViewText.h b/tools/llvm-cov/SourceCoverageViewText.h index dd78d3ad73c..fe2642a2b45 100644 --- a/tools/llvm-cov/SourceCoverageViewText.h +++ b/tools/llvm-cov/SourceCoverageViewText.h @@ -78,10 +78,9 @@ class SourceCoverageViewText : public SourceCoverageView { public: SourceCoverageViewText(StringRef SourceName, const MemoryBuffer &File, const CoverageViewOptions &Options, - coverage::CoverageData &&CoverageInfo, - bool FunctionView) - : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo), - FunctionView) {} + coverage::CoverageData &&CoverageInfo) + : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) { + } }; } // namespace llvm