14 #ifndef LLVM_CLANG_AST_TEMPLATEBASE_H 15 #define LLVM_CLANG_AST_TEMPLATEBASE_H 22 #include "llvm/ADT/APInt.h" 23 #include "llvm/ADT/APSInt.h" 24 #include "llvm/ADT/ArrayRef.h" 25 #include "llvm/ADT/None.h" 26 #include "llvm/ADT/Optional.h" 27 #include "llvm/ADT/SmallVector.h" 28 #include "llvm/Support/Compiler.h" 29 #include "llvm/Support/TrailingObjects.h" 36 class FoldingSetNodeID;
43 class DiagnosticBuilder;
45 struct PrintingPolicy;
106 unsigned BitWidth : 31;
107 unsigned IsUnsigned : 1;
113 const uint64_t *pVal;
124 unsigned NumExpansions;
135 struct TA TemplateArg;
136 struct TV TypeOrValue;
145 TypeOrValue.Kind = isNullPtr ? NullPtr :
Type;
153 assert(D &&
"Expected decl");
154 DeclArg.Kind = Declaration;
179 TemplateArg.Kind = Template;
181 TemplateArg.NumExpansions = 0;
196 TemplateArg.Kind = TemplateExpansion;
199 TemplateArg.NumExpansions = *NumExpansions + 1;
201 TemplateArg.NumExpansions = 0;
210 TypeOrValue.Kind = Expression;
211 TypeOrValue.V =
reinterpret_cast<uintptr_t>(E);
219 this->Args.Kind = Pack;
220 this->Args.Args = Args.data();
221 this->Args.NumArgs = Args.size();
242 bool isDependent()
const;
246 bool isInstantiationDependent()
const;
250 bool containsUnexpandedParameterPack()
const;
253 bool isPackExpansion()
const;
257 assert(
getKind() == Type &&
"Unexpected kind");
258 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
264 assert(
getKind() == Declaration &&
"Unexpected kind");
269 assert(
getKind() == Declaration &&
"Unexpected kind");
270 return QualType::getFromOpaquePtr(DeclArg.QT);
275 assert(
getKind() == NullPtr &&
"Unexpected kind");
276 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
281 assert(
getKind() == Template &&
"Unexpected kind");
282 return TemplateName::getFromVoidPointer(TemplateArg.Name);
288 assert((
getKind() == Template ||
getKind() == TemplateExpansion) &&
291 return TemplateName::getFromVoidPointer(TemplateArg.Name);
301 assert(
getKind() == Integral &&
"Unexpected kind");
303 using namespace llvm;
308 unsigned NumWords = APInt::getNumWords(
Integer.BitWidth);
315 assert(
getKind() == Integral &&
"Unexpected kind");
316 return QualType::getFromOpaquePtr(
Integer.Type);
320 assert(
getKind() == Integral &&
"Unexpected kind");
326 QualType getNonTypeTemplateArgumentType()
const;
330 assert(
getKind() == Expression &&
"Unexpected kind");
331 return reinterpret_cast<Expr *
>(TypeOrValue.V);
348 return Args.Args + Args.NumArgs;
354 return llvm::makeArrayRef(pack_begin(), pack_end());
367 return llvm::makeArrayRef(Args.Args, Args.NumArgs);
382 void dump(raw_ostream &Out)
const;
388 void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context)
const;
398 void *QualifierLocData;
399 unsigned TemplateNameLoc;
400 unsigned EllipsisLoc;
435 Template.QualifierLocData);
439 return SourceLocation::getFromRawEncoding(Template.TemplateNameLoc);
443 return SourceLocation::getFromRawEncoding(Template.EllipsisLoc);
458 : Argument(Argument), LocInfo(Opaque) {}
461 : Argument(Argument), LocInfo(TInfo) {
466 : Argument(Argument), LocInfo(E) {
470 assert(Argument.
getKind() == TemplateArgument::NullPtr ||
471 Argument.
getKind() == TemplateArgument::Integral ||
472 Argument.
getKind() == TemplateArgument::Declaration ||
473 Argument.
getKind() == TemplateArgument::Expression);
480 : Argument(Argument),
481 LocInfo(QualifierLoc, TemplateNameLoc, EllipsisLoc) {
482 assert(Argument.
getKind() == TemplateArgument::Template ||
483 Argument.
getKind() == TemplateArgument::TemplateExpansion);
488 if (Argument.
getKind() == TemplateArgument::Template ||
489 Argument.
getKind() == TemplateArgument::TemplateExpansion)
490 return getTemplateNameLoc();
512 assert(Argument.
getKind() == TemplateArgument::Expression);
517 assert(Argument.
getKind() == TemplateArgument::Declaration);
522 assert(Argument.
getKind() == TemplateArgument::NullPtr);
527 assert(Argument.
getKind() == TemplateArgument::Integral);
532 if (Argument.
getKind() != TemplateArgument::Template &&
533 Argument.
getKind() != TemplateArgument::TemplateExpansion)
539 if (Argument.
getKind() != TemplateArgument::Template &&
540 Argument.
getKind() != TemplateArgument::TemplateExpansion)
546 if (Argument.
getKind() != TemplateArgument::TemplateExpansion)
564 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
576 unsigned size()
const {
return Arguments.size(); }
579 return Arguments.data();
595 Arguments.push_back(Loc);
605 TemplateArgumentLoc> {
627 return getTrailingObjects<TemplateArgumentLoc>();
632 return llvm::makeArrayRef(getTemplateArgs(), getNumTemplateArgs());
636 return getTemplateArgs()[I];
672 bool &InstantiationDependent,
673 bool &ContainsUnexpandedParameterPack);
684 TemplateSpecializationType::end()
const {
685 return getArgs() + getNumArgs();
689 DependentTemplateSpecializationType::end()
const {
690 return getArgs() + getNumArgs();
694 TemplateSpecializationType::getArg(
unsigned Idx)
const {
695 assert(Idx < getNumArgs() &&
"Template argument out of range");
696 return getArgs()[Idx];
700 DependentTemplateSpecializationType::getArg(
unsigned Idx)
const {
701 assert(Idx < getNumArgs() &&
"Template argument out of range");
702 return getArgs()[Idx];
707 #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
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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. ...
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
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()
SourceLocation getBegin() const
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
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...
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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)
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
static raw_ostream & operator<<(raw_ostream &Out, BindingKey K)
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.
bool Null(InterpState &S, CodePtr OpPC)
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.
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