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