15 #ifndef LLVM_CLANG_AST_TEMPLATEBASE_H
16 #define LLVM_CLANG_AST_TEMPLATEBASE_H
20 #include "llvm/ADT/APSInt.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/iterator_range.h"
23 #include "llvm/Support/Compiler.h"
24 #include "llvm/Support/ErrorHandling.h"
27 class FoldingSetNodeID;
32 class DiagnosticBuilder;
34 struct PrintingPolicy;
87 unsigned BitWidth : 31;
88 unsigned IsUnsigned : 1;
102 unsigned NumExpansions;
136 assert(D &&
"Expected decl");
202 this->Args.Kind =
Pack;
204 this->Args.NumArgs = NumArgs;
286 using namespace llvm;
290 unsigned NumWords = APInt::getNumWords(
Integer.BitWidth);
291 return APSInt(APInt(
Integer.BitWidth, makeArrayRef(
Integer.pVal, NumWords)),
345 return llvm::makeArrayRef(
Args.Args,
Args.NumArgs);
371 void *QualifierLocData;
372 unsigned TemplateNameLoc;
373 unsigned EllipsisLoc;
432 : Argument(Argument), LocInfo(Opaque) {
436 : Argument(Argument), LocInfo(TInfo) {
441 : Argument(Argument), LocInfo(E) {
449 : Argument(Argument), LocInfo(QualifierLoc, TemplateNameLoc, EllipsisLoc) {
458 return getTemplateNameLoc();
460 return getSourceRange().getBegin();
476 return LocInfo.getAsTypeSourceInfo();
481 return LocInfo.getAsExpr();
486 return LocInfo.getAsExpr();
491 return LocInfo.getAsExpr();
496 return LocInfo.getAsExpr();
502 return LocInfo.getTemplateQualifierLoc();
508 return LocInfo.getTemplateNameLoc();
513 return LocInfo.getTemplateEllipsisLoc();
533 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
541 unsigned size()
const {
return Arguments.size(); }
544 return Arguments.data();
556 Arguments.push_back(Loc);
579 llvm::AlignedCharArray<
580 llvm::AlignOf<TemplateArgumentLoc>::Alignment, 1>
Aligner;
594 return getTemplateArgs()[I];
602 bool &Dependent,
bool &InstantiationDependent,
603 bool &ContainsUnexpandedParameterPack);
605 static std::size_t sizeFor(
unsigned NumTemplateArgs);
620 (getTemplateArgs() + NumTemplateArgs);
626 (getTemplateArgs() + NumTemplateArgs) = TemplateKWLoc;
637 bool &Dependent,
bool &InstantiationDependent,
638 bool &ContainsUnexpandedParameterPack);
641 static std::size_t sizeFor(
unsigned NumTemplateArgs);
644 const DiagnosticBuilder &
operator<<(
const DiagnosticBuilder &DB,
649 return getArgs() + getNumArgs();
654 return getArgs() + getNumArgs();
659 assert(Idx < getNumArgs() &&
"Template argument out of range");
660 return getArgs()[Idx];
665 assert(Idx < getNumArgs() &&
"Template argument out of range");
666 return getArgs()[Idx];
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
Expr * getSourceExpression() const
llvm::iterator_range< pack_iterator > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
TemplateArgument(const TemplateArgument *Args, unsigned NumArgs)
Construct a template argument that is a template argument pack.
TemplateArgumentLoc & operator[](unsigned I)
TemplateArgument()
Construct an empty, invalid template argument.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
A container of type source information.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void * getAsOpaquePtr() const
const TemplateArgumentLoc * getArgumentArray() const
void setTemplateKeywordLoc(SourceLocation TemplateKWLoc)
Sets the source location of the template keyword.
void setRAngleLoc(SourceLocation Loc)
Information about one declarator, including the parsed type information and the identifier.
static TemplateArgument CreatePackCopy(ASTContext &Context, const TemplateArgument *Args, unsigned NumArgs)
Create a new template argument pack by copying the given set of template arguments.
Represents an empty template argument, e.g., one that has not been deduced.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>". This is safe to be used inside an AST node, in contrast with TemplateArgumentListInfo.
Describes how types, statements, expressions, and declarations should be printed. ...
static StringRef bytes(const std::vector< T, Allocator > &v)
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateArgument(const TemplateArgument &Other, QualType Type)
Construct an integral constant template argument with the same value as Other but a different type...
TemplateArgument(Expr *E)
Construct a template argument that is an expression.
const TemplateArgument * iterator
static TemplateArgument getEmptyPack()
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
SourceLocation getLocation() const
Fetches the primary location of the argument.
const TemplateArgumentLoc & operator[](unsigned I) const
TypeSourceInfo * getTypeSourceInfo() const
SourceLocation getTemplateEllipsisLoc() const
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep)
Creates clause with a list of variables VL and a linear step Step.
SourceLocation getRAngleLoc() const
SourceLocation getTemplateNameLoc() const
Extends ASTTemplateArgumentListInfo with the source location information for the template keyword; th...
ASTTemplateArgumentListInfo Base
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
ID
Defines the set of possible language-specific address spaces.
TemplateArgument(TemplateName Name, Optional< unsigned > NumExpansions)
Construct a template argument that is a template pack expansion.
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs. The actual template arguments (if any) are stored a...
ArgKind
The kind of template argument we're storing.
ArgKind getKind() const
Return the kind of stored template argument.
TypeSourceInfo * Declarator
Represents a C++ template name within the type system.
Expr * getSourceNullPtrExpression() const
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.
TemplateArgumentLocInfo(TypeSourceInfo *TInfo)
TemplateArgumentLoc * getTemplateArgs()
Retrieve the template arguments.
TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
SourceLocation getTemplateNameLoc() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
static TemplateName getFromVoidPointer(void *Ptr)
Build a template name from a void pointer.
Expr * getSourceIntegralExpression() const
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
void setIntegralType(QualType T)
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
SourceLocation getTemplateEllipsisLoc() const
TemplateArgumentLocInfo(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
SourceLocation getLAngleLoc() const
const TemplateArgumentLoc & operator[](unsigned I) const
llvm::AlignedCharArray< llvm::AlignOf< TemplateArgumentLoc >::Alignment, 1 > Aligner
static QualType getFromOpaquePtr(const void *Ptr)
void setLAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
TemplateArgumentListInfo()
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
TemplateArgumentLocInfo(Expr *E)
bool isNull() const
Determine whether this template argument has no value.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
const TemplateArgument & getArg(unsigned Idx) const
QualType getIntegralType() const
Retrieve the type of the integral value.
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
The template argument is a type.
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
Expr * getSourceDeclExpression() const
TemplateArgumentLocInfo getLocInfo() const
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
unsigned pack_size() const
The number of template arguments in the given template argument pack.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Location information for a TemplateArgument.
TemplateArgument(QualType T, bool isNullPtr=false)
Construct a template type argument.
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
QualType getParamTypeForDecl() const
SourceLocation getTemplateKeywordLoc() const
Get the source location of the template keyword.
TypeSourceInfo * getAsTypeSourceInfo() const
TemplateArgument(ValueDecl *D, QualType QT)
Construct a template argument that refers to a declaration, which is either an external declaration o...
TemplateArgument(TemplateName Name)
Construct a template argument that is a template.
TemplateArgumentLoc(const TemplateArgument &Argument, TemplateArgumentLocInfo Opaque)
A trivial tuple used to represent a source range.
TemplateArgumentLoc(const TemplateArgument &Argument, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc=SourceLocation())