30#include "llvm/ADT/APSInt.h"
31#include "llvm/ADT/FoldingSet.h"
32#include "llvm/ADT/StringExtras.h"
33#include "llvm/Support/Compiler.h"
34#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
59 if (
const auto *ED =
T->getAsEnumDecl()) {
65 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
66 ECD->printQualifiedName(Out, Policy);
76 if (
T->isBooleanType()) {
78 Out << (Val.getBoolValue() ?
"true" :
"false");
81 }
else if (
T->isCharType()) {
83 if (
T->isSpecificBuiltinType(BuiltinType::SChar))
84 Out <<
"(signed char)";
85 else if (
T->isSpecificBuiltinType(BuiltinType::UChar))
86 Out <<
"(unsigned char)";
92 if (
T->isWideCharType())
94 else if (
T->isChar8Type())
96 else if (
T->isChar16Type())
98 else if (
T->isChar32Type())
103 }
else if (IncludeType) {
105 switch (BT->getKind()) {
106 case BuiltinType::ULongLong:
109 case BuiltinType::LongLong:
112 case BuiltinType::ULong:
115 case BuiltinType::Long:
118 case BuiltinType::UInt:
121 case BuiltinType::Int:
125 Out <<
"(" <<
T->getCanonicalTypeInternal().getAsString(Policy) <<
")"
130 Out <<
"(" <<
T->getCanonicalTypeInternal().getAsString(Policy) <<
")"
138 while (
const auto *
arrayType =
type->getAsArrayTypeUnsafe()) {
160void TemplateArgument::initFromType(
QualType T,
bool IsNullPtr,
169 assert(D &&
"Expected decl");
171 DeclArg.IsDefaulted = IsDefaulted;
176void TemplateArgument::initFromIntegral(
const ASTContext &Ctx,
177 const llvm::APSInt &
Value,
180 Integer.IsDefaulted = IsDefaulted;
185 unsigned NumWords =
Value.getNumWords();
187 void *Mem = Ctx.
Allocate(NumWords *
sizeof(uint64_t));
188 std::memcpy(Mem,
Value.getRawData(), NumWords *
sizeof(uint64_t));
198 const APValue &
V,
bool IsDefaulted) {
200 Value.IsDefaulted = IsDefaulted;
209 initFromIntegral(Ctx,
Value,
Type, IsDefaulted);
215 if (
V.isMemberPointer() &&
V.getMemberPointerPath().empty())
216 return V.getMemberPointerDecl();
220 if (
V.isStruct() ||
V.isUnion()) {
223 if (
T->isDependentType() ||
T->isInstantiationDependentType())
230 if (
V.isLValue() &&
V.hasLValuePath() &&
V.getLValuePath().empty() &&
231 !
V.isLValueOnePastTheEnd())
232 return V.getLValueBase().dyn_cast<
const ValueDecl *>();
239 const APValue &V,
bool IsDefaulted) {
240 if (
Type->isIntegralOrEnumerationType() && V.isInt())
241 initFromIntegral(Ctx, V.getInt(),
Type, IsDefaulted);
242 else if ((V.isLValue() && V.isNullPointer()) ||
243 (V.isMemberPointer() && !V.getMemberPointerDecl()))
244 initFromType(
Type,
true, IsDefaulted);
247 initFromDeclaration(
const_cast<ValueDecl *
>(VD),
Type, IsDefaulted);
249 initFromStructural(Ctx,
Type, V, IsDefaulted);
262 auto Deps = TemplateArgumentDependence::None;
265 llvm_unreachable(
"Should not have a NULL template argument");
270 Deps |= TemplateArgumentDependence::Dependent;
277 return TemplateArgumentDependence::Dependent |
278 TemplateArgumentDependence::Instantiation;
281 auto *DC = dyn_cast<DeclContext>(
getAsDecl());
284 if (DC->isDependentContext())
285 Deps = TemplateArgumentDependence::Dependent |
286 TemplateArgumentDependence::Instantiation;
293 return TemplateArgumentDependence::None;
298 Deps |= TemplateArgumentDependence::Dependent |
299 TemplateArgumentDependence::Instantiation;
304 Deps |= P.getDependence();
307 llvm_unreachable(
"unhandled ArgKind");
311 return getDependence() & TemplateArgumentDependence::Dependent;
315 return getDependence() & TemplateArgumentDependence::Instantiation;
339 llvm_unreachable(
"Invalid TemplateArgument Kind!");
346 if (isa_and_nonnull<ConceptDecl>(
getAsTemplate().getAsTemplateDecl()))
348 if (
auto *TTP = llvm::dyn_cast_or_null<TemplateTemplateParmDecl>(
355 return getDependence() & TemplateArgumentDependence::UnexpandedPack;
388 llvm_unreachable(
"Invalid TemplateArgument Kind!");
412 ID.AddInteger(
TemplateArg.NumExpansions.toInternalRepresentation());
431 ID.AddBoolean(IsCanonical);
440 ID.AddInteger(
Args.NumArgs);
441 for (
unsigned I = 0; I !=
Args.NumArgs; ++I)
442 Args.Args[I].Profile(ID, Context);
473 Other.getStructuralValueType().getCanonicalType())
476 llvm::FoldingSetNodeID A, B;
478 Other.getAsStructuralValue().Profile(B);
483 if (
Args.NumArgs !=
Other.Args.NumArgs)
return false;
484 for (
unsigned I = 0, E =
Args.NumArgs; I != E; ++I)
485 if (!
Args.Args[I].structurallyEquals(
Other.Args.Args[I]))
490 llvm_unreachable(
"Invalid TemplateArgument Kind!");
517 llvm_unreachable(
"Invalid TemplateArgument Kind!");
521 bool IncludeType)
const {
538 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(VD)) {
539 TPO->getType().getUnqualifiedType().print(Out, Policy);
540 TPO->printAsInit(Out, Policy);
589 P.print(Policy, Out, IncludeType);
606 : Argument(Argument),
607 LocInfo(Ctx, TemplateKWLoc, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
611 Argument.getAsTemplateOrTemplatePattern().getQualifier());
619 Argument.getAsTemplateOrTemplatePattern().getQualifier(),
620 LocInfo.getTemplate()->QualifierLocData);
624 switch (Argument.getKind()) {
636 return TSI->getTypeLoc().getSourceRange();
663 llvm_unreachable(
"Invalid TemplateArgument Kind!");
672 return DB <<
"(null template argument)";
681 return DB <<
"nullptr";
689 llvm::raw_svector_ostream OS(Str);
691 LangOpts.CPlusPlus =
true;
695 return DB << OS.str();
711 llvm::raw_svector_ostream OS(Str);
713 LangOpts.CPlusPlus =
true;
715 Arg.
print(Policy, OS,
true);
716 return DB << OS.str();
720 llvm_unreachable(
"Invalid TemplateArgument Kind!");
733 Template->TemplateKwLoc = TemplateKWLoc;
735 Template->TemplateNameLoc = TemplateNameLoc;
736 Template->EllipsisLoc = EllipsisLoc;
743 std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.
size());
744 void *Mem =
C.Allocate(size,
alignof(ASTTemplateArgumentListInfo));
745 return new (Mem) ASTTemplateArgumentListInfo(List);
750 const ASTTemplateArgumentListInfo *List) {
755 void *Mem =
C.Allocate(size,
alignof(ASTTemplateArgumentListInfo));
756 return new (Mem) ASTTemplateArgumentListInfo(List);
759ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
770ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
810 Deps |= Info[i].getArgument().getDependence();
Defines the clang::ASTContext interface.
Defines the Diagnostic-related interfaces.
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static bool isRecordType(QualType T)
Defines the clang::SourceLocation class and associated facilities.
static const ValueDecl * getAsSimpleValueDeclRef(const ASTContext &Ctx, QualType T, const APValue &V)
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, const PrintingPolicy &Policy, bool IncludeType)
Print a template integral argument value.
static unsigned getArrayDepth(QualType type)
static const T & DiagTemplateArg(const T &DB, const TemplateArgument &Arg)
static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType)
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TemplateParamObjectDecl * getTemplateParamObjectDecl(QualType T, const APValue &V) const
Return the template parameter object of the given type with the given value.
void * Allocate(size_t Size, unsigned Align=8) const
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
This class is used for builtin types like 'int'.
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
DeclContext * getDeclContext()
An instance of this object exists for each enum constant that is defined.
This represents one expression.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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...
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
A (possibly-)qualified type.
void Profile(llvm::FoldingSetNodeID &ID) const
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
void * getAsOpaquePtr() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
A convenient class for passing around template argument information.
SourceLocation getRAngleLoc() const
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
SourceLocation getLAngleLoc() const
Location wrapper for a TemplateArgument.
SourceLocation getTemplateEllipsisLoc() const
Expr * getSourceStructuralValueExpression() const
Expr * getSourceIntegralExpression() const
SourceLocation getTemplateNameLoc() const
TypeSourceInfo * getTypeSourceInfo() const
Expr * getSourceNullPtrExpression() const
SourceRange getSourceRange() const LLVM_READONLY
Expr * getSourceDeclExpression() const
Expr * getSourceExpression() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
bool isConceptOrConceptTemplateParameter() const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
static TemplateArgument getEmptyPack()
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
TemplateArgumentDependence getDependence() const
bool isCanonicalExpr() const
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
A container of type source information.
The base class of the type hierarchy.
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isMemberPointerType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ TNK_Concept_template
The name refers to a concept.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
TemplateArgumentDependence toTemplateArgumentDependence(TypeDependence D)
U cast(CodeGen::Address addr)
@ Other
Other implicit parameter.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
SourceLocation getLAngleLoc() const
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
unsigned getNumTemplateArgs() const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
SourceLocation getRAngleLoc() const
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Describes how types, statements, expressions, and declarations should be printed.
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
unsigned UseEnumerators
Whether to print enumerator non-type template parameters with a matching enumerator name or via cast ...
unsigned PrintAsCanonical
Whether to print entities as written or canonically.
TemplateArgumentLocInfo()