29 #include "llvm/ADT/APSInt.h" 30 #include "llvm/ADT/FoldingSet.h" 31 #include "llvm/ADT/None.h" 32 #include "llvm/ADT/SmallString.h" 33 #include "llvm/ADT/StringRef.h" 34 #include "llvm/Support/Casting.h" 35 #include "llvm/Support/Compiler.h" 36 #include "llvm/Support/ErrorHandling.h" 37 #include "llvm/Support/raw_ostream.h" 43 using namespace clang;
63 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
64 ECD->printQualifiedName(Out, Policy);
71 Out << (Val.getBoolValue() ?
"true" :
"false");
73 const char Ch = Val.getZExtValue();
74 Out << ((Ch ==
'\'') ?
"'\\" :
"'");
75 Out.write_escaped(StringRef(&Ch, 1),
true);
90 Integer.BitWidth = Value.getBitWidth();
91 Integer.IsUnsigned = Value.isUnsigned();
93 unsigned NumWords = Value.getNumWords();
95 void *Mem = Ctx.
Allocate(NumWords *
sizeof(uint64_t));
96 std::memcpy(Mem, Value.getRawData(), NumWords *
sizeof(uint64_t));
97 Integer.pVal =
static_cast<uint64_t *
>(Mem);
99 Integer.VAL = Value.getZExtValue();
117 llvm_unreachable(
"Should not have a NULL template argument");
131 return DC->isDependentContext();
152 llvm_unreachable(
"Invalid TemplateArgument Kind!");
158 llvm_unreachable(
"Should not have a NULL template argument");
171 return DC->isDependentContext();
186 if (
P.isInstantiationDependent())
191 llvm_unreachable(
"Invalid TemplateArgument Kind!");
208 return isa<PackExpansionType>(
getAsType());
211 return isa<PackExpansionExpr>(
getAsExpr());
214 llvm_unreachable(
"Invalid TemplateArgument Kind!");
243 if (
P.containsUnexpandedParameterPack())
282 llvm_unreachable(
"Invalid TemplateArgument Kind!");
308 = dyn_cast_or_null<TemplateTemplateParmDecl>(
311 ID.AddInteger(TTP->getDepth());
312 ID.AddInteger(TTP->getPosition());
313 ID.AddBoolean(TTP->isParameterPack());
315 ID.AddBoolean(
false);
332 ID.AddInteger(
Args.NumArgs);
333 for (
unsigned I = 0; I !=
Args.NumArgs; ++I)
334 Args.Args[I].Profile(ID, Context);
358 if (
Args.NumArgs != Other.
Args.NumArgs)
return false;
359 for (
unsigned I = 0, E =
Args.NumArgs; I != E; ++I)
360 if (!
Args.Args[I].structurallyEquals(Other.
Args.Args[I]))
365 llvm_unreachable(
"Invalid TemplateArgument Kind!");
376 return cast<PackExpansionExpr>(
getAsExpr())->getPattern();
390 llvm_unreachable(
"Invalid TemplateArgument Kind!");
394 raw_ostream &Out)
const {
414 Out <<
"(anonymous)";
449 P.print(Policy, Out);
470 switch (Argument.getKind()) {
472 return getSourceExpression()->getSourceRange();
475 return getSourceDeclExpression()->getSourceRange();
478 return getSourceNullPtrExpression()->getSourceRange();
482 return TSI->getTypeLoc().getSourceRange();
487 if (getTemplateQualifierLoc())
488 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
489 getTemplateNameLoc());
493 if (getTemplateQualifierLoc())
494 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
495 getTemplateEllipsisLoc());
496 return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc());
499 return getSourceIntegralExpression()->getSourceRange();
506 llvm_unreachable(
"Invalid TemplateArgument Kind!");
515 return DB <<
"(null template argument)";
524 return DB <<
"nullptr";
540 llvm::raw_svector_ostream OS(Str);
542 LangOpts.CPlusPlus =
true;
545 return DB << OS.str();
551 llvm::raw_svector_ostream OS(Str);
553 LangOpts.CPlusPlus =
true;
555 Arg.
print(Policy, OS);
556 return DB << OS.str();
560 llvm_unreachable(
"Invalid TemplateArgument Kind!");
571 ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
575 NumTemplateArgs = Info.
size();
578 for (
unsigned i = 0; i != NumTemplateArgs; ++i)
585 this->TemplateKWLoc = TemplateKWLoc;
588 NumTemplateArgs = Info.
size();
590 for (
unsigned i = 0; i != NumTemplateArgs; ++i)
595 assert(TemplateKWLoc.
isValid());
598 this->TemplateKWLoc = TemplateKWLoc;
605 bool &InstantiationDependent,
bool &ContainsUnexpandedParameterPack) {
606 this->TemplateKWLoc = TemplateKWLoc;
609 NumTemplateArgs = Info.
size();
611 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
612 Dependent = Dependent || Info[i].getArgument().isDependent();
613 InstantiationDependent = InstantiationDependent ||
614 Info[i].getArgument().isInstantiationDependent();
615 ContainsUnexpandedParameterPack =
616 ContainsUnexpandedParameterPack ||
617 Info[i].getArgument().containsUnexpandedParameterPack();
627 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.
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...
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
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...
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
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.
const T * castAs() const
Member-template castAs<specific type>.
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.
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.