1 //===- SourceCoverageViewHTML.h - A html code coverage view ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file This file defines the interface to the html coverage renderer.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_COV_SOURCECOVERAGEVIEWHTML_H
14 #define LLVM_COV_SOURCECOVERAGEVIEWHTML_H
15 
16 #include "SourceCoverageView.h"
17 
18 namespace llvm {
19 
20 using namespace coverage;
21 
22 class ThreadPool;
23 
24 struct FileCoverageSummary;
25 
26 /// A coverage printer for html output.
27 class CoveragePrinterHTML : public CoveragePrinter {
28 public:
29   Expected<OwnedStream> createViewFile(StringRef Path,
30                                        bool InToplevel) override;
31 
32   void closeViewFile(OwnedStream OS) override;
33 
34   Error createIndexFile(ArrayRef<std::string> SourceFiles,
35                         const coverage::CoverageMapping &Coverage,
36                         const CoverageFiltersMatchAll &Filters) override;
37 
38   CoveragePrinterHTML(const CoverageViewOptions &Opts)
39       : CoveragePrinter(Opts) {}
40 
41 protected:
42   Error emitStyleSheet();
43   void emitReportHeader(raw_ostream &OSRef, const std::string &Title);
44 
45 private:
46   void emitFileSummary(raw_ostream &OS, StringRef SF,
47                        const FileCoverageSummary &FCS,
48                        bool IsTotals = false) const;
49   std::string buildLinkToFile(StringRef SF,
50                               const FileCoverageSummary &FCS) const;
51 };
52 
53 /// A coverage printer for html output, but generates index files in every
54 /// subdirectory to show a hierarchical view.
55 class CoveragePrinterHTMLDirectory : public CoveragePrinterHTML {
56 public:
57   using CoveragePrinterHTML::CoveragePrinterHTML;
58 
59   Error createIndexFile(ArrayRef<std::string> SourceFiles,
60                         const coverage::CoverageMapping &Coverage,
61                         const CoverageFiltersMatchAll &Filters) override;
62 
63 private:
64   struct Reporter;
65 };
66 
67 /// A code coverage view which supports html-based rendering.
68 class SourceCoverageViewHTML : public SourceCoverageView {
69   void renderViewHeader(raw_ostream &OS) override;
70 
71   void renderViewFooter(raw_ostream &OS) override;
72 
73   void renderSourceName(raw_ostream &OS, bool WholeFile) override;
74 
75   void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override;
76 
77   void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override;
78 
79   void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override;
80 
81   void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS,
82                   unsigned ExpansionCol, unsigned ViewDepth) override;
83 
84   void renderExpansionSite(raw_ostream &OS, LineRef L,
85                            const LineCoverageStats &LCS, unsigned ExpansionCol,
86                            unsigned ViewDepth) override;
87 
88   void renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
89                            unsigned ViewDepth) override;
90 
91   void renderBranchView(raw_ostream &OS, BranchView &BRV,
92                         unsigned ViewDepth) override;
93 
94   void renderMCDCView(raw_ostream &OS, MCDCView &BRV,
95                       unsigned ViewDepth) override;
96 
97   void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV,
98                                unsigned ViewDepth) override;
99 
100   void renderLineCoverageColumn(raw_ostream &OS,
101                                 const LineCoverageStats &Line) override;
102 
103   void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override;
104 
105   void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line,
106                            unsigned ViewDepth) override;
107 
108   void renderTitle(raw_ostream &OS, StringRef Title) override;
109 
110   void renderTableHeader(raw_ostream &OS, unsigned FirstUncoveredLineNo,
111                          unsigned IndentLevel) override;
112 
113 public:
114   SourceCoverageViewHTML(StringRef SourceName, const MemoryBuffer &File,
115                          const CoverageViewOptions &Options,
116                          coverage::CoverageData &&CoverageInfo)
117       : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) {
118   }
119 };
120 
121 } // namespace llvm
122 
123 #endif // LLVM_COV_SOURCECOVERAGEVIEWHTML_H
124