[clang] e3cba2f - Clean up template parameter list profiling. No functionality change.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 30 17:00:47 PDT 2023
Author: Richard Smith
Date: 2023-03-30T17:00:16-07:00
New Revision: e3cba2f464d318213ba05361e635e9b3b862e174
URL: https://github.com/llvm/llvm-project/commit/e3cba2f464d318213ba05361e635e9b3b862e174
DIFF: https://github.com/llvm/llvm-project/commit/e3cba2f464d318213ba05361e635e9b3b862e174.diff
LOG: Clean up template parameter list profiling. No functionality change.
Added:
Modified:
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/DeclTemplate.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index 03d5b778d26b..3677335fa176 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -117,6 +117,8 @@ class TemplateParameterList final
SourceLocation RAngleLoc,
Expr *RequiresClause);
+ void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const;
+
/// Iterates through the template parameters in this list.
using iterator = NamedDecl **;
@@ -616,7 +618,7 @@ class FunctionTemplateSpecializationInfo final
static void
Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
- ASTContext &Context) {
+ const ASTContext &Context) {
ID.AddInteger(TemplateArgs.size());
for (const TemplateArgument &TemplateArg : TemplateArgs)
TemplateArg.Profile(ID, Context);
@@ -2081,7 +2083,7 @@ class ClassTemplateSpecializationDecl
static void
Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
- ASTContext &Context) {
+ const ASTContext &Context) {
ID.AddInteger(TemplateArgs.size());
for (const TemplateArgument &TemplateArg : TemplateArgs)
TemplateArg.Profile(ID, Context);
@@ -2257,7 +2259,7 @@ class ClassTemplatePartialSpecializationDecl
static void
Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
- TemplateParameterList *TPL, ASTContext &Context);
+ TemplateParameterList *TPL, const ASTContext &Context);
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -2934,7 +2936,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
static void Profile(llvm::FoldingSetNodeID &ID,
ArrayRef<TemplateArgument> TemplateArgs,
- ASTContext &Context) {
+ const ASTContext &Context) {
ID.AddInteger(TemplateArgs.size());
for (const TemplateArgument &TemplateArg : TemplateArgs)
TemplateArg.Profile(ID, Context);
@@ -3094,7 +3096,7 @@ class VarTemplatePartialSpecializationDecl
static void
Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
- TemplateParameterList *TPL, ASTContext &Context);
+ TemplateParameterList *TPL, const ASTContext &Context);
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 77dfd58fdd32..fd4c8eafc1c3 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -127,6 +127,39 @@ TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc,
RAngleLoc, RequiresClause);
}
+void TemplateParameterList::Profile(llvm::FoldingSetNodeID &ID,
+ const ASTContext &C) const {
+ const Expr *RC = getRequiresClause();
+ ID.AddBoolean(RC != nullptr);
+ if (RC)
+ RC->Profile(ID, C, /*Canonical=*/true);
+ ID.AddInteger(size());
+ for (NamedDecl *D : *this) {
+ if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
+ ID.AddInteger(0);
+ ID.AddBoolean(NTTP->isParameterPack());
+ NTTP->getType().getCanonicalType().Profile(ID);
+ ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
+ if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
+ E->Profile(ID, C, /*Canonical=*/true);
+ continue;
+ }
+ if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D)) {
+ ID.AddInteger(1);
+ ID.AddBoolean(TTP->isParameterPack());
+ ID.AddBoolean(TTP->hasTypeConstraint());
+ if (const TypeConstraint *TC = TTP->getTypeConstraint())
+ TC->getImmediatelyDeclaredConstraint()->Profile(ID, C,
+ /*Canonical=*/true);
+ continue;
+ }
+ const auto *TTP = cast<TemplateTemplateParmDecl>(D);
+ ID.AddInteger(2);
+ ID.AddBoolean(TTP->isParameterPack());
+ TTP->getTemplateParameters()->Profile(ID, C);
+ }
+}
+
unsigned TemplateParameterList::getMinRequiredArguments() const {
unsigned NumRequiredArgs = 0;
for (const NamedDecl *P : asArray()) {
@@ -517,47 +550,13 @@ ClassTemplateDecl::findPartialSpecialization(
TPL);
}
-static void ProfileTemplateParameterList(ASTContext &C,
- llvm::FoldingSetNodeID &ID, const TemplateParameterList *TPL) {
- const Expr *RC = TPL->getRequiresClause();
- ID.AddBoolean(RC != nullptr);
- if (RC)
- RC->Profile(ID, C, /*Canonical=*/true);
- ID.AddInteger(TPL->size());
- for (NamedDecl *D : *TPL) {
- if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
- ID.AddInteger(0);
- ID.AddBoolean(NTTP->isParameterPack());
- NTTP->getType().getCanonicalType().Profile(ID);
- ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
- if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
- E->Profile(ID, C, /*Canonical=*/true);
- continue;
- }
- if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D)) {
- ID.AddInteger(1);
- ID.AddBoolean(TTP->isParameterPack());
- ID.AddBoolean(TTP->hasTypeConstraint());
- if (const TypeConstraint *TC = TTP->getTypeConstraint())
- TC->getImmediatelyDeclaredConstraint()->Profile(ID, C,
- /*Canonical=*/true);
- continue;
- }
- const auto *TTP = cast<TemplateTemplateParmDecl>(D);
- ID.AddInteger(2);
- ID.AddBoolean(TTP->isParameterPack());
- ProfileTemplateParameterList(C, ID, TTP->getTemplateParameters());
- }
-}
-
-void
-ClassTemplatePartialSpecializationDecl::Profile(llvm::FoldingSetNodeID &ID,
- ArrayRef<TemplateArgument> TemplateArgs, TemplateParameterList *TPL,
- ASTContext &Context) {
+void ClassTemplatePartialSpecializationDecl::Profile(
+ llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
+ TemplateParameterList *TPL, const ASTContext &Context) {
ID.AddInteger(TemplateArgs.size());
for (const TemplateArgument &TemplateArg : TemplateArgs)
TemplateArg.Profile(ID, Context);
- ProfileTemplateParameterList(Context, ID, TPL);
+ TPL->Profile(ID, Context);
}
void ClassTemplateDecl::AddPartialSpecialization(
@@ -1283,14 +1282,13 @@ VarTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args,
TPL);
}
-void
-VarTemplatePartialSpecializationDecl::Profile(llvm::FoldingSetNodeID &ID,
- ArrayRef<TemplateArgument> TemplateArgs, TemplateParameterList *TPL,
- ASTContext &Context) {
+void VarTemplatePartialSpecializationDecl::Profile(
+ llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
+ TemplateParameterList *TPL, const ASTContext &Context) {
ID.AddInteger(TemplateArgs.size());
for (const TemplateArgument &TemplateArg : TemplateArgs)
TemplateArg.Profile(ID, Context);
- ProfileTemplateParameterList(Context, ID, TPL);
+ TPL->Profile(ID, Context);
}
void VarTemplateDecl::AddPartialSpecialization(
More information about the cfe-commits
mailing list