[PATCH] D21364: clang-rename: implement renaming of classes with a dtor
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 15 11:42:36 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL272816: clang-rename: implement renaming of classes with a dtor (authored by vmiklos).
Changed prior to commit:
http://reviews.llvm.org/D21364?vs=60801&id=60869#toc
Repository:
rL LLVM
http://reviews.llvm.org/D21364
Files:
clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp
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
@@ -87,6 +87,28 @@
return true;
}
+ bool VisitCXXDestructorDecl(clang::CXXDestructorDecl *DestructorDecl) {
+ if (getUSRForDecl(DestructorDecl->getParent()) == USR) {
+ // Handles "~Foo" from "Foo::~Foo".
+ SourceLocation Location = DestructorDecl->getLocation();
+ const ASTContext &Context = DestructorDecl->getASTContext();
+ StringRef TokenName = Lexer::getSourceText(
+ CharSourceRange::getTokenRange(Location), Context.getSourceManager(),
+ Context.getLangOpts());
+ // 1 is the length of the "~" string that is not to be touched by the
+ // rename.
+ assert(TokenName.startswith("~"));
+ LocationsFound.push_back(Location.getLocWithOffset(1));
+
+ if (DestructorDecl->isThisDeclarationADefinition()) {
+ // Handles "Foo" from "Foo::~Foo".
+ LocationsFound.push_back(DestructorDecl->getLocStart());
+ }
+ }
+
+ return true;
+ }
+
// Expression visitors:
bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
Index: clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp
+++ clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp
@@ -0,0 +1,17 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=135 -new-name=Bar %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+class Foo {
+public:
+ Foo();
+ ~Foo(); // CHECK: ~Bar();
+};
+
+Foo::Foo() {
+}
+
+Foo::~Foo() { // CHECK: Bar::~Bar()
+}
+
+// Use grep -FUbo 'Foo' <file> to get the correct offset of foo when changing
+// this file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21364.60869.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160615/35c1ef65/attachment.bin>
More information about the cfe-commits
mailing list