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