SourceCoverageViewHTML.cpp 21 KB

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