1//===- SourceCoverageViewHTML.cpp - 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 implements the html coverage renderer.
10///
11//===----------------------------------------------------------------------===//
12
13#include "CoverageReport.h"
14#include "SourceCoverageViewHTML.h"
15#include "llvm/ADT/Optional.h"
16#include "llvm/ADT/SmallString.h"
17#include "llvm/ADT/StringExtras.h"
18#include "llvm/Support/Format.h"
19#include "llvm/Support/Path.h"
20
21using namespace llvm;
22
23namespace {
24
25// Return a string with the special characters in \p Str escaped.
26std::string escape(StringRef Str, const CoverageViewOptions &Opts) {
27  std::string TabExpandedResult;
28  unsigned ColNum = 0; // Record the column number.
29  for (char C : Str) {
30    if (C == '\t') {
31      // Replace '\t' with up to TabSize spaces.
32      unsigned NumSpaces = Opts.TabSize - (ColNum % Opts.TabSize);
33      for (unsigned I = 0; I < NumSpaces; ++I)
34        TabExpandedResult += ' ';
35      ColNum += NumSpaces;
36    } else {
37      TabExpandedResult += C;
38      if (C == '\n' || C == '\r')
39        ColNum = 0;
40      else
41        ++ColNum;
42    }
43  }
44  std::string EscapedHTML;
45  {
46    raw_string_ostream OS{EscapedHTML};
47    printHTMLEscaped(TabExpandedResult, OS);
48  }
49  return EscapedHTML;
50}
51
52// Create a \p Name tag around \p Str, and optionally set its \p ClassName.
53std::string tag(const std::string &Name, const std::string &Str,
54                const std::string &ClassName = "") {
55  std::string Tag = "<" + Name;
56  if (!ClassName.empty())
57    Tag += " class='" + ClassName + "'";
58  return Tag + ">" + Str + "</" + Name + ">";
59}
60
61// Create an anchor to \p Link with the label \p Str.
62std::string a(const std::string &Link, const std::string &Str,
63              const std::string &TargetName = "") {
64  std::string Name = TargetName.empty() ? "" : ("name='" + TargetName + "' ");
65  return "<a " + Name + "href='" + Link + "'>" + Str + "</a>";
66}
67
68const char *BeginHeader =
69  "<head>"
70    "<meta name='viewport' content='width=device-width,initial-scale=1'>"
71    "<meta charset='UTF-8'>";
72
73const char *CSSForCoverage =
74    R"(.red {
75  background-color: #ffd0d0;
76}
77.cyan {
78  background-color: cyan;
79}
80body {
81  font-family: -apple-system, sans-serif;
82}
83pre {
84  margin-top: 0px !important;
85  margin-bottom: 0px !important;
86}
87.source-name-title {
88  padding: 5px 10px;
89  border-bottom: 1px solid #dbdbdb;
90  background-color: #eee;
91  line-height: 35px;
92}
93.centered {
94  display: table;
95  margin-left: left;
96  margin-right: auto;
97  border: 1px solid #dbdbdb;
98  border-radius: 3px;
99}
100.expansion-view {
101  background-color: rgba(0, 0, 0, 0);
102  margin-left: 0px;
103  margin-top: 5px;
104  margin-right: 5px;
105  margin-bottom: 5px;
106  border: 1px solid #dbdbdb;
107  border-radius: 3px;
108}
109table {
110  border-collapse: collapse;
111}
112.light-row {
113  background: #ffffff;
114  border: 1px solid #dbdbdb;
115}
116.light-row-bold {
117  background: #ffffff;
118  border: 1px solid #dbdbdb;
119  font-weight: bold;
120}
121.column-entry {
122  text-align: left;
123}
124.column-entry-bold {
125  font-weight: bold;
126  text-align: left;
127}
128.column-entry-yellow {
129  text-align: left;
130  background-color: #ffffd0;
131}
132.column-entry-yellow:hover {
133  background-color: #fffff0;
134}
135.column-entry-red {
136  text-align: left;
137  background-color: #ffd0d0;
138}
139.column-entry-red:hover {
140  background-color: #fff0f0;
141}
142.column-entry-green {
143  text-align: left;
144  background-color: #d0ffd0;
145}
146.column-entry-green:hover {
147  background-color: #f0fff0;
148}
149.line-number {
150  text-align: right;
151  color: #aaa;
152}
153.covered-line {
154  text-align: right;
155  color: #0080ff;
156}
157.uncovered-line {
158  text-align: right;
159  color: #ff3300;
160}
161.tooltip {
162  position: relative;
163  display: inline;
164  background-color: #b3e6ff;
165  text-decoration: none;
166}
167.tooltip span.tooltip-content {
168  position: absolute;
169  width: 100px;
170  margin-left: -50px;
171  color: #FFFFFF;
172  background: #000000;
173  height: 30px;
174  line-height: 30px;
175  text-align: center;
176  visibility: hidden;
177  border-radius: 6px;
178}
179.tooltip span.tooltip-content:after {
180  content: '';
181  position: absolute;
182  top: 100%;
183  left: 50%;
184  margin-left: -8px;
185  width: 0; height: 0;
186  border-top: 8px solid #000000;
187  border-right: 8px solid transparent;
188  border-left: 8px solid transparent;
189}
190:hover.tooltip span.tooltip-content {
191  visibility: visible;
192  opacity: 0.8;
193  bottom: 30px;
194  left: 50%;
195  z-index: 999;
196}
197th, td {
198  vertical-align: top;
199  padding: 2px 8px;
200  border-collapse: collapse;
201  border-right: solid 1px #eee;
202  border-left: solid 1px #eee;
203  text-align: left;
204}
205td pre {
206  display: inline-block;
207}
208td:first-child {
209  border-left: none;
210}
211td:last-child {
212  border-right: none;
213}
214tr:hover {
215  background-color: #f0f0f0;
216}
217)";
218
219const char *EndHeader = "</head>";
220
221const char *BeginCenteredDiv = "<div class='centered'>";
222
223const char *EndCenteredDiv = "</div>";
224
225const char *BeginSourceNameDiv = "<div class='source-name-title'>";
226
227const char *EndSourceNameDiv = "</div>";
228
229const char *BeginCodeTD = "<td class='code'>";
230
231const char *EndCodeTD = "</td>";
232
233const char *BeginPre = "<pre>";
234
235const char *EndPre = "</pre>";
236
237const char *BeginExpansionDiv = "<div class='expansion-view'>";
238
239const char *EndExpansionDiv = "</div>";
240
241const char *BeginTable = "<table>";
242
243const char *EndTable = "</table>";
244
245const char *ProjectTitleTag = "h1";
246
247const char *ReportTitleTag = "h2";
248
249const char *CreatedTimeTag = "h4";
250
251std::string getPathToStyle(StringRef ViewPath) {
252  std::string PathToStyle = "";
253  std::string PathSep = sys::path::get_separator();
254  unsigned NumSeps = ViewPath.count(PathSep);
255  for (unsigned I = 0, E = NumSeps; I < E; ++I)
256    PathToStyle += ".." + PathSep;
257  return PathToStyle + "style.css";
258}
259
260void emitPrelude(raw_ostream &OS, const CoverageViewOptions &Opts,
261                 const std::string &PathToStyle = "") {
262  OS << "<!doctype html>"
263        "<html>"
264     << BeginHeader;
265
266  // Link to a stylesheet if one is available. Otherwise, use the default style.
267  if (PathToStyle.empty())
268    OS << "<style>" << CSSForCoverage << "</style>";
269  else
270    OS << "<link rel='stylesheet' type='text/css' href='"
271       << escape(PathToStyle, Opts) << "'>";
272
273  OS << EndHeader << "<body>";
274}
275
276void emitEpilog(raw_ostream &OS) {
277  OS << "</body>"
278     << "</html>";
279}
280
281} // anonymous namespace
282
283Expected<CoveragePrinter::OwnedStream>
284CoveragePrinterHTML::createViewFile(StringRef Path, bool InToplevel) {
285  auto OSOrErr = createOutputStream(Path, "html", InToplevel);
286  if (!OSOrErr)
287    return OSOrErr;
288
289  OwnedStream OS = std::move(OSOrErr.get());
290
291  if (!Opts.hasOutputDirectory()) {
292    emitPrelude(*OS.get(), Opts);
293  } else {
294    std::string ViewPath = getOutputPath(Path, "html", InToplevel);
295    emitPrelude(*OS.get(), Opts, getPathToStyle(ViewPath));
296  }
297
298  return std::move(OS);
299}
300
301void CoveragePrinterHTML::closeViewFile(OwnedStream OS) {
302  emitEpilog(*OS.get());
303}
304
305/// Emit column labels for the table in the index.
306static void emitColumnLabelsForIndex(raw_ostream &OS,
307                                     const CoverageViewOptions &Opts) {
308  SmallVector<std::string, 4> Columns;
309  Columns.emplace_back(tag("td", "Filename", "column-entry-bold"));
310  Columns.emplace_back(tag("td", "Function Coverage", "column-entry-bold"));
311  if (Opts.ShowInstantiationSummary)
312    Columns.emplace_back(
313        tag("td", "Instantiation Coverage", "column-entry-bold"));
314  Columns.emplace_back(tag("td", "Line Coverage", "column-entry-bold"));
315  if (Opts.ShowRegionSummary)
316    Columns.emplace_back(tag("td", "Region Coverage", "column-entry-bold"));
317  OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
318}
319
320std::string
321CoveragePrinterHTML::buildLinkToFile(StringRef SF,
322                                     const FileCoverageSummary &FCS) const {
323  SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name));
324  sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true);
325  sys::path::native(LinkTextStr);
326  std::string LinkText = escape(LinkTextStr, Opts);
327  std::string LinkTarget =
328      escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
329  return a(LinkTarget, LinkText);
330}
331
332/// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is
333/// false, link the summary to \p SF.
334void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
335                                          const FileCoverageSummary &FCS,
336                                          bool IsTotals) const {
337  SmallVector<std::string, 8> Columns;
338
339  // Format a coverage triple and add the result to the list of columns.
340  auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total,
341                                              float Pctg) {
342    std::string S;
343    {
344      raw_string_ostream RSO{S};
345      if (Total)
346        RSO << format("%*.2f", 7, Pctg) << "% ";
347      else
348        RSO << "- ";
349      RSO << '(' << Hit << '/' << Total << ')';
350    }
351    const char *CellClass = "column-entry-yellow";
352    if (Hit == Total)
353      CellClass = "column-entry-green";
354    else if (Pctg < 80.0)
355      CellClass = "column-entry-red";
356    Columns.emplace_back(tag("td", tag("pre", S), CellClass));
357  };
358
359  // Simplify the display file path, and wrap it in a link if requested.
360  std::string Filename;
361  if (IsTotals) {
362    Filename = SF;
363  } else {
364    Filename = buildLinkToFile(SF, FCS);
365  }
366
367  Columns.emplace_back(tag("td", tag("pre", Filename)));
368  AddCoverageTripleToColumn(FCS.FunctionCoverage.getExecuted(),
369                            FCS.FunctionCoverage.getNumFunctions(),
370                            FCS.FunctionCoverage.getPercentCovered());
371  if (Opts.ShowInstantiationSummary)
372    AddCoverageTripleToColumn(FCS.InstantiationCoverage.getExecuted(),
373                              FCS.InstantiationCoverage.getNumFunctions(),
374                              FCS.InstantiationCoverage.getPercentCovered());
375  AddCoverageTripleToColumn(FCS.LineCoverage.getCovered(),
376                            FCS.LineCoverage.getNumLines(),
377                            FCS.LineCoverage.getPercentCovered());
378  if (Opts.ShowRegionSummary)
379    AddCoverageTripleToColumn(FCS.RegionCoverage.getCovered(),
380                              FCS.RegionCoverage.getNumRegions(),
381                              FCS.RegionCoverage.getPercentCovered());
382
383  if (IsTotals)
384    OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row-bold");
385  else
386    OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row");
387}
388
389Error CoveragePrinterHTML::createIndexFile(
390    ArrayRef<std::string> SourceFiles, const CoverageMapping &Coverage,
391    const CoverageFiltersMatchAll &Filters) {
392  // Emit the default stylesheet.
393  auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true);
394  if (Error E = CSSOrErr.takeError())
395    return E;
396
397  OwnedStream CSS = std::move(CSSOrErr.get());
398  CSS->operator<<(CSSForCoverage);
399
400  // Emit a file index along with some coverage statistics.
401  auto OSOrErr = createOutputStream("index", "html", /*InToplevel=*/true);
402  if (Error E = OSOrErr.takeError())
403    return E;
404  auto OS = std::move(OSOrErr.get());
405  raw_ostream &OSRef = *OS.get();
406
407  assert(Opts.hasOutputDirectory() && "No output directory for index file");
408  emitPrelude(OSRef, Opts, getPathToStyle(""));
409
410  // Emit some basic information about the coverage report.
411  if (Opts.hasProjectTitle())
412    OSRef << tag(ProjectTitleTag, escape(Opts.ProjectTitle, Opts));
413  OSRef << tag(ReportTitleTag, "Coverage Report");
414  if (Opts.hasCreatedTime())
415    OSRef << tag(CreatedTimeTag, escape(Opts.CreatedTimeStr, Opts));
416
417  // Emit a link to some documentation.
418  OSRef << tag("p", "Click " +
419                        a("http://clang.llvm.org/docs/"
420                          "SourceBasedCodeCoverage.html#interpreting-reports",
421                          "here") +
422                        " for information about interpreting this report.");
423
424  // Emit a table containing links to reports for each file in the covmapping.
425  // Exclude files which don't contain any regions.
426  OSRef << BeginCenteredDiv << BeginTable;
427  emitColumnLabelsForIndex(OSRef, Opts);
428  FileCoverageSummary Totals("TOTALS");
429  auto FileReports = CoverageReport::prepareFileReports(
430      Coverage, Totals, SourceFiles, Opts, Filters);
431  bool EmptyFiles = false;
432  for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
433    if (FileReports[I].FunctionCoverage.getNumFunctions())
434      emitFileSummary(OSRef, SourceFiles[I], FileReports[I]);
435    else
436      EmptyFiles = true;
437  }
438  emitFileSummary(OSRef, "Totals", Totals, /*IsTotals=*/true);
439  OSRef << EndTable << EndCenteredDiv;
440
441  // Emit links to files which don't contain any functions. These are normally
442  // not very useful, but could be relevant for code which abuses the
443  // preprocessor.
444  if (EmptyFiles && Filters.empty()) {
445    OSRef << tag("p", "Files which contain no functions. (These "
446                      "files contain code pulled into other files "
447                      "by the preprocessor.)\n");
448    OSRef << BeginCenteredDiv << BeginTable;
449    for (unsigned I = 0, E = FileReports.size(); I < E; ++I)
450      if (!FileReports[I].FunctionCoverage.getNumFunctions()) {
451        std::string Link = buildLinkToFile(SourceFiles[I], FileReports[I]);
452        OSRef << tag("tr", tag("td", tag("pre", Link)), "light-row") << '\n';
453      }
454    OSRef << EndTable << EndCenteredDiv;
455  }
456
457  OSRef << tag("h5", escape(Opts.getLLVMVersionString(), Opts));
458  emitEpilog(OSRef);
459
460  return Error::success();
461}
462
463void SourceCoverageViewHTML::renderViewHeader(raw_ostream &OS) {
464  OS << BeginCenteredDiv << BeginTable;
465}
466
467void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) {
468  OS << EndTable << EndCenteredDiv;
469}
470
471void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) {
472  OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions()))
473     << EndSourceNameDiv;
474}
475
476void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned) {
477  OS << "<tr>";
478}
479
480void SourceCoverageViewHTML::renderLineSuffix(raw_ostream &OS, unsigned) {
481  // If this view has sub-views, renderLine() cannot close the view's cell.
482  // Take care of it here, after all sub-views have been rendered.
483  if (hasSubViews())
484    OS << EndCodeTD;
485  OS << "</tr>";
486}
487
488void SourceCoverageViewHTML::renderViewDivider(raw_ostream &, unsigned) {
489  // The table-based output makes view dividers unnecessary.
490}
491
492void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L,
493                                        const LineCoverageStats &LCS,
494                                        unsigned ExpansionCol, unsigned) {
495  StringRef Line = L.Line;
496  unsigned LineNo = L.LineNo;
497
498  // Steps for handling text-escaping, highlighting, and tooltip creation:
499  //
500  // 1. Split the line into N+1 snippets, where N = |Segments|. The first
501  //    snippet starts from Col=1 and ends at the start of the first segment.
502  //    The last snippet starts at the last mapped column in the line and ends
503  //    at the end of the line. Both are required but may be empty.
504
505  SmallVector<std::string, 8> Snippets;
506  CoverageSegmentArray Segments = LCS.getLineSegments();
507
508  unsigned LCol = 1;
509  auto Snip = [&](unsigned Start, unsigned Len) {
510    Snippets.push_back(Line.substr(Start, Len));
511    LCol += Len;
512  };
513
514  Snip(LCol - 1, Segments.empty() ? 0 : (Segments.front()->Col - 1));
515
516  for (unsigned I = 1, E = Segments.size(); I < E; ++I)
517    Snip(LCol - 1, Segments[I]->Col - LCol);
518
519  // |Line| + 1 is needed to avoid underflow when, e.g |Line| = 0 and LCol = 1.
520  Snip(LCol - 1, Line.size() + 1 - LCol);
521
522  // 2. Escape all of the snippets.
523
524  for (unsigned I = 0, E = Snippets.size(); I < E; ++I)
525    Snippets[I] = escape(Snippets[I], getOptions());
526
527  // 3. Use \p WrappedSegment to set the highlight for snippet 0. Use segment
528  //    1 to set the highlight for snippet 2, segment 2 to set the highlight for
529  //    snippet 3, and so on.
530
531  Optional<StringRef> Color;
532  SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
533  auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) {
534    if (getOptions().Debug)
535      HighlightedRanges.emplace_back(LC, RC);
536    return tag("span", Snippet, Color.getValue());
537  };
538
539  auto CheckIfUncovered = [&](const CoverageSegment *S) {
540    return S && (!S->IsGapRegion || (Color && *Color == "red")) &&
541           S->HasCount && S->Count == 0;
542  };
543
544  if (CheckIfUncovered(LCS.getWrappedSegment())) {
545    Color = "red";
546    if (!Snippets[0].empty())
547      Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size());
548  }
549
550  for (unsigned I = 0, E = Segments.size(); I < E; ++I) {
551    const auto *CurSeg = Segments[I];
552    if (CheckIfUncovered(CurSeg))
553      Color = "red";
554    else if (CurSeg->Col == ExpansionCol)
555      Color = "cyan";
556    else
557      Color = None;
558
559    if (Color.hasValue())
560      Snippets[I + 1] = Highlight(Snippets[I + 1], CurSeg->Col,
561                                  CurSeg->Col + Snippets[I + 1].size());
562  }
563
564  if (Color.hasValue() && Segments.empty())
565    Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size());
566
567  if (getOptions().Debug) {
568    for (const auto &Range : HighlightedRanges) {
569      errs() << "Highlighted line " << LineNo << ", " << Range.first << " -> ";
570      if (Range.second == 0)
571        errs() << "?";
572      else
573        errs() << Range.second;
574      errs() << "\n";
575    }
576  }
577
578  // 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate
579  //    sub-line region count tooltips if needed.
580
581  if (shouldRenderRegionMarkers(LCS)) {
582    // Just consider the segments which start *and* end on this line.
583    for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
584      const auto *CurSeg = Segments[I];
585      if (!CurSeg->IsRegionEntry)
586        continue;
587      if (CurSeg->Count == LCS.getExecutionCount())
588        continue;
589
590      Snippets[I + 1] =
591          tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count),
592                                           "tooltip-content"),
593              "tooltip");
594
595      if (getOptions().Debug)
596        errs() << "Marker at " << CurSeg->Line << ":" << CurSeg->Col << " = "
597               << formatCount(CurSeg->Count) << "\n";
598    }
599  }
600
601  OS << BeginCodeTD;
602  OS << BeginPre;
603  for (const auto &Snippet : Snippets)
604    OS << Snippet;
605  OS << EndPre;
606
607  // If there are no sub-views left to attach to this cell, end the cell.
608  // Otherwise, end it after the sub-views are rendered (renderLineSuffix()).
609  if (!hasSubViews())
610    OS << EndCodeTD;
611}
612
613void SourceCoverageViewHTML::renderLineCoverageColumn(
614    raw_ostream &OS, const LineCoverageStats &Line) {
615  std::string Count = "";
616  if (Line.isMapped())
617    Count = tag("pre", formatCount(Line.getExecutionCount()));
618  std::string CoverageClass =
619      (Line.getExecutionCount() > 0) ? "covered-line" : "uncovered-line";
620  OS << tag("td", Count, CoverageClass);
621}
622
623void SourceCoverageViewHTML::renderLineNumberColumn(raw_ostream &OS,
624                                                    unsigned LineNo) {
625  std::string LineNoStr = utostr(uint64_t(LineNo));
626  std::string TargetName = "L" + LineNoStr;
627  OS << tag("td", a("#" + TargetName, tag("pre", LineNoStr), TargetName),
628            "line-number");
629}
630
631void SourceCoverageViewHTML::renderRegionMarkers(raw_ostream &,
632                                                 const LineCoverageStats &Line,
633                                                 unsigned) {
634  // Region markers are rendered in-line using tooltips.
635}
636
637void SourceCoverageViewHTML::renderExpansionSite(raw_ostream &OS, LineRef L,
638                                                 const LineCoverageStats &LCS,
639                                                 unsigned ExpansionCol,
640                                                 unsigned ViewDepth) {
641  // Render the line containing the expansion site. No extra formatting needed.
642  renderLine(OS, L, LCS, ExpansionCol, ViewDepth);
643}
644
645void SourceCoverageViewHTML::renderExpansionView(raw_ostream &OS,
646                                                 ExpansionView &ESV,
647                                                 unsigned ViewDepth) {
648  OS << BeginExpansionDiv;
649  ESV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/false,
650                  /*ShowTitle=*/false, ViewDepth + 1);
651  OS << EndExpansionDiv;
652}
653
654void SourceCoverageViewHTML::renderInstantiationView(raw_ostream &OS,
655                                                     InstantiationView &ISV,
656                                                     unsigned ViewDepth) {
657  OS << BeginExpansionDiv;
658  if (!ISV.View)
659    OS << BeginSourceNameDiv
660       << tag("pre",
661              escape("Unexecuted instantiation: " + ISV.FunctionName.str(),
662                     getOptions()))
663       << EndSourceNameDiv;
664  else
665    ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true,
666                    /*ShowTitle=*/false, ViewDepth);
667  OS << EndExpansionDiv;
668}
669
670void SourceCoverageViewHTML::renderTitle(raw_ostream &OS, StringRef Title) {
671  if (getOptions().hasProjectTitle())
672    OS << tag(ProjectTitleTag, escape(getOptions().ProjectTitle, getOptions()));
673  OS << tag(ReportTitleTag, escape(Title, getOptions()));
674  if (getOptions().hasCreatedTime())
675    OS << tag(CreatedTimeTag,
676              escape(getOptions().CreatedTimeStr, getOptions()));
677}
678
679void SourceCoverageViewHTML::renderTableHeader(raw_ostream &OS,
680                                               unsigned FirstUncoveredLineNo,
681                                               unsigned ViewDepth) {
682  std::string SourceLabel;
683  if (FirstUncoveredLineNo == 0) {
684    SourceLabel = tag("td", tag("pre", "Source"));
685  } else {
686    std::string LinkTarget = "#L" + utostr(uint64_t(FirstUncoveredLineNo));
687    SourceLabel =
688        tag("td", tag("pre", "Source (" +
689                                 a(LinkTarget, "jump to first uncovered line") +
690                                 ")"));
691  }
692
693  renderLinePrefix(OS, ViewDepth);
694  OS << tag("td", tag("pre", "Line")) << tag("td", tag("pre", "Count"))
695     << SourceLabel;
696  renderLineSuffix(OS, ViewDepth);
697}
698