clang 17.0.0git
TemplateBase.h
Go to the documentation of this file.
1//===- TemplateBase.h - Core classes for C++ templates ----------*- C++ -*-===//
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 provides definitions which are common for all kinds of
10// template representation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_TEMPLATEBASE_H
15#define LLVM_CLANG_AST_TEMPLATEBASE_H
16
20#include "clang/AST/Type.h"
21#include "clang/Basic/LLVM.h"
23#include "llvm/ADT/APInt.h"
24#include "llvm/ADT/APSInt.h"
25#include "llvm/ADT/ArrayRef.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/Support/Compiler.h"
28#include "llvm/Support/TrailingObjects.h"
29#include <cassert>
30#include <cstddef>
31#include <cstdint>
32#include <optional>
33
34namespace llvm {
35
36class FoldingSetNodeID;
37
38// Provide PointerLikeTypeTraits for clang::Expr*, this default one requires a
39// full definition of Expr, but this file only sees a forward del because of
40// the dependency.
41template <> struct PointerLikeTypeTraits<clang::Expr *> {
42 static inline void *getAsVoidPointer(clang::Expr *P) { return P; }
43 static inline clang::Expr *getFromVoidPointer(void *P) {
44 return static_cast<clang::Expr *>(P);
45 }
46 static constexpr int NumLowBitsAvailable = 2;
47};
48
49} // namespace llvm
50
51namespace clang {
52
53class ASTContext;
54class Expr;
55struct PrintingPolicy;
56class TypeSourceInfo;
57class ValueDecl;
58
59/// Represents a template argument.
61public:
62 /// The kind of template argument we're storing.
63 enum ArgKind {
64 /// Represents an empty template argument, e.g., one that has not
65 /// been deduced.
66 Null = 0,
67
68 /// The template argument is a type.
70
71 /// The template argument is a declaration that was provided for a pointer,
72 /// reference, or pointer to member non-type template parameter.
74
75 /// The template argument is a null pointer or null pointer to member that
76 /// was provided for a non-type template parameter.
78
79 /// The template argument is an integral value stored in an llvm::APSInt
80 /// that was provided for an integral non-type template parameter.
82
83 /// The template argument is a template name that was provided for a
84 /// template template parameter.
86
87 /// The template argument is a pack expansion of a template name that was
88 /// provided for a template template parameter.
90
91 /// The template argument is an expression, and we've not resolved it to one
92 /// of the other forms yet, either because it's dependent or because we're
93 /// representing a non-canonical template argument (for instance, in a
94 /// TemplateSpecializationType).
96
97 /// The template argument is actually a parameter pack. Arguments are stored
98 /// in the Args struct.
99 Pack
100 };
101
102private:
103 /// The kind of template argument we're storing.
104
105 struct DA {
106 unsigned Kind : 31;
107 unsigned IsDefaulted : 1;
108 void *QT;
109 ValueDecl *D;
110 };
111 struct I {
112 unsigned Kind : 31;
113 unsigned IsDefaulted : 1;
114 // We store a decomposed APSInt with the data allocated by ASTContext if
115 // BitWidth > 64. The memory may be shared between multiple
116 // TemplateArgument instances.
117 unsigned BitWidth : 31;
118 unsigned IsUnsigned : 1;
119 union {
120 /// Used to store the <= 64 bits integer value.
121 uint64_t VAL;
122
123 /// Used to store the >64 bits integer value.
124 const uint64_t *pVal;
125 };
126 void *Type;
127 };
128 struct A {
129 unsigned Kind : 31;
130 unsigned IsDefaulted : 1;
131 unsigned NumArgs;
132 const TemplateArgument *Args;
133 };
134 struct TA {
135 unsigned Kind : 31;
136 unsigned IsDefaulted : 1;
137 unsigned NumExpansions;
138 void *Name;
139 };
140 struct TV {
141 unsigned Kind : 31;
142 unsigned IsDefaulted : 1;
143 uintptr_t V;
144 };
145 union {
146 struct DA DeclArg;
147 struct I Integer;
148 struct A Args;
149 struct TA TemplateArg;
150 struct TV TypeOrValue;
151 };
152
153public:
154 /// Construct an empty, invalid template argument.
155 constexpr TemplateArgument() : TypeOrValue({Null, 0, /* IsDefaulted */ 0}) {}
156
157 /// Construct a template type argument.
158 TemplateArgument(QualType T, bool isNullPtr = false,
159 bool IsDefaulted = false) {
160 TypeOrValue.Kind = isNullPtr ? NullPtr : Type;
161 TypeOrValue.IsDefaulted = IsDefaulted;
162 TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
163 }
164
165 /// Construct a template argument that refers to a
166 /// declaration, which is either an external declaration or a
167 /// template declaration.
168 TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
169 assert(D && "Expected decl");
170 DeclArg.Kind = Declaration;
171 DeclArg.IsDefaulted = IsDefaulted;
172 DeclArg.QT = QT.getAsOpaquePtr();
173 DeclArg.D = D;
174 }
175
176 /// Construct an integral constant template argument. The memory to
177 /// store the value is allocated with Ctx.
178 TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type,
179 bool IsDefaulted = false);
180
181 /// Construct an integral constant template argument with the same
182 /// value as Other but a different type.
184 Integer = Other.Integer;
185 Integer.Type = Type.getAsOpaquePtr();
186 }
187
188 /// Construct a template argument that is a template.
189 ///
190 /// This form of template argument is generally used for template template
191 /// parameters. However, the template name could be a dependent template
192 /// name that ends up being instantiated to a function template whose address
193 /// is taken.
194 ///
195 /// \param Name The template name.
196 ///
197 /// \param IsDefaulted If 'true', implies that this TemplateArgument
198 /// corresponds to a default template parameter
199 TemplateArgument(TemplateName Name, bool IsDefaulted = false) {
200 TemplateArg.Kind = Template;
201 TemplateArg.IsDefaulted = IsDefaulted;
202 TemplateArg.Name = Name.getAsVoidPointer();
203 TemplateArg.NumExpansions = 0;
204 }
205
206 /// Construct a template argument that is a template pack expansion.
207 ///
208 /// This form of template argument is generally used for template template
209 /// parameters. However, the template name could be a dependent template
210 /// name that ends up being instantiated to a function template whose address
211 /// is taken.
212 ///
213 /// \param Name The template name.
214 ///
215 /// \param NumExpansions The number of expansions that will be generated by
216 /// instantiating
217 ///
218 /// \param IsDefaulted If 'true', implies that this TemplateArgument
219 /// corresponds to a default template parameter
220 TemplateArgument(TemplateName Name, std::optional<unsigned> NumExpansions,
221 bool IsDefaulted = false) {
223 TemplateArg.IsDefaulted = IsDefaulted;
224 TemplateArg.Name = Name.getAsVoidPointer();
225 if (NumExpansions)
226 TemplateArg.NumExpansions = *NumExpansions + 1;
227 else
228 TemplateArg.NumExpansions = 0;
229 }
230
231 /// Construct a template argument that is an expression.
232 ///
233 /// This form of template argument only occurs in template argument
234 /// lists used for dependent types and for expression; it will not
235 /// occur in a non-dependent, canonical template argument list.
236 TemplateArgument(Expr *E, bool IsDefaulted = false) {
237 TypeOrValue.Kind = Expression;
238 TypeOrValue.IsDefaulted = IsDefaulted;
239 TypeOrValue.V = reinterpret_cast<uintptr_t>(E);
240 }
241
242 /// Construct a template argument that is a template argument pack.
243 ///
244 /// We assume that storage for the template arguments provided
245 /// outlives the TemplateArgument itself.
247 this->Args.Kind = Pack;
248 this->Args.IsDefaulted = false;
249 this->Args.Args = Args.data();
250 this->Args.NumArgs = Args.size();
251 }
252
254 return TemplateArgument(std::nullopt);
255 }
256
257 /// Create a new template argument pack by copying the given set of
258 /// template arguments.
261
262 /// Return the kind of stored template argument.
263 ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; }
264
265 /// Determine whether this template argument has no value.
266 bool isNull() const { return getKind() == Null; }
267
268 TemplateArgumentDependence getDependence() const;
269
270 /// Whether this template argument is dependent on a template
271 /// parameter such that its result can change from one instantiation to
272 /// another.
273 bool isDependent() const;
274
275 /// Whether this template argument is dependent on a template
276 /// parameter.
277 bool isInstantiationDependent() const;
278
279 /// Whether this template argument contains an unexpanded
280 /// parameter pack.
282
283 /// Determine whether this template argument is a pack expansion.
284 bool isPackExpansion() const;
285
286 /// Retrieve the type for a type template argument.
288 assert(getKind() == Type && "Unexpected kind");
289 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
290 }
291
292 /// Retrieve the declaration for a declaration non-type
293 /// template argument.
295 assert(getKind() == Declaration && "Unexpected kind");
296 return DeclArg.D;
297 }
298
300 assert(getKind() == Declaration && "Unexpected kind");
302 }
303
304 /// Retrieve the type for null non-type template argument.
306 assert(getKind() == NullPtr && "Unexpected kind");
307 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
308 }
309
310 /// Retrieve the template name for a template name argument.
312 assert(getKind() == Template && "Unexpected kind");
314 }
315
316 /// Retrieve the template argument as a template name; if the argument
317 /// is a pack expansion, return the pattern as a template name.
319 assert((getKind() == Template || getKind() == TemplateExpansion) &&
320 "Unexpected kind");
321
323 }
324
325 /// Retrieve the number of expansions that a template template argument
326 /// expansion will produce, if known.
327 std::optional<unsigned> getNumTemplateExpansions() const;
328
329 /// Retrieve the template argument as an integral value.
330 // FIXME: Provide a way to read the integral data without copying the value.
331 llvm::APSInt getAsIntegral() const {
332 assert(getKind() == Integral && "Unexpected kind");
333
334 using namespace llvm;
335
336 if (Integer.BitWidth <= 64)
337 return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
338
339 unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
340 return APSInt(APInt(Integer.BitWidth, ArrayRef(Integer.pVal, NumWords)),
341 Integer.IsUnsigned);
342 }
343
344 /// Retrieve the type of the integral value.
346 assert(getKind() == Integral && "Unexpected kind");
348 }
349
351 assert(getKind() == Integral && "Unexpected kind");
352 Integer.Type = T.getAsOpaquePtr();
353 }
354
355 /// Set to 'true' if this TemplateArgument corresponds to a
356 /// default template parameter.
357 void setIsDefaulted(bool v) { TypeOrValue.IsDefaulted = v; }
358
359 /// If returns 'true', this TemplateArgument corresponds to a
360 /// default template parameter.
361 bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
362
363 /// If this is a non-type template argument, get its type. Otherwise,
364 /// returns a null QualType.
366
367 /// Retrieve the template argument as an expression.
368 Expr *getAsExpr() const {
369 assert(getKind() == Expression && "Unexpected kind");
370 return reinterpret_cast<Expr *>(TypeOrValue.V);
371 }
372
373 /// Iterator that traverses the elements of a template argument pack.
375
376 /// Iterator referencing the first argument of a template argument
377 /// pack.
379 assert(getKind() == Pack);
380 return Args.Args;
381 }
382
383 /// Iterator referencing one past the last argument of a template
384 /// argument pack.
386 assert(getKind() == Pack);
387 return Args.Args + Args.NumArgs;
388 }
389
390 /// Iterator range referencing all of the elements of a template
391 /// argument pack.
394 }
395
396 /// The number of template arguments in the given template argument
397 /// pack.
398 unsigned pack_size() const {
399 assert(getKind() == Pack);
400 return Args.NumArgs;
401 }
402
403 /// Return the array of arguments in this template argument pack.
405 assert(getKind() == Pack);
406 return llvm::ArrayRef(Args.Args, Args.NumArgs);
407 }
408
409 /// Determines whether two template arguments are superficially the
410 /// same.
411 bool structurallyEquals(const TemplateArgument &Other) const;
412
413 /// When the template argument is a pack expansion, returns
414 /// the pattern of the pack expansion.
416
417 /// Print this template argument to the given output stream.
418 void print(const PrintingPolicy &Policy, raw_ostream &Out,
419 bool IncludeType) const;
420
421 /// Debugging aid that dumps the template argument.
422 void dump(raw_ostream &Out) const;
423
424 /// Debugging aid that dumps the template argument to standard error.
425 void dump() const;
426
427 /// Used to insert TemplateArguments into FoldingSets.
428 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
429};
430
431/// Location information for a TemplateArgument.
433private:
434 struct TemplateTemplateArgLocInfo {
435 // FIXME: We'd like to just use the qualifier in the TemplateName,
436 // but template arguments get canonicalized too quickly.
437 NestedNameSpecifier *Qualifier;
438 void *QualifierLocData;
439 SourceLocation TemplateNameLoc;
440 SourceLocation EllipsisLoc;
441 };
442
443 llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
444 Pointer;
445
446 TemplateTemplateArgLocInfo *getTemplate() const {
447 return Pointer.get<TemplateTemplateArgLocInfo *>();
448 }
449
450public:
453
454 TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
455 // Ctx is used for allocation -- this case is unusually large and also rare,
456 // so we store the payload out-of-line.
458 SourceLocation TemplateNameLoc,
459 SourceLocation EllipsisLoc);
460
462 return Pointer.get<TypeSourceInfo *>();
463 }
464
465 Expr *getAsExpr() const { return Pointer.get<Expr *>(); }
466
468 const auto *Template = getTemplate();
469 return NestedNameSpecifierLoc(Template->Qualifier,
470 Template->QualifierLocData);
471 }
472
474 return getTemplate()->TemplateNameLoc;
475 }
476
478 return getTemplate()->EllipsisLoc;
479 }
480};
481
482/// Location wrapper for a TemplateArgument. TemplateArgument is to
483/// TemplateArgumentLoc as Type is to TypeLoc.
485 TemplateArgument Argument;
487
488public:
490
493 : Argument(Argument), LocInfo(Opaque) {}
494
496 : Argument(Argument), LocInfo(TInfo) {
497 assert(Argument.getKind() == TemplateArgument::Type);
498 }
499
501 : Argument(Argument), LocInfo(E) {
502
503 // Permit any kind of template argument that can be represented with an
504 // expression.
505 assert(Argument.getKind() == TemplateArgument::NullPtr ||
506 Argument.getKind() == TemplateArgument::Integral ||
509 }
510
512 NestedNameSpecifierLoc QualifierLoc,
513 SourceLocation TemplateNameLoc,
514 SourceLocation EllipsisLoc = SourceLocation())
515 : Argument(Argument),
516 LocInfo(Ctx, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
517 assert(Argument.getKind() == TemplateArgument::Template ||
519 }
520
521 /// - Fetches the primary location of the argument.
523 if (Argument.getKind() == TemplateArgument::Template ||
525 return getTemplateNameLoc();
526
527 return getSourceRange().getBegin();
528 }
529
530 /// - Fetches the full source range of the argument.
531 SourceRange getSourceRange() const LLVM_READONLY;
532
534 return Argument;
535 }
536
538 return LocInfo;
539 }
540
542 if (Argument.getKind() != TemplateArgument::Type)
543 return nullptr;
544 return LocInfo.getAsTypeSourceInfo();
545 }
546
548 assert(Argument.getKind() == TemplateArgument::Expression);
549 return LocInfo.getAsExpr();
550 }
551
553 assert(Argument.getKind() == TemplateArgument::Declaration);
554 return LocInfo.getAsExpr();
555 }
556
558 assert(Argument.getKind() == TemplateArgument::NullPtr);
559 return LocInfo.getAsExpr();
560 }
561
563 assert(Argument.getKind() == TemplateArgument::Integral);
564 return LocInfo.getAsExpr();
565 }
566
568 if (Argument.getKind() != TemplateArgument::Template &&
570 return NestedNameSpecifierLoc();
571 return LocInfo.getTemplateQualifierLoc();
572 }
573
575 if (Argument.getKind() != TemplateArgument::Template &&
577 return SourceLocation();
578 return LocInfo.getTemplateNameLoc();
579 }
580
583 return SourceLocation();
584 return LocInfo.getTemplateEllipsisLoc();
585 }
586};
587
588/// A convenient class for passing around template argument
589/// information. Designed to be passed by reference.
592 SourceLocation LAngleLoc;
593 SourceLocation RAngleLoc;
594
595public:
597
599 SourceLocation RAngleLoc)
600 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
601
602 // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
603 // instead.
604 void *operator new(size_t bytes, ASTContext &C) = delete;
605
606 SourceLocation getLAngleLoc() const { return LAngleLoc; }
607 SourceLocation getRAngleLoc() const { return RAngleLoc; }
608
609 void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
610 void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
611
612 unsigned size() const { return Arguments.size(); }
613
615 return Arguments.data();
616 }
617
619 return Arguments;
620 }
621
622 const TemplateArgumentLoc &operator[](unsigned I) const {
623 return Arguments[I];
624 }
625
627 return Arguments[I];
628 }
629
631 Arguments.push_back(Loc);
632 }
633};
634
635/// Represents an explicit template argument list in C++, e.g.,
636/// the "<int>" in "sort<int>".
637/// This is safe to be used inside an AST node, in contrast with
638/// TemplateArgumentListInfo.
640 : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
641 TemplateArgumentLoc> {
642private:
643 friend class ASTNodeImporter;
644 friend TrailingObjects;
645
647
648 // FIXME: Is it ever necessary to copy to another context?
650
651public:
652 /// The source location of the left angle bracket ('<').
654
655 /// The source location of the right angle bracket ('>').
657
658 /// The number of template arguments in TemplateArgs.
660
663
664 /// Retrieve the template arguments
666 return getTrailingObjects<TemplateArgumentLoc>();
667 }
668 unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
669
672 }
673
674 const TemplateArgumentLoc &operator[](unsigned I) const {
675 return getTemplateArgs()[I];
676 }
677
678 static const ASTTemplateArgumentListInfo *
679 Create(const ASTContext &C, const TemplateArgumentListInfo &List);
680
681 // FIXME: Is it ever necessary to copy to another context?
682 static const ASTTemplateArgumentListInfo *
683 Create(const ASTContext &C, const ASTTemplateArgumentListInfo *List);
684};
685
686/// Represents an explicit template argument list in C++, e.g.,
687/// the "<int>" in "sort<int>".
688///
689/// It is intended to be used as a trailing object on AST nodes, and
690/// as such, doesn't contain the array of TemplateArgumentLoc itself,
691/// but expects the containing object to also provide storage for
692/// that.
693struct alignas(void *) ASTTemplateKWAndArgsInfo {
694 /// The source location of the left angle bracket ('<').
696
697 /// The source location of the right angle bracket ('>').
699
700 /// The source location of the template keyword; this is used
701 /// as part of the representation of qualified identifiers, such as
702 /// S<T>::template apply<T>. Will be empty if this expression does
703 /// not have a template keyword.
705
706 /// The number of template arguments in TemplateArgs.
708
710 const TemplateArgumentListInfo &List,
711 TemplateArgumentLoc *OutArgArray);
712 // FIXME: The parameter Deps is the result populated by this method, the
713 // caller doesn't need it since it is populated by computeDependence. remove
714 // it.
716 const TemplateArgumentListInfo &List,
717 TemplateArgumentLoc *OutArgArray,
718 TemplateArgumentDependence &Deps);
720
721 void copyInto(const TemplateArgumentLoc *ArgArray,
722 TemplateArgumentListInfo &List) const;
723};
724
726 const TemplateArgument &Arg);
727
728} // namespace clang
729
730#endif // LLVM_CLANG_AST_TEMPLATEBASE_H
#define V(N, I)
Definition: ASTContext.h:3217
MatchType Type
StringRef P
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:123
llvm::APSInt APSInt
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
do v
Definition: arm_acle.h:76
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1850
This represents one expression.
Definition: Expr.h:110
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A (possibly-)qualified type.
Definition: Type.h:736
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:785
void * getAsOpaquePtr() const
Definition: Type.h:783
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1110
A convenient class for passing around template argument information.
Definition: TemplateBase.h:590
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:607
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:609
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:610
TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
Definition: TemplateBase.h:598
const TemplateArgumentLoc * getArgumentArray() const
Definition: TemplateBase.h:614
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:630
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:618
const TemplateArgumentLoc & operator[](unsigned I) const
Definition: TemplateBase.h:622
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:606
TemplateArgumentLoc & operator[](unsigned I)
Definition: TemplateBase.h:626
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:484
SourceLocation getLocation() const
Definition: TemplateBase.h:522
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:581
Expr * getSourceIntegralExpression() const
Definition: TemplateBase.h:562
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:537
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:533
TemplateArgumentLoc(const TemplateArgument &Argument, TemplateArgumentLocInfo Opaque)
Definition: TemplateBase.h:491
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:574
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:541
TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
Definition: TemplateBase.h:495
Expr * getSourceNullPtrExpression() const
Definition: TemplateBase.h:557
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
Definition: TemplateBase.h:500
SourceRange getSourceRange() const LLVM_READONLY
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:567
Expr * getSourceDeclExpression() const
Definition: TemplateBase.h:552
Expr * getSourceExpression() const
Definition: TemplateBase.h:547
TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc=SourceLocation())
Definition: TemplateBase.h:511
Represents a template argument.
Definition: TemplateBase.h:60
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:404
TemplateArgument(const TemplateArgument &Other, QualType Type)
Construct an integral constant template argument with the same value as Other but a different type.
Definition: TemplateBase.h:183
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:299
TemplateArgument(QualType T, bool isNullPtr=false, bool IsDefaulted=false)
Construct a template type argument.
Definition: TemplateBase.h:158
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:368
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
TemplateArgument(ArrayRef< TemplateArgument > Args)
Construct a template argument that is a template argument pack.
Definition: TemplateBase.h:246
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
Definition: TemplateBase.h:385
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
Definition: TemplateBase.h:155
void setIntegralType(QualType T)
Definition: TemplateBase.h:350
TemplateArgument(TemplateName Name, std::optional< unsigned > NumExpansions, bool IsDefaulted=false)
Construct a template argument that is a template pack expansion.
Definition: TemplateBase.h:220
TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted=false)
Construct a template argument that refers to a declaration, which is either an external declaration o...
Definition: TemplateBase.h:168
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:378
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:287
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:331
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:305
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:311
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.
TemplateArgument(Expr *E, bool IsDefaulted=false)
Construct a template argument that is an expression.
Definition: TemplateBase.h:236
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:266
static TemplateArgument getEmptyPack()
Definition: TemplateBase.h:253
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:398
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:345
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:361
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:294
TemplateArgument(TemplateName Name, bool IsDefaulted=false)
Construct a template argument that is a template.
Definition: TemplateBase.h:199
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:392
ArgKind
The kind of template argument we're storing.
Definition: TemplateBase.h:63
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:73
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:85
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:99
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:89
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:77
@ Type
The template argument is a type.
Definition: TemplateBase.h:69
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:66
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:81
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:95
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:263
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:318
void setIsDefaulted(bool v)
Set to 'true' if this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:357
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
static TemplateName getFromVoidPointer(void *Ptr)
Build a template name from a void pointer.
Definition: TemplateName.h:360
A container of type source information.
Definition: Type.h:6620
The base class of the type hierarchy.
Definition: Type.h:1566
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:701
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
@ C
Languages that the frontend can parse and compile.
YAML serialization mapping.
Definition: Dominators.h:30
__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:641
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:656
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Definition: TemplateBase.h:665
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:653
const TemplateArgumentLoc & operator[](unsigned I) const
Definition: TemplateBase.h:674
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:661
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:670
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:659
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:662
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:693
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:695
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:707
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:698
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Definition: TemplateBase.h:704
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
Location information for a TemplateArgument.
Definition: TemplateBase.h:432
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:477
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:467
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:461
TemplateArgumentLocInfo(TypeSourceInfo *Declarator)
Definition: TemplateBase.h:452
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:473
static void * getAsVoidPointer(clang::Expr *P)
Definition: TemplateBase.h:42
static clang::Expr * getFromVoidPointer(void *P)
Definition: TemplateBase.h:43