Coverage Report

Created: 2018-01-17 21:32

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