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 Error emitJavaScript(); 42 void emitReportHeader(raw_ostream &OSRef, const std::string &Title); 43 44 private: 45 void emitFileSummary(raw_ostream &OS, StringRef SF, 46 const FileCoverageSummary &FCS, 47 bool IsTotals = false) const; 48 std::string buildLinkToFile(StringRef SF, 49 const FileCoverageSummary &FCS) const; 50 }; 51 52 /// A coverage printer for html output, but generates index files in every 53 /// subdirectory to show a hierarchical view. 54 class CoveragePrinterHTMLDirectory : public CoveragePrinterHTML { 55 public: 56 using CoveragePrinterHTML::CoveragePrinterHTML; 57 58 Error createIndexFile(ArrayRef<std::string> SourceFiles, 59 const coverage::CoverageMapping &Coverage, 60 const CoverageFiltersMatchAll &Filters) override; 61 62 private: 63 struct Reporter; 64 }; 65 66 /// A code coverage view which supports html-based rendering. 67 class SourceCoverageViewHTML : public SourceCoverageView { 68 void renderViewHeader(raw_ostream &OS) override; 69 70 void renderViewFooter(raw_ostream &OS) override; 71 72 void renderSourceName(raw_ostream &OS, bool WholeFile) override; 73 74 void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override; 75 76 void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override; 77 78 void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override; 79 80 void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS, 81 unsigned ExpansionCol, unsigned ViewDepth) override; 82 83 void renderExpansionSite(raw_ostream &OS, LineRef L, 84 const LineCoverageStats &LCS, unsigned ExpansionCol, 85 unsigned ViewDepth) override; 86 87 void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, 88 unsigned ViewDepth) override; 89 90 void renderBranchView(raw_ostream &OS, BranchView &BRV, 91 unsigned ViewDepth) override; 92 93 void renderMCDCView(raw_ostream &OS, MCDCView &BRV, 94 unsigned ViewDepth) override; 95 96 void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, 97 unsigned ViewDepth) override; 98 99 void renderLineCoverageColumn(raw_ostream &OS, 100 const LineCoverageStats &Line) override; 101 102 void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override; 103 104 void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line, 105 unsigned ViewDepth) override; 106 107 void renderTitle(raw_ostream &OS, StringRef Title) override; 108 109 void renderTableHeader(raw_ostream &OS, 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