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} // namespace llvm
39
40namespace clang {
41
42class APValue;
43class ASTContext;
44class Expr;
45struct PrintingPolicy;
46class TypeSourceInfo;
47class ValueDecl;
48
49/// Represents a template argument.
51public:
52 /// The kind of template argument we're storing.
53 enum ArgKind {
54 /// Represents an empty template argument, e.g., one that has not
55 /// been deduced.
56 Null = 0,
57
58 /// The template argument is a type.
60
61 /// The template argument is a declaration that was provided for a pointer,
62 /// reference, or pointer to member non-type template parameter.
64
65 /// The template argument is a null pointer or null pointer to member that
66 /// was provided for a non-type template parameter.
68
69 /// The template argument is an integral value stored in an llvm::APSInt
70 /// that was provided for an integral non-type template parameter.
72
73 /// The template argument is a non-type template argument that can't be
74 /// represented by the special-case Declaration, NullPtr, or Integral
75 /// forms. These values are only ever produced by constant evaluation,
76 /// so cannot be dependent.
77 /// TODO: merge Declaration, NullPtr and Integral into this?
79
80 /// The template argument is a template name that was provided for a
81 /// template template parameter.
83
84 /// The template argument is a pack expansion of a template name that was
85 /// provided for a template template parameter.
87
88 /// The template argument is an expression, and we've not resolved it to one
89 /// of the other forms yet, either because it's dependent or because we're
90 /// representing a non-canonical template argument (for instance, in a
91 /// TemplateSpecializationType).
93
94 /// The template argument is actually a parameter pack. Arguments are stored
95 /// in the Args struct.
97 };
98
99private:
100 /// The kind of template argument we're storing.
101
102 struct DA {
103 LLVM_PREFERRED_TYPE(ArgKind)
104 unsigned Kind : 31;
105 LLVM_PREFERRED_TYPE(bool)
106 unsigned IsDefaulted : 1;
107 void *QT;
108 ValueDecl *D;
109 };
110 struct I {
111 LLVM_PREFERRED_TYPE(ArgKind)
112 unsigned Kind : 31;
113 LLVM_PREFERRED_TYPE(bool)
114 unsigned IsDefaulted : 1;
115 // We store a decomposed APSInt with the data allocated by ASTContext if
116 // BitWidth > 64. The memory may be shared between multiple
117 // TemplateArgument instances.
118 unsigned BitWidth : 31;
119 LLVM_PREFERRED_TYPE(bool)
120 unsigned IsUnsigned : 1;
121 union {
122 /// Used to store the <= 64 bits integer value.
123 uint64_t VAL;
124
125 /// Used to store the >64 bits integer value.
126 const uint64_t *pVal;
127 };
128 void *Type;
129 };
130 struct V {
131 LLVM_PREFERRED_TYPE(ArgKind)
132 unsigned Kind : 31;
133 LLVM_PREFERRED_TYPE(bool)
134 unsigned IsDefaulted : 1;
135 APValue *Value;
136 void *Type;
137 };
138 struct A {
139 LLVM_PREFERRED_TYPE(ArgKind)
140 unsigned Kind : 31;
141 LLVM_PREFERRED_TYPE(bool)
142 unsigned IsDefaulted : 1;
143 unsigned NumArgs;
144 const TemplateArgument *Args;
145 };
146 struct TA {
147 LLVM_PREFERRED_TYPE(ArgKind)
148 unsigned Kind : 31;
149 LLVM_PREFERRED_TYPE(bool)
150 unsigned IsDefaulted : 1;
151 UnsignedOrNone NumExpansions;
152 void *Name;
153 };
154 struct TV {
155 LLVM_PREFERRED_TYPE(ArgKind)
156 unsigned Kind : 31;
157 LLVM_PREFERRED_TYPE(bool)
158 unsigned IsDefaulted : 1;
159 LLVM_PREFERRED_TYPE(bool)
160 unsigned IsCanonicalExpr : 1;
161 uintptr_t V;
162 };
163 union {
164 struct DA DeclArg;
165 struct I Integer;
166 struct V Value;
167 struct A Args;
168 struct TA TemplateArg;
169 struct TV TypeOrValue;
170 };
171
172 void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
173 void initFromDeclaration(ValueDecl *D, QualType QT, bool IsDefaulted);
174 void initFromIntegral(const ASTContext &Ctx, const llvm::APSInt &Value,
175 QualType Type, bool IsDefaulted);
176 void initFromStructural(const ASTContext &Ctx, QualType Type,
177 const APValue &V, bool IsDefaulted);
178
179public:
180 /// Construct an empty, invalid template argument.
182 : TypeOrValue{Null, /*IsDefaulted=*/0, /*IsCanonicalExpr=*/0, /*V=*/0} {}
183
184 /// Construct a template type argument.
186 bool IsDefaulted = false) {
187 initFromType(T, isNullPtr, IsDefaulted);
188 }
189
190 /// Construct a template argument that refers to a (non-dependent)
191 /// declaration.
192 TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
193 initFromDeclaration(D, QT, IsDefaulted);
194 }
195
196 /// Construct an integral constant template argument. The memory to
197 /// store the value is allocated with Ctx.
198 TemplateArgument(const ASTContext &Ctx, const llvm::APSInt &Value,
199 QualType Type, bool IsDefaulted = false);
200
201 /// Construct a template argument from an arbitrary constant value.
203 bool IsDefaulted = false);
204
205 /// Construct an integral constant template argument with the same
206 /// value as Other but a different type.
208 Integer = Other.Integer;
209 Integer.Type = Type.getAsOpaquePtr();
210 }
211
212 /// Construct a template argument that is a template.
213 ///
214 /// This form of template argument is generally used for template template
215 /// parameters. However, the template name could be a dependent template
216 /// name that ends up being instantiated to a function template whose address
217 /// is taken.
218 ///
219 /// \param Name The template name.
220 ///
221 /// \param IsDefaulted If 'true', implies that this TemplateArgument
222 /// corresponds to a default template parameter
223 TemplateArgument(TemplateName Name, bool IsDefaulted = false) {
224 TemplateArg.Kind = Template;
225 TemplateArg.IsDefaulted = IsDefaulted;
226 TemplateArg.Name = Name.getAsVoidPointer();
227 TemplateArg.NumExpansions = std::nullopt;
228 }
229
230 /// Construct a template argument that is a template pack expansion.
231 ///
232 /// This form of template argument is generally used for template template
233 /// parameters. However, the template name could be a dependent template
234 /// name that ends up being instantiated to a function template whose address
235 /// is taken.
236 ///
237 /// \param Name The template name.
238 ///
239 /// \param NumExpansions The number of expansions that will be generated by
240 /// instantiating
241 ///
242 /// \param IsDefaulted If 'true', implies that this TemplateArgument
243 /// corresponds to a default template parameter
245 bool IsDefaulted = false) {
247 TemplateArg.IsDefaulted = IsDefaulted;
248 TemplateArg.Name = Name.getAsVoidPointer();
249 TemplateArg.NumExpansions = NumExpansions;
250 }
251
252 /// Construct a template argument that is an expression.
253 ///
254 /// This form of template argument only occurs in template argument
255 /// lists used for dependent types and for expression; it will not
256 /// occur in a non-dependent, canonical template argument list.
257 TemplateArgument(Expr *E, bool IsCanonical, bool IsDefaulted = false) {
258 TypeOrValue.Kind = Expression;
259 TypeOrValue.IsDefaulted = IsDefaulted;
260 TypeOrValue.IsCanonicalExpr = IsCanonical;
261 TypeOrValue.V = reinterpret_cast<uintptr_t>(E);
262 }
263
264 /// Construct a template argument that is a template argument pack.
265 ///
266 /// We assume that storage for the template arguments provided
267 /// outlives the TemplateArgument itself.
269 this->Args.Kind = Pack;
270 this->Args.IsDefaulted = false;
271 this->Args.Args = Args.data();
272 this->Args.NumArgs = Args.size();
273 }
274
278
279 /// Create a new template argument pack by copying the given set of
280 /// template arguments.
283
284 /// Return the kind of stored template argument.
285 ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; }
286
287 StringRef getKindName() const;
288
289 /// Determine whether this template argument has no value.
290 bool isNull() const { return getKind() == Null; }
291
292 TemplateArgumentDependence getDependence() const;
293
294 /// Whether this template argument is dependent on a template
295 /// parameter such that its result can change from one instantiation to
296 /// another.
297 bool isDependent() const;
298
299 /// Whether this template argument is dependent on a template
300 /// parameter.
301 bool isInstantiationDependent() const;
302
303 /// Whether this template argument contains an unexpanded
304 /// parameter pack.
306
307 /// Determine whether this template argument is a pack expansion.
308 bool isPackExpansion() const;
309
311
312 /// Retrieve the type for a type template argument.
314 assert(getKind() == Type && "Unexpected kind");
315 return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
316 }
317
318 /// Retrieve the declaration for a declaration non-type
319 /// template argument.
321 assert(getKind() == Declaration && "Unexpected kind");
322 return DeclArg.D;
323 }
324
326 assert(getKind() == Declaration && "Unexpected kind");
328 }
329
330 /// Retrieve the type for null non-type template argument.
332 assert(getKind() == NullPtr && "Unexpected kind");
333 return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
334 }
335
336 /// Retrieve the template name for a template name argument.
338 assert(getKind() == Template && "Unexpected kind");
340 }
341
342 /// Retrieve the template argument as a template name; if the argument
343 /// is a pack expansion, return the pattern as a template name.
345 assert((getKind() == Template || getKind() == TemplateExpansion) &&
346 "Unexpected kind");
347
349 }
350
351 /// Retrieve the number of expansions that a template template argument
352 /// expansion will produce, if known.
354
355 /// Retrieve the template argument as an integral value.
356 // FIXME: Provide a way to read the integral data without copying the value.
357 llvm::APSInt getAsIntegral() const {
358 assert(getKind() == Integral && "Unexpected kind");
359
360 using namespace llvm;
361
362 if (Integer.BitWidth <= 64)
363 return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
364
365 unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
366 return APSInt(APInt(Integer.BitWidth, ArrayRef(Integer.pVal, NumWords)),
367 Integer.IsUnsigned);
368 }
369
370 /// Retrieve the type of the integral value.
372 assert(getKind() == Integral && "Unexpected kind");
374 }
375
377 assert(getKind() == Integral && "Unexpected kind");
378 Integer.Type = T.getAsOpaquePtr();
379 }
380
381 /// Set to 'true' if this TemplateArgument corresponds to a
382 /// default template parameter.
383 void setIsDefaulted(bool v) { TypeOrValue.IsDefaulted = v; }
384
385 /// If returns 'true', this TemplateArgument corresponds to a
386 /// default template parameter.
387 bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
388
389 /// Get the value of a StructuralValue.
390 const APValue &getAsStructuralValue() const { return *Value.Value; }
391
392 /// Get the type of a StructuralValue.
396
397 /// If this is a non-type template argument, get its type. Otherwise,
398 /// returns a null QualType.
400
401 /// Retrieve the template argument as an expression.
402 Expr *getAsExpr() const {
403 assert(getKind() == Expression && "Unexpected kind");
404 return reinterpret_cast<Expr *>(TypeOrValue.V);
405 }
406
407 bool isCanonicalExpr() const {
408 assert(getKind() == Expression && "Unexpected kind");
409 return TypeOrValue.IsCanonicalExpr;
410 }
411
412 /// Iterator that traverses the elements of a template argument pack.
414
415 /// Iterator referencing the first argument of a template argument
416 /// pack.
418 assert(getKind() == Pack);
419 return Args.Args;
420 }
421
422 /// Iterator referencing one past the last argument of a template
423 /// argument pack.
425 assert(getKind() == Pack);
426 return Args.Args + Args.NumArgs;
427 }
428
429 /// Iterator range referencing all of the elements of a template
430 /// argument pack.
434
435 /// The number of template arguments in the given template argument
436 /// pack.
437 unsigned pack_size() const {
438 assert(getKind() == Pack);
439 return Args.NumArgs;
440 }
441
442 /// Return the array of arguments in this template argument pack.
444 assert(getKind() == Pack);
445 return {Args.Args, Args.NumArgs};
446 }
447
448 /// Determines whether two template arguments are superficially the
449 /// same.
450 bool structurallyEquals(const TemplateArgument &Other) const;
451
452 /// When the template argument is a pack expansion, returns
453 /// the pattern of the pack expansion.
455
456 /// Print this template argument to the given output stream.
457 void print(const PrintingPolicy &Policy, raw_ostream &Out,
458 bool IncludeType) const;
459
460 /// Debugging aid that dumps the template argument.
461 void dump(raw_ostream &Out, const ASTContext &Context) const;
462
463 /// Debugging aid that dumps the template argument to standard error.
464 void dump() const;
465
466 /// Used to insert TemplateArguments into FoldingSets.
467 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
468};
469
470/// Location information for a TemplateArgument.
478
482
485
486 TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
487
488 // For trivial source locations for converted template argument kinds.
490
491 // Ctx is used for allocation -- this case is unusually large and also rare,
492 // so we store the payload out-of-line.
494 NestedNameSpecifierLoc QualifierLoc,
495 SourceLocation TemplateNameLoc,
496 SourceLocation EllipsisLoc);
497
499 return cast<TypeSourceInfo *>(Pointer);
500 }
501
502 Expr *getAsExpr() const { return cast<Expr *>(Pointer); }
503
507
511
515
516 bool isNull() const { return Pointer.isNull(); }
517
518 bool isTrivial() const { return isa<LocOrPointer>(Pointer); }
519
521 auto *P = cast<LocOrPointer>(Pointer);
522 if constexpr (EmbedLocInPointer)
524 (reinterpret_cast<uintptr_t>(P) >> LowBitsRequired) - 1u);
525 else
526 return *static_cast<SourceLocation *>(P);
527 }
528
529private:
530 static constexpr bool EmbedLocInPointer = sizeof(void *) >
531 sizeof(SourceLocation);
532 using LocOrPointer =
533 std::conditional_t<EmbedLocInPointer, void, SourceLocation> *;
534 llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *,
535 LocOrPointer>
536 Pointer;
537 static constexpr unsigned LowBitsRequired = 2;
538};
539
540/// Location wrapper for a TemplateArgument. TemplateArgument is to
541/// TemplateArgumentLoc as Type is to TypeLoc.
543 TemplateArgument Argument;
545
546public:
548
551 : Argument(Argument), LocInfo(Opaque) {
552 switch (Argument.getKind()) {
553 case TemplateArgument::Null:
554 assert(Opaque.isNull());
555 return;
556 case TemplateArgument::Pack:
557 assert(Opaque.isTrivial());
558 return;
559 case TemplateArgument::NullPtr:
560 case TemplateArgument::Integral:
561 case TemplateArgument::Declaration:
562 case TemplateArgument::StructuralValue:
563 assert(Opaque.isTrivial() || Opaque.getAsExpr() != nullptr);
564 return;
565 case TemplateArgument::Expression:
566 assert(Opaque.getAsExpr() != nullptr);
567 return;
568 case TemplateArgument::Type:
569 assert(Opaque.getAsTypeSourceInfo() != nullptr);
570 return;
571 case TemplateArgument::Template:
572 case TemplateArgument::TemplateExpansion:
573 assert(Opaque.getTemplate() != nullptr);
574 return;
575 }
576 llvm_unreachable("Unknown TemplateArgument kind");
577 }
578
580 : Argument(Argument), LocInfo(TInfo) {
581 assert(Argument.getKind() == TemplateArgument::Type);
582 assert(TInfo != nullptr);
583 }
584
586 : Argument(Argument), LocInfo(E) {
587 assert(E != nullptr);
588 // Permit any kind of template argument that can be represented with an
589 // expression.
590 assert(Argument.getKind() == TemplateArgument::NullPtr ||
591 Argument.getKind() == TemplateArgument::Integral ||
592 Argument.getKind() == TemplateArgument::Declaration ||
593 Argument.getKind() == TemplateArgument::StructuralValue ||
594 Argument.getKind() == TemplateArgument::Expression);
595 }
596
597 TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument,
598 SourceLocation TemplateKWLoc,
599 NestedNameSpecifierLoc QualifierLoc,
600 SourceLocation TemplateNameLoc,
601 SourceLocation EllipsisLoc = SourceLocation());
602
603 /// - Fetches the primary location of the argument.
605 if (Argument.getKind() == TemplateArgument::Template ||
606 Argument.getKind() == TemplateArgument::TemplateExpansion)
607 return getTemplateNameLoc();
608
609 return getSourceRange().getBegin();
610 }
611
612 /// - Fetches the full source range of the argument.
613 SourceRange getSourceRange() const LLVM_READONLY;
614
615 const TemplateArgument &getArgument() const { return Argument; }
616
617 TemplateArgumentLocInfo getLocInfo() const { return LocInfo; }
618
620 if (Argument.getKind() != TemplateArgument::Type)
621 return nullptr;
622 return LocInfo.getAsTypeSourceInfo();
623 }
624
626 assert(Argument.getKind() == TemplateArgument::Expression);
627 return LocInfo.getAsExpr();
628 }
629
631 assert(Argument.getKind() == TemplateArgument::Declaration);
632 return LocInfo.getAsExpr();
633 }
634
636 assert(Argument.getKind() == TemplateArgument::NullPtr);
637 return LocInfo.getAsExpr();
638 }
639
641 assert(Argument.getKind() == TemplateArgument::Integral);
642 return LocInfo.getAsExpr();
643 }
644
646 assert(Argument.getKind() == TemplateArgument::StructuralValue);
647 return LocInfo.getAsExpr();
648 }
649
651 if (Argument.getKind() != TemplateArgument::Template &&
652 Argument.getKind() != TemplateArgument::TemplateExpansion)
653 return SourceLocation();
654 return LocInfo.getTemplateKwLoc();
655 }
656
658
660 if (Argument.getKind() != TemplateArgument::Template &&
661 Argument.getKind() != TemplateArgument::TemplateExpansion)
662 return SourceLocation();
663 return LocInfo.getTemplateNameLoc();
664 }
665
667 if (Argument.getKind() != TemplateArgument::TemplateExpansion)
668 return SourceLocation();
669 return LocInfo.getTemplateEllipsisLoc();
670 }
671};
672
673/// A convenient class for passing around template argument
674/// information. Designed to be passed by reference.
677 SourceLocation LAngleLoc;
678 SourceLocation RAngleLoc;
679
680public:
682
684 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
685
686 // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
687 // instead.
688 void *operator new(size_t bytes, ASTContext &C) = delete;
689
690 SourceLocation getLAngleLoc() const { return LAngleLoc; }
691 SourceLocation getRAngleLoc() const { return RAngleLoc; }
692
693 void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
694 void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
695
696 unsigned size() const { return Arguments.size(); }
697
699 return Arguments.data();
700 }
701
702 ArrayRef<TemplateArgumentLoc> arguments() const { return Arguments; }
703
704 const TemplateArgumentLoc &operator[](unsigned I) const {
705 return Arguments[I];
706 }
707
708 TemplateArgumentLoc &operator[](unsigned I) { return Arguments[I]; }
709
710 void addArgument(const TemplateArgumentLoc &Loc) { Arguments.push_back(Loc); }
711};
712
713/// Represents an explicit template argument list in C++, e.g.,
714/// the "<int>" in "sort<int>".
715/// This is safe to be used inside an AST node, in contrast with
716/// TemplateArgumentListInfo.
717struct ASTTemplateArgumentListInfo final
718 : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
719 TemplateArgumentLoc> {
720private:
721 friend class ASTNodeImporter;
722 friend TrailingObjects;
723
724 ASTTemplateArgumentListInfo(const TemplateArgumentListInfo &List);
725
726public:
727 /// The source location of the left angle bracket ('<').
729
730 /// The source location of the right angle bracket ('>').
732
733 /// The number of template arguments in TemplateArgs.
735
738
739 /// Retrieve the template arguments
741 return getTrailingObjects();
742 }
743 unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
744
748
749 const TemplateArgumentLoc &operator[](unsigned I) const {
750 return getTemplateArgs()[I];
751 }
752
753 static const ASTTemplateArgumentListInfo *
754 Create(const ASTContext &C, const TemplateArgumentListInfo &List);
755};
756
757/// Represents an explicit template argument list in C++, e.g.,
758/// the "<int>" in "sort<int>".
759///
760/// It is designed to be usable as a trailing object on AST nodes, and
761/// as such, doesn't contain the array of TemplateArgumentLoc itself,
762/// but expects the containing object to also provide storage for
763/// that.
764struct alignas(void *) ASTTemplateKWAndArgsInfo {
765 /// The source location of the left angle bracket ('<').
767
768 /// The source location of the right angle bracket ('>').
770
771 /// The source location of the template keyword; this is used
772 /// as part of the representation of qualified identifiers, such as
773 /// S<T>::template apply<T>. Will be empty if this expression does
774 /// not have a template keyword.
776
777 /// The number of template arguments in TemplateArgs.
779
781 const TemplateArgumentListInfo &List,
782 TemplateArgumentLoc *OutArgArray);
783 // FIXME: The parameter Deps is the result populated by this method, the
784 // caller doesn't need it since it is populated by computeDependence. remove
785 // it.
787 const TemplateArgumentListInfo &List,
788 TemplateArgumentLoc *OutArgArray,
789 TemplateArgumentDependence &Deps);
791
792 void copyInto(const TemplateArgumentLoc *ArgArray,
793 TemplateArgumentListInfo &List) const;
794};
795
797 const TemplateArgument &Arg);
798
799} // namespace clang
800
801#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.
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:1952
This represents one expression.
Definition Expr.h:113
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:8473
The base class of the type hierarchy.
Definition TypeBase.h:1879
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Top level wrappers for InstallAPI frontend operations.
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