SourceCoverageViewHTML.cpp 21 KB

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