[PATCH] D21012: clang-rename: implement renaming of classes inside static_cast

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 6 12:46:56 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL271933: clang-rename: implement renaming of classes inside static_cast (authored by vmiklos).

Changed prior to commit:
  http://reviews.llvm.org/D21012?vs=59695&id=59766#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21012

Files:
  clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
  clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp

Index: clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp
+++ clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp
@@ -0,0 +1,24 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=150 -new-name=X %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+class Base {
+};
+
+class Derived : public Base {
+public:
+  int getValue() const {
+    return 0;
+  }
+};
+
+int main() {
+  Derived D;
+  const Base &Reference = D;
+  const Base *Pointer = &D;
+
+  static_cast<const Derived &>(Reference).getValue(); // CHECK: static_cast<const X &>
+  static_cast<const Derived *>(Pointer)->getValue();  // CHECK: static_cast<const X *>
+}
+
+// Use grep -FUbo 'Derived' <file> to get the correct offset of foo when changing
+// this file.
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
@@ -123,6 +123,23 @@
     return true;
   }
 
+  bool VisitCXXStaticCastExpr(clang::CXXStaticCastExpr *Expr) {
+    clang::QualType Type = Expr->getType();
+    // See if this a cast of a pointer.
+    const RecordDecl* Decl = Type->getPointeeCXXRecordDecl();
+    if (!Decl) {
+      // See if this is a cast of a reference.
+      Decl = Type->getAsCXXRecordDecl();
+    }
+
+    if (Decl && getUSRForDecl(Decl) == USR) {
+      SourceLocation Location = Expr->getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
+      LocationsFound.push_back(Location);
+    }
+
+    return true;
+  }
+
   // Non-visitors:
 
   // \brief Returns a list of unique locations. Duplicate or overlapping


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21012.59766.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160606/04932541/attachment-0001.bin>


More information about the cfe-commits mailing list