Coverage Report

Created: 2019-07-24 05:18

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