1 //===- TemplateName.h - C++ Template Name Representation --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the TemplateName interface and subclasses.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_AST_TEMPLATENAME_H
14 #define LLVM_CLANG_AST_TEMPLATENAME_H
15
16 #include "clang/AST/DependenceFlags.h"
17 #include "clang/AST/NestedNameSpecifier.h"
18 #include "clang/Basic/LLVM.h"
19 #include "clang/Basic/OperatorKinds.h"
20 #include "clang/Basic/UnsignedOrNone.h"
21 #include "llvm/ADT/FoldingSet.h"
22 #include "llvm/ADT/PointerIntPair.h"
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/Support/PointerLikeTypeTraits.h"
25 #include <cassert>
26 #include <optional>
27
28 namespace clang {
29
30 class ASTContext;
31 class Decl;
32 class DependentTemplateName;
33 class IdentifierInfo;
34 class NamedDecl;
35 class NestedNameSpecifier;
36 enum OverloadedOperatorKind : int;
37 class OverloadedTemplateStorage;
38 class AssumedTemplateStorage;
39 class DeducedTemplateStorage;
40 struct PrintingPolicy;
41 class QualifiedTemplateName;
42 class SubstTemplateTemplateParmPackStorage;
43 class SubstTemplateTemplateParmStorage;
44 class TemplateArgument;
45 class TemplateDecl;
46 class TemplateTemplateParmDecl;
47 class UsingShadowDecl;
48
49 /// Implementation class used to describe either a set of overloaded
50 /// template names or an already-substituted template template parameter pack.
51 class UncommonTemplateNameStorage {
52 protected:
53 enum Kind {
54 Overloaded,
55 Assumed, // defined in DeclarationName.h
56 Deduced,
57 SubstTemplateTemplateParm,
58 SubstTemplateTemplateParmPack
59 };
60
61 struct BitsTag {
62 LLVM_PREFERRED_TYPE(Kind)
63 unsigned Kind : 3;
64
65 // The template parameter index.
66 unsigned Index : 14;
67
68 /// The pack index, or the number of stored templates
69 /// or template arguments, depending on which subclass we have.
70 unsigned Data : 15;
71 };
72
73 union {
74 struct BitsTag Bits;
75 void *PointerAlignment;
76 };
77
UncommonTemplateNameStorage(Kind Kind,unsigned Index,unsigned Data)78 UncommonTemplateNameStorage(Kind Kind, unsigned Index, unsigned Data) {
79 Bits.Kind = Kind;
80 Bits.Index = Index;
81 Bits.Data = Data;
82 }
83
84 public:
getAsOverloadedStorage()85 OverloadedTemplateStorage *getAsOverloadedStorage() {
86 return Bits.Kind == Overloaded
87 ? reinterpret_cast<OverloadedTemplateStorage *>(this)
88 : nullptr;
89 }
90
getAsAssumedTemplateName()91 AssumedTemplateStorage *getAsAssumedTemplateName() {
92 return Bits.Kind == Assumed
93 ? reinterpret_cast<AssumedTemplateStorage *>(this)
94 : nullptr;
95 }
96
getAsDeducedTemplateName()97 DeducedTemplateStorage *getAsDeducedTemplateName() {
98 return Bits.Kind == Deduced
99 ? reinterpret_cast<DeducedTemplateStorage *>(this)
100 : nullptr;
101 }
102
getAsSubstTemplateTemplateParm()103 SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() {
104 return Bits.Kind == SubstTemplateTemplateParm
105 ? reinterpret_cast<SubstTemplateTemplateParmStorage *>(this)
106 : nullptr;
107 }
108
getAsSubstTemplateTemplateParmPack()109 SubstTemplateTemplateParmPackStorage *getAsSubstTemplateTemplateParmPack() {
110 return Bits.Kind == SubstTemplateTemplateParmPack
111 ? reinterpret_cast<SubstTemplateTemplateParmPackStorage *>(this)
112 : nullptr;
113 }
114 };
115
116 /// A structure for storing the information associated with an
117 /// overloaded template name.
118 class OverloadedTemplateStorage : public UncommonTemplateNameStorage {
119 friend class ASTContext;
120
OverloadedTemplateStorage(unsigned size)121 OverloadedTemplateStorage(unsigned size)
122 : UncommonTemplateNameStorage(Overloaded, 0, size) {}
123
getStorage()124 NamedDecl **getStorage() {
125 return reinterpret_cast<NamedDecl **>(this + 1);
126 }
getStorage()127 NamedDecl * const *getStorage() const {
128 return reinterpret_cast<NamedDecl *const *>(this + 1);
129 }
130
131 public:
size()132 unsigned size() const { return Bits.Data; }
133
134 using iterator = NamedDecl *const *;
135
begin()136 iterator begin() const { return getStorage(); }
end()137 iterator end() const { return getStorage() + Bits.Data; }
138
decls()139 llvm::ArrayRef<NamedDecl*> decls() const {
140 return llvm::ArrayRef(begin(), end());
141 }
142 };
143
144 /// A structure for storing an already-substituted template template
145 /// parameter pack.
146 ///
147 /// This kind of template names occurs when the parameter pack has been
148 /// provided with a template template argument pack in a context where its
149 /// enclosing pack expansion could not be fully expanded.
150 class SubstTemplateTemplateParmPackStorage : public UncommonTemplateNameStorage,
151 public llvm::FoldingSetNode {
152 const TemplateArgument *Arguments;
153 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
154
155 public:
156 SubstTemplateTemplateParmPackStorage(ArrayRef<TemplateArgument> ArgPack,
157 Decl *AssociatedDecl, unsigned Index,
158 bool Final);
159
160 /// A template-like entity which owns the whole pattern being substituted.
161 /// This will own a set of template parameters.
162 Decl *getAssociatedDecl() const;
163
164 /// Returns the index of the replaced parameter in the associated declaration.
165 /// This should match the result of `getParameterPack()->getIndex()`.
getIndex()166 unsigned getIndex() const { return Bits.Index; }
167
168 // When true the substitution will be 'Final' (subst node won't be placed).
169 bool getFinal() const;
170
171 /// Retrieve the template template parameter pack being substituted.
172 TemplateTemplateParmDecl *getParameterPack() const;
173
174 /// Retrieve the template template argument pack with which this
175 /// parameter was substituted.
176 TemplateArgument getArgumentPack() const;
177
178 void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context);
179
180 static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
181 const TemplateArgument &ArgPack, Decl *AssociatedDecl,
182 unsigned Index, bool Final);
183 };
184
185 struct DefaultArguments {
186 // The position in the template parameter list
187 // the first argument corresponds to.
188 unsigned StartPos;
189 ArrayRef<TemplateArgument> Args;
190
191 operator bool() const { return !Args.empty(); }
192 };
193
194 /// Represents a C++ template name within the type system.
195 ///
196 /// A C++ template name refers to a template within the C++ type
197 /// system. In most cases, a template name is simply a reference to a
198 /// class template, e.g.
199 ///
200 /// \code
201 /// template<typename T> class X { };
202 ///
203 /// X<int> xi;
204 /// \endcode
205 ///
206 /// Here, the 'X' in \c X<int> is a template name that refers to the
207 /// declaration of the class template X, above. Template names can
208 /// also refer to function templates, C++0x template aliases, etc.
209 ///
210 /// Some template names are dependent. For example, consider:
211 ///
212 /// \code
213 /// template<typename MetaFun, typename T1, typename T2> struct apply2 {
214 /// typedef typename MetaFun::template apply<T1, T2>::type type;
215 /// };
216 /// \endcode
217 ///
218 /// Here, "apply" is treated as a template name within the typename
219 /// specifier in the typedef. "apply" is a nested template, and can
220 /// only be understood in the context of a template instantiation,
221 /// hence is represented as a dependent template name.
222 class TemplateName {
223 // NameDecl is either a TemplateDecl or a UsingShadowDecl depending on the
224 // NameKind.
225 // !! There is no free low bits in 32-bit builds to discriminate more than 4
226 // pointer types in PointerUnion.
227 using StorageType =
228 llvm::PointerUnion<Decl *, UncommonTemplateNameStorage *,
229 QualifiedTemplateName *, DependentTemplateName *>;
230
231 StorageType Storage;
232
233 explicit TemplateName(void *Ptr);
234
235 public:
236 // Kind of name that is actually stored.
237 enum NameKind {
238 /// A single template declaration.
239 Template,
240
241 /// A set of overloaded template declarations.
242 OverloadedTemplate,
243
244 /// An unqualified-id that has been assumed to name a function template
245 /// that will be found by ADL.
246 AssumedTemplate,
247
248 /// A qualified template name, where the qualification is kept
249 /// to describe the source code as written.
250 QualifiedTemplate,
251
252 /// A dependent template name that has not been resolved to a
253 /// template (or set of templates).
254 DependentTemplate,
255
256 /// A template template parameter that has been substituted
257 /// for some other template name.
258 SubstTemplateTemplateParm,
259
260 /// A template template parameter pack that has been substituted for
261 /// a template template argument pack, but has not yet been expanded into
262 /// individual arguments.
263 SubstTemplateTemplateParmPack,
264
265 /// A template name that refers to a template declaration found through a
266 /// specific using shadow declaration.
267 UsingTemplate,
268
269 /// A template name that refers to another TemplateName with deduced default
270 /// arguments.
271 DeducedTemplate,
272 };
273
274 TemplateName() = default;
275 explicit TemplateName(TemplateDecl *Template);
276 explicit TemplateName(OverloadedTemplateStorage *Storage);
277 explicit TemplateName(AssumedTemplateStorage *Storage);
278 explicit TemplateName(SubstTemplateTemplateParmStorage *Storage);
279 explicit TemplateName(SubstTemplateTemplateParmPackStorage *Storage);
280 explicit TemplateName(QualifiedTemplateName *Qual);
281 explicit TemplateName(DependentTemplateName *Dep);
282 explicit TemplateName(UsingShadowDecl *Using);
283 explicit TemplateName(DeducedTemplateStorage *Deduced);
284
285 /// Determine whether this template name is NULL.
286 bool isNull() const;
287
288 // Get the kind of name that is actually stored.
289 NameKind getKind() const;
290
291 /// Retrieve the underlying template declaration that
292 /// this template name refers to, if known.
293 ///
294 /// \returns The template declaration that this template name refers
295 /// to, if any. If the template name does not refer to a specific
296 /// declaration because it is a dependent name, or if it refers to a
297 /// set of function templates, returns NULL.
298 TemplateDecl *getAsTemplateDecl(bool IgnoreDeduced = false) const;
299
300 /// Retrieves the underlying template declaration that
301 /// this template name refers to, along with the
302 /// deduced default arguments, if any.
303 std::pair<TemplateDecl *, DefaultArguments>
304 getTemplateDeclAndDefaultArgs() const;
305
306 /// Retrieve the underlying, overloaded function template
307 /// declarations that this template name refers to, if known.
308 ///
309 /// \returns The set of overloaded function templates that this template
310 /// name refers to, if known. If the template name does not refer to a
311 /// specific set of function templates because it is a dependent name or
312 /// refers to a single template, returns NULL.
313 OverloadedTemplateStorage *getAsOverloadedTemplate() const;
314
315 /// Retrieve information on a name that has been assumed to be a
316 /// template-name in order to permit a call via ADL.
317 AssumedTemplateStorage *getAsAssumedTemplateName() const;
318
319 /// Retrieve the substituted template template parameter, if
320 /// known.
321 ///
322 /// \returns The storage for the substituted template template parameter,
323 /// if known. Otherwise, returns NULL.
324 SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() const;
325
326 /// Retrieve the substituted template template parameter pack, if
327 /// known.
328 ///
329 /// \returns The storage for the substituted template template parameter pack,
330 /// if known. Otherwise, returns NULL.
331 SubstTemplateTemplateParmPackStorage *
332 getAsSubstTemplateTemplateParmPack() const;
333
334 /// Retrieve the underlying qualified template name
335 /// structure, if any.
336 QualifiedTemplateName *getAsQualifiedTemplateName() const;
337
338 /// Retrieve the underlying dependent template name
339 /// structure, if any.
340 DependentTemplateName *getAsDependentTemplateName() const;
341
342 /// Retrieve the using shadow declaration through which the underlying
343 /// template declaration is introduced, if any.
344 UsingShadowDecl *getAsUsingShadowDecl() const;
345
346 /// Retrieve the deduced template info, if any.
347 DeducedTemplateStorage *getAsDeducedTemplateName() const;
348
349 std::optional<TemplateName> desugar(bool IgnoreDeduced) const;
350
351 TemplateName getUnderlying() const;
352
353 TemplateNameDependence getDependence() const;
354
355 /// Determines whether this is a dependent template name.
356 bool isDependent() const;
357
358 /// Determines whether this is a template name that somehow
359 /// depends on a template parameter.
360 bool isInstantiationDependent() const;
361
362 /// Determines whether this template name contains an
363 /// unexpanded parameter pack (for C++0x variadic templates).
364 bool containsUnexpandedParameterPack() const;
365
366 enum class Qualified { None, AsWritten };
367 /// Print the template name.
368 ///
369 /// \param OS the output stream to which the template name will be
370 /// printed.
371 ///
372 /// \param Qual print the (Qualified::None) simple name,
373 /// (Qualified::AsWritten) any written (possibly partial) qualifier, or
374 /// (Qualified::Fully) the fully qualified name.
375 void print(raw_ostream &OS, const PrintingPolicy &Policy,
376 Qualified Qual = Qualified::AsWritten) const;
377
378 /// Debugging aid that dumps the template name.
379 void dump(raw_ostream &OS, const ASTContext &Context) const;
380
381 /// Debugging aid that dumps the template name to standard
382 /// error.
383 void dump() const;
384
Profile(llvm::FoldingSetNodeID & ID)385 void Profile(llvm::FoldingSetNodeID &ID) {
386 ID.AddPointer(Storage.getOpaqueValue());
387 }
388
389 /// Retrieve the template name as a void pointer.
getAsVoidPointer()390 void *getAsVoidPointer() const { return Storage.getOpaqueValue(); }
391
392 /// Build a template name from a void pointer.
getFromVoidPointer(void * Ptr)393 static TemplateName getFromVoidPointer(void *Ptr) {
394 return TemplateName(Ptr);
395 }
396
397 /// Structural equality.
398 bool operator==(TemplateName Other) const { return Storage == Other.Storage; }
399 bool operator!=(TemplateName Other) const { return !operator==(Other); }
400 };
401
402 /// Insertion operator for diagnostics. This allows sending TemplateName's
403 /// into a diagnostic with <<.
404 const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
405 TemplateName N);
406
407 /// A structure for storing the information associated with a
408 /// substituted template template parameter.
409 class SubstTemplateTemplateParmStorage
410 : public UncommonTemplateNameStorage, public llvm::FoldingSetNode {
411 friend class ASTContext;
412
413 TemplateName Replacement;
414 Decl *AssociatedDecl;
415
SubstTemplateTemplateParmStorage(TemplateName Replacement,Decl * AssociatedDecl,unsigned Index,UnsignedOrNone PackIndex,bool Final)416 SubstTemplateTemplateParmStorage(TemplateName Replacement,
417 Decl *AssociatedDecl, unsigned Index,
418 UnsignedOrNone PackIndex, bool Final)
419 : UncommonTemplateNameStorage(
420 SubstTemplateTemplateParm, Index,
421 ((PackIndex.toInternalRepresentation()) << 1) | Final),
422 Replacement(Replacement), AssociatedDecl(AssociatedDecl) {
423 assert(AssociatedDecl != nullptr);
424 }
425
426 public:
427 /// A template-like entity which owns the whole pattern being substituted.
428 /// This will own a set of template parameters.
getAssociatedDecl()429 Decl *getAssociatedDecl() const { return AssociatedDecl; }
430
431 /// Returns the index of the replaced parameter in the associated declaration.
432 /// This should match the result of `getParameter()->getIndex()`.
getIndex()433 unsigned getIndex() const { return Bits.Index; }
434
435 // This substitution is Final, which means the substitution is fully
436 // sugared: it doesn't need to be resugared later.
getFinal()437 bool getFinal() const { return Bits.Data & 1; }
438
getPackIndex()439 UnsignedOrNone getPackIndex() const {
440 return UnsignedOrNone::fromInternalRepresentation(Bits.Data >> 1);
441 }
442
443 TemplateTemplateParmDecl *getParameter() const;
getReplacement()444 TemplateName getReplacement() const { return Replacement; }
445
446 void Profile(llvm::FoldingSetNodeID &ID);
447
448 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Replacement,
449 Decl *AssociatedDecl, unsigned Index,
450 UnsignedOrNone PackIndex, bool Final);
451 };
452
453 class DeducedTemplateStorage : public UncommonTemplateNameStorage,
454 public llvm::FoldingSetNode {
455 friend class ASTContext;
456
457 TemplateName Underlying;
458
459 DeducedTemplateStorage(TemplateName Underlying,
460 const DefaultArguments &DefArgs);
461
462 public:
getUnderlying()463 TemplateName getUnderlying() const { return Underlying; }
464
getDefaultArguments()465 DefaultArguments getDefaultArguments() const {
466 return {/*StartPos=*/Bits.Index,
467 /*Args=*/{reinterpret_cast<const TemplateArgument *>(this + 1),
468 Bits.Data}};
469 }
470
471 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
472
473 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
474 TemplateName Underlying, const DefaultArguments &DefArgs);
475 };
476
getUnderlying()477 inline TemplateName TemplateName::getUnderlying() const {
478 if (SubstTemplateTemplateParmStorage *subst
479 = getAsSubstTemplateTemplateParm())
480 return subst->getReplacement().getUnderlying();
481 return *this;
482 }
483
484 /// Represents a template name as written in source code.
485 ///
486 /// This kind of template name may refer to a template name that was
487 /// preceded by a nested name specifier, e.g., \c std::vector. Here,
488 /// the nested name specifier is "std::" and the template name is the
489 /// declaration for "vector". It may also have been written with the
490 /// 'template' keyword. The QualifiedTemplateName class is only
491 /// used to provide "sugar" for template names, so that they can
492 /// be differentiated from canonical template names. and has no
493 /// semantic meaning. In this manner, it is to TemplateName what
494 /// ElaboratedType is to Type, providing extra syntactic sugar
495 /// for downstream clients.
496 class QualifiedTemplateName : public llvm::FoldingSetNode {
497 friend class ASTContext;
498
499 /// The nested name specifier that qualifies the template name.
500 ///
501 /// The bit is used to indicate whether the "template" keyword was
502 /// present before the template name itself. Note that the
503 /// "template" keyword is always redundant in this case (otherwise,
504 /// the template name would be a dependent name and we would express
505 /// this name with DependentTemplateName).
506 llvm::PointerIntPair<NestedNameSpecifier *, 1> Qualifier;
507
508 /// The underlying template name, it is either
509 /// 1) a Template -- a template declaration that this qualified name refers
510 /// to.
511 /// 2) or a UsingTemplate -- a template declaration introduced by a
512 /// using-shadow declaration.
513 TemplateName UnderlyingTemplate;
514
QualifiedTemplateName(NestedNameSpecifier * NNS,bool TemplateKeyword,TemplateName Template)515 QualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword,
516 TemplateName Template)
517 : Qualifier(NNS, TemplateKeyword ? 1 : 0), UnderlyingTemplate(Template) {
518 assert(UnderlyingTemplate.getKind() == TemplateName::Template ||
519 UnderlyingTemplate.getKind() == TemplateName::UsingTemplate);
520 }
521
522 public:
523 /// Return the nested name specifier that qualifies this name.
getQualifier()524 NestedNameSpecifier *getQualifier() const { return Qualifier.getPointer(); }
525
526 /// Whether the template name was prefixed by the "template"
527 /// keyword.
hasTemplateKeyword()528 bool hasTemplateKeyword() const { return Qualifier.getInt(); }
529
530 /// Return the underlying template name.
getUnderlyingTemplate()531 TemplateName getUnderlyingTemplate() const { return UnderlyingTemplate; }
532
Profile(llvm::FoldingSetNodeID & ID)533 void Profile(llvm::FoldingSetNodeID &ID) {
534 Profile(ID, getQualifier(), hasTemplateKeyword(), UnderlyingTemplate);
535 }
536
Profile(llvm::FoldingSetNodeID & ID,NestedNameSpecifier * NNS,bool TemplateKeyword,TemplateName TN)537 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
538 bool TemplateKeyword, TemplateName TN) {
539 ID.AddPointer(NNS);
540 ID.AddBoolean(TemplateKeyword);
541 ID.AddPointer(TN.getAsVoidPointer());
542 }
543 };
544
545 struct IdentifierOrOverloadedOperator {
546 IdentifierOrOverloadedOperator() = default;
547 IdentifierOrOverloadedOperator(const IdentifierInfo *II);
548 IdentifierOrOverloadedOperator(OverloadedOperatorKind OOK);
549
550 /// Returns the identifier to which this template name refers.
getIdentifierIdentifierOrOverloadedOperator551 const IdentifierInfo *getIdentifier() const {
552 if (getOperator() != OO_None)
553 return nullptr;
554 return reinterpret_cast<const IdentifierInfo *>(PtrOrOp);
555 }
556
557 /// Return the overloaded operator to which this template name refers.
getOperatorIdentifierOrOverloadedOperator558 OverloadedOperatorKind getOperator() const {
559 uintptr_t OOK = -PtrOrOp;
560 return OOK < NUM_OVERLOADED_OPERATORS ? OverloadedOperatorKind(OOK)
561 : OO_None;
562 }
563
564 void Profile(llvm::FoldingSetNodeID &ID) const;
565
566 bool operator==(const IdentifierOrOverloadedOperator &Other) const {
567 return PtrOrOp == Other.PtrOrOp;
568 };
569
570 private:
571 uintptr_t PtrOrOp = 0;
572 };
573
574 /// Represents a dependent template name that cannot be
575 /// resolved prior to template instantiation.
576 ///
577 /// This kind of template name refers to a dependent template name,
578 /// including its nested name specifier (if any). For example,
579 /// DependentTemplateName can refer to "MetaFun::template apply",
580 /// where "MetaFun::" is the nested name specifier and "apply" is the
581 /// template name referenced. The "template" keyword is implied.
582 class DependentTemplateStorage {
583 /// The nested name specifier that qualifies the template
584 /// name.
585 ///
586 /// The bit stored in this qualifier describes whether the \c Name field
587 /// was preceeded by a template keyword.
588 llvm::PointerIntPair<NestedNameSpecifier *, 1, bool> Qualifier;
589
590 /// The dependent template name.
591 IdentifierOrOverloadedOperator Name;
592
593 public:
594 DependentTemplateStorage(NestedNameSpecifier *Qualifier,
595 IdentifierOrOverloadedOperator Name,
596 bool HasTemplateKeyword);
597
598 /// Return the nested name specifier that qualifies this name.
getQualifier()599 NestedNameSpecifier *getQualifier() const { return Qualifier.getPointer(); }
600
getName()601 IdentifierOrOverloadedOperator getName() const { return Name; }
602
603 /// Was this template name was preceeded by the template keyword?
hasTemplateKeyword()604 bool hasTemplateKeyword() const { return Qualifier.getInt(); }
605
606 TemplateNameDependence getDependence() const;
607
Profile(llvm::FoldingSetNodeID & ID)608 void Profile(llvm::FoldingSetNodeID &ID) const {
609 Profile(ID, getQualifier(), getName(), hasTemplateKeyword());
610 }
611
Profile(llvm::FoldingSetNodeID & ID,NestedNameSpecifier * NNS,IdentifierOrOverloadedOperator Name,bool HasTemplateKeyword)612 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
613 IdentifierOrOverloadedOperator Name,
614 bool HasTemplateKeyword) {
615 ID.AddPointer(NNS);
616 ID.AddBoolean(HasTemplateKeyword);
617 Name.Profile(ID);
618 }
619
620 void print(raw_ostream &OS, const PrintingPolicy &Policy) const;
621 };
622
623 class DependentTemplateName : public DependentTemplateStorage,
624 public llvm::FoldingSetNode {
625 friend class ASTContext;
626 using DependentTemplateStorage::DependentTemplateStorage;
DependentTemplateName(const DependentTemplateStorage & S)627 DependentTemplateName(const DependentTemplateStorage &S)
628 : DependentTemplateStorage(S) {}
629 };
630
631 } // namespace clang.
632
633 namespace llvm {
634
635 /// The clang::TemplateName class is effectively a pointer.
636 template<>
637 struct PointerLikeTypeTraits<clang::TemplateName> {
638 static inline void *getAsVoidPointer(clang::TemplateName TN) {
639 return TN.getAsVoidPointer();
640 }
641
642 static inline clang::TemplateName getFromVoidPointer(void *Ptr) {
643 return clang::TemplateName::getFromVoidPointer(Ptr);
644 }
645
646 // No bits are available!
647 static constexpr int NumLowBitsAvailable = 0;
648 };
649
650 } // namespace llvm.
651
652 #endif // LLVM_CLANG_AST_TEMPLATENAME_H
653