[PATCH] D22237: clang-rename: fix renaming member functions
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 11 13:15:41 PDT 2016
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22237.63561.patch
Type: text/x-patch
Size: 1466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160711/8ef9cb19/attachment-0001.bin>
More information about the cfe-commits
mailing list