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

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 2 02:46:20 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL277437: [clang-rename] add support for template parameter renaming (authored by omtcyfz).

Changed prior to commit:
  https://reviews.llvm.org/D22853?vs=66373&id=66446#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22853

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

Index: clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp
+++ clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp
@@ -1,11 +1,7 @@
 // RUN: cat %s > %t.cpp
-// RUN: clang-rename -offset=350 -new-name=U %t.cpp -i --
+// RUN: clang-rename -offset=227 -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: *
-
 template <typename T>             // CHECK: template <typename U>
 class Foo {
 T foo(T arg, T& ref, T* ptr) {    // CHECK: U foo(U arg, U& ref, U* ptr) {
Index: clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
+++ clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
@@ -1,11 +1,7 @@
 // RUN: cat %s > %t.cpp
-// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i --
+// RUN: clang-rename -offset=147 -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: *
-
 template <typename T>             // CHECK: template <typename U>
 class Foo {
 T foo(T arg, T& ref, T* ptr) {    // CHECK: U foo(U arg, U& ref, U* ptr) {
Index: clang-tools-extra/trunk/clang-rename/USRFinder.cpp
===================================================================
--- clang-tools-extra/trunk/clang-rename/USRFinder.cpp
+++ clang-tools-extra/trunk/clang-rename/USRFinder.cpp
@@ -77,6 +77,10 @@
     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);
   }
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
@@ -104,6 +104,13 @@
         USRSet.end()) {
       checkAndAddLocation(Loc.getBeginLoc());
     }
+    if (const auto *TemplateTypeParm =
+            dyn_cast<TemplateTypeParmType>(Loc.getType())) {
+      if (USRSet.find(getUSRForDecl(TemplateTypeParm->getDecl())) !=
+          USRSet.end()) {
+        checkAndAddLocation(Loc.getBeginLoc());
+      }
+    }
     return true;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22853.66446.patch
Type: text/x-patch
Size: 3007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160802/499339eb/attachment.bin>


More information about the cfe-commits mailing list