clang: include/clang/AST/TemplateBase.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_AST_TEMPLATEBASE_H
15#define LLVM_CLANG_AST_TEMPLATEBASE_H
16
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
30#include
31#include
32#include
33
34namespace llvm {
35
36class FoldingSetNodeID;
37
38
39
40
45 }
46 static constexpr int NumLowBitsAvailable = 2;
47};
48
49}
50
52
53class APValue;
54class ASTContext;
55class Expr;
56struct PrintingPolicy;
57class TypeSourceInfo;
58class ValueDecl;
59
60
62public:
63
65
66
68
69
71
72
73
75
76
77
79
80
81
83
84
85
86
87
88
90
91
92
94
95
96
98
99
100
101
102
104
105
106
109
110private:
111
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;
120 };
121 struct I {
122 LLVM_PREFERRED_TYPE(ArgKind)
123 unsigned Kind : 31;
124 LLVM_PREFERRED_TYPE(bool)
125 unsigned IsDefaulted : 1;
126
127
128
129 unsigned BitWidth : 31;
130 LLVM_PREFERRED_TYPE(bool)
131 unsigned IsUnsigned : 1;
132 union {
133
134 uint64_t VAL;
135
136
137 const uint64_t *pVal;
138 };
140 };
141 struct V {
142 LLVM_PREFERRED_TYPE(ArgKind)
143 unsigned Kind : 31;
144 LLVM_PREFERRED_TYPE(bool)
145 unsigned IsDefaulted : 1;
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;
156 };
157 struct TA {
158 LLVM_PREFERRED_TYPE(ArgKind)
159 unsigned Kind : 31;
160 LLVM_PREFERRED_TYPE(bool)
161 unsigned IsDefaulted : 1;
162 unsigned NumExpansions;
163 void *Name;
164 };
165 struct TV {
166 LLVM_PREFERRED_TYPE(ArgKind)
167 unsigned Kind : 31;
168 LLVM_PREFERRED_TYPE(bool)
169 unsigned IsDefaulted : 1;
171 };
172 union {
179 };
180
181 void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
182 void initFromDeclaration(ValueDecl *D, QualType QT, bool IsDefaulted);
183 void initFromIntegral(const ASTContext &Ctx, const llvm::APSInt &Value,
186 const APValue &V, bool IsDefaulted);
187
188public:
189
191
192
194 bool IsDefaulted = false) {
195 initFromType(T, isNullPtr, IsDefaulted);
196 }
197
198
199
201 initFromDeclaration(D, QT, IsDefaulted);
202 }
203
204
205
208
209
211 bool IsDefaulted = false);
212
213
214
218 }
219
220
221
222
223
224
225
226
227
228
229
230
234 TemplateArg.Name = Name.getAsVoidPointer();
236 }
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
253 bool IsDefaulted = false) {
256 TemplateArg.Name = Name.getAsVoidPointer();
257 if (NumExpansions)
258 TemplateArg.NumExpansions = *NumExpansions + 1;
259 else
261 }
262
263
264
265
266
267
272 }
273
274
275
276
277
279 this->Args.Kind = Pack;
280 this->Args.IsDefaulted = false;
281 this->Args.Args = Args.data();
282 this->Args.NumArgs = Args.size();
283 }
284
287 }
288
289
290
293
294
296
297
299
300 TemplateArgumentDependence getDependence() const;
301
302
303
304
306
307
308
310
311
312
314
315
317
318
320 assert(getKind() == Type && "Unexpected kind");
322 }
323
324
325
329 }
330
334 }
335
336
340 }
341
342
346 }
347
348
349
352 "Unexpected kind");
353
355 }
356
357
358
360
361
362
365
366 using namespace llvm;
367
368 if (Integer.BitWidth <= 64)
370
371 unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
374 }
375
376
380 }
381
384 Integer.Type = T.getAsOpaquePtr();
385 }
386
387
388
390
391
392
394
395
397
398
401 }
402
403
404
406
407
411 }
412
413
415
416
417
420 return Args.Args;
421 }
422
423
424
427 return Args.Args + Args.NumArgs;
428 }
429
430
431
434 }
435
436
437
440 return Args.NumArgs;
441 }
442
443
447 }
448
449
450
452
453
454
456
457
459 bool IncludeType) const;
460
461
463
464
465 void dump() const;
466
467
468 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
469};
470
471
473private:
474 struct TemplateTemplateArgLocInfo {
475
476
478 void *QualifierLocData;
481 };
482
483 llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
484 Pointer;
485
486 TemplateTemplateArgLocInfo *getTemplate() const {
487 return cast<TemplateTemplateArgLocInfo *>(Pointer);
488 }
489
490public:
493
495
496
500
502 return cast<TypeSourceInfo *>(Pointer);
503 }
504
506
508 const auto *Template = getTemplate();
510 Template->QualifierLocData);
511 }
512
514 return getTemplate()->TemplateNameLoc;
515 }
516
518 return getTemplate()->EllipsisLoc;
519 }
520};
521
522
523
527
528public:
530
533 : Argument(Argument), LocInfo(Opaque) {}
534
536 : Argument(Argument), LocInfo(TInfo) {
538 }
539
541 : Argument(Argument), LocInfo(E) {
542
543
544
550 }
551
556 : Argument(Argument),
557 LocInfo(Ctx, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
560 }
561
562
567
569 }
570
571
573
575
577
580 return nullptr;
582 }
583
587 }
588
592 }
593
597 }
598
602 }
603
607 }
608
614 }
615
621 }
622
627 }
628};
629
630
631
636
637public:
639
641 : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
642
643
644
646
649
652
653 unsigned size() const { return Arguments.size(); }
654
656 return Arguments.data();
657 }
658
660
662 return Arguments[I];
663 }
664
666
668};
669
670
671
672
673
675 : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
676 TemplateArgumentLoc> {
677private:
679 friend TrailingObjects;
680
682
683
685
686public:
687
689
690
692
693
695
698
699
701 return getTrailingObjects();
702 }
704
707 }
708
711 }
712
715
716
719};
720
721
722
723
724
725
726
727
729
731
732
734
735
736
737
738
740
741
743
747
748
749
753 TemplateArgumentDependence &Deps);
755
758};
759
762
763}
764
765#endif
static StringRef bytes(const std::vector< T, Allocator > &v)
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],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Information about one declarator, including the parsed type information and the identifier.
This represents one expression.
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector::".
A (possibly-)qualified type.
static QualType getFromOpaquePtr(const void *Ptr)
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.
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)
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
TemplateArgumentListInfo()=default
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
TypeSourceInfo * getTypeSourceInfo() const
TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
Expr * getSourceNullPtrExpression() const
TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
SourceRange getSourceRange() const LLVM_READONLY
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Expr * getSourceDeclExpression() const
Expr * getSourceExpression() const
TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc=SourceLocation())
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.
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
constexpr TemplateArgument()
Construct an empty, invalid template argument.
void setIntegralType(QualType T)
TemplateArgument(TemplateName Name, std::optional< unsigned > NumExpansions, bool IsDefaulted=false)
Construct a template argument that is a template pack expansion.
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.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
void dump() const
Debugging aid that dumps the template argument to standard error.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
QualType getAsType() const
Retrieve the type for a type template argument.
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 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 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.
A container of type source information.
The base class of the type hierarchy.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
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.
__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 "" in "sort".
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
unsigned getNumTemplateArgs() const
llvm::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 "" in "sort".
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
NestedNameSpecifierLoc getTemplateQualifierLoc() const
TypeSourceInfo * getAsTypeSourceInfo() const
TemplateArgumentLocInfo(TypeSourceInfo *Declarator)
SourceLocation getTemplateNameLoc() const
TemplateArgumentLocInfo()
TemplateArgumentLocInfo(Expr *E)
static void * getAsVoidPointer(clang::Expr *P)
static clang::Expr * getFromVoidPointer(void *P)