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/StringRef.h" 35 #include "llvm/Support/Casting.h" 36 #include "llvm/Support/Compiler.h" 37 #include "llvm/Support/ErrorHandling.h" 38 #include "llvm/Support/raw_ostream.h" 44 using namespace clang;
64 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
65 ECD->printQualifiedName(Out, Policy);
72 Out << (Val.getBoolValue() ?
"true" :
"false");
74 const char Ch = Val.getZExtValue();
75 Out << ((Ch ==
'\'') ?
"'\\" :
"'");
76 Out.write_escaped(StringRef(&Ch, 1),
true);
91 Integer.BitWidth = Value.getBitWidth();
92 Integer.IsUnsigned = Value.isUnsigned();
94 unsigned NumWords = Value.getNumWords();
96 void *Mem = Ctx.
Allocate(NumWords *
sizeof(uint64_t));
97 std::memcpy(Mem, Value.getRawData(), NumWords *
sizeof(uint64_t));
98 Integer.pVal =
static_cast<uint64_t *
>(Mem);
100 Integer.VAL = Value.getZExtValue();
118 llvm_unreachable(
"Should not have a NULL template argument");
132 return DC->isDependentContext();
153 llvm_unreachable(
"Invalid TemplateArgument Kind!");
159 llvm_unreachable(
"Should not have a NULL template argument");
172 return DC->isDependentContext();
187 if (
P.isInstantiationDependent())
192 llvm_unreachable(
"Invalid TemplateArgument Kind!");
209 return isa<PackExpansionType>(
getAsType());
212 return isa<PackExpansionExpr>(
getAsExpr());
215 llvm_unreachable(
"Invalid TemplateArgument Kind!");
244 if (
P.containsUnexpandedParameterPack())
283 llvm_unreachable(
"Invalid TemplateArgument Kind!");
309 = dyn_cast_or_null<TemplateTemplateParmDecl>(
312 ID.AddInteger(TTP->getDepth());
313 ID.AddInteger(TTP->getPosition());
314 ID.AddBoolean(TTP->isParameterPack());
316 ID.AddBoolean(
false);
333 ID.AddInteger(
Args.NumArgs);
334 for (
unsigned I = 0; I !=
Args.NumArgs; ++I)
335 Args.Args[I].Profile(ID, Context);
359 if (
Args.NumArgs != Other.
Args.NumArgs)
return false;
360 for (
unsigned I = 0, E =
Args.NumArgs; I != E; ++I)
361 if (!
Args.Args[I].structurallyEquals(Other.
Args.Args[I]))
366 llvm_unreachable(
"Invalid TemplateArgument Kind!");
377 return cast<PackExpansionExpr>(
getAsExpr())->getPattern();
391 llvm_unreachable(
"Invalid TemplateArgument Kind!");
395 raw_ostream &Out)
const {
415 Out <<
"(anonymous)";
450 P.print(Policy, Out);
471 switch (Argument.getKind()) {
473 return getSourceExpression()->getSourceRange();
476 return getSourceDeclExpression()->getSourceRange();
479 return getSourceNullPtrExpression()->getSourceRange();
483 return TSI->getTypeLoc().getSourceRange();
488 if (getTemplateQualifierLoc())
489 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
490 getTemplateNameLoc());
494 if (getTemplateQualifierLoc())
495 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
496 getTemplateEllipsisLoc());
497 return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc());
500 return getSourceIntegralExpression()->getSourceRange();
507 llvm_unreachable(
"Invalid TemplateArgument Kind!");
516 return DB <<
"(null template argument)";
525 return DB <<
"nullptr";
541 llvm::raw_svector_ostream OS(Str);
543 LangOpts.CPlusPlus =
true;
546 return DB << OS.str();
552 llvm::raw_svector_ostream OS(Str);
554 LangOpts.CPlusPlus =
true;
556 Arg.
print(Policy, OS);
557 return DB << OS.str();
561 llvm_unreachable(
"Invalid TemplateArgument Kind!");
572 ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
576 NumTemplateArgs = Info.
size();
579 for (
unsigned i = 0; i != NumTemplateArgs; ++i)
586 this->TemplateKWLoc = TemplateKWLoc;
589 NumTemplateArgs = Info.
size();
591 for (
unsigned i = 0; i != NumTemplateArgs; ++i)
596 assert(TemplateKWLoc.
isValid());
599 this->TemplateKWLoc = TemplateKWLoc;
606 bool &InstantiationDependent,
bool &ContainsUnexpandedParameterPack) {
607 this->TemplateKWLoc = TemplateKWLoc;
610 NumTemplateArgs = Info.
size();
612 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
613 Dependent = Dependent || Info[i].getArgument().isDependent();
614 InstantiationDependent = InstantiationDependent ||
615 Info[i].getArgument().isInstantiationDependent();
616 ContainsUnexpandedParameterPack =
617 ContainsUnexpandedParameterPack ||
618 Info[i].getArgument().containsUnexpandedParameterPack();
628 for (
unsigned I = 0; I != NumTemplateArgs; ++I)
Defines the clang::ASTContext interface.
static const Decl * getCanonicalDecl(const Decl *D)
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
A (possibly-)qualified type.
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, const PrintingPolicy &Policy)
Print a template integral argument value.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
An instance of this object exists for each enum constant that is defined.
C Language Family Type Representation.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Defines the C++ template declaration subclasses.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
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)
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
const T * getAs() const
Member-template getAs<specific type>'.
Represents an empty template argument, e.g., one that has not been deduced.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
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. ...
Defines the clang::Expr interface and subclasses for C++ expressions.
QualType getIntegralType() const
Retrieve the type of the integral value.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
static TemplateArgument getEmptyPack()
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS=false) const
Print the template name.
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 ...
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
SourceRange getSourceRange() const LLVM_READONLY
QualType getParamTypeForDecl() const
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
A convenient class for passing around template argument information.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Defines the Diagnostic-related interfaces.
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
void * getAsOpaquePtr() const
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
A little helper class used to produce diagnostics.
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Defines the clang::LangOptions interface.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
void Profile(llvm::FoldingSetNodeID &ID) const
DeclContext * getDeclContext()
Represents a C++ template name within the type system.
Defines the clang::TypeLoc interface and its subclasses.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
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...
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
void setLAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Represents a pack expansion of types.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
void * Allocate(size_t Size, unsigned Align=8) const
Represents a template argument.
Dataflow Directional Tag Classes.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
bool isValid() const
Return true if this is a valid SourceLocation object.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The template argument is a pack expansion of a template name that was provided for a template templat...
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
bool isBooleanType() const
Location wrapper for a TemplateArgument.
The template argument is a type.
The template argument is actually a parameter pack.
ArgKind getKind() const
Return the kind of stored template argument.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
Defines the clang::SourceLocation class and associated facilities.
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
The template argument is a template name that was provided for a template template parameter...
TemplateName getCanonicalTemplateName(TemplateName Name) const
Retrieves the "canonical" template name that refers to a given template.
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation getLAngleLoc() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
QualType getAsType() const
Retrieve the type for a type template argument.
void dump() const
Debugging aid that dumps the template argument to standard error.
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
SourceLocation getRAngleLoc() 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.
bool isDependent() const
Determines whether this is a dependent template name.
bool isInstantiationDependent() const
Determines whether this is a template name that somehow depends on a template parameter.