1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[llvm-cov] Fix issues with segment highlighting in the html view

The text and html coverage views take different approaches to emitting
highlighted regions. That's because this problem is easier in the text
view: there's no need to worry about escaping text or adding tooltip
content to a highlighted snippet.

Unfortunately, the html view didn't get region highlighting quite right.

This patch fixes the situation, bringing parity between the two views.

llvm-svn: 280981
This commit is contained in:
Vedant Kumar 2016-09-08 19:18:23 +00:00
parent a98b17ce43
commit 60cc519524
3 changed files with 24 additions and 30 deletions

View File

@ -1,38 +1,38 @@
// RUN: llvm-cov show %S/Inputs/highlightedRanges.covmapping -instr-profile %S/Inputs/highlightedRanges.profdata -dump -filename-equivalence %s 2>&1 | FileCheck %s -check-prefixes=TEXT,SHARED
void func() {
return; // TEXT: Highlighted line [[@LINE+1]], 3 -> ?
int i = 0; // HTML: Highlighted line [[@LINE]], 1 ->
return;
int i = 0; // SHARED: Highlighted line [[@LINE]], 3 ->
} // SHARED: Highlighted line [[@LINE]], 1 -> 2
void func2(int x) {
if(x > 5) {
while(x >= 9) {
return;
--x; // TEXT: Highlighted line [[@LINE]], 7 -> ?
--x; // SHARED: Highlighted line [[@LINE]], 7 ->
} // SHARED: Highlighted line [[@LINE]], 1 -> 6
int i = 0; // TEXT: Highlighted line [[@LINE]], 5 -> ?
int i = 0; // SHARED: Highlighted line [[@LINE]], 5 ->
} // SHARED: Highlighted line [[@LINE]], 1 -> 4
}
void test() {
int x = 0;
if (x) { // TEXT: Highlighted line [[@LINE]], 10 -> ?
x = 0; // SHARED: Highlighted line [[@LINE]], 1 -> ?
} else { // TEXT: Highlighted line [[@LINE]], 1 -> 4
if (x) { // SHARED: Highlighted line [[@LINE]], 10 ->
x = 0; // SHARED: Highlighted line [[@LINE]], 1 ->
} else { // SHARED: Highlighted line [[@LINE]], 1 -> 4
x = 1;
}
// TEXT: Highlighted line [[@LINE+1]], 26 -> 29
for (int i = 0; i < 0; ++i) { // TEXT: Highlighted line [[@LINE]], 31 -> ?
x = 1; // TEXT: Highlighted line [[@LINE]], 1 -> ?
// SHARED: Highlighted line [[@LINE+1]], 26 ->
for (int i = 0; i < 0; ++i) { // SHARED: Highlighted line [[@LINE]], 31 ->
x = 1; // SHARED: Highlighted line [[@LINE]], 1 ->
} // SHARED: Highlighted line [[@LINE]], 1 -> 4
x = x < 10 ? x +
1
: x - 1; // TEXT: Highlighted line [[@LINE]], 16 -> 21
x = x > 10 ? x + // TEXT: Highlighted line [[@LINE]], 16 -> ?
: x - 1; // SHARED: Highlighted line [[@LINE]], 16 -> 21
x = x > 10 ? x + // SHARED: Highlighted line [[@LINE]], 16 ->
1 // SHARED: Highlighted line [[@LINE]], 1 -> 17
: x - 1;
}

View File

@ -50,7 +50,7 @@ int main() { // TEXT: [[@LINE]]| 161|int main(
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() {
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> int x = 0
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre><span class='red'> if (x) {
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> if (x) {
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre><span class='red'> }</span>
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = 1;
@ -62,7 +62,7 @@ int main() { // TEXT: [[@LINE]]| 161|int main(
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = x &lt; 10
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = x &gt; 10
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre><span class='red'> x - 1:
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> x - 1:
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x + 1;
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> return 0;

View File

@ -415,26 +415,21 @@ void SourceCoverageViewHTML::renderLine(
// snippet 3, and so on.
Optional<std::string> Color;
SmallVector<std::pair<unsigned, unsigned>, 4> HighlightedRanges;
SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) {
if (getOptions().Debug) {
if (!HighlightedRanges.empty() &&
HighlightedRanges.back().second == LC - 1) {
HighlightedRanges.back().second = RC;
} else
if (getOptions().Debug)
HighlightedRanges.emplace_back(LC, RC);
}
return tag("span", Snippet, Color.getValue());
};
auto CheckIfUncovered = [](const coverage::CoverageSegment *S) {
return S && (S->HasCount && S->Count == 0);
return S && S->HasCount && S->Count == 0;
};
if (CheckIfUncovered(WrappedSegment) ||
CheckIfUncovered(Segments.empty() ? nullptr : Segments.front())) {
if (CheckIfUncovered(WrappedSegment)) {
Color = "red";
Snippets[0] = Highlight(Snippets[0], 0, Snippets[0].size());
if (!Snippets[0].empty())
Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size());
}
for (unsigned I = 0, E = Segments.size(); I < E; ++I) {
@ -452,16 +447,15 @@ void SourceCoverageViewHTML::renderLine(
}
if (Color.hasValue() && Segments.empty())
Snippets.back() = Highlight(Snippets.back(), Snippets[0].size(), 0);
Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size());
if (getOptions().Debug) {
for (const auto &Range : HighlightedRanges) {
errs() << "Highlighted line " << LineNo << ", " << Range.first + 1
<< " -> ";
errs() << "Highlighted line " << LineNo << ", " << Range.first << " -> ";
if (Range.second == 0)
errs() << "?";
else
errs() << Range.second + 1;
errs() << Range.second;
errs() << "\n";
}
}