Re: [PATCH] D21120: clang-rename: implement renaming of classes inside dynamic_cast
vmiklos added a comment. Possible solution posted as http://reviews.llvm.org/D21186. Repository: rL LLVM http://reviews.llvm.org/D21120 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21120: clang-rename: implement renaming of classes inside dynamic_cast
vmiklos added a comment. Hmm, http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/14332/steps/test/logs/stdio fails with "error: cannot use dynamic_cast with -fno-rtti"; is there some way to detect if "-fno-rtti" is the default, and in that case don't execute the test? Thanks. Repository: rL LLVM http://reviews.llvm.org/D21120 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21120: clang-rename: implement renaming of classes inside dynamic_cast
This revision was automatically updated to reflect the committed changes. Closed by commit rL272188: clang-rename: implement renaming of classes inside dynamic_cast (authored by vmiklos). Changed prior to commit: http://reviews.llvm.org/D21120?vs=60001&id=60073#toc Repository: rL LLVM http://reviews.llvm.org/D21120 Files: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp 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 @@ -124,20 +124,11 @@ } 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 @@ } } + 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. Index: clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp === --- clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp +++ clang-tools-extra/trunk/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(Reference).getValue(); // CHECK: dynamic_cast + dynamic_cast(Pointer)->getValue(); // CHECK: dynamic_cast +} + +// Use grep -FUbo 'Derived' 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 @@ -124,20 +124,11 @@ } 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 @@ } } + 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. Index: clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp === --- clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp +++ clang-tools-extra/trunk/test/clang-rename/DynamicCastExpr.cpp @@ -0,0 +1,25 @@ +// RUN: cat %s
Re: [PATCH] D21120: clang-rename: implement renaming of classes inside dynamic_cast
klimek accepted this revision. klimek added a comment. This revision is now accepted and ready to land. lg http://reviews.llvm.org/D21120 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D21120: clang-rename: implement renaming of classes inside dynamic_cast
vmiklos created this revision. vmiklos added a reviewer: klimek. vmiklos added a subscriber: cfe-commits. Refactor to do the same as what is done already for static_cast. http://reviews.llvm.org/D21120 Files: clang-rename/USRLocFinder.cpp test/clang-rename/DynamicCastExpr.cpp Index: test/clang-rename/DynamicCastExpr.cpp === --- /dev/null +++ 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(Reference).getValue(); // CHECK: dynamic_cast + dynamic_cast(Pointer)->getValue(); // CHECK: dynamic_cast +} + +// Use grep -FUbo 'Derived' to get the correct offset of foo when changing +// this file. Index: clang-rename/USRLocFinder.cpp === --- clang-rename/USRLocFinder.cpp +++ clang-rename/USRLocFinder.cpp @@ -124,20 +124,11 @@ } 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 @@ } } + 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. Index: test/clang-rename/DynamicCastExpr.cpp === --- /dev/null +++ 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(Reference).getValue(); // CHECK: dynamic_cast + dynamic_cast(Pointer)->getValue(); // CHECK: dynamic_cast +} + +// Use grep -FUbo 'Derived' to get the correct offset of foo when changing +// this file. Index: clang-rename/USRLocFinder.cpp === --- clang-rename/USRLocFinder.cpp +++ clang-rename/USRLocFinder.cpp @@ -124,20 +124,11 @@ } 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 @@ } } + 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 foun