clang 20.0.0git
TemplateBase.cpp
Go to the documentation of this file.
1//===- TemplateBase.cpp - Common template AST class implementation --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements common classes used throughout C++ template
10// representations.
11//
12//===----------------------------------------------------------------------===//
13
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclBase.h"
20#include "clang/AST/Expr.h"
21#include "clang/AST/ExprCXX.h"
24#include "clang/AST/Type.h"
25#include "clang/AST/TypeLoc.h"
27#include "clang/Basic/LLVM.h"
30#include "llvm/ADT/APSInt.h"
31#include "llvm/ADT/FoldingSet.h"
32#include "llvm/ADT/SmallString.h"
33#include "llvm/ADT/StringExtras.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"
39#include <cassert>
40#include <cstddef>
41#include <cstdint>
42#include <cstring>
43#include <optional>
44
45using namespace clang;
46
47/// Print a template integral argument value.
48///
49/// \param TemplArg the TemplateArgument instance to print.
50///
51/// \param Out the raw_ostream instance to use for printing.
52///
53/// \param Policy the printing policy for EnumConstantDecl printing.
54///
55/// \param IncludeType If set, ensure that the type of the expression printed
56/// matches the type of the template argument.
57static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
58 const PrintingPolicy &Policy, bool IncludeType) {
59 const Type *T = TemplArg.getIntegralType().getTypePtr();
60 const llvm::APSInt &Val = TemplArg.getAsIntegral();
61
62 if (Policy.UseEnumerators) {
63 if (const EnumType *ET = T->getAs<EnumType>()) {
64 for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) {
65 // In Sema::CheckTemplateArugment, enum template arguments value are
66 // extended to the size of the integer underlying the enum type. This
67 // may create a size difference between the enum value and template
68 // argument value, requiring isSameValue here instead of operator==.
69 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
70 ECD->printQualifiedName(Out, Policy);
71 return;
72 }
73 }
74 }
75 }
76
77 if (Policy.MSVCFormatting)
78 IncludeType = false;
79
80 if (T->isBooleanType()) {
81 if (!Policy.MSVCFormatting)
82 Out << (Val.getBoolValue() ? "true" : "false");
83 else
84 Out << Val;
85 } else if (T->isCharType()) {
86 if (IncludeType) {
87 if (T->isSpecificBuiltinType(BuiltinType::SChar))
88 Out << "(signed char)";
89 else if (T->isSpecificBuiltinType(BuiltinType::UChar))
90 Out << "(unsigned char)";
91 }
92 CharacterLiteral::print(Val.getZExtValue(), CharacterLiteralKind::Ascii,
93 Out);
94 } else if (T->isAnyCharacterType() && !Policy.MSVCFormatting) {
96 if (T->isWideCharType())
97 Kind = CharacterLiteralKind::Wide;
98 else if (T->isChar8Type())
99 Kind = CharacterLiteralKind::UTF8;
100 else if (T->isChar16Type())
101 Kind = CharacterLiteralKind::UTF16;
102 else if (T->isChar32Type())
103 Kind = CharacterLiteralKind::UTF32;
104 else
105 Kind = CharacterLiteralKind::Ascii;
106 CharacterLiteral::print(Val.getExtValue(), Kind, Out);
107 } else if (IncludeType) {
108 if (const auto *BT = T->getAs<BuiltinType>()) {
109 switch (BT->getKind()) {
110 case BuiltinType::ULongLong:
111 Out << Val << "ULL";
112 break;
113 case BuiltinType::LongLong:
114 Out << Val << "LL";
115 break;
116 case BuiltinType::ULong:
117 Out << Val << "UL";
118 break;
119 case BuiltinType::Long:
120 Out << Val << "L";
121 break;
122 case BuiltinType::UInt:
123 Out << Val << "U";
124 break;
125 case BuiltinType::Int:
126 Out << Val;
127 break;
128 default:
129 Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
130 << Val;
131 break;
132 }
133 } else
134 Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
135 << Val;
136 } else
137 Out << Val;
138}
139
140static unsigned getArrayDepth(QualType type) {
141 unsigned count = 0;
142 while (const auto *arrayType = type->getAsArrayTypeUnsafe()) {
143 count++;
144 type = arrayType->getElementType();
145 }
146 return count;
147}
148
149static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType) {
150 // Generally, if the parameter type is a pointer, we must be taking the
151 // address of something and need a &. However, if the argument is an array,
152 // this could be implicit via array-to-pointer decay.
153 if (!paramType->isPointerType())
154 return paramType->isMemberPointerType();
155 if (argType->isArrayType())
156 return getArrayDepth(argType) == getArrayDepth(paramType->getPointeeType());
157 return true;
158}
159
160//===----------------------------------------------------------------------===//
161// TemplateArgument Implementation
162//===----------------------------------------------------------------------===//
163
164void TemplateArgument::initFromType(QualType T, bool IsNullPtr,
165 bool IsDefaulted) {
166 TypeOrValue.Kind = IsNullPtr ? NullPtr : Type;
167 TypeOrValue.IsDefaulted = IsDefaulted;
168 TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
169}
170
171void TemplateArgument::initFromDeclaration(ValueDecl *D, QualType QT,
172 bool IsDefaulted) {
173 assert(D && "Expected decl");
174 DeclArg.Kind = Declaration;
175 DeclArg.IsDefaulted = IsDefaulted;
176 DeclArg.QT = QT.getAsOpaquePtr();
177 DeclArg.D = D;
178}
179
180void TemplateArgument::initFromIntegral(const ASTContext &Ctx,
181 const llvm::APSInt &Value,
182 QualType Type, bool IsDefaulted) {
183 Integer.Kind = Integral;
184 Integer.IsDefaulted = IsDefaulted;
185 // Copy the APSInt value into our decomposed form.
186 Integer.BitWidth = Value.getBitWidth();
187 Integer.IsUnsigned = Value.isUnsigned();
188 // If the value is large, we have to get additional memory from the ASTContext
189 unsigned NumWords = Value.getNumWords();
190 if (NumWords > 1) {
191 void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
192 std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
193 Integer.pVal = static_cast<uint64_t *>(Mem);
194 } else {
195 Integer.VAL = Value.getZExtValue();
196 }
197
198 Integer.Type = Type.getAsOpaquePtr();
199}
200
201void TemplateArgument::initFromStructural(const ASTContext &Ctx, QualType Type,
202 const APValue &V, bool IsDefaulted) {
204 Value.IsDefaulted = IsDefaulted;
205 Value.Value = new (Ctx) APValue(V);
207 Value.Type = Type.getAsOpaquePtr();
208}
209
211 const llvm::APSInt &Value, QualType Type,
212 bool IsDefaulted) {
213 initFromIntegral(Ctx, Value, Type, IsDefaulted);
214}
215
217 QualType T, const APValue &V) {
218 // Pointers to members are relatively easy.
219 if (V.isMemberPointer() && V.getMemberPointerPath().empty())
220 return V.getMemberPointerDecl();
221
222 // We model class non-type template parameters as their template parameter
223 // object declaration.
224 if (V.isStruct() || V.isUnion()) {
225 // Dependent types are not supposed to be described as
226 // TemplateParamObjectDecls.
228 return nullptr;
229 return Ctx.getTemplateParamObjectDecl(T, V);
230 }
231
232 // Pointers and references with an empty path use the special 'Declaration'
233 // representation.
234 if (V.isLValue() && V.hasLValuePath() && V.getLValuePath().empty() &&
235 !V.isLValueOnePastTheEnd())
236 return V.getLValueBase().dyn_cast<const ValueDecl *>();
237
238 // Everything else uses the 'structural' representation.
239 return nullptr;
240}
241
243 const APValue &V, bool IsDefaulted) {
244 if (Type->isIntegralOrEnumerationType() && V.isInt())
245 initFromIntegral(Ctx, V.getInt(), Type, IsDefaulted);
246 else if ((V.isLValue() && V.isNullPointer()) ||
247 (V.isMemberPointer() && !V.getMemberPointerDecl()))
248 initFromType(Type, /*isNullPtr=*/true, IsDefaulted);
249 else if (const ValueDecl *VD = getAsSimpleValueDeclRef(Ctx, Type, V))
250 // FIXME: The Declaration form should expose a const ValueDecl*.
251 initFromDeclaration(const_cast<ValueDecl *>(VD), Type, IsDefaulted);
252 else
253 initFromStructural(Ctx, Type, V, IsDefaulted);
254}
255
259 if (Args.empty())
260 return getEmptyPack();
261
262 return TemplateArgument(Args.copy(Context));
263}
264
265TemplateArgumentDependence TemplateArgument::getDependence() const {
266 auto Deps = TemplateArgumentDependence::None;
267 switch (getKind()) {
268 case Null:
269 llvm_unreachable("Should not have a NULL template argument");
270
271 case Type:
273 if (isa<PackExpansionType>(getAsType()))
274 Deps |= TemplateArgumentDependence::Dependent;
275 return Deps;
276
277 case Template:
279
281 return TemplateArgumentDependence::Dependent |
282 TemplateArgumentDependence::Instantiation;
283
284 case Declaration: {
285 auto *DC = dyn_cast<DeclContext>(getAsDecl());
286 if (!DC)
287 DC = getAsDecl()->getDeclContext();
288 if (DC->isDependentContext())
289 Deps = TemplateArgumentDependence::Dependent |
290 TemplateArgumentDependence::Instantiation;
291 return Deps;
292 }
293
294 case NullPtr:
295 case Integral:
296 case StructuralValue:
297 return TemplateArgumentDependence::None;
298
299 case Expression:
301 if (isa<PackExpansionExpr>(getAsExpr()))
302 Deps |= TemplateArgumentDependence::Dependent |
303 TemplateArgumentDependence::Instantiation;
304 return Deps;
305
306 case Pack:
307 for (const auto &P : pack_elements())
308 Deps |= P.getDependence();
309 return Deps;
310 }
311 llvm_unreachable("unhandled ArgKind");
312}
313
315 return getDependence() & TemplateArgumentDependence::Dependent;
316}
317
319 return getDependence() & TemplateArgumentDependence::Instantiation;
320}
321
323 switch (getKind()) {
324 case Null:
325 case Declaration:
326 case Integral:
327 case StructuralValue:
328 case Pack:
329 case Template:
330 case NullPtr:
331 return false;
332
334 return true;
335
336 case Type:
337 return isa<PackExpansionType>(getAsType());
338
339 case Expression:
340 return isa<PackExpansionExpr>(getAsExpr());
341 }
342
343 llvm_unreachable("Invalid TemplateArgument Kind!");
344}
345
347 return getDependence() & TemplateArgumentDependence::UnexpandedPack;
348}
349
350std::optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
351 assert(getKind() == TemplateExpansion);
352 if (TemplateArg.NumExpansions)
353 return TemplateArg.NumExpansions - 1;
354
355 return std::nullopt;
356}
357
359 switch (getKind()) {
365 return QualType();
366
368 return getIntegralType();
369
371 return getAsExpr()->getType();
372
374 return getParamTypeForDecl();
375
377 return getNullPtrType();
378
380 return getStructuralValueType();
381 }
382
383 llvm_unreachable("Invalid TemplateArgument Kind!");
384}
385
386void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
387 const ASTContext &Context) const {
388 ID.AddInteger(getKind());
389 switch (getKind()) {
390 case Null:
391 break;
392
393 case Type:
394 getAsType().Profile(ID);
395 break;
396
397 case NullPtr:
399 break;
400
401 case Declaration:
403 ID.AddPointer(getAsDecl());
404 break;
405
407 ID.AddInteger(TemplateArg.NumExpansions);
408 [[fallthrough]];
409 case Template:
410 ID.AddPointer(TemplateArg.Name);
411 break;
412
413 case Integral:
415 getAsIntegral().Profile(ID);
416 break;
417
418 case StructuralValue:
421 break;
422
423 case Expression:
424 getAsExpr()->Profile(ID, Context, true);
425 break;
426
427 case Pack:
428 ID.AddInteger(Args.NumArgs);
429 for (unsigned I = 0; I != Args.NumArgs; ++I)
430 Args.Args[I].Profile(ID, Context);
431 }
432}
433
435 if (getKind() != Other.getKind()) return false;
436
437 switch (getKind()) {
438 case Null:
439 case Type:
440 case Expression:
441 case NullPtr:
442 return TypeOrValue.V == Other.TypeOrValue.V;
443
444 case Template:
446 return TemplateArg.Name == Other.TemplateArg.Name &&
447 TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
448
449 case Declaration:
450 return getAsDecl() == Other.getAsDecl() &&
451 getParamTypeForDecl() == Other.getParamTypeForDecl();
452
453 case Integral:
454 return getIntegralType() == Other.getIntegralType() &&
455 getAsIntegral() == Other.getAsIntegral();
456
457 case StructuralValue: {
458 if (getStructuralValueType().getCanonicalType() !=
459 Other.getStructuralValueType().getCanonicalType())
460 return false;
461
462 llvm::FoldingSetNodeID A, B;
464 Other.getAsStructuralValue().Profile(B);
465 return A == B;
466 }
467
468 case Pack:
469 if (Args.NumArgs != Other.Args.NumArgs) return false;
470 for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
471 if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
472 return false;
473 return true;
474 }
475
476 llvm_unreachable("Invalid TemplateArgument Kind!");
477}
478
480 assert(isPackExpansion());
481
482 switch (getKind()) {
483 case Type:
484 return getAsType()->castAs<PackExpansionType>()->getPattern();
485
486 case Expression:
487 return cast<PackExpansionExpr>(getAsExpr())->getPattern();
488
491
492 case Declaration:
493 case Integral:
494 case StructuralValue:
495 case Pack:
496 case Null:
497 case Template:
498 case NullPtr:
499 return TemplateArgument();
500 }
501
502 llvm_unreachable("Invalid TemplateArgument Kind!");
503}
504
505void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
506 bool IncludeType) const {
507
508 switch (getKind()) {
509 case Null:
510 Out << "(no value)";
511 break;
512
513 case Type: {
514 PrintingPolicy SubPolicy(Policy);
515 SubPolicy.SuppressStrongLifetime = true;
516 getAsType().print(Out, SubPolicy);
517 break;
518 }
519
520 case Declaration: {
521 NamedDecl *ND = getAsDecl();
523 if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
524 TPO->getType().getUnqualifiedType().print(Out, Policy);
525 TPO->printAsInit(Out, Policy);
526 break;
527 }
528 }
529 if (auto *VD = dyn_cast<ValueDecl>(ND)) {
531 Out << "&";
532 }
533 ND->printQualifiedName(Out);
534 break;
535 }
536
537 case StructuralValue:
539 break;
540
541 case NullPtr:
542 // FIXME: Include the type if it's not obvious from the context.
543 Out << "nullptr";
544 break;
545
546 case Template: {
547 getAsTemplate().print(Out, Policy);
548 break;
549 }
550
553 Out << "...";
554 break;
555
556 case Integral:
557 printIntegral(*this, Out, Policy, IncludeType);
558 break;
559
560 case Expression:
561 getAsExpr()->printPretty(Out, nullptr, Policy);
562 break;
563
564 case Pack:
565 Out << "<";
566 bool First = true;
567 for (const auto &P : pack_elements()) {
568 if (First)
569 First = false;
570 else
571 Out << ", ";
572
573 P.print(Policy, Out, IncludeType);
574 }
575 Out << ">";
576 break;
577 }
578}
579
580//===----------------------------------------------------------------------===//
581// TemplateArgumentLoc Implementation
582//===----------------------------------------------------------------------===//
583
585 switch (Argument.getKind()) {
588
591
594
597 return TSI->getTypeLoc().getSourceRange();
598 else
599 return SourceRange();
600
603 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
606
609 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
612
615
618
621 return SourceRange();
622 }
623
624 llvm_unreachable("Invalid TemplateArgument Kind!");
625}
626
627template <typename T>
628static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
629 switch (Arg.getKind()) {
631 // This is bad, but not as bad as crashing because of argument
632 // count mismatches.
633 return DB << "(null template argument)";
634
636 return DB << Arg.getAsType();
637
639 return DB << Arg.getAsDecl();
640
642 return DB << "nullptr";
643
645 return DB << toString(Arg.getAsIntegral(), 10);
646
648 // FIXME: We're guessing at LangOptions!
649 SmallString<32> Str;
650 llvm::raw_svector_ostream OS(Str);
651 LangOptions LangOpts;
652 LangOpts.CPlusPlus = true;
653 PrintingPolicy Policy(LangOpts);
654 Arg.getAsStructuralValue().printPretty(OS, Policy,
656 return DB << OS.str();
657 }
658
660 return DB << Arg.getAsTemplate();
661
663 return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
664
666 // This shouldn't actually ever happen, so it's okay that we're
667 // regurgitating an expression here.
668 // FIXME: We're guessing at LangOptions!
669 SmallString<32> Str;
670 llvm::raw_svector_ostream OS(Str);
671 LangOptions LangOpts;
672 LangOpts.CPlusPlus = true;
673 PrintingPolicy Policy(LangOpts);
674 Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
675 return DB << OS.str();
676 }
677
679 // FIXME: We're guessing at LangOptions!
680 SmallString<32> Str;
681 llvm::raw_svector_ostream OS(Str);
682 LangOptions LangOpts;
683 LangOpts.CPlusPlus = true;
684 PrintingPolicy Policy(LangOpts);
685 Arg.print(Policy, OS, /*IncludeType*/ true);
686 return DB << OS.str();
687 }
688 }
689
690 llvm_unreachable("Invalid TemplateArgument Kind!");
691}
692
694 const TemplateArgument &Arg) {
695 return DiagTemplateArg(DB, Arg);
696}
697
699 ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
700 SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
701 TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
702 Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
703 Template->QualifierLocData = QualifierLoc.getOpaqueData();
704 Template->TemplateNameLoc = TemplateNameLoc;
705 Template->EllipsisLoc = EllipsisLoc;
706 Pointer = Template;
707}
708
711 const TemplateArgumentListInfo &List) {
712 std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
713 void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
714 return new (Mem) ASTTemplateArgumentListInfo(List);
715}
716
719 const ASTTemplateArgumentListInfo *List) {
720 if (!List)
721 return nullptr;
722 std::size_t size =
723 totalSizeToAlloc<TemplateArgumentLoc>(List->getNumTemplateArgs());
724 void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
725 return new (Mem) ASTTemplateArgumentListInfo(List);
726}
727
728ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
729 const TemplateArgumentListInfo &Info) {
730 LAngleLoc = Info.getLAngleLoc();
731 RAngleLoc = Info.getRAngleLoc();
732 NumTemplateArgs = Info.size();
733
734 TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
735 for (unsigned i = 0; i != NumTemplateArgs; ++i)
736 new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
737}
738
739ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
740 const ASTTemplateArgumentListInfo *Info) {
741 LAngleLoc = Info->getLAngleLoc();
742 RAngleLoc = Info->getRAngleLoc();
744
745 TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
746 for (unsigned i = 0; i != NumTemplateArgs; ++i)
747 new (&ArgBuffer[i]) TemplateArgumentLoc((*Info)[i]);
748}
749
751 SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
752 TemplateArgumentLoc *OutArgArray) {
753 this->TemplateKWLoc = TemplateKWLoc;
754 LAngleLoc = Info.getLAngleLoc();
755 RAngleLoc = Info.getRAngleLoc();
756 NumTemplateArgs = Info.size();
757
758 for (unsigned i = 0; i != NumTemplateArgs; ++i)
759 new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
760}
761
763 assert(TemplateKWLoc.isValid());
766 this->TemplateKWLoc = TemplateKWLoc;
767 NumTemplateArgs = 0;
768}
769
771 SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
772 TemplateArgumentLoc *OutArgArray, TemplateArgumentDependence &Deps) {
773 this->TemplateKWLoc = TemplateKWLoc;
774 LAngleLoc = Info.getLAngleLoc();
775 RAngleLoc = Info.getRAngleLoc();
776 NumTemplateArgs = Info.size();
777
778 for (unsigned i = 0; i != NumTemplateArgs; ++i) {
779 Deps |= Info[i].getArgument().getDependence();
780
781 new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
782 }
783}
784
786 TemplateArgumentListInfo &Info) const {
789 for (unsigned I = 0; I != NumTemplateArgs; ++I)
790 Info.addArgument(ArgArray[I]);
791}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3341
StringRef P
Defines the Diagnostic-related interfaces.
const Decl * D
Expr * E
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],...
Definition: APValue.h:122
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
Definition: APValue.cpp:479
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Definition: APValue.cpp:693
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
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
Definition: ASTContext.h:734
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3171
This class is used for builtin types like 'int'.
Definition: Type.h:3023
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition: Expr.cpp:1022
DeclContext * getDeclContext()
Definition: DeclBase.h:455
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3270
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5991
QualType getType() const
Definition: Expr.h:142
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
This represents a decl that may have a name.
Definition: Decl.h:249
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...
Definition: Decl.cpp:1675
A C++ nested-name-specifier augmented with source location information.
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Represents a pack expansion of types.
Definition: Type.h:6960
A (possibly-)qualified type.
Definition: Type.h:941
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1405
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7750
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void * getAsOpaquePtr() const
Definition: Type.h:988
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1339
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
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...
Definition: Stmt.cpp:326
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.
Definition: Diagnostic.h:1115
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:650
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:651
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:623
Expr * getSourceStructuralValueExpression() const
Definition: TemplateBase.h:604
Expr * getSourceIntegralExpression() const
Definition: TemplateBase.h:599
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:616
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:578
Expr * getSourceNullPtrExpression() const
Definition: TemplateBase.h:594
SourceRange getSourceRange() const LLVM_READONLY
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:609
Expr * getSourceDeclExpression() const
Definition: TemplateBase.h:589
Expr * getSourceExpression() const
Definition: TemplateBase.h:584
Represents a template argument.
Definition: TemplateBase.h:61
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:331
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
Definition: TemplateBase.h:190
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
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.
Definition: TemplateBase.h:319
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:363
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:337
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.
Definition: TemplateBase.h:343
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()
Definition: TemplateBase.h:285
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.
Definition: TemplateBase.h:377
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
TemplateArgumentDependence getDependence() 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,...
Definition: TemplateBase.h:350
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
A container of type source information.
Definition: Type.h:7721
The base class of the type hierarchy.
Definition: Type.h:1829
bool isBooleanType() const
Definition: Type.h:8447
bool isArrayType() const
Definition: Type.h:8075
bool isCharType() const
Definition: Type.cpp:2089
bool isPointerType() const
Definition: Type.h:8003
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8607
bool isChar8Type() const
Definition: Type.cpp:2105
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:8434
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:2125
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2703
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:8288
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2695
bool isChar16Type() const
Definition: Type.cpp:2111
QualType getCanonicalTypeInternal() const
Definition: Type.h:2978
bool isMemberPointerType() const
Definition: Type.h:8057
bool isChar32Type() const
Definition: Type.cpp:2117
bool isWideCharType() const
Definition: Type.cpp:2098
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8540
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
Value()=default
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
The JSON file list parser is used to communicate input to InstallAPI.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
const FunctionProtoType * T
TemplateArgumentDependence toTemplateArgumentDependence(TypeDependence D)
@ Other
Other implicit parameter.
CharacterLiteralKind
Definition: Expr.h:1589
unsigned long uint64_t
__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>".
Definition: TemplateBase.h:676
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:691
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:688
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:696
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:694
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:697
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:730
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:742
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:733
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Definition: TemplateBase.h:739
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
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 ...