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