[clang-tools-extra] r277437 - [clang-rename] add support for template parameter renaming
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 2 02:38:38 PDT 2016
Author: omtcyfz
Date: Tue Aug 2 04:38:38 2016
New Revision: 277437
URL: http://llvm.org/viewvc/llvm-project?rev=277437&view=rev
Log:
[clang-rename] add support for template parameter renaming
Few simple tweaks allow template parameters to be renamed. See
TemplateTypenameFindBy{TemplateParam|TypeInside}.cpp
Reviewers: alexfh
Differential Revision: https://reviews.llvm.org/D22853
Modified:
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
Modified: clang-tools-extra/trunk/clang-rename/USRFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRFinder.cpp?rev=277437&r1=277436&r2=277437&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRFinder.cpp Tue Aug 2 04:38:38 2016
@@ -77,6 +77,10 @@ public:
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);
}
Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=277437&r1=277436&r2=277437&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Tue Aug 2 04:38:38 2016
@@ -104,6 +104,13 @@ public:
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;
}
Modified: clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp?rev=277437&r1=277436&r2=277437&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp (original)
+++ clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTemplateParam.cpp Tue Aug 2 04:38:38 2016
@@ -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) {
Modified: clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp?rev=277437&r1=277436&r2=277437&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp (original)
+++ clang-tools-extra/trunk/test/clang-rename/TemplateTypenameFindByTypeInside.cpp Tue Aug 2 04:38:38 2016
@@ -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) {
More information about the cfe-commits
mailing list