clang 19.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 return Ctx.getTemplateParamObjectDecl(T, V);
226
227 // Pointers and references with an empty path use the special 'Declaration'
228 // representation.
229 if (V.isLValue() && V.hasLValuePath() && V.getLValuePath().empty() &&
230 !V.isLValueOnePastTheEnd())
231 return V.getLValueBase().dyn_cast<const ValueDecl *>();
232
233 // Everything else uses the 'structural' representation.
234 return nullptr;
235}
236
238 const APValue &V, bool IsDefaulted) {
239 if (Type->isIntegralOrEnumerationType() && V.isInt())
240 initFromIntegral(Ctx, V.getInt(), Type, IsDefaulted);
241 else if ((V.isLValue() && V.isNullPointer()) ||
242 (V.isMemberPointer() && !V.getMemberPointerDecl()))
243 initFromType(Type, /*isNullPtr=*/true, IsDefaulted);
244 else if (const ValueDecl *VD = getAsSimpleValueDeclRef(Ctx, Type, V))
245 // FIXME: The Declaration form should expose a const ValueDecl*.
246 initFromDeclaration(const_cast<ValueDecl *>(VD), Type, IsDefaulted);
247 else
248 initFromStructural(Ctx, Type, V, IsDefaulted);
249}
250
254 if (Args.empty())
255 return getEmptyPack();
256
257 return TemplateArgument(Args.copy(Context));
258}
259
260TemplateArgumentDependence TemplateArgument::getDependence() const {
261 auto Deps = TemplateArgumentDependence::None;
262 switch (getKind()) {
263 case Null:
264 llvm_unreachable("Should not have a NULL template argument");
265
266 case Type:
268 if (isa<PackExpansionType>(getAsType()))
269 Deps |= TemplateArgumentDependence::Dependent;
270 return Deps;
271
272 case Template:
274
276 return TemplateArgumentDependence::Dependent |
277 TemplateArgumentDependence::Instantiation;
278
279 case Declaration: {
280 auto *DC = dyn_cast<DeclContext>(getAsDecl());
281 if (!DC)
282 DC = getAsDecl()->getDeclContext();
283 if (DC->isDependentContext())
284 Deps = TemplateArgumentDependence::Dependent |
285 TemplateArgumentDependence::Instantiation;
286 return Deps;
287 }
288
289 case NullPtr:
290 case Integral:
291 case StructuralValue:
292 return TemplateArgumentDependence::None;
293
294 case Expression:
296 if (isa<PackExpansionExpr>(getAsExpr()))
297 Deps |= TemplateArgumentDependence::Dependent |
298 TemplateArgumentDependence::Instantiation;
299 return Deps;
300
301 case Pack:
302 for (const auto &P : pack_elements())
303 Deps |= P.getDependence();
304 return Deps;
305 }
306 llvm_unreachable("unhandled ArgKind");
307}
308
310 return getDependence() & TemplateArgumentDependence::Dependent;
311}
312
314 return getDependence() & TemplateArgumentDependence::Instantiation;
315}
316
318 switch (getKind()) {
319 case Null:
320 case Declaration:
321 case Integral:
322 case StructuralValue:
323 case Pack:
324 case Template:
325 case NullPtr:
326 return false;
327
329 return true;
330
331 case Type:
332 return isa<PackExpansionType>(getAsType());
333
334 case Expression:
335 return isa<PackExpansionExpr>(getAsExpr());
336 }
337
338 llvm_unreachable("Invalid TemplateArgument Kind!");
339}
340
342 return getDependence() & TemplateArgumentDependence::UnexpandedPack;
343}
344
345std::optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
346 assert(getKind() == TemplateExpansion);
347 if (TemplateArg.NumExpansions)
348 return TemplateArg.NumExpansions - 1;
349
350 return std::nullopt;
351}
352
354 switch (getKind()) {
360 return QualType();
361
363 return getIntegralType();
364
366 return getAsExpr()->getType();
367
369 return getParamTypeForDecl();
370
372 return getNullPtrType();
373
375 return getStructuralValueType();
376 }
377
378 llvm_unreachable("Invalid TemplateArgument Kind!");
379}
380
381void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
382 const ASTContext &Context) const {
383 ID.AddInteger(getKind());
384 switch (getKind()) {
385 case Null:
386 break;
387
388 case Type:
389 getAsType().Profile(ID);
390 break;
391
392 case NullPtr:
394 break;
395
396 case Declaration:
398 ID.AddPointer(getAsDecl());
399 break;
400
402 ID.AddInteger(TemplateArg.NumExpansions);
403 [[fallthrough]];
404 case Template:
405 ID.AddPointer(TemplateArg.Name);
406 break;
407
408 case Integral:
410 getAsIntegral().Profile(ID);
411 break;
412
413 case StructuralValue:
416 break;
417
418 case Expression:
419 getAsExpr()->Profile(ID, Context, true);
420 break;
421
422 case Pack:
423 ID.AddInteger(Args.NumArgs);
424 for (unsigned I = 0; I != Args.NumArgs; ++I)
425 Args.Args[I].Profile(ID, Context);
426 }
427}
428
430 if (getKind() != Other.getKind()) return false;
431
432 switch (getKind()) {
433 case Null:
434 case Type:
435 case Expression:
436 case NullPtr:
437 return TypeOrValue.V == Other.TypeOrValue.V;
438
439 case Template:
441 return TemplateArg.Name == Other.TemplateArg.Name &&
442 TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
443
444 case Declaration:
445 return getAsDecl() == Other.getAsDecl() &&
446 getParamTypeForDecl() == Other.getParamTypeForDecl();
447
448 case Integral:
449 return getIntegralType() == Other.getIntegralType() &&
450 getAsIntegral() == Other.getAsIntegral();
451
452 case StructuralValue: {
453 if (getStructuralValueType().getCanonicalType() !=
454 Other.getStructuralValueType().getCanonicalType())
455 return false;
456
457 llvm::FoldingSetNodeID A, B;
459 Other.getAsStructuralValue().Profile(B);
460 return A == B;
461 }
462
463 case Pack:
464 if (Args.NumArgs != Other.Args.NumArgs) return false;
465 for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
466 if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
467 return false;
468 return true;
469 }
470
471 llvm_unreachable("Invalid TemplateArgument Kind!");
472}
473
475 assert(isPackExpansion());
476
477 switch (getKind()) {
478 case Type:
479 return getAsType()->castAs<PackExpansionType>()->getPattern();
480
481 case Expression:
482 return cast<PackExpansionExpr>(getAsExpr())->getPattern();
483
486
487 case Declaration:
488 case Integral:
489 case StructuralValue:
490 case Pack:
491 case Null:
492 case Template:
493 case NullPtr:
494 return TemplateArgument();
495 }
496
497 llvm_unreachable("Invalid TemplateArgument Kind!");
498}
499
500void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
501 bool IncludeType) const {
502
503 switch (getKind()) {
504 case Null:
505 Out << "(no value)";
506 break;
507
508 case Type: {
509 PrintingPolicy SubPolicy(Policy);
510 SubPolicy.SuppressStrongLifetime = true;
511 getAsType().print(Out, SubPolicy);
512 break;
513 }
514
515 case Declaration: {
516 NamedDecl *ND = getAsDecl();
518 if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
519 TPO->getType().getUnqualifiedType().print(Out, Policy);
520 TPO->printAsInit(Out, Policy);
521 break;
522 }
523 }
524 if (auto *VD = dyn_cast<ValueDecl>(ND)) {
526 Out << "&";
527 }
528 ND->printQualifiedName(Out);
529 break;
530 }
531
532 case StructuralValue:
534 break;
535
536 case NullPtr:
537 // FIXME: Include the type if it's not obvious from the context.
538 Out << "nullptr";
539 break;
540
541 case Template:
543 break;
544
547 Out << "...";
548 break;
549
550 case Integral:
551 printIntegral(*this, Out, Policy, IncludeType);
552 break;
553
554 case Expression:
555 getAsExpr()->printPretty(Out, nullptr, Policy);
556 break;
557
558 case Pack:
559 Out << "<";
560 bool First = true;
561 for (const auto &P : pack_elements()) {
562 if (First)
563 First = false;
564 else
565 Out << ", ";
566
567 P.print(Policy, Out, IncludeType);
568 }
569 Out << ">";
570 break;
571 }
572}
573
574void TemplateArgument::dump(raw_ostream &Out) const {
575 LangOptions LO; // FIXME! see also TemplateName::dump().
576 LO.CPlusPlus = true;
577 LO.Bool = true;
578 print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
579}
580
581LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
582
583//===----------------------------------------------------------------------===//
584// TemplateArgumentLoc Implementation
585//===----------------------------------------------------------------------===//
586
588 switch (Argument.getKind()) {
591
594
597
600 return TSI->getTypeLoc().getSourceRange();
601 else
602 return SourceRange();
603
606 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
609
612 return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
615
618
621
624 return SourceRange();
625 }
626
627 llvm_unreachable("Invalid TemplateArgument Kind!");
628}
629
630template <typename T>
631static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
632 switch (Arg.getKind()) {
634 // This is bad, but not as bad as crashing because of argument
635 // count mismatches.
636 return DB << "(null template argument)";
637
639 return DB << Arg.getAsType();
640
642 return DB << Arg.getAsDecl();
643
645 return DB << "nullptr";
646
648 return DB << toString(Arg.getAsIntegral(), 10);
649
651 // FIXME: We're guessing at LangOptions!
652 SmallString<32> Str;
653 llvm::raw_svector_ostream OS(Str);
654 LangOptions LangOpts;
655 LangOpts.CPlusPlus = true;
656 PrintingPolicy Policy(LangOpts);
657 Arg.getAsStructuralValue().printPretty(OS, Policy,
659 return DB << OS.str();
660 }
661
663 return DB << Arg.getAsTemplate();
664
666 return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
667
669 // This shouldn't actually ever happen, so it's okay that we're
670 // regurgitating an expression here.
671 // FIXME: We're guessing at LangOptions!
672 SmallString<32> Str;
673 llvm::raw_svector_ostream OS(Str);
674 LangOptions LangOpts;
675 LangOpts.CPlusPlus = true;
676 PrintingPolicy Policy(LangOpts);
677 Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
678 return DB << OS.str();
679 }
680
682 // FIXME: We're guessing at LangOptions!
683 SmallString<32> Str;
684 llvm::raw_svector_ostream OS(Str);
685 LangOptions LangOpts;
686 LangOpts.CPlusPlus = true;
687 PrintingPolicy Policy(LangOpts);
688 Arg.print(Policy, OS, /*IncludeType*/ true);
689 return DB << OS.str();
690 }
691 }
692
693 llvm_unreachable("Invalid TemplateArgument Kind!");
694}
695
697 const TemplateArgument &Arg) {
698 return DiagTemplateArg(DB, Arg);
699}
700
702 ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
703 SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
704 TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
705 Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
706 Template->QualifierLocData = QualifierLoc.getOpaqueData();
707 Template->TemplateNameLoc = TemplateNameLoc;
708 Template->EllipsisLoc = EllipsisLoc;
709 Pointer = Template;
710}
711
714 const TemplateArgumentListInfo &List) {
715 std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
716 void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
717 return new (Mem) ASTTemplateArgumentListInfo(List);
718}
719
722 const ASTTemplateArgumentListInfo *List) {
723 if (!List)
724 return nullptr;
725 std::size_t size =
726 totalSizeToAlloc<TemplateArgumentLoc>(List->getNumTemplateArgs());
727 void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
728 return new (Mem) ASTTemplateArgumentListInfo(List);
729}
730
731ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
732 const TemplateArgumentListInfo &Info) {
733 LAngleLoc = Info.getLAngleLoc();
734 RAngleLoc = Info.getRAngleLoc();
735 NumTemplateArgs = Info.size();
736
737 TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
738 for (unsigned i = 0; i != NumTemplateArgs; ++i)
739 new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
740}
741
742ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
743 const ASTTemplateArgumentListInfo *Info) {
744 LAngleLoc = Info->getLAngleLoc();
745 RAngleLoc = Info->getRAngleLoc();
747
748 TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
749 for (unsigned i = 0; i != NumTemplateArgs; ++i)
750 new (&ArgBuffer[i]) TemplateArgumentLoc((*Info)[i]);
751}
752
754 SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
755 TemplateArgumentLoc *OutArgArray) {
756 this->TemplateKWLoc = TemplateKWLoc;
757 LAngleLoc = Info.getLAngleLoc();
758 RAngleLoc = Info.getRAngleLoc();
759 NumTemplateArgs = Info.size();
760
761 for (unsigned i = 0; i != NumTemplateArgs; ++i)
762 new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
763}
764
766 assert(TemplateKWLoc.isValid());
769 this->TemplateKWLoc = TemplateKWLoc;
770 NumTemplateArgs = 0;
771}
772
774 SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
775 TemplateArgumentLoc *OutArgArray, TemplateArgumentDependence &Deps) {
776 this->TemplateKWLoc = TemplateKWLoc;
777 LAngleLoc = Info.getLAngleLoc();
778 RAngleLoc = Info.getRAngleLoc();
779 NumTemplateArgs = Info.size();
780
781 for (unsigned i = 0; i != NumTemplateArgs; ++i) {
782 Deps |= Info[i].getArgument().getDependence();
783
784 new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
785 }
786}
787
789 TemplateArgumentListInfo &Info) const {
792 for (unsigned I = 0; I != NumTemplateArgs; ++I)
793 Info.addArgument(ArgArray[I]);
794}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3255
StringRef P
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],...
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:182
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:713
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3082
This class is used for builtin types like 'int'.
Definition: Type.h:2739
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition: Expr.cpp:991
DeclContext * getDeclContext()
Definition: DeclBase.h:453
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3265
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5117
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:418
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:1690
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:6111
A (possibly-)qualified type.
Definition: Type.h:737
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1190
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6901
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void * getAsOpaquePtr() const
Definition: Type.h:784
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1124
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 dump() const
Debugging aid that dumps the template argument to standard error.
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:6872
The base class of the type hierarchy.
Definition: Type.h:1606
bool isBooleanType() const
Definition: Type.h:7562
bool isArrayType() const
Definition: Type.h:7219
bool isCharType() const
Definition: Type.cpp:2026
bool isPointerType() const
Definition: Type.h:7153
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7719
bool isChar8Type() const
Definition: Type.cpp:2042
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:651
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:7549
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:2062
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:7411
bool isChar16Type() const
Definition: Type.cpp:2048
QualType getCanonicalTypeInternal() const
Definition: Type.h:2702
bool isMemberPointerType() const
Definition: Type.h:7201
bool isChar32Type() const
Definition: Type.cpp:2054
bool isWideCharType() const
Definition: Type.cpp:2035
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7652
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
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.
TemplateArgumentDependence toTemplateArgumentDependence(TypeDependence D)
@ Other
Other implicit parameter.
CharacterLiteralKind
Definition: Expr.h:1571
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 ...