SourceCoverageViewHTML.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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. SmallVector<std::string, 4> Columns;
  254. Columns.emplace_back(tag("td", "Filename", "column-entry-left"));
  255. for (const char *Label : {"Function Coverage", "Instantiation Coverage",
  256. "Line Coverage", "Region Coverage"})
  257. Columns.emplace_back(tag("td", Label, "column-entry"));
  258. OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
  259. }
  260. std::string
  261. CoveragePrinterHTML::buildLinkToFile(StringRef SF,
  262. const FileCoverageSummary &FCS) const {
  263. SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name));
  264. sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true);
  265. sys::path::native(LinkTextStr);
  266. std::string LinkText = escape(LinkTextStr, Opts);
  267. std::string LinkTarget =
  268. escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
  269. return a(LinkTarget, LinkText);
  270. }
  271. /// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is
  272. /// false, link the summary to \p SF.
  273. void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
  274. const FileCoverageSummary &FCS,
  275. bool IsTotals) const {
  276. SmallVector<std::string, 8> Columns;
  277. // Format a coverage triple and add the result to the list of columns.
  278. auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total,
  279. float Pctg) {
  280. std::string S;
  281. {
  282. raw_string_ostream RSO{S};
  283. if (Total)
  284. RSO << format("%*.2f", 7, Pctg) << "% ";
  285. else
  286. RSO << "- ";
  287. RSO << '(' << Hit << '/' << Total << ')';
  288. }
  289. const char *CellClass = "column-entry-yellow";
  290. if (Hit == Total)
  291. CellClass = "column-entry-green";
  292. else if (Pctg < 80.0)
  293. CellClass = "column-entry-red";
  294. Columns.emplace_back(tag("td", tag("pre", S), CellClass));
  295. };
  296. // Simplify the display file path, and wrap it in a link if requested.
  297. std::string Filename;
  298. if (IsTotals) {
  299. Filename = "TOTALS";
  300. } else {
  301. Filename = buildLinkToFile(SF, FCS);
  302. }
  303. Columns.emplace_back(tag("td", tag("pre", Filename)));
  304. AddCoverageTripleToColumn(FCS.FunctionCoverage.Executed,
  305. FCS.FunctionCoverage.NumFunctions,
  306. FCS.FunctionCoverage.getPercentCovered());
  307. AddCoverageTripleToColumn(FCS.InstantiationCoverage.Executed,
  308. FCS.InstantiationCoverage.NumFunctions,
  309. FCS.InstantiationCoverage.getPercentCovered());
  310. AddCoverageTripleToColumn(FCS.LineCoverage.Covered, FCS.LineCoverage.NumLines,
  311. FCS.LineCoverage.getPercentCovered());
  312. AddCoverageTripleToColumn(FCS.RegionCoverage.Covered,
  313. FCS.RegionCoverage.NumRegions,
  314. FCS.RegionCoverage.getPercentCovered());
  315. OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row");
  316. }
  317. Error CoveragePrinterHTML::createIndexFile(
  318. ArrayRef<std::string> SourceFiles,
  319. const coverage::CoverageMapping &Coverage) {
  320. // Emit the default stylesheet.
  321. auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true);
  322. if (Error E = CSSOrErr.takeError())
  323. return E;
  324. OwnedStream CSS = std::move(CSSOrErr.get());
  325. CSS->operator<<(CSSForCoverage);
  326. // Emit a file index along with some coverage statistics.
  327. auto OSOrErr = createOutputStream("index", "html", /*InToplevel=*/true);
  328. if (Error E = OSOrErr.takeError())
  329. return E;
  330. auto OS = std::move(OSOrErr.get());
  331. raw_ostream &OSRef = *OS.get();
  332. assert(Opts.hasOutputDirectory() && "No output directory for index file");
  333. emitPrelude(OSRef, Opts, getPathToStyle(""));
  334. // Emit some basic information about the coverage report.
  335. if (Opts.hasProjectTitle())
  336. OSRef << tag(ProjectTitleTag, escape(Opts.ProjectTitle, Opts));
  337. OSRef << tag(ReportTitleTag, "Coverage Report");
  338. if (Opts.hasCreatedTime())
  339. OSRef << tag(CreatedTimeTag, escape(Opts.CreatedTimeStr, Opts));
  340. // Emit a link to some documentation.
  341. OSRef << tag("p", "Click " +
  342. a("http://clang.llvm.org/docs/"
  343. "SourceBasedCodeCoverage.html#interpreting-reports",
  344. "here") +
  345. " for information about interpreting this report.");
  346. // Emit a table containing links to reports for each file in the covmapping.
  347. // Exclude files which don't contain any regions.
  348. OSRef << BeginCenteredDiv << BeginTable;
  349. emitColumnLabelsForIndex(OSRef);
  350. FileCoverageSummary Totals("TOTALS");
  351. auto FileReports =
  352. CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
  353. bool EmptyFiles = false;
  354. for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
  355. if (FileReports[I].FunctionCoverage.NumFunctions)
  356. emitFileSummary(OSRef, SourceFiles[I], FileReports[I]);
  357. else
  358. EmptyFiles = true;
  359. }
  360. emitFileSummary(OSRef, "Totals", Totals, /*IsTotals=*/true);
  361. OSRef << EndTable << EndCenteredDiv;
  362. // Emit links to files which don't contain any functions. These are normally
  363. // not very useful, but could be relevant for code which abuses the
  364. // preprocessor.
  365. if (EmptyFiles) {
  366. OSRef << tag("p", "Files which contain no functions. (These "
  367. "files contain code pulled into other files "
  368. "by the preprocessor.)\n");
  369. OSRef << BeginCenteredDiv << BeginTable;
  370. for (unsigned I = 0, E = FileReports.size(); I < E; ++I)
  371. if (!FileReports[I].FunctionCoverage.NumFunctions) {
  372. std::string Link = buildLinkToFile(SourceFiles[I], FileReports[I]);
  373. OSRef << tag("tr", tag("td", tag("pre", Link)), "light-row") << '\n';
  374. }
  375. OSRef << EndTable << EndCenteredDiv;
  376. }
  377. OSRef << tag("h5", escape(Opts.getLLVMVersionString(), Opts));
  378. emitEpilog(OSRef);
  379. return Error::success();
  380. }
  381. void SourceCoverageViewHTML::renderViewHeader(raw_ostream &OS) {
  382. OS << BeginCenteredDiv << BeginTable;
  383. }
  384. void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) {
  385. OS << EndTable << EndCenteredDiv;
  386. }
  387. void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) {
  388. OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions()))
  389. << EndSourceNameDiv;
  390. }
  391. void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned) {
  392. OS << "<tr>";
  393. }
  394. void SourceCoverageViewHTML::renderLineSuffix(raw_ostream &OS, unsigned) {
  395. // If this view has sub-views, renderLine() cannot close the view's cell.
  396. // Take care of it here, after all sub-views have been rendered.
  397. if (hasSubViews())
  398. OS << EndCodeTD;
  399. OS << "</tr>";
  400. }
  401. void SourceCoverageViewHTML::renderViewDivider(raw_ostream &, unsigned) {
  402. // The table-based output makes view dividers unnecessary.
  403. }
  404. void SourceCoverageViewHTML::renderLine(
  405. raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment,
  406. CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned) {
  407. StringRef Line = L.Line;
  408. unsigned LineNo = L.LineNo;
  409. // Steps for handling text-escaping, highlighting, and tooltip creation:
  410. //
  411. // 1. Split the line into N+1 snippets, where N = |Segments|. The first
  412. // snippet starts from Col=1 and ends at the start of the first segment.
  413. // The last snippet starts at the last mapped column in the line and ends
  414. // at the end of the line. Both are required but may be empty.
  415. SmallVector<std::string, 8> Snippets;
  416. unsigned LCol = 1;
  417. auto Snip = [&](unsigned Start, unsigned Len) {
  418. Snippets.push_back(Line.substr(Start, Len));
  419. LCol += Len;
  420. };
  421. Snip(LCol - 1, Segments.empty() ? 0 : (Segments.front()->Col - 1));
  422. for (unsigned I = 1, E = Segments.size(); I < E; ++I)
  423. Snip(LCol - 1, Segments[I]->Col - LCol);
  424. // |Line| + 1 is needed to avoid underflow when, e.g |Line| = 0 and LCol = 1.
  425. Snip(LCol - 1, Line.size() + 1 - LCol);
  426. // 2. Escape all of the snippets.
  427. for (unsigned I = 0, E = Snippets.size(); I < E; ++I)
  428. Snippets[I] = escape(Snippets[I], getOptions());
  429. // 3. Use \p WrappedSegment to set the highlight for snippet 0. Use segment
  430. // 1 to set the highlight for snippet 2, segment 2 to set the highlight for
  431. // snippet 3, and so on.
  432. Optional<std::string> Color;
  433. SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
  434. auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) {
  435. if (getOptions().Debug)
  436. HighlightedRanges.emplace_back(LC, RC);
  437. return tag("span", Snippet, Color.getValue());
  438. };
  439. auto CheckIfUncovered = [](const coverage::CoverageSegment *S) {
  440. return S && S->HasCount && S->Count == 0;
  441. };
  442. if (CheckIfUncovered(WrappedSegment)) {
  443. Color = "red";
  444. if (!Snippets[0].empty())
  445. Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size());
  446. }
  447. for (unsigned I = 0, E = Segments.size(); I < E; ++I) {
  448. const auto *CurSeg = Segments[I];
  449. if (CurSeg->Col == ExpansionCol)
  450. Color = "cyan";
  451. else if (CheckIfUncovered(CurSeg))
  452. Color = "red";
  453. else
  454. Color = None;
  455. if (Color.hasValue())
  456. Snippets[I + 1] = Highlight(Snippets[I + 1], CurSeg->Col,
  457. CurSeg->Col + Snippets[I + 1].size());
  458. }
  459. if (Color.hasValue() && Segments.empty())
  460. Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size());
  461. if (getOptions().Debug) {
  462. for (const auto &Range : HighlightedRanges) {
  463. errs() << "Highlighted line " << LineNo << ", " << Range.first << " -> ";
  464. if (Range.second == 0)
  465. errs() << "?";
  466. else
  467. errs() << Range.second;
  468. errs() << "\n";
  469. }
  470. }
  471. // 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate
  472. // sub-line region count tooltips if needed.
  473. if (shouldRenderRegionMarkers(Segments)) {
  474. // Just consider the segments which start *and* end on this line.
  475. for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
  476. const auto *CurSeg = Segments[I];
  477. if (!CurSeg->IsRegionEntry)
  478. continue;
  479. Snippets[I + 1] =
  480. tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count),
  481. "tooltip-content"),
  482. "tooltip");
  483. if (getOptions().Debug)
  484. errs() << "Marker at " << CurSeg->Line << ":" << CurSeg->Col << " = "
  485. << formatCount(CurSeg->Count) << "\n";
  486. }
  487. }
  488. OS << BeginCodeTD;
  489. OS << BeginPre;
  490. for (const auto &Snippet : Snippets)
  491. OS << Snippet;
  492. OS << EndPre;
  493. // If there are no sub-views left to attach to this cell, end the cell.
  494. // Otherwise, end it after the sub-views are rendered (renderLineSuffix()).
  495. if (!hasSubViews())
  496. OS << EndCodeTD;
  497. }
  498. void SourceCoverageViewHTML::renderLineCoverageColumn(
  499. raw_ostream &OS, const LineCoverageStats &Line) {
  500. std::string Count = "";
  501. if (Line.isMapped())
  502. Count = tag("pre", formatCount(Line.ExecutionCount));
  503. std::string CoverageClass =
  504. (Line.ExecutionCount > 0) ? "covered-line" : "uncovered-line";
  505. OS << tag("td", Count, CoverageClass);
  506. }
  507. void SourceCoverageViewHTML::renderLineNumberColumn(raw_ostream &OS,
  508. unsigned LineNo) {
  509. std::string LineNoStr = utostr(uint64_t(LineNo));
  510. std::string TargetName = "L" + LineNoStr;
  511. OS << tag("td", a("#" + TargetName, tag("pre", LineNoStr), TargetName),
  512. "line-number");
  513. }
  514. void SourceCoverageViewHTML::renderRegionMarkers(raw_ostream &,
  515. CoverageSegmentArray,
  516. unsigned) {
  517. // Region markers are rendered in-line using tooltips.
  518. }
  519. void SourceCoverageViewHTML::renderExpansionSite(
  520. raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment,
  521. CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) {
  522. // Render the line containing the expansion site. No extra formatting needed.
  523. renderLine(OS, L, WrappedSegment, Segments, ExpansionCol, ViewDepth);
  524. }
  525. void SourceCoverageViewHTML::renderExpansionView(raw_ostream &OS,
  526. ExpansionView &ESV,
  527. unsigned ViewDepth) {
  528. OS << BeginExpansionDiv;
  529. ESV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/false,
  530. ViewDepth + 1);
  531. OS << EndExpansionDiv;
  532. }
  533. void SourceCoverageViewHTML::renderInstantiationView(raw_ostream &OS,
  534. InstantiationView &ISV,
  535. unsigned ViewDepth) {
  536. OS << BeginExpansionDiv;
  537. if (!ISV.View)
  538. OS << BeginSourceNameDiv
  539. << tag("pre",
  540. escape("Unexecuted instantiation: " + ISV.FunctionName.str(),
  541. getOptions()))
  542. << EndSourceNameDiv;
  543. else
  544. ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true,
  545. ViewDepth);
  546. OS << EndExpansionDiv;
  547. }
  548. void SourceCoverageViewHTML::renderTitle(raw_ostream &OS, StringRef Title) {
  549. if (getOptions().hasProjectTitle())
  550. OS << tag(ProjectTitleTag, escape(getOptions().ProjectTitle, getOptions()));
  551. OS << tag(ReportTitleTag, escape(Title, getOptions()));
  552. if (getOptions().hasCreatedTime())
  553. OS << tag(CreatedTimeTag,
  554. escape(getOptions().CreatedTimeStr, getOptions()));
  555. }
  556. void SourceCoverageViewHTML::renderTableHeader(raw_ostream &OS,
  557. unsigned FirstUncoveredLineNo,
  558. unsigned ViewDepth) {
  559. std::string SourceLabel;
  560. if (FirstUncoveredLineNo == 0) {
  561. SourceLabel = tag("td", tag("pre", "Source"));
  562. } else {
  563. std::string LinkTarget = "#L" + utostr(uint64_t(FirstUncoveredLineNo));
  564. SourceLabel =
  565. tag("td", tag("pre", "Source (" +
  566. a(LinkTarget, "jump to first uncovered line") +
  567. ")"));
  568. }
  569. renderLinePrefix(OS, ViewDepth);
  570. OS << tag("td", tag("pre", "Line")) << tag("td", tag("pre", "Count"))
  571. << SourceLabel;
  572. renderLineSuffix(OS, ViewDepth);
  573. }