[PATCH] D22853: [clang-rename] add support for template parameter renaming

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 29 02:17:39 PDT 2016


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

git rebase; git resolve conflicts


https://reviews.llvm.org/D22853

Files:
  clang-rename/USRFinder.cpp
  clang-rename/USRLocFinder.cpp
  test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
  test/clang-rename/TemplateTypenameFindByTypeInside.cpp

Index: test/clang-rename/TemplateTypenameFindByTypeInside.cpp
===================================================================
--- test/clang-rename/TemplateTypenameFindByTypeInside.cpp
+++ test/clang-rename/TemplateTypenameFindByTypeInside.cpp
@@ -1,8 +1,4 @@
-// RUN: clang-rename -offset=289 -new-name=U %s -- | FileCheck %s
-
-// Currently unsupported test.
-// FIXME: clang-rename should be able to rename template parameters correctly.
-// XFAIL: *
+// RUN: clang-rename -offset=153 -new-name=Bar %s -- | FileCheck %s
 
 template <typename T>             // CHECK: template <typename U>
 class Foo {
Index: test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
===================================================================
--- test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
+++ test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
@@ -1,10 +1,4 @@
-// RUN: cat %s > %t.cpp
-// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i --
-// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
-
-// Currently unsupported test.
-// FIXME: clang-rename should be able to rename template parameters correctly.
-// XFAIL: *
+// RUN: clang-rename -offset=87 -new-name=Bar %s -- | FileCheck %s
 
 template <typename T>             // CHECK: template <typename U>
 class Foo {
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -101,6 +101,11 @@
     if (getUSRForDecl(Loc.getType()->getAsCXXRecordDecl()) == USR) {
       checkAndAddLocation(Loc.getBeginLoc());
     }
+    if (const auto TemplateTypeParm = dyn_cast<TemplateTypeParmType>(Loc.getType())) {
+      if (getUSRForDecl(TemplateTypeParm->getDecl()) == USR) {
+        checkAndAddLocation(Loc.getBeginLoc());
+      }
+    }
     return true;
   }
 
Index: clang-rename/USRFinder.cpp
===================================================================
--- clang-rename/USRFinder.cpp
+++ clang-rename/USRFinder.cpp
@@ -77,6 +77,9 @@
     const auto TypeBeginLoc = Loc.getBeginLoc();
     const auto TypeEndLoc = Lexer::getLocForEndOfToken(
         TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());
+    if (const auto *TemplateTypeParm = dyn_cast<TemplateTypeParmType>(Loc.getType())) {
+      return setResult(TemplateTypeParm->getDecl(), TypeBeginLoc, TypeEndLoc);
+    }
     return setResult(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc,
                      TypeEndLoc);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22853.66095.patch
Type: text/x-patch
Size: 2506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160729/98a29f19/attachment.bin>


More information about the cfe-commits mailing list