Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:43

0001 //===- TemplateName.h - C++ Template Name Representation --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the TemplateName interface and subclasses.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_TEMPLATENAME_H
0014 #define LLVM_CLANG_AST_TEMPLATENAME_H
0015 
0016 #include "clang/AST/DependenceFlags.h"
0017 #include "clang/AST/NestedNameSpecifier.h"
0018 #include "clang/Basic/LLVM.h"
0019 #include "llvm/ADT/FoldingSet.h"
0020 #include "llvm/ADT/PointerIntPair.h"
0021 #include "llvm/ADT/PointerUnion.h"
0022 #include "llvm/Support/PointerLikeTypeTraits.h"
0023 #include <cassert>
0024 #include <optional>
0025 
0026 namespace clang {
0027 
0028 class ASTContext;
0029 class Decl;
0030 class DependentTemplateName;
0031 class IdentifierInfo;
0032 class NamedDecl;
0033 class NestedNameSpecifier;
0034 enum OverloadedOperatorKind : int;
0035 class OverloadedTemplateStorage;
0036 class AssumedTemplateStorage;
0037 class DeducedTemplateStorage;
0038 struct PrintingPolicy;
0039 class QualifiedTemplateName;
0040 class SubstTemplateTemplateParmPackStorage;
0041 class SubstTemplateTemplateParmStorage;
0042 class TemplateArgument;
0043 class TemplateDecl;
0044 class TemplateTemplateParmDecl;
0045 class UsingShadowDecl;
0046 
0047 /// Implementation class used to describe either a set of overloaded
0048 /// template names or an already-substituted template template parameter pack.
0049 class UncommonTemplateNameStorage {
0050 protected:
0051   enum Kind {
0052     Overloaded,
0053     Assumed, // defined in DeclarationName.h
0054     Deduced,
0055     SubstTemplateTemplateParm,
0056     SubstTemplateTemplateParmPack
0057   };
0058 
0059   struct BitsTag {
0060     LLVM_PREFERRED_TYPE(Kind)
0061     unsigned Kind : 3;
0062 
0063     // The template parameter index.
0064     unsigned Index : 14;
0065 
0066     /// The pack index, or the number of stored templates
0067     /// or template arguments, depending on which subclass we have.
0068     unsigned Data : 15;
0069   };
0070 
0071   union {
0072     struct BitsTag Bits;
0073     void *PointerAlignment;
0074   };
0075 
0076   UncommonTemplateNameStorage(Kind Kind, unsigned Index, unsigned Data) {
0077     Bits.Kind = Kind;
0078     Bits.Index = Index;
0079     Bits.Data = Data;
0080   }
0081 
0082 public:
0083   OverloadedTemplateStorage *getAsOverloadedStorage()  {
0084     return Bits.Kind == Overloaded
0085              ? reinterpret_cast<OverloadedTemplateStorage *>(this)
0086              : nullptr;
0087   }
0088 
0089   AssumedTemplateStorage *getAsAssumedTemplateName()  {
0090     return Bits.Kind == Assumed
0091              ? reinterpret_cast<AssumedTemplateStorage *>(this)
0092              : nullptr;
0093   }
0094 
0095   DeducedTemplateStorage *getAsDeducedTemplateName() {
0096     return Bits.Kind == Deduced
0097                ? reinterpret_cast<DeducedTemplateStorage *>(this)
0098                : nullptr;
0099   }
0100 
0101   SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() {
0102     return Bits.Kind == SubstTemplateTemplateParm
0103              ? reinterpret_cast<SubstTemplateTemplateParmStorage *>(this)
0104              : nullptr;
0105   }
0106 
0107   SubstTemplateTemplateParmPackStorage *getAsSubstTemplateTemplateParmPack() {
0108     return Bits.Kind == SubstTemplateTemplateParmPack
0109              ? reinterpret_cast<SubstTemplateTemplateParmPackStorage *>(this)
0110              : nullptr;
0111   }
0112 };
0113 
0114 /// A structure for storing the information associated with an
0115 /// overloaded template name.
0116 class OverloadedTemplateStorage : public UncommonTemplateNameStorage {
0117   friend class ASTContext;
0118 
0119   OverloadedTemplateStorage(unsigned size)
0120       : UncommonTemplateNameStorage(Overloaded, 0, size) {}
0121 
0122   NamedDecl **getStorage() {
0123     return reinterpret_cast<NamedDecl **>(this + 1);
0124   }
0125   NamedDecl * const *getStorage() const {
0126     return reinterpret_cast<NamedDecl *const *>(this + 1);
0127   }
0128 
0129 public:
0130   unsigned size() const { return Bits.Data; }
0131 
0132   using iterator = NamedDecl *const *;
0133 
0134   iterator begin() const { return getStorage(); }
0135   iterator end() const { return getStorage() + Bits.Data; }
0136 
0137   llvm::ArrayRef<NamedDecl*> decls() const {
0138     return llvm::ArrayRef(begin(), end());
0139   }
0140 };
0141 
0142 /// A structure for storing an already-substituted template template
0143 /// parameter pack.
0144 ///
0145 /// This kind of template names occurs when the parameter pack has been
0146 /// provided with a template template argument pack in a context where its
0147 /// enclosing pack expansion could not be fully expanded.
0148 class SubstTemplateTemplateParmPackStorage : public UncommonTemplateNameStorage,
0149                                              public llvm::FoldingSetNode {
0150   const TemplateArgument *Arguments;
0151   llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
0152 
0153 public:
0154   SubstTemplateTemplateParmPackStorage(ArrayRef<TemplateArgument> ArgPack,
0155                                        Decl *AssociatedDecl, unsigned Index,
0156                                        bool Final);
0157 
0158   /// A template-like entity which owns the whole pattern being substituted.
0159   /// This will own a set of template parameters.
0160   Decl *getAssociatedDecl() const;
0161 
0162   /// Returns the index of the replaced parameter in the associated declaration.
0163   /// This should match the result of `getParameterPack()->getIndex()`.
0164   unsigned getIndex() const { return Bits.Index; }
0165 
0166   // When true the substitution will be 'Final' (subst node won't be placed).
0167   bool getFinal() const;
0168 
0169   /// Retrieve the template template parameter pack being substituted.
0170   TemplateTemplateParmDecl *getParameterPack() const;
0171 
0172   /// Retrieve the template template argument pack with which this
0173   /// parameter was substituted.
0174   TemplateArgument getArgumentPack() const;
0175 
0176   void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context);
0177 
0178   static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
0179                       const TemplateArgument &ArgPack, Decl *AssociatedDecl,
0180                       unsigned Index, bool Final);
0181 };
0182 
0183 struct DefaultArguments {
0184   // The position in the template parameter list
0185   // the first argument corresponds to.
0186   unsigned StartPos;
0187   ArrayRef<TemplateArgument> Args;
0188 
0189   operator bool() const { return !Args.empty(); }
0190 };
0191 
0192 /// Represents a C++ template name within the type system.
0193 ///
0194 /// A C++ template name refers to a template within the C++ type
0195 /// system. In most cases, a template name is simply a reference to a
0196 /// class template, e.g.
0197 ///
0198 /// \code
0199 /// template<typename T> class X { };
0200 ///
0201 /// X<int> xi;
0202 /// \endcode
0203 ///
0204 /// Here, the 'X' in \c X<int> is a template name that refers to the
0205 /// declaration of the class template X, above. Template names can
0206 /// also refer to function templates, C++0x template aliases, etc.
0207 ///
0208 /// Some template names are dependent. For example, consider:
0209 ///
0210 /// \code
0211 /// template<typename MetaFun, typename T1, typename T2> struct apply2 {
0212 ///   typedef typename MetaFun::template apply<T1, T2>::type type;
0213 /// };
0214 /// \endcode
0215 ///
0216 /// Here, "apply" is treated as a template name within the typename
0217 /// specifier in the typedef. "apply" is a nested template, and can
0218 /// only be understood in the context of a template instantiation,
0219 /// hence is represented as a dependent template name.
0220 class TemplateName {
0221   // NameDecl is either a TemplateDecl or a UsingShadowDecl depending on the
0222   // NameKind.
0223   // !! There is no free low bits in 32-bit builds to discriminate more than 4
0224   // pointer types in PointerUnion.
0225   using StorageType =
0226       llvm::PointerUnion<Decl *, UncommonTemplateNameStorage *,
0227                          QualifiedTemplateName *, DependentTemplateName *>;
0228 
0229   StorageType Storage;
0230 
0231   explicit TemplateName(void *Ptr);
0232 
0233 public:
0234   // Kind of name that is actually stored.
0235   enum NameKind {
0236     /// A single template declaration.
0237     Template,
0238 
0239     /// A set of overloaded template declarations.
0240     OverloadedTemplate,
0241 
0242     /// An unqualified-id that has been assumed to name a function template
0243     /// that will be found by ADL.
0244     AssumedTemplate,
0245 
0246     /// A qualified template name, where the qualification is kept
0247     /// to describe the source code as written.
0248     QualifiedTemplate,
0249 
0250     /// A dependent template name that has not been resolved to a
0251     /// template (or set of templates).
0252     DependentTemplate,
0253 
0254     /// A template template parameter that has been substituted
0255     /// for some other template name.
0256     SubstTemplateTemplateParm,
0257 
0258     /// A template template parameter pack that has been substituted for
0259     /// a template template argument pack, but has not yet been expanded into
0260     /// individual arguments.
0261     SubstTemplateTemplateParmPack,
0262 
0263     /// A template name that refers to a template declaration found through a
0264     /// specific using shadow declaration.
0265     UsingTemplate,
0266 
0267     /// A template name that refers to another TemplateName with deduced default
0268     /// arguments.
0269     DeducedTemplate,
0270   };
0271 
0272   TemplateName() = default;
0273   explicit TemplateName(TemplateDecl *Template);
0274   explicit TemplateName(OverloadedTemplateStorage *Storage);
0275   explicit TemplateName(AssumedTemplateStorage *Storage);
0276   explicit TemplateName(SubstTemplateTemplateParmStorage *Storage);
0277   explicit TemplateName(SubstTemplateTemplateParmPackStorage *Storage);
0278   explicit TemplateName(QualifiedTemplateName *Qual);
0279   explicit TemplateName(DependentTemplateName *Dep);
0280   explicit TemplateName(UsingShadowDecl *Using);
0281   explicit TemplateName(DeducedTemplateStorage *Deduced);
0282 
0283   /// Determine whether this template name is NULL.
0284   bool isNull() const;
0285 
0286   // Get the kind of name that is actually stored.
0287   NameKind getKind() const;
0288 
0289   /// Retrieve the underlying template declaration that
0290   /// this template name refers to, if known.
0291   ///
0292   /// \returns The template declaration that this template name refers
0293   /// to, if any. If the template name does not refer to a specific
0294   /// declaration because it is a dependent name, or if it refers to a
0295   /// set of function templates, returns NULL.
0296   TemplateDecl *getAsTemplateDecl(bool IgnoreDeduced = false) const;
0297 
0298   /// Retrieves the underlying template declaration that
0299   /// this template name refers to, along with the
0300   /// deduced default arguments, if any.
0301   std::pair<TemplateDecl *, DefaultArguments>
0302   getTemplateDeclAndDefaultArgs() const;
0303 
0304   /// Retrieve the underlying, overloaded function template
0305   /// declarations that this template name refers to, if known.
0306   ///
0307   /// \returns The set of overloaded function templates that this template
0308   /// name refers to, if known. If the template name does not refer to a
0309   /// specific set of function templates because it is a dependent name or
0310   /// refers to a single template, returns NULL.
0311   OverloadedTemplateStorage *getAsOverloadedTemplate() const;
0312 
0313   /// Retrieve information on a name that has been assumed to be a
0314   /// template-name in order to permit a call via ADL.
0315   AssumedTemplateStorage *getAsAssumedTemplateName() const;
0316 
0317   /// Retrieve the substituted template template parameter, if
0318   /// known.
0319   ///
0320   /// \returns The storage for the substituted template template parameter,
0321   /// if known. Otherwise, returns NULL.
0322   SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() const;
0323 
0324   /// Retrieve the substituted template template parameter pack, if
0325   /// known.
0326   ///
0327   /// \returns The storage for the substituted template template parameter pack,
0328   /// if known. Otherwise, returns NULL.
0329   SubstTemplateTemplateParmPackStorage *
0330   getAsSubstTemplateTemplateParmPack() const;
0331 
0332   /// Retrieve the underlying qualified template name
0333   /// structure, if any.
0334   QualifiedTemplateName *getAsQualifiedTemplateName() const;
0335 
0336   /// Retrieve the underlying dependent template name
0337   /// structure, if any.
0338   DependentTemplateName *getAsDependentTemplateName() const;
0339 
0340   /// Retrieve the using shadow declaration through which the underlying
0341   /// template declaration is introduced, if any.
0342   UsingShadowDecl *getAsUsingShadowDecl() const;
0343 
0344   /// Retrieve the deduced template info, if any.
0345   DeducedTemplateStorage *getAsDeducedTemplateName() const;
0346 
0347   std::optional<TemplateName> desugar(bool IgnoreDeduced) const;
0348 
0349   TemplateName getUnderlying() const;
0350 
0351   TemplateNameDependence getDependence() const;
0352 
0353   /// Determines whether this is a dependent template name.
0354   bool isDependent() const;
0355 
0356   /// Determines whether this is a template name that somehow
0357   /// depends on a template parameter.
0358   bool isInstantiationDependent() const;
0359 
0360   /// Determines whether this template name contains an
0361   /// unexpanded parameter pack (for C++0x variadic templates).
0362   bool containsUnexpandedParameterPack() const;
0363 
0364   enum class Qualified { None, AsWritten };
0365   /// Print the template name.
0366   ///
0367   /// \param OS the output stream to which the template name will be
0368   /// printed.
0369   ///
0370   /// \param Qual print the (Qualified::None) simple name,
0371   /// (Qualified::AsWritten) any written (possibly partial) qualifier, or
0372   /// (Qualified::Fully) the fully qualified name.
0373   void print(raw_ostream &OS, const PrintingPolicy &Policy,
0374              Qualified Qual = Qualified::AsWritten) const;
0375 
0376   /// Debugging aid that dumps the template name.
0377   void dump(raw_ostream &OS, const ASTContext &Context) const;
0378 
0379   /// Debugging aid that dumps the template name to standard
0380   /// error.
0381   void dump() const;
0382 
0383   void Profile(llvm::FoldingSetNodeID &ID) {
0384     ID.AddPointer(Storage.getOpaqueValue());
0385   }
0386 
0387   /// Retrieve the template name as a void pointer.
0388   void *getAsVoidPointer() const { return Storage.getOpaqueValue(); }
0389 
0390   /// Build a template name from a void pointer.
0391   static TemplateName getFromVoidPointer(void *Ptr) {
0392     return TemplateName(Ptr);
0393   }
0394 
0395   /// Structural equality.
0396   bool operator==(TemplateName Other) const { return Storage == Other.Storage; }
0397   bool operator!=(TemplateName Other) const { return !operator==(Other); }
0398 };
0399 
0400 /// Insertion operator for diagnostics.  This allows sending TemplateName's
0401 /// into a diagnostic with <<.
0402 const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
0403                                       TemplateName N);
0404 
0405 /// A structure for storing the information associated with a
0406 /// substituted template template parameter.
0407 class SubstTemplateTemplateParmStorage
0408   : public UncommonTemplateNameStorage, public llvm::FoldingSetNode {
0409   friend class ASTContext;
0410 
0411   TemplateName Replacement;
0412   Decl *AssociatedDecl;
0413 
0414   SubstTemplateTemplateParmStorage(TemplateName Replacement,
0415                                    Decl *AssociatedDecl, unsigned Index,
0416                                    std::optional<unsigned> PackIndex)
0417       : UncommonTemplateNameStorage(SubstTemplateTemplateParm, Index,
0418                                     PackIndex ? *PackIndex + 1 : 0),
0419         Replacement(Replacement), AssociatedDecl(AssociatedDecl) {
0420     assert(AssociatedDecl != nullptr);
0421   }
0422 
0423 public:
0424   /// A template-like entity which owns the whole pattern being substituted.
0425   /// This will own a set of template parameters.
0426   Decl *getAssociatedDecl() const { return AssociatedDecl; }
0427 
0428   /// Returns the index of the replaced parameter in the associated declaration.
0429   /// This should match the result of `getParameter()->getIndex()`.
0430   unsigned getIndex() const { return Bits.Index; }
0431 
0432   std::optional<unsigned> getPackIndex() const {
0433     if (Bits.Data == 0)
0434       return std::nullopt;
0435     return Bits.Data - 1;
0436   }
0437 
0438   TemplateTemplateParmDecl *getParameter() const;
0439   TemplateName getReplacement() const { return Replacement; }
0440 
0441   void Profile(llvm::FoldingSetNodeID &ID);
0442 
0443   static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Replacement,
0444                       Decl *AssociatedDecl, unsigned Index,
0445                       std::optional<unsigned> PackIndex);
0446 };
0447 
0448 class DeducedTemplateStorage : public UncommonTemplateNameStorage,
0449                                public llvm::FoldingSetNode {
0450   friend class ASTContext;
0451 
0452   TemplateName Underlying;
0453 
0454   DeducedTemplateStorage(TemplateName Underlying,
0455                          const DefaultArguments &DefArgs);
0456 
0457 public:
0458   TemplateName getUnderlying() const { return Underlying; }
0459 
0460   DefaultArguments getDefaultArguments() const {
0461     return {/*StartPos=*/Bits.Index,
0462             /*Args=*/{reinterpret_cast<const TemplateArgument *>(this + 1),
0463                       Bits.Data}};
0464   }
0465 
0466   void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
0467 
0468   static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
0469                       TemplateName Underlying, const DefaultArguments &DefArgs);
0470 };
0471 
0472 inline TemplateName TemplateName::getUnderlying() const {
0473   if (SubstTemplateTemplateParmStorage *subst
0474         = getAsSubstTemplateTemplateParm())
0475     return subst->getReplacement().getUnderlying();
0476   return *this;
0477 }
0478 
0479 /// Represents a template name as written in source code.
0480 ///
0481 /// This kind of template name may refer to a template name that was
0482 /// preceded by a nested name specifier, e.g., \c std::vector. Here,
0483 /// the nested name specifier is "std::" and the template name is the
0484 /// declaration for "vector". It may also have been written with the
0485 /// 'template' keyword. The QualifiedTemplateName class is only
0486 /// used to provide "sugar" for template names, so that they can
0487 /// be differentiated from canonical template names. and has no
0488 /// semantic meaning. In this manner, it is to TemplateName what
0489 /// ElaboratedType is to Type, providing extra syntactic sugar
0490 /// for downstream clients.
0491 class QualifiedTemplateName : public llvm::FoldingSetNode {
0492   friend class ASTContext;
0493 
0494   /// The nested name specifier that qualifies the template name.
0495   ///
0496   /// The bit is used to indicate whether the "template" keyword was
0497   /// present before the template name itself. Note that the
0498   /// "template" keyword is always redundant in this case (otherwise,
0499   /// the template name would be a dependent name and we would express
0500   /// this name with DependentTemplateName).
0501   llvm::PointerIntPair<NestedNameSpecifier *, 1> Qualifier;
0502 
0503   /// The underlying template name, it is either
0504   ///  1) a Template -- a template declaration that this qualified name refers
0505   ///     to.
0506   ///  2) or a UsingTemplate -- a template declaration introduced by a
0507   ///     using-shadow declaration.
0508   TemplateName UnderlyingTemplate;
0509 
0510   QualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword,
0511                         TemplateName Template)
0512       : Qualifier(NNS, TemplateKeyword ? 1 : 0), UnderlyingTemplate(Template) {
0513     assert(UnderlyingTemplate.getKind() == TemplateName::Template ||
0514            UnderlyingTemplate.getKind() == TemplateName::UsingTemplate);
0515   }
0516 
0517 public:
0518   /// Return the nested name specifier that qualifies this name.
0519   NestedNameSpecifier *getQualifier() const { return Qualifier.getPointer(); }
0520 
0521   /// Whether the template name was prefixed by the "template"
0522   /// keyword.
0523   bool hasTemplateKeyword() const { return Qualifier.getInt(); }
0524 
0525   /// Return the underlying template name.
0526   TemplateName getUnderlyingTemplate() const { return UnderlyingTemplate; }
0527 
0528   void Profile(llvm::FoldingSetNodeID &ID) {
0529     Profile(ID, getQualifier(), hasTemplateKeyword(), UnderlyingTemplate);
0530   }
0531 
0532   static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
0533                       bool TemplateKeyword, TemplateName TN) {
0534     ID.AddPointer(NNS);
0535     ID.AddBoolean(TemplateKeyword);
0536     ID.AddPointer(TN.getAsVoidPointer());
0537   }
0538 };
0539 
0540 /// Represents a dependent template name that cannot be
0541 /// resolved prior to template instantiation.
0542 ///
0543 /// This kind of template name refers to a dependent template name,
0544 /// including its nested name specifier (if any). For example,
0545 /// DependentTemplateName can refer to "MetaFun::template apply",
0546 /// where "MetaFun::" is the nested name specifier and "apply" is the
0547 /// template name referenced. The "template" keyword is implied.
0548 class DependentTemplateName : public llvm::FoldingSetNode {
0549   friend class ASTContext;
0550 
0551   /// The nested name specifier that qualifies the template
0552   /// name.
0553   ///
0554   /// The bit stored in this qualifier describes whether the \c Name field
0555   /// is interpreted as an IdentifierInfo pointer (when clear) or as an
0556   /// overloaded operator kind (when set).
0557   llvm::PointerIntPair<NestedNameSpecifier *, 1, bool> Qualifier;
0558 
0559   /// The dependent template name.
0560   union {
0561     /// The identifier template name.
0562     ///
0563     /// Only valid when the bit on \c Qualifier is clear.
0564     const IdentifierInfo *Identifier;
0565 
0566     /// The overloaded operator name.
0567     ///
0568     /// Only valid when the bit on \c Qualifier is set.
0569     OverloadedOperatorKind Operator;
0570   };
0571 
0572   /// The canonical template name to which this dependent
0573   /// template name refers.
0574   ///
0575   /// The canonical template name for a dependent template name is
0576   /// another dependent template name whose nested name specifier is
0577   /// canonical.
0578   TemplateName CanonicalTemplateName;
0579 
0580   DependentTemplateName(NestedNameSpecifier *Qualifier,
0581                         const IdentifierInfo *Identifier)
0582       : Qualifier(Qualifier, false), Identifier(Identifier),
0583         CanonicalTemplateName(this) {}
0584 
0585   DependentTemplateName(NestedNameSpecifier *Qualifier,
0586                         const IdentifierInfo *Identifier,
0587                         TemplateName Canon)
0588       : Qualifier(Qualifier, false), Identifier(Identifier),
0589         CanonicalTemplateName(Canon) {}
0590 
0591   DependentTemplateName(NestedNameSpecifier *Qualifier,
0592                         OverloadedOperatorKind Operator)
0593       : Qualifier(Qualifier, true), Operator(Operator),
0594         CanonicalTemplateName(this) {}
0595 
0596   DependentTemplateName(NestedNameSpecifier *Qualifier,
0597                         OverloadedOperatorKind Operator,
0598                         TemplateName Canon)
0599        : Qualifier(Qualifier, true), Operator(Operator),
0600          CanonicalTemplateName(Canon) {}
0601 
0602 public:
0603   /// Return the nested name specifier that qualifies this name.
0604   NestedNameSpecifier *getQualifier() const { return Qualifier.getPointer(); }
0605 
0606   /// Determine whether this template name refers to an identifier.
0607   bool isIdentifier() const { return !Qualifier.getInt(); }
0608 
0609   /// Returns the identifier to which this template name refers.
0610   const IdentifierInfo *getIdentifier() const {
0611     assert(isIdentifier() && "Template name isn't an identifier?");
0612     return Identifier;
0613   }
0614 
0615   /// Determine whether this template name refers to an overloaded
0616   /// operator.
0617   bool isOverloadedOperator() const { return Qualifier.getInt(); }
0618 
0619   /// Return the overloaded operator to which this template name refers.
0620   OverloadedOperatorKind getOperator() const {
0621     assert(isOverloadedOperator() &&
0622            "Template name isn't an overloaded operator?");
0623     return Operator;
0624   }
0625 
0626   void Profile(llvm::FoldingSetNodeID &ID) {
0627     if (isIdentifier())
0628       Profile(ID, getQualifier(), getIdentifier());
0629     else
0630       Profile(ID, getQualifier(), getOperator());
0631   }
0632 
0633   static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
0634                       const IdentifierInfo *Identifier) {
0635     ID.AddPointer(NNS);
0636     ID.AddBoolean(false);
0637     ID.AddPointer(Identifier);
0638   }
0639 
0640   static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
0641                       OverloadedOperatorKind Operator) {
0642     ID.AddPointer(NNS);
0643     ID.AddBoolean(true);
0644     ID.AddInteger(Operator);
0645   }
0646 };
0647 
0648 } // namespace clang.
0649 
0650 namespace llvm {
0651 
0652 /// The clang::TemplateName class is effectively a pointer.
0653 template<>
0654 struct PointerLikeTypeTraits<clang::TemplateName> {
0655   static inline void *getAsVoidPointer(clang::TemplateName TN) {
0656     return TN.getAsVoidPointer();
0657   }
0658 
0659   static inline clang::TemplateName getFromVoidPointer(void *Ptr) {
0660     return clang::TemplateName::getFromVoidPointer(Ptr);
0661   }
0662 
0663   // No bits are available!
0664   static constexpr int NumLowBitsAvailable = 0;
0665 };
0666 
0667 } // namespace llvm.
0668 
0669 #endif // LLVM_CLANG_AST_TEMPLATENAME_H