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