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 private: 40 void emitFileSummary(raw_ostream &OS, StringRef SF, 41 const FileCoverageSummary &FCS, 42 bool IsTotals = false) const; 43 std::string buildLinkToFile(StringRef SF, 44 const FileCoverageSummary &FCS) const; 45 }; 46 47 /// A code coverage view which supports html-based rendering. 48 class SourceCoverageViewHTML : public SourceCoverageView { 49 void renderViewHeader(raw_ostream &OS) override; 50 51 void renderViewFooter(raw_ostream &OS) override; 52 53 void renderSourceName(raw_ostream &OS, bool WholeFile) override; 54 55 void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override; 56 57 void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override; 58 59 void renderViewDivider(raw_ostream &OS, unsigned ViewDepth) override; 60 61 void renderLine(raw_ostream &OS, LineRef L, const LineCoverageStats &LCS, 62 unsigned ExpansionCol, unsigned ViewDepth) override; 63 64 void renderExpansionSite(raw_ostream &OS, LineRef L, 65 const LineCoverageStats &LCS, unsigned ExpansionCol, 66 unsigned ViewDepth) override; 67 68 void renderExpansionView(raw_ostream &OS, ExpansionView &ESV, 69 unsigned ViewDepth) override; 70 71 void renderBranchView(raw_ostream &OS, BranchView &BRV, 72 unsigned ViewDepth) override; 73 74 void renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, 75 unsigned ViewDepth) override; 76 77 void renderLineCoverageColumn(raw_ostream &OS, 78 const LineCoverageStats &Line) override; 79 80 void renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) override; 81 82 void renderRegionMarkers(raw_ostream &OS, const LineCoverageStats &Line, 83 unsigned ViewDepth) override; 84 85 void renderTitle(raw_ostream &OS, StringRef Title) override; 86 87 void renderTableHeader(raw_ostream &OS, unsigned FirstUncoveredLineNo, 88 unsigned IndentLevel) override; 89 90 public: 91 SourceCoverageViewHTML(StringRef SourceName, const MemoryBuffer &File, 92 const CoverageViewOptions &Options, 93 coverage::CoverageData &&CoverageInfo) 94 : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) { 95 } 96 }; 97 98 } // namespace llvm 99 100 #endif // LLVM_COV_SOURCECOVERAGEVIEWHTML_H 101