xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewText.h (revision 5def4c47d4bd90b209b9b4a4ba9faec15846d8fd)
1 //===- SourceCoverageViewText.h - A text-based 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 text-based coverage renderer.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_COV_SOURCECOVERAGEVIEWTEXT_H
14 #define LLVM_COV_SOURCECOVERAGEVIEWTEXT_H
15 
16 #include "SourceCoverageView.h"
17 
18 namespace llvm {
19 
20 using namespace coverage;
21 
22 /// A coverage printer for text output.
23 class CoveragePrinterText : public CoveragePrinter {
24 public:
25   Expected<OwnedStream> createViewFile(StringRef Path,
26                                        bool InToplevel) override;
27 
28   void closeViewFile(OwnedStream OS) override;
29 
30   Error createIndexFile(ArrayRef<std::string> SourceFiles,
31                         const CoverageMapping &Coverage,
32                         const CoverageFiltersMatchAll &Filters) override;
33 
34   CoveragePrinterText(const CoverageViewOptions &Opts)
35       : CoveragePrinter(Opts) {}
36 };
37 
38 /// A code coverage view which supports text-based rendering.
39 class SourceCoverageViewText : public SourceCoverageView {
40   void renderViewHeader(raw_ostream &OS) override;
41 
42   void renderViewFooter(raw_ostream &OS) override;
43 
44   void renderSourceName(raw_ostream &OS, bool WholeFile) override;
45 
46   void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override;
47 
48   void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override;
49 
50   void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override;
51 
52   void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS,
53                   unsigned ExpansionCol, unsigned ViewDepth) override;
54 
55   void renderExpansionSite(raw_ostream &OS, LineRef L,
56                            const LineCoverageStats &LCS, unsigned ExpansionCol,
57                            unsigned ViewDepth) override;
58 
59   void renderExpansionView(raw_ostream &OS, ExpansionView &ESV,
60                            unsigned ViewDepth) override;
61 
62   void renderBranchView(raw_ostream &OS, BranchView &BRV,
63                         unsigned ViewDepth) override;
64 
65   void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV,
66                                unsigned ViewDepth) override;
67 
68   void renderLineCoverageColumn(raw_ostream &OS,
69                                 const LineCoverageStats &Line) override;
70 
71   void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override;
72 
73   void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line,
74                            unsigned ViewDepth) override;
75 
76   void renderTitle(raw_ostream &OS, StringRef Title) override;
77 
78   void renderTableHeader(raw_ostream &OS, unsigned FirstUncoveredLineNo,
79                          unsigned IndentLevel) override;
80 
81 public:
82   SourceCoverageViewText(StringRef SourceName, const MemoryBuffer &File,
83                          const CoverageViewOptions &Options,
84                          CoverageData &&CoverageInfo)
85       : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) {
86   }
87 };
88 
89 } // namespace llvm
90 
91 #endif // LLVM_COV_SOURCECOVERAGEVIEWTEXT_H
92