clang 22.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/TypeBase.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 UnsignedOrNone 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 LLVM_PREFERRED_TYPE(bool)
171 unsigned IsCanonicalExpr : 1;
172 uintptr_t V;
173 };
174 union {
175 struct DA DeclArg;
176 struct I Integer;
177 struct V Value;
178 struct A Args;
179 struct TA TemplateArg;
180 struct TV TypeOrValue;
181 };
182
183 void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
184 void initFromDeclaration(ValueDecl *D, QualType QT, bool IsDefaulted);
185 void initFromIntegral(const ASTContext &Ctx, const llvm::APSInt &Value,
186 QualType Type, bool IsDefaulted);
187 void initFromStructural(const ASTContext &Ctx, QualType Type,
188 const APValue &V, bool IsDefaulted);
189
190public:
191 /// Construct an empty, invalid template argument.
193 : TypeOrValue{Null, /*IsDefaulted=*/0, /*IsCanonicalExpr=*/0, /*V=*/0} {}
194
195 /// Construct a template type argument.
196 TemplateArgument(QualType T, bool isNullPtr = false,
197 bool IsDefaulted = false) {
198 initFromType(T, isNullPtr, IsDefaulted);
199 }
200
201 /// Construct a template argument that refers to a (non-dependent)
202 /// declaration.
203 TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
204 initFromDeclaration(D, QT, IsDefaulted);
205 }
206
207 /// Construct an integral constant template argument. The memory to
208 /// store the value is allocated with Ctx.
209 TemplateArgument(const ASTContext &Ctx, const llvm::APSInt &Value,
210 QualType Type, bool IsDefaulted = false);
211
212 /// Construct a template argument from an arbitrary constant value.
214 bool IsDefaulted = false);
215
216 /// Construct an integral constant template argument with the same
217 /// value as Other but a different type.
219 Integer = Other.Integer;
220 Integer.Type = Type.getAsOpaquePtr();
221 }
222
223 /// Construct a template argument that is a template.
224 ///
225 /// This form of template argument is generally used for template template
226 /// parameters. However, the template name could be a dependent template
227 /// name that ends up being instantiated to a function template whose address
228 /// is taken.
229 ///
230 /// \param Name The template name.
231 ///
232 /// \param IsDefaulted If 'true', implies that this TemplateArgument
233 /// corresponds to a default template parameter
234 TemplateArgument(TemplateName Name, bool IsDefaulted = false) {
235 TemplateArg.Kind = Template;
236 TemplateArg.IsDefaulted = IsDefaulted;
237 TemplateArg.Name = Name.getAsVoidPointer();
238 TemplateArg.NumExpansions = std::nullopt;
239 }
240
241 /// Construct a template argument that is a template pack expansion.
242 ///
243 /// This form of template argument is generally used for template template
244 /// parameters. However, the template name could be a dependent template
245 /// name that ends up being instantiated to a function template whose address
246 /// is taken.
247 ///
248 /// \param Name The template name.
249 ///
250 /// \param NumExpansions The number of expansions that will be generated by
251 /// instantiating
252 ///
253 /// \param IsDefaulted If 'true', implies that this TemplateArgument
254 /// corresponds to a default template parameter
256 bool IsDefaulted = false) {
258 TemplateArg.IsDefaulted = IsDefaulted;
259 TemplateArg.Name = Name.getAsVoidPointer();
260 TemplateArg.NumExpansions = NumExpansions;
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 IsCanonical, bool IsDefaulted = false) {
269 TypeOrValue.Kind = Expression;
270 TypeOrValue.IsDefaulted = IsDefaulted;
271 TypeOrValue.IsCanonicalExpr = IsCanonical;
272 TypeOrValue.V = reinterpret_cast<uintptr_t>(E);
273 }
274
275 /// Construct a template argument that is a template argument pack.
276 ///
277 /// We assume that storage for the template arguments provided
278 /// outlives the TemplateArgument itself.
280 this->Args.Kind = Pack;
281 this->Args.IsDefaulted = false;
282 this->Args.Args = Args.data();
283 this->Args.NumArgs = Args.size();
284 }
285
288 }
289
290 /// Create a new template argument pack by copying the given set of
291 /// template arguments.
294
295 /// Return the kind of stored template argument.
296 ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; }
297
298 /// Determine whether this template argument has no value.
299 bool isNull() const { return getKind() == Null; }
300
301 TemplateArgumentDependence getDependence() const;
302
303 /// Whether this template argument is dependent on a template
304 /// parameter such that its result can change from one instantiation to
305 /// another.
306 bool isDependent() const;
307
308 /// Whether this template argument is dependent on a template
309 /// parameter.
310 bool isInstantiationDependent() const;
311
312 /// Whether this template argument contains an unexpanded
313 /// parameter pack.
315
316 /// Determine whether this template argument is a pack expansion.
317 bool isPackExpansion() const;
318
320
321 /// Retrieve the type for a type template argument.
323 assert(getKind() == Type && "Unexpected kind");
324 return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
325 }
326
327 /// Retrieve the declaration for a declaration non-type
328 /// template argument.
330 assert(getKind() == Declaration && "Unexpected kind");
331 return DeclArg.D;
332 }
333
335 assert(getKind() == Declaration && "Unexpected kind");
337 }
338
339 /// Retrieve the type for null non-type template argument.
341 assert(getKind() == NullPtr && "Unexpected kind");
342 return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
343 }
344
345 /// Retrieve the template name for a template name argument.
347 assert(getKind() == Template && "Unexpected kind");
349 }
350
351 /// Retrieve the template argument as a template name; if the argument
352 /// is a pack expansion, return the pattern as a template name.
354 assert((getKind() == Template || getKind() == TemplateExpansion) &&
355 "Unexpected kind");
356
358 }
359
360 /// Retrieve the number of expansions that a template template argument
361 /// expansion will produce, if known.
363
364 /// Retrieve the template argument as an integral value.
365 // FIXME: Provide a way to read the integral data without copying the value.
366 llvm::APSInt getAsIntegral() const {
367 assert(getKind() == Integral && "Unexpected kind");
368
369 using namespace llvm;
370
371 if (Integer.BitWidth <= 64)
372 return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
373
374 unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
375 return APSInt(APInt(Integer.BitWidth, ArrayRef(Integer.pVal, NumWords)),
376 Integer.IsUnsigned);
377 }
378
379 /// Retrieve the type of the integral value.
381 assert(getKind() == Integral && "Unexpected kind");
383 }
384
386 assert(getKind() == Integral && "Unexpected kind");
387 Integer.Type = T.getAsOpaquePtr();
388 }
389
390 /// Set to 'true' if this TemplateArgument corresponds to a
391 /// default template parameter.
392 void setIsDefaulted(bool v) { TypeOrValue.IsDefaulted = v; }
393
394 /// If returns 'true', this TemplateArgument corresponds to a
395 /// default template parameter.
396 bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
397
398 /// Get the value of a StructuralValue.
399 const APValue &getAsStructuralValue() const { return *Value.Value; }
400
401 /// Get the type of a StructuralValue.
404 }
405
406 /// If this is a non-type template argument, get its type. Otherwise,
407 /// returns a null QualType.
409
410 /// Retrieve the template argument as an expression.
411 Expr *getAsExpr() const {
412 assert(getKind() == Expression && "Unexpected kind");
413 return reinterpret_cast<Expr *>(TypeOrValue.V);
414 }
415
416 bool isCanonicalExpr() const {
417 assert(getKind() == Expression && "Unexpected kind");
418 return TypeOrValue.IsCanonicalExpr;
419 }
420
421 /// Iterator that traverses the elements of a template argument pack.
423
424 /// Iterator referencing the first argument of a template argument
425 /// pack.
427 assert(getKind() == Pack);
428 return Args.Args;
429 }
430
431 /// Iterator referencing one past the last argument of a template
432 /// argument pack.
434 assert(getKind() == Pack);
435 return Args.Args + Args.NumArgs;
436 }
437
438 /// Iterator range referencing all of the elements of a template
439 /// argument pack.
441 return {pack_begin(), pack_end()};
442 }
443
444 /// The number of template arguments in the given template argument
445 /// pack.
446 unsigned pack_size() const {
447 assert(getKind() == Pack);
448 return Args.NumArgs;
449 }
450
451 /// Return the array of arguments in this template argument pack.
453 assert(getKind() == Pack);
454 return {Args.Args, Args.NumArgs};
455 }
456
457 /// Determines whether two template arguments are superficially the
458 /// same.
459 bool structurallyEquals(const TemplateArgument &Other) const;
460
461 /// When the template argument is a pack expansion, returns
462 /// the pattern of the pack expansion.
464
465 /// Print this template argument to the given output stream.
466 void print(const PrintingPolicy &Policy, raw_ostream &Out,
467 bool IncludeType) const;
468
469 /// Debugging aid that dumps the template argument.
470 void dump(raw_ostream &Out, const ASTContext &Context) const;
471
472 /// Debugging aid that dumps the template argument to standard error.
473 void dump() const;
474
475 /// Used to insert TemplateArguments into FoldingSets.
476 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
477};
478
479/// Location information for a TemplateArgument.
486 };
487
489 return cast<TemplateTemplateArgLocInfo *>(Pointer);
490 }
491
494
496 // Ctx is used for allocation -- this case is unusually large and also rare,
497 // so we store the payload out-of-line.
499 NestedNameSpecifierLoc QualifierLoc,
500 SourceLocation TemplateNameLoc,
501 SourceLocation EllipsisLoc);
502
504 return cast<TypeSourceInfo *>(Pointer);
505 }
506
507 Expr *getAsExpr() const { return cast<Expr *>(Pointer); }
508
510 return getTemplate()->TemplateKwLoc;
511 }
512
515 }
516
518 return getTemplate()->EllipsisLoc;
519 }
520
521private:
522 llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
523 Pointer;
524};
525
526/// Location wrapper for a TemplateArgument. TemplateArgument is to
527/// TemplateArgumentLoc as Type is to TypeLoc.
529 TemplateArgument Argument;
531
532public:
534
537 : Argument(Argument), LocInfo(Opaque) {}
538
540 : Argument(Argument), LocInfo(TInfo) {
541 assert(Argument.getKind() == TemplateArgument::Type);
542 }
543
545 : Argument(Argument), LocInfo(E) {
546
547 // Permit any kind of template argument that can be represented with an
548 // expression.
549 assert(Argument.getKind() == TemplateArgument::NullPtr ||
550 Argument.getKind() == TemplateArgument::Integral ||
554 }
555
556 TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument,
557 SourceLocation TemplateKWLoc,
558 NestedNameSpecifierLoc QualifierLoc,
559 SourceLocation TemplateNameLoc,
560 SourceLocation EllipsisLoc = SourceLocation());
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 SourceLocation();
613 return LocInfo.getTemplateKwLoc();
614 }
615
617
619 if (Argument.getKind() != TemplateArgument::Template &&
621 return SourceLocation();
622 return LocInfo.getTemplateNameLoc();
623 }
624
627 return SourceLocation();
628 return LocInfo.getTemplateEllipsisLoc();
629 }
630};
631
632/// A convenient class for passing around template argument
633/// information. Designed to be passed by reference.
636 SourceLocation LAngleLoc;
637 SourceLocation RAngleLoc;
638
639public:
641
643 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
644
645 // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
646 // instead.
647 void *operator new(size_t bytes, ASTContext &C) = delete;
648
649 SourceLocation getLAngleLoc() const { return LAngleLoc; }
650 SourceLocation getRAngleLoc() const { return RAngleLoc; }
651
652 void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
653 void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
654
655 unsigned size() const { return Arguments.size(); }
656
658 return Arguments.data();
659 }
660
661 ArrayRef<TemplateArgumentLoc> arguments() const { return Arguments; }
662
663 const TemplateArgumentLoc &operator[](unsigned I) const {
664 return Arguments[I];
665 }
666
667 TemplateArgumentLoc &operator[](unsigned I) { return Arguments[I]; }
668
669 void addArgument(const TemplateArgumentLoc &Loc) { Arguments.push_back(Loc); }
670};
671
672/// Represents an explicit template argument list in C++, e.g.,
673/// the "<int>" in "sort<int>".
674/// This is safe to be used inside an AST node, in contrast with
675/// TemplateArgumentListInfo.
677 : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
678 TemplateArgumentLoc> {
679private:
680 friend class ASTNodeImporter;
681 friend TrailingObjects;
682
684
685 // FIXME: Is it ever necessary to copy to another context?
687
688public:
689 /// The source location of the left angle bracket ('<').
691
692 /// The source location of the right angle bracket ('>').
694
695 /// The number of template arguments in TemplateArgs.
697
700
701 /// Retrieve the template arguments
703 return getTrailingObjects();
704 }
705 unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
706
709 }
710
711 const TemplateArgumentLoc &operator[](unsigned I) const {
712 return getTemplateArgs()[I];
713 }
714
715 static const ASTTemplateArgumentListInfo *
716 Create(const ASTContext &C, const TemplateArgumentListInfo &List);
717
718 // FIXME: Is it ever necessary to copy to another context?
719 static const ASTTemplateArgumentListInfo *
720 Create(const ASTContext &C, const ASTTemplateArgumentListInfo *List);
721};
722
723/// Represents an explicit template argument list in C++, e.g.,
724/// the "<int>" in "sort<int>".
725///
726/// It is intended to be used as a trailing object on AST nodes, and
727/// as such, doesn't contain the array of TemplateArgumentLoc itself,
728/// but expects the containing object to also provide storage for
729/// that.
730struct alignas(void *) ASTTemplateKWAndArgsInfo {
731 /// The source location of the left angle bracket ('<').
733
734 /// The source location of the right angle bracket ('>').
736
737 /// The source location of the template keyword; this is used
738 /// as part of the representation of qualified identifiers, such as
739 /// S<T>::template apply<T>. Will be empty if this expression does
740 /// not have a template keyword.
742
743 /// The number of template arguments in TemplateArgs.
745
747 const TemplateArgumentListInfo &List,
748 TemplateArgumentLoc *OutArgArray);
749 // FIXME: The parameter Deps is the result populated by this method, the
750 // caller doesn't need it since it is populated by computeDependence. remove
751 // it.
753 const TemplateArgumentListInfo &List,
754 TemplateArgumentLoc *OutArgArray,
755 TemplateArgumentDependence &Deps);
757
758 void copyInto(const TemplateArgumentLoc *ArgArray,
759 TemplateArgumentListInfo &List) const;
760};
761
763 const TemplateArgument &Arg);
764
765} // namespace clang
766
767#endif // LLVM_CLANG_AST_TEMPLATEBASE_H
#define V(N, I)
Definition: ASTContext.h:3597
MatchType Type
StringRef P
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:126
static char ID
Definition: Arena.cpp:183
const Decl * D
Expr * E
llvm::APSInt APSInt
Definition: Compiler.cpp:23
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
SourceLocation Loc
Definition: SemaObjC.cpp:754
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
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:188
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1874
This represents one expression.
Definition: Expr.h:112
A C++ nested-name-specifier augmented with source location information.
A (possibly-)qualified type.
Definition: TypeBase.h:937
static QualType getFromOpaquePtr(const void *Ptr)
Definition: TypeBase.h:986
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:634
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:650
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:652
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:653
TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
Definition: TemplateBase.h:642
const TemplateArgumentLoc * getArgumentArray() const
Definition: TemplateBase.h:657
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:669
ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:661
const TemplateArgumentLoc & operator[](unsigned I) const
Definition: TemplateBase.h:663
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:649
TemplateArgumentLoc & operator[](unsigned I)
Definition: TemplateBase.h:667
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:528
SourceLocation getLocation() const
Definition: TemplateBase.h:563
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:625
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:535
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:618
SourceLocation getTemplateKWLoc() const
Definition: TemplateBase.h:609
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:578
TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
Definition: TemplateBase.h:539
Expr * getSourceNullPtrExpression() const
Definition: TemplateBase.h:594
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
Definition: TemplateBase.h:544
SourceRange getSourceRange() const LLVM_READONLY
Expr * getSourceDeclExpression() const
Definition: TemplateBase.h:589
Expr * getSourceExpression() const
Definition: TemplateBase.h:584
NestedNameSpecifierLoc getTemplateQualifierLoc() const
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:452
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:402
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:218
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:334
TemplateArgument(QualType T, bool isNullPtr=false, bool IsDefaulted=false)
Construct a template type argument.
Definition: TemplateBase.h:196
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:411
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:279
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
Definition: TemplateBase.h:433
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
Definition: TemplateBase.h:192
TemplateArgument(TemplateName Name, UnsignedOrNone NumExpansions, bool IsDefaulted=false)
Construct a template argument that is a template pack expansion.
Definition: TemplateBase.h:255
void setIntegralType(QualType T)
Definition: TemplateBase.h:385
TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted=false)
Construct a template argument that refers to a (non-dependent) declaration.
Definition: TemplateBase.h:203
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:426
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
bool isConceptOrConceptTemplateParameter() const
void dump() const
Debugging aid that dumps the template argument to standard error.
Definition: ASTDumper.cpp:387
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:322
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:366
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:340
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:346
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 IsCanonical, 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:299
static TemplateArgument getEmptyPack()
Definition: TemplateBase.h:286
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:446
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:380
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:396
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:329
TemplateArgument(TemplateName Name, bool IsDefaulted=false)
Construct a template argument that is a template.
Definition: TemplateBase.h:234
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:440
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:296
TemplateArgumentDependence getDependence() const
bool isCanonicalExpr() const
Definition: TemplateBase.h:416
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:353
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:399
void setIsDefaulted(bool v)
Set to 'true' if this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:392
Represents a C++ template name within the type system.
Definition: TemplateName.h:222
static TemplateName getFromVoidPointer(void *Ptr)
Build a template name from a void pointer.
Definition: TemplateName.h:401
A container of type source information.
Definition: TypeBase.h:8314
The base class of the type hierarchy.
Definition: TypeBase.h:1833
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:711
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:678
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:693
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Definition: TemplateBase.h:702
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:690
const TemplateArgumentLoc & operator[](unsigned I) const
Definition: TemplateBase.h:711
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:698
ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:707
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:696
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:699
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:730
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:732
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:744
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:735
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Definition: TemplateBase.h:741
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
Location information for a TemplateArgument.
Definition: TemplateBase.h:480
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
SourceLocation getTemplateKwLoc() const
Definition: TemplateBase.h:509
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:503
TemplateArgumentLocInfo(TypeSourceInfo *Declarator)
Definition: TemplateBase.h:493
TemplateTemplateArgLocInfo * getTemplate() const
Definition: TemplateBase.h:488
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