forked from OSchip/llvm-project
clang-rename: implement renaming of classes inside dynamic_cast
Refactor to do the same as what is done already for static_cast. Reviewers: klimek Differential Revision: http://reviews.llvm.org/D21120 llvm-svn: 272188
This commit is contained in:
parent
f3c3c13206
commit
85b7b1c06a
|
@ -124,20 +124,11 @@ public:
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return handleCXXNamedCastExpr(Expr);
|
||||
}
|
||||
|
||||
if (Decl && getUSRForDecl(Decl) == USR) {
|
||||
SourceLocation Location = Expr->getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
|
||||
LocationsFound.push_back(Location);
|
||||
}
|
||||
|
||||
return true;
|
||||
bool VisitCXXDynamicCastExpr(clang::CXXDynamicCastExpr *Expr) {
|
||||
return handleCXXNamedCastExpr(Expr);
|
||||
}
|
||||
|
||||
// Non-visitors:
|
||||
|
@ -159,6 +150,23 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
bool handleCXXNamedCastExpr(clang::CXXNamedCastExpr *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;
|
||||
}
|
||||
|
||||
// All the locations of the USR were found.
|
||||
const std::string USR;
|
||||
// Old name that is renamed.
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// RUN: cat %s > %t.cpp
|
||||
// RUN: clang-rename -offset=186 -new-name=X %t.cpp -i --
|
||||
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
|
||||
class Base {
|
||||
virtual int getValue() const = 0;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
int getValue() const {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Derived D;
|
||||
const Base &Reference = D;
|
||||
const Base *Pointer = &D;
|
||||
|
||||
dynamic_cast<const Derived &>(Reference).getValue(); // CHECK: dynamic_cast<const X &>
|
||||
dynamic_cast<const Derived *>(Pointer)->getValue(); // CHECK: dynamic_cast<const X *>
|
||||
}
|
||||
|
||||
// Use grep -FUbo 'Derived' <file> to get the correct offset of foo when changing
|
||||
// this file.
|
Loading…
Reference in New Issue