[clang-tools-extra] r272816 - clang-rename: implement renaming of classes with a dtor

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 11:35:42 PDT 2016


Author: vmiklos
Date: Wed Jun 15 13:35:41 2016
New Revision: 272816

URL: http://llvm.org/viewvc/llvm-project?rev=272816&view=rev
Log:
clang-rename: implement renaming of classes with a dtor

The declaration wasn't renamed. Also neither part of the declaration
wasn't renamed.

Reviewers: klimek

Differential Revision: http://reviews.llvm.org/D21364

Added:
    clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp
Modified:
    clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp

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=272816&r1=272815&r2=272816&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Wed Jun 15 13:35:41 2016
@@ -87,6 +87,28 @@ public:
     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) {

Added: clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp?rev=272816&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp (added)
+++ clang-tools-extra/trunk/test/clang-rename/DtorDefTest.cpp Wed Jun 15 13:35:41 2016
@@ -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.




More information about the cfe-commits mailing list