diff options
Diffstat (limited to 'include/clang/AST/DeclTemplate.h')
-rw-r--r-- | include/clang/AST/DeclTemplate.h | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 226af34..d189900 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -203,6 +203,9 @@ public: /// Get the position of the template parameter within its parameter list. unsigned getPosition() const { return Position; } + + /// Get the index of the template parameter within its parameter list. + unsigned getIndex() const { return Position; } }; /// TemplateTypeParmDecl - Declaration of a template type parameter, @@ -299,7 +302,8 @@ public: using TemplateParmPosition::getDepth; using TemplateParmPosition::getPosition; - + using TemplateParmPosition::getIndex; + /// \brief Determine whether this template parameter has a default /// argument. bool hasDefaultArgument() const { return DefaultArgument; } @@ -350,7 +354,8 @@ public: using TemplateParmPosition::getDepth; using TemplateParmPosition::getPosition; - + using TemplateParmPosition::getIndex; + /// \brief Determine whether this template parameter has a default /// argument. bool hasDefaultArgument() const { return DefaultArgument; } @@ -390,20 +395,21 @@ class TemplateArgument { public: /// \brief The type of template argument we're storing. enum ArgKind { + Null = 0, /// The template argument is a type. It's value is stored in the /// TypeOrValue field. - Type = 0, + Type = 1, /// The template argument is a declaration - Declaration = 1, + Declaration = 2, /// The template argument is an integral value stored in an llvm::APSInt. - Integral = 2, + Integral = 3, /// The template argument is a value- or type-dependent expression /// stored in an Expr*. - Expression = 3 + Expression = 4 } Kind; /// \brief Construct an empty, invalid template argument. - TemplateArgument() : TypeOrValue(0), StartLoc(), Kind(Type) { } + TemplateArgument() : TypeOrValue(0), StartLoc(), Kind(Null) { } /// \brief Construct a template type argument. TemplateArgument(SourceLocation Loc, QualType T) : Kind(Type) { @@ -484,6 +490,9 @@ public: /// \brief Return the kind of stored template argument. ArgKind getKind() const { return Kind; } + /// \brief Determine whether this template argument has no value. + bool isNull() const { return Kind == Null; } + /// \brief Retrieve the template argument as a type. QualType getAsType() const { if (Kind != Type) @@ -519,6 +528,12 @@ public: return QualType::getFromOpaquePtr(Integer.Type); } + void setIntegralType(QualType T) { + assert(Kind == Integral && + "Cannot set the integral type of a non-integral template argument"); + Integer.Type = T.getAsOpaquePtr(); + }; + /// \brief Retrieve the template argument as an expression. Expr *getAsExpr() const { if (Kind != Expression) @@ -534,6 +549,9 @@ public: void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(Kind); switch (Kind) { + case Null: + break; + case Type: getAsType().Profile(ID); break; @@ -555,6 +573,22 @@ public: } }; +/// \brief A helper class for making template argument lists. +class TemplateArgumentListBuilder { + llvm::SmallVector<TemplateArgument, 16> Args; + + ASTContext &Context; +public: + TemplateArgumentListBuilder(ASTContext &Context) : Context(Context) { } + + // FIXME: Should use the index array size. + size_t size() const { return Args.size(); } + size_t flatSize() const { return Args.size(); } + + void push_back(const TemplateArgument& Arg); + TemplateArgument *getFlatArgumentList() { return Args.data(); } +}; + /// \brief A template argument list. /// /// FIXME: In the future, this class will be extended to support @@ -571,12 +605,10 @@ class TemplateArgumentList { /// argument list. unsigned NumArguments; - public: TemplateArgumentList(ASTContext &Context, - TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs, - bool CopyArgs); + TemplateArgumentListBuilder &Builder, + bool CopyArgs, bool FlattenArgs); ~TemplateArgumentList(); @@ -660,14 +692,13 @@ protected: ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, DeclContext *DC, SourceLocation L, ClassTemplateDecl *SpecializedTemplate, - TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); + TemplateArgumentListBuilder &Builder); public: static ClassTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation L, ClassTemplateDecl *SpecializedTemplate, - TemplateArgument *TemplateArgs, unsigned NumTemplateArgs, + TemplateArgumentListBuilder &Builder, ClassTemplateSpecializationDecl *PrevDecl); /// \brief Retrieve the template that this specialization specializes. @@ -730,11 +761,9 @@ class ClassTemplatePartialSpecializationDecl DeclContext *DC, SourceLocation L, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, - TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs) + TemplateArgumentListBuilder &Builder) : ClassTemplateSpecializationDecl(Context, ClassTemplatePartialSpecialization, - DC, L, SpecializedTemplate, TemplateArgs, - NumTemplateArgs), + DC, L, SpecializedTemplate, Builder), TemplateParams(Params) { } public: @@ -742,7 +771,7 @@ public: Create(ASTContext &Context, DeclContext *DC, SourceLocation L, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, - TemplateArgument *TemplateArgs, unsigned NumTemplateArgs, + TemplateArgumentListBuilder &Builder, ClassTemplatePartialSpecializationDecl *PrevDecl); /// Get the list of template parameters |