From 2e0893629af16965dcb5b56f3e39f8df660c0fdc Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 18 Jul 2016 17:53:16 +0000 Subject: [PATCH] [llvm-cov] Place anchors around line numbers in html reports Based on a suggestion by Harlan Haskins! llvm-svn: 275840 --- .../tools/llvm-cov/showLineExecutionCounts.cpp | 48 ++++++++--------- .../tools/llvm-cov/showTemplateInstantiations.cpp | 62 +++++++++++----------- llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 9 ++-- 3 files changed, 61 insertions(+), 58 deletions(-) diff --git a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp index c624c14..7a33c31e 100644 --- a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp +++ b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp @@ -45,27 +45,27 @@ int main() { // TEXT: 161| [[@LINE]]|int main( // RUN: FileCheck -check-prefixes=HTML,HTML-WHOLE-FILE -input-file %t.html.dir/coverage/tmp/showLineExecutionCounts.cpp.html %s // RUN: FileCheck -check-prefixes=HTML,HTML-FILTER -input-file %t.html.dir/functions.html %s // -// HTML-WHOLE-FILE:
[[@LINE-44]]
// before
-// HTML-FILTER-NOT: 
[[@LINE-45]]
// before
-// HTML: 
161
[[@LINE-44]]
int main() {
-// HTML: 
161
[[@LINE-44]]
  int x = 0
-// HTML: 
161
[[@LINE-44]]
-// HTML: 
0
[[@LINE-44]]
  if (x) {
-// HTML: 
0
[[@LINE-44]]
-// HTML: 
161
[[@LINE-44]]
  }
-// HTML: 
161
[[@LINE-44]]
    x = 1;
-// HTML: 
161
[[@LINE-44]]
  }
-// HTML: 
161
[[@LINE-44]]
-// HTML: 
16.2k
[[@LINE-44]]
  for (int i = 0; i < 100; ++i)
-// HTML: 
16.1k
[[@LINE-44]]
    x = 1;
-// HTML: 
16.1k
[[@LINE-44]]
  }
-// HTML: 
161
[[@LINE-44]]
-// HTML: 
161
[[@LINE-44]]
  x = x < 10
-// HTML: 
161
[[@LINE-44]]
  x = x > 10
-// HTML: 
0
[[@LINE-44]]
        x - 1:
-// HTML: 
161
[[@LINE-44]]
        x + 1;
-// HTML: 
161
[[@LINE-44]]
-// HTML: 
161
[[@LINE-44]]
  return 0;
-// HTML: 
161
[[@LINE-44]]
}
-// HTML-WHOLE-FILE: 
[[@LINE-44]]
// after
-// HTML-FILTER-NOT: 
[[@LINE-45]]
// after
+// HTML-WHOLE-FILE: 
[[@LINE-44]]
// before
+// HTML-FILTER-NOT: 
[[@LINE-45]]
// before
+// HTML: 
161
[[@LINE-44]]
int main() {
+// HTML: 
161
[[@LINE-44]]
  int x = 0
+// HTML: 
161
[[@LINE-44]]
+// HTML: 
0
[[@LINE-44]]
  if (x) {
+// HTML: 
0
[[@LINE-44]]
+// HTML: 
161
[[@LINE-44]]
  }
+// HTML: 
161
[[@LINE-44]]
    x = 1;
+// HTML: 
161
[[@LINE-44]]
  }
+// HTML: 
161
[[@LINE-44]]
+// HTML: 
16.2k
[[@LINE-44]]
  for (int i = 0; i < 100; ++i)
+// HTML: 
16.1k
[[@LINE-44]]
    x = 1;
+// HTML: 
16.1k
[[@LINE-44]]
  }
+// HTML: 
161
[[@LINE-44]]
+// HTML: 
161
[[@LINE-44]]
  x = x < 10
+// HTML: 
161
[[@LINE-44]]
  x = x > 10
+// HTML: 
0
[[@LINE-44]]
        x - 1:
+// HTML: 
161
[[@LINE-44]]
        x + 1;
+// HTML: 
161
[[@LINE-44]]
+// HTML: 
161
[[@LINE-44]]
  return 0;
+// HTML: 
161
[[@LINE-44]]
}
+// HTML-WHOLE-FILE: 
[[@LINE-44]]
// after
+// HTML-FILTER-NOT: 
[[@LINE-45]]
// after
diff --git a/llvm/test/tools/llvm-cov/showTemplateInstantiations.cpp b/llvm/test/tools/llvm-cov/showTemplateInstantiations.cpp
index 8fc4589..b4bb45b 100644
--- a/llvm/test/tools/llvm-cov/showTemplateInstantiations.cpp
+++ b/llvm/test/tools/llvm-cov/showTemplateInstantiations.cpp
@@ -45,41 +45,41 @@ int main() {         // ALL:         1| [[@LINE]]|int main() {
 // RUN: FileCheck -check-prefixes=HTML-SHARED,HTML-ALL -input-file=%t.html.dir/coverage/tmp/showTemplateInstantiations.cpp.html %s
 // RUN: FileCheck -check-prefixes=HTML-SHARED,HTML-FILTER -input-file=%t.html.dir/functions.html %s
 
-// HTML-ALL: 
[[@LINE-44]]
// before
-// HTML-FILTER-NOT: 
[[@LINE-45]]
// before
-// HTML-ALL: 
[[@LINE-44]]
template<typename T>
-// HTML-ALL: 
2
[[@LINE-44]]
int func(T x) {
-// HTML-ALL: 
2
[[@LINE-44]]
  if(x)
-// HTML-ALL: 
1
[[@LINE-44]]
    ret
-// HTML-ALL: 
2
[[@LINE-44]]
  else
-// HTML-ALL: 
1
[[@LINE-44]]
    ret
-// HTML-ALL: 
0
[[@LINE-44]]
-// HTML-ALL: 
2
[[@LINE-44]]
}
+// HTML-ALL: 
[[@LINE-44]]
// before
+// HTML-FILTER-NOT: 
[[@LINE-45]]
// before
+// HTML-ALL: 
[[@LINE-44]]
template<typename T>
+// HTML-ALL: 
2
[[@LINE-44]]
int func(T x) {
+// HTML-ALL: 
2
[[@LINE-44]]
  if(x)
+// HTML-ALL: 
1
[[@LINE-44]]
    ret
+// HTML-ALL: 
2
[[@LINE-44]]
  else
+// HTML-ALL: 
1
[[@LINE-44]]
    ret
+// HTML-ALL: 
0
[[@LINE-44]]
+// HTML-ALL: 
2
[[@LINE-44]]
}
 
 // HTML-SHARED: 
_Z4funcIbEiT_
-// HTML-SHARED:
1
[[@LINE-53]]
int func(T x) {
-// HTML-SHARED: 
1
[[@LINE-53]]
  if(x)
-// HTML-SHARED: 
1
[[@LINE-53]]
    ret
-// HTML-SHARED: 
1
[[@LINE-53]]
  else
-// HTML-SHARED: 
0
[[@LINE-53]]
-// HTML-SHARED: 
0
[[@LINE-53]]
-// HTML-SHARED: 
1
[[@LINE-53]]
}
+// HTML-SHARED: 
1
[[@LINE-53]]
int func(T x) {
+// HTML-SHARED: 
1
[[@LINE-53]]
  if(x)
+// HTML-SHARED: 
1
[[@LINE-53]]
    ret
+// HTML-SHARED: 
1
[[@LINE-53]]
  else
+// HTML-SHARED: 
0
[[@LINE-53]]
+// HTML-SHARED: 
0
[[@LINE-53]]
+// HTML-SHARED: 
1
[[@LINE-53]]
}
 
 // HTML-ALL: 
_Z4funcIiEiT_
// HTML-FILTER-NOT:
_Z4funcIiEiT_
-// HTML-ALL:
1
[[@LINE-63]]
int func(T x) {
-// HTML-ALL: 
1
[[@LINE-63]]
  if(x)
-// HTML-ALL: 
0
[[@LINE-63]]
-// HTML-ALL: 
1
[[@LINE-63]]
  else
-// HTML-ALL: 
1
[[@LINE-63]]
    ret
-// HTML-ALL: 
0
[[@LINE-63]]
-// HTML-ALL: 
1
[[@LINE-63]]
}
+// HTML-ALL: 
1
[[@LINE-63]]
int func(T x) {
+// HTML-ALL: 
1
[[@LINE-63]]
  if(x)
+// HTML-ALL: 
0
[[@LINE-63]]
+// HTML-ALL: 
1
[[@LINE-63]]
  else
+// HTML-ALL: 
1
[[@LINE-63]]
    ret
+// HTML-ALL: 
0
[[@LINE-63]]
+// HTML-ALL: 
1
[[@LINE-63]]
}
 
-// HTML-ALL: td class='covered-line'>
1
[[@LINE-44]]
int main() {
-// HTML-ALL: 
1
[[@LINE-44]]
  func<int>(0);
-// HTML-ALL: 
1
[[@LINE-44]]
  func<bool>(true);
-// HTML-ALL: 
1
[[@LINE-44]]
  return 0;
-// HTML-ALL: 
1
[[@LINE-44]]
}
+// HTML-ALL: td class='covered-line'>
1
[[@LINE-44]]
int main() {
+// HTML-ALL: 
1
[[@LINE-44]]
  func<int>(0);
+// HTML-ALL: 
1
[[@LINE-44]]
  func<bool>(true);
+// HTML-ALL: 
1
[[@LINE-44]]
  return 0;
+// HTML-ALL: 
1
[[@LINE-44]]
}
 
-// HTML-ALL: 
[[@LINE-45]]
// after
-// HTML-FILTER-NOT: 
[[@LINE-46]]
// after
+// HTML-ALL: 
[[@LINE-45]]
// after
+// HTML-FILTER-NOT: 
[[@LINE-46]]
// after
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index 81963e5..fb4ad2d 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -210,8 +210,9 @@ std::string tag(const std::string &Name, const std::string &Str,
 }
 
 // Create an anchor to \p Link with the label \p Str.
-std::string a(const std::string &Link, const std::string &Str) {
-  return "" + Str + "";
+std::string a(const std::string &Link, const std::string &Str,
+              const std::string &TargetType = "href") {
+  return "" + Str + "";
 }
 
 } // anonymous namespace
@@ -402,7 +403,9 @@ void SourceCoverageViewHTML::renderLineCoverageColumn(
 
 void SourceCoverageViewHTML::renderLineNumberColumn(raw_ostream &OS,
                                                     unsigned LineNo) {
-  OS << tag("td", tag("pre", utostr(uint64_t(LineNo))), "line-number");
+  std::string LineNoStr = utostr(uint64_t(LineNo));
+  OS << tag("td", a("L" + LineNoStr, tag("pre", LineNoStr), "name"),
+            "line-number");
 }
 
 void SourceCoverageViewHTML::renderRegionMarkers(raw_ostream &,
-- 
2.7.4