[PATCH] D19957: clang-rename: when renaming a field, rename initializers of that field as well

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Thu May 5 00:23:11 PDT 2016


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

The second check failed, the initializer wasn't renamed.

http://reviews.llvm.org/D19957

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

Index: test/clang-rename/FieldTest.cpp
===================================================================
--- /dev/null
+++ test/clang-rename/FieldTest.cpp
@@ -0,0 +1,17 @@
+class Cla
+{
+  int foo; // CHECK: hector;
+public:
+  Cla();
+};
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=18 -new-name=hector %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+Cla::Cla()
+  : foo(0) // CHECK: hector(0)
+{
+}
+
+// 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
@@ -57,6 +57,19 @@
     return true;
   }
 
+  bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) {
+    for (clang::CXXConstructorDecl::init_const_iterator it = ConstructorDecl->init_begin(); it != ConstructorDecl->init_end(); ++it) {
+      const clang::CXXCtorInitializer* Initializer = *it;
+      if (const clang::FieldDecl *FieldDecl = Initializer->getAnyMember()) {
+        if (getUSRForDecl(FieldDecl) == USR) {
+          // The initializer refers to a field that is to be renamed.
+          LocationsFound.push_back(Initializer->getSourceLocation());
+        }
+      }
+    }
+    return true;
+  }
+
   // Expression visitors:
 
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19957.56241.patch
Type: text/x-patch
Size: 1414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160505/88437427/attachment.bin>


More information about the cfe-commits mailing list