[PATCH] D89220: [clang-rename] Simplify the code of handling class paritial specializations, NFC.
hokein added inline comments. Comment at: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp:119 +llvm::for_each(PartialSpecs, + [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); }); addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl()); danilaml wrote: > Btw, this breaks on GCC <= 7.1, due to > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67274 > Workaround is to use `this->`. oh, thanks for spotting it! Fixed in e6b4179c5d282905a8ad17c57153b991c42d1126, instead of adding `this->`, I reverted it to the for-range loop. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89220/new/ https://reviews.llvm.org/D89220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D89220: [clang-rename] Simplify the code of handling class paritial specializations, NFC.
danilaml added inline comments. Comment at: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp:119 +llvm::for_each(PartialSpecs, + [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); }); addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl()); Btw, this breaks on GCC <= 7.1, due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67274 Workaround is to use `this->`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89220/new/ https://reviews.llvm.org/D89220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D89220: [clang-rename] Simplify the code of handling class paritial specializations, NFC.
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG27c691cf62a9: [clang-rename] Simplify the code of handling class paritial specializations… (authored by hokein). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89220/new/ https://reviews.llvm.org/D89220 Files: clang/include/clang/AST/DeclTemplate.h clang/lib/AST/DeclTemplate.cpp clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp === --- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -27,6 +27,7 @@ #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Refactoring/Rename/USRFinder.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/STLExtras.h" #include #include @@ -96,12 +97,6 @@ return true; } - bool VisitClassTemplatePartialSpecializationDecl( - const ClassTemplatePartialSpecializationDecl *PartialSpec) { -PartialSpecs.push_back(PartialSpec); -return true; - } - private: void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) { if (!RecordDecl->getDefinition()) { @@ -118,11 +113,10 @@ void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) { for (const auto *Specialization : TemplateDecl->specializations()) addUSRsOfCtorDtors(Specialization); - -for (const auto *PartialSpec : PartialSpecs) { - if (PartialSpec->getSpecializedTemplate() == TemplateDecl) -addUSRsOfCtorDtors(PartialSpec); -} +SmallVector PartialSpecs; +TemplateDecl->getPartialSpecializations(PartialSpecs); +llvm::for_each(PartialSpecs, + [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); }); addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl()); } @@ -184,7 +178,6 @@ std::set USRSet; std::vector OverriddenMethods; std::vector InstantiatedMethods; - std::vector PartialSpecs; }; } // namespace Index: clang/lib/AST/DeclTemplate.cpp === --- clang/lib/AST/DeclTemplate.cpp +++ clang/lib/AST/DeclTemplate.cpp @@ -440,7 +440,7 @@ } llvm::FoldingSetVector & -ClassTemplateDecl::getPartialSpecializations() { +ClassTemplateDecl::getPartialSpecializations() const { LoadLazySpecializations(); return getCommonPtr()->PartialSpecializations; } @@ -528,7 +528,7 @@ } void ClassTemplateDecl::getPartialSpecializations( - SmallVectorImpl ) { +SmallVectorImpl ) const { llvm::FoldingSetVector = getPartialSpecializations(); PS.clear(); Index: clang/include/clang/AST/DeclTemplate.h === --- clang/include/clang/AST/DeclTemplate.h +++ clang/include/clang/AST/DeclTemplate.h @@ -2266,7 +2266,7 @@ /// Retrieve the set of partial specializations of this class /// template. llvm::FoldingSetVector & - getPartialSpecializations(); + getPartialSpecializations() const; ClassTemplateDecl(ASTContext , DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, @@ -2363,7 +2363,7 @@ /// Retrieve the partial specializations as an ordered list. void getPartialSpecializations( - SmallVectorImpl ); + SmallVectorImpl ) const; /// Find a class template partial specialization with the given /// type T. Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp === --- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -27,6 +27,7 @@ #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Refactoring/Rename/USRFinder.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/STLExtras.h" #include #include @@ -96,12 +97,6 @@ return true; } - bool VisitClassTemplatePartialSpecializationDecl( - const ClassTemplatePartialSpecializationDecl *PartialSpec) { -PartialSpecs.push_back(PartialSpec); -return true; - } - private: void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) { if (!RecordDecl->getDefinition()) { @@ -118,11 +113,10 @@ void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) { for (const auto *Specialization : TemplateDecl->specializations()) addUSRsOfCtorDtors(Specialization); - -for (const auto *PartialSpec : PartialSpecs) { - if (PartialSpec->getSpecializedTemplate() == TemplateDecl) -addUSRsOfCtorDtors(PartialSpec); -} +SmallVector PartialSpecs; +TemplateDecl->getPartialSpecializations(PartialSpecs); +llvm::for_each(PartialSpecs, + [&](const auto *Spec) { addUSRsOfCtorDtors(Spec);
[PATCH] D89220: [clang-rename] Simplify the code of handling class paritial specializations, NFC.
kbobyrev accepted this revision. kbobyrev added a comment. This revision is now accepted and ready to land. LGTM, thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89220/new/ https://reviews.llvm.org/D89220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D89220: [clang-rename] Simplify the code of handling class paritial specializations, NFC.
hokein created this revision. hokein added a reviewer: kbobyrev. Herald added a project: clang. hokein requested review of this revision. Instead of collecting all specializations and doing a post-filterin, we can just get all targeted specializations from getPartialSpecializationsizations. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D89220 Files: clang/include/clang/AST/DeclTemplate.h clang/lib/AST/DeclTemplate.cpp clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp === --- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -27,6 +27,7 @@ #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Refactoring/Rename/USRFinder.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/STLExtras.h" #include #include @@ -96,12 +97,6 @@ return true; } - bool VisitClassTemplatePartialSpecializationDecl( - const ClassTemplatePartialSpecializationDecl *PartialSpec) { -PartialSpecs.push_back(PartialSpec); -return true; - } - private: void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) { if (!RecordDecl->getDefinition()) { @@ -118,11 +113,10 @@ void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) { for (const auto *Specialization : TemplateDecl->specializations()) addUSRsOfCtorDtors(Specialization); - -for (const auto *PartialSpec : PartialSpecs) { - if (PartialSpec->getSpecializedTemplate() == TemplateDecl) -addUSRsOfCtorDtors(PartialSpec); -} +SmallVector PartialSpecs; +TemplateDecl->getPartialSpecializations(PartialSpecs); +llvm::for_each(PartialSpecs, + [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); }); addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl()); } @@ -184,7 +178,6 @@ std::set USRSet; std::vector OverriddenMethods; std::vector InstantiatedMethods; - std::vector PartialSpecs; }; } // namespace Index: clang/lib/AST/DeclTemplate.cpp === --- clang/lib/AST/DeclTemplate.cpp +++ clang/lib/AST/DeclTemplate.cpp @@ -440,7 +440,7 @@ } llvm::FoldingSetVector & -ClassTemplateDecl::getPartialSpecializations() { +ClassTemplateDecl::getPartialSpecializations() const { LoadLazySpecializations(); return getCommonPtr()->PartialSpecializations; } @@ -528,7 +528,7 @@ } void ClassTemplateDecl::getPartialSpecializations( - SmallVectorImpl ) { +SmallVectorImpl ) const { llvm::FoldingSetVector = getPartialSpecializations(); PS.clear(); Index: clang/include/clang/AST/DeclTemplate.h === --- clang/include/clang/AST/DeclTemplate.h +++ clang/include/clang/AST/DeclTemplate.h @@ -2266,7 +2266,7 @@ /// Retrieve the set of partial specializations of this class /// template. llvm::FoldingSetVector & - getPartialSpecializations(); + getPartialSpecializations() const; ClassTemplateDecl(ASTContext , DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, @@ -2363,7 +2363,7 @@ /// Retrieve the partial specializations as an ordered list. void getPartialSpecializations( - SmallVectorImpl ); + SmallVectorImpl ) const; /// Find a class template partial specialization with the given /// type T. Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp === --- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -27,6 +27,7 @@ #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Refactoring/Rename/USRFinder.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/STLExtras.h" #include #include @@ -96,12 +97,6 @@ return true; } - bool VisitClassTemplatePartialSpecializationDecl( - const ClassTemplatePartialSpecializationDecl *PartialSpec) { -PartialSpecs.push_back(PartialSpec); -return true; - } - private: void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) { if (!RecordDecl->getDefinition()) { @@ -118,11 +113,10 @@ void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) { for (const auto *Specialization : TemplateDecl->specializations()) addUSRsOfCtorDtors(Specialization); - -for (const auto *PartialSpec : PartialSpecs) { - if (PartialSpec->getSpecializedTemplate() == TemplateDecl) -addUSRsOfCtorDtors(PartialSpec); -} +SmallVector PartialSpecs; +TemplateDecl->getPartialSpecializations(PartialSpecs); +llvm::for_each(PartialSpecs, + [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); });