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/StringExtras.h"
33#include "llvm/Support/Compiler.h"
34#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
36#include <cassert>
37#include <cstddef>
38#include <cstdint>
39#include <cstring>
40#include <optional>
41
42using namespace clang;
43
44/// Print a template integral argument value.
45///
46/// \param TemplArg the TemplateArgument instance to print.
47///
48/// \param Out the raw_ostream instance to use for printing.
49///
50/// \param Policy the printing policy for EnumConstantDecl printing.
51///
52/// \param IncludeType If set, ensure that the type of the expression printed
53/// matches the type of the template argument.
54static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
55 const PrintingPolicy &Policy, bool IncludeType) {
56 const Type *T = TemplArg.getIntegralType().getTypePtr();
57 const llvm::APSInt &Val = TemplArg.getAsIntegral();
58
59 if (Policy.UseEnumerators) {
60 if (const EnumType *ET = T->getAs<EnumType>()) {
61 for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) {
62 // In Sema::CheckTemplateArugment, enum template arguments value are
63 // extended to the size of the integer underlying the enum type. This
64 // may create a size difference between the enum value and template
65 // argument value, requiring isSameValue here instead of operator==.
66 if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
67 ECD->printQualifiedName(Out, Policy);
68 return;
69 }
70 }
71 }
72 }
73
74 if (Policy.MSVCFormatting)
75 IncludeType = false;
76
77 if (T->isBooleanType()) {
78 if (!Policy.MSVCFormatting)
79 Out << (Val.getBoolValue() ? "true" : "false");
80 else
81 Out << Val;
82 } else if (T->isCharType()) {
83 if (IncludeType) {
84 if (T->isSpecificBuiltinType(BuiltinType::SChar))
85 Out << "(signed char)";
86 else if (T->isSpecificBuiltinType(BuiltinType::UChar))
87 Out << "(unsigned char)";
88 }
89 CharacterLiteral::print(Val.getZExtValue(), CharacterLiteralKind::Ascii,
90 Out);
91 } else if (T->isAnyCharacterType() && !Policy.MSVCFormatting) {
93 if (T->isWideCharType())
94 Kind = CharacterLiteralKind::Wide;
95 else if (T->isChar8Type())
96 Kind = CharacterLiteralKind::UTF8;
97 else if (T->isChar16Type())
98 Kind = CharacterLiteralKind::UTF16;
99 else if (T->isChar32Type())
100 Kind = CharacterLiteralKind::UTF32;
101 else
102 Kind = CharacterLiteralKind::Ascii;
103 CharacterLiteral::print(Val.getExtValue(), Kind, Out);
104 } else if (IncludeType) {
105 if (const auto *BT = T->getAs<BuiltinType>()) {
106 switch (BT->getKind()) {
107 case BuiltinType::ULongLong:
108 Out << Val << "ULL";
109 break;
110 case BuiltinType::LongLong:
111 Out << Val << "LL";
112 break;
113 case BuiltinType::ULong:
114 Out << Val << "UL";
115 break;
116 case BuiltinType::Long:
117 Out << Val << "L";
118 break;
119 case BuiltinType::UInt:
120 Out << Val << "U";
121 break;
122 case BuiltinType::Int:
123 Out << Val;
124 break;
125 default:
126 Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
127 << Val;
128 break;
129 }
130 } else
131 Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
132 << Val;
133 } else
134 Out << Val;
135}
136
137static unsigned getArrayDepth(QualType type) {
138 unsigned count = 0;
139 while (const auto *arrayType = type->getAsArrayTypeUnsafe()) {
140 count++;
141 type = arrayType->getElementType();
142 }
143 return count;
144}
145
146static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType) {
147 // Generally, if the parameter type is a pointer, we must be taking the
148 // address of something and need a &. However, if the argument is an array,
149 // this could be implicit via array-to-pointer decay.
150 if (!paramType->isPointerType())
151 return paramType->isMemberPointerType();
152 if (argType->isArrayType())
153 return getArrayDepth(argType) == getArrayDepth(paramType->getPointeeType());
154 return true;
155}
156
157//===----------------------------------------------------------------------===//
158// TemplateArgument Implementation
159//===----------------------------------------------------------------------===//
160
161void TemplateArgument::initFromType(QualType T, bool IsNullPtr,
162 bool IsDefaulted) {
163 TypeOrValue.Kind = IsNullPtr ? NullPtr : Type;
164 TypeOrValue.IsDefaulted = IsDefaulted;
165 TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
166}
167
168void TemplateArgument::initFromDeclaration(ValueDecl *D, QualType QT,
169 bool IsDefaulted) {
170 assert(D && "Expected decl");
171 DeclArg.Kind = Declaration;
172 DeclArg.IsDefaulted = IsDefaulted;
173 DeclArg.QT = QT.getAsOpaquePtr();
174 DeclArg.D = D;
175}
176
177void TemplateArgument::initFromIntegral(const ASTContext &Ctx,
178 const llvm::APSInt &Value,
179 QualType Type, bool IsDefaulted) {
180 Integer.Kind = Integral;
181 Integer.IsDefaulted = IsDefaulted;
182 // Copy the APSInt value into our decomposed form.
183 Integer.BitWidth = Value.getBitWidth();
184 Integer.IsUnsigned = Value.isUnsigned();
185 // If the value is large, we have to get additional memory from the ASTContext
186 unsigned NumWords = Value.getNumWords();
187 if (NumWords > 1) {
188 void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
189 std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
190 Integer.pVal = static_cast<uint64_t *>(Mem);
191 } else {
192 Integer.VAL = Value.getZExtValue();
193 }
194
195 Integer.Type = Type.getAsOpaquePtr();
196}
197
198void TemplateArgument::initFromStructural(const ASTContext &Ctx, QualType Type,
199 const APValue &V, bool IsDefaulted) {
201 Value.IsDefaulted = IsDefaulted;
202 Value.Value = new (Ctx) APValue(V);
204 Value.Type = Type.getAsOpaquePtr();
205}
206
208 const llvm::APSInt &Value, QualType Type,
209 bool IsDefaulted) {
210 initFromIntegral(Ctx, Value, Type, IsDefaulted);
211}
212
214 QualType T, const APValue &V) {
215 // Pointers to members are relatively easy.
216 if (V.isMemberPointer() && V.getMemberPointerPath().empty())
217 return V.getMemberPointerDecl();
218
219 // We model class non-type template parameters as their template parameter
220 // object declaration.
221 if (V.isStruct() || V.isUnion()) {
222 // Dependent types are not supposed to be described as
223 // TemplateParamObjectDecls.
225 return nullptr;
226 return Ctx.getTemplateParamObjectDecl(T, V);
227 }
228
229 // Pointers and references with an empty path use the special 'Declaration'
230 // representation.
231 if (V.isLValue() && V.hasLValuePath() && V.getLValuePath().empty() &&
232 !V.isLValueOnePastTheEnd())
233 return V.getLValueBase().dyn_cast<const ValueDecl *>();
234
235 // Everything else uses the 'structural' representation.
236 return nullptr;
237}
238
240 const APValue &V, bool IsDefaulted) {
241 if (Type->isIntegralOrEnumerationType() && V.isInt())
242 initFromIntegral(Ctx, V.getInt(), Type, IsDefaulted);
243 else if ((V.isLValue() && V.isNullPointer()) ||
244 (V.isMemberPointer() && !V.getMemberPointerDecl()))
245 initFromType(Type, /*isNullPtr=*/true, IsDefaulted);
246 else if (const ValueDecl *VD = getAsSimpleValueDeclRef(Ctx, Type, V))
247 // FIXME: The Declaration form should expose a const ValueDecl*.
248 initFromDeclaration(const_cast<ValueDecl *>(VD), Type, IsDefaulted);
249 else
250 initFromStructural(Ctx, Type, V, IsDefaulted);
251}
252
256 if (Args.empty())
257 return getEmptyPack();
258
259 return TemplateArgument(Args.copy(Context));
260}
261
262TemplateArgumentDependence TemplateArgument::getDependence() const {
263 auto Deps = TemplateArgumentDependence::None;
264 switch (getKind()) {
265 case Null:
266 llvm_unreachable("Should not have a NULL template argument");
267
268 case Type:
270 if (isa<PackExpansionType>(getAsType()))
271 Deps |= TemplateArgumentDependence::Dependent;
272 return Deps;
273
274 case Template:
276
278 return TemplateArgumentDependence::Dependent |
279 TemplateArgumentDependence::Instantiation;
280
281 case Declaration: {
282 auto *DC = dyn_cast<DeclContext>(getAsDecl());
283 if (!DC)
284 DC = getAsDecl()->getDeclContext();
285 if (DC->isDependentContext())
286 Deps = TemplateArgumentDependence::Dependent |
287 TemplateArgumentDependence::Instantiation;
288 return Deps;
289 }
290
291 case NullPtr:
292 case Integral:
293 case StructuralValue:
294 return TemplateArgumentDependence::None;
295
296 case Expression:
298 if (isa<PackExpansionExpr>(getAsExpr()))
299 Deps |= TemplateArgumentDependence::Dependent |
300 TemplateArgumentDependence::Instantiation;
301 return Deps;
302
303 case Pack:
304 for (const auto &P : pack_elements())
305 Deps |= P.getDependence();
306 return Deps;
307 }
308 llvm_unreachable("unhandled ArgKind");
309}
310
312 return getDependence() & TemplateArgumentDependence::Dependent;
313}
314
316 return getDependence() & TemplateArgumentDependence::Instantiation;
317}
318
320 switch (getKind()) {
321 case Null:
322 case Declaration:
323 case Integral:
324 case StructuralValue:
325 case Pack:
326 case Template:
327 case NullPtr:
328 return false;
329
331 return true;
332
333 case Type:
334 return isa<PackExpansionType>(getAsType());
335
336 case Expression:
337 return isa<PackExpansionExpr>(getAsExpr());
338 }
339
340 llvm_unreachable("Invalid TemplateArgument Kind!");
341}
342
344 return getDependence() & TemplateArgumentDependence::UnexpandedPack;
345}
346
347std::optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
348 assert(getKind() == TemplateExpansion);
349 if (TemplateArg.NumExpansions)
350 return TemplateArg.NumExpansions - 1;
351
352 return std::nullopt;
353}
354
356 switch (getKind()) {
362 return QualType();
363
365 return getIntegralType();
366
368 return getAsExpr()->getType();
369
371 return getParamTypeForDecl();
372
374 return getNullPtrType();
375
377 return getStructuralValueType();
378 }
379
380 llvm_unreachable("Invalid TemplateArgument Kind!");
381}
382
383void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
384 const ASTContext &Context) const {
385 ID.AddInteger(getKind());
386 switch (getKind()) {
387 case Null:
388 break;
389
390 case Type:
391 getAsType().Profile(ID);
392 break;
393
394 case NullPtr:
396 break;
397
398 case Declaration:
400 ID.AddPointer(getAsDecl());
401 break;
402
404 ID.AddInteger(TemplateArg.NumExpansions);
405 [[fallthrough]];
406 case Template:
407 ID.AddPointer(TemplateArg.Name);
408 break;
409
410 case Integral:
412 getAsIntegral().Profile(ID);
413 break;
414
415 case StructuralValue:
418 break;
419
420 case Expression:
421 getAsExpr()->Profile(ID, Context, true);
422 break;
423
424 case Pack:
425 ID.AddInteger(Args.NumArgs);
426 for (unsigned I = 0; I != Args.NumArgs; ++I)
427 Args.Args[I].Profile(ID, Context);
428 }
429}
430
432 if (getKind() != Other.getKind()) return false;
433
434 switch (getKind()) {
435 case Null:
436 case Type:
437 case Expression:
438 case NullPtr:
439 return TypeOrValue.V == Other.TypeOrValue.V;
440
441 case Template:
443 return TemplateArg.Name == Other.TemplateArg.Name &&
444 TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
445
446 case Declaration:
447 return getAsDecl() == Other.getAsDecl() &&
448 getParamTypeForDecl() == Other.getParamTypeForDecl();
449
450 case Integral:
451 return getIntegralType() == Other.getIntegralType() &&
452 getAsIntegral() == Other.getAsIntegral();
453
454 case StructuralValue: {
455 if (getStructuralValueType().getCanonicalType() !=
456 Other.getStructuralValueType().getCanonicalType())
457 return false;
458
459 llvm::FoldingSetNodeID A, B;
461 Other.getAsStructuralValue().Profile(B);
462 return A == B;
463 }
464
465 case Pack:
466 if (Args.NumArgs != Other.Args.NumArgs) return false;
467 for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
468 if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
469 return false;
470 return true;
471 }
472
473 llvm_unreachable("Invalid TemplateArgument Kind!");
474}
475
477 assert(isPackExpansion());
478
479 switch (getKind()) {
480 case Type:
481 return getAsType()->castAs<PackExpansionType>()->getPattern();
482
483 case Expression:
484 return cast<PackExpansionExpr>(getAsExpr())->getPattern();
485
488
489 case Declaration:
490 case Integral:
491 case StructuralValue:
492 case Pack:
493 case Null:
494 case Template:
495 case NullPtr:
496 return TemplateArgument();
497 }
498
499 llvm_unreachable("Invalid TemplateArgument Kind!");
500}
501
502void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
503 bool IncludeType) const {
504
505 switch (getKind()) {
506 case Null:
507 Out << "(no value)";
508 break;
509
510 case Type: {
511 PrintingPolicy SubPolicy(Policy);
512 SubPolicy.SuppressStrongLifetime = true;
513 getAsType().print(Out, SubPolicy);
514 break;
515 }
516
517 case Declaration: {
518 NamedDecl *ND = getAsDecl();
520 if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
521 TPO->getType().getUnqualifiedType().print(Out, Policy);
522 TPO->printAsInit(Out, Policy);
523 break;
524 }
525 }
526 if (auto *VD = dyn_cast<ValueDecl>(ND)) {
528 Out << "&";
529 }
530 ND->printQualifiedName(Out);
531 break;
532 }
533
534 case StructuralValue:
536 break;
537
538 case NullPtr:
539 // FIXME: Include the type if it's not obvious from the context.
540 Out << "nullptr";
541 break;
542
543 case Template: {
544 getAsTemplate().print(Out, Policy);
545 break;
546 }
547
550 Out << "...";
551 break;
552
553 case Integral:
554 printIntegral(*this, Out, Policy, IncludeType);
555 break;
556
557 case Expression:
558 getAsExpr()->printPretty(Out, nullptr, Policy);
559 break;
560
561 case Pack:
562 Out << "<";
563 bool First = true;
564 for (const auto &P : pack_elements()) {
565 if (First)
566 First = false;
567 else
568 Out << ", ";
569
570 P.print(Policy, Out, IncludeType);
571 }
572 Out << ">";
573 break;
574 }
575}
576
577//===----------------------------------------------------------------------===//
578// TemplateArgumentLoc Implementation
579//===----------------------------------------------------------------------===//
580
582 switch (Argument.getKind()) {
585
588
591
594 return TSI->getTypeLoc().getSourceRange();
595 else
596 return SourceRange();
597
600 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
603
606 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
609
612
615
618 return SourceRange();
619 }
620
621 llvm_unreachable("Invalid TemplateArgument Kind!");
622}
623
624template <typename T>
625static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
626 switch (Arg.getKind()) {
628 // This is bad, but not as bad as crashing because of argument
629 // count mismatches.
630 return DB << "(null template argument)";
631
633 return DB << Arg.getAsType();
634
636 return DB << Arg.getAsDecl();
637
639 return DB << "nullptr";
640
642 return DB << toString(Arg.getAsIntegral(), 10);
643
645 // FIXME: We're guessing at LangOptions!
646 SmallString<32> Str;
647 llvm::raw_svector_ostream OS(Str);
648 LangOptions LangOpts;
649 LangOpts.CPlusPlus = true;
650 PrintingPolicy Policy(LangOpts);
651 Arg.getAsStructuralValue().printPretty(OS, Policy,
653 return DB << OS.str();
654 }
655
657 return DB << Arg.getAsTemplate();
658
660 return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
661
663 // This shouldn't actually ever happen, so it's okay that we're
664 // regurgitating an expression here.
665 // FIXME: We're guessing at LangOptions!
666 SmallString<32> Str;
667 llvm::raw_svector_ostream OS(Str);
668 LangOptions LangOpts;
669 LangOpts.CPlusPlus = true;
670 PrintingPolicy Policy(LangOpts);
671 Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
672 return DB << OS.str();
673 }
674
676 // FIXME: We're guessing at LangOptions!
677 SmallString<32> Str;
678 llvm::raw_svector_ostream OS(Str);
679 LangOptions LangOpts;
680 LangOpts.CPlusPlus = true;
681 PrintingPolicy Policy(LangOpts);
682 Arg.print(Policy, OS, /*IncludeType*/ true);
683 return DB << OS.str();
684 }
685 }
686
687 llvm_unreachable("Invalid TemplateArgument Kind!");
688}
689
691 const TemplateArgument &Arg) {
692 return DiagTemplateArg(DB, Arg);
693}
694
696 ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
697 SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
698 TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
699 Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
700 Template->QualifierLocData = QualifierLoc.getOpaqueData();
701 Template->TemplateNameLoc = TemplateNameLoc;
702 Template->EllipsisLoc = EllipsisLoc;
703 Pointer = Template;
704}
705
708 const TemplateArgumentListInfo &List) {
709 std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
710 void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
711 return new (Mem) ASTTemplateArgumentListInfo(List);
712}
713
716 const ASTTemplateArgumentListInfo *List) {
717 if (!List)
718 return nullptr;
719 std::size_t size =
720 totalSizeToAlloc<TemplateArgumentLoc>(List->getNumTemplateArgs());
721 void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
722 return new (Mem) ASTTemplateArgumentListInfo(List);
723}
724
725ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
726 const TemplateArgumentListInfo &Info) {
727 LAngleLoc = Info.getLAngleLoc();
728 RAngleLoc = Info.getRAngleLoc();
729 NumTemplateArgs = Info.size();
730
731 TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
732 for (unsigned i = 0; i != NumTemplateArgs; ++i)
733 new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
734}
735
736ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
737 const ASTTemplateArgumentListInfo *Info) {
738 LAngleLoc = Info->getLAngleLoc();
739 RAngleLoc = Info->getRAngleLoc();
741
742 TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
743 for (unsigned i = 0; i != NumTemplateArgs; ++i)
744 new (&ArgBuffer[i]) TemplateArgumentLoc((*Info)[i]);
745}
746
748 SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
749 TemplateArgumentLoc *OutArgArray) {
750 this->TemplateKWLoc = TemplateKWLoc;
751 LAngleLoc = Info.getLAngleLoc();
752 RAngleLoc = Info.getRAngleLoc();
753 NumTemplateArgs = Info.size();
754
755 for (unsigned i = 0; i != NumTemplateArgs; ++i)
756 new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
757}
758
760 assert(TemplateKWLoc.isValid());
763 this->TemplateKWLoc = TemplateKWLoc;
764 NumTemplateArgs = 0;
765}
766
768 SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
769 TemplateArgumentLoc *OutArgArray, TemplateArgumentDependence &Deps) {
770 this->TemplateKWLoc = TemplateKWLoc;
771 LAngleLoc = Info.getLAngleLoc();
772 RAngleLoc = Info.getRAngleLoc();
773 NumTemplateArgs = Info.size();
774
775 for (unsigned i = 0; i != NumTemplateArgs; ++i) {
776 Deps |= Info[i].getArgument().getDependence();
777
778 new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
779 }
780}
781
783 TemplateArgumentListInfo &Info) const {
786 for (unsigned I = 0; I != NumTemplateArgs; ++I)
787 Info.addArgument(ArgArray[I]);
788}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3443
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:188
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:754
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3261
This class is used for builtin types like 'int'.
Definition: Type.h:3034
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition: Expr.cpp:1018
DeclContext * getDeclContext()
Definition: DeclBase.h:451
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3277
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:6098
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:499
This represents a decl that may have a name.
Definition: Decl.h:253
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:7141
A (possibly-)qualified type.
Definition: Type.h:929
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1393
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void * getAsOpaquePtr() const
Definition: Type.h:976
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1327
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:333
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:1102
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:7902
The base class of the type hierarchy.
Definition: Type.h:1828
bool isBooleanType() const
Definition: Type.h:8638
bool isArrayType() const
Definition: Type.h:8258
bool isCharType() const
Definition: Type.cpp:2123
bool isPointerType() const
Definition: Type.h:8186
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8800
bool isChar8Type() const
Definition: Type.cpp:2139
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:8625
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:2159
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2714
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:8479
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
bool isChar16Type() const
Definition: Type.cpp:2145
QualType getCanonicalTypeInternal() const
Definition: Type.h:2989
bool isMemberPointerType() const
Definition: Type.h:8240
bool isChar32Type() const
Definition: Type.cpp:2151
bool isWideCharType() const
Definition: Type.cpp:2132
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
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 ...