Coverage Report

Created: 2018-06-18 20:01

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