|
@@ -168,6 +168,16 @@ public:
|
|
return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr;
|
|
return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// \brief All associated constraints derived from this template parameter
|
|
|
|
+ /// list, including the requires clause and any constraints derived from
|
|
|
|
+ /// constrained-parameters.
|
|
|
|
+ ///
|
|
|
|
+ /// The constraints in the resulting list are to be treated as if in a
|
|
|
|
+ /// conjunction ("and").
|
|
|
|
+ void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const;
|
|
|
|
+
|
|
|
|
+ bool hasAssociatedConstraints() const;
|
|
|
|
+
|
|
SourceLocation getTemplateLoc() const { return TemplateLoc; }
|
|
SourceLocation getTemplateLoc() const { return TemplateLoc; }
|
|
SourceLocation getLAngleLoc() const { return LAngleLoc; }
|
|
SourceLocation getLAngleLoc() const { return LAngleLoc; }
|
|
SourceLocation getRAngleLoc() const { return RAngleLoc; }
|
|
SourceLocation getRAngleLoc() const { return RAngleLoc; }
|
|
@@ -369,33 +379,7 @@ public:
|
|
// Kinds of Templates
|
|
// Kinds of Templates
|
|
//===----------------------------------------------------------------------===//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
-/// Stores the template parameter list and associated constraints for
|
|
|
|
-/// \c TemplateDecl objects that track associated constraints.
|
|
|
|
-class ConstrainedTemplateDeclInfo {
|
|
|
|
- friend TemplateDecl;
|
|
|
|
-
|
|
|
|
-public:
|
|
|
|
- ConstrainedTemplateDeclInfo() = default;
|
|
|
|
-
|
|
|
|
- TemplateParameterList *getTemplateParameters() const {
|
|
|
|
- return TemplateParams;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Expr *getAssociatedConstraints() const { return AssociatedConstraints; }
|
|
|
|
-
|
|
|
|
-protected:
|
|
|
|
- void setTemplateParameters(TemplateParameterList *TParams) {
|
|
|
|
- TemplateParams = TParams;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void setAssociatedConstraints(Expr *AC) { AssociatedConstraints = AC; }
|
|
|
|
-
|
|
|
|
- TemplateParameterList *TemplateParams = nullptr;
|
|
|
|
- Expr *AssociatedConstraints = nullptr;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/// The base class of all kinds of template declarations (e.g.,
|
|
|
|
|
|
+/// \brief The base class of all kinds of template declarations (e.g.,
|
|
/// class, function, etc.).
|
|
/// class, function, etc.).
|
|
///
|
|
///
|
|
/// The TemplateDecl class stores the list of template parameters and a
|
|
/// The TemplateDecl class stores the list of template parameters and a
|
|
@@ -404,54 +388,32 @@ class TemplateDecl : public NamedDecl {
|
|
void anchor() override;
|
|
void anchor() override;
|
|
|
|
|
|
protected:
|
|
protected:
|
|
|
|
+ // Construct a template decl with name, parameters, and templated element.
|
|
|
|
+ TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
|
|
+ TemplateParameterList *Params, NamedDecl *Decl);
|
|
|
|
+
|
|
// Construct a template decl with the given name and parameters.
|
|
// Construct a template decl with the given name and parameters.
|
|
// Used when there is no templated element (e.g., for tt-params).
|
|
// Used when there is no templated element (e.g., for tt-params).
|
|
- TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
|
|
|
|
- SourceLocation L, DeclarationName Name,
|
|
|
|
- TemplateParameterList *Params)
|
|
|
|
- : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr),
|
|
|
|
- TemplateParams(CTDI) {
|
|
|
|
- this->setTemplateParameters(Params);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
TemplateParameterList *Params)
|
|
TemplateParameterList *Params)
|
|
- : TemplateDecl(nullptr, DK, DC, L, Name, Params) {}
|
|
|
|
-
|
|
|
|
- // Construct a template decl with name, parameters, and templated element.
|
|
|
|
- TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
|
|
|
|
- SourceLocation L, DeclarationName Name,
|
|
|
|
- TemplateParameterList *Params, NamedDecl *Decl)
|
|
|
|
- : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl),
|
|
|
|
- TemplateParams(CTDI) {
|
|
|
|
- this->setTemplateParameters(Params);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
|
|
- TemplateParameterList *Params, NamedDecl *Decl)
|
|
|
|
- : TemplateDecl(nullptr, DK, DC, L, Name, Params, Decl) {}
|
|
|
|
|
|
+ : TemplateDecl(DK, DC, L, Name, Params, nullptr) {}
|
|
|
|
|
|
public:
|
|
public:
|
|
|
|
+ friend class ASTDeclReader;
|
|
|
|
+ friend class ASTDeclWriter;
|
|
|
|
+
|
|
/// Get the list of template parameters
|
|
/// Get the list of template parameters
|
|
TemplateParameterList *getTemplateParameters() const {
|
|
TemplateParameterList *getTemplateParameters() const {
|
|
- const auto *const CTDI =
|
|
|
|
- TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>();
|
|
|
|
- return CTDI ? CTDI->getTemplateParameters()
|
|
|
|
- : TemplateParams.get<TemplateParameterList *>();
|
|
|
|
|
|
+ return TemplateParams;
|
|
}
|
|
}
|
|
|
|
|
|
- /// Get the constraint-expression from the associated requires-clause (if any)
|
|
|
|
- const Expr *getRequiresClause() const {
|
|
|
|
- const TemplateParameterList *const TP = getTemplateParameters();
|
|
|
|
- return TP ? TP->getRequiresClause() : nullptr;
|
|
|
|
- }
|
|
|
|
|
|
+ /// \brief Get the total constraint-expression associated with this template,
|
|
|
|
+ /// including constraint-expressions derived from the requires-clause,
|
|
|
|
+ /// trailing requires-clause (for functions and methods) and constrained
|
|
|
|
+ /// template parameters.
|
|
|
|
+ void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const;
|
|
|
|
|
|
- Expr *getAssociatedConstraints() const {
|
|
|
|
- const auto *const C = cast<TemplateDecl>(getCanonicalDecl());
|
|
|
|
- const auto *const CTDI =
|
|
|
|
- C->TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>();
|
|
|
|
- return CTDI ? CTDI->getAssociatedConstraints() : nullptr;
|
|
|
|
- }
|
|
|
|
|
|
+ bool hasAssociatedConstraints() const;
|
|
|
|
|
|
/// Get the underlying, templated declaration.
|
|
/// Get the underlying, templated declaration.
|
|
NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
|
|
NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
|
|
@@ -470,29 +432,10 @@ public:
|
|
|
|
|
|
protected:
|
|
protected:
|
|
NamedDecl *TemplatedDecl;
|
|
NamedDecl *TemplatedDecl;
|
|
-
|
|
|
|
- /// The template parameter list and optional requires-clause
|
|
|
|
- /// associated with this declaration; alternatively, a
|
|
|
|
- /// \c ConstrainedTemplateDeclInfo if the associated constraints of the
|
|
|
|
- /// template are being tracked by this particular declaration.
|
|
|
|
- llvm::PointerUnion<TemplateParameterList *,
|
|
|
|
- ConstrainedTemplateDeclInfo *>
|
|
|
|
- TemplateParams;
|
|
|
|
|
|
+ TemplateParameterList *TemplateParams;
|
|
|
|
|
|
void setTemplateParameters(TemplateParameterList *TParams) {
|
|
void setTemplateParameters(TemplateParameterList *TParams) {
|
|
- if (auto *const CTDI =
|
|
|
|
- TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>()) {
|
|
|
|
- CTDI->setTemplateParameters(TParams);
|
|
|
|
- } else {
|
|
|
|
- TemplateParams = TParams;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void setAssociatedConstraints(Expr *AC) {
|
|
|
|
- assert(isCanonicalDecl() &&
|
|
|
|
- "Attaching associated constraints to non-canonical Decl");
|
|
|
|
- TemplateParams.get<ConstrainedTemplateDeclInfo *>()
|
|
|
|
- ->setAssociatedConstraints(AC);
|
|
|
|
|
|
+ TemplateParams = TParams;
|
|
}
|
|
}
|
|
|
|
|
|
public:
|
|
public:
|
|
@@ -889,17 +832,10 @@ protected:
|
|
virtual CommonBase *newCommon(ASTContext &C) const = 0;
|
|
virtual CommonBase *newCommon(ASTContext &C) const = 0;
|
|
|
|
|
|
// Construct a template decl with name, parameters, and templated element.
|
|
// Construct a template decl with name, parameters, and templated element.
|
|
- RedeclarableTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK,
|
|
|
|
- ASTContext &C, DeclContext *DC, SourceLocation L,
|
|
|
|
- DeclarationName Name, TemplateParameterList *Params,
|
|
|
|
- NamedDecl *Decl)
|
|
|
|
- : TemplateDecl(CTDI, DK, DC, L, Name, Params, Decl), redeclarable_base(C)
|
|
|
|
- {}
|
|
|
|
-
|
|
|
|
RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC,
|
|
RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC,
|
|
SourceLocation L, DeclarationName Name,
|
|
SourceLocation L, DeclarationName Name,
|
|
TemplateParameterList *Params, NamedDecl *Decl)
|
|
TemplateParameterList *Params, NamedDecl *Decl)
|
|
- : RedeclarableTemplateDecl(nullptr, DK, C, DC, L, Name, Params, Decl) {}
|
|
|
|
|
|
+ : TemplateDecl(DK, DC, L, Name, Params, Decl), redeclarable_base(C) {}
|
|
|
|
|
|
public:
|
|
public:
|
|
friend class ASTDeclReader;
|
|
friend class ASTDeclReader;
|
|
@@ -2026,6 +1962,20 @@ public:
|
|
return TemplateParams;
|
|
return TemplateParams;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// \brief All associated constraints of this partial specialization,
|
|
|
|
+ /// including the requires clause and any constraints derived from
|
|
|
|
+ /// constrained-parameters.
|
|
|
|
+ ///
|
|
|
|
+ /// The constraints in the resulting list are to be treated as if in a
|
|
|
|
+ /// conjunction ("and").
|
|
|
|
+ void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
|
|
|
|
+ TemplateParams->getAssociatedConstraints(AC);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool hasAssociatedConstraints() const {
|
|
|
|
+ return TemplateParams->hasAssociatedConstraints();
|
|
|
|
+ }
|
|
|
|
+
|
|
/// Get the template arguments as written.
|
|
/// Get the template arguments as written.
|
|
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
|
|
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
|
|
return ArgsAsWritten;
|
|
return ArgsAsWritten;
|
|
@@ -2145,16 +2095,10 @@ protected:
|
|
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
|
|
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
|
|
getPartialSpecializations();
|
|
getPartialSpecializations();
|
|
|
|
|
|
- ClassTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, ASTContext &C,
|
|
|
|
- DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
|
|
- TemplateParameterList *Params, NamedDecl *Decl)
|
|
|
|
- : RedeclarableTemplateDecl(CTDI, ClassTemplate, C, DC, L, Name, Params,
|
|
|
|
- Decl) {}
|
|
|
|
-
|
|
|
|
ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
|
|
ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
|
|
DeclarationName Name, TemplateParameterList *Params,
|
|
DeclarationName Name, TemplateParameterList *Params,
|
|
NamedDecl *Decl)
|
|
NamedDecl *Decl)
|
|
- : ClassTemplateDecl(nullptr, C, DC, L, Name, Params, Decl) {}
|
|
|
|
|
|
+ : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
|
|
|
|
|
|
CommonBase *newCommon(ASTContext &C) const override;
|
|
CommonBase *newCommon(ASTContext &C) const override;
|
|
|
|
|
|
@@ -2180,14 +2124,12 @@ public:
|
|
return getTemplatedDecl()->isThisDeclarationADefinition();
|
|
return getTemplatedDecl()->isThisDeclarationADefinition();
|
|
}
|
|
}
|
|
|
|
|
|
- // FIXME: remove default argument for AssociatedConstraints
|
|
|
|
- /// Create a class template node.
|
|
|
|
|
|
+ /// \brief Create a class template node.
|
|
static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC,
|
|
static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC,
|
|
SourceLocation L,
|
|
SourceLocation L,
|
|
DeclarationName Name,
|
|
DeclarationName Name,
|
|
TemplateParameterList *Params,
|
|
TemplateParameterList *Params,
|
|
- NamedDecl *Decl,
|
|
|
|
- Expr *AssociatedConstraints = nullptr);
|
|
|
|
|
|
+ NamedDecl *Decl);
|
|
|
|
|
|
/// Create an empty class template node.
|
|
/// Create an empty class template node.
|
|
static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
|
|
static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
|
|
@@ -2862,7 +2804,21 @@ public:
|
|
return ArgsAsWritten;
|
|
return ArgsAsWritten;
|
|
}
|
|
}
|
|
|
|
|
|
- /// Retrieve the member variable template partial specialization from
|
|
|
|
|
|
+ /// \brief All associated constraints of this partial specialization,
|
|
|
|
+ /// including the requires clause and any constraints derived from
|
|
|
|
+ /// constrained-parameters.
|
|
|
|
+ ///
|
|
|
|
+ /// The constraints in the resulting list are to be treated as if in a
|
|
|
|
+ /// conjunction ("and").
|
|
|
|
+ void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
|
|
|
|
+ TemplateParams->getAssociatedConstraints(AC);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool hasAssociatedConstraints() const {
|
|
|
|
+ return TemplateParams->hasAssociatedConstraints();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// \brief Retrieve the member variable template partial specialization from
|
|
/// which this particular variable template partial specialization was
|
|
/// which this particular variable template partial specialization was
|
|
/// instantiated.
|
|
/// instantiated.
|
|
///
|
|
///
|
|
@@ -3091,11 +3047,9 @@ class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
|
|
protected:
|
|
protected:
|
|
Expr *ConstraintExpr;
|
|
Expr *ConstraintExpr;
|
|
|
|
|
|
- ConceptDecl(DeclContext *DC,
|
|
|
|
- SourceLocation L, DeclarationName Name,
|
|
|
|
- TemplateParameterList *Params,
|
|
|
|
- Expr *ConstraintExpr)
|
|
|
|
- : TemplateDecl(nullptr, Concept, DC, L, Name, Params),
|
|
|
|
|
|
+ ConceptDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
|
|
|
|
+ TemplateParameterList *Params, Expr *ConstraintExpr)
|
|
|
|
+ : TemplateDecl(Concept, DC, L, Name, Params),
|
|
ConstraintExpr(ConstraintExpr) {};
|
|
ConstraintExpr(ConstraintExpr) {};
|
|
public:
|
|
public:
|
|
static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
|
|
static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
|