24 #include "llvm/ADT/FoldingSet.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/Support/raw_ostream.h"
29 using namespace clang;
49 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
50 ECD->printQualifiedName(Out, Policy);
56 if (T->isBooleanType()) {
57 Out << (Val.getBoolValue() ?
"true" :
"false");
58 }
else if (T->isCharType()) {
59 const char Ch = Val.getZExtValue();
60 Out << ((Ch ==
'\'') ?
"'\\" :
"'");
61 Out.write_escaped(StringRef(&Ch, 1),
true);
76 Integer.BitWidth = Value.getBitWidth();
77 Integer.IsUnsigned = Value.isUnsigned();
79 unsigned NumWords = Value.getNumWords();
81 void *Mem = Ctx.
Allocate(NumWords *
sizeof(uint64_t));
82 std::memcpy(Mem, Value.getRawData(), NumWords *
sizeof(uint64_t));
83 Integer.pVal =
static_cast<uint64_t *
>(Mem);
85 Integer.VAL = Value.getZExtValue();
98 std::copy(Args, Args + NumArgs, Storage);
105 llvm_unreachable(
"Should not have a NULL template argument");
119 return DC->isDependentContext();
140 llvm_unreachable(
"Invalid TemplateArgument Kind!");
146 llvm_unreachable(
"Should not have a NULL template argument");
159 return DC->isDependentContext();
174 if (
P.isInstantiationDependent())
179 llvm_unreachable(
"Invalid TemplateArgument Kind!");
196 return isa<PackExpansionType>(
getAsType());
199 return isa<PackExpansionExpr>(
getAsExpr());
202 llvm_unreachable(
"Invalid TemplateArgument Kind!");
231 if (
P.containsUnexpandedParameterPack())
271 = dyn_cast_or_null<TemplateTemplateParmDecl>(
274 ID.AddInteger(TTP->getDepth());
275 ID.AddInteger(TTP->getPosition());
276 ID.AddBoolean(TTP->isParameterPack());
278 ID.AddBoolean(
false);
295 ID.AddInteger(
Args.NumArgs);
296 for (
unsigned I = 0; I !=
Args.NumArgs; ++I)
297 Args.Args[I].Profile(ID, Context);
321 if (
Args.NumArgs != Other.
Args.NumArgs)
return false;
322 for (
unsigned I = 0, E =
Args.NumArgs; I != E; ++I)
323 if (!
Args.Args[I].structurallyEquals(Other.
Args.Args[I]))
328 llvm_unreachable(
"Invalid TemplateArgument Kind!");
339 return cast<PackExpansionExpr>(
getAsExpr())->getPattern();
353 llvm_unreachable(
"Invalid TemplateArgument Kind!");
357 raw_ostream &Out)
const {
377 Out <<
"(anonymous)";
401 getAsExpr()->printPretty(Out,
nullptr, Policy);
413 P.print(Policy, Out);
441 return TSI->getTypeLoc().getSourceRange();
465 llvm_unreachable(
"Invalid TemplateArgument Kind!");
474 return DB <<
"(null template argument)";
483 return DB <<
"nullptr";
499 llvm::raw_svector_ostream OS(Str);
501 LangOpts.CPlusPlus =
true;
503 Arg.
getAsExpr()->printPretty(OS,
nullptr, Policy);
504 return DB << OS.str();
510 llvm::raw_svector_ostream OS(Str);
512 LangOpts.CPlusPlus =
true;
514 Arg.
print(Policy, OS);
515 return DB << OS.str();
519 llvm_unreachable(
"Invalid TemplateArgument Kind!");
525 assert(llvm::alignOf<ASTTemplateArgumentListInfo>() >=
526 llvm::alignOf<TemplateArgumentLoc>());
528 void *Mem = C.
Allocate(size, llvm::alignOf<ASTTemplateArgumentListInfo>());
548 bool &InstantiationDependent,
549 bool &ContainsUnexpandedParameterPack) {
556 Dependent = Dependent || Info[i].getArgument().isDependent();
557 InstantiationDependent = InstantiationDependent ||
558 Info[i].getArgument().isInstantiationDependent();
559 ContainsUnexpandedParameterPack
560 = ContainsUnexpandedParameterPack ||
561 Info[i].getArgument().containsUnexpandedParameterPack();
592 bool &InstantiationDependent,
593 bool &ContainsUnexpandedParameterPack) {
594 Base::initializeFrom(Info, Dependent, InstantiationDependent,
595 ContainsUnexpandedParameterPack);
596 setTemplateKeywordLoc(TemplateKWLoc);
602 assert(TemplateKWLoc.
isValid());
Defines the clang::ASTContext interface.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS=false) const
Print the template name.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
Expr * getSourceExpression() const
llvm::iterator_range< pack_iterator > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, const PrintingPolicy &Policy)
Print a template integral argument value.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
static std::size_t sizeFor(unsigned NumTemplateArgs)
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
void initializeFrom(const TemplateArgumentListInfo &List)
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
TemplateArgument()
Construct an empty, invalid template argument.
Defines the C++ template declaration subclasses.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
A container of type source information.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
void * getAsOpaquePtr() const
void setTemplateKeywordLoc(SourceLocation TemplateKWLoc)
Sets the source location of the template keyword.
void setRAngleLoc(SourceLocation Loc)
static TemplateArgument CreatePackCopy(ASTContext &Context, const TemplateArgument *Args, unsigned NumArgs)
Create a new template argument pack by copying the given set of template arguments.
Represents an empty template argument, e.g., one that has not been deduced.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>". This is safe to be used inside an AST node, in contrast with TemplateArgumentListInfo.
Describes how types, statements, expressions, and declarations should be printed. ...
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateArgumentLocInfo()
static TemplateArgument getEmptyPack()
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TypeSourceInfo * getTypeSourceInfo() const
SourceRange getSourceRange() const LLVM_READONLY
Fetches the full source range of the argument.
SourceLocation getTemplateEllipsisLoc() const
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation getRAngleLoc() const
SourceLocation getTemplateNameLoc() const
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
A little helper class used to produce diagnostics.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
ID
Defines the set of possible language-specific address spaces.
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs. The actual template arguments (if any) are stored a...
bool isInstantiationDependent() const
Determines whether this is a template name that somehow depends on a template parameter.
ArgKind getKind() const
Return the kind of stored template argument.
DeclContext * getDeclContext()
Represents a C++ template name within the type system.
Expr * getSourceNullPtrExpression() const
Defines the clang::TypeLoc interface and its subclasses.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine()) const
bool isDependentType() 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.
DeclarationName getDeclName() const
TemplateArgumentLoc * getTemplateArgs()
Retrieve the template arguments.
Expr * getSourceIntegralExpression() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const Type * getTypePtr() const
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
SourceLocation getLAngleLoc() const
void setLAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
void printQualifiedName(raw_ostream &OS) const
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Represents a pack expansion of types.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
static std::size_t sizeFor(unsigned NumTemplateArgs)
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
bool isDependent() const
Determines whether this is a dependent template name.
TemplateName getCanonicalTemplateName(TemplateName Name) const
Retrieves the "canonical" template name that refers to a given template.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Defines the Diagnostic-related interfaces.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
The template argument is a type.
Expr * getSourceDeclExpression() const
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
static const ASTTemplateArgumentListInfo * Create(ASTContext &C, const TemplateArgumentListInfo &List)
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List)
void * Allocate(size_t Size, unsigned Align=8) const
Location information for a TemplateArgument.
void copyInto(TemplateArgumentListInfo &List) const
void Profile(llvm::FoldingSetNodeID &ID) const
A trivial tuple used to represent a source range.