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);
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();
103 llvm_unreachable(
"Should not have a NULL template argument");
117 return DC->isDependentContext();
138 llvm_unreachable(
"Invalid TemplateArgument Kind!");
144 llvm_unreachable(
"Should not have a NULL template argument");
157 return DC->isDependentContext();
172 if (
P.isInstantiationDependent())
177 llvm_unreachable(
"Invalid TemplateArgument Kind!");
194 return isa<PackExpansionType>(
getAsType());
197 return isa<PackExpansionExpr>(
getAsExpr());
200 llvm_unreachable(
"Invalid TemplateArgument Kind!");
229 if (
P.containsUnexpandedParameterPack())
269 = dyn_cast_or_null<TemplateTemplateParmDecl>(
272 ID.AddInteger(TTP->getDepth());
273 ID.AddInteger(TTP->getPosition());
274 ID.AddBoolean(TTP->isParameterPack());
276 ID.AddBoolean(
false);
293 ID.AddInteger(
Args.NumArgs);
294 for (
unsigned I = 0;
I !=
Args.NumArgs; ++
I)
295 Args.Args[
I].Profile(ID, Context);
319 if (
Args.NumArgs != Other.
Args.NumArgs)
return false;
320 for (
unsigned I = 0,
E =
Args.NumArgs;
I !=
E; ++
I)
321 if (!
Args.Args[
I].structurallyEquals(Other.
Args.Args[
I]))
326 llvm_unreachable(
"Invalid TemplateArgument Kind!");
337 return cast<PackExpansionExpr>(
getAsExpr())->getPattern();
351 llvm_unreachable(
"Invalid TemplateArgument Kind!");
355 raw_ostream &Out)
const {
375 Out <<
"(anonymous)";
399 getAsExpr()->printPretty(Out,
nullptr, Policy);
411 P.print(Policy, Out);
439 return TSI->getTypeLoc().getSourceRange();
463 llvm_unreachable(
"Invalid TemplateArgument Kind!");
472 return DB <<
"(null template argument)";
481 return DB <<
"nullptr";
497 llvm::raw_svector_ostream OS(Str);
499 LangOpts.CPlusPlus =
true;
501 Arg.
getAsExpr()->printPretty(OS,
nullptr, Policy);
502 return DB << OS.str();
508 llvm::raw_svector_ostream OS(Str);
510 LangOpts.CPlusPlus =
true;
512 Arg.
print(Policy, OS);
513 return DB << OS.str();
517 llvm_unreachable(
"Invalid TemplateArgument Kind!");
524 void *Mem = C.
Allocate(size, llvm::alignOf<ASTTemplateArgumentListInfo>());
528 ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
539 void ASTTemplateKWAndArgsInfo::initializeFrom(
542 this->TemplateKWLoc = TemplateKWLoc;
545 NumTemplateArgs = Info.
size();
547 for (
unsigned i = 0; i != NumTemplateArgs; ++i)
551 void ASTTemplateKWAndArgsInfo::initializeFrom(
SourceLocation TemplateKWLoc) {
552 assert(TemplateKWLoc.
isValid());
555 this->TemplateKWLoc = TemplateKWLoc;
559 void ASTTemplateKWAndArgsInfo::initializeFrom(
562 bool &InstantiationDependent,
bool &ContainsUnexpandedParameterPack) {
563 this->TemplateKWLoc = TemplateKWLoc;
566 NumTemplateArgs = Info.
size();
568 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
569 Dependent = Dependent || Info[i].getArgument().isDependent();
570 InstantiationDependent = InstantiationDependent ||
571 Info[i].getArgument().isInstantiationDependent();
572 ContainsUnexpandedParameterPack =
573 ContainsUnexpandedParameterPack ||
574 Info[i].getArgument().containsUnexpandedParameterPack();
584 for (
unsigned I = 0;
I != NumTemplateArgs; ++
I)
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.
A (possibly-)qualified type.
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.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
EnumConstantDecl - 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...
TemplateArgument()
Construct an empty, invalid template argument.
Defines the C++ template declaration subclasses.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
The base class of the type hierarchy.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
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.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
void * getAsOpaquePtr() const
void setRAngleLoc(SourceLocation Loc)
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>".
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 ...
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
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.
A convenient class for passing around template argument information.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
SourceLocation getRAngleLoc() const
SourceLocation getTemplateNameLoc() const
detail::InMemoryDirectory::const_iterator I
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 template argument is a null pointer or null pointer to member that was provided for a non-type te...
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
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
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
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Expr * getSourceIntegralExpression() const
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
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
printQualifiedName - Returns human-readable qualified name for declaration, like A::B::i, for i being member of namespace A::B.
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.
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isDependent() const
Determines whether this is a dependent template name.
The template argument is a pack expansion of a template name that was provided for a template templat...
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 ('<').
detail::InMemoryDirectory::const_iterator E
Defines the Diagnostic-related interfaces.
Location wrapper for a TemplateArgument.
const T * getAs() const
Member-template getAs<specific type>'.
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.
The template argument is actually a parameter pack.
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)
The template argument is a template name that was provided for a template template parameter...
void * Allocate(size_t Size, unsigned Align=8) const
Location information for a TemplateArgument.
void Profile(llvm::FoldingSetNodeID &ID) const
bool MSVCFormatting
Use whitespace and punctuation like MSVC does.
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.