/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/DeclTemplate.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- DeclTemplate.h - Classes for representing 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 | | /// \file |
10 | | /// Defines the C++ template declaration subclasses. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #ifndef LLVM_CLANG_AST_DECLTEMPLATE_H |
15 | | #define LLVM_CLANG_AST_DECLTEMPLATE_H |
16 | | |
17 | | #include "clang/AST/ASTConcept.h" |
18 | | #include "clang/AST/ASTContext.h" |
19 | | #include "clang/AST/Decl.h" |
20 | | #include "clang/AST/DeclBase.h" |
21 | | #include "clang/AST/DeclCXX.h" |
22 | | #include "clang/AST/DeclarationName.h" |
23 | | #include "clang/AST/Redeclarable.h" |
24 | | #include "clang/AST/TemplateBase.h" |
25 | | #include "clang/AST/Type.h" |
26 | | #include "clang/Basic/LLVM.h" |
27 | | #include "clang/Basic/SourceLocation.h" |
28 | | #include "clang/Basic/Specifiers.h" |
29 | | #include "llvm/ADT/ArrayRef.h" |
30 | | #include "llvm/ADT/FoldingSet.h" |
31 | | #include "llvm/ADT/PointerIntPair.h" |
32 | | #include "llvm/ADT/PointerUnion.h" |
33 | | #include "llvm/ADT/iterator.h" |
34 | | #include "llvm/ADT/iterator_range.h" |
35 | | #include "llvm/Support/Casting.h" |
36 | | #include "llvm/Support/Compiler.h" |
37 | | #include "llvm/Support/TrailingObjects.h" |
38 | | #include <cassert> |
39 | | #include <cstddef> |
40 | | #include <cstdint> |
41 | | #include <iterator> |
42 | | #include <utility> |
43 | | |
44 | | namespace clang { |
45 | | |
46 | | enum BuiltinTemplateKind : int; |
47 | | class ClassTemplateDecl; |
48 | | class ClassTemplatePartialSpecializationDecl; |
49 | | class Expr; |
50 | | class FunctionTemplateDecl; |
51 | | class IdentifierInfo; |
52 | | class NonTypeTemplateParmDecl; |
53 | | class TemplateDecl; |
54 | | class TemplateTemplateParmDecl; |
55 | | class TemplateTypeParmDecl; |
56 | | class ConceptDecl; |
57 | | class UnresolvedSetImpl; |
58 | | class VarTemplateDecl; |
59 | | class VarTemplatePartialSpecializationDecl; |
60 | | |
61 | | /// Stores a template parameter of any kind. |
62 | | using TemplateParameter = |
63 | | llvm::PointerUnion<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, |
64 | | TemplateTemplateParmDecl *>; |
65 | | |
66 | | NamedDecl *getAsNamedDecl(TemplateParameter P); |
67 | | |
68 | | /// Stores a list of template parameters for a TemplateDecl and its |
69 | | /// derived classes. |
70 | | class TemplateParameterList final |
71 | | : private llvm::TrailingObjects<TemplateParameterList, NamedDecl *, |
72 | | Expr *> { |
73 | | /// The location of the 'template' keyword. |
74 | | SourceLocation TemplateLoc; |
75 | | |
76 | | /// The locations of the '<' and '>' angle brackets. |
77 | | SourceLocation LAngleLoc, RAngleLoc; |
78 | | |
79 | | /// The number of template parameters in this template |
80 | | /// parameter list. |
81 | | unsigned NumParams : 29; |
82 | | |
83 | | /// Whether this template parameter list contains an unexpanded parameter |
84 | | /// pack. |
85 | | unsigned ContainsUnexpandedParameterPack : 1; |
86 | | |
87 | | /// Whether this template parameter list has a requires clause. |
88 | | unsigned HasRequiresClause : 1; |
89 | | |
90 | | /// Whether any of the template parameters has constrained-parameter |
91 | | /// constraint-expression. |
92 | | unsigned HasConstrainedParameters : 1; |
93 | | |
94 | | protected: |
95 | | TemplateParameterList(const ASTContext& C, SourceLocation TemplateLoc, |
96 | | SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params, |
97 | | SourceLocation RAngleLoc, Expr *RequiresClause); |
98 | | |
99 | 7.67k | size_t numTrailingObjects(OverloadToken<NamedDecl *>) const { |
100 | 7.67k | return NumParams; |
101 | 7.67k | } |
102 | | |
103 | 0 | size_t numTrailingObjects(OverloadToken<Expr *>) const { |
104 | 0 | return HasRequiresClause ? 1 : 0; |
105 | 0 | } |
106 | | |
107 | | public: |
108 | | template <size_t N, bool HasRequiresClause> |
109 | | friend class FixedSizeTemplateParameterListStorage; |
110 | | friend TrailingObjects; |
111 | | |
112 | | static TemplateParameterList *Create(const ASTContext &C, |
113 | | SourceLocation TemplateLoc, |
114 | | SourceLocation LAngleLoc, |
115 | | ArrayRef<NamedDecl *> Params, |
116 | | SourceLocation RAngleLoc, |
117 | | Expr *RequiresClause); |
118 | | |
119 | | /// Iterates through the template parameters in this list. |
120 | | using iterator = NamedDecl **; |
121 | | |
122 | | /// Iterates through the template parameters in this list. |
123 | | using const_iterator = NamedDecl * const *; |
124 | | |
125 | 59.7M | iterator begin() { return getTrailingObjects<NamedDecl *>(); } |
126 | 18.0M | const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); } |
127 | 17.5M | iterator end() { return begin() + NumParams; } |
128 | 3.26M | const_iterator end() const { return begin() + NumParams; } |
129 | | |
130 | 69.9M | unsigned size() const { return NumParams; } |
131 | | |
132 | 235k | ArrayRef<NamedDecl*> asArray() { |
133 | 235k | return llvm::makeArrayRef(begin(), end()); |
134 | 235k | } |
135 | 5.04M | ArrayRef<const NamedDecl*> asArray() const { |
136 | 5.04M | return llvm::makeArrayRef(begin(), size()); |
137 | 5.04M | } |
138 | | |
139 | 19.8M | NamedDecl* getParam(unsigned Idx) { |
140 | 19.8M | assert(Idx < size() && "Template parameter index out-of-range"); |
141 | 0 | return begin()[Idx]; |
142 | 19.8M | } |
143 | 6.48M | const NamedDecl* getParam(unsigned Idx) const { |
144 | 6.48M | assert(Idx < size() && "Template parameter index out-of-range"); |
145 | 0 | return begin()[Idx]; |
146 | 6.48M | } |
147 | | |
148 | | /// Returns the minimum number of arguments needed to form a |
149 | | /// template specialization. |
150 | | /// |
151 | | /// This may be fewer than the number of template parameters, if some of |
152 | | /// the parameters have default arguments or if there is a parameter pack. |
153 | | unsigned getMinRequiredArguments() const; |
154 | | |
155 | | /// Get the depth of this template parameter list in the set of |
156 | | /// template parameter lists. |
157 | | /// |
158 | | /// The first template parameter list in a declaration will have depth 0, |
159 | | /// the second template parameter list will have depth 1, etc. |
160 | | unsigned getDepth() const; |
161 | | |
162 | | /// Determine whether this template parameter list contains an |
163 | | /// unexpanded parameter pack. |
164 | | bool containsUnexpandedParameterPack() const; |
165 | | |
166 | | /// Determine whether this template parameter list contains a parameter pack. |
167 | 1 | bool hasParameterPack() const { |
168 | 1 | for (const NamedDecl *P : asArray()) |
169 | 2 | if (P->isParameterPack()) |
170 | 1 | return true; |
171 | 0 | return false; |
172 | 1 | } |
173 | | |
174 | | /// The constraint-expression of the associated requires-clause. |
175 | 2.38M | Expr *getRequiresClause() { |
176 | 2.38M | return HasRequiresClause ? getTrailingObjects<Expr *>()[0]1.25k : nullptr2.37M ; |
177 | 2.38M | } |
178 | | |
179 | | /// The constraint-expression of the associated requires-clause. |
180 | 358k | const Expr *getRequiresClause() const { |
181 | 358k | return HasRequiresClause ? getTrailingObjects<Expr *>()[0]4.71k : nullptr353k ; |
182 | 358k | } |
183 | | |
184 | | /// \brief All associated constraints derived from this template parameter |
185 | | /// list, including the requires clause and any constraints derived from |
186 | | /// constrained-parameters. |
187 | | /// |
188 | | /// The constraints in the resulting list are to be treated as if in a |
189 | | /// conjunction ("and"). |
190 | | void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const; |
191 | | |
192 | | bool hasAssociatedConstraints() const; |
193 | | |
194 | 5.43M | SourceLocation getTemplateLoc() const { return TemplateLoc; } |
195 | 981k | SourceLocation getLAngleLoc() const { return LAngleLoc; } |
196 | 981k | SourceLocation getRAngleLoc() const { return RAngleLoc; } |
197 | | |
198 | 89.7k | SourceRange getSourceRange() const LLVM_READONLY { |
199 | 89.7k | return SourceRange(TemplateLoc, RAngleLoc); |
200 | 89.7k | } |
201 | | |
202 | | void print(raw_ostream &Out, const ASTContext &Context, |
203 | | bool OmitTemplateKW = false) const; |
204 | | void print(raw_ostream &Out, const ASTContext &Context, |
205 | | const PrintingPolicy &Policy, bool OmitTemplateKW = false) const; |
206 | | |
207 | | static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, |
208 | | const TemplateParameterList *TPL, |
209 | | unsigned Idx); |
210 | | }; |
211 | | |
212 | | /// Stores a list of template parameters and the associated |
213 | | /// requires-clause (if any) for a TemplateDecl and its derived classes. |
214 | | /// Suitable for creating on the stack. |
215 | | template <size_t N, bool HasRequiresClause> |
216 | | class FixedSizeTemplateParameterListStorage |
217 | | : public TemplateParameterList::FixedSizeStorageOwner { |
218 | | typename TemplateParameterList::FixedSizeStorage< |
219 | | NamedDecl *, Expr *>::with_counts< |
220 | | N, HasRequiresClause ? 1u : 0u |
221 | | >::type storage; |
222 | | |
223 | | public: |
224 | | FixedSizeTemplateParameterListStorage(const ASTContext &C, |
225 | | SourceLocation TemplateLoc, |
226 | | SourceLocation LAngleLoc, |
227 | | ArrayRef<NamedDecl *> Params, |
228 | | SourceLocation RAngleLoc, |
229 | | Expr *RequiresClause) |
230 | | : FixedSizeStorageOwner( |
231 | | (assert(N == Params.size()), |
232 | | assert(HasRequiresClause == (RequiresClause != nullptr)), |
233 | | new (static_cast<void *>(&storage)) TemplateParameterList(C, |
234 | 31.9k | TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {} |
235 | | }; |
236 | | |
237 | | /// A template argument list. |
238 | | class TemplateArgumentList final |
239 | | : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> { |
240 | | /// The template argument list. |
241 | | const TemplateArgument *Arguments; |
242 | | |
243 | | /// The number of template arguments in this template |
244 | | /// argument list. |
245 | | unsigned NumArguments; |
246 | | |
247 | | // Constructs an instance with an internal Argument list, containing |
248 | | // a copy of the Args array. (Called by CreateCopy) |
249 | | TemplateArgumentList(ArrayRef<TemplateArgument> Args); |
250 | | |
251 | | public: |
252 | | friend TrailingObjects; |
253 | | |
254 | | TemplateArgumentList(const TemplateArgumentList &) = delete; |
255 | | TemplateArgumentList &operator=(const TemplateArgumentList &) = delete; |
256 | | |
257 | | /// Type used to indicate that the template argument list itself is a |
258 | | /// stack object. It does not own its template arguments. |
259 | | enum OnStackType { OnStack }; |
260 | | |
261 | | /// Create a new template argument list that copies the given set of |
262 | | /// template arguments. |
263 | | static TemplateArgumentList *CreateCopy(ASTContext &Context, |
264 | | ArrayRef<TemplateArgument> Args); |
265 | | |
266 | | /// Construct a new, temporary template argument list on the stack. |
267 | | /// |
268 | | /// The template argument list does not own the template arguments |
269 | | /// provided. |
270 | | explicit TemplateArgumentList(OnStackType, ArrayRef<TemplateArgument> Args) |
271 | 2.79M | : Arguments(Args.data()), NumArguments(Args.size()) {} |
272 | | |
273 | | /// Produces a shallow copy of the given template argument list. |
274 | | /// |
275 | | /// This operation assumes that the input argument list outlives it. |
276 | | /// This takes the list as a pointer to avoid looking like a copy |
277 | | /// constructor, since this really really isn't safe to use that |
278 | | /// way. |
279 | | explicit TemplateArgumentList(const TemplateArgumentList *Other) |
280 | 6.20k | : Arguments(Other->data()), NumArguments(Other->size()) {} |
281 | | |
282 | | /// Retrieve the template argument at a given index. |
283 | 8.35M | const TemplateArgument &get(unsigned Idx) const { |
284 | 8.35M | assert(Idx < NumArguments && "Invalid template argument index"); |
285 | 0 | return data()[Idx]; |
286 | 8.35M | } |
287 | | |
288 | | /// Retrieve the template argument at a given index. |
289 | 7.47M | const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); } |
290 | | |
291 | | /// Produce this as an array ref. |
292 | 11.1M | ArrayRef<TemplateArgument> asArray() const { |
293 | 11.1M | return llvm::makeArrayRef(data(), size()); |
294 | 11.1M | } |
295 | | |
296 | | /// Retrieve the number of template arguments in this |
297 | | /// template argument list. |
298 | 21.1M | unsigned size() const { return NumArguments; } |
299 | | |
300 | | /// Retrieve a pointer to the template argument list. |
301 | 26.2M | const TemplateArgument *data() const { return Arguments; } |
302 | | }; |
303 | | |
304 | | void *allocateDefaultArgStorageChain(const ASTContext &C); |
305 | | |
306 | | /// Storage for a default argument. This is conceptually either empty, or an |
307 | | /// argument value, or a pointer to a previous declaration that had a default |
308 | | /// argument. |
309 | | /// |
310 | | /// However, this is complicated by modules: while we require all the default |
311 | | /// arguments for a template to be equivalent, there may be more than one, and |
312 | | /// we need to track all the originating parameters to determine if the default |
313 | | /// argument is visible. |
314 | | template<typename ParmDecl, typename ArgType> |
315 | | class DefaultArgStorage { |
316 | | /// Storage for both the value *and* another parameter from which we inherit |
317 | | /// the default argument. This is used when multiple default arguments for a |
318 | | /// parameter are merged together from different modules. |
319 | | struct Chain { |
320 | | ParmDecl *PrevDeclWithDefaultArg; |
321 | | ArgType Value; |
322 | | }; |
323 | | static_assert(sizeof(Chain) == sizeof(void *) * 2, |
324 | | "non-pointer argument type?"); |
325 | | |
326 | | llvm::PointerUnion<ArgType, ParmDecl*, Chain*> ValueOrInherited; |
327 | | |
328 | 61.8k | static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { |
329 | 61.8k | const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); |
330 | 61.8k | if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>()) |
331 | 27.9k | Parm = Prev; |
332 | 61.8k | assert(!Parm->getDefaultArgStorage() |
333 | 61.8k | .ValueOrInherited.template is<ParmDecl *>() && |
334 | 61.8k | "should only be one level of indirection"); |
335 | 0 | return Parm; |
336 | 61.8k | } clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::getParmOwningDefaultArg(clang::TemplateTypeParmDecl*) Line | Count | Source | 328 | 59.7k | static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { | 329 | 59.7k | const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); | 330 | 59.7k | if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>()) | 331 | 27.9k | Parm = Prev; | 332 | 59.7k | assert(!Parm->getDefaultArgStorage() | 333 | 59.7k | .ValueOrInherited.template is<ParmDecl *>() && | 334 | 59.7k | "should only be one level of indirection"); | 335 | 0 | return Parm; | 336 | 59.7k | } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::getParmOwningDefaultArg(clang::NonTypeTemplateParmDecl*) Line | Count | Source | 328 | 2.04k | static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { | 329 | 2.04k | const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); | 330 | 2.04k | if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>()) | 331 | 30 | Parm = Prev; | 332 | 2.04k | assert(!Parm->getDefaultArgStorage() | 333 | 2.04k | .ValueOrInherited.template is<ParmDecl *>() && | 334 | 2.04k | "should only be one level of indirection"); | 335 | 0 | return Parm; | 336 | 2.04k | } |
clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::getParmOwningDefaultArg(clang::TemplateTemplateParmDecl*) Line | Count | Source | 328 | 96 | static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { | 329 | 96 | const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); | 330 | 96 | if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>()) | 331 | 3 | Parm = Prev; | 332 | 96 | assert(!Parm->getDefaultArgStorage() | 333 | 96 | .ValueOrInherited.template is<ParmDecl *>() && | 334 | 96 | "should only be one level of indirection"); | 335 | 0 | return Parm; | 336 | 96 | } |
|
337 | | |
338 | | public: |
339 | 6.01M | DefaultArgStorage() : ValueOrInherited(ArgType()) {} clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::DefaultArgStorage() Line | Count | Source | 339 | 5.25M | DefaultArgStorage() : ValueOrInherited(ArgType()) {} |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::DefaultArgStorage() Line | Count | Source | 339 | 713k | DefaultArgStorage() : ValueOrInherited(ArgType()) {} |
clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::DefaultArgStorage() Line | Count | Source | 339 | 43.8k | DefaultArgStorage() : ValueOrInherited(ArgType()) {} |
|
340 | | |
341 | | /// Determine whether there is a default argument for this parameter. |
342 | 22.6M | bool isSet() const { return !ValueOrInherited.isNull(); } clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::isSet() const Line | Count | Source | 342 | 19.5M | bool isSet() const { return !ValueOrInherited.isNull(); } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::isSet() const Line | Count | Source | 342 | 2.95M | bool isSet() const { return !ValueOrInherited.isNull(); } |
clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::isSet() const Line | Count | Source | 342 | 149k | bool isSet() const { return !ValueOrInherited.isNull(); } |
|
343 | | |
344 | | /// Determine whether the default argument for this parameter was inherited |
345 | | /// from a previous declaration of the same entity. |
346 | 3.83M | bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::isInherited() const Line | Count | Source | 346 | 10.5k | bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } |
clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::isInherited() const Line | Count | Source | 346 | 2.95M | bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::isInherited() const Line | Count | Source | 346 | 862k | bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } |
|
347 | | |
348 | | /// Get the default argument's value. This does not consider whether the |
349 | | /// default argument is visible. |
350 | 2.79M | ArgType get() const { |
351 | 2.79M | const DefaultArgStorage *Storage = this; |
352 | 2.79M | if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>()) |
353 | 304k | Storage = &Prev->getDefaultArgStorage(); |
354 | 2.79M | if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>()) |
355 | 384 | return C->Value; |
356 | 2.79M | return Storage->ValueOrInherited.template get<ArgType>(); |
357 | 2.79M | } clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::get() const Line | Count | Source | 350 | 1.98M | ArgType get() const { | 351 | 1.98M | const DefaultArgStorage *Storage = this; | 352 | 1.98M | if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>()) | 353 | 252k | Storage = &Prev->getDefaultArgStorage(); | 354 | 1.98M | if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>()) | 355 | 128 | return C->Value; | 356 | 1.98M | return Storage->ValueOrInherited.template get<ArgType>(); | 357 | 1.98M | } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::get() const Line | Count | Source | 350 | 746k | ArgType get() const { | 351 | 746k | const DefaultArgStorage *Storage = this; | 352 | 746k | if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>()) | 353 | 51.7k | Storage = &Prev->getDefaultArgStorage(); | 354 | 746k | if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>()) | 355 | 81 | return C->Value; | 356 | 746k | return Storage->ValueOrInherited.template get<ArgType>(); | 357 | 746k | } |
clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::get() const Line | Count | Source | 350 | 66.0k | ArgType get() const { | 351 | 66.0k | const DefaultArgStorage *Storage = this; | 352 | 66.0k | if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>()) | 353 | 103 | Storage = &Prev->getDefaultArgStorage(); | 354 | 66.0k | if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>()) | 355 | 175 | return C->Value; | 356 | 65.8k | return Storage->ValueOrInherited.template get<ArgType>(); | 357 | 66.0k | } |
|
358 | | |
359 | | /// Get the parameter from which we inherit the default argument, if any. |
360 | | /// This is the parameter on which the default argument was actually written. |
361 | 625k | const ParmDecl *getInheritedFrom() const { |
362 | 625k | if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) |
363 | 625k | return D; |
364 | 465 | if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>()) |
365 | 38 | return C->PrevDeclWithDefaultArg; |
366 | 427 | return nullptr; |
367 | 465 | } clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::getInheritedFrom() const Line | Count | Source | 361 | 110 | const ParmDecl *getInheritedFrom() const { | 362 | 110 | if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) | 363 | 44 | return D; | 364 | 66 | if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>()) | 365 | 11 | return C->PrevDeclWithDefaultArg; | 366 | 55 | return nullptr; | 367 | 66 | } |
clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::getInheritedFrom() const Line | Count | Source | 361 | 566k | const ParmDecl *getInheritedFrom() const { | 362 | 566k | if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) | 363 | 566k | return D; | 364 | 302 | if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>()) | 365 | 16 | return C->PrevDeclWithDefaultArg; | 366 | 286 | return nullptr; | 367 | 302 | } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::getInheritedFrom() const Line | Count | Source | 361 | 59.2k | const ParmDecl *getInheritedFrom() const { | 362 | 59.2k | if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) | 363 | 59.1k | return D; | 364 | 97 | if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>()) | 365 | 11 | return C->PrevDeclWithDefaultArg; | 366 | 86 | return nullptr; | 367 | 97 | } |
|
368 | | |
369 | | /// Set the default argument. |
370 | 614k | void set(ArgType Arg) { |
371 | 614k | assert(!isSet() && "default argument already set"); |
372 | 0 | ValueOrInherited = Arg; |
373 | 614k | } clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::set(clang::TemplateArgumentLoc*) Line | Count | Source | 370 | 19.5k | void set(ArgType Arg) { | 371 | 19.5k | assert(!isSet() && "default argument already set"); | 372 | 0 | ValueOrInherited = Arg; | 373 | 19.5k | } |
clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::set(clang::TypeSourceInfo*) Line | Count | Source | 370 | 397k | void set(ArgType Arg) { | 371 | 397k | assert(!isSet() && "default argument already set"); | 372 | 0 | ValueOrInherited = Arg; | 373 | 397k | } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::set(clang::Expr*) Line | Count | Source | 370 | 196k | void set(ArgType Arg) { | 371 | 196k | assert(!isSet() && "default argument already set"); | 372 | 0 | ValueOrInherited = Arg; | 373 | 196k | } |
|
374 | | |
375 | | /// Set that the default argument was inherited from another parameter. |
376 | 61.8k | void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) { |
377 | 61.8k | InheritedFrom = getParmOwningDefaultArg(InheritedFrom); |
378 | 61.8k | if (!isSet()) |
379 | 61.6k | ValueOrInherited = InheritedFrom; |
380 | 215 | else if (auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) { |
381 | 1 | assert(C.isSameDefaultTemplateArgument(D, InheritedFrom)); |
382 | 0 | ValueOrInherited = |
383 | 1 | new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()}; |
384 | 214 | } else if (auto *Inherited = |
385 | 214 | ValueOrInherited.template dyn_cast<Chain *>()) { |
386 | 1 | assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg, |
387 | 1 | InheritedFrom)); |
388 | 0 | Inherited->PrevDeclWithDefaultArg = InheritedFrom; |
389 | 1 | } else |
390 | 213 | ValueOrInherited = new (allocateDefaultArgStorageChain(C)) |
391 | 213 | Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; |
392 | 61.8k | } clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::setInherited(clang::ASTContext const&, clang::TemplateTypeParmDecl*) Line | Count | Source | 376 | 59.7k | void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) { | 377 | 59.7k | InheritedFrom = getParmOwningDefaultArg(InheritedFrom); | 378 | 59.7k | if (!isSet()) | 379 | 59.6k | ValueOrInherited = InheritedFrom; | 380 | 94 | else if (auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) { | 381 | 1 | assert(C.isSameDefaultTemplateArgument(D, InheritedFrom)); | 382 | 0 | ValueOrInherited = | 383 | 1 | new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()}; | 384 | 93 | } else if (auto *Inherited = | 385 | 93 | ValueOrInherited.template dyn_cast<Chain *>()) { | 386 | 1 | assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg, | 387 | 1 | InheritedFrom)); | 388 | 0 | Inherited->PrevDeclWithDefaultArg = InheritedFrom; | 389 | 1 | } else | 390 | 92 | ValueOrInherited = new (allocateDefaultArgStorageChain(C)) | 391 | 92 | Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; | 392 | 59.7k | } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::setInherited(clang::ASTContext const&, clang::NonTypeTemplateParmDecl*) Line | Count | Source | 376 | 2.04k | void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) { | 377 | 2.04k | InheritedFrom = getParmOwningDefaultArg(InheritedFrom); | 378 | 2.04k | if (!isSet()) | 379 | 1.98k | ValueOrInherited = InheritedFrom; | 380 | 62 | else if (auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) { | 381 | 0 | assert(C.isSameDefaultTemplateArgument(D, InheritedFrom)); | 382 | 0 | ValueOrInherited = | 383 | 0 | new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()}; | 384 | 62 | } else if (auto *Inherited = | 385 | 62 | ValueOrInherited.template dyn_cast<Chain *>()) { | 386 | 0 | assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg, | 387 | 0 | InheritedFrom)); | 388 | 0 | Inherited->PrevDeclWithDefaultArg = InheritedFrom; | 389 | 0 | } else | 390 | 62 | ValueOrInherited = new (allocateDefaultArgStorageChain(C)) | 391 | 62 | Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; | 392 | 2.04k | } |
clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::setInherited(clang::ASTContext const&, clang::TemplateTemplateParmDecl*) Line | Count | Source | 376 | 96 | void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) { | 377 | 96 | InheritedFrom = getParmOwningDefaultArg(InheritedFrom); | 378 | 96 | if (!isSet()) | 379 | 37 | ValueOrInherited = InheritedFrom; | 380 | 59 | else if (auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) { | 381 | 0 | assert(C.isSameDefaultTemplateArgument(D, InheritedFrom)); | 382 | 0 | ValueOrInherited = | 383 | 0 | new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()}; | 384 | 59 | } else if (auto *Inherited = | 385 | 59 | ValueOrInherited.template dyn_cast<Chain *>()) { | 386 | 0 | assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg, | 387 | 0 | InheritedFrom)); | 388 | 0 | Inherited->PrevDeclWithDefaultArg = InheritedFrom; | 389 | 0 | } else | 390 | 59 | ValueOrInherited = new (allocateDefaultArgStorageChain(C)) | 391 | 59 | Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; | 392 | 96 | } |
|
393 | | |
394 | | /// Remove the default argument, even if it was inherited. |
395 | 71 | void clear() { |
396 | 71 | ValueOrInherited = ArgType(); |
397 | 71 | } clang::DefaultArgStorage<clang::TemplateTypeParmDecl, clang::TypeSourceInfo*>::clear() Line | Count | Source | 395 | 49 | void clear() { | 396 | 49 | ValueOrInherited = ArgType(); | 397 | 49 | } |
clang::DefaultArgStorage<clang::NonTypeTemplateParmDecl, clang::Expr*>::clear() Line | Count | Source | 395 | 12 | void clear() { | 396 | 12 | ValueOrInherited = ArgType(); | 397 | 12 | } |
clang::DefaultArgStorage<clang::TemplateTemplateParmDecl, clang::TemplateArgumentLoc*>::clear() Line | Count | Source | 395 | 10 | void clear() { | 396 | 10 | ValueOrInherited = ArgType(); | 397 | 10 | } |
|
398 | | }; |
399 | | |
400 | | //===----------------------------------------------------------------------===// |
401 | | // Kinds of Templates |
402 | | //===----------------------------------------------------------------------===// |
403 | | |
404 | | /// \brief The base class of all kinds of template declarations (e.g., |
405 | | /// class, function, etc.). |
406 | | /// |
407 | | /// The TemplateDecl class stores the list of template parameters and a |
408 | | /// reference to the templated scoped declaration: the underlying AST node. |
409 | | class TemplateDecl : public NamedDecl { |
410 | | void anchor() override; |
411 | | |
412 | | protected: |
413 | | // Construct a template decl with name, parameters, and templated element. |
414 | | TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, |
415 | | TemplateParameterList *Params, NamedDecl *Decl); |
416 | | |
417 | | // Construct a template decl with the given name and parameters. |
418 | | // Used when there is no templated element (e.g., for tt-params). |
419 | | TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, |
420 | | TemplateParameterList *Params) |
421 | 46.2k | : TemplateDecl(DK, DC, L, Name, Params, nullptr) {} |
422 | | |
423 | | public: |
424 | | friend class ASTDeclReader; |
425 | | friend class ASTDeclWriter; |
426 | | |
427 | | /// Get the list of template parameters |
428 | 45.3M | TemplateParameterList *getTemplateParameters() const { |
429 | 45.3M | return TemplateParams; |
430 | 45.3M | } |
431 | | |
432 | | /// \brief Get the total constraint-expression associated with this template, |
433 | | /// including constraint-expressions derived from the requires-clause, |
434 | | /// trailing requires-clause (for functions and methods) and constrained |
435 | | /// template parameters. |
436 | | void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const; |
437 | | |
438 | | bool hasAssociatedConstraints() const; |
439 | | |
440 | | /// Get the underlying, templated declaration. |
441 | 20.6M | NamedDecl *getTemplatedDecl() const { return TemplatedDecl; } |
442 | | |
443 | | // Implement isa/cast/dyncast/etc. |
444 | 381M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
445 | | |
446 | 381M | static bool classofKind(Kind K) { |
447 | 381M | return K >= firstTemplate && K <= lastTemplate378M ; |
448 | 381M | } |
449 | | |
450 | 1.29M | SourceRange getSourceRange() const override LLVM_READONLY { |
451 | 1.29M | return SourceRange(getTemplateParameters()->getTemplateLoc(), |
452 | 1.29M | TemplatedDecl->getSourceRange().getEnd()); |
453 | 1.29M | } |
454 | | |
455 | | protected: |
456 | | NamedDecl *TemplatedDecl; |
457 | | TemplateParameterList *TemplateParams; |
458 | | |
459 | 0 | void setTemplateParameters(TemplateParameterList *TParams) { |
460 | 0 | TemplateParams = TParams; |
461 | 0 | } |
462 | | |
463 | | public: |
464 | | /// Initialize the underlying templated declaration and |
465 | | /// template parameters. |
466 | 658k | void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) { |
467 | 658k | assert(!TemplatedDecl && "TemplatedDecl already set!"); |
468 | 0 | assert(!TemplateParams && "TemplateParams already set!"); |
469 | 0 | TemplatedDecl = templatedDecl; |
470 | 658k | TemplateParams = templateParams; |
471 | 658k | } |
472 | | }; |
473 | | |
474 | | /// Provides information about a function template specialization, |
475 | | /// which is a FunctionDecl that has been explicitly specialization or |
476 | | /// instantiated from a function template. |
477 | | class FunctionTemplateSpecializationInfo final |
478 | | : public llvm::FoldingSetNode, |
479 | | private llvm::TrailingObjects<FunctionTemplateSpecializationInfo, |
480 | | MemberSpecializationInfo *> { |
481 | | /// The function template specialization that this structure describes and a |
482 | | /// flag indicating if the function is a member specialization. |
483 | | llvm::PointerIntPair<FunctionDecl *, 1, bool> Function; |
484 | | |
485 | | /// The function template from which this function template |
486 | | /// specialization was generated. |
487 | | /// |
488 | | /// The two bits contain the top 4 values of TemplateSpecializationKind. |
489 | | llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template; |
490 | | |
491 | | public: |
492 | | /// The template arguments used to produce the function template |
493 | | /// specialization from the function template. |
494 | | const TemplateArgumentList *TemplateArguments; |
495 | | |
496 | | /// The template arguments as written in the sources, if provided. |
497 | | /// FIXME: Normally null; tail-allocate this. |
498 | | const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten; |
499 | | |
500 | | /// The point at which this function template specialization was |
501 | | /// first instantiated. |
502 | | SourceLocation PointOfInstantiation; |
503 | | |
504 | | private: |
505 | | FunctionTemplateSpecializationInfo( |
506 | | FunctionDecl *FD, FunctionTemplateDecl *Template, |
507 | | TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, |
508 | | const ASTTemplateArgumentListInfo *TemplateArgsAsWritten, |
509 | | SourceLocation POI, MemberSpecializationInfo *MSInfo) |
510 | | : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1), |
511 | | TemplateArguments(TemplateArgs), |
512 | | TemplateArgumentsAsWritten(TemplateArgsAsWritten), |
513 | 500k | PointOfInstantiation(POI) { |
514 | 500k | if (MSInfo) |
515 | 114 | getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo; |
516 | 500k | } |
517 | | |
518 | 1.48M | size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const { |
519 | 1.48M | return Function.getInt(); |
520 | 1.48M | } |
521 | | |
522 | | public: |
523 | | friend TrailingObjects; |
524 | | |
525 | | static FunctionTemplateSpecializationInfo * |
526 | | Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, |
527 | | TemplateSpecializationKind TSK, |
528 | | const TemplateArgumentList *TemplateArgs, |
529 | | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
530 | | SourceLocation POI, MemberSpecializationInfo *MSInfo); |
531 | | |
532 | | /// Retrieve the declaration of the function template specialization. |
533 | 1.50M | FunctionDecl *getFunction() const { return Function.getPointer(); } |
534 | | |
535 | | /// Retrieve the template from which this function was specialized. |
536 | 3.87M | FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); } |
537 | | |
538 | | /// Determine what kind of template specialization this is. |
539 | 2.72M | TemplateSpecializationKind getTemplateSpecializationKind() const { |
540 | 2.72M | return (TemplateSpecializationKind)(Template.getInt() + 1); |
541 | 2.72M | } |
542 | | |
543 | 94.6k | bool isExplicitSpecialization() const { |
544 | 94.6k | return getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
545 | 94.6k | } |
546 | | |
547 | | /// True if this declaration is an explicit specialization, |
548 | | /// explicit instantiation declaration, or explicit instantiation |
549 | | /// definition. |
550 | 310k | bool isExplicitInstantiationOrSpecialization() const { |
551 | 310k | return isTemplateExplicitInstantiationOrSpecialization( |
552 | 310k | getTemplateSpecializationKind()); |
553 | 310k | } |
554 | | |
555 | | /// Set the template specialization kind. |
556 | 139k | void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
557 | 139k | assert(TSK != TSK_Undeclared && |
558 | 139k | "Cannot encode TSK_Undeclared for a function template specialization"); |
559 | 0 | Template.setInt(TSK - 1); |
560 | 139k | } |
561 | | |
562 | | /// Retrieve the first point of instantiation of this function |
563 | | /// template specialization. |
564 | | /// |
565 | | /// The point of instantiation may be an invalid source location if this |
566 | | /// function has yet to be instantiated. |
567 | 357k | SourceLocation getPointOfInstantiation() const { |
568 | 357k | return PointOfInstantiation; |
569 | 357k | } |
570 | | |
571 | | /// Set the (first) point of instantiation of this function template |
572 | | /// specialization. |
573 | 137k | void setPointOfInstantiation(SourceLocation POI) { |
574 | 137k | PointOfInstantiation = POI; |
575 | 137k | } |
576 | | |
577 | | /// Get the specialization info if this function template specialization is |
578 | | /// also a member specialization: |
579 | | /// |
580 | | /// \code |
581 | | /// template<typename> struct A { |
582 | | /// template<typename> void f(); |
583 | | /// template<> void f<int>(); // ClassScopeFunctionSpecializationDecl |
584 | | /// }; |
585 | | /// \endcode |
586 | | /// |
587 | | /// Here, A<int>::f<int> is a function template specialization that is |
588 | | /// an explicit specialization of A<int>::f, but it's also a member |
589 | | /// specialization (an implicit instantiation in this case) of A::f<int>. |
590 | | /// Further: |
591 | | /// |
592 | | /// \code |
593 | | /// template<> template<> void A<int>::f<int>() {} |
594 | | /// \endcode |
595 | | /// |
596 | | /// ... declares a function template specialization that is an explicit |
597 | | /// specialization of A<int>::f, and is also an explicit member |
598 | | /// specialization of A::f<int>. |
599 | | /// |
600 | | /// Note that the TemplateSpecializationKind of the MemberSpecializationInfo |
601 | | /// need not be the same as that returned by getTemplateSpecializationKind(), |
602 | | /// and represents the relationship between the function and the class-scope |
603 | | /// explicit specialization in the original templated class -- whereas our |
604 | | /// TemplateSpecializationKind represents the relationship between the |
605 | | /// function and the function template, and should always be |
606 | | /// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo. |
607 | 1.48M | MemberSpecializationInfo *getMemberSpecializationInfo() const { |
608 | 1.48M | return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>()) |
609 | 1.48M | ? getTrailingObjects<MemberSpecializationInfo *>()[0]921 |
610 | 1.48M | : nullptr1.48M ; |
611 | 1.48M | } |
612 | | |
613 | 878k | void Profile(llvm::FoldingSetNodeID &ID) { |
614 | 878k | Profile(ID, TemplateArguments->asArray(), getFunction()->getASTContext()); |
615 | 878k | } |
616 | | |
617 | | static void |
618 | | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, |
619 | 1.69M | ASTContext &Context) { |
620 | 1.69M | ID.AddInteger(TemplateArgs.size()); |
621 | 1.69M | for (const TemplateArgument &TemplateArg : TemplateArgs) |
622 | 2.30M | TemplateArg.Profile(ID, Context); |
623 | 1.69M | } |
624 | | }; |
625 | | |
626 | | /// Provides information a specialization of a member of a class |
627 | | /// template, which may be a member function, static data member, |
628 | | /// member class or member enumeration. |
629 | | class MemberSpecializationInfo { |
630 | | // The member declaration from which this member was instantiated, and the |
631 | | // manner in which the instantiation occurred (in the lower two bits). |
632 | | llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK; |
633 | | |
634 | | // The point at which this member was first instantiated. |
635 | | SourceLocation PointOfInstantiation; |
636 | | |
637 | | public: |
638 | | explicit |
639 | | MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, |
640 | | SourceLocation POI = SourceLocation()) |
641 | 1.44M | : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) { |
642 | 1.44M | assert(TSK != TSK_Undeclared && |
643 | 1.44M | "Cannot encode undeclared template specializations for members"); |
644 | 1.44M | } |
645 | | |
646 | | /// Retrieve the member declaration from which this member was |
647 | | /// instantiated. |
648 | 31.9M | NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); } |
649 | | |
650 | | /// Determine what kind of template specialization this is. |
651 | 20.1M | TemplateSpecializationKind getTemplateSpecializationKind() const { |
652 | 20.1M | return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1); |
653 | 20.1M | } |
654 | | |
655 | 715k | bool isExplicitSpecialization() const { |
656 | 715k | return getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
657 | 715k | } |
658 | | |
659 | | /// Set the template specialization kind. |
660 | 884k | void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
661 | 884k | assert(TSK != TSK_Undeclared && |
662 | 884k | "Cannot encode undeclared template specializations for members"); |
663 | 0 | MemberAndTSK.setInt(TSK - 1); |
664 | 884k | } |
665 | | |
666 | | /// Retrieve the first point of instantiation of this member. |
667 | | /// If the point of instantiation is an invalid location, then this member |
668 | | /// has not yet been instantiated. |
669 | 2.40M | SourceLocation getPointOfInstantiation() const { |
670 | 2.40M | return PointOfInstantiation; |
671 | 2.40M | } |
672 | | |
673 | | /// Set the first point of instantiation. |
674 | 769k | void setPointOfInstantiation(SourceLocation POI) { |
675 | 769k | PointOfInstantiation = POI; |
676 | 769k | } |
677 | | }; |
678 | | |
679 | | /// Provides information about a dependent function-template |
680 | | /// specialization declaration. |
681 | | /// |
682 | | /// Since explicit function template specialization and instantiation |
683 | | /// declarations can only appear in namespace scope, and you can only |
684 | | /// specialize a member of a fully-specialized class, the only way to |
685 | | /// get one of these is in a friend declaration like the following: |
686 | | /// |
687 | | /// \code |
688 | | /// template \<class T> void foo(T); |
689 | | /// template \<class T> class A { |
690 | | /// friend void foo<>(T); |
691 | | /// }; |
692 | | /// \endcode |
693 | | class DependentFunctionTemplateSpecializationInfo final |
694 | | : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo, |
695 | | TemplateArgumentLoc, |
696 | | FunctionTemplateDecl *> { |
697 | | /// The number of potential template candidates. |
698 | | unsigned NumTemplates; |
699 | | |
700 | | /// The number of template arguments. |
701 | | unsigned NumArgs; |
702 | | |
703 | | /// The locations of the left and right angle brackets. |
704 | | SourceRange AngleLocs; |
705 | | |
706 | 36.1k | size_t numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const { |
707 | 36.1k | return NumArgs; |
708 | 36.1k | } |
709 | 0 | size_t numTrailingObjects(OverloadToken<FunctionTemplateDecl *>) const { |
710 | 0 | return NumTemplates; |
711 | 0 | } |
712 | | |
713 | | DependentFunctionTemplateSpecializationInfo( |
714 | | const UnresolvedSetImpl &Templates, |
715 | | const TemplateArgumentListInfo &TemplateArgs); |
716 | | |
717 | | public: |
718 | | friend TrailingObjects; |
719 | | |
720 | | static DependentFunctionTemplateSpecializationInfo * |
721 | | Create(ASTContext &Context, const UnresolvedSetImpl &Templates, |
722 | | const TemplateArgumentListInfo &TemplateArgs); |
723 | | |
724 | | /// Returns the number of function templates that this might |
725 | | /// be a specialization of. |
726 | 38.1k | unsigned getNumTemplates() const { return NumTemplates; } |
727 | | |
728 | | /// Returns the i'th template candidate. |
729 | 33.8k | FunctionTemplateDecl *getTemplate(unsigned I) const { |
730 | 33.8k | assert(I < getNumTemplates() && "template index out of range"); |
731 | 0 | return getTrailingObjects<FunctionTemplateDecl *>()[I]; |
732 | 33.8k | } |
733 | | |
734 | | /// Returns the explicit template arguments that were given. |
735 | 4.20k | const TemplateArgumentLoc *getTemplateArgs() const { |
736 | 4.20k | return getTrailingObjects<TemplateArgumentLoc>(); |
737 | 4.20k | } |
738 | | |
739 | | /// Returns the number of explicit template arguments that were given. |
740 | 4.32k | unsigned getNumTemplateArgs() const { return NumArgs; } |
741 | | |
742 | 3.88k | llvm::ArrayRef<TemplateArgumentLoc> arguments() const { |
743 | 3.88k | return llvm::makeArrayRef(getTemplateArgs(), getNumTemplateArgs()); |
744 | 3.88k | } |
745 | | |
746 | | /// Returns the nth template argument. |
747 | 0 | const TemplateArgumentLoc &getTemplateArg(unsigned I) const { |
748 | 0 | assert(I < getNumTemplateArgs() && "template arg index out of range"); |
749 | 0 | return getTemplateArgs()[I]; |
750 | 0 | } |
751 | | |
752 | 4.26k | SourceLocation getLAngleLoc() const { |
753 | 4.26k | return AngleLocs.getBegin(); |
754 | 4.26k | } |
755 | | |
756 | 4.26k | SourceLocation getRAngleLoc() const { |
757 | 4.26k | return AngleLocs.getEnd(); |
758 | 4.26k | } |
759 | | }; |
760 | | |
761 | | /// Declaration of a redeclarable template. |
762 | | class RedeclarableTemplateDecl : public TemplateDecl, |
763 | | public Redeclarable<RedeclarableTemplateDecl> |
764 | | { |
765 | | using redeclarable_base = Redeclarable<RedeclarableTemplateDecl>; |
766 | | |
767 | 1.82M | RedeclarableTemplateDecl *getNextRedeclarationImpl() override { |
768 | 1.82M | return getNextRedeclaration(); |
769 | 1.82M | } |
770 | | |
771 | 1.82M | RedeclarableTemplateDecl *getPreviousDeclImpl() override { |
772 | 1.82M | return getPreviousDecl(); |
773 | 1.82M | } |
774 | | |
775 | 20.2M | RedeclarableTemplateDecl *getMostRecentDeclImpl() override { |
776 | 20.2M | return getMostRecentDecl(); |
777 | 20.2M | } |
778 | | |
779 | | void anchor() override; |
780 | | protected: |
781 | | template <typename EntryType> struct SpecEntryTraits { |
782 | | using DeclType = EntryType; |
783 | | |
784 | 1.90M | static DeclType *getDecl(EntryType *D) { |
785 | 1.90M | return D; |
786 | 1.90M | } clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplatePartialSpecializationDecl>::getDecl(clang::ClassTemplatePartialSpecializationDecl*) Line | Count | Source | 784 | 6.84k | static DeclType *getDecl(EntryType *D) { | 785 | 6.84k | return D; | 786 | 6.84k | } |
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplatePartialSpecializationDecl>::getDecl(clang::VarTemplatePartialSpecializationDecl*) Line | Count | Source | 784 | 139 | static DeclType *getDecl(EntryType *D) { | 785 | 139 | return D; | 786 | 139 | } |
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>::getDecl(clang::ClassTemplateSpecializationDecl*) Line | Count | Source | 784 | 1.89M | static DeclType *getDecl(EntryType *D) { | 785 | 1.89M | return D; | 786 | 1.89M | } |
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>::getDecl(clang::VarTemplateSpecializationDecl*) Line | Count | Source | 784 | 3.57k | static DeclType *getDecl(EntryType *D) { | 785 | 3.57k | return D; | 786 | 3.57k | } |
Unexecuted instantiation: clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::Decl const>::getDecl(clang::Decl const*) |
787 | | |
788 | 1.18M | static ArrayRef<TemplateArgument> getTemplateArgs(EntryType *D) { |
789 | 1.18M | return D->getTemplateArgs().asArray(); |
790 | 1.18M | } clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>::getTemplateArgs(clang::ClassTemplateSpecializationDecl*) Line | Count | Source | 788 | 1.18M | static ArrayRef<TemplateArgument> getTemplateArgs(EntryType *D) { | 789 | 1.18M | return D->getTemplateArgs().asArray(); | 790 | 1.18M | } |
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>::getTemplateArgs(clang::VarTemplateSpecializationDecl*) Line | Count | Source | 788 | 4.79k | static ArrayRef<TemplateArgument> getTemplateArgs(EntryType *D) { | 789 | 4.79k | return D->getTemplateArgs().asArray(); | 790 | 4.79k | } |
|
791 | | }; |
792 | | |
793 | | template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>, |
794 | | typename DeclType = typename SETraits::DeclType> |
795 | | struct SpecIterator |
796 | | : llvm::iterator_adaptor_base< |
797 | | SpecIterator<EntryType, SETraits, DeclType>, |
798 | | typename llvm::FoldingSetVector<EntryType>::iterator, |
799 | | typename std::iterator_traits<typename llvm::FoldingSetVector< |
800 | | EntryType>::iterator>::iterator_category, |
801 | | DeclType *, ptrdiff_t, DeclType *, DeclType *> { |
802 | | SpecIterator() = default; |
803 | | explicit SpecIterator( |
804 | | typename llvm::FoldingSetVector<EntryType>::iterator SetIter) |
805 | 208k | : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {} clang::RedeclarableTemplateDecl::SpecIterator<clang::ClassTemplateSpecializationDecl, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>, clang::ClassTemplateSpecializationDecl>::SpecIterator(llvm::pointee_iterator<clang::ClassTemplateSpecializationDecl**, clang::ClassTemplateSpecializationDecl>) Line | Count | Source | 805 | 71.9k | : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {} |
clang::RedeclarableTemplateDecl::SpecIterator<clang::FunctionTemplateSpecializationInfo, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::FunctionTemplateSpecializationInfo>, clang::FunctionDecl>::SpecIterator(llvm::pointee_iterator<clang::FunctionTemplateSpecializationInfo**, clang::FunctionTemplateSpecializationInfo>) Line | Count | Source | 805 | 132k | : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {} |
clang::RedeclarableTemplateDecl::SpecIterator<clang::VarTemplateSpecializationDecl, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>, clang::VarTemplateSpecializationDecl>::SpecIterator(llvm::pointee_iterator<clang::VarTemplateSpecializationDecl**, clang::VarTemplateSpecializationDecl>) Line | Count | Source | 805 | 4.33k | : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {} |
|
806 | | |
807 | 47.9k | DeclType *operator*() const { |
808 | 47.9k | return SETraits::getDecl(&*this->I)->getMostRecentDecl(); |
809 | 47.9k | } clang::RedeclarableTemplateDecl::SpecIterator<clang::ClassTemplateSpecializationDecl, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>, clang::ClassTemplateSpecializationDecl>::operator*() const Line | Count | Source | 807 | 36.8k | DeclType *operator*() const { | 808 | 36.8k | return SETraits::getDecl(&*this->I)->getMostRecentDecl(); | 809 | 36.8k | } |
clang::RedeclarableTemplateDecl::SpecIterator<clang::FunctionTemplateSpecializationInfo, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::FunctionTemplateSpecializationInfo>, clang::FunctionDecl>::operator*() const Line | Count | Source | 807 | 10.6k | DeclType *operator*() const { | 808 | 10.6k | return SETraits::getDecl(&*this->I)->getMostRecentDecl(); | 809 | 10.6k | } |
clang::RedeclarableTemplateDecl::SpecIterator<clang::VarTemplateSpecializationDecl, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>, clang::VarTemplateSpecializationDecl>::operator*() const Line | Count | Source | 807 | 324 | DeclType *operator*() const { | 808 | 324 | return SETraits::getDecl(&*this->I)->getMostRecentDecl(); | 809 | 324 | } |
|
810 | | |
811 | | DeclType *operator->() const { return **this; } |
812 | | }; |
813 | | |
814 | | template <typename EntryType> |
815 | | static SpecIterator<EntryType> |
816 | 208k | makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) { |
817 | 208k | return SpecIterator<EntryType>(isEnd ? Specs.end()104k : Specs.begin()104k ); |
818 | 208k | } clang::RedeclarableTemplateDecl::SpecIterator<clang::ClassTemplateSpecializationDecl, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>::DeclType> clang::RedeclarableTemplateDecl::makeSpecIterator<clang::ClassTemplateSpecializationDecl>(llvm::FoldingSetVector<clang::ClassTemplateSpecializationDecl, llvm::SmallVector<clang::ClassTemplateSpecializationDecl*, 8u> >&, bool) Line | Count | Source | 816 | 71.9k | makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) { | 817 | 71.9k | return SpecIterator<EntryType>(isEnd ? Specs.end()35.9k : Specs.begin()35.9k ); | 818 | 71.9k | } |
clang::RedeclarableTemplateDecl::SpecIterator<clang::FunctionTemplateSpecializationInfo, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::FunctionTemplateSpecializationInfo>, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::FunctionTemplateSpecializationInfo>::DeclType> clang::RedeclarableTemplateDecl::makeSpecIterator<clang::FunctionTemplateSpecializationInfo>(llvm::FoldingSetVector<clang::FunctionTemplateSpecializationInfo, llvm::SmallVector<clang::FunctionTemplateSpecializationInfo*, 8u> >&, bool) Line | Count | Source | 816 | 132k | makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) { | 817 | 132k | return SpecIterator<EntryType>(isEnd ? Specs.end()66.2k : Specs.begin()66.2k ); | 818 | 132k | } |
clang::RedeclarableTemplateDecl::SpecIterator<clang::VarTemplateSpecializationDecl, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>, clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>::DeclType> clang::RedeclarableTemplateDecl::makeSpecIterator<clang::VarTemplateSpecializationDecl>(llvm::FoldingSetVector<clang::VarTemplateSpecializationDecl, llvm::SmallVector<clang::VarTemplateSpecializationDecl*, 8u> >&, bool) Line | Count | Source | 816 | 4.33k | makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) { | 817 | 4.33k | return SpecIterator<EntryType>(isEnd ? Specs.end()2.16k : Specs.begin()2.16k ); | 818 | 4.33k | } |
|
819 | | |
820 | | void loadLazySpecializationsImpl() const; |
821 | | |
822 | | template <class EntryType, typename ...ProfileArguments> |
823 | | typename SpecEntryTraits<EntryType>::DeclType* |
824 | | findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs, |
825 | | void *&InsertPos, ProfileArguments &&...ProfileArgs); |
826 | | |
827 | | template <class Derived, class EntryType> |
828 | | void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs, |
829 | | EntryType *Entry, void *InsertPos); |
830 | | |
831 | | struct CommonBase { |
832 | 1.74M | CommonBase() : InstantiatedFromMember(nullptr, false) {} |
833 | | |
834 | | /// The template from which this was most |
835 | | /// directly instantiated (or null). |
836 | | /// |
837 | | /// The boolean value indicates whether this template |
838 | | /// was explicitly specialized. |
839 | | llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool> |
840 | | InstantiatedFromMember; |
841 | | |
842 | | /// If non-null, points to an array of specializations (including |
843 | | /// partial specializations) known only by their external declaration IDs. |
844 | | /// |
845 | | /// The first value in the array is the number of specializations/partial |
846 | | /// specializations that follow. |
847 | | uint32_t *LazySpecializations = nullptr; |
848 | | }; |
849 | | |
850 | | /// Pointer to the common data shared by all declarations of this |
851 | | /// template. |
852 | | mutable CommonBase *Common = nullptr; |
853 | | |
854 | | /// Retrieves the "common" pointer shared by all (re-)declarations of |
855 | | /// the same template. Calling this routine may implicitly allocate memory |
856 | | /// for the common pointer. |
857 | | CommonBase *getCommonPtr() const; |
858 | | |
859 | | virtual CommonBase *newCommon(ASTContext &C) const = 0; |
860 | | |
861 | | // Construct a template decl with name, parameters, and templated element. |
862 | | RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC, |
863 | | SourceLocation L, DeclarationName Name, |
864 | | TemplateParameterList *Params, NamedDecl *Decl) |
865 | 2.33M | : TemplateDecl(DK, DC, L, Name, Params, Decl), redeclarable_base(C) {} |
866 | | |
867 | | public: |
868 | | friend class ASTDeclReader; |
869 | | friend class ASTDeclWriter; |
870 | | friend class ASTReader; |
871 | | template <class decl_type> friend class RedeclarableTemplate; |
872 | | |
873 | | /// Retrieves the canonical declaration of this template. |
874 | 111M | RedeclarableTemplateDecl *getCanonicalDecl() override { |
875 | 111M | return getFirstDecl(); |
876 | 111M | } |
877 | 0 | const RedeclarableTemplateDecl *getCanonicalDecl() const { |
878 | 0 | return getFirstDecl(); |
879 | 0 | } |
880 | | |
881 | | /// Determines whether this template was a specialization of a |
882 | | /// member template. |
883 | | /// |
884 | | /// In the following example, the function template \c X<int>::f and the |
885 | | /// member template \c X<int>::Inner are member specializations. |
886 | | /// |
887 | | /// \code |
888 | | /// template<typename T> |
889 | | /// struct X { |
890 | | /// template<typename U> void f(T, U); |
891 | | /// template<typename U> struct Inner; |
892 | | /// }; |
893 | | /// |
894 | | /// template<> template<typename T> |
895 | | /// void X<int>::f(int, T); |
896 | | /// template<> template<typename T> |
897 | | /// struct X<int>::Inner { /* ... */ }; |
898 | | /// \endcode |
899 | 4.89M | bool isMemberSpecialization() const { |
900 | 4.89M | return getCommonPtr()->InstantiatedFromMember.getInt(); |
901 | 4.89M | } |
902 | | |
903 | | /// Note that this member template is a specialization. |
904 | 166 | void setMemberSpecialization() { |
905 | 166 | assert(getCommonPtr()->InstantiatedFromMember.getPointer() && |
906 | 166 | "Only member templates can be member template specializations"); |
907 | 0 | getCommonPtr()->InstantiatedFromMember.setInt(true); |
908 | 166 | } |
909 | | |
910 | | /// Retrieve the member template from which this template was |
911 | | /// instantiated, or nullptr if this template was not instantiated from a |
912 | | /// member template. |
913 | | /// |
914 | | /// A template is instantiated from a member template when the member |
915 | | /// template itself is part of a class template (or member thereof). For |
916 | | /// example, given |
917 | | /// |
918 | | /// \code |
919 | | /// template<typename T> |
920 | | /// struct X { |
921 | | /// template<typename U> void f(T, U); |
922 | | /// }; |
923 | | /// |
924 | | /// void test(X<int> x) { |
925 | | /// x.f(1, 'a'); |
926 | | /// }; |
927 | | /// \endcode |
928 | | /// |
929 | | /// \c X<int>::f is a FunctionTemplateDecl that describes the function |
930 | | /// template |
931 | | /// |
932 | | /// \code |
933 | | /// template<typename U> void X<int>::f(int, U); |
934 | | /// \endcode |
935 | | /// |
936 | | /// which was itself created during the instantiation of \c X<int>. Calling |
937 | | /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will |
938 | | /// retrieve the FunctionTemplateDecl for the original template \c f within |
939 | | /// the class template \c X<T>, i.e., |
940 | | /// |
941 | | /// \code |
942 | | /// template<typename T> |
943 | | /// template<typename U> |
944 | | /// void X<T>::f(T, U); |
945 | | /// \endcode |
946 | 2.72M | RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() const { |
947 | 2.72M | return getCommonPtr()->InstantiatedFromMember.getPointer(); |
948 | 2.72M | } |
949 | | |
950 | 333k | void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD) { |
951 | 333k | assert(!getCommonPtr()->InstantiatedFromMember.getPointer()); |
952 | 0 | getCommonPtr()->InstantiatedFromMember.setPointer(TD); |
953 | 333k | } |
954 | | |
955 | | using redecl_range = redeclarable_base::redecl_range; |
956 | | using redecl_iterator = redeclarable_base::redecl_iterator; |
957 | | |
958 | | using redeclarable_base::redecls_begin; |
959 | | using redeclarable_base::redecls_end; |
960 | | using redeclarable_base::redecls; |
961 | | using redeclarable_base::getPreviousDecl; |
962 | | using redeclarable_base::getMostRecentDecl; |
963 | | using redeclarable_base::isFirstDecl; |
964 | | |
965 | | // Implement isa/cast/dyncast/etc. |
966 | 3.61M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
967 | | |
968 | 3.61M | static bool classofKind(Kind K) { |
969 | 3.61M | return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate3.61M ; |
970 | 3.61M | } |
971 | | }; |
972 | | |
973 | | template <> struct RedeclarableTemplateDecl:: |
974 | | SpecEntryTraits<FunctionTemplateSpecializationInfo> { |
975 | | using DeclType = FunctionDecl; |
976 | | |
977 | 630k | static DeclType *getDecl(FunctionTemplateSpecializationInfo *I) { |
978 | 630k | return I->getFunction(); |
979 | 630k | } |
980 | | |
981 | | static ArrayRef<TemplateArgument> |
982 | 0 | getTemplateArgs(FunctionTemplateSpecializationInfo *I) { |
983 | 0 | return I->TemplateArguments->asArray(); |
984 | 0 | } |
985 | | }; |
986 | | |
987 | | /// Declaration of a template function. |
988 | | class FunctionTemplateDecl : public RedeclarableTemplateDecl { |
989 | | protected: |
990 | | friend class FunctionDecl; |
991 | | |
992 | | /// Data that is common to all of the declarations of a given |
993 | | /// function template. |
994 | | struct Common : CommonBase { |
995 | | /// The function template specializations for this function |
996 | | /// template, including explicit specializations and instantiations. |
997 | | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations; |
998 | | |
999 | | /// The set of "injected" template arguments used within this |
1000 | | /// function template. |
1001 | | /// |
1002 | | /// This pointer refers to the template arguments (there are as |
1003 | | /// many template arguments as template parameaters) for the function |
1004 | | /// template, and is allocated lazily, since most function templates do not |
1005 | | /// require the use of this information. |
1006 | | TemplateArgument *InjectedArgs = nullptr; |
1007 | | |
1008 | 1.17M | Common() = default; |
1009 | | }; |
1010 | | |
1011 | | FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
1012 | | DeclarationName Name, TemplateParameterList *Params, |
1013 | | NamedDecl *Decl) |
1014 | | : RedeclarableTemplateDecl(FunctionTemplate, C, DC, L, Name, Params, |
1015 | 1.53M | Decl) {} |
1016 | | |
1017 | | CommonBase *newCommon(ASTContext &C) const override; |
1018 | | |
1019 | 1.34M | Common *getCommonPtr() const { |
1020 | 1.34M | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
1021 | 1.34M | } |
1022 | | |
1023 | | /// Retrieve the set of function template specializations of this |
1024 | | /// function template. |
1025 | | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> & |
1026 | | getSpecializations() const; |
1027 | | |
1028 | | /// Add a specialization of this function template. |
1029 | | /// |
1030 | | /// \param InsertPos Insert position in the FoldingSetVector, must have been |
1031 | | /// retrieved by an earlier call to findSpecialization(). |
1032 | | void addSpecialization(FunctionTemplateSpecializationInfo* Info, |
1033 | | void *InsertPos); |
1034 | | |
1035 | | public: |
1036 | | friend class ASTDeclReader; |
1037 | | friend class ASTDeclWriter; |
1038 | | |
1039 | | /// Load any lazily-loaded specializations from the external source. |
1040 | | void LoadLazySpecializations() const; |
1041 | | |
1042 | | /// Get the underlying function declaration of the template. |
1043 | 19.8M | FunctionDecl *getTemplatedDecl() const { |
1044 | 19.8M | return static_cast<FunctionDecl *>(TemplatedDecl); |
1045 | 19.8M | } |
1046 | | |
1047 | | /// Returns whether this template declaration defines the primary |
1048 | | /// pattern. |
1049 | 83.3k | bool isThisDeclarationADefinition() const { |
1050 | 83.3k | return getTemplatedDecl()->isThisDeclarationADefinition(); |
1051 | 83.3k | } |
1052 | | |
1053 | | /// Return the specialization with the provided arguments if it exists, |
1054 | | /// otherwise return the insertion point. |
1055 | | FunctionDecl *findSpecialization(ArrayRef<TemplateArgument> Args, |
1056 | | void *&InsertPos); |
1057 | | |
1058 | 76.4M | FunctionTemplateDecl *getCanonicalDecl() override { |
1059 | 76.4M | return cast<FunctionTemplateDecl>( |
1060 | 76.4M | RedeclarableTemplateDecl::getCanonicalDecl()); |
1061 | 76.4M | } |
1062 | 0 | const FunctionTemplateDecl *getCanonicalDecl() const { |
1063 | 0 | return cast<FunctionTemplateDecl>( |
1064 | 0 | RedeclarableTemplateDecl::getCanonicalDecl()); |
1065 | 0 | } |
1066 | | |
1067 | | /// Retrieve the previous declaration of this function template, or |
1068 | | /// nullptr if no such declaration exists. |
1069 | 726k | FunctionTemplateDecl *getPreviousDecl() { |
1070 | 726k | return cast_or_null<FunctionTemplateDecl>( |
1071 | 726k | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
1072 | 726k | } |
1073 | 0 | const FunctionTemplateDecl *getPreviousDecl() const { |
1074 | 0 | return cast_or_null<FunctionTemplateDecl>( |
1075 | 0 | static_cast<const RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
1076 | 0 | } |
1077 | | |
1078 | 37.4k | FunctionTemplateDecl *getMostRecentDecl() { |
1079 | 37.4k | return cast<FunctionTemplateDecl>( |
1080 | 37.4k | static_cast<RedeclarableTemplateDecl *>(this) |
1081 | 37.4k | ->getMostRecentDecl()); |
1082 | 37.4k | } |
1083 | 37.4k | const FunctionTemplateDecl *getMostRecentDecl() const { |
1084 | 37.4k | return const_cast<FunctionTemplateDecl*>(this)->getMostRecentDecl(); |
1085 | 37.4k | } |
1086 | | |
1087 | 757k | FunctionTemplateDecl *getInstantiatedFromMemberTemplate() const { |
1088 | 757k | return cast_or_null<FunctionTemplateDecl>( |
1089 | 757k | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
1090 | 757k | } |
1091 | | |
1092 | | using spec_iterator = SpecIterator<FunctionTemplateSpecializationInfo>; |
1093 | | using spec_range = llvm::iterator_range<spec_iterator>; |
1094 | | |
1095 | 66.2k | spec_range specializations() const { |
1096 | 66.2k | return spec_range(spec_begin(), spec_end()); |
1097 | 66.2k | } |
1098 | | |
1099 | 66.2k | spec_iterator spec_begin() const { |
1100 | 66.2k | return makeSpecIterator(getSpecializations(), false); |
1101 | 66.2k | } |
1102 | | |
1103 | 66.2k | spec_iterator spec_end() const { |
1104 | 66.2k | return makeSpecIterator(getSpecializations(), true); |
1105 | 66.2k | } |
1106 | | |
1107 | | /// Retrieve the "injected" template arguments that correspond to the |
1108 | | /// template parameters of this function template. |
1109 | | /// |
1110 | | /// Although the C++ standard has no notion of the "injected" template |
1111 | | /// arguments for a function template, the notion is convenient when |
1112 | | /// we need to perform substitutions inside the definition of a function |
1113 | | /// template. |
1114 | | ArrayRef<TemplateArgument> getInjectedTemplateArgs(); |
1115 | | |
1116 | | /// Return whether this function template is an abbreviated function template, |
1117 | | /// e.g. `void foo(auto x)` or `template<typename T> void foo(auto x)` |
1118 | 441k | bool isAbbreviated() const { |
1119 | | // Since the invented template parameters generated from 'auto' parameters |
1120 | | // are either appended to the end of the explicit template parameter list or |
1121 | | // form a new template parameter list, we can simply observe the last |
1122 | | // parameter to determine if such a thing happened. |
1123 | 441k | const TemplateParameterList *TPL = getTemplateParameters(); |
1124 | 441k | return TPL->getParam(TPL->size() - 1)->isImplicit(); |
1125 | 441k | } |
1126 | | |
1127 | | /// Merge \p Prev with our RedeclarableTemplateDecl::Common. |
1128 | | void mergePrevDecl(FunctionTemplateDecl *Prev); |
1129 | | |
1130 | | /// Create a function template node. |
1131 | | static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
1132 | | SourceLocation L, |
1133 | | DeclarationName Name, |
1134 | | TemplateParameterList *Params, |
1135 | | NamedDecl *Decl); |
1136 | | |
1137 | | /// Create an empty function template node. |
1138 | | static FunctionTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1139 | | |
1140 | | // Implement isa/cast/dyncast support |
1141 | 624M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1142 | 624M | static bool classofKind(Kind K) { return K == FunctionTemplate; } |
1143 | | }; |
1144 | | |
1145 | | //===----------------------------------------------------------------------===// |
1146 | | // Kinds of Template Parameters |
1147 | | //===----------------------------------------------------------------------===// |
1148 | | |
1149 | | /// Defines the position of a template parameter within a template |
1150 | | /// parameter list. |
1151 | | /// |
1152 | | /// Because template parameter can be listed |
1153 | | /// sequentially for out-of-line template members, each template parameter is |
1154 | | /// given a Depth - the nesting of template parameter scopes - and a Position - |
1155 | | /// the occurrence within the parameter list. |
1156 | | /// This class is inheritedly privately by different kinds of template |
1157 | | /// parameters and is not part of the Decl hierarchy. Just a facility. |
1158 | | class TemplateParmPosition { |
1159 | | protected: |
1160 | | enum { DepthWidth = 20, PositionWidth = 12 }; |
1161 | | unsigned Depth : DepthWidth; |
1162 | | unsigned Position : PositionWidth; |
1163 | | |
1164 | | static constexpr unsigned MaxDepth = (1U << DepthWidth) - 1; |
1165 | | static constexpr unsigned MaxPosition = (1U << PositionWidth) - 1; |
1166 | | |
1167 | 757k | TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) { |
1168 | | // The input may fill maximum values to show that it is invalid. |
1169 | | // Add one here to convert it to zero. |
1170 | 757k | assert((D + 1) <= MaxDepth && |
1171 | 757k | "The depth of template parmeter position is more than 2^20!"); |
1172 | 0 | assert((P + 1) <= MaxPosition && |
1173 | 757k | "The position of template parmeter position is more than 2^12!"); |
1174 | 757k | } |
1175 | | |
1176 | | public: |
1177 | | TemplateParmPosition() = delete; |
1178 | | |
1179 | | /// Get the nesting depth of the template parameter. |
1180 | 7.43M | unsigned getDepth() const { return Depth; } |
1181 | 199k | void setDepth(unsigned D) { |
1182 | 199k | assert((D + 1) <= MaxDepth && |
1183 | 199k | "The depth of template parmeter position is more than 2^20!"); |
1184 | 0 | Depth = D; |
1185 | 199k | } |
1186 | | |
1187 | | /// Get the position of the template parameter within its parameter list. |
1188 | 2.39M | unsigned getPosition() const { return Position; } |
1189 | 200k | void setPosition(unsigned P) { |
1190 | 200k | assert((P + 1) <= MaxPosition && |
1191 | 200k | "The position of template parmeter position is more than 2^12!"); |
1192 | 0 | Position = P; |
1193 | 200k | } |
1194 | | |
1195 | | /// Get the index of the template parameter within its parameter list. |
1196 | 2.66M | unsigned getIndex() const { return Position; } |
1197 | | }; |
1198 | | |
1199 | | /// Declaration of a template type parameter. |
1200 | | /// |
1201 | | /// For example, "T" in |
1202 | | /// \code |
1203 | | /// template<typename T> class vector; |
1204 | | /// \endcode |
1205 | | class TemplateTypeParmDecl final : public TypeDecl, |
1206 | | private llvm::TrailingObjects<TemplateTypeParmDecl, TypeConstraint> { |
1207 | | /// Sema creates these on the stack during auto type deduction. |
1208 | | friend class Sema; |
1209 | | friend TrailingObjects; |
1210 | | friend class ASTDeclReader; |
1211 | | |
1212 | | /// Whether this template type parameter was declaration with |
1213 | | /// the 'typename' keyword. |
1214 | | /// |
1215 | | /// If false, it was declared with the 'class' keyword. |
1216 | | bool Typename : 1; |
1217 | | |
1218 | | /// Whether this template type parameter has a type-constraint construct. |
1219 | | bool HasTypeConstraint : 1; |
1220 | | |
1221 | | /// Whether the type constraint has been initialized. This can be false if the |
1222 | | /// constraint was not initialized yet or if there was an error forming the |
1223 | | /// type constraint. |
1224 | | bool TypeConstraintInitialized : 1; |
1225 | | |
1226 | | /// Whether this non-type template parameter is an "expanded" |
1227 | | /// parameter pack, meaning that its type is a pack expansion and we |
1228 | | /// already know the set of types that expansion expands to. |
1229 | | bool ExpandedParameterPack : 1; |
1230 | | |
1231 | | /// The number of type parameters in an expanded parameter pack. |
1232 | | unsigned NumExpanded = 0; |
1233 | | |
1234 | | /// The default template argument, if any. |
1235 | | using DefArgStorage = |
1236 | | DefaultArgStorage<TemplateTypeParmDecl, TypeSourceInfo *>; |
1237 | | DefArgStorage DefaultArgument; |
1238 | | |
1239 | | TemplateTypeParmDecl(DeclContext *DC, SourceLocation KeyLoc, |
1240 | | SourceLocation IdLoc, IdentifierInfo *Id, bool Typename, |
1241 | | bool HasTypeConstraint, Optional<unsigned> NumExpanded) |
1242 | | : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename), |
1243 | | HasTypeConstraint(HasTypeConstraint), TypeConstraintInitialized(false), |
1244 | | ExpandedParameterPack(NumExpanded), |
1245 | 5.25M | NumExpanded(NumExpanded.value_or(0)) {} |
1246 | | |
1247 | | public: |
1248 | | static TemplateTypeParmDecl *Create(const ASTContext &C, DeclContext *DC, |
1249 | | SourceLocation KeyLoc, |
1250 | | SourceLocation NameLoc, |
1251 | | unsigned D, unsigned P, |
1252 | | IdentifierInfo *Id, bool Typename, |
1253 | | bool ParameterPack, |
1254 | | bool HasTypeConstraint = false, |
1255 | | Optional<unsigned> NumExpanded = None); |
1256 | | static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C, |
1257 | | unsigned ID); |
1258 | | static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C, |
1259 | | unsigned ID, |
1260 | | bool HasTypeConstraint); |
1261 | | |
1262 | | /// Whether this template type parameter was declared with |
1263 | | /// the 'typename' keyword. |
1264 | | /// |
1265 | | /// If not, it was either declared with the 'class' keyword or with a |
1266 | | /// type-constraint (see hasTypeConstraint()). |
1267 | 1.27M | bool wasDeclaredWithTypename() const { |
1268 | 1.27M | return Typename && !HasTypeConstraint22.4k ; |
1269 | 1.27M | } |
1270 | | |
1271 | 2.60M | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } |
1272 | | |
1273 | | /// Determine whether this template parameter has a default |
1274 | | /// argument. |
1275 | 19.1M | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } |
1276 | | |
1277 | | /// Retrieve the default argument, if any. |
1278 | 29.4k | QualType getDefaultArgument() const { |
1279 | 29.4k | return DefaultArgument.get()->getType(); |
1280 | 29.4k | } |
1281 | | |
1282 | | /// Retrieves the default argument's source information, if any. |
1283 | 1.95M | TypeSourceInfo *getDefaultArgumentInfo() const { |
1284 | 1.95M | return DefaultArgument.get(); |
1285 | 1.95M | } |
1286 | | |
1287 | | /// Retrieves the location of the default argument declaration. |
1288 | | SourceLocation getDefaultArgumentLoc() const; |
1289 | | |
1290 | | /// Determines whether the default argument was inherited |
1291 | | /// from a previous declaration of this template. |
1292 | 157k | bool defaultArgumentWasInherited() const { |
1293 | 157k | return DefaultArgument.isInherited(); |
1294 | 157k | } |
1295 | | |
1296 | | /// Set the default argument for this template parameter. |
1297 | 397k | void setDefaultArgument(TypeSourceInfo *DefArg) { |
1298 | 397k | DefaultArgument.set(DefArg); |
1299 | 397k | } |
1300 | | |
1301 | | /// Set that this default argument was inherited from another |
1302 | | /// parameter. |
1303 | | void setInheritedDefaultArgument(const ASTContext &C, |
1304 | 59.7k | TemplateTypeParmDecl *Prev) { |
1305 | 59.7k | DefaultArgument.setInherited(C, Prev); |
1306 | 59.7k | } |
1307 | | |
1308 | | /// Removes the default argument of this template parameter. |
1309 | 49 | void removeDefaultArgument() { |
1310 | 49 | DefaultArgument.clear(); |
1311 | 49 | } |
1312 | | |
1313 | | /// Set whether this template type parameter was declared with |
1314 | | /// the 'typename' or 'class' keyword. |
1315 | 1.43M | void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; } |
1316 | | |
1317 | | /// Retrieve the depth of the template parameter. |
1318 | | unsigned getDepth() const; |
1319 | | |
1320 | | /// Retrieve the index of the template parameter. |
1321 | | unsigned getIndex() const; |
1322 | | |
1323 | | /// Returns whether this is a parameter pack. |
1324 | | bool isParameterPack() const; |
1325 | | |
1326 | | /// Whether this parameter pack is a pack expansion. |
1327 | | /// |
1328 | | /// A template type template parameter pack can be a pack expansion if its |
1329 | | /// type-constraint contains an unexpanded parameter pack. |
1330 | 2.11k | bool isPackExpansion() const { |
1331 | 2.11k | if (!isParameterPack()) |
1332 | 2.11k | return false; |
1333 | 4 | if (const TypeConstraint *TC = getTypeConstraint()) |
1334 | 4 | if (TC->hasExplicitTemplateArgs()) |
1335 | 4 | for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments()) |
1336 | 5 | if (ArgLoc.getArgument().containsUnexpandedParameterPack()) |
1337 | 3 | return true; |
1338 | 1 | return false; |
1339 | 4 | } |
1340 | | |
1341 | | /// Whether this parameter is a template type parameter pack that has a known |
1342 | | /// list of different type-constraints at different positions. |
1343 | | /// |
1344 | | /// A parameter pack is an expanded parameter pack when the original |
1345 | | /// parameter pack's type-constraint was itself a pack expansion, and that |
1346 | | /// expansion has already been expanded. For example, given: |
1347 | | /// |
1348 | | /// \code |
1349 | | /// template<typename ...Types> |
1350 | | /// struct X { |
1351 | | /// template<convertible_to<Types> ...Convertibles> |
1352 | | /// struct Y { /* ... */ }; |
1353 | | /// }; |
1354 | | /// \endcode |
1355 | | /// |
1356 | | /// The parameter pack \c Convertibles has (convertible_to<Types> && ...) as |
1357 | | /// its type-constraint. When \c Types is supplied with template arguments by |
1358 | | /// instantiating \c X, the instantiation of \c Convertibles becomes an |
1359 | | /// expanded parameter pack. For example, instantiating |
1360 | | /// \c X<int, unsigned int> results in \c Convertibles being an expanded |
1361 | | /// parameter pack of size 2 (use getNumExpansionTypes() to get this number). |
1362 | 14.4M | bool isExpandedParameterPack() const { return ExpandedParameterPack; } |
1363 | | |
1364 | | /// Retrieves the number of parameters in an expanded parameter pack. |
1365 | 10 | unsigned getNumExpansionParameters() const { |
1366 | 10 | assert(ExpandedParameterPack && "Not an expansion parameter pack"); |
1367 | 0 | return NumExpanded; |
1368 | 10 | } |
1369 | | |
1370 | | /// Returns the type constraint associated with this template parameter (if |
1371 | | /// any). |
1372 | 10.6M | const TypeConstraint *getTypeConstraint() const { |
1373 | 10.6M | return TypeConstraintInitialized ? getTrailingObjects<TypeConstraint>()23.2k : |
1374 | 10.6M | nullptr10.5M ; |
1375 | 10.6M | } |
1376 | | |
1377 | | void setTypeConstraint(NestedNameSpecifierLoc NNS, |
1378 | | DeclarationNameInfo NameInfo, NamedDecl *FoundDecl, |
1379 | | ConceptDecl *CD, |
1380 | | const ASTTemplateArgumentListInfo *ArgsAsWritten, |
1381 | | Expr *ImmediatelyDeclaredConstraint); |
1382 | | |
1383 | | /// Determine whether this template parameter has a type-constraint. |
1384 | 7.13M | bool hasTypeConstraint() const { |
1385 | 7.13M | return HasTypeConstraint; |
1386 | 7.13M | } |
1387 | | |
1388 | | /// \brief Get the associated-constraints of this template parameter. |
1389 | | /// This will either be the immediately-introduced constraint or empty. |
1390 | | /// |
1391 | | /// Use this instead of getConstraintExpression for concepts APIs that |
1392 | | /// accept an ArrayRef of constraint expressions. |
1393 | 0 | void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const { |
1394 | 0 | if (HasTypeConstraint) |
1395 | 0 | AC.push_back(getTypeConstraint()->getImmediatelyDeclaredConstraint()); |
1396 | 0 | } |
1397 | | |
1398 | | SourceRange getSourceRange() const override LLVM_READONLY; |
1399 | | |
1400 | | // Implement isa/cast/dyncast/etc. |
1401 | 492M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1402 | 492M | static bool classofKind(Kind K) { return K == TemplateTypeParm; } |
1403 | | }; |
1404 | | |
1405 | | /// NonTypeTemplateParmDecl - Declares a non-type template parameter, |
1406 | | /// e.g., "Size" in |
1407 | | /// @code |
1408 | | /// template<int Size> class array { }; |
1409 | | /// @endcode |
1410 | | class NonTypeTemplateParmDecl final |
1411 | | : public DeclaratorDecl, |
1412 | | protected TemplateParmPosition, |
1413 | | private llvm::TrailingObjects<NonTypeTemplateParmDecl, |
1414 | | std::pair<QualType, TypeSourceInfo *>, |
1415 | | Expr *> { |
1416 | | friend class ASTDeclReader; |
1417 | | friend TrailingObjects; |
1418 | | |
1419 | | /// The default template argument, if any, and whether or not |
1420 | | /// it was inherited. |
1421 | | using DefArgStorage = DefaultArgStorage<NonTypeTemplateParmDecl, Expr *>; |
1422 | | DefArgStorage DefaultArgument; |
1423 | | |
1424 | | // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index |
1425 | | // down here to save memory. |
1426 | | |
1427 | | /// Whether this non-type template parameter is a parameter pack. |
1428 | | bool ParameterPack; |
1429 | | |
1430 | | /// Whether this non-type template parameter is an "expanded" |
1431 | | /// parameter pack, meaning that its type is a pack expansion and we |
1432 | | /// already know the set of types that expansion expands to. |
1433 | | bool ExpandedParameterPack = false; |
1434 | | |
1435 | | /// The number of types in an expanded parameter pack. |
1436 | | unsigned NumExpandedTypes = 0; |
1437 | | |
1438 | | size_t numTrailingObjects( |
1439 | 7 | OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const { |
1440 | 7 | return NumExpandedTypes; |
1441 | 7 | } |
1442 | | |
1443 | | NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc, |
1444 | | SourceLocation IdLoc, unsigned D, unsigned P, |
1445 | | IdentifierInfo *Id, QualType T, |
1446 | | bool ParameterPack, TypeSourceInfo *TInfo) |
1447 | | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
1448 | 713k | TemplateParmPosition(D, P), ParameterPack(ParameterPack) {} |
1449 | | |
1450 | | NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc, |
1451 | | SourceLocation IdLoc, unsigned D, unsigned P, |
1452 | | IdentifierInfo *Id, QualType T, |
1453 | | TypeSourceInfo *TInfo, |
1454 | | ArrayRef<QualType> ExpandedTypes, |
1455 | | ArrayRef<TypeSourceInfo *> ExpandedTInfos); |
1456 | | |
1457 | | public: |
1458 | | static NonTypeTemplateParmDecl * |
1459 | | Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1460 | | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, |
1461 | | QualType T, bool ParameterPack, TypeSourceInfo *TInfo); |
1462 | | |
1463 | | static NonTypeTemplateParmDecl * |
1464 | | Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1465 | | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, |
1466 | | QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes, |
1467 | | ArrayRef<TypeSourceInfo *> ExpandedTInfos); |
1468 | | |
1469 | | static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C, |
1470 | | unsigned ID, |
1471 | | bool HasTypeConstraint); |
1472 | | static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C, |
1473 | | unsigned ID, |
1474 | | unsigned NumExpandedTypes, |
1475 | | bool HasTypeConstraint); |
1476 | | |
1477 | | using TemplateParmPosition::getDepth; |
1478 | | using TemplateParmPosition::setDepth; |
1479 | | using TemplateParmPosition::getPosition; |
1480 | | using TemplateParmPosition::setPosition; |
1481 | | using TemplateParmPosition::getIndex; |
1482 | | |
1483 | | SourceRange getSourceRange() const override LLVM_READONLY; |
1484 | | |
1485 | 770k | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } |
1486 | | |
1487 | | /// Determine whether this template parameter has a default |
1488 | | /// argument. |
1489 | 2.75M | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } |
1490 | | |
1491 | | /// Retrieve the default argument, if any. |
1492 | 746k | Expr *getDefaultArgument() const { return DefaultArgument.get(); } |
1493 | | |
1494 | | /// Retrieve the location of the default argument, if any. |
1495 | | SourceLocation getDefaultArgumentLoc() const; |
1496 | | |
1497 | | /// Determines whether the default argument was inherited |
1498 | | /// from a previous declaration of this template. |
1499 | 88.9k | bool defaultArgumentWasInherited() const { |
1500 | 88.9k | return DefaultArgument.isInherited(); |
1501 | 88.9k | } |
1502 | | |
1503 | | /// Set the default argument for this template parameter, and |
1504 | | /// whether that default argument was inherited from another |
1505 | | /// declaration. |
1506 | 196k | void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); } |
1507 | | void setInheritedDefaultArgument(const ASTContext &C, |
1508 | 2.04k | NonTypeTemplateParmDecl *Parm) { |
1509 | 2.04k | DefaultArgument.setInherited(C, Parm); |
1510 | 2.04k | } |
1511 | | |
1512 | | /// Removes the default argument of this template parameter. |
1513 | 12 | void removeDefaultArgument() { DefaultArgument.clear(); } |
1514 | | |
1515 | | /// Whether this parameter is a non-type template parameter pack. |
1516 | | /// |
1517 | | /// If the parameter is a parameter pack, the type may be a |
1518 | | /// \c PackExpansionType. In the following example, the \c Dims parameter |
1519 | | /// is a parameter pack (whose type is 'unsigned'). |
1520 | | /// |
1521 | | /// \code |
1522 | | /// template<typename T, unsigned ...Dims> struct multi_array; |
1523 | | /// \endcode |
1524 | 15.2M | bool isParameterPack() const { return ParameterPack; } |
1525 | | |
1526 | | /// Whether this parameter pack is a pack expansion. |
1527 | | /// |
1528 | | /// A non-type template parameter pack is a pack expansion if its type |
1529 | | /// contains an unexpanded parameter pack. In this case, we will have |
1530 | | /// built a PackExpansionType wrapping the type. |
1531 | 157k | bool isPackExpansion() const { |
1532 | 157k | return ParameterPack && getType()->getAs<PackExpansionType>()30.9k ; |
1533 | 157k | } |
1534 | | |
1535 | | /// Whether this parameter is a non-type template parameter pack |
1536 | | /// that has a known list of different types at different positions. |
1537 | | /// |
1538 | | /// A parameter pack is an expanded parameter pack when the original |
1539 | | /// parameter pack's type was itself a pack expansion, and that expansion |
1540 | | /// has already been expanded. For example, given: |
1541 | | /// |
1542 | | /// \code |
1543 | | /// template<typename ...Types> |
1544 | | /// struct X { |
1545 | | /// template<Types ...Values> |
1546 | | /// struct Y { /* ... */ }; |
1547 | | /// }; |
1548 | | /// \endcode |
1549 | | /// |
1550 | | /// The parameter pack \c Values has a \c PackExpansionType as its type, |
1551 | | /// which expands \c Types. When \c Types is supplied with template arguments |
1552 | | /// by instantiating \c X, the instantiation of \c Values becomes an |
1553 | | /// expanded parameter pack. For example, instantiating |
1554 | | /// \c X<int, unsigned int> results in \c Values being an expanded parameter |
1555 | | /// pack with expansion types \c int and \c unsigned int. |
1556 | | /// |
1557 | | /// The \c getExpansionType() and \c getExpansionTypeSourceInfo() functions |
1558 | | /// return the expansion types. |
1559 | 4.34M | bool isExpandedParameterPack() const { return ExpandedParameterPack; } |
1560 | | |
1561 | | /// Retrieves the number of expansion types in an expanded parameter |
1562 | | /// pack. |
1563 | 292 | unsigned getNumExpansionTypes() const { |
1564 | 292 | assert(ExpandedParameterPack && "Not an expansion parameter pack"); |
1565 | 0 | return NumExpandedTypes; |
1566 | 292 | } |
1567 | | |
1568 | | /// Retrieve a particular expansion type within an expanded parameter |
1569 | | /// pack. |
1570 | 267 | QualType getExpansionType(unsigned I) const { |
1571 | 267 | assert(I < NumExpandedTypes && "Out-of-range expansion type index"); |
1572 | 0 | auto TypesAndInfos = |
1573 | 267 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
1574 | 267 | return TypesAndInfos[I].first; |
1575 | 267 | } |
1576 | | |
1577 | | /// Retrieve a particular expansion type source info within an |
1578 | | /// expanded parameter pack. |
1579 | 13 | TypeSourceInfo *getExpansionTypeSourceInfo(unsigned I) const { |
1580 | 13 | assert(I < NumExpandedTypes && "Out-of-range expansion type index"); |
1581 | 0 | auto TypesAndInfos = |
1582 | 13 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
1583 | 13 | return TypesAndInfos[I].second; |
1584 | 13 | } |
1585 | | |
1586 | | /// Return the constraint introduced by the placeholder type of this non-type |
1587 | | /// template parameter (if any). |
1588 | 21.8k | Expr *getPlaceholderTypeConstraint() const { |
1589 | 21.8k | return hasPlaceholderTypeConstraint() ? *getTrailingObjects<Expr *>()5 : |
1590 | 21.8k | nullptr21.8k ; |
1591 | 21.8k | } |
1592 | | |
1593 | 2 | void setPlaceholderTypeConstraint(Expr *E) { |
1594 | 2 | *getTrailingObjects<Expr *>() = E; |
1595 | 2 | } |
1596 | | |
1597 | | /// Determine whether this non-type template parameter's type has a |
1598 | | /// placeholder with a type-constraint. |
1599 | 969k | bool hasPlaceholderTypeConstraint() const { |
1600 | 969k | auto *AT = getType()->getContainedAutoType(); |
1601 | 969k | return AT && AT->isConstrained()242 ; |
1602 | 969k | } |
1603 | | |
1604 | | /// \brief Get the associated-constraints of this template parameter. |
1605 | | /// This will either be a vector of size 1 containing the immediately-declared |
1606 | | /// constraint introduced by the placeholder type, or an empty vector. |
1607 | | /// |
1608 | | /// Use this instead of getPlaceholderImmediatelyDeclaredConstraint for |
1609 | | /// concepts APIs that accept an ArrayRef of constraint expressions. |
1610 | 0 | void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const { |
1611 | 0 | if (Expr *E = getPlaceholderTypeConstraint()) |
1612 | 0 | AC.push_back(E); |
1613 | 0 | } |
1614 | | |
1615 | | // Implement isa/cast/dyncast/etc. |
1616 | 440M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1617 | 440M | static bool classofKind(Kind K) { return K == NonTypeTemplateParm; } |
1618 | | }; |
1619 | | |
1620 | | /// TemplateTemplateParmDecl - Declares a template template parameter, |
1621 | | /// e.g., "T" in |
1622 | | /// @code |
1623 | | /// template <template <typename> class T> class container { }; |
1624 | | /// @endcode |
1625 | | /// A template template parameter is a TemplateDecl because it defines the |
1626 | | /// name of a template and the template parameters allowable for substitution. |
1627 | | class TemplateTemplateParmDecl final |
1628 | | : public TemplateDecl, |
1629 | | protected TemplateParmPosition, |
1630 | | private llvm::TrailingObjects<TemplateTemplateParmDecl, |
1631 | | TemplateParameterList *> { |
1632 | | /// The default template argument, if any. |
1633 | | using DefArgStorage = |
1634 | | DefaultArgStorage<TemplateTemplateParmDecl, TemplateArgumentLoc *>; |
1635 | | DefArgStorage DefaultArgument; |
1636 | | |
1637 | | /// Whether this parameter is a parameter pack. |
1638 | | bool ParameterPack; |
1639 | | |
1640 | | /// Whether this template template parameter is an "expanded" |
1641 | | /// parameter pack, meaning that it is a pack expansion and we |
1642 | | /// already know the set of template parameters that expansion expands to. |
1643 | | bool ExpandedParameterPack = false; |
1644 | | |
1645 | | /// The number of parameters in an expanded parameter pack. |
1646 | | unsigned NumExpandedParams = 0; |
1647 | | |
1648 | | TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, |
1649 | | unsigned D, unsigned P, bool ParameterPack, |
1650 | | IdentifierInfo *Id, TemplateParameterList *Params) |
1651 | | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), |
1652 | 43.8k | TemplateParmPosition(D, P), ParameterPack(ParameterPack) {} |
1653 | | |
1654 | | TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, |
1655 | | unsigned D, unsigned P, |
1656 | | IdentifierInfo *Id, TemplateParameterList *Params, |
1657 | | ArrayRef<TemplateParameterList *> Expansions); |
1658 | | |
1659 | | void anchor() override; |
1660 | | |
1661 | | public: |
1662 | | friend class ASTDeclReader; |
1663 | | friend class ASTDeclWriter; |
1664 | | friend TrailingObjects; |
1665 | | |
1666 | | static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC, |
1667 | | SourceLocation L, unsigned D, |
1668 | | unsigned P, bool ParameterPack, |
1669 | | IdentifierInfo *Id, |
1670 | | TemplateParameterList *Params); |
1671 | | static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC, |
1672 | | SourceLocation L, unsigned D, |
1673 | | unsigned P, |
1674 | | IdentifierInfo *Id, |
1675 | | TemplateParameterList *Params, |
1676 | | ArrayRef<TemplateParameterList *> Expansions); |
1677 | | |
1678 | | static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C, |
1679 | | unsigned ID); |
1680 | | static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C, |
1681 | | unsigned ID, |
1682 | | unsigned NumExpansions); |
1683 | | |
1684 | | using TemplateParmPosition::getDepth; |
1685 | | using TemplateParmPosition::setDepth; |
1686 | | using TemplateParmPosition::getPosition; |
1687 | | using TemplateParmPosition::setPosition; |
1688 | | using TemplateParmPosition::getIndex; |
1689 | | |
1690 | | /// Whether this template template parameter is a template |
1691 | | /// parameter pack. |
1692 | | /// |
1693 | | /// \code |
1694 | | /// template<template <class T> ...MetaFunctions> struct Apply; |
1695 | | /// \endcode |
1696 | 498k | bool isParameterPack() const { return ParameterPack; } |
1697 | | |
1698 | | /// Whether this parameter pack is a pack expansion. |
1699 | | /// |
1700 | | /// A template template parameter pack is a pack expansion if its template |
1701 | | /// parameter list contains an unexpanded parameter pack. |
1702 | 9.93k | bool isPackExpansion() const { |
1703 | 9.93k | return ParameterPack && |
1704 | 9.93k | getTemplateParameters()->containsUnexpandedParameterPack()126 ; |
1705 | 9.93k | } |
1706 | | |
1707 | | /// Whether this parameter is a template template parameter pack that |
1708 | | /// has a known list of different template parameter lists at different |
1709 | | /// positions. |
1710 | | /// |
1711 | | /// A parameter pack is an expanded parameter pack when the original parameter |
1712 | | /// pack's template parameter list was itself a pack expansion, and that |
1713 | | /// expansion has already been expanded. For exampe, given: |
1714 | | /// |
1715 | | /// \code |
1716 | | /// template<typename...Types> struct Outer { |
1717 | | /// template<template<Types> class...Templates> struct Inner; |
1718 | | /// }; |
1719 | | /// \endcode |
1720 | | /// |
1721 | | /// The parameter pack \c Templates is a pack expansion, which expands the |
1722 | | /// pack \c Types. When \c Types is supplied with template arguments by |
1723 | | /// instantiating \c Outer, the instantiation of \c Templates is an expanded |
1724 | | /// parameter pack. |
1725 | 118k | bool isExpandedParameterPack() const { return ExpandedParameterPack; } |
1726 | | |
1727 | | /// Retrieves the number of expansion template parameters in |
1728 | | /// an expanded parameter pack. |
1729 | 8.33k | unsigned getNumExpansionTemplateParameters() const { |
1730 | 8.33k | assert(ExpandedParameterPack && "Not an expansion parameter pack"); |
1731 | 0 | return NumExpandedParams; |
1732 | 8.33k | } |
1733 | | |
1734 | | /// Retrieve a particular expansion type within an expanded parameter |
1735 | | /// pack. |
1736 | 8.32k | TemplateParameterList *getExpansionTemplateParameters(unsigned I) const { |
1737 | 8.32k | assert(I < NumExpandedParams && "Out-of-range expansion type index"); |
1738 | 0 | return getTrailingObjects<TemplateParameterList *>()[I]; |
1739 | 8.32k | } |
1740 | | |
1741 | 2.74k | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } |
1742 | | |
1743 | | /// Determine whether this template parameter has a default |
1744 | | /// argument. |
1745 | 63.6k | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } |
1746 | | |
1747 | | /// Retrieve the default argument, if any. |
1748 | 66.0k | const TemplateArgumentLoc &getDefaultArgument() const { |
1749 | 66.0k | static const TemplateArgumentLoc NoneLoc; |
1750 | 66.0k | return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc0 ; |
1751 | 66.0k | } |
1752 | | |
1753 | | /// Retrieve the location of the default argument, if any. |
1754 | | SourceLocation getDefaultArgumentLoc() const; |
1755 | | |
1756 | | /// Determines whether the default argument was inherited |
1757 | | /// from a previous declaration of this template. |
1758 | 7.95k | bool defaultArgumentWasInherited() const { |
1759 | 7.95k | return DefaultArgument.isInherited(); |
1760 | 7.95k | } |
1761 | | |
1762 | | /// Set the default argument for this template parameter, and |
1763 | | /// whether that default argument was inherited from another |
1764 | | /// declaration. |
1765 | | void setDefaultArgument(const ASTContext &C, |
1766 | | const TemplateArgumentLoc &DefArg); |
1767 | | void setInheritedDefaultArgument(const ASTContext &C, |
1768 | 96 | TemplateTemplateParmDecl *Prev) { |
1769 | 96 | DefaultArgument.setInherited(C, Prev); |
1770 | 96 | } |
1771 | | |
1772 | | /// Removes the default argument of this template parameter. |
1773 | 10 | void removeDefaultArgument() { DefaultArgument.clear(); } |
1774 | | |
1775 | 121 | SourceRange getSourceRange() const override LLVM_READONLY { |
1776 | 121 | SourceLocation End = getLocation(); |
1777 | 121 | if (hasDefaultArgument() && !defaultArgumentWasInherited()12 ) |
1778 | 11 | End = getDefaultArgument().getSourceRange().getEnd(); |
1779 | 121 | return SourceRange(getTemplateParameters()->getTemplateLoc(), End); |
1780 | 121 | } |
1781 | | |
1782 | | // Implement isa/cast/dyncast/etc. |
1783 | 110M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1784 | 110M | static bool classofKind(Kind K) { return K == TemplateTemplateParm; } |
1785 | | }; |
1786 | | |
1787 | | /// Represents the builtin template declaration which is used to |
1788 | | /// implement __make_integer_seq and other builtin templates. It serves |
1789 | | /// no real purpose beyond existing as a place to hold template parameters. |
1790 | | class BuiltinTemplateDecl : public TemplateDecl { |
1791 | | BuiltinTemplateKind BTK; |
1792 | | |
1793 | | BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC, |
1794 | | DeclarationName Name, BuiltinTemplateKind BTK); |
1795 | | |
1796 | | void anchor() override; |
1797 | | |
1798 | | public: |
1799 | | // Implement isa/cast/dyncast support |
1800 | 1.75M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1801 | 1.75M | static bool classofKind(Kind K) { return K == BuiltinTemplate; } |
1802 | | |
1803 | | static BuiltinTemplateDecl *Create(const ASTContext &C, DeclContext *DC, |
1804 | | DeclarationName Name, |
1805 | 1.14k | BuiltinTemplateKind BTK) { |
1806 | 1.14k | return new (C, DC) BuiltinTemplateDecl(C, DC, Name, BTK); |
1807 | 1.14k | } |
1808 | | |
1809 | 4 | SourceRange getSourceRange() const override LLVM_READONLY { |
1810 | 4 | return {}; |
1811 | 4 | } |
1812 | | |
1813 | 1.96k | BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; } |
1814 | | }; |
1815 | | |
1816 | | /// Represents a class template specialization, which refers to |
1817 | | /// a class template with a given set of template arguments. |
1818 | | /// |
1819 | | /// Class template specializations represent both explicit |
1820 | | /// specialization of class templates, as in the example below, and |
1821 | | /// implicit instantiations of class templates. |
1822 | | /// |
1823 | | /// \code |
1824 | | /// template<typename T> class array; |
1825 | | /// |
1826 | | /// template<> |
1827 | | /// class array<bool> { }; // class template specialization array<bool> |
1828 | | /// \endcode |
1829 | | class ClassTemplateSpecializationDecl |
1830 | | : public CXXRecordDecl, public llvm::FoldingSetNode { |
1831 | | /// Structure that stores information about a class template |
1832 | | /// specialization that was instantiated from a class template partial |
1833 | | /// specialization. |
1834 | | struct SpecializedPartialSpecialization { |
1835 | | /// The class template partial specialization from which this |
1836 | | /// class template specialization was instantiated. |
1837 | | ClassTemplatePartialSpecializationDecl *PartialSpecialization; |
1838 | | |
1839 | | /// The template argument list deduced for the class template |
1840 | | /// partial specialization itself. |
1841 | | const TemplateArgumentList *TemplateArgs; |
1842 | | }; |
1843 | | |
1844 | | /// The template that this specialization specializes |
1845 | | llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *> |
1846 | | SpecializedTemplate; |
1847 | | |
1848 | | /// Further info for explicit template specialization/instantiation. |
1849 | | struct ExplicitSpecializationInfo { |
1850 | | /// The type-as-written. |
1851 | | TypeSourceInfo *TypeAsWritten = nullptr; |
1852 | | |
1853 | | /// The location of the extern keyword. |
1854 | | SourceLocation ExternLoc; |
1855 | | |
1856 | | /// The location of the template keyword. |
1857 | | SourceLocation TemplateKeywordLoc; |
1858 | | |
1859 | 328k | ExplicitSpecializationInfo() = default; |
1860 | | }; |
1861 | | |
1862 | | /// Further info for explicit template specialization/instantiation. |
1863 | | /// Does not apply to implicit specializations. |
1864 | | ExplicitSpecializationInfo *ExplicitInfo = nullptr; |
1865 | | |
1866 | | /// The template arguments used to describe this specialization. |
1867 | | const TemplateArgumentList *TemplateArgs; |
1868 | | |
1869 | | /// The point where this template was instantiated (if any) |
1870 | | SourceLocation PointOfInstantiation; |
1871 | | |
1872 | | /// The kind of specialization this declaration refers to. |
1873 | | /// Really a value of type TemplateSpecializationKind. |
1874 | | unsigned SpecializationKind : 3; |
1875 | | |
1876 | | protected: |
1877 | | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
1878 | | DeclContext *DC, SourceLocation StartLoc, |
1879 | | SourceLocation IdLoc, |
1880 | | ClassTemplateDecl *SpecializedTemplate, |
1881 | | ArrayRef<TemplateArgument> Args, |
1882 | | ClassTemplateSpecializationDecl *PrevDecl); |
1883 | | |
1884 | | explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); |
1885 | | |
1886 | | public: |
1887 | | friend class ASTDeclReader; |
1888 | | friend class ASTDeclWriter; |
1889 | | |
1890 | | static ClassTemplateSpecializationDecl * |
1891 | | Create(ASTContext &Context, TagKind TK, DeclContext *DC, |
1892 | | SourceLocation StartLoc, SourceLocation IdLoc, |
1893 | | ClassTemplateDecl *SpecializedTemplate, |
1894 | | ArrayRef<TemplateArgument> Args, |
1895 | | ClassTemplateSpecializationDecl *PrevDecl); |
1896 | | static ClassTemplateSpecializationDecl * |
1897 | | CreateDeserialized(ASTContext &C, unsigned ID); |
1898 | | |
1899 | | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, |
1900 | | bool Qualified) const override; |
1901 | | |
1902 | | // FIXME: This is broken. CXXRecordDecl::getMostRecentDecl() returns a |
1903 | | // different "most recent" declaration from this function for the same |
1904 | | // declaration, because we don't override getMostRecentDeclImpl(). But |
1905 | | // it's not clear that we should override that, because the most recent |
1906 | | // declaration as a CXXRecordDecl sometimes is the injected-class-name. |
1907 | 2.58M | ClassTemplateSpecializationDecl *getMostRecentDecl() { |
1908 | 2.58M | return cast<ClassTemplateSpecializationDecl>( |
1909 | 2.58M | getMostRecentNonInjectedDecl()); |
1910 | 2.58M | } |
1911 | | |
1912 | | /// Retrieve the template that this specialization specializes. |
1913 | | ClassTemplateDecl *getSpecializedTemplate() const; |
1914 | | |
1915 | | /// Retrieve the template arguments of the class template |
1916 | | /// specialization. |
1917 | 9.93M | const TemplateArgumentList &getTemplateArgs() const { |
1918 | 9.93M | return *TemplateArgs; |
1919 | 9.93M | } |
1920 | | |
1921 | 8.82k | void setTemplateArgs(TemplateArgumentList *Args) { |
1922 | 8.82k | TemplateArgs = Args; |
1923 | 8.82k | } |
1924 | | |
1925 | | /// Determine the kind of specialization that this |
1926 | | /// declaration represents. |
1927 | 12.9M | TemplateSpecializationKind getSpecializationKind() const { |
1928 | 12.9M | return static_cast<TemplateSpecializationKind>(SpecializationKind); |
1929 | 12.9M | } |
1930 | | |
1931 | 2.42M | bool isExplicitSpecialization() const { |
1932 | 2.42M | return getSpecializationKind() == TSK_ExplicitSpecialization; |
1933 | 2.42M | } |
1934 | | |
1935 | | /// Is this an explicit specialization at class scope (within the class that |
1936 | | /// owns the primary template)? For example: |
1937 | | /// |
1938 | | /// \code |
1939 | | /// template<typename T> struct Outer { |
1940 | | /// template<typename U> struct Inner; |
1941 | | /// template<> struct Inner; // class-scope explicit specialization |
1942 | | /// }; |
1943 | | /// \endcode |
1944 | 2.27M | bool isClassScopeExplicitSpecialization() const { |
1945 | 2.27M | return isExplicitSpecialization() && |
1946 | 2.27M | isa<CXXRecordDecl>(getLexicalDeclContext())222 ; |
1947 | 2.27M | } |
1948 | | |
1949 | | /// True if this declaration is an explicit specialization, |
1950 | | /// explicit instantiation declaration, or explicit instantiation |
1951 | | /// definition. |
1952 | 1.13M | bool isExplicitInstantiationOrSpecialization() const { |
1953 | 1.13M | return isTemplateExplicitInstantiationOrSpecialization( |
1954 | 1.13M | getTemplateSpecializationKind()); |
1955 | 1.13M | } |
1956 | | |
1957 | 0 | void setSpecializedTemplate(ClassTemplateDecl *Specialized) { |
1958 | 0 | SpecializedTemplate = Specialized; |
1959 | 0 | } |
1960 | | |
1961 | 1.60M | void setSpecializationKind(TemplateSpecializationKind TSK) { |
1962 | 1.60M | SpecializationKind = TSK; |
1963 | 1.60M | } |
1964 | | |
1965 | | /// Get the point of instantiation (if any), or null if none. |
1966 | 228k | SourceLocation getPointOfInstantiation() const { |
1967 | 228k | return PointOfInstantiation; |
1968 | 228k | } |
1969 | | |
1970 | 977k | void setPointOfInstantiation(SourceLocation Loc) { |
1971 | 977k | assert(Loc.isValid() && "point of instantiation must be valid!"); |
1972 | 0 | PointOfInstantiation = Loc; |
1973 | 977k | } |
1974 | | |
1975 | | /// If this class template specialization is an instantiation of |
1976 | | /// a template (rather than an explicit specialization), return the |
1977 | | /// class template or class template partial specialization from which it |
1978 | | /// was instantiated. |
1979 | | llvm::PointerUnion<ClassTemplateDecl *, |
1980 | | ClassTemplatePartialSpecializationDecl *> |
1981 | 1.12M | getInstantiatedFrom() const { |
1982 | 1.12M | if (!isTemplateInstantiation(getSpecializationKind())) |
1983 | 76.3k | return llvm::PointerUnion<ClassTemplateDecl *, |
1984 | 76.3k | ClassTemplatePartialSpecializationDecl *>(); |
1985 | | |
1986 | 1.04M | return getSpecializedTemplateOrPartial(); |
1987 | 1.12M | } |
1988 | | |
1989 | | /// Retrieve the class template or class template partial |
1990 | | /// specialization which was specialized by this. |
1991 | | llvm::PointerUnion<ClassTemplateDecl *, |
1992 | | ClassTemplatePartialSpecializationDecl *> |
1993 | 4.20M | getSpecializedTemplateOrPartial() const { |
1994 | 4.20M | if (const auto *PartialSpec = |
1995 | 4.20M | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
1996 | 425k | return PartialSpec->PartialSpecialization; |
1997 | | |
1998 | 3.77M | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
1999 | 4.20M | } |
2000 | | |
2001 | | /// Retrieve the set of template arguments that should be used |
2002 | | /// to instantiate members of the class template or class template partial |
2003 | | /// specialization from which this class template specialization was |
2004 | | /// instantiated. |
2005 | | /// |
2006 | | /// \returns For a class template specialization instantiated from the primary |
2007 | | /// template, this function will return the same template arguments as |
2008 | | /// getTemplateArgs(). For a class template specialization instantiated from |
2009 | | /// a class template partial specialization, this function will return the |
2010 | | /// deduced template arguments for the class template partial specialization |
2011 | | /// itself. |
2012 | 2.28M | const TemplateArgumentList &getTemplateInstantiationArgs() const { |
2013 | 2.28M | if (const auto *PartialSpec = |
2014 | 2.28M | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
2015 | 328k | return *PartialSpec->TemplateArgs; |
2016 | | |
2017 | 1.96M | return getTemplateArgs(); |
2018 | 2.28M | } |
2019 | | |
2020 | | /// Note that this class template specialization is actually an |
2021 | | /// instantiation of the given class template partial specialization whose |
2022 | | /// template arguments have been deduced. |
2023 | | void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, |
2024 | 212k | const TemplateArgumentList *TemplateArgs) { |
2025 | 212k | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && |
2026 | 212k | "Already set to a class template partial specialization!"); |
2027 | 0 | auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); |
2028 | 212k | PS->PartialSpecialization = PartialSpec; |
2029 | 212k | PS->TemplateArgs = TemplateArgs; |
2030 | 212k | SpecializedTemplate = PS; |
2031 | 212k | } |
2032 | | |
2033 | | /// Note that this class template specialization is an instantiation |
2034 | | /// of the given class template. |
2035 | 8.82k | void setInstantiationOf(ClassTemplateDecl *TemplDecl) { |
2036 | 8.82k | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && |
2037 | 8.82k | "Previously set to a class template partial specialization!"); |
2038 | 0 | SpecializedTemplate = TemplDecl; |
2039 | 8.82k | } |
2040 | | |
2041 | | /// Sets the type of this specialization as it was written by |
2042 | | /// the user. This will be a class template specialization type. |
2043 | 275k | void setTypeAsWritten(TypeSourceInfo *T) { |
2044 | 275k | if (!ExplicitInfo) |
2045 | 275k | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
2046 | 275k | ExplicitInfo->TypeAsWritten = T; |
2047 | 275k | } |
2048 | | |
2049 | | /// Gets the type of this specialization as it was written by |
2050 | | /// the user, if it was so written. |
2051 | 936k | TypeSourceInfo *getTypeAsWritten() const { |
2052 | 936k | return ExplicitInfo ? ExplicitInfo->TypeAsWritten76.4k : nullptr859k ; |
2053 | 936k | } |
2054 | | |
2055 | | /// Gets the location of the extern keyword, if present. |
2056 | 493k | SourceLocation getExternLoc() const { |
2057 | 493k | return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation()0 ; |
2058 | 493k | } |
2059 | | |
2060 | | /// Sets the location of the extern keyword. |
2061 | 9.06k | void setExternLoc(SourceLocation Loc) { |
2062 | 9.06k | if (!ExplicitInfo) |
2063 | 0 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
2064 | 9.06k | ExplicitInfo->ExternLoc = Loc; |
2065 | 9.06k | } |
2066 | | |
2067 | | /// Sets the location of the template keyword. |
2068 | 268k | void setTemplateKeywordLoc(SourceLocation Loc) { |
2069 | 268k | if (!ExplicitInfo) |
2070 | 0 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
2071 | 268k | ExplicitInfo->TemplateKeywordLoc = Loc; |
2072 | 268k | } |
2073 | | |
2074 | | /// Gets the location of the template keyword, if present. |
2075 | 494k | SourceLocation getTemplateKeywordLoc() const { |
2076 | 494k | return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation()0 ; |
2077 | 494k | } |
2078 | | |
2079 | | SourceRange getSourceRange() const override LLVM_READONLY; |
2080 | | |
2081 | 4.48M | void Profile(llvm::FoldingSetNodeID &ID) const { |
2082 | 4.48M | Profile(ID, TemplateArgs->asArray(), getASTContext()); |
2083 | 4.48M | } |
2084 | | |
2085 | | static void |
2086 | | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, |
2087 | 8.71M | ASTContext &Context) { |
2088 | 8.71M | ID.AddInteger(TemplateArgs.size()); |
2089 | 8.71M | for (const TemplateArgument &TemplateArg : TemplateArgs) |
2090 | 13.8M | TemplateArg.Profile(ID, Context); |
2091 | 8.71M | } |
2092 | | |
2093 | 114M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2094 | | |
2095 | 119M | static bool classofKind(Kind K) { |
2096 | 119M | return K >= firstClassTemplateSpecialization && |
2097 | 119M | K <= lastClassTemplateSpecialization91.6M ; |
2098 | 119M | } |
2099 | | }; |
2100 | | |
2101 | | class ClassTemplatePartialSpecializationDecl |
2102 | | : public ClassTemplateSpecializationDecl { |
2103 | | /// The list of template parameters |
2104 | | TemplateParameterList* TemplateParams = nullptr; |
2105 | | |
2106 | | /// The source info for the template arguments as written. |
2107 | | /// FIXME: redundant with TypeAsWritten? |
2108 | | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; |
2109 | | |
2110 | | /// The class template partial specialization from which this |
2111 | | /// class template partial specialization was instantiated. |
2112 | | /// |
2113 | | /// The boolean value will be true to indicate that this class template |
2114 | | /// partial specialization was specialized at this level. |
2115 | | llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool> |
2116 | | InstantiatedFromMember; |
2117 | | |
2118 | | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
2119 | | DeclContext *DC, |
2120 | | SourceLocation StartLoc, |
2121 | | SourceLocation IdLoc, |
2122 | | TemplateParameterList *Params, |
2123 | | ClassTemplateDecl *SpecializedTemplate, |
2124 | | ArrayRef<TemplateArgument> Args, |
2125 | | const ASTTemplateArgumentListInfo *ArgsAsWritten, |
2126 | | ClassTemplatePartialSpecializationDecl *PrevDecl); |
2127 | | |
2128 | | ClassTemplatePartialSpecializationDecl(ASTContext &C) |
2129 | | : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization), |
2130 | 33.7k | InstantiatedFromMember(nullptr, false) {} |
2131 | | |
2132 | | void anchor() override; |
2133 | | |
2134 | | public: |
2135 | | friend class ASTDeclReader; |
2136 | | friend class ASTDeclWriter; |
2137 | | |
2138 | | static ClassTemplatePartialSpecializationDecl * |
2139 | | Create(ASTContext &Context, TagKind TK, DeclContext *DC, |
2140 | | SourceLocation StartLoc, SourceLocation IdLoc, |
2141 | | TemplateParameterList *Params, |
2142 | | ClassTemplateDecl *SpecializedTemplate, |
2143 | | ArrayRef<TemplateArgument> Args, |
2144 | | const TemplateArgumentListInfo &ArgInfos, |
2145 | | QualType CanonInjectedType, |
2146 | | ClassTemplatePartialSpecializationDecl *PrevDecl); |
2147 | | |
2148 | | static ClassTemplatePartialSpecializationDecl * |
2149 | | CreateDeserialized(ASTContext &C, unsigned ID); |
2150 | | |
2151 | 793k | ClassTemplatePartialSpecializationDecl *getMostRecentDecl() { |
2152 | 793k | return cast<ClassTemplatePartialSpecializationDecl>( |
2153 | 793k | static_cast<ClassTemplateSpecializationDecl *>( |
2154 | 793k | this)->getMostRecentDecl()); |
2155 | 793k | } |
2156 | | |
2157 | | /// Get the list of template parameters |
2158 | 2.63M | TemplateParameterList *getTemplateParameters() const { |
2159 | 2.63M | return TemplateParams; |
2160 | 2.63M | } |
2161 | | |
2162 | | /// \brief All associated constraints of this partial specialization, |
2163 | | /// including the requires clause and any constraints derived from |
2164 | | /// constrained-parameters. |
2165 | | /// |
2166 | | /// The constraints in the resulting list are to be treated as if in a |
2167 | | /// conjunction ("and"). |
2168 | 237k | void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const { |
2169 | 237k | TemplateParams->getAssociatedConstraints(AC); |
2170 | 237k | } |
2171 | | |
2172 | 0 | bool hasAssociatedConstraints() const { |
2173 | 0 | return TemplateParams->hasAssociatedConstraints(); |
2174 | 0 | } |
2175 | | |
2176 | | /// Get the template arguments as written. |
2177 | 330k | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { |
2178 | 330k | return ArgsAsWritten; |
2179 | 330k | } |
2180 | | |
2181 | | /// Retrieve the member class template partial specialization from |
2182 | | /// which this particular class template partial specialization was |
2183 | | /// instantiated. |
2184 | | /// |
2185 | | /// \code |
2186 | | /// template<typename T> |
2187 | | /// struct Outer { |
2188 | | /// template<typename U> struct Inner; |
2189 | | /// template<typename U> struct Inner<U*> { }; // #1 |
2190 | | /// }; |
2191 | | /// |
2192 | | /// Outer<float>::Inner<int*> ii; |
2193 | | /// \endcode |
2194 | | /// |
2195 | | /// In this example, the instantiation of \c Outer<float>::Inner<int*> will |
2196 | | /// end up instantiating the partial specialization |
2197 | | /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class |
2198 | | /// template partial specialization \c Outer<T>::Inner<U*>. Given |
2199 | | /// \c Outer<float>::Inner<U*>, this function would return |
2200 | | /// \c Outer<T>::Inner<U*>. |
2201 | 325k | ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { |
2202 | 325k | const auto *First = |
2203 | 325k | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
2204 | 325k | return First->InstantiatedFromMember.getPointer(); |
2205 | 325k | } |
2206 | | ClassTemplatePartialSpecializationDecl * |
2207 | 0 | getInstantiatedFromMemberTemplate() const { |
2208 | 0 | return getInstantiatedFromMember(); |
2209 | 0 | } |
2210 | | |
2211 | | void setInstantiatedFromMember( |
2212 | 6.97k | ClassTemplatePartialSpecializationDecl *PartialSpec) { |
2213 | 6.97k | auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
2214 | 6.97k | First->InstantiatedFromMember.setPointer(PartialSpec); |
2215 | 6.97k | } |
2216 | | |
2217 | | /// Determines whether this class template partial specialization |
2218 | | /// template was a specialization of a member partial specialization. |
2219 | | /// |
2220 | | /// In the following example, the member template partial specialization |
2221 | | /// \c X<int>::Inner<T*> is a member specialization. |
2222 | | /// |
2223 | | /// \code |
2224 | | /// template<typename T> |
2225 | | /// struct X { |
2226 | | /// template<typename U> struct Inner; |
2227 | | /// template<typename U> struct Inner<U*>; |
2228 | | /// }; |
2229 | | /// |
2230 | | /// template<> template<typename T> |
2231 | | /// struct X<int>::Inner<T*> { /* ... */ }; |
2232 | | /// \endcode |
2233 | 109k | bool isMemberSpecialization() { |
2234 | 109k | const auto *First = |
2235 | 109k | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
2236 | 109k | return First->InstantiatedFromMember.getInt(); |
2237 | 109k | } |
2238 | | |
2239 | | /// Note that this member template is a specialization. |
2240 | 1 | void setMemberSpecialization() { |
2241 | 1 | auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
2242 | 1 | assert(First->InstantiatedFromMember.getPointer() && |
2243 | 1 | "Only member templates can be member template specializations"); |
2244 | 0 | return First->InstantiatedFromMember.setInt(true); |
2245 | 1 | } |
2246 | | |
2247 | | /// Retrieves the injected specialization type for this partial |
2248 | | /// specialization. This is not the same as the type-decl-type for |
2249 | | /// this partial specialization, which is an InjectedClassNameType. |
2250 | 339k | QualType getInjectedSpecializationType() const { |
2251 | 339k | assert(getTypeForDecl() && "partial specialization has no type set!"); |
2252 | 0 | return cast<InjectedClassNameType>(getTypeForDecl()) |
2253 | 339k | ->getInjectedSpecializationType(); |
2254 | 339k | } |
2255 | | |
2256 | 48.4k | void Profile(llvm::FoldingSetNodeID &ID) const { |
2257 | 48.4k | Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(), |
2258 | 48.4k | getASTContext()); |
2259 | 48.4k | } |
2260 | | |
2261 | | static void |
2262 | | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, |
2263 | | TemplateParameterList *TPL, ASTContext &Context); |
2264 | | |
2265 | 14.9M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2266 | | |
2267 | 224M | static bool classofKind(Kind K) { |
2268 | 224M | return K == ClassTemplatePartialSpecialization; |
2269 | 224M | } |
2270 | | }; |
2271 | | |
2272 | | /// Declaration of a class template. |
2273 | | class ClassTemplateDecl : public RedeclarableTemplateDecl { |
2274 | | protected: |
2275 | | /// Data that is common to all of the declarations of a given |
2276 | | /// class template. |
2277 | | struct Common : CommonBase { |
2278 | | /// The class template specializations for this class |
2279 | | /// template, including explicit specializations and instantiations. |
2280 | | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations; |
2281 | | |
2282 | | /// The class template partial specializations for this class |
2283 | | /// template. |
2284 | | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> |
2285 | | PartialSpecializations; |
2286 | | |
2287 | | /// The injected-class-name type for this class template. |
2288 | | QualType InjectedClassNameType; |
2289 | | |
2290 | 520k | Common() = default; |
2291 | | }; |
2292 | | |
2293 | | /// Retrieve the set of specializations of this class template. |
2294 | | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
2295 | | getSpecializations() const; |
2296 | | |
2297 | | /// Retrieve the set of partial specializations of this class |
2298 | | /// template. |
2299 | | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
2300 | | getPartialSpecializations() const; |
2301 | | |
2302 | | ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
2303 | | DeclarationName Name, TemplateParameterList *Params, |
2304 | | NamedDecl *Decl) |
2305 | 674k | : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {} |
2306 | | |
2307 | | CommonBase *newCommon(ASTContext &C) const override; |
2308 | | |
2309 | 8.44M | Common *getCommonPtr() const { |
2310 | 8.44M | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
2311 | 8.44M | } |
2312 | | |
2313 | | public: |
2314 | | friend class ASTDeclReader; |
2315 | | friend class ASTDeclWriter; |
2316 | | |
2317 | | /// Load any lazily-loaded specializations from the external source. |
2318 | | void LoadLazySpecializations() const; |
2319 | | |
2320 | | /// Get the underlying class declarations of the template. |
2321 | 9.67M | CXXRecordDecl *getTemplatedDecl() const { |
2322 | 9.67M | return static_cast<CXXRecordDecl *>(TemplatedDecl); |
2323 | 9.67M | } |
2324 | | |
2325 | | /// Returns whether this template declaration defines the primary |
2326 | | /// class pattern. |
2327 | 105k | bool isThisDeclarationADefinition() const { |
2328 | 105k | return getTemplatedDecl()->isThisDeclarationADefinition(); |
2329 | 105k | } |
2330 | | |
2331 | | /// \brief Create a class template node. |
2332 | | static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
2333 | | SourceLocation L, |
2334 | | DeclarationName Name, |
2335 | | TemplateParameterList *Params, |
2336 | | NamedDecl *Decl); |
2337 | | |
2338 | | /// Create an empty class template node. |
2339 | | static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2340 | | |
2341 | | /// Return the specialization with the provided arguments if it exists, |
2342 | | /// otherwise return the insertion point. |
2343 | | ClassTemplateSpecializationDecl * |
2344 | | findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); |
2345 | | |
2346 | | /// Insert the specified specialization knowing that it is not already |
2347 | | /// in. InsertPos must be obtained from findSpecialization. |
2348 | | void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos); |
2349 | | |
2350 | 32.5M | ClassTemplateDecl *getCanonicalDecl() override { |
2351 | 32.5M | return cast<ClassTemplateDecl>( |
2352 | 32.5M | RedeclarableTemplateDecl::getCanonicalDecl()); |
2353 | 32.5M | } |
2354 | 0 | const ClassTemplateDecl *getCanonicalDecl() const { |
2355 | 0 | return cast<ClassTemplateDecl>( |
2356 | 0 | RedeclarableTemplateDecl::getCanonicalDecl()); |
2357 | 0 | } |
2358 | | |
2359 | | /// Retrieve the previous declaration of this class template, or |
2360 | | /// nullptr if no such declaration exists. |
2361 | | ClassTemplateDecl *getPreviousDecl() { |
2362 | | return cast_or_null<ClassTemplateDecl>( |
2363 | | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
2364 | | } |
2365 | 0 | const ClassTemplateDecl *getPreviousDecl() const { |
2366 | 0 | return cast_or_null<ClassTemplateDecl>( |
2367 | 0 | static_cast<const RedeclarableTemplateDecl *>( |
2368 | 0 | this)->getPreviousDecl()); |
2369 | 0 | } |
2370 | | |
2371 | 55.7k | ClassTemplateDecl *getMostRecentDecl() { |
2372 | 55.7k | return cast<ClassTemplateDecl>( |
2373 | 55.7k | static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl()); |
2374 | 55.7k | } |
2375 | 0 | const ClassTemplateDecl *getMostRecentDecl() const { |
2376 | 0 | return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl(); |
2377 | 0 | } |
2378 | | |
2379 | 1.82M | ClassTemplateDecl *getInstantiatedFromMemberTemplate() const { |
2380 | 1.82M | return cast_or_null<ClassTemplateDecl>( |
2381 | 1.82M | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
2382 | 1.82M | } |
2383 | | |
2384 | | /// Return the partial specialization with the provided arguments if it |
2385 | | /// exists, otherwise return the insertion point. |
2386 | | ClassTemplatePartialSpecializationDecl * |
2387 | | findPartialSpecialization(ArrayRef<TemplateArgument> Args, |
2388 | | TemplateParameterList *TPL, void *&InsertPos); |
2389 | | |
2390 | | /// Insert the specified partial specialization knowing that it is not |
2391 | | /// already in. InsertPos must be obtained from findPartialSpecialization. |
2392 | | void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, |
2393 | | void *InsertPos); |
2394 | | |
2395 | | /// Retrieve the partial specializations as an ordered list. |
2396 | | void getPartialSpecializations( |
2397 | | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) const; |
2398 | | |
2399 | | /// Find a class template partial specialization with the given |
2400 | | /// type T. |
2401 | | /// |
2402 | | /// \param T a dependent type that names a specialization of this class |
2403 | | /// template. |
2404 | | /// |
2405 | | /// \returns the class template partial specialization that exactly matches |
2406 | | /// the type \p T, or nullptr if no such partial specialization exists. |
2407 | | ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T); |
2408 | | |
2409 | | /// Find a class template partial specialization which was instantiated |
2410 | | /// from the given member partial specialization. |
2411 | | /// |
2412 | | /// \param D a member class template partial specialization. |
2413 | | /// |
2414 | | /// \returns the class template partial specialization which was instantiated |
2415 | | /// from the given member partial specialization, or nullptr if no such |
2416 | | /// partial specialization exists. |
2417 | | ClassTemplatePartialSpecializationDecl * |
2418 | | findPartialSpecInstantiatedFromMember( |
2419 | | ClassTemplatePartialSpecializationDecl *D); |
2420 | | |
2421 | | /// Retrieve the template specialization type of the |
2422 | | /// injected-class-name for this class template. |
2423 | | /// |
2424 | | /// The injected-class-name for a class template \c X is \c |
2425 | | /// X<template-args>, where \c template-args is formed from the |
2426 | | /// template arguments that correspond to the template parameters of |
2427 | | /// \c X. For example: |
2428 | | /// |
2429 | | /// \code |
2430 | | /// template<typename T, int N> |
2431 | | /// struct array { |
2432 | | /// typedef array this_type; // "array" is equivalent to "array<T, N>" |
2433 | | /// }; |
2434 | | /// \endcode |
2435 | | QualType getInjectedClassNameSpecialization(); |
2436 | | |
2437 | | using spec_iterator = SpecIterator<ClassTemplateSpecializationDecl>; |
2438 | | using spec_range = llvm::iterator_range<spec_iterator>; |
2439 | | |
2440 | 35.9k | spec_range specializations() const { |
2441 | 35.9k | return spec_range(spec_begin(), spec_end()); |
2442 | 35.9k | } |
2443 | | |
2444 | 35.9k | spec_iterator spec_begin() const { |
2445 | 35.9k | return makeSpecIterator(getSpecializations(), false); |
2446 | 35.9k | } |
2447 | | |
2448 | 35.9k | spec_iterator spec_end() const { |
2449 | 35.9k | return makeSpecIterator(getSpecializations(), true); |
2450 | 35.9k | } |
2451 | | |
2452 | | // Implement isa/cast/dyncast support |
2453 | 71.9M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2454 | 71.9M | static bool classofKind(Kind K) { return K == ClassTemplate; } |
2455 | | }; |
2456 | | |
2457 | | /// Declaration of a friend template. |
2458 | | /// |
2459 | | /// For example: |
2460 | | /// \code |
2461 | | /// template \<typename T> class A { |
2462 | | /// friend class MyVector<T>; // not a friend template |
2463 | | /// template \<typename U> friend class B; // not a friend template |
2464 | | /// template \<typename U> friend class Foo<T>::Nested; // friend template |
2465 | | /// }; |
2466 | | /// \endcode |
2467 | | /// |
2468 | | /// \note This class is not currently in use. All of the above |
2469 | | /// will yield a FriendDecl, not a FriendTemplateDecl. |
2470 | | class FriendTemplateDecl : public Decl { |
2471 | | virtual void anchor(); |
2472 | | |
2473 | | public: |
2474 | | using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>; |
2475 | | |
2476 | | private: |
2477 | | // The number of template parameters; always non-zero. |
2478 | | unsigned NumParams = 0; |
2479 | | |
2480 | | // The parameter list. |
2481 | | TemplateParameterList **Params = nullptr; |
2482 | | |
2483 | | // The declaration that's a friend of this class. |
2484 | | FriendUnion Friend; |
2485 | | |
2486 | | // Location of the 'friend' specifier. |
2487 | | SourceLocation FriendLoc; |
2488 | | |
2489 | | FriendTemplateDecl(DeclContext *DC, SourceLocation Loc, |
2490 | | TemplateParameterList **Params, unsigned NumParams, |
2491 | | FriendUnion Friend, SourceLocation FriendLoc) |
2492 | | : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams), |
2493 | 6 | Params(Params), Friend(Friend), FriendLoc(FriendLoc) {} |
2494 | | |
2495 | 0 | FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {} |
2496 | | |
2497 | | public: |
2498 | | friend class ASTDeclReader; |
2499 | | |
2500 | | static FriendTemplateDecl * |
2501 | | Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, |
2502 | | MutableArrayRef<TemplateParameterList *> Params, FriendUnion Friend, |
2503 | | SourceLocation FriendLoc); |
2504 | | |
2505 | | static FriendTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2506 | | |
2507 | | /// If this friend declaration names a templated type (or |
2508 | | /// a dependent member type of a templated type), return that |
2509 | | /// type; otherwise return null. |
2510 | 0 | TypeSourceInfo *getFriendType() const { |
2511 | 0 | return Friend.dyn_cast<TypeSourceInfo*>(); |
2512 | 0 | } |
2513 | | |
2514 | | /// If this friend declaration names a templated function (or |
2515 | | /// a member function of a templated type), return that type; |
2516 | | /// otherwise return null. |
2517 | 0 | NamedDecl *getFriendDecl() const { |
2518 | 0 | return Friend.dyn_cast<NamedDecl*>(); |
2519 | 0 | } |
2520 | | |
2521 | | /// Retrieves the location of the 'friend' keyword. |
2522 | 0 | SourceLocation getFriendLoc() const { |
2523 | 0 | return FriendLoc; |
2524 | 0 | } |
2525 | | |
2526 | 0 | TemplateParameterList *getTemplateParameterList(unsigned i) const { |
2527 | 0 | assert(i <= NumParams); |
2528 | 0 | return Params[i]; |
2529 | 0 | } |
2530 | | |
2531 | 0 | unsigned getNumTemplateParameters() const { |
2532 | 0 | return NumParams; |
2533 | 0 | } |
2534 | | |
2535 | | // Implement isa/cast/dyncast/etc. |
2536 | 0 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2537 | 0 | static bool classofKind(Kind K) { return K == Decl::FriendTemplate; } |
2538 | | }; |
2539 | | |
2540 | | /// Declaration of an alias template. |
2541 | | /// |
2542 | | /// For example: |
2543 | | /// \code |
2544 | | /// template \<typename T> using V = std::map<T*, int, MyCompare<T>>; |
2545 | | /// \endcode |
2546 | | class TypeAliasTemplateDecl : public RedeclarableTemplateDecl { |
2547 | | protected: |
2548 | | using Common = CommonBase; |
2549 | | |
2550 | | TypeAliasTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
2551 | | DeclarationName Name, TemplateParameterList *Params, |
2552 | | NamedDecl *Decl) |
2553 | | : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params, |
2554 | 114k | Decl) {} |
2555 | | |
2556 | | CommonBase *newCommon(ASTContext &C) const override; |
2557 | | |
2558 | 0 | Common *getCommonPtr() { |
2559 | 0 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
2560 | 0 | } |
2561 | | |
2562 | | public: |
2563 | | friend class ASTDeclReader; |
2564 | | friend class ASTDeclWriter; |
2565 | | |
2566 | | /// Get the underlying function declaration of the template. |
2567 | 1.16M | TypeAliasDecl *getTemplatedDecl() const { |
2568 | 1.16M | return static_cast<TypeAliasDecl *>(TemplatedDecl); |
2569 | 1.16M | } |
2570 | | |
2571 | | |
2572 | 2.87M | TypeAliasTemplateDecl *getCanonicalDecl() override { |
2573 | 2.87M | return cast<TypeAliasTemplateDecl>( |
2574 | 2.87M | RedeclarableTemplateDecl::getCanonicalDecl()); |
2575 | 2.87M | } |
2576 | 0 | const TypeAliasTemplateDecl *getCanonicalDecl() const { |
2577 | 0 | return cast<TypeAliasTemplateDecl>( |
2578 | 0 | RedeclarableTemplateDecl::getCanonicalDecl()); |
2579 | 0 | } |
2580 | | |
2581 | | /// Retrieve the previous declaration of this function template, or |
2582 | | /// nullptr if no such declaration exists. |
2583 | 0 | TypeAliasTemplateDecl *getPreviousDecl() { |
2584 | 0 | return cast_or_null<TypeAliasTemplateDecl>( |
2585 | 0 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
2586 | 0 | } |
2587 | 0 | const TypeAliasTemplateDecl *getPreviousDecl() const { |
2588 | 0 | return cast_or_null<TypeAliasTemplateDecl>( |
2589 | 0 | static_cast<const RedeclarableTemplateDecl *>( |
2590 | 0 | this)->getPreviousDecl()); |
2591 | 0 | } |
2592 | | |
2593 | 0 | TypeAliasTemplateDecl *getInstantiatedFromMemberTemplate() const { |
2594 | 0 | return cast_or_null<TypeAliasTemplateDecl>( |
2595 | 0 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
2596 | 0 | } |
2597 | | |
2598 | | /// Create a function template node. |
2599 | | static TypeAliasTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
2600 | | SourceLocation L, |
2601 | | DeclarationName Name, |
2602 | | TemplateParameterList *Params, |
2603 | | NamedDecl *Decl); |
2604 | | |
2605 | | /// Create an empty alias template node. |
2606 | | static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2607 | | |
2608 | | // Implement isa/cast/dyncast support |
2609 | 25.1M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2610 | 25.1M | static bool classofKind(Kind K) { return K == TypeAliasTemplate; } |
2611 | | }; |
2612 | | |
2613 | | /// Declaration of a function specialization at template class scope. |
2614 | | /// |
2615 | | /// For example: |
2616 | | /// \code |
2617 | | /// template <class T> |
2618 | | /// class A { |
2619 | | /// template <class U> void foo(U a) { } |
2620 | | /// template<> void foo(int a) { } |
2621 | | /// } |
2622 | | /// \endcode |
2623 | | /// |
2624 | | /// "template<> foo(int a)" will be saved in Specialization as a normal |
2625 | | /// CXXMethodDecl. Then during an instantiation of class A, it will be |
2626 | | /// transformed into an actual function specialization. |
2627 | | /// |
2628 | | /// FIXME: This is redundant; we could store the same information directly on |
2629 | | /// the CXXMethodDecl as a DependentFunctionTemplateSpecializationInfo. |
2630 | | class ClassScopeFunctionSpecializationDecl : public Decl { |
2631 | | CXXMethodDecl *Specialization; |
2632 | | const ASTTemplateArgumentListInfo *TemplateArgs; |
2633 | | |
2634 | | ClassScopeFunctionSpecializationDecl( |
2635 | | DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD, |
2636 | | const ASTTemplateArgumentListInfo *TemplArgs) |
2637 | | : Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc), |
2638 | 71 | Specialization(FD), TemplateArgs(TemplArgs) {} |
2639 | | |
2640 | | ClassScopeFunctionSpecializationDecl(EmptyShell Empty) |
2641 | 0 | : Decl(Decl::ClassScopeFunctionSpecialization, Empty) {} |
2642 | | |
2643 | | virtual void anchor(); |
2644 | | |
2645 | | public: |
2646 | | friend class ASTDeclReader; |
2647 | | friend class ASTDeclWriter; |
2648 | | |
2649 | 101 | CXXMethodDecl *getSpecialization() const { return Specialization; } |
2650 | 16 | bool hasExplicitTemplateArgs() const { return TemplateArgs; } |
2651 | 97 | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { |
2652 | 97 | return TemplateArgs; |
2653 | 97 | } |
2654 | | |
2655 | | static ClassScopeFunctionSpecializationDecl * |
2656 | | Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD, |
2657 | | bool HasExplicitTemplateArgs, |
2658 | 59 | const TemplateArgumentListInfo &TemplateArgs) { |
2659 | 59 | return new (C, DC) ClassScopeFunctionSpecializationDecl( |
2660 | 59 | DC, Loc, FD, |
2661 | 59 | HasExplicitTemplateArgs |
2662 | 59 | ? ASTTemplateArgumentListInfo::Create(C, TemplateArgs)44 |
2663 | 59 | : nullptr15 ); |
2664 | 59 | } |
2665 | | |
2666 | | static ClassScopeFunctionSpecializationDecl * |
2667 | | CreateDeserialized(ASTContext &Context, unsigned ID); |
2668 | | |
2669 | | // Implement isa/cast/dyncast/etc. |
2670 | 49.0M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2671 | | |
2672 | 49.0M | static bool classofKind(Kind K) { |
2673 | 49.0M | return K == Decl::ClassScopeFunctionSpecialization; |
2674 | 49.0M | } |
2675 | | }; |
2676 | | |
2677 | | /// Represents a variable template specialization, which refers to |
2678 | | /// a variable template with a given set of template arguments. |
2679 | | /// |
2680 | | /// Variable template specializations represent both explicit |
2681 | | /// specializations of variable templates, as in the example below, and |
2682 | | /// implicit instantiations of variable templates. |
2683 | | /// |
2684 | | /// \code |
2685 | | /// template<typename T> constexpr T pi = T(3.1415926535897932385); |
2686 | | /// |
2687 | | /// template<> |
2688 | | /// constexpr float pi<float>; // variable template specialization pi<float> |
2689 | | /// \endcode |
2690 | | class VarTemplateSpecializationDecl : public VarDecl, |
2691 | | public llvm::FoldingSetNode { |
2692 | | |
2693 | | /// Structure that stores information about a variable template |
2694 | | /// specialization that was instantiated from a variable template partial |
2695 | | /// specialization. |
2696 | | struct SpecializedPartialSpecialization { |
2697 | | /// The variable template partial specialization from which this |
2698 | | /// variable template specialization was instantiated. |
2699 | | VarTemplatePartialSpecializationDecl *PartialSpecialization; |
2700 | | |
2701 | | /// The template argument list deduced for the variable template |
2702 | | /// partial specialization itself. |
2703 | | const TemplateArgumentList *TemplateArgs; |
2704 | | }; |
2705 | | |
2706 | | /// The template that this specialization specializes. |
2707 | | llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *> |
2708 | | SpecializedTemplate; |
2709 | | |
2710 | | /// Further info for explicit template specialization/instantiation. |
2711 | | struct ExplicitSpecializationInfo { |
2712 | | /// The type-as-written. |
2713 | | TypeSourceInfo *TypeAsWritten = nullptr; |
2714 | | |
2715 | | /// The location of the extern keyword. |
2716 | | SourceLocation ExternLoc; |
2717 | | |
2718 | | /// The location of the template keyword. |
2719 | | SourceLocation TemplateKeywordLoc; |
2720 | | |
2721 | 1.03k | ExplicitSpecializationInfo() = default; |
2722 | | }; |
2723 | | |
2724 | | /// Further info for explicit template specialization/instantiation. |
2725 | | /// Does not apply to implicit specializations. |
2726 | | ExplicitSpecializationInfo *ExplicitInfo = nullptr; |
2727 | | |
2728 | | /// The template arguments used to describe this specialization. |
2729 | | const TemplateArgumentList *TemplateArgs; |
2730 | | const ASTTemplateArgumentListInfo *TemplateArgsInfo = nullptr; |
2731 | | |
2732 | | /// The point where this template was instantiated (if any). |
2733 | | SourceLocation PointOfInstantiation; |
2734 | | |
2735 | | /// The kind of specialization this declaration refers to. |
2736 | | /// Really a value of type TemplateSpecializationKind. |
2737 | | unsigned SpecializationKind : 3; |
2738 | | |
2739 | | /// Whether this declaration is a complete definition of the |
2740 | | /// variable template specialization. We can't otherwise tell apart |
2741 | | /// an instantiated declaration from an instantiated definition with |
2742 | | /// no initializer. |
2743 | | unsigned IsCompleteDefinition : 1; |
2744 | | |
2745 | | protected: |
2746 | | VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, |
2747 | | SourceLocation StartLoc, SourceLocation IdLoc, |
2748 | | VarTemplateDecl *SpecializedTemplate, |
2749 | | QualType T, TypeSourceInfo *TInfo, |
2750 | | StorageClass S, |
2751 | | ArrayRef<TemplateArgument> Args); |
2752 | | |
2753 | | explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context); |
2754 | | |
2755 | | public: |
2756 | | friend class ASTDeclReader; |
2757 | | friend class ASTDeclWriter; |
2758 | | friend class VarDecl; |
2759 | | |
2760 | | static VarTemplateSpecializationDecl * |
2761 | | Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
2762 | | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
2763 | | TypeSourceInfo *TInfo, StorageClass S, |
2764 | | ArrayRef<TemplateArgument> Args); |
2765 | | static VarTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, |
2766 | | unsigned ID); |
2767 | | |
2768 | | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, |
2769 | | bool Qualified) const override; |
2770 | | |
2771 | 3.78k | VarTemplateSpecializationDecl *getMostRecentDecl() { |
2772 | 3.78k | VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl(); |
2773 | 3.78k | return cast<VarTemplateSpecializationDecl>(Recent); |
2774 | 3.78k | } |
2775 | | |
2776 | | /// Retrieve the template that this specialization specializes. |
2777 | | VarTemplateDecl *getSpecializedTemplate() const; |
2778 | | |
2779 | | /// Retrieve the template arguments of the variable template |
2780 | | /// specialization. |
2781 | 21.7k | const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; } |
2782 | | |
2783 | | // TODO: Always set this when creating the new specialization? |
2784 | | void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo); |
2785 | | void setTemplateArgsInfo(const ASTTemplateArgumentListInfo *ArgsInfo); |
2786 | | |
2787 | 219 | const ASTTemplateArgumentListInfo *getTemplateArgsInfo() const { |
2788 | 219 | return TemplateArgsInfo; |
2789 | 219 | } |
2790 | | |
2791 | | /// Determine the kind of specialization that this |
2792 | | /// declaration represents. |
2793 | 95.8k | TemplateSpecializationKind getSpecializationKind() const { |
2794 | 95.8k | return static_cast<TemplateSpecializationKind>(SpecializationKind); |
2795 | 95.8k | } |
2796 | | |
2797 | 7.36k | bool isExplicitSpecialization() const { |
2798 | 7.36k | return getSpecializationKind() == TSK_ExplicitSpecialization; |
2799 | 7.36k | } |
2800 | | |
2801 | 5.61k | bool isClassScopeExplicitSpecialization() const { |
2802 | 5.61k | return isExplicitSpecialization() && |
2803 | 5.61k | isa<CXXRecordDecl>(getLexicalDeclContext())18 ; |
2804 | 5.61k | } |
2805 | | |
2806 | | /// True if this declaration is an explicit specialization, |
2807 | | /// explicit instantiation declaration, or explicit instantiation |
2808 | | /// definition. |
2809 | 5.56k | bool isExplicitInstantiationOrSpecialization() const { |
2810 | 5.56k | return isTemplateExplicitInstantiationOrSpecialization( |
2811 | 5.56k | getTemplateSpecializationKind()); |
2812 | 5.56k | } |
2813 | | |
2814 | 11.1k | void setSpecializationKind(TemplateSpecializationKind TSK) { |
2815 | 11.1k | SpecializationKind = TSK; |
2816 | 11.1k | } |
2817 | | |
2818 | | /// Get the point of instantiation (if any), or null if none. |
2819 | 19.2k | SourceLocation getPointOfInstantiation() const { |
2820 | 19.2k | return PointOfInstantiation; |
2821 | 19.2k | } |
2822 | | |
2823 | 4.36k | void setPointOfInstantiation(SourceLocation Loc) { |
2824 | 4.36k | assert(Loc.isValid() && "point of instantiation must be valid!"); |
2825 | 0 | PointOfInstantiation = Loc; |
2826 | 4.36k | } |
2827 | | |
2828 | 3.04k | void setCompleteDefinition() { IsCompleteDefinition = true; } |
2829 | | |
2830 | | /// If this variable template specialization is an instantiation of |
2831 | | /// a template (rather than an explicit specialization), return the |
2832 | | /// variable template or variable template partial specialization from which |
2833 | | /// it was instantiated. |
2834 | | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
2835 | 5.59k | getInstantiatedFrom() const { |
2836 | 5.59k | if (!isTemplateInstantiation(getSpecializationKind())) |
2837 | 0 | return llvm::PointerUnion<VarTemplateDecl *, |
2838 | 0 | VarTemplatePartialSpecializationDecl *>(); |
2839 | | |
2840 | 5.59k | return getSpecializedTemplateOrPartial(); |
2841 | 5.59k | } |
2842 | | |
2843 | | /// Retrieve the variable template or variable template partial |
2844 | | /// specialization which was specialized by this. |
2845 | | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
2846 | 15.8k | getSpecializedTemplateOrPartial() const { |
2847 | 15.8k | if (const auto *PartialSpec = |
2848 | 15.8k | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
2849 | 1.42k | return PartialSpec->PartialSpecialization; |
2850 | | |
2851 | 14.4k | return SpecializedTemplate.get<VarTemplateDecl *>(); |
2852 | 15.8k | } |
2853 | | |
2854 | | /// Retrieve the set of template arguments that should be used |
2855 | | /// to instantiate the initializer of the variable template or variable |
2856 | | /// template partial specialization from which this variable template |
2857 | | /// specialization was instantiated. |
2858 | | /// |
2859 | | /// \returns For a variable template specialization instantiated from the |
2860 | | /// primary template, this function will return the same template arguments |
2861 | | /// as getTemplateArgs(). For a variable template specialization instantiated |
2862 | | /// from a variable template partial specialization, this function will the |
2863 | | /// return deduced template arguments for the variable template partial |
2864 | | /// specialization itself. |
2865 | 5.63k | const TemplateArgumentList &getTemplateInstantiationArgs() const { |
2866 | 5.63k | if (const auto *PartialSpec = |
2867 | 5.63k | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
2868 | 613 | return *PartialSpec->TemplateArgs; |
2869 | | |
2870 | 5.02k | return getTemplateArgs(); |
2871 | 5.63k | } |
2872 | | |
2873 | | /// Note that this variable template specialization is actually an |
2874 | | /// instantiation of the given variable template partial specialization whose |
2875 | | /// template arguments have been deduced. |
2876 | | void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec, |
2877 | 863 | const TemplateArgumentList *TemplateArgs) { |
2878 | 863 | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && |
2879 | 863 | "Already set to a variable template partial specialization!"); |
2880 | 0 | auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); |
2881 | 863 | PS->PartialSpecialization = PartialSpec; |
2882 | 863 | PS->TemplateArgs = TemplateArgs; |
2883 | 863 | SpecializedTemplate = PS; |
2884 | 863 | } |
2885 | | |
2886 | | /// Note that this variable template specialization is an instantiation |
2887 | | /// of the given variable template. |
2888 | 0 | void setInstantiationOf(VarTemplateDecl *TemplDecl) { |
2889 | 0 | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && |
2890 | 0 | "Previously set to a variable template partial specialization!"); |
2891 | 0 | SpecializedTemplate = TemplDecl; |
2892 | 0 | } |
2893 | | |
2894 | | /// Sets the type of this specialization as it was written by |
2895 | | /// the user. |
2896 | 49 | void setTypeAsWritten(TypeSourceInfo *T) { |
2897 | 49 | if (!ExplicitInfo) |
2898 | 49 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
2899 | 49 | ExplicitInfo->TypeAsWritten = T; |
2900 | 49 | } |
2901 | | |
2902 | | /// Gets the type of this specialization as it was written by |
2903 | | /// the user, if it was so written. |
2904 | 1.89k | TypeSourceInfo *getTypeAsWritten() const { |
2905 | 1.89k | return ExplicitInfo ? ExplicitInfo->TypeAsWritten385 : nullptr1.50k ; |
2906 | 1.89k | } |
2907 | | |
2908 | | /// Gets the location of the extern keyword, if present. |
2909 | 9 | SourceLocation getExternLoc() const { |
2910 | 9 | return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation()0 ; |
2911 | 9 | } |
2912 | | |
2913 | | /// Sets the location of the extern keyword. |
2914 | 0 | void setExternLoc(SourceLocation Loc) { |
2915 | 0 | if (!ExplicitInfo) |
2916 | 0 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
2917 | 0 | ExplicitInfo->ExternLoc = Loc; |
2918 | 0 | } |
2919 | | |
2920 | | /// Sets the location of the template keyword. |
2921 | 979 | void setTemplateKeywordLoc(SourceLocation Loc) { |
2922 | 979 | if (!ExplicitInfo) |
2923 | 979 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
2924 | 979 | ExplicitInfo->TemplateKeywordLoc = Loc; |
2925 | 979 | } |
2926 | | |
2927 | | /// Gets the location of the template keyword, if present. |
2928 | 9 | SourceLocation getTemplateKeywordLoc() const { |
2929 | 9 | return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation()0 ; |
2930 | 9 | } |
2931 | | |
2932 | 7.01k | void Profile(llvm::FoldingSetNodeID &ID) const { |
2933 | 7.01k | Profile(ID, TemplateArgs->asArray(), getASTContext()); |
2934 | 7.01k | } |
2935 | | |
2936 | | static void Profile(llvm::FoldingSetNodeID &ID, |
2937 | | ArrayRef<TemplateArgument> TemplateArgs, |
2938 | 23.0k | ASTContext &Context) { |
2939 | 23.0k | ID.AddInteger(TemplateArgs.size()); |
2940 | 23.0k | for (const TemplateArgument &TemplateArg : TemplateArgs) |
2941 | 35.3k | TemplateArg.Profile(ID, Context); |
2942 | 23.0k | } |
2943 | | |
2944 | 67.6M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2945 | | |
2946 | 67.6M | static bool classofKind(Kind K) { |
2947 | 67.6M | return K >= firstVarTemplateSpecialization && |
2948 | 67.6M | K <= lastVarTemplateSpecialization182k ; |
2949 | 67.6M | } |
2950 | | }; |
2951 | | |
2952 | | class VarTemplatePartialSpecializationDecl |
2953 | | : public VarTemplateSpecializationDecl { |
2954 | | /// The list of template parameters |
2955 | | TemplateParameterList *TemplateParams = nullptr; |
2956 | | |
2957 | | /// The source info for the template arguments as written. |
2958 | | /// FIXME: redundant with TypeAsWritten? |
2959 | | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; |
2960 | | |
2961 | | /// The variable template partial specialization from which this |
2962 | | /// variable template partial specialization was instantiated. |
2963 | | /// |
2964 | | /// The boolean value will be true to indicate that this variable template |
2965 | | /// partial specialization was specialized at this level. |
2966 | | llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool> |
2967 | | InstantiatedFromMember; |
2968 | | |
2969 | | VarTemplatePartialSpecializationDecl( |
2970 | | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
2971 | | SourceLocation IdLoc, TemplateParameterList *Params, |
2972 | | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
2973 | | StorageClass S, ArrayRef<TemplateArgument> Args, |
2974 | | const ASTTemplateArgumentListInfo *ArgInfos); |
2975 | | |
2976 | | VarTemplatePartialSpecializationDecl(ASTContext &Context) |
2977 | | : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, |
2978 | | Context), |
2979 | 55 | InstantiatedFromMember(nullptr, false) {} |
2980 | | |
2981 | | void anchor() override; |
2982 | | |
2983 | | public: |
2984 | | friend class ASTDeclReader; |
2985 | | friend class ASTDeclWriter; |
2986 | | |
2987 | | static VarTemplatePartialSpecializationDecl * |
2988 | | Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
2989 | | SourceLocation IdLoc, TemplateParameterList *Params, |
2990 | | VarTemplateDecl *SpecializedTemplate, QualType T, |
2991 | | TypeSourceInfo *TInfo, StorageClass S, ArrayRef<TemplateArgument> Args, |
2992 | | const TemplateArgumentListInfo &ArgInfos); |
2993 | | |
2994 | | static VarTemplatePartialSpecializationDecl *CreateDeserialized(ASTContext &C, |
2995 | | unsigned ID); |
2996 | | |
2997 | 1.25k | VarTemplatePartialSpecializationDecl *getMostRecentDecl() { |
2998 | 1.25k | return cast<VarTemplatePartialSpecializationDecl>( |
2999 | 1.25k | static_cast<VarTemplateSpecializationDecl *>( |
3000 | 1.25k | this)->getMostRecentDecl()); |
3001 | 1.25k | } |
3002 | | |
3003 | | /// Get the list of template parameters |
3004 | 5.07k | TemplateParameterList *getTemplateParameters() const { |
3005 | 5.07k | return TemplateParams; |
3006 | 5.07k | } |
3007 | | |
3008 | | /// Get the template arguments as written. |
3009 | 1.28k | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { |
3010 | 1.28k | return ArgsAsWritten; |
3011 | 1.28k | } |
3012 | | |
3013 | | /// \brief All associated constraints of this partial specialization, |
3014 | | /// including the requires clause and any constraints derived from |
3015 | | /// constrained-parameters. |
3016 | | /// |
3017 | | /// The constraints in the resulting list are to be treated as if in a |
3018 | | /// conjunction ("and"). |
3019 | 993 | void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const { |
3020 | 993 | TemplateParams->getAssociatedConstraints(AC); |
3021 | 993 | } |
3022 | | |
3023 | 0 | bool hasAssociatedConstraints() const { |
3024 | 0 | return TemplateParams->hasAssociatedConstraints(); |
3025 | 0 | } |
3026 | | |
3027 | | /// \brief Retrieve the member variable template partial specialization from |
3028 | | /// which this particular variable template partial specialization was |
3029 | | /// instantiated. |
3030 | | /// |
3031 | | /// \code |
3032 | | /// template<typename T> |
3033 | | /// struct Outer { |
3034 | | /// template<typename U> U Inner; |
3035 | | /// template<typename U> U* Inner<U*> = (U*)(0); // #1 |
3036 | | /// }; |
3037 | | /// |
3038 | | /// template int* Outer<float>::Inner<int*>; |
3039 | | /// \endcode |
3040 | | /// |
3041 | | /// In this example, the instantiation of \c Outer<float>::Inner<int*> will |
3042 | | /// end up instantiating the partial specialization |
3043 | | /// \c Outer<float>::Inner<U*>, which itself was instantiated from the |
3044 | | /// variable template partial specialization \c Outer<T>::Inner<U*>. Given |
3045 | | /// \c Outer<float>::Inner<U*>, this function would return |
3046 | | /// \c Outer<T>::Inner<U*>. |
3047 | 742 | VarTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { |
3048 | 742 | const auto *First = |
3049 | 742 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
3050 | 742 | return First->InstantiatedFromMember.getPointer(); |
3051 | 742 | } |
3052 | | |
3053 | | void |
3054 | 59 | setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec) { |
3055 | 59 | auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
3056 | 59 | First->InstantiatedFromMember.setPointer(PartialSpec); |
3057 | 59 | } |
3058 | | |
3059 | | /// Determines whether this variable template partial specialization |
3060 | | /// was a specialization of a member partial specialization. |
3061 | | /// |
3062 | | /// In the following example, the member template partial specialization |
3063 | | /// \c X<int>::Inner<T*> is a member specialization. |
3064 | | /// |
3065 | | /// \code |
3066 | | /// template<typename T> |
3067 | | /// struct X { |
3068 | | /// template<typename U> U Inner; |
3069 | | /// template<typename U> U* Inner<U*> = (U*)(0); |
3070 | | /// }; |
3071 | | /// |
3072 | | /// template<> template<typename T> |
3073 | | /// U* X<int>::Inner<T*> = (T*)(0) + 1; |
3074 | | /// \endcode |
3075 | 2.32k | bool isMemberSpecialization() { |
3076 | 2.32k | const auto *First = |
3077 | 2.32k | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
3078 | 2.32k | return First->InstantiatedFromMember.getInt(); |
3079 | 2.32k | } |
3080 | | |
3081 | | /// Note that this member template is a specialization. |
3082 | 21 | void setMemberSpecialization() { |
3083 | 21 | auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
3084 | 21 | assert(First->InstantiatedFromMember.getPointer() && |
3085 | 21 | "Only member templates can be member template specializations"); |
3086 | 0 | return First->InstantiatedFromMember.setInt(true); |
3087 | 21 | } |
3088 | | |
3089 | 165 | void Profile(llvm::FoldingSetNodeID &ID) const { |
3090 | 165 | Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(), |
3091 | 165 | getASTContext()); |
3092 | 165 | } |
3093 | | |
3094 | | static void |
3095 | | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, |
3096 | | TemplateParameterList *TPL, ASTContext &Context); |
3097 | | |
3098 | 23.3M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3099 | | |
3100 | 23.3M | static bool classofKind(Kind K) { |
3101 | 23.3M | return K == VarTemplatePartialSpecialization; |
3102 | 23.3M | } |
3103 | | }; |
3104 | | |
3105 | | /// Declaration of a variable template. |
3106 | | class VarTemplateDecl : public RedeclarableTemplateDecl { |
3107 | | protected: |
3108 | | /// Data that is common to all of the declarations of a given |
3109 | | /// variable template. |
3110 | | struct Common : CommonBase { |
3111 | | /// The variable template specializations for this variable |
3112 | | /// template, including explicit specializations and instantiations. |
3113 | | llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations; |
3114 | | |
3115 | | /// The variable template partial specializations for this variable |
3116 | | /// template. |
3117 | | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> |
3118 | | PartialSpecializations; |
3119 | | |
3120 | 3.37k | Common() = default; |
3121 | | }; |
3122 | | |
3123 | | /// Retrieve the set of specializations of this variable template. |
3124 | | llvm::FoldingSetVector<VarTemplateSpecializationDecl> & |
3125 | | getSpecializations() const; |
3126 | | |
3127 | | /// Retrieve the set of partial specializations of this class |
3128 | | /// template. |
3129 | | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> & |
3130 | | getPartialSpecializations() const; |
3131 | | |
3132 | | VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
3133 | | DeclarationName Name, TemplateParameterList *Params, |
3134 | | NamedDecl *Decl) |
3135 | 5.19k | : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {} |
3136 | | |
3137 | | CommonBase *newCommon(ASTContext &C) const override; |
3138 | | |
3139 | 27.4k | Common *getCommonPtr() const { |
3140 | 27.4k | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
3141 | 27.4k | } |
3142 | | |
3143 | | public: |
3144 | | friend class ASTDeclReader; |
3145 | | friend class ASTDeclWriter; |
3146 | | |
3147 | | /// Load any lazily-loaded specializations from the external source. |
3148 | | void LoadLazySpecializations() const; |
3149 | | |
3150 | | /// Get the underlying variable declarations of the template. |
3151 | 23.7k | VarDecl *getTemplatedDecl() const { |
3152 | 23.7k | return static_cast<VarDecl *>(TemplatedDecl); |
3153 | 23.7k | } |
3154 | | |
3155 | | /// Returns whether this template declaration defines the primary |
3156 | | /// variable pattern. |
3157 | 233 | bool isThisDeclarationADefinition() const { |
3158 | 233 | return getTemplatedDecl()->isThisDeclarationADefinition(); |
3159 | 233 | } |
3160 | | |
3161 | | VarTemplateDecl *getDefinition(); |
3162 | | |
3163 | | /// Create a variable template node. |
3164 | | static VarTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
3165 | | SourceLocation L, DeclarationName Name, |
3166 | | TemplateParameterList *Params, |
3167 | | VarDecl *Decl); |
3168 | | |
3169 | | /// Create an empty variable template node. |
3170 | | static VarTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3171 | | |
3172 | | /// Return the specialization with the provided arguments if it exists, |
3173 | | /// otherwise return the insertion point. |
3174 | | VarTemplateSpecializationDecl * |
3175 | | findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); |
3176 | | |
3177 | | /// Insert the specified specialization knowing that it is not already |
3178 | | /// in. InsertPos must be obtained from findSpecialization. |
3179 | | void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos); |
3180 | | |
3181 | 40.6k | VarTemplateDecl *getCanonicalDecl() override { |
3182 | 40.6k | return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl()); |
3183 | 40.6k | } |
3184 | 0 | const VarTemplateDecl *getCanonicalDecl() const { |
3185 | 0 | return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl()); |
3186 | 0 | } |
3187 | | |
3188 | | /// Retrieve the previous declaration of this variable template, or |
3189 | | /// nullptr if no such declaration exists. |
3190 | 92 | VarTemplateDecl *getPreviousDecl() { |
3191 | 92 | return cast_or_null<VarTemplateDecl>( |
3192 | 92 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
3193 | 92 | } |
3194 | 0 | const VarTemplateDecl *getPreviousDecl() const { |
3195 | 0 | return cast_or_null<VarTemplateDecl>( |
3196 | 0 | static_cast<const RedeclarableTemplateDecl *>( |
3197 | 0 | this)->getPreviousDecl()); |
3198 | 0 | } |
3199 | | |
3200 | 62 | VarTemplateDecl *getMostRecentDecl() { |
3201 | 62 | return cast<VarTemplateDecl>( |
3202 | 62 | static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl()); |
3203 | 62 | } |
3204 | 0 | const VarTemplateDecl *getMostRecentDecl() const { |
3205 | 0 | return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl(); |
3206 | 0 | } |
3207 | | |
3208 | 9.46k | VarTemplateDecl *getInstantiatedFromMemberTemplate() const { |
3209 | 9.46k | return cast_or_null<VarTemplateDecl>( |
3210 | 9.46k | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
3211 | 9.46k | } |
3212 | | |
3213 | | /// Return the partial specialization with the provided arguments if it |
3214 | | /// exists, otherwise return the insertion point. |
3215 | | VarTemplatePartialSpecializationDecl * |
3216 | | findPartialSpecialization(ArrayRef<TemplateArgument> Args, |
3217 | | TemplateParameterList *TPL, void *&InsertPos); |
3218 | | |
3219 | | /// Insert the specified partial specialization knowing that it is not |
3220 | | /// already in. InsertPos must be obtained from findPartialSpecialization. |
3221 | | void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, |
3222 | | void *InsertPos); |
3223 | | |
3224 | | /// Retrieve the partial specializations as an ordered list. |
3225 | | void getPartialSpecializations( |
3226 | | SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) const; |
3227 | | |
3228 | | /// Find a variable template partial specialization which was |
3229 | | /// instantiated |
3230 | | /// from the given member partial specialization. |
3231 | | /// |
3232 | | /// \param D a member variable template partial specialization. |
3233 | | /// |
3234 | | /// \returns the variable template partial specialization which was |
3235 | | /// instantiated |
3236 | | /// from the given member partial specialization, or nullptr if no such |
3237 | | /// partial specialization exists. |
3238 | | VarTemplatePartialSpecializationDecl *findPartialSpecInstantiatedFromMember( |
3239 | | VarTemplatePartialSpecializationDecl *D); |
3240 | | |
3241 | | using spec_iterator = SpecIterator<VarTemplateSpecializationDecl>; |
3242 | | using spec_range = llvm::iterator_range<spec_iterator>; |
3243 | | |
3244 | 2.16k | spec_range specializations() const { |
3245 | 2.16k | return spec_range(spec_begin(), spec_end()); |
3246 | 2.16k | } |
3247 | | |
3248 | 2.16k | spec_iterator spec_begin() const { |
3249 | 2.16k | return makeSpecIterator(getSpecializations(), false); |
3250 | 2.16k | } |
3251 | | |
3252 | 2.16k | spec_iterator spec_end() const { |
3253 | 2.16k | return makeSpecIterator(getSpecializations(), true); |
3254 | 2.16k | } |
3255 | | |
3256 | | // Implement isa/cast/dyncast support |
3257 | 26.2M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3258 | 26.2M | static bool classofKind(Kind K) { return K == VarTemplate; } |
3259 | | }; |
3260 | | |
3261 | | /// Declaration of a C++2a concept. |
3262 | | class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> { |
3263 | | protected: |
3264 | | Expr *ConstraintExpr; |
3265 | | |
3266 | | ConceptDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, |
3267 | | TemplateParameterList *Params, Expr *ConstraintExpr) |
3268 | | : TemplateDecl(Concept, DC, L, Name, Params), |
3269 | 1.26k | ConstraintExpr(ConstraintExpr) {}; |
3270 | | public: |
3271 | | static ConceptDecl *Create(ASTContext &C, DeclContext *DC, |
3272 | | SourceLocation L, DeclarationName Name, |
3273 | | TemplateParameterList *Params, |
3274 | | Expr *ConstraintExpr); |
3275 | | static ConceptDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3276 | | |
3277 | 10.5k | Expr *getConstraintExpr() const { |
3278 | 10.5k | return ConstraintExpr; |
3279 | 10.5k | } |
3280 | | |
3281 | 41 | SourceRange getSourceRange() const override LLVM_READONLY { |
3282 | 41 | return SourceRange(getTemplateParameters()->getTemplateLoc(), |
3283 | 41 | ConstraintExpr->getEndLoc()); |
3284 | 41 | } |
3285 | | |
3286 | 3.19k | bool isTypeConcept() const { |
3287 | 3.19k | return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0)); |
3288 | 3.19k | } |
3289 | | |
3290 | 38.1k | ConceptDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3291 | 0 | const ConceptDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3292 | | |
3293 | | // Implement isa/cast/dyncast/etc. |
3294 | 20.0M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3295 | 20.0M | static bool classofKind(Kind K) { return K == Concept; } |
3296 | | |
3297 | | friend class ASTReader; |
3298 | | friend class ASTDeclReader; |
3299 | | friend class ASTDeclWriter; |
3300 | | }; |
3301 | | |
3302 | | /// A template parameter object. |
3303 | | /// |
3304 | | /// Template parameter objects represent values of class type used as template |
3305 | | /// arguments. There is one template parameter object for each such distinct |
3306 | | /// value used as a template argument across the program. |
3307 | | /// |
3308 | | /// \code |
3309 | | /// struct A { int x, y; }; |
3310 | | /// template<A> struct S; |
3311 | | /// S<A{1, 2}> s1; |
3312 | | /// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl. |
3313 | | /// \endcode |
3314 | | class TemplateParamObjectDecl : public ValueDecl, |
3315 | | public Mergeable<TemplateParamObjectDecl>, |
3316 | | public llvm::FoldingSetNode { |
3317 | | private: |
3318 | | /// The value of this template parameter object. |
3319 | | APValue Value; |
3320 | | |
3321 | | TemplateParamObjectDecl(DeclContext *DC, QualType T, const APValue &V) |
3322 | | : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(), |
3323 | | T), |
3324 | 271 | Value(V) {} |
3325 | | |
3326 | | static TemplateParamObjectDecl *Create(const ASTContext &C, QualType T, |
3327 | | const APValue &V); |
3328 | | static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C, |
3329 | | unsigned ID); |
3330 | | |
3331 | | /// Only ASTContext::getTemplateParamObjectDecl and deserialization |
3332 | | /// create these. |
3333 | | friend class ASTContext; |
3334 | | friend class ASTReader; |
3335 | | friend class ASTDeclReader; |
3336 | | |
3337 | | public: |
3338 | | /// Print this template parameter object in a human-readable format. |
3339 | | void printName(llvm::raw_ostream &OS) const override; |
3340 | | |
3341 | | /// Print this object as an equivalent expression. |
3342 | | void printAsExpr(llvm::raw_ostream &OS) const; |
3343 | | void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const; |
3344 | | |
3345 | | /// Print this object as an initializer suitable for a variable of the |
3346 | | /// object's type. |
3347 | | void printAsInit(llvm::raw_ostream &OS) const; |
3348 | | void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const; |
3349 | | |
3350 | 1.46k | const APValue &getValue() const { return Value; } |
3351 | | |
3352 | | static void Profile(llvm::FoldingSetNodeID &ID, QualType T, |
3353 | 537 | const APValue &V) { |
3354 | 537 | ID.AddPointer(T.getCanonicalType().getAsOpaquePtr()); |
3355 | 537 | V.Profile(ID); |
3356 | 537 | } |
3357 | 181 | void Profile(llvm::FoldingSetNodeID &ID) { |
3358 | 181 | Profile(ID, getType(), getValue()); |
3359 | 181 | } |
3360 | | |
3361 | 1.18k | TemplateParamObjectDecl *getCanonicalDecl() override { |
3362 | 1.18k | return getFirstDecl(); |
3363 | 1.18k | } |
3364 | 0 | const TemplateParamObjectDecl *getCanonicalDecl() const { |
3365 | 0 | return getFirstDecl(); |
3366 | 0 | } |
3367 | | |
3368 | 21.2M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3369 | 21.2M | static bool classofKind(Kind K) { return K == TemplateParamObject; } |
3370 | | }; |
3371 | | |
3372 | 828k | inline NamedDecl *getAsNamedDecl(TemplateParameter P) { |
3373 | 828k | if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>()) |
3374 | 391k | return PD; |
3375 | 437k | if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>()) |
3376 | 434k | return PD; |
3377 | 2.07k | return P.get<TemplateTemplateParmDecl *>(); |
3378 | 437k | } |
3379 | | |
3380 | 62.9k | inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) { |
3381 | 62.9k | auto *TD = dyn_cast<TemplateDecl>(D); |
3382 | 62.9k | return TD && (4.61k isa<ClassTemplateDecl>(TD)4.61k || |
3383 | 4.61k | isa<ClassTemplatePartialSpecializationDecl>(TD)466 || |
3384 | 4.61k | isa<TypeAliasTemplateDecl>(TD)466 || |
3385 | 4.61k | isa<TemplateTemplateParmDecl>(TD)286 ) |
3386 | 62.9k | ? TD4.50k |
3387 | 62.9k | : nullptr58.4k ; |
3388 | 62.9k | } |
3389 | | |
3390 | | /// Check whether the template parameter is a pack expansion, and if so, |
3391 | | /// determine the number of parameters produced by that expansion. For instance: |
3392 | | /// |
3393 | | /// \code |
3394 | | /// template<typename ...Ts> struct A { |
3395 | | /// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B; |
3396 | | /// }; |
3397 | | /// \endcode |
3398 | | /// |
3399 | | /// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us |
3400 | | /// is not a pack expansion, so returns an empty Optional. |
3401 | 17.8M | inline Optional<unsigned> getExpandedPackSize(const NamedDecl *Param) { |
3402 | 17.8M | if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) { |
3403 | 14.3M | if (TTP->isExpandedParameterPack()) |
3404 | 10 | return TTP->getNumExpansionParameters(); |
3405 | 14.3M | } |
3406 | | |
3407 | 17.8M | if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) { |
3408 | 3.45M | if (NTTP->isExpandedParameterPack()) |
3409 | 180 | return NTTP->getNumExpansionTypes(); |
3410 | 3.45M | } |
3411 | | |
3412 | 17.8M | if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) { |
3413 | 45.7k | if (TTP->isExpandedParameterPack()) |
3414 | 8.25k | return TTP->getNumExpansionTemplateParameters(); |
3415 | 45.7k | } |
3416 | | |
3417 | 17.8M | return None; |
3418 | 17.8M | } |
3419 | | |
3420 | | } // namespace clang |
3421 | | |
3422 | | #endif // LLVM_CLANG_AST_DECLTEMPLATE_H |