Skip to content

Commit

Permalink
[clang-rename] add support for template parameter renaming
Browse files Browse the repository at this point in the history
Few simple tweaks allow template parameters to be renamed. See
TemplateTypenameFindBy{TemplateParam|TypeInside}.cpp

Reviewers: alexfh

Differential Revision: https://reviews.llvm.org/D22853

llvm-svn: 277437
  • Loading branch information
kirillbobyrev committed Aug 2, 2016
1 parent a0053cc commit 9e0dab9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions clang-tools-extra/clang-rename/USRFinder.cpp
Expand Up @@ -77,6 +77,10 @@ class NamedDeclFindingASTVisitor
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);
}
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clang-rename/USRLocFinder.cpp
Expand Up @@ -104,6 +104,13 @@ class USRLocFindingASTVisitor
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;
}

Expand Down
@@ -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) {
Expand Down
@@ -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) {
Expand Down

0 comments on commit 9e0dab9

Please sign in to comment.