clang  6.0.0svn
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
clang::TemplateArgument Class Reference

Represents a template argument. More...

#include "clang/AST/TemplateBase.h"

Inheritance diagram for clang::TemplateArgument:
Inheritance graph
[legend]
Collaboration diagram for clang::TemplateArgument:
Collaboration graph
[legend]

Public Types

enum  ArgKind {
  Null = 0, Type, Declaration, NullPtr,
  Integral, Template, TemplateExpansion, Expression,
  Pack
}
 The kind of template argument we're storing. More...
 
typedef const TemplateArgumentpack_iterator
 Iterator that traverses the elements of a template argument pack. More...
 

Public Member Functions

constexpr TemplateArgument ()
 Construct an empty, invalid template argument. More...
 
 TemplateArgument (QualType T, bool isNullPtr=false)
 Construct a template type argument. More...
 
 TemplateArgument (ValueDecl *D, QualType QT)
 Construct a template argument that refers to a declaration, which is either an external declaration or a template declaration. More...
 
 TemplateArgument (ASTContext &Ctx, const llvm::APSInt &Value, QualType Type)
 Construct an integral constant template argument. More...
 
 TemplateArgument (const TemplateArgument &Other, QualType Type)
 Construct an integral constant template argument with the same value as Other but a different type. More...
 
 TemplateArgument (TemplateName Name)
 Construct a template argument that is a template. More...
 
 TemplateArgument (TemplateName Name, Optional< unsigned > NumExpansions)
 Construct a template argument that is a template pack expansion. More...
 
 TemplateArgument (Expr *E)
 Construct a template argument that is an expression. More...
 
 TemplateArgument (ArrayRef< TemplateArgument > Args)
 Construct a template argument that is a template argument pack. More...
 
ArgKind getKind () const
 Return the kind of stored template argument. More...
 
bool isNull () const
 Determine whether this template argument has no value. More...
 
bool isDependent () const
 Whether this template argument is dependent on a template parameter such that its result can change from one instantiation to another. More...
 
bool isInstantiationDependent () const
 Whether this template argument is dependent on a template parameter. More...
 
bool containsUnexpandedParameterPack () const
 Whether this template argument contains an unexpanded parameter pack. More...
 
bool isPackExpansion () const
 Determine whether this template argument is a pack expansion. More...
 
QualType getAsType () const
 Retrieve the type for a type template argument. More...
 
ValueDeclgetAsDecl () const
 Retrieve the declaration for a declaration non-type template argument. More...
 
QualType getParamTypeForDecl () const
 
QualType getNullPtrType () const
 Retrieve the type for null non-type template argument. More...
 
TemplateName getAsTemplate () const
 Retrieve the template name for a template name argument. More...
 
TemplateName getAsTemplateOrTemplatePattern () const
 Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name. More...
 
Optional< unsigned > getNumTemplateExpansions () const
 Retrieve the number of expansions that a template template argument expansion will produce, if known. More...
 
llvm::APSInt getAsIntegral () const
 Retrieve the template argument as an integral value. More...
 
QualType getIntegralType () const
 Retrieve the type of the integral value. More...
 
void setIntegralType (QualType T)
 
QualType getNonTypeTemplateArgumentType () const
 If this is a non-type template argument, get its type. More...
 
ExprgetAsExpr () const
 Retrieve the template argument as an expression. More...
 
pack_iterator pack_begin () const
 Iterator referencing the first argument of a template argument pack. More...
 
pack_iterator pack_end () const
 Iterator referencing one past the last argument of a template argument pack. More...
 
ArrayRef< TemplateArgumentpack_elements () const
 Iterator range referencing all of the elements of a template argument pack. More...
 
unsigned pack_size () const
 The number of template arguments in the given template argument pack. More...
 
ArrayRef< TemplateArgumentgetPackAsArray () const
 Return the array of arguments in this template argument pack. More...
 
bool structurallyEquals (const TemplateArgument &Other) const
 Determines whether two template arguments are superficially the same. More...
 
TemplateArgument getPackExpansionPattern () const
 When the template argument is a pack expansion, returns the pattern of the pack expansion. More...
 
void print (const PrintingPolicy &Policy, raw_ostream &Out) const
 Print this template argument to the given output stream. More...
 
void dump (raw_ostream &Out) const
 Debugging aid that dumps the template argument. More...
 
void dump () const
 Debugging aid that dumps the template argument to standard error. More...
 
void Profile (llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
 Used to insert TemplateArguments into FoldingSets. More...
 

Static Public Member Functions

static TemplateArgument getEmptyPack ()
 
static TemplateArgument CreatePackCopy (ASTContext &Context, ArrayRef< TemplateArgument > Args)
 Create a new template argument pack by copying the given set of template arguments. More...
 

Detailed Description

Represents a template argument.

Definition at line 40 of file TemplateBase.h.

Member Typedef Documentation

◆ pack_iterator

Iterator that traverses the elements of a template argument pack.

Definition at line 312 of file TemplateBase.h.

Member Enumeration Documentation

◆ ArgKind

The kind of template argument we're storing.

Enumerator
Null 

Represents an empty template argument, e.g., one that has not been deduced.

Type 

The template argument is a type.

Declaration 

The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.

NullPtr 

The template argument is a null pointer or null pointer to member that was provided for a non-type template parameter.

Integral 

The template argument is an integral value stored in an llvm::APSInt that was provided for an integral non-type template parameter.

Template 

The template argument is a template name that was provided for a template template parameter.

TemplateExpansion 

The template argument is a pack expansion of a template name that was provided for a template template parameter.

Expression 

The template argument is an expression, and we've not resolved it to one of the other forms yet, either because it's dependent or because we're representing a non-canonical template argument (for instance, in a TemplateSpecializationType).

Also used to represent a non-dependent __uuidof expression (a Microsoft extension).

Pack 

The template argument is actually a parameter pack.

Arguments are stored in the Args struct.

Definition at line 43 of file TemplateBase.h.

Constructor & Destructor Documentation

◆ TemplateArgument() [1/9]

constexpr clang::TemplateArgument::TemplateArgument ( )
inline

Construct an empty, invalid template argument.

Definition at line 122 of file TemplateBase.h.

Referenced by getPackExpansionPattern().

◆ TemplateArgument() [2/9]

clang::TemplateArgument::TemplateArgument ( QualType  T,
bool  isNullPtr = false 
)
inline

Construct a template type argument.

Definition at line 125 of file TemplateBase.h.

References clang::QualType::getAsOpaquePtr().

◆ TemplateArgument() [3/9]

clang::TemplateArgument::TemplateArgument ( ValueDecl D,
QualType  QT 
)
inline

Construct a template argument that refers to a declaration, which is either an external declaration or a template declaration.

Definition at line 133 of file TemplateBase.h.

References clang::QualType::getAsOpaquePtr().

◆ TemplateArgument() [4/9]

TemplateArgument::TemplateArgument ( ASTContext Ctx,
const llvm::APSInt &  Value,
QualType  Type 
)

Construct an integral constant template argument.

The memory to store the value is allocated with Ctx.

Definition at line 72 of file TemplateBase.cpp.

References clang::ASTContext::Allocate(), clang::QualType::getAsOpaquePtr(), Integer, and Integral.

◆ TemplateArgument() [5/9]

clang::TemplateArgument::TemplateArgument ( const TemplateArgument Other,
QualType  Type 
)
inline

Construct an integral constant template argument with the same value as Other but a different type.

Definition at line 146 of file TemplateBase.h.

References clang::QualType::getAsOpaquePtr(), and Integer.

◆ TemplateArgument() [6/9]

clang::TemplateArgument::TemplateArgument ( TemplateName  Name)
inline

Construct a template argument that is a template.

This form of template argument is generally used for template template parameters. However, the template name could be a dependent template name that ends up being instantiated to a function template whose address is taken.

Parameters
NameThe template name.

Definition at line 159 of file TemplateBase.h.

◆ TemplateArgument() [7/9]

clang::TemplateArgument::TemplateArgument ( TemplateName  Name,
Optional< unsigned >  NumExpansions 
)
inline

Construct a template argument that is a template pack expansion.

This form of template argument is generally used for template template parameters. However, the template name could be a dependent template name that ends up being instantiated to a function template whose address is taken.

Parameters
NameThe template name.
NumExpansionsThe number of expansions that will be generated by instantiating

Definition at line 176 of file TemplateBase.h.

◆ TemplateArgument() [8/9]

clang::TemplateArgument::TemplateArgument ( Expr E)
inline

Construct a template argument that is an expression.

This form of template argument only occurs in template argument lists used for dependent types and for expression; it will not occur in a non-dependent, canonical template argument list.

Definition at line 190 of file TemplateBase.h.

◆ TemplateArgument() [9/9]

clang::TemplateArgument::TemplateArgument ( ArrayRef< TemplateArgument Args)
inlineexplicit

Construct a template argument that is a template argument pack.

We assume that storage for the template arguments provided outlives the TemplateArgument itself.

Definition at line 199 of file TemplateBase.h.

Member Function Documentation

◆ containsUnexpandedParameterPack()

bool TemplateArgument::containsUnexpandedParameterPack ( ) const

Whether this template argument contains an unexpanded parameter pack.

Definition at line 203 of file TemplateBase.cpp.

References Declaration, Expression, getAsExpr(), getAsTemplate(), getAsType(), getKind(), Integral, Null, NullPtr, P, Pack, pack_elements(), Template, TemplateExpansion, and Type.

Referenced by clang::Sema::DiagnoseUnexpandedParameterPack(), and clang::Sema::getFullyPackExpandedSize().

◆ CreatePackCopy()

TemplateArgument TemplateArgument::CreatePackCopy ( ASTContext Context,
ArrayRef< TemplateArgument Args 
)
static

Create a new template argument pack by copying the given set of template arguments.

Definition at line 92 of file TemplateBase.cpp.

Referenced by clang::Sema::CheckTemplateArgumentList(), and ConvertDeducedTemplateArgument().

◆ dump() [1/2]

void TemplateArgument::dump ( raw_ostream &  Out) const

Debugging aid that dumps the template argument.

Definition at line 443 of file TemplateBase.cpp.

References print().

◆ dump() [2/2]

LLVM_DUMP_METHOD void TemplateArgument::dump ( ) const

Debugging aid that dumps the template argument to standard error.

Definition at line 450 of file TemplateBase.cpp.

◆ getAsDecl()

ValueDecl* clang::TemplateArgument::getAsDecl ( ) const
inline

◆ getAsExpr()

Expr* clang::TemplateArgument::getAsExpr ( ) const
inline

◆ getAsIntegral()

llvm::APSInt clang::TemplateArgument::getAsIntegral ( ) const
inline

Retrieve the template argument as an integral value.

Definition at line 279 of file TemplateBase.h.

References getKind().

Referenced by clang::ASTRecordWriter::AddTemplateArgument(), DeduceTemplateArguments(), clang::operator<<(), printIntegral(), and structurallyEquals().

◆ getAsTemplate()

TemplateName clang::TemplateArgument::getAsTemplate ( ) const
inline

◆ getAsTemplateOrTemplatePattern()

TemplateName clang::TemplateArgument::getAsTemplateOrTemplatePattern ( ) const
inline

◆ getAsType()

QualType clang::TemplateArgument::getAsType ( ) const
inline

◆ getEmptyPack()

static TemplateArgument clang::TemplateArgument::getEmptyPack ( )
inlinestatic

Definition at line 205 of file TemplateBase.h.

References clang::diff::None.

◆ getIntegralType()

QualType clang::TemplateArgument::getIntegralType ( ) const
inline

◆ getKind()

ArgKind clang::TemplateArgument::getKind ( ) const
inline

Return the kind of stored template argument.

Definition at line 213 of file TemplateBase.h.

Referenced by addAssociatedClassesAndNamespaces(), clang::ODRHash::AddTemplateArgument(), clang::ASTRecordWriter::AddTemplateArgument(), clang::ASTRecordWriter::AddTemplateArgumentLoc(), clang::Sema::BuildExpressionFromIntegralTemplateArgument(), clang::Sema::CheckTemplateArgument(), clang::Sema::CheckTemplateTypeArgument(), containsUnexpandedParameterPack(), ConvertDeducedTemplateArgument(), DeduceTemplateArguments(), clang::ASTContext::getCanonicalTemplateArgument(), clang::Sema::getFullyPackExpandedSize(), clang::TypeName::getFullyQualifiedTemplateArgument(), clang::comments::getFunctionTypeLoc(), clang::TemplateArgumentLoc::getLocation(), getNonTypeTemplateArgumentType(), getNumTemplateExpansions(), getPackExpansionPattern(), clang::TemplateArgumentLoc::getSourceDeclExpression(), clang::TemplateArgumentLoc::getSourceExpression(), clang::TemplateArgumentLoc::getSourceIntegralExpression(), clang::TemplateArgumentLoc::getSourceNullPtrExpression(), clang::Sema::getTemplateArgumentPackExpansionPattern(), clang::TemplateArgumentLoc::getTemplateEllipsisLoc(), clang::TemplateArgumentLoc::getTemplateNameLoc(), clang::TemplateArgumentLoc::getTemplateQualifierLoc(), clang::Sema::getTrivialTemplateArgumentLoc(), clang::TemplateArgumentLoc::getTypeSourceInfo(), hasTemplateArgumentForDeduction(), clang::ASTNodeImporter::ImportTemplateArgument(), clang::ASTNodeImporter::ImportTemplateArgumentLoc(), clang::TreeTransform< Derived >::InventTemplateArgumentLoc(), isDependent(), isEnableIf(), isInstantiationDependent(), isPackExpansion(), isTemplateArgumentTemplateParameter(), MarkUsedTemplateParameters(), clang::operator<<(), print(), clang::ASTReader::ReadTemplateArgumentLoc(), clang::TreeTransform< Derived >::RebuildPackExpansion(), structurallyEquals(), clang::TemplateArgumentLoc::TemplateArgumentLoc(), clang::TreeTransform< Derived >::TransformTemplateArguments(), clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArgument(), clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArgumentLoc(), and clang::TypeLocReader::VisitFunctionTypeLoc().

◆ getNonTypeTemplateArgumentType()

QualType TemplateArgument::getNonTypeTemplateArgumentType ( ) const

If this is a non-type template argument, get its type.

Otherwise, returns a null QualType.

Definition at line 246 of file TemplateBase.cpp.

References Declaration, Expression, getAsExpr(), getIntegralType(), getKind(), getNullPtrType(), getParamTypeForDecl(), clang::Expr::getType(), Integral, Null, NullPtr, Pack, Template, TemplateExpansion, and Type.

◆ getNullPtrType()

QualType clang::TemplateArgument::getNullPtrType ( ) const
inline

◆ getNumTemplateExpansions()

Optional< unsigned > TemplateArgument::getNumTemplateExpansions ( ) const

Retrieve the number of expansions that a template template argument expansion will produce, if known.

Definition at line 238 of file TemplateBase.cpp.

References getKind(), clang::None, TemplateArg, and TemplateExpansion.

Referenced by clang::ASTRecordWriter::AddTemplateArgument(), clang::ASTContext::getCanonicalTemplateArgument(), and clang::ASTNodeImporter::ImportTemplateArgument().

◆ getPackAsArray()

ArrayRef<TemplateArgument> clang::TemplateArgument::getPackAsArray ( ) const
inline

Return the array of arguments in this template argument pack.

Definition at line 342 of file TemplateBase.h.

References dump(), and getKind().

◆ getPackExpansionPattern()

TemplateArgument TemplateArgument::getPackExpansionPattern ( ) const

When the template argument is a pack expansion, returns the pattern of the pack expansion.

Definition at line 354 of file TemplateBase.cpp.

References Declaration, Expression, clang::Type::getAs(), getAsExpr(), getAsTemplateOrTemplatePattern(), getAsType(), getKind(), Integral, isPackExpansion(), Null, NullPtr, Pack, Template, TemplateArgument(), TemplateExpansion, and Type.

Referenced by DeduceTemplateArguments().

◆ getParamTypeForDecl()

QualType clang::TemplateArgument::getParamTypeForDecl ( ) const
inline

◆ isDependent()

bool TemplateArgument::isDependent ( ) const

Whether this template argument is dependent on a template parameter such that its result can change from one instantiation to another.

Definition at line 100 of file TemplateBase.cpp.

References Declaration, Expression, getAsDecl(), getAsExpr(), getAsTemplate(), getAsType(), clang::Decl::getDeclContext(), getKind(), Integral, clang::TemplateName::isDependent(), clang::DeclContext::isDependentContext(), clang::Type::isDependentType(), Null, NullPtr, P, Pack, pack_elements(), Template, TemplateExpansion, and Type.

◆ isInstantiationDependent()

bool TemplateArgument::isInstantiationDependent ( ) const

◆ isNull()

bool clang::TemplateArgument::isNull ( ) const
inline

◆ isPackExpansion()

bool TemplateArgument::isPackExpansion ( ) const

◆ pack_begin()

pack_iterator clang::TemplateArgument::pack_begin ( ) const
inline

◆ pack_elements()

ArrayRef<TemplateArgument> clang::TemplateArgument::pack_elements ( ) const
inline

◆ pack_end()

pack_iterator clang::TemplateArgument::pack_end ( ) const
inline

Iterator referencing one past the last argument of a template argument pack.

Definition at line 323 of file TemplateBase.h.

References getKind().

Referenced by clang::ASTContext::getCanonicalTemplateArgument(), and clang::TreeTransform< Derived >::TransformTemplateArguments().

◆ pack_size()

unsigned clang::TemplateArgument::pack_size ( ) const
inline

◆ print()

void TemplateArgument::print ( const PrintingPolicy Policy,
raw_ostream &  Out 
) const

◆ Profile()

void TemplateArgument::Profile ( llvm::FoldingSetNodeID &  ID,
const ASTContext Context 
) const

Used to insert TemplateArguments into FoldingSets.

Definition at line 271 of file TemplateBase.cpp.

◆ setIntegralType()

void clang::TemplateArgument::setIntegralType ( QualType  T)
inline

Definition at line 296 of file TemplateBase.h.

References clang::QualType::getAsOpaquePtr(), and getKind().

◆ structurallyEquals()

bool TemplateArgument::structurallyEquals ( const TemplateArgument Other) const

Determines whether two template arguments are superficially the same.

Definition at line 324 of file TemplateBase.cpp.

References Args, Declaration, Expression, getAsDecl(), getAsIntegral(), getIntegralType(), getKind(), Integral, Null, NullPtr, Pack, Template, TemplateExpansion, Type, and TypeOrValue.

Member Data Documentation

◆ Args

struct A clang::TemplateArgument::Args

Definition at line 113 of file TemplateBase.h.

Referenced by structurallyEquals().

◆ DeclArg

struct DA clang::TemplateArgument::DeclArg

Definition at line 111 of file TemplateBase.h.

◆ Integer

struct I clang::TemplateArgument::Integer

Definition at line 112 of file TemplateBase.h.

Referenced by TemplateArgument().

◆ TemplateArg

struct TA clang::TemplateArgument::TemplateArg

Definition at line 114 of file TemplateBase.h.

Referenced by getNumTemplateExpansions().

◆ TypeOrValue

struct TV clang::TemplateArgument::TypeOrValue

Definition at line 115 of file TemplateBase.h.

Referenced by structurallyEquals().


The documentation for this class was generated from the following files: