[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
Sat May 7 07:39:31 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268857: clang-rename: when renaming a field, rename initializers of that field as well (authored by vmiklos).
Changed prior to commit:
http://reviews.llvm.org/D19957?vs=56241&id=56497#toc
Repository:
rL LLVM
http://reviews.llvm.org/D19957
Files:
clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp
Index: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
===================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
+++ clang-tools-extra/trunk/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) {
Index: clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp
+++ clang-tools-extra/trunk/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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19957.56497.patch
Type: text/x-patch
Size: 1580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160507/b8e662c5/attachment.bin>
More information about the cfe-commits
mailing list