diff options
author | Haojian Wu <hokein@google.com> | 2017-10-25 11:54:45 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2017-10-25 11:54:45 +0000 |
commit | f8bfb340103374d4894f9769940b34172329e2e0 (patch) | |
tree | e353311b4db3a3c9f90012ee9cba56c917e0121b /clang/lib | |
parent | b35022121d5d82705fd576b846eea6be9e98c0fd (diff) | |
download | bcm5719-llvm-f8bfb340103374d4894f9769940b34172329e2e0.tar.gz bcm5719-llvm-f8bfb340103374d4894f9769940b34172329e2e0.zip |
[rename] support renaming class member.
Reviewers: ioeric
Reviewed By: ioeric
Subscribers: klimek, cfe-commits, mgorny
Differential Revision: https://reviews.llvm.org/D39178
llvm-svn: 316571
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp index 38b2a624eae..c77304a1733 100644 --- a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp +++ b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp @@ -212,6 +212,41 @@ public: return true; } + bool VisitMemberExpr(const MemberExpr *Expr) { + const NamedDecl *Decl = Expr->getFoundDecl(); + auto StartLoc = Expr->getMemberLoc(); + auto EndLoc = Expr->getMemberLoc(); + if (isInUSRSet(Decl)) { + RenameInfos.push_back({StartLoc, EndLoc, + /*FromDecl=*/nullptr, + /*Context=*/nullptr, + /*Specifier=*/nullptr, + /*IgnorePrefixQualifiers=*/true}); + } + return true; + } + + bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) { + // Fix the constructor initializer when renaming class members. + for (const auto *Initializer : CD->inits()) { + // Ignore implicit initializers. + if (!Initializer->isWritten()) + continue; + + if (const FieldDecl *FD = Initializer->getMember()) { + if (isInUSRSet(FD)) { + auto Loc = Initializer->getSourceLocation(); + RenameInfos.push_back({Loc, Loc, + /*FromDecl=*/nullptr, + /*Context=*/nullptr, + /*Specifier=*/nullptr, + /*IgnorePrefixQualifiers=*/true}); + } + } + } + return true; + } + bool VisitDeclRefExpr(const DeclRefExpr *Expr) { const NamedDecl *Decl = Expr->getFoundDecl(); // Get the underlying declaration of the shadow declaration introduced by a @@ -227,6 +262,20 @@ public: ? Expr->getLAngleLoc().getLocWithOffset(-1) : Expr->getLocEnd(); + if (const auto *MD = llvm::dyn_cast<CXXMethodDecl>(Decl)) { + if (isInUSRSet(MD)) { + // Handle renaming static template class methods, we only rename the + // name without prefix qualifiers and restrict the source range to the + // name. + RenameInfos.push_back({EndLoc, EndLoc, + /*FromDecl=*/nullptr, + /*Context=*/nullptr, + /*Specifier=*/nullptr, + /*IgnorePrefixQualifiers=*/true}); + return true; + } + } + // In case of renaming an enum declaration, we have to explicitly handle // unscoped enum constants referenced in expressions (e.g. // "auto r = ns1::ns2::Green" where Green is an enum constant of an unscoped |