omtcyfz created this revision.
omtcyfz added a reviewer: alexfh.
omtcyfz added a subscriber: cfe-commits.

`clang-rename` is currently not able to find a symbol in initializer list. This 
patch is a fix of that bug.

https://reviews.llvm.org/D23193

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

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; }


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; }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to