Go to the documentation of this file.
30 #include "llvm/ADT/APSInt.h"
31 #include "llvm/ADT/FoldingSet.h"
32 #include "llvm/ADT/None.h"
33 #include "llvm/ADT/SmallString.h"
34 #include "llvm/ADT/StringExtras.h"
35 #include "llvm/ADT/StringRef.h"
36 #include "llvm/Support/Casting.h"
37 #include "llvm/Support/Compiler.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include "llvm/Support/raw_ostream.h"
45 using namespace clang;
69 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
70 ECD->printQualifiedName(Out, Policy);
82 Out << (Val.getBoolValue() ?
"true" :
"false");
88 Out <<
"(signed char)";
90 Out <<
"(unsigned char)";
106 }
else if (IncludeType) {
108 switch (BT->getKind()) {
109 case BuiltinType::ULongLong:
112 case BuiltinType::LongLong:
115 case BuiltinType::ULong:
118 case BuiltinType::Long:
121 case BuiltinType::UInt:
124 case BuiltinType::Int:
141 while (
const auto *
arrayType =
type->getAsArrayTypeUnsafe()) {
170 unsigned NumWords =
Value.getNumWords();
172 void *Mem = Ctx.
Allocate(NumWords *
sizeof(uint64_t));
174 Integer.pVal =
static_cast<uint64_t *
>(Mem);
195 llvm_unreachable(
"Should not have a NULL template argument");
200 Deps |= TemplateArgumentDependence::Dependent;
207 return TemplateArgumentDependence::Dependent |
208 TemplateArgumentDependence::Instantiation;
211 auto *DC = dyn_cast<DeclContext>(
getAsDecl());
214 if (DC->isDependentContext())
215 Deps = TemplateArgumentDependence::Dependent |
216 TemplateArgumentDependence::Instantiation;
227 Deps |= TemplateArgumentDependence::Dependent |
228 TemplateArgumentDependence::Instantiation;
233 Deps |=
P.getDependence();
236 llvm_unreachable(
"unhandled ArgKind");
240 return getDependence() & TemplateArgumentDependence::Dependent;
244 return getDependence() & TemplateArgumentDependence::Instantiation;
261 return isa<PackExpansionType>(
getAsType());
264 return isa<PackExpansionExpr>(
getAsExpr());
267 llvm_unreachable(
"Invalid TemplateArgument Kind!");
271 return getDependence() & TemplateArgumentDependence::UnexpandedPack;
304 llvm_unreachable(
"Invalid TemplateArgument Kind!");
331 = dyn_cast_or_null<TemplateTemplateParmDecl>(
334 ID.AddInteger(TTP->getDepth());
335 ID.AddInteger(TTP->getPosition());
336 ID.AddBoolean(TTP->isParameterPack());
338 ID.AddBoolean(
false);
355 ID.AddInteger(
Args.NumArgs);
356 for (
unsigned I = 0; I !=
Args.NumArgs; ++I)
357 Args.Args[I].Profile(
ID, Context);
384 if (
Args.NumArgs != Other.
Args.NumArgs)
return false;
385 for (
unsigned I = 0, E =
Args.NumArgs; I != E; ++I)
386 if (!
Args.Args[I].structurallyEquals(Other.
Args.Args[I]))
391 llvm_unreachable(
"Invalid TemplateArgument Kind!");
402 return cast<PackExpansionExpr>(
getAsExpr())->getPattern();
416 llvm_unreachable(
"Invalid TemplateArgument Kind!");
420 bool IncludeType)
const {
438 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
439 TPO->printAsInit(Out, Policy);
443 if (
auto *VD = dyn_cast<ValueDecl>(ND)) {
482 P.print(Policy, Out, IncludeType);
515 return TSI->getTypeLoc().getSourceRange();
539 llvm_unreachable(
"Invalid TemplateArgument Kind!");
542 template <
typename T>
548 return DB <<
"(null template argument)";
557 return DB <<
"nullptr";
573 llvm::raw_svector_ostream OS(Str);
575 LangOpts.CPlusPlus =
true;
578 return DB << OS.str();
584 llvm::raw_svector_ostream OS(Str);
586 LangOpts.CPlusPlus =
true;
588 Arg.
print(Policy, OS,
true);
589 return DB << OS.str();
593 llvm_unreachable(
"Invalid TemplateArgument Kind!");
604 TemplateTemplateArgLocInfo *Template =
new (Ctx) TemplateTemplateArgLocInfo;
607 Template->TemplateNameLoc = TemplateNameLoc;
608 Template->EllipsisLoc = EllipsisLoc;
615 std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
620 ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
660 Deps |= Info[i].getArgument().getDependence();
This class is used for builtin types like 'int'.
A trivial tuple used to represent a source range.
TemplateArgumentDependence getDependence() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Expr * getSourceExpression() const
SourceLocation getTemplateEllipsisLoc() const
Encodes a location in the source.
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
This represents a decl that may have a name.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool isWideCharType() const
static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
QualType getParamTypeForDecl() const
A (possibly-)qualified type.
TemplateArgumentLocInfo()
SourceLocation getRAngleLoc() const
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Describes how types, statements, expressions, and declarations should be printed.
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Expr * getAsExpr() const
Retrieve the template argument as an expression.
TypeSourceInfo * getTypeSourceInfo() const
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
The base class of the type hierarchy.
SourceLocation getLAngleLoc() const
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
TemplateArgumentDependence toTemplateArgumentDependence(TypeDependence D)
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
void * Allocate(size_t Size, unsigned Align=8) const
Expr * getSourceDeclExpression() const
ArgKind getKind() const
Return the kind of stored template argument.
Represents a pack expansion of types.
A convenient class for passing around template argument information.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
unsigned UseEnumerators
Whether to print enumerator non-type template parameters with a matching enumerator name or via cast ...
void addArgument(const TemplateArgumentLoc &Loc)
constexpr XRayInstrMask None
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, const PrintingPolicy &Policy, bool IncludeType)
Print a template integral argument value.
static TemplateArgument getEmptyPack()
std::string toString(const til::SExpr *E)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a template argument.
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
Location wrapper for a TemplateArgument.
SourceRange getSourceRange() const LLVM_READONLY
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
void setLAngleLoc(SourceLocation Loc)
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
QualType getCanonicalTypeInternal() const
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
An instance of this object exists for each enum constant that is defined.
A C++ nested-name-specifier augmented with source location information.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
const T * castAs() const
Member-template castAs<specific type>.
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
bool isMemberPointerType() const
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
bool isPointerType() const
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Represents a C++ template name within the type system.
static const Decl * getCanonicalDecl(const Decl *D)
Expr * getSourceIntegralExpression() const
void dump() const
Debugging aid that dumps the template argument to standard error.
static unsigned getArrayDepth(QualType type)
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
TemplateName getCanonicalTemplateName(const TemplateName &Name) const
Retrieves the "canonical" template name that refers to a given template.
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
Expr * getSourceNullPtrExpression() const
static const T & DiagTemplateArg(const T &DB, const TemplateArgument &Arg)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isBooleanType() const
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
static bool isRecordType(QualType T)
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
void Profile(llvm::FoldingSetNodeID &ID) const
@ Type
The template argument is a type.
void setRAngleLoc(SourceLocation Loc)
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
@ Template
The template argument is a template name that was provided for a template template parameter.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
bool isValid() const
Return true if this is a valid SourceLocation object.
A container of type source information.
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
NestedNameSpecifierLoc getTemplateQualifierLoc() const
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
SourceLocation getTemplateNameLoc() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
bool isChar16Type() const
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
bool isChar32Type() const
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
QualType getAsType() const
Retrieve the type for a type template argument.
static void print(unsigned val, CharacterKind Kind, raw_ostream &OS)
@ Pack
The template argument is actually a parameter pack.
DeclContext * getDeclContext()