15 #ifndef LLVM_CLANG_AST_TEMPLATEBASE_H 16 #define LLVM_CLANG_AST_TEMPLATEBASE_H 23 #include "llvm/ADT/APInt.h" 24 #include "llvm/ADT/APSInt.h" 25 #include "llvm/ADT/ArrayRef.h" 26 #include "llvm/ADT/None.h" 27 #include "llvm/ADT/Optional.h" 28 #include "llvm/ADT/SmallVector.h" 29 #include "llvm/Support/Compiler.h" 30 #include "llvm/Support/TrailingObjects.h" 37 class FoldingSetNodeID;
44 class DiagnosticBuilder;
46 struct PrintingPolicy;
107 unsigned BitWidth : 31;
108 unsigned IsUnsigned : 1;
114 const uint64_t *pVal;
125 unsigned NumExpansions;
136 struct TA TemplateArg;
137 struct TV TypeOrValue;
146 TypeOrValue.Kind = isNullPtr ? NullPtr :
Type;
154 assert(D &&
"Expected decl");
155 DeclArg.Kind = Declaration;
180 TemplateArg.Kind = Template;
182 TemplateArg.NumExpansions = 0;
197 TemplateArg.Kind = TemplateExpansion;
200 TemplateArg.NumExpansions = *NumExpansions + 1;
202 TemplateArg.NumExpansions = 0;
211 TypeOrValue.Kind = Expression;
212 TypeOrValue.V =
reinterpret_cast<uintptr_t>(E);
220 this->Args.Kind = Pack;
221 this->Args.Args = Args.data();
222 this->Args.NumArgs = Args.size();
243 bool isDependent()
const;
247 bool isInstantiationDependent()
const;
251 bool containsUnexpandedParameterPack()
const;
254 bool isPackExpansion()
const;
258 assert(
getKind() == Type &&
"Unexpected kind");
259 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
265 assert(
getKind() == Declaration &&
"Unexpected kind");
270 assert(
getKind() == Declaration &&
"Unexpected kind");
271 return QualType::getFromOpaquePtr(DeclArg.QT);
276 assert(
getKind() == NullPtr &&
"Unexpected kind");
277 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
282 assert(
getKind() == Template &&
"Unexpected kind");
283 return TemplateName::getFromVoidPointer(TemplateArg.Name);
289 assert((
getKind() == Template ||
getKind() == TemplateExpansion) &&
292 return TemplateName::getFromVoidPointer(TemplateArg.Name);
302 assert(
getKind() == Integral &&
"Unexpected kind");
304 using namespace llvm;
309 unsigned NumWords = APInt::getNumWords(
Integer.BitWidth);
310 return APSInt(APInt(
Integer.BitWidth, makeArrayRef(
Integer.pVal, NumWords)),
316 assert(
getKind() == Integral &&
"Unexpected kind");
317 return QualType::getFromOpaquePtr(
Integer.Type);
321 assert(
getKind() == Integral &&
"Unexpected kind");
327 QualType getNonTypeTemplateArgumentType()
const;
331 assert(
getKind() == Expression &&
"Unexpected kind");
332 return reinterpret_cast<Expr *
>(TypeOrValue.V);
349 return Args.Args + Args.NumArgs;
355 return llvm::makeArrayRef(pack_begin(), pack_end());
368 return llvm::makeArrayRef(Args.Args, Args.NumArgs);
383 void dump(raw_ostream &Out)
const;
389 void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context)
const;
399 void *QualifierLocData;
400 unsigned TemplateNameLoc;
401 unsigned EllipsisLoc;
436 Template.QualifierLocData);
440 return SourceLocation::getFromRawEncoding(Template.TemplateNameLoc);
444 return SourceLocation::getFromRawEncoding(Template.EllipsisLoc);
459 : Argument(Argument), LocInfo(Opaque) {}
462 : Argument(Argument), LocInfo(TInfo) {
467 : Argument(Argument), LocInfo(E) {
471 assert(Argument.
getKind() == TemplateArgument::NullPtr ||
472 Argument.
getKind() == TemplateArgument::Integral ||
473 Argument.
getKind() == TemplateArgument::Declaration ||
474 Argument.
getKind() == TemplateArgument::Expression);
481 : Argument(Argument),
482 LocInfo(QualifierLoc, TemplateNameLoc, EllipsisLoc) {
483 assert(Argument.
getKind() == TemplateArgument::Template ||
484 Argument.
getKind() == TemplateArgument::TemplateExpansion);
489 if (Argument.
getKind() == TemplateArgument::Template ||
490 Argument.
getKind() == TemplateArgument::TemplateExpansion)
491 return getTemplateNameLoc();
513 assert(Argument.
getKind() == TemplateArgument::Expression);
518 assert(Argument.
getKind() == TemplateArgument::Declaration);
523 assert(Argument.
getKind() == TemplateArgument::NullPtr);
528 assert(Argument.
getKind() == TemplateArgument::Integral);
533 if (Argument.
getKind() != TemplateArgument::Template &&
534 Argument.
getKind() != TemplateArgument::TemplateExpansion)
540 if (Argument.
getKind() != TemplateArgument::Template &&
541 Argument.
getKind() != TemplateArgument::TemplateExpansion)
547 if (Argument.
getKind() != TemplateArgument::TemplateExpansion)
565 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
577 unsigned size()
const {
return Arguments.size(); }
580 return Arguments.data();
596 Arguments.push_back(Loc);
606 TemplateArgumentLoc> {
628 return getTrailingObjects<TemplateArgumentLoc>();
633 return llvm::makeArrayRef(getTemplateArgs(), getNumTemplateArgs());
637 return getTemplateArgs()[I];
673 bool &InstantiationDependent,
674 bool &ContainsUnexpandedParameterPack);
685 TemplateSpecializationType::end()
const {
686 return getArgs() + getNumArgs();
690 DependentTemplateSpecializationType::end()
const {
691 return getArgs() + getNumArgs();
695 TemplateSpecializationType::getArg(
unsigned Idx)
const {
696 assert(Idx < getNumArgs() &&
"Template argument out of range");
697 return getArgs()[Idx];
701 DependentTemplateSpecializationType::getArg(
unsigned Idx)
const {
702 assert(Idx < getNumArgs() &&
"Template argument out of range");
703 return getArgs()[Idx];
708 #endif // LLVM_CLANG_AST_TEMPLATEBASE_H
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
TemplateArgument(ArrayRef< TemplateArgument > Args)
Construct a template argument that is a template argument pack.
A (possibly-)qualified type.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
NestedNameSpecifierLoc getTemplateQualifierLoc() const
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
C Language Family Type Representation.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
TemplateArgumentLoc & operator[](unsigned I)
The base class of the type hierarchy.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
A container of type source information.
void setRAngleLoc(SourceLocation Loc)
Information about one declarator, including the parsed type information and the identifier.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Describes how types, statements, expressions, and declarations should be printed. ...
static StringRef bytes(const std::vector< T, Allocator > &v)
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
QualType getIntegralType() const
Retrieve the type of the integral value.
unsigned getNumTemplateArgs() const
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.
static TemplateArgument getEmptyPack()
Expr * getAsExpr() const
Retrieve the template argument as an expression.
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)
TypeSourceInfo * getTypeSourceInfo() const
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
SourceLocation getLocation() const
QualType getParamTypeForDecl() const
A convenient class for passing around template argument information.
const TemplateArgumentLoc & operator[](unsigned I) const
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation getLAngleLoc() const
const TemplateArgumentLoc * getArgumentArray() const
SourceLocation getTemplateEllipsisLoc() const
static raw_ostream & operator<<(raw_ostream &os, BindingKey K)
void * getAsOpaquePtr() const
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation getTemplateEllipsisLoc() const
A little helper class used to produce diagnostics.
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Expr * getSourceDeclExpression() const
TemplateArgument(TemplateName Name, Optional< unsigned > NumExpansions)
Construct a template argument that is a template pack expansion.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
ArgKind
The kind of template argument we're storing.
TypeSourceInfo * Declarator
Represents a C++ template name within the type system.
TemplateArgumentLocInfo(TypeSourceInfo *TInfo)
TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
TypeSourceInfo * getAsTypeSourceInfo() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Encodes a location in the source.
void setIntegralType(QualType T)
TemplateArgumentLocInfo(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
unsigned pack_size() const
The number of template arguments in the given template argument pack.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
void setLAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Represents a template argument.
Optional< types::ID > Type
Dataflow Directional Tag Classes.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
The template argument is a pack expansion of a template name that was provided for a template templat...
Expr * getSourceExpression() const
TemplateArgumentLocInfo(Expr *E)
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Expr * getSourceNullPtrExpression() const
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
bool isNull() const
Determine whether this template argument has no value.
SourceLocation getRAngleLoc() const
Location wrapper for a TemplateArgument.
The template argument is a type.
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
Expr * getSourceIntegralExpression() const
ArgKind getKind() const
Return the kind of stored template argument.
Defines the clang::SourceLocation class and associated facilities.
The template argument is a template name that was provided for a template template parameter...
TemplateArgumentLocInfo getLocInfo() const
constexpr TemplateArgumentLoc()
Location information for a TemplateArgument.
TemplateArgument(QualType T, bool isNullPtr=false)
Construct a template type argument.
SourceLocation getLAngleLoc() const
static Decl::Kind getKind(const Decl *D)
QualType getAsType() const
Retrieve the type for a type template argument.
TemplateArgument(ValueDecl *D, QualType QT)
Construct a template argument that refers to a declaration, which is either an external declaration o...
SourceLocation getTemplateNameLoc() const
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.
constexpr TemplateArgumentLocInfo()
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
SourceLocation getRAngleLoc() const
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
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.
SourceLocation getBegin() const
TemplateArgumentLoc(const TemplateArgument &Argument, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc=SourceLocation())
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
const TemplateArgumentLoc & operator[](unsigned I) const