[clang-tools-extra] r271933 - clang-rename: implement renaming of classes inside static_cast
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 6 12:40:13 PDT 2016
Author: vmiklos
Date: Mon Jun 6 14:40:12 2016
New Revision: 271933
URL: http://llvm.org/viewvc/llvm-project?rev=271933&view=rev
Log:
clang-rename: implement renaming of classes inside static_cast
"Derived" in static_cast<Derived&>(...) wasn't renamed, nor in its
pointer equivalent.
Reviewers: klimek
Differential Revision: http://reviews.llvm.org/D21012
Added:
clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.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=271933&r1=271932&r2=271933&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Mon Jun 6 14:40:12 2016
@@ -123,6 +123,23 @@ public:
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
Added: clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp?rev=271933&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-rename/StaticCastExpr.cpp Mon Jun 6 14:40:12 2016
@@ -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.
More information about the cfe-commits
mailing list