vmiklos created this revision.
vmiklos added a reviewer: klimek.
vmiklos added a subscriber: cfe-commits.

Testcase by Kirill Bobyrev.

http://reviews.llvm.org/D22237

Files:
  clang-rename/USRLocFinder.cpp
  test/clang-rename/VirtualFunction.cpp

Index: test/clang-rename/VirtualFunction.cpp
===================================================================
--- /dev/null
+++ test/clang-rename/VirtualFunction.cpp
@@ -0,0 +1,16 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=163 -new-name=boo %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class A {
+public:
+  virtual void foo(); // CHECK: virtual void boo();
+};
+
+class B : public A {
+public:
+  void foo();         // CHECK: void boo();
+};
+
+// Use grep -FUbo 'foo' <file> to get the correct offset of foo when changing
+// this file.
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -161,6 +161,22 @@
     return handleCXXNamedCastExpr(Expr);
   }
 
+  bool VisitCXXMethodDecl(CXXMethodDecl *Decl) {
+    if (getUSRForDecl(Decl) == USR) {
+      // This member function was requested to be renamed explicitly.
+      LocationsFound.push_back(Decl->getLocation());
+    } else if (Decl->isVirtual()) {
+      for (auto *OverridenDecl : Decl->overridden_methods()) {
+        if (getUSRForDecl(OverridenDecl) == USR) {
+          // This member function overwrites one that is to be renamed.
+          LocationsFound.push_back(Decl->getLocation());
+        }
+      }
+    }
+
+    return true;
+  }
+
   // Non-visitors:
 
   // \brief Returns a list of unique locations. Duplicate or overlapping


Index: test/clang-rename/VirtualFunction.cpp
===================================================================
--- /dev/null
+++ test/clang-rename/VirtualFunction.cpp
@@ -0,0 +1,16 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=163 -new-name=boo %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class A {
+public:
+  virtual void foo(); // CHECK: virtual void boo();
+};
+
+class B : public A {
+public:
+  void foo();         // CHECK: void boo();
+};
+
+// Use grep -FUbo 'foo' <file> to get the correct offset of foo when changing
+// this file.
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -161,6 +161,22 @@
     return handleCXXNamedCastExpr(Expr);
   }
 
+  bool VisitCXXMethodDecl(CXXMethodDecl *Decl) {
+    if (getUSRForDecl(Decl) == USR) {
+      // This member function was requested to be renamed explicitly.
+      LocationsFound.push_back(Decl->getLocation());
+    } else if (Decl->isVirtual()) {
+      for (auto *OverridenDecl : Decl->overridden_methods()) {
+        if (getUSRForDecl(OverridenDecl) == USR) {
+          // This member function overwrites one that is to be renamed.
+          LocationsFound.push_back(Decl->getLocation());
+        }
+      }
+    }
+
+    return true;
+  }
+
   // Non-visitors:
 
   // \brief Returns a list of unique locations. Duplicate or overlapping
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to