[PATCH] D19905: clang-rename: when renaming a class, rename pointers to that class as well

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Wed May 4 00:49:26 PDT 2016


vmiklos created this revision.
vmiklos added reviewers: cfe-commits, klimek.

The second "CHECK:" failed in the testcase without the code change.

http://reviews.llvm.org/D19905

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

Index: test/clang-rename/ClassTest.cpp
===================================================================
--- /dev/null
+++ test/clang-rename/ClassTest.cpp
@@ -0,0 +1,15 @@
+class Cla  // CHECK: class Hector
+{
+};
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=6 -new-name=Hector %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+int main()
+{
+    Cla *Pointer = 0; // CHECK: Hector *Pointer = 0;
+    return 0;
+}
+
+// Use grep -FUbo 'Cla' <file> to get the correct offset of Cla when changing
+// this file.
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -45,6 +45,18 @@
     return true;
   }
 
+  bool VisitVarDecl(clang::VarDecl *Decl) {
+    clang::QualType Type = Decl->getType();
+    const clang::RecordDecl *RecordDecl = Type->getPointeeCXXRecordDecl();
+    if (RecordDecl) {
+      if (getUSRForDecl(RecordDecl) == USR) {
+        // The declaration refers to a type that is to be renamed.
+        LocationsFound.push_back(Decl->getTypeSpecStartLoc());
+      }
+    }
+    return true;
+  }
+
   // Expression visitors:
 
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19905.56102.patch
Type: text/x-patch
Size: 1241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160504/93e82627/attachment-0001.bin>


More information about the cfe-commits mailing list