clang 18.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 LLVM_PREFERRED_TYPE(ArgKind)
107 unsigned Kind : 31;
108 LLVM_PREFERRED_TYPE(bool)
109 unsigned IsDefaulted : 1;
110 void *QT;
111 ValueDecl *D;
112 };
113 struct I {
114 LLVM_PREFERRED_TYPE(ArgKind)
115 unsigned Kind : 31;
116 LLVM_PREFERRED_TYPE(bool)
117 unsigned IsDefaulted : 1;
118 // We store a decomposed APSInt with the data allocated by ASTContext if
119 // BitWidth > 64. The memory may be shared between multiple
120 // TemplateArgument instances.
121 unsigned BitWidth : 31;
122 LLVM_PREFERRED_TYPE(bool)
123 unsigned IsUnsigned : 1;
124 union {
125 /// Used to store the <= 64 bits integer value.
126 uint64_t VAL;
127
128 /// Used to store the >64 bits integer value.
129 const uint64_t *pVal;
130 };
131 void *Type;
132 };
133 struct A {
134 LLVM_PREFERRED_TYPE(ArgKind)
135 unsigned Kind : 31;
136 LLVM_PREFERRED_TYPE(bool)
137 unsigned IsDefaulted : 1;
138 unsigned NumArgs;
139 const TemplateArgument *Args;
140 };
141 struct TA {
142 LLVM_PREFERRED_TYPE(ArgKind)
143 unsigned Kind : 31;
144 LLVM_PREFERRED_TYPE(bool)
145 unsigned IsDefaulted : 1;
146 unsigned NumExpansions;
147 void *Name;
148 };
149 struct TV {
150 LLVM_PREFERRED_TYPE(ArgKind)
151 unsigned Kind : 31;
152 LLVM_PREFERRED_TYPE(bool)
153 unsigned IsDefaulted : 1;
154 uintptr_t V;
155 };
156 union {
157 struct DA DeclArg;
158 struct I Integer;
159 struct A Args;
160 struct TA TemplateArg;
161 struct TV TypeOrValue;
162 };
163
164public:
165 /// Construct an empty, invalid template argument.
166 constexpr TemplateArgument() : TypeOrValue({Null, 0, /* IsDefaulted */ 0}) {}
167
168 /// Construct a template type argument.
169 TemplateArgument(QualType T, bool isNullPtr = false,
170 bool IsDefaulted = false) {
171 TypeOrValue.Kind = isNullPtr ? NullPtr : Type;
172 TypeOrValue.IsDefaulted = IsDefaulted;
173 TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
174 }
175
176 /// Construct a template argument that refers to a
177 /// declaration, which is either an external declaration or a
178 /// template declaration.
179 TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
180 assert(D && "Expected decl");
181 DeclArg.Kind = Declaration;
182 DeclArg.IsDefaulted = IsDefaulted;
183 DeclArg.QT = QT.getAsOpaquePtr();
184 DeclArg.D = D;
185 }
186
187 /// Construct an integral constant template argument. The memory to
188 /// store the value is allocated with Ctx.
189 TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type,
190 bool IsDefaulted = false);
191
192 /// Construct an integral constant template argument with the same
193 /// value as Other but a different type.
195 Integer = Other.Integer;
196 Integer.Type = Type.getAsOpaquePtr();
197 }
198
199 /// Construct a template argument that is a template.
200 ///
201 /// This form of template argument is generally used for template template
202 /// parameters. However, the template name could be a dependent template
203 /// name that ends up being instantiated to a function template whose address
204 /// is taken.
205 ///
206 /// \param Name The template name.
207 ///
208 /// \param IsDefaulted If 'true', implies that this TemplateArgument
209 /// corresponds to a default template parameter
210 TemplateArgument(TemplateName Name, bool IsDefaulted = false) {
211 TemplateArg.Kind = Template;
212 TemplateArg.IsDefaulted = IsDefaulted;
213 TemplateArg.Name = Name.getAsVoidPointer();
214 TemplateArg.NumExpansions = 0;
215 }
216
217 /// Construct a template argument that is a template pack expansion.
218 ///
219 /// This form of template argument is generally used for template template
220 /// parameters. However, the template name could be a dependent template
221 /// name that ends up being instantiated to a function template whose address
222 /// is taken.
223 ///
224 /// \param Name The template name.
225 ///
226 /// \param NumExpansions The number of expansions that will be generated by
227 /// instantiating
228 ///
229 /// \param IsDefaulted If 'true', implies that this TemplateArgument
230 /// corresponds to a default template parameter
231 TemplateArgument(TemplateName Name, std::optional<unsigned> NumExpansions,
232 bool IsDefaulted = false) {
234 TemplateArg.IsDefaulted = IsDefaulted;
235 TemplateArg.Name = Name.getAsVoidPointer();
236 if (NumExpansions)
237 TemplateArg.NumExpansions = *NumExpansions + 1;
238 else
239 TemplateArg.NumExpansions = 0;
240 }
241
242 /// Construct a template argument that is an expression.
243 ///
244 /// This form of template argument only occurs in template argument
245 /// lists used for dependent types and for expression; it will not
246 /// occur in a non-dependent, canonical template argument list.
247 TemplateArgument(Expr *E, bool IsDefaulted = false) {
248 TypeOrValue.Kind = Expression;
249 TypeOrValue.IsDefaulted = IsDefaulted;
250 TypeOrValue.V = reinterpret_cast<uintptr_t>(E);
251 }
252
253 /// Construct a template argument that is a template argument pack.
254 ///
255 /// We assume that storage for the template arguments provided
256 /// outlives the TemplateArgument itself.
258 this->Args.Kind = Pack;
259 this->Args.IsDefaulted = false;
260 this->Args.Args = Args.data();
261 this->Args.NumArgs = Args.size();
262 }
263
265 return TemplateArgument(std::nullopt);
266 }
267
268 /// Create a new template argument pack by copying the given set of
269 /// template arguments.
272
273 /// Return the kind of stored template argument.
274 ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; }
275
276 /// Determine whether this template argument has no value.
277 bool isNull() const { return getKind() == Null; }
278
279 TemplateArgumentDependence getDependence() const;
280
281 /// Whether this template argument is dependent on a template
282 /// parameter such that its result can change from one instantiation to
283 /// another.
284 bool isDependent() const;
285
286 /// Whether this template argument is dependent on a template
287 /// parameter.
288 bool isInstantiationDependent() const;
289
290 /// Whether this template argument contains an unexpanded
291 /// parameter pack.
293
294 /// Determine whether this template argument is a pack expansion.
295 bool isPackExpansion() const;
296
297 /// Retrieve the type for a type template argument.
299 assert(getKind() == Type && "Unexpected kind");
300 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
301 }
302
303 /// Retrieve the declaration for a declaration non-type
304 /// template argument.
306 assert(getKind() == Declaration && "Unexpected kind");
307 return DeclArg.D;
308 }
309
311 assert(getKind() == Declaration && "Unexpected kind");
313 }
314
315 /// Retrieve the type for null non-type template argument.
317 assert(getKind() == NullPtr && "Unexpected kind");
318 return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
319 }
320
321 /// Retrieve the template name for a template name argument.
323 assert(getKind() == Template && "Unexpected kind");
325 }
326
327 /// Retrieve the template argument as a template name; if the argument
328 /// is a pack expansion, return the pattern as a template name.
330 assert((getKind() == Template || getKind() == TemplateExpansion) &&
331 "Unexpected kind");
332
334 }
335
336 /// Retrieve the number of expansions that a template template argument
337 /// expansion will produce, if known.
338 std::optional<unsigned> getNumTemplateExpansions() const;
339
340 /// Retrieve the template argument as an integral value.
341 // FIXME: Provide a way to read the integral data without copying the value.
342 llvm::APSInt getAsIntegral() const {
343 assert(getKind() == Integral && "Unexpected kind");
344
345 using namespace llvm;
346
347 if (Integer.BitWidth <= 64)
348 return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
349
350 unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
351 return APSInt(APInt(Integer.BitWidth, ArrayRef(Integer.pVal, NumWords)),
352 Integer.IsUnsigned);
353 }
354
355 /// Retrieve the type of the integral value.
357 assert(getKind() == Integral && "Unexpected kind");
359 }
360
362 assert(getKind() == Integral && "Unexpected kind");
363 Integer.Type = T.getAsOpaquePtr();
364 }
365
366 /// Set to 'true' if this TemplateArgument corresponds to a
367 /// default template parameter.
368 void setIsDefaulted(bool v) { TypeOrValue.IsDefaulted = v; }
369
370 /// If returns 'true', this TemplateArgument corresponds to a
371 /// default template parameter.
372 bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
373
374 /// If this is a non-type template argument, get its type. Otherwise,
375 /// returns a null QualType.
377
378 /// Retrieve the template argument as an expression.
379 Expr *getAsExpr() const {
380 assert(getKind() == Expression && "Unexpected kind");
381 return reinterpret_cast<Expr *>(TypeOrValue.V);
382 }
383
384 /// Iterator that traverses the elements of a template argument pack.
386
387 /// Iterator referencing the first argument of a template argument
388 /// pack.
390 assert(getKind() == Pack);
391 return Args.Args;
392 }
393
394 /// Iterator referencing one past the last argument of a template
395 /// argument pack.
397 assert(getKind() == Pack);
398 return Args.Args + Args.NumArgs;
399 }
400
401 /// Iterator range referencing all of the elements of a template
402 /// argument pack.
405 }
406
407 /// The number of template arguments in the given template argument
408 /// pack.
409 unsigned pack_size() const {
410 assert(getKind() == Pack);
411 return Args.NumArgs;
412 }
413
414 /// Return the array of arguments in this template argument pack.
416 assert(getKind() == Pack);
417 return llvm::ArrayRef(Args.Args, Args.NumArgs);
418 }
419
420 /// Determines whether two template arguments are superficially the
421 /// same.
422 bool structurallyEquals(const TemplateArgument &Other) const;
423
424 /// When the template argument is a pack expansion, returns
425 /// the pattern of the pack expansion.
427
428 /// Print this template argument to the given output stream.
429 void print(const PrintingPolicy &Policy, raw_ostream &Out,
430 bool IncludeType) const;
431
432 /// Debugging aid that dumps the template argument.
433 void dump(raw_ostream &Out) const;
434
435 /// Debugging aid that dumps the template argument to standard error.
436 void dump() const;
437
438 /// Used to insert TemplateArguments into FoldingSets.
439 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
440};
441
442/// Location information for a TemplateArgument.
444private:
445 struct TemplateTemplateArgLocInfo {
446 // FIXME: We'd like to just use the qualifier in the TemplateName,
447 // but template arguments get canonicalized too quickly.
448 NestedNameSpecifier *Qualifier;
449 void *QualifierLocData;
450 SourceLocation TemplateNameLoc;
451 SourceLocation EllipsisLoc;
452 };
453
454 llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
455 Pointer;
456
457 TemplateTemplateArgLocInfo *getTemplate() const {
458 return Pointer.get<TemplateTemplateArgLocInfo *>();
459 }
460
461public:
464
465 TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
466 // Ctx is used for allocation -- this case is unusually large and also rare,
467 // so we store the payload out-of-line.
469 SourceLocation TemplateNameLoc,
470 SourceLocation EllipsisLoc);
471
473 return Pointer.get<TypeSourceInfo *>();
474 }
475
476 Expr *getAsExpr() const { return Pointer.get<Expr *>(); }
477
479 const auto *Template = getTemplate();
480 return NestedNameSpecifierLoc(Template->Qualifier,
481 Template->QualifierLocData);
482 }
483
485 return getTemplate()->TemplateNameLoc;
486 }
487
489 return getTemplate()->EllipsisLoc;
490 }
491};
492
493/// Location wrapper for a TemplateArgument. TemplateArgument is to
494/// TemplateArgumentLoc as Type is to TypeLoc.
496 TemplateArgument Argument;
498
499public:
501
504 : Argument(Argument), LocInfo(Opaque) {}
505
507 : Argument(Argument), LocInfo(TInfo) {
508 assert(Argument.getKind() == TemplateArgument::Type);
509 }
510
512 : Argument(Argument), LocInfo(E) {
513
514 // Permit any kind of template argument that can be represented with an
515 // expression.
516 assert(Argument.getKind() == TemplateArgument::NullPtr ||
517 Argument.getKind() == TemplateArgument::Integral ||
520 }
521
523 NestedNameSpecifierLoc QualifierLoc,
524 SourceLocation TemplateNameLoc,
525 SourceLocation EllipsisLoc = SourceLocation())
526 : Argument(Argument),
527 LocInfo(Ctx, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
528 assert(Argument.getKind() == TemplateArgument::Template ||
530 }
531
532 /// - Fetches the primary location of the argument.
534 if (Argument.getKind() == TemplateArgument::Template ||
536 return getTemplateNameLoc();
537
538 return getSourceRange().getBegin();
539 }
540
541 /// - Fetches the full source range of the argument.
542 SourceRange getSourceRange() const LLVM_READONLY;
543
545 return Argument;
546 }
547
549 return LocInfo;
550 }
551
553 if (Argument.getKind() != TemplateArgument::Type)
554 return nullptr;
555 return LocInfo.getAsTypeSourceInfo();
556 }
557
559 assert(Argument.getKind() == TemplateArgument::Expression);
560 return LocInfo.getAsExpr();
561 }
562
564 assert(Argument.getKind() == TemplateArgument::Declaration);
565 return LocInfo.getAsExpr();
566 }
567
569 assert(Argument.getKind() == TemplateArgument::NullPtr);
570 return LocInfo.getAsExpr();
571 }
572
574 assert(Argument.getKind() == TemplateArgument::Integral);
575 return LocInfo.getAsExpr();
576 }
577
579 if (Argument.getKind() != TemplateArgument::Template &&
581 return NestedNameSpecifierLoc();
582 return LocInfo.getTemplateQualifierLoc();
583 }
584
586 if (Argument.getKind() != TemplateArgument::Template &&
588 return SourceLocation();
589 return LocInfo.getTemplateNameLoc();
590 }
591
594 return SourceLocation();
595 return LocInfo.getTemplateEllipsisLoc();
596 }
597};
598
599/// A convenient class for passing around template argument
600/// information. Designed to be passed by reference.
603 SourceLocation LAngleLoc;
604 SourceLocation RAngleLoc;
605
606public:
608
610 SourceLocation RAngleLoc)
611 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
612
613 // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
614 // instead.
615 void *operator new(size_t bytes, ASTContext &C) = delete;
616
617 SourceLocation getLAngleLoc() const { return LAngleLoc; }
618 SourceLocation getRAngleLoc() const { return RAngleLoc; }
619
620 void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
621 void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
622
623 unsigned size() const { return Arguments.size(); }
624
626 return Arguments.data();
627 }
628
630 return Arguments;
631 }
632
633 const TemplateArgumentLoc &operator[](unsigned I) const {
634 return Arguments[I];
635 }
636
638 return Arguments[I];
639 }
640
642 Arguments.push_back(Loc);
643 }
644};
645
646/// Represents an explicit template argument list in C++, e.g.,
647/// the "<int>" in "sort<int>".
648/// This is safe to be used inside an AST node, in contrast with
649/// TemplateArgumentListInfo.
651 : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
652 TemplateArgumentLoc> {
653private:
654 friend class ASTNodeImporter;
655 friend TrailingObjects;
656
658
659 // FIXME: Is it ever necessary to copy to another context?
661
662public:
663 /// The source location of the left angle bracket ('<').
665
666 /// The source location of the right angle bracket ('>').
668
669 /// The number of template arguments in TemplateArgs.
671
674
675 /// Retrieve the template arguments
677 return getTrailingObjects<TemplateArgumentLoc>();
678 }
679 unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
680
683 }
684
685 const TemplateArgumentLoc &operator[](unsigned I) const {
686 return getTemplateArgs()[I];
687 }
688
689 static const ASTTemplateArgumentListInfo *
691
692 // FIXME: Is it ever necessary to copy to another context?
693 static const ASTTemplateArgumentListInfo *
695};
696
697/// Represents an explicit template argument list in C++, e.g.,
698/// the "<int>" in "sort<int>".
699///
700/// It is intended to be used as a trailing object on AST nodes, and
701/// as such, doesn't contain the array of TemplateArgumentLoc itself,
702/// but expects the containing object to also provide storage for
703/// that.
704struct alignas(void *) ASTTemplateKWAndArgsInfo {
705 /// The source location of the left angle bracket ('<').
707
708 /// The source location of the right angle bracket ('>').
710
711 /// The source location of the template keyword; this is used
712 /// as part of the representation of qualified identifiers, such as
713 /// S<T>::template apply<T>. Will be empty if this expression does
714 /// not have a template keyword.
716
717 /// The number of template arguments in TemplateArgs.
719
722 TemplateArgumentLoc *OutArgArray);
723 // FIXME: The parameter Deps is the result populated by this method, the
724 // caller doesn't need it since it is populated by computeDependence. remove
725 // it.
728 TemplateArgumentLoc *OutArgArray,
729 TemplateArgumentDependence &Deps);
731
732 void copyInto(const TemplateArgumentLoc *ArgArray,
734};
735
737 const TemplateArgument &Arg);
738
739} // namespace clang
740
741#endif // LLVM_CLANG_AST_TEMPLATEBASE_H
#define V(N, I)
Definition: ASTContext.h:3241
MatchType Type
StringRef P
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:123
static char ID
Definition: Arena.cpp:183
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:1115
A convenient class for passing around template argument information.
Definition: TemplateBase.h:601
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:618
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:620
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:621
TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
Definition: TemplateBase.h:609
const TemplateArgumentLoc * getArgumentArray() const
Definition: TemplateBase.h:625
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:641
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:629
const TemplateArgumentLoc & operator[](unsigned I) const
Definition: TemplateBase.h:633
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:617
TemplateArgumentLoc & operator[](unsigned I)
Definition: TemplateBase.h:637
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:495
SourceLocation getLocation() const
Definition: TemplateBase.h:533
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:592
Expr * getSourceIntegralExpression() const
Definition: TemplateBase.h:573
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:548
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:544
TemplateArgumentLoc(const TemplateArgument &Argument, TemplateArgumentLocInfo Opaque)
Definition: TemplateBase.h:502
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:585
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:552
TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
Definition: TemplateBase.h:506
Expr * getSourceNullPtrExpression() const
Definition: TemplateBase.h:568
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
Definition: TemplateBase.h:511
SourceRange getSourceRange() const LLVM_READONLY
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:578
Expr * getSourceDeclExpression() const
Definition: TemplateBase.h:563
Expr * getSourceExpression() const
Definition: TemplateBase.h:558
TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc=SourceLocation())
Definition: TemplateBase.h:522
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:415
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:194
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:310
TemplateArgument(QualType T, bool isNullPtr=false, bool IsDefaulted=false)
Construct a template type argument.
Definition: TemplateBase.h:169
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:379
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:257
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:396
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
Definition: TemplateBase.h:166
void setIntegralType(QualType T)
Definition: TemplateBase.h:361
TemplateArgument(TemplateName Name, std::optional< unsigned > NumExpansions, bool IsDefaulted=false)
Construct a template argument that is a template pack expansion.
Definition: TemplateBase.h:231
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:179
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:389
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:298
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:342
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:316
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:322
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:247
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:277
static TemplateArgument getEmptyPack()
Definition: TemplateBase.h:264
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:409
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:356
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:372
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:305
TemplateArgument(TemplateName Name, bool IsDefaulted=false)
Construct a template argument that is a template.
Definition: TemplateBase.h:210
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:403
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:274
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:329
void setIsDefaulted(bool v)
Set to 'true' if this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:368
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:6752
The base class of the type hierarchy.
Definition: Type.h:1602
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:704
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
@ Other
Other implicit parameter.
@ List
New-expression has a C++11 list-initializer.
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:652
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:667
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Definition: TemplateBase.h:676
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:664
const TemplateArgumentLoc & operator[](unsigned I) const
Definition: TemplateBase.h:685
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:672
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:681
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:670
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:673
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:704
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:706
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:718
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:709
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Definition: TemplateBase.h:715
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
Location information for a TemplateArgument.
Definition: TemplateBase.h:443
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:488
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:478
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:472
TemplateArgumentLocInfo(TypeSourceInfo *Declarator)
Definition: TemplateBase.h:463
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:484
static void * getAsVoidPointer(clang::Expr *P)
Definition: TemplateBase.h:42
static clang::Expr * getFromVoidPointer(void *P)
Definition: TemplateBase.h:43