[clang] 27c691c - [clang-rename] Simplify the code of handling class paritial specializations, NFC.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 00:58:25 PDT 2020
Author: Haojian Wu
Date: 2020-10-14T09:57:55+02:00
New Revision: 27c691cf62a9b34789516a24233fa0ee7bbd8111
URL: https://github.com/llvm/llvm-project/commit/27c691cf62a9b34789516a24233fa0ee7bbd8111
DIFF: https://github.com/llvm/llvm-project/commit/27c691cf62a9b34789516a24233fa0ee7bbd8111.diff
LOG: [clang-rename] Simplify the code of handling class paritial specializations, NFC.
Instead of collecting all specializations and doing a post-filterin, we
can just get all targeted specializations from getPartialSpecializationsizations.
Differential Revision: https://reviews.llvm.org/D89220
Added:
Modified:
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/DeclTemplate.cpp
clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index 9e2254376150..d10103752d81 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -2266,7 +2266,7 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
/// Retrieve the set of partial specializations of this class
/// template.
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
- getPartialSpecializations();
+ getPartialSpecializations() const;
ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
DeclarationName Name, TemplateParameterList *Params,
@@ -2363,7 +2363,7 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
/// Retrieve the partial specializations as an ordered list.
void getPartialSpecializations(
- SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS);
+ SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) const;
/// Find a class template partial specialization with the given
/// type T.
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 7857e75f57a1..5538651a453d 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -440,7 +440,7 @@ ClassTemplateDecl::getSpecializations() const {
}
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
-ClassTemplateDecl::getPartialSpecializations() {
+ClassTemplateDecl::getPartialSpecializations() const {
LoadLazySpecializations();
return getCommonPtr()->PartialSpecializations;
}
@@ -528,7 +528,7 @@ void ClassTemplateDecl::AddPartialSpecialization(
}
void ClassTemplateDecl::getPartialSpecializations(
- SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
+ SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) const {
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
= getPartialSpecializations();
PS.clear();
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
index 43dc32e158d3..82ef26e18369 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ b/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 <algorithm>
#include <set>
@@ -96,12 +97,6 @@ class AdditionalUSRFinder : public RecursiveASTVisitor<AdditionalUSRFinder> {
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 @@ class AdditionalUSRFinder : public RecursiveASTVisitor<AdditionalUSRFinder> {
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<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs;
+ TemplateDecl->getPartialSpecializations(PartialSpecs);
+ llvm::for_each(PartialSpecs,
+ [&](const auto *Spec) { addUSRsOfCtorDtors(Spec); });
addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
}
@@ -184,7 +178,6 @@ class AdditionalUSRFinder : public RecursiveASTVisitor<AdditionalUSRFinder> {
std::set<std::string> USRSet;
std::vector<const CXXMethodDecl *> OverriddenMethods;
std::vector<const CXXMethodDecl *> InstantiatedMethods;
- std::vector<const ClassTemplatePartialSpecializationDecl *> PartialSpecs;
};
} // namespace
More information about the cfe-commits
mailing list