clang 24.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.
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.
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
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 StringRef getKindName() const;
299
300 /// Determine whether this template argument has no value.
301 bool isNull() const { return getKind() == Null; }
302
303 TemplateArgumentDependence getDependence() const;
304
305 /// Whether this template argument is dependent on a template
306 /// parameter such that its result can change from one instantiation to
307 /// another.
308 bool isDependent() const;
309
310 /// Whether this template argument is dependent on a template
311 /// parameter.
312 bool isInstantiationDependent() const;
313
314 /// Whether this template argument contains an unexpanded
315 /// parameter pack.
317
318 /// Determine whether this template argument is a pack expansion.
319 bool isPackExpansion() const;
320
322
323 /// Retrieve the type for a type template argument.
325 assert(getKind() == Type && "Unexpected kind");
326 return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
327 }
328
329 /// Retrieve the declaration for a declaration non-type
330 /// template argument.
332 assert(getKind() == Declaration && "Unexpected kind");
333 return DeclArg.D;
334 }
335
337 assert(getKind() == Declaration && "Unexpected kind");
339 }
340
341 /// Retrieve the type for null non-type template argument.
343 assert(getKind() == NullPtr && "Unexpected kind");
344 return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
345 }
346
347 /// Retrieve the template name for a template name argument.
349 assert(getKind() == Template && "Unexpected kind");
351 }
352
353 /// Retrieve the template argument as a template name; if the argument
354 /// is a pack expansion, return the pattern as a template name.
356 assert((getKind() == Template || getKind() == TemplateExpansion) &&
357 "Unexpected kind");
358
360 }
361
362 /// Retrieve the number of expansions that a template template argument
363 /// expansion will produce, if known.
365
366 /// Retrieve the template argument as an integral value.
367 // FIXME: Provide a way to read the integral data without copying the value.
368 llvm::APSInt getAsIntegral() const {
369 assert(getKind() == Integral && "Unexpected kind");
370
371 using namespace llvm;
372
373 if (Integer.BitWidth <= 64)
374 return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
375
376 unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
377 return APSInt(APInt(Integer.BitWidth, ArrayRef(Integer.pVal, NumWords)),
378 Integer.IsUnsigned);
379 }
380
381 /// Retrieve the type of the integral value.
383 assert(getKind() == Integral && "Unexpected kind");
385 }
386
388 assert(getKind() == Integral && "Unexpected kind");
389 Integer.Type = T.getAsOpaquePtr();
390 }
391
392 /// Set to 'true' if this TemplateArgument corresponds to a
393 /// default template parameter.
394 void setIsDefaulted(bool v) { TypeOrValue.IsDefaulted = v; }
395
396 /// If returns 'true', this TemplateArgument corresponds to a
397 /// default template parameter.
398 bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
399
400 /// Get the value of a StructuralValue.
401 const APValue &getAsStructuralValue() const { return *Value.Value; }
402
403 /// Get the type of a StructuralValue.
407
408 /// If this is a non-type template argument, get its type. Otherwise,
409 /// returns a null QualType.
411
412 /// Retrieve the template argument as an expression.
413 Expr *getAsExpr() const {
414 assert(getKind() == Expression && "Unexpected kind");
415 return reinterpret_cast<Expr *>(TypeOrValue.V);
416 }
417
418 bool isCanonicalExpr() const {
419 assert(getKind() == Expression && "Unexpected kind");
420 return TypeOrValue.IsCanonicalExpr;
421 }
422
423 /// Iterator that traverses the elements of a template argument pack.
425
426 /// Iterator referencing the first argument of a template argument
427 /// pack.
429 assert(getKind() == Pack);
430 return Args.Args;
431 }
432
433 /// Iterator referencing one past the last argument of a template
434 /// argument pack.
436 assert(getKind() == Pack);
437 return Args.Args + Args.NumArgs;
438 }
439
440 /// Iterator range referencing all of the elements of a template
441 /// argument pack.
445
446 /// The number of template arguments in the given template argument
447 /// pack.
448 unsigned pack_size() const {
449 assert(getKind() == Pack);
450 return Args.NumArgs;
451 }
452
453 /// Return the array of arguments in this template argument pack.
455 assert(getKind() == Pack);
456 return {Args.Args, Args.NumArgs};
457 }
458
459 /// Determines whether two template arguments are superficially the
460 /// same.
461 bool structurallyEquals(const TemplateArgument &Other) const;
462
463 /// When the template argument is a pack expansion, returns
464 /// the pattern of the pack expansion.
466
467 /// Print this template argument to the given output stream.
468 void print(const PrintingPolicy &Policy, raw_ostream &Out,
469 bool IncludeType) const;
470
471 /// Debugging aid that dumps the template argument.
472 void dump(raw_ostream &Out, const ASTContext &Context) const;
473
474 /// Debugging aid that dumps the template argument to standard error.
475 void dump() const;
476
477 /// Used to insert TemplateArguments into FoldingSets.
478 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
479};
480
481/// Location information for a TemplateArgument.
489
493
496
497 TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
498
499 // For trivial source locations for converted template argument kinds.
501
502 // Ctx is used for allocation -- this case is unusually large and also rare,
503 // so we store the payload out-of-line.
505 NestedNameSpecifierLoc QualifierLoc,
506 SourceLocation TemplateNameLoc,
507 SourceLocation EllipsisLoc);
508
510 return cast<TypeSourceInfo *>(Pointer);
511 }
512
513 Expr *getAsExpr() const { return cast<Expr *>(Pointer); }
514
518
522
526
527 bool isNull() const { return Pointer.isNull(); }
528
529 bool isTrivial() const { return isa<LocOrPointer>(Pointer); }
530
532 auto *P = cast<LocOrPointer>(Pointer);
533 if constexpr (EmbedLocInPointer)
535 (reinterpret_cast<uintptr_t>(P) >> LowBitsRequired) - 1u);
536 else
537 return *static_cast<SourceLocation *>(P);
538 }
539
540private:
541 static constexpr bool EmbedLocInPointer = sizeof(void *) >
542 sizeof(SourceLocation);
543 using LocOrPointer =
544 std::conditional_t<EmbedLocInPointer, void, SourceLocation> *;
545 llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *,
546 LocOrPointer>
547 Pointer;
548 static constexpr unsigned LowBitsRequired = 2;
549};
550
551/// Location wrapper for a TemplateArgument. TemplateArgument is to
552/// TemplateArgumentLoc as Type is to TypeLoc.
554 TemplateArgument Argument;
556
557public:
559
562 : Argument(Argument), LocInfo(Opaque) {
563 switch (Argument.getKind()) {
564 case TemplateArgument::Null:
565 assert(Opaque.isNull());
566 return;
567 case TemplateArgument::Pack:
568 assert(Opaque.isTrivial());
569 return;
570 case TemplateArgument::NullPtr:
571 case TemplateArgument::Integral:
572 case TemplateArgument::Declaration:
573 case TemplateArgument::StructuralValue:
574 assert(Opaque.isTrivial() || Opaque.getAsExpr() != nullptr);
575 return;
576 case TemplateArgument::Expression:
577 assert(Opaque.getAsExpr() != nullptr);
578 return;
579 case TemplateArgument::Type:
580 assert(Opaque.getAsTypeSourceInfo() != nullptr);
581 return;
582 case TemplateArgument::Template:
583 case TemplateArgument::TemplateExpansion:
584 assert(Opaque.getTemplate() != nullptr);
585 return;
586 }
587 llvm_unreachable("Unknown TemplateArgument kind");
588 }
589
591 : Argument(Argument), LocInfo(TInfo) {
592 assert(Argument.getKind() == TemplateArgument::Type);
593 assert(TInfo != nullptr);
594 }
595
597 : Argument(Argument), LocInfo(E) {
598 assert(E != nullptr);
599 // Permit any kind of template argument that can be represented with an
600 // expression.
601 assert(Argument.getKind() == TemplateArgument::NullPtr ||
602 Argument.getKind() == TemplateArgument::Integral ||
603 Argument.getKind() == TemplateArgument::Declaration ||
604 Argument.getKind() == TemplateArgument::StructuralValue ||
605 Argument.getKind() == TemplateArgument::Expression);
606 }
607
608 TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument,
609 SourceLocation TemplateKWLoc,
610 NestedNameSpecifierLoc QualifierLoc,
611 SourceLocation TemplateNameLoc,
612 SourceLocation EllipsisLoc = SourceLocation());
613
614 /// - Fetches the primary location of the argument.
616 if (Argument.getKind() == TemplateArgument::Template ||
617 Argument.getKind() == TemplateArgument::TemplateExpansion)
618 return getTemplateNameLoc();
619
620 return getSourceRange().getBegin();
621 }
622
623 /// - Fetches the full source range of the argument.
624 SourceRange getSourceRange() const LLVM_READONLY;
625
626 const TemplateArgument &getArgument() const { return Argument; }
627
628 TemplateArgumentLocInfo getLocInfo() const { return LocInfo; }
629
631 if (Argument.getKind() != TemplateArgument::Type)
632 return nullptr;
633 return LocInfo.getAsTypeSourceInfo();
634 }
635
637 assert(Argument.getKind() == TemplateArgument::Expression);
638 return LocInfo.getAsExpr();
639 }
640
642 assert(Argument.getKind() == TemplateArgument::Declaration);
643 return LocInfo.getAsExpr();
644 }
645
647 assert(Argument.getKind() == TemplateArgument::NullPtr);
648 return LocInfo.getAsExpr();
649 }
650
652 assert(Argument.getKind() == TemplateArgument::Integral);
653 return LocInfo.getAsExpr();
654 }
655
657 assert(Argument.getKind() == TemplateArgument::StructuralValue);
658 return LocInfo.getAsExpr();
659 }
660
662 if (Argument.getKind() != TemplateArgument::Template &&
663 Argument.getKind() != TemplateArgument::TemplateExpansion)
664 return SourceLocation();
665 return LocInfo.getTemplateKwLoc();
666 }
667
669
671 if (Argument.getKind() != TemplateArgument::Template &&
672 Argument.getKind() != TemplateArgument::TemplateExpansion)
673 return SourceLocation();
674 return LocInfo.getTemplateNameLoc();
675 }
676
678 if (Argument.getKind() != TemplateArgument::TemplateExpansion)
679 return SourceLocation();
680 return LocInfo.getTemplateEllipsisLoc();
681 }
682};
683
684/// A convenient class for passing around template argument
685/// information. Designed to be passed by reference.
688 SourceLocation LAngleLoc;
689 SourceLocation RAngleLoc;
690
691public:
693
695 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
696
697 // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
698 // instead.
699 void *operator new(size_t bytes, ASTContext &C) = delete;
700
701 SourceLocation getLAngleLoc() const { return LAngleLoc; }
702 SourceLocation getRAngleLoc() const { return RAngleLoc; }
703
704 void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
705 void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
706
707 unsigned size() const { return Arguments.size(); }
708
710 return Arguments.data();
711 }
712
713 ArrayRef<TemplateArgumentLoc> arguments() const { return Arguments; }
714
715 const TemplateArgumentLoc &operator[](unsigned I) const {
716 return Arguments[I];
717 }
718
719 TemplateArgumentLoc &operator[](unsigned I) { return Arguments[I]; }
720
721 void addArgument(const TemplateArgumentLoc &Loc) { Arguments.push_back(Loc); }
722};
723
724/// Represents an explicit template argument list in C++, e.g.,
725/// the "<int>" in "sort<int>".
726/// This is safe to be used inside an AST node, in contrast with
727/// TemplateArgumentListInfo.
728struct ASTTemplateArgumentListInfo final
729 : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
730 TemplateArgumentLoc> {
731private:
732 friend class ASTNodeImporter;
733 friend TrailingObjects;
734
735 ASTTemplateArgumentListInfo(const TemplateArgumentListInfo &List);
736
737 // FIXME: Is it ever necessary to copy to another context?
738 ASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *List);
739
740public:
741 /// The source location of the left angle bracket ('<').
743
744 /// The source location of the right angle bracket ('>').
746
747 /// The number of template arguments in TemplateArgs.
749
752
753 /// Retrieve the template arguments
755 return getTrailingObjects();
756 }
757 unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
758
762
763 const TemplateArgumentLoc &operator[](unsigned I) const {
764 return getTemplateArgs()[I];
765 }
766
767 static const ASTTemplateArgumentListInfo *
768 Create(const ASTContext &C, const TemplateArgumentListInfo &List);
769
770 // FIXME: Is it ever necessary to copy to another context?
771 static const ASTTemplateArgumentListInfo *
772 Create(const ASTContext &C, const ASTTemplateArgumentListInfo *List);
773};
774
775/// Represents an explicit template argument list in C++, e.g.,
776/// the "<int>" in "sort<int>".
777///
778/// It is intended to be used as a trailing object on AST nodes, and
779/// as such, doesn't contain the array of TemplateArgumentLoc itself,
780/// but expects the containing object to also provide storage for
781/// that.
782struct alignas(void *) ASTTemplateKWAndArgsInfo {
783 /// The source location of the left angle bracket ('<').
785
786 /// The source location of the right angle bracket ('>').
788
789 /// The source location of the template keyword; this is used
790 /// as part of the representation of qualified identifiers, such as
791 /// S<T>::template apply<T>. Will be empty if this expression does
792 /// not have a template keyword.
794
795 /// The number of template arguments in TemplateArgs.
797
799 const TemplateArgumentListInfo &List,
800 TemplateArgumentLoc *OutArgArray);
801 // FIXME: The parameter Deps is the result populated by this method, the
802 // caller doesn't need it since it is populated by computeDependence. remove
803 // it.
805 const TemplateArgumentListInfo &List,
806 TemplateArgumentLoc *OutArgArray,
807 TemplateArgumentDependence &Deps);
809
810 void copyInto(const TemplateArgumentLoc *ArgArray,
811 TemplateArgumentListInfo &List) const;
812};
813
815 const TemplateArgument &Arg);
816
817} // namespace clang
818
819#endif // LLVM_CLANG_AST_TEMPLATEBASE_H
#define V(N, I)
static StringRef bytes(const std::vector< T, Allocator > &v)
llvm::APSInt APSInt
Definition Compiler.cpp:25
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.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
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:223
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:2001
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:938
static QualType getFromOpaquePtr(const void *Ptr)
Definition TypeBase.h:987
Encodes a location in the source.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
A convenient class for passing around template argument information.
SourceLocation getRAngleLoc() const
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
const TemplateArgumentLoc * getArgumentArray() const
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
const TemplateArgumentLoc & operator[](unsigned I) const
SourceLocation getLAngleLoc() const
TemplateArgumentLoc & operator[](unsigned I)
Location wrapper for a TemplateArgument.
SourceLocation getLocation() const
SourceLocation getTemplateEllipsisLoc() const
Expr * getSourceStructuralValueExpression() const
Expr * getSourceIntegralExpression() const
TemplateArgumentLocInfo getLocInfo() const
const TemplateArgument & getArgument() const
TemplateArgumentLoc(const TemplateArgument &Argument, TemplateArgumentLocInfo Opaque)
SourceLocation getTemplateNameLoc() const
SourceLocation getTemplateKWLoc() const
TypeSourceInfo * getTypeSourceInfo() const
TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
Expr * getSourceNullPtrExpression() const
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
SourceRange getSourceRange() const LLVM_READONLY
Expr * getSourceDeclExpression() const
Expr * getSourceExpression() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
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.
TemplateArgument(const TemplateArgument &Other, QualType Type)
Construct an integral constant template argument with the same value as Other but a different type.
QualType getParamTypeForDecl() const
TemplateArgument(QualType T, bool isNullPtr=false, bool IsDefaulted=false)
Construct a template type argument.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
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.
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
TemplateArgument(TemplateName Name, UnsignedOrNone NumExpansions, bool IsDefaulted=false)
Construct a template argument that is a template pack expansion.
void setIntegralType(QualType T)
TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted=false)
Construct a template argument that refers to a (non-dependent) declaration.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
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
StringRef getKindName() const
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.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
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.
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.
bool isNull() const
Determine whether this template argument has no value.
static TemplateArgument getEmptyPack()
unsigned pack_size() const
The number of template arguments in the given template argument pack.
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.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
TemplateArgument(TemplateName Name, bool IsDefaulted=false)
Construct a template argument that is a template.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
ArgKind
The kind of template argument we're storing.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
TemplateArgumentDependence getDependence() const
bool isCanonicalExpr() 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,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
void setIsDefaulted(bool v)
Set to 'true' if this TemplateArgument corresponds to a default template parameter.
Represents a C++ template name within the type system.
static TemplateName getFromVoidPointer(void *Ptr)
Build a template name from a void pointer.
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
A container of type source information.
Definition TypeBase.h:8472
The base class of the type hierarchy.
Definition TypeBase.h:1876
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isNullPtr(const clang::Expr *E)
Definition ASTUtils.cpp:287
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Other
Other implicit parameter.
Definition Decl.h:1774
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>".
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
const TemplateArgumentLoc & operator[](unsigned I) const
SourceLocation getLAngleLoc() const
ArrayRef< TemplateArgumentLoc > arguments() const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
SourceLocation getRAngleLoc() const
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Describes how types, statements, expressions, and declarations should be printed.
Location information for a TemplateArgument.
SourceLocation getTemplateEllipsisLoc() const
SourceLocation getTemplateKwLoc() const
SourceLocation getTrivialLoc() const
TypeSourceInfo * getAsTypeSourceInfo() const
TemplateArgumentLocInfo(TypeSourceInfo *Declarator)
TemplateTemplateArgLocInfo * getTemplate() const
SourceLocation getTemplateNameLoc() const
static void * getAsVoidPointer(clang::Expr *P)
static clang::Expr * getFromVoidPointer(void *P)