diff options
| author | Miklos Vajna <vmiklos@vmiklos.hu> | 2016-06-08 18:38:23 +0000 |
|---|---|---|
| committer | Miklos Vajna <vmiklos@vmiklos.hu> | 2016-06-08 18:38:23 +0000 |
| commit | 85b7b1c06ac147cb59b3e62652c099357c7d249e (patch) | |
| tree | 9b9e1582ef89a7193d3a357236d4cc8e9a169ff0 /clang-tools-extra | |
| parent | f3c3c13206ce76f46a633d9665d88997587cbd9c (diff) | |
| download | bcm5719-llvm-85b7b1c06ac147cb59b3e62652c099357c7d249e.tar.gz bcm5719-llvm-85b7b1c06ac147cb59b3e62652c099357c7d249e.zip | |
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
Diffstat (limited to 'clang-tools-extra')
| -rw-r--r-- | clang-tools-extra/clang-rename/USRLocFinder.cpp | 34 | ||||
| -rw-r--r-- | clang-tools-extra/test/clang-rename/DynamicCastExpr.cpp | 25 |
2 files changed, 46 insertions, 13 deletions
diff --git a/clang-tools-extra/clang-rename/USRLocFinder.cpp b/clang-tools-extra/clang-rename/USRLocFinder.cpp index be110f15276..2a8804d3e63 100644 --- a/clang-tools-extra/clang-rename/USRLocFinder.cpp +++ b/clang-tools-extra/clang-rename/USRLocFinder.cpp @@ -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(); - } - - if (Decl && getUSRForDecl(Decl) == USR) { - SourceLocation Location = Expr->getTypeInfoAsWritten()->getTypeLoc().getBeginLoc(); - LocationsFound.push_back(Location); - } + return handleCXXNamedCastExpr(Expr); + } - 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. diff --git a/clang-tools-extra/test/clang-rename/DynamicCastExpr.cpp b/clang-tools-extra/test/clang-rename/DynamicCastExpr.cpp new file mode 100644 index 00000000000..91d4f25ab07 --- /dev/null +++ b/clang-tools-extra/test/clang-rename/DynamicCastExpr.cpp @@ -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. |

