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 | struct FileCoverageSummary; |
23 | |
24 | /// A coverage printer for html output. |
25 | class CoveragePrinterHTML : public CoveragePrinter { |
26 | public: |
27 | Expected<OwnedStream> createViewFile(StringRef Path, |
28 | bool InToplevel) override; |
29 | |
30 | void closeViewFile(OwnedStream OS) override; |
31 | |
32 | Error createIndexFile(ArrayRef<std::string> SourceFiles, |
33 | const coverage::CoverageMapping &Coverage, |
34 | const CoverageFiltersMatchAll &Filters) override; |
35 | |
36 | CoveragePrinterHTML(const CoverageViewOptions &Opts) |
37 | : CoveragePrinter(Opts) {} |
38 | |
39 | protected: |
40 | Error emitStyleSheet(); |
41 | void (raw_ostream &OSRef, const std::string &Title); |
42 | |
43 | private: |
44 | void emitFileSummary(raw_ostream &OS, StringRef SF, |
45 | const FileCoverageSummary &FCS, |
46 | bool IsTotals = false) const; |
47 | std::string buildLinkToFile(StringRef SF, |
48 | const FileCoverageSummary &FCS) const; |
49 | }; |
50 | |
51 | /// A coverage printer for html output, but generates index files in every |
52 | /// subdirectory to show a hierarchical view. |
53 | class CoveragePrinterHTMLDirectory : public CoveragePrinterHTML { |
54 | public: |
55 | using CoveragePrinterHTML::CoveragePrinterHTML; |
56 | |
57 | Error createIndexFile(ArrayRef<std::string> SourceFiles, |
58 | const coverage::CoverageMapping &Coverage, |
59 | const CoverageFiltersMatchAll &Filters) override; |
60 | |
61 | private: |
62 | struct Reporter; |
63 | }; |
64 | |
65 | /// A code coverage view which supports html-based rendering. |
66 | class SourceCoverageViewHTML : public SourceCoverageView { |
67 | void (raw_ostream &OS) override; |
68 | |
69 | void (raw_ostream &OS) override; |
70 | |
71 | void renderSourceName(raw_ostream &OS, bool WholeFile) override; |
72 | |
73 | void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override; |
74 | |
75 | void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override; |
76 | |
77 | void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override; |
78 | |
79 | void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS, |
80 | unsigned ExpansionCol, unsigned ViewDepth) override; |
81 | |
82 | void renderExpansionSite(raw_ostream &OS, LineRef L, |
83 | const LineCoverageStats &LCS, unsigned ExpansionCol, |
84 | unsigned ViewDepth) override; |
85 | |
86 | void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, |
87 | unsigned ViewDepth) override; |
88 | |
89 | void renderBranchView(raw_ostream &OS, BranchView &BRV, |
90 | unsigned ViewDepth) override; |
91 | |
92 | void renderMCDCView(raw_ostream &OS, MCDCView &BRV, |
93 | unsigned ViewDepth) override; |
94 | |
95 | void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, |
96 | unsigned ViewDepth) override; |
97 | |
98 | void renderLineCoverageColumn(raw_ostream &OS, |
99 | const LineCoverageStats &Line) override; |
100 | |
101 | void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override; |
102 | |
103 | void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line, |
104 | unsigned ViewDepth) override; |
105 | |
106 | void renderTitle(raw_ostream &OS, StringRef Title) override; |
107 | |
108 | void (raw_ostream &OS, unsigned FirstUncoveredLineNo, |
109 | unsigned IndentLevel) override; |
110 | |
111 | public: |
112 | SourceCoverageViewHTML(StringRef SourceName, const MemoryBuffer &File, |
113 | const CoverageViewOptions &Options, |
114 | coverage::CoverageData &&CoverageInfo) |
115 | : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) { |
116 | } |
117 | }; |
118 | |
119 | } // namespace llvm |
120 | |
121 | #endif // LLVM_COV_SOURCECOVERAGEVIEWHTML_H |
122 | |