[PATCH] D23193: [clang-rename] fix bug with initializer lists

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 8 07:42:59 PDT 2016


omtcyfz updated this revision to Diff 67165.
omtcyfz added a comment.

Do these symbolic pointers seem reasonable?


https://reviews.llvm.org/D23193

Files:
  clang-rename/USRFinder.cpp
  clang-rename/USRLocFinder.cpp
  test/clang-rename/Field.cpp

Index: test/clang-rename/Field.cpp
===================================================================
--- test/clang-rename/Field.cpp
+++ test/clang-rename/Field.cpp
@@ -1,14 +1,12 @@
-// RUN: cat %s > %t.cpp
-// RUN: clang-rename -offset=148 -new-name=Bar %t.cpp -i --
-// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
-
 class Baz {
   int Foo;              // CHECK: Bar;
+//    ^ first offset
 public:
   Baz();
 };
 
 Baz::Baz() : Foo(0) {}  // CHECK: Baz::Baz() : Bar(0) {}
+//           ^ second offset
 
-// Use grep -FUbo 'Foo' <file> to get the correct offset of foo when changing
-// this file.
+// RUN: clang-rename -offset=18 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// RUN: clang-rename -offset=106 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -48,18 +48,9 @@
         // Ignore implicit initializers.
         continue;
       }
-      if (const clang::FieldDecl *FieldDecl = Initializer->getAnyMember()) {
+      if (const clang::FieldDecl *FieldDecl = Initializer->getMember()) {
         if (USRSet.find(getUSRForDecl(FieldDecl)) != USRSet.end()) {
-          // The initializer refers to a field that is to be renamed.
-          SourceLocation Location = Initializer->getSourceLocation();
-          StringRef TokenName = Lexer::getSourceText(
-              CharSourceRange::getTokenRange(Location),
-              Context.getSourceManager(), Context.getLangOpts());
-          if (TokenName == PrevName) {
-            // The token of the source location we find actually has the old
-            // name.
-            LocationsFound.push_back(Initializer->getSourceLocation());
-          }
+          LocationsFound.push_back(Initializer->getSourceLocation());
         }
       }
     }
Index: clang-rename/USRFinder.cpp
===================================================================
--- clang-rename/USRFinder.cpp
+++ clang-rename/USRFinder.cpp
@@ -90,6 +90,24 @@
                      TypeEndLoc);
   }
 
+  bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) {
+    for (auto &Initializer : ConstructorDecl->inits()) {
+      if (Initializer->getSourceOrder() == -1) {
+        // Ignore implicit initializers.
+        continue;
+      }
+      if (const clang::FieldDecl *FieldDecl = Initializer->getMember()) {
+        const auto InitBeginLoc = Initializer->getSourceLocation();
+        const auto InitEndLoc = Lexer::getLocForEndOfToken(
+            InitBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());
+        if (!setResult(FieldDecl, InitBeginLoc, InitEndLoc)) {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+
   // Other:
 
   const NamedDecl *getNamedDecl() { return Result; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23193.67165.patch
Type: text/x-patch
Size: 2882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160808/6d67df1a/attachment.bin>


More information about the cfe-commits mailing list