Home | History | Annotate | Download | only in AST
      1 //===-- DeclarationName.h - Representation of declaration names -*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file declares the DeclarationName and DeclarationNameTable classes.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
     14 #define LLVM_CLANG_AST_DECLARATIONNAME_H
     15 
     16 #include "clang/Basic/IdentifierTable.h"
     17 #include "clang/Basic/PartialDiagnostic.h"
     18 #include "llvm/Support/Compiler.h"
     19 
     20 namespace llvm {
     21   template <typename T> struct DenseMapInfo;
     22 }
     23 
     24 namespace clang {
     25   class ASTContext;
     26   class CXXDeductionGuideNameExtra;
     27   class CXXLiteralOperatorIdName;
     28   class CXXOperatorIdName;
     29   class CXXSpecialName;
     30   class DeclarationNameExtra;
     31   class IdentifierInfo;
     32   class MultiKeywordSelector;
     33   enum OverloadedOperatorKind : int;
     34   struct PrintingPolicy;
     35   class QualType;
     36   class TemplateDecl;
     37   class Type;
     38   class TypeSourceInfo;
     39   class UsingDirectiveDecl;
     40 
     41   template <typename> class CanQual;
     42   typedef CanQual<Type> CanQualType;
     43 
     44 /// DeclarationName - The name of a declaration. In the common case,
     45 /// this just stores an IdentifierInfo pointer to a normal
     46 /// name. However, it also provides encodings for Objective-C
     47 /// selectors (optimizing zero- and one-argument selectors, which make
     48 /// up 78% percent of all selectors in Cocoa.h) and special C++ names
     49 /// for constructors, destructors, and conversion functions.
     50 class DeclarationName {
     51 public:
     52   /// NameKind - The kind of name this object contains.
     53   enum NameKind {
     54     Identifier,
     55     ObjCZeroArgSelector,
     56     ObjCOneArgSelector,
     57     ObjCMultiArgSelector,
     58     CXXConstructorName,
     59     CXXDestructorName,
     60     CXXConversionFunctionName,
     61     CXXDeductionGuideName,
     62     CXXOperatorName,
     63     CXXLiteralOperatorName,
     64     CXXUsingDirective
     65   };
     66   static const unsigned NumNameKinds = CXXUsingDirective + 1;
     67 
     68 private:
     69   /// StoredNameKind - The kind of name that is actually stored in the
     70   /// upper bits of the Ptr field. This is only used internally.
     71   ///
     72   /// Note: The entries here are synchronized with the entries in Selector,
     73   /// for efficient translation between the two.
     74   enum StoredNameKind {
     75     StoredIdentifier = 0,
     76     StoredObjCZeroArgSelector = 0x01,
     77     StoredObjCOneArgSelector = 0x02,
     78     StoredDeclarationNameExtra = 0x03,
     79     PtrMask = 0x03
     80   };
     81 
     82   /// Ptr - The lowest two bits are used to express what kind of name
     83   /// we're actually storing, using the values of NameKind. Depending
     84   /// on the kind of name this is, the upper bits of Ptr may have one
     85   /// of several different meanings:
     86   ///
     87   ///   StoredIdentifier - The name is a normal identifier, and Ptr is
     88   ///   a normal IdentifierInfo pointer.
     89   ///
     90   ///   StoredObjCZeroArgSelector - The name is an Objective-C
     91   ///   selector with zero arguments, and Ptr is an IdentifierInfo
     92   ///   pointer pointing to the selector name.
     93   ///
     94   ///   StoredObjCOneArgSelector - The name is an Objective-C selector
     95   ///   with one argument, and Ptr is an IdentifierInfo pointer
     96   ///   pointing to the selector name.
     97   ///
     98   ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
     99   ///   DeclarationNameExtra structure, whose first value will tell us
    100   ///   whether this is an Objective-C selector, C++ operator-id name,
    101   ///   or special C++ name.
    102   uintptr_t Ptr;
    103 
    104   /// getStoredNameKind - Return the kind of object that is stored in
    105   /// Ptr.
    106   StoredNameKind getStoredNameKind() const {
    107     return static_cast<StoredNameKind>(Ptr & PtrMask);
    108   }
    109 
    110   /// getExtra - Get the "extra" information associated with this
    111   /// multi-argument selector or C++ special name.
    112   DeclarationNameExtra *getExtra() const {
    113     assert(getStoredNameKind() == StoredDeclarationNameExtra &&
    114            "Declaration name does not store an Extra structure");
    115     return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask);
    116   }
    117 
    118   /// getAsCXXSpecialName - If the stored pointer is actually a
    119   /// CXXSpecialName, returns a pointer to it. Otherwise, returns
    120   /// a NULL pointer.
    121   CXXSpecialName *getAsCXXSpecialName() const {
    122     NameKind Kind = getNameKind();
    123     if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName)
    124       return reinterpret_cast<CXXSpecialName *>(getExtra());
    125     return nullptr;
    126   }
    127 
    128   /// If the stored pointer is actually a CXXDeductionGuideNameExtra, returns a
    129   /// pointer to it. Otherwise, returns a NULL pointer.
    130   CXXDeductionGuideNameExtra *getAsCXXDeductionGuideNameExtra() const {
    131     if (getNameKind() == CXXDeductionGuideName)
    132       return reinterpret_cast<CXXDeductionGuideNameExtra *>(getExtra());
    133     return nullptr;
    134   }
    135 
    136   /// getAsCXXOperatorIdName
    137   CXXOperatorIdName *getAsCXXOperatorIdName() const {
    138     if (getNameKind() == CXXOperatorName)
    139       return reinterpret_cast<CXXOperatorIdName *>(getExtra());
    140     return nullptr;
    141   }
    142 
    143   CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
    144     if (getNameKind() == CXXLiteralOperatorName)
    145       return reinterpret_cast<CXXLiteralOperatorIdName *>(getExtra());
    146     return nullptr;
    147   }
    148 
    149   // Construct a declaration name from the name of a C++ constructor,
    150   // destructor, or conversion function.
    151   DeclarationName(DeclarationNameExtra *Name)
    152     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
    153     assert((Ptr & PtrMask) == 0 && "Improperly aligned DeclarationNameExtra");
    154     Ptr |= StoredDeclarationNameExtra;
    155   }
    156 
    157   /// Construct a declaration name from a raw pointer.
    158   DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
    159 
    160   friend class DeclarationNameTable;
    161   friend class NamedDecl;
    162 
    163   /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer
    164   /// for this name as a void pointer if it's not an identifier.
    165   void *getFETokenInfoAsVoidSlow() const;
    166 
    167 public:
    168   /// DeclarationName - Used to create an empty selector.
    169   DeclarationName() : Ptr(0) { }
    170 
    171   // Construct a declaration name from an IdentifierInfo *.
    172   DeclarationName(const IdentifierInfo *II)
    173     : Ptr(reinterpret_cast<uintptr_t>(II)) {
    174     assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
    175   }
    176 
    177   // Construct a declaration name from an Objective-C selector.
    178   DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { }
    179 
    180   /// getUsingDirectiveName - Return name for all using-directives.
    181   static DeclarationName getUsingDirectiveName();
    182 
    183   // operator bool() - Evaluates true when this declaration name is
    184   // non-empty.
    185   explicit operator bool() const {
    186     return ((Ptr & PtrMask) != 0) ||
    187            (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
    188   }
    189 
    190   /// \brief Evaluates true when this declaration name is empty.
    191   bool isEmpty() const {
    192     return !*this;
    193   }
    194 
    195   /// Predicate functions for querying what type of name this is.
    196   bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
    197   bool isObjCZeroArgSelector() const {
    198     return getStoredNameKind() == StoredObjCZeroArgSelector;
    199   }
    200   bool isObjCOneArgSelector() const {
    201     return getStoredNameKind() == StoredObjCOneArgSelector;
    202   }
    203 
    204   /// getNameKind - Determine what kind of name this is.
    205   NameKind getNameKind() const;
    206 
    207   /// \brief Determines whether the name itself is dependent, e.g., because it
    208   /// involves a C++ type that is itself dependent.
    209   ///
    210   /// Note that this does not capture all of the notions of "dependent name",
    211   /// because an identifier can be a dependent name if it is used as the
    212   /// callee in a call expression with dependent arguments.
    213   bool isDependentName() const;
    214 
    215   /// getNameAsString - Retrieve the human-readable string for this name.
    216   std::string getAsString() const;
    217 
    218   /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
    219   /// this declaration name, or NULL if this declaration name isn't a
    220   /// simple identifier.
    221   IdentifierInfo *getAsIdentifierInfo() const {
    222     if (isIdentifier())
    223       return reinterpret_cast<IdentifierInfo *>(Ptr);
    224     return nullptr;
    225   }
    226 
    227   /// getAsOpaqueInteger - Get the representation of this declaration
    228   /// name as an opaque integer.
    229   uintptr_t getAsOpaqueInteger() const { return Ptr; }
    230 
    231   /// getAsOpaquePtr - Get the representation of this declaration name as
    232   /// an opaque pointer.
    233   void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); }
    234 
    235   static DeclarationName getFromOpaquePtr(void *P) {
    236     DeclarationName N;
    237     N.Ptr = reinterpret_cast<uintptr_t> (P);
    238     return N;
    239   }
    240 
    241   static DeclarationName getFromOpaqueInteger(uintptr_t P) {
    242     DeclarationName N;
    243     N.Ptr = P;
    244     return N;
    245   }
    246 
    247   /// getCXXNameType - If this name is one of the C++ names (of a
    248   /// constructor, destructor, or conversion function), return the
    249   /// type associated with that name.
    250   QualType getCXXNameType() const;
    251 
    252   /// If this name is the name of a C++ deduction guide, return the
    253   /// template associated with that name.
    254   TemplateDecl *getCXXDeductionGuideTemplate() const;
    255 
    256   /// getCXXOverloadedOperator - If this name is the name of an
    257   /// overloadable operator in C++ (e.g., @c operator+), retrieve the
    258   /// kind of overloaded operator.
    259   OverloadedOperatorKind getCXXOverloadedOperator() const;
    260 
    261   /// getCXXLiteralIdentifier - If this name is the name of a literal
    262   /// operator, retrieve the identifier associated with it.
    263   IdentifierInfo *getCXXLiteralIdentifier() const;
    264 
    265   /// getObjCSelector - Get the Objective-C selector stored in this
    266   /// declaration name.
    267   Selector getObjCSelector() const {
    268     assert((getNameKind() == ObjCZeroArgSelector ||
    269             getNameKind() == ObjCOneArgSelector ||
    270             getNameKind() == ObjCMultiArgSelector ||
    271             Ptr == 0) && "Not a selector!");
    272     return Selector(Ptr);
    273   }
    274 
    275   /// getFETokenInfo/setFETokenInfo - The language front-end is
    276   /// allowed to associate arbitrary metadata with some kinds of
    277   /// declaration names, including normal identifiers and C++
    278   /// constructors, destructors, and conversion functions.
    279   template<typename T>
    280   T *getFETokenInfo() const {
    281     if (const IdentifierInfo *Info = getAsIdentifierInfo())
    282       return Info->getFETokenInfo<T>();
    283     return static_cast<T*>(getFETokenInfoAsVoidSlow());
    284   }
    285 
    286   void setFETokenInfo(void *T);
    287 
    288   /// operator== - Determine whether the specified names are identical..
    289   friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
    290     return LHS.Ptr == RHS.Ptr;
    291   }
    292 
    293   /// operator!= - Determine whether the specified names are different.
    294   friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
    295     return LHS.Ptr != RHS.Ptr;
    296   }
    297 
    298   static DeclarationName getEmptyMarker() {
    299     return DeclarationName(uintptr_t(-1));
    300   }
    301 
    302   static DeclarationName getTombstoneMarker() {
    303     return DeclarationName(uintptr_t(-2));
    304   }
    305 
    306   static int compare(DeclarationName LHS, DeclarationName RHS);
    307 
    308   void print(raw_ostream &OS, const PrintingPolicy &Policy);
    309 
    310   void dump() const;
    311 };
    312 
    313 raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
    314 
    315 /// Ordering on two declaration names. If both names are identifiers,
    316 /// this provides a lexicographical ordering.
    317 inline bool operator<(DeclarationName LHS, DeclarationName RHS) {
    318   return DeclarationName::compare(LHS, RHS) < 0;
    319 }
    320 
    321 /// Ordering on two declaration names. If both names are identifiers,
    322 /// this provides a lexicographical ordering.
    323 inline bool operator>(DeclarationName LHS, DeclarationName RHS) {
    324   return DeclarationName::compare(LHS, RHS) > 0;
    325 }
    326 
    327 /// Ordering on two declaration names. If both names are identifiers,
    328 /// this provides a lexicographical ordering.
    329 inline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
    330   return DeclarationName::compare(LHS, RHS) <= 0;
    331 }
    332 
    333 /// Ordering on two declaration names. If both names are identifiers,
    334 /// this provides a lexicographical ordering.
    335 inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
    336   return DeclarationName::compare(LHS, RHS) >= 0;
    337 }
    338 
    339 /// DeclarationNameTable - Used to store and retrieve DeclarationName
    340 /// instances for the various kinds of declaration names, e.g., normal
    341 /// identifiers, C++ constructor names, etc. This class contains
    342 /// uniqued versions of each of the C++ special names, which can be
    343 /// retrieved using its member functions (e.g.,
    344 /// getCXXConstructorName).
    345 class DeclarationNameTable {
    346   const ASTContext &Ctx;
    347   void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
    348   CXXOperatorIdName *CXXOperatorNames; // Operator names
    349   void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
    350   void *CXXDeductionGuideNames; // FoldingSet<CXXDeductionGuideNameExtra> *
    351 
    352   DeclarationNameTable(const DeclarationNameTable&) = delete;
    353   void operator=(const DeclarationNameTable&) = delete;
    354 
    355 public:
    356   DeclarationNameTable(const ASTContext &C);
    357   ~DeclarationNameTable();
    358 
    359   /// getIdentifier - Create a declaration name that is a simple
    360   /// identifier.
    361   DeclarationName getIdentifier(const IdentifierInfo *ID) {
    362     return DeclarationName(ID);
    363   }
    364 
    365   /// getCXXConstructorName - Returns the name of a C++ constructor
    366   /// for the given Type.
    367   DeclarationName getCXXConstructorName(CanQualType Ty);
    368 
    369   /// getCXXDestructorName - Returns the name of a C++ destructor
    370   /// for the given Type.
    371   DeclarationName getCXXDestructorName(CanQualType Ty);
    372 
    373   /// Returns the name of a C++ deduction guide for the given template.
    374   DeclarationName getCXXDeductionGuideName(TemplateDecl *TD);
    375 
    376   /// getCXXConversionFunctionName - Returns the name of a C++
    377   /// conversion function for the given Type.
    378   DeclarationName getCXXConversionFunctionName(CanQualType Ty);
    379 
    380   /// getCXXSpecialName - Returns a declaration name for special kind
    381   /// of C++ name, e.g., for a constructor, destructor, or conversion
    382   /// function.
    383   DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
    384                                     CanQualType Ty);
    385 
    386   /// getCXXOperatorName - Get the name of the overloadable C++
    387   /// operator corresponding to Op.
    388   DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
    389 
    390   /// getCXXLiteralOperatorName - Get the name of the literal operator function
    391   /// with II as the identifier.
    392   DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
    393 };
    394 
    395 /// DeclarationNameLoc - Additional source/type location info
    396 /// for a declaration name. Needs a DeclarationName in order
    397 /// to be interpreted correctly.
    398 struct DeclarationNameLoc {
    399   // The source location for identifier stored elsewhere.
    400   // struct {} Identifier;
    401 
    402   // Type info for constructors, destructors and conversion functions.
    403   // Locations (if any) for the tilde (destructor) or operator keyword
    404   // (conversion) are stored elsewhere.
    405   struct NT {
    406     TypeSourceInfo *TInfo;
    407   };
    408 
    409   // The location (if any) of the operator keyword is stored elsewhere.
    410   struct CXXOpName {
    411     unsigned BeginOpNameLoc;
    412     unsigned EndOpNameLoc;
    413   };
    414 
    415   // The location (if any) of the operator keyword is stored elsewhere.
    416   struct CXXLitOpName {
    417     unsigned OpNameLoc;
    418   };
    419 
    420   // struct {} CXXUsingDirective;
    421   // struct {} ObjCZeroArgSelector;
    422   // struct {} ObjCOneArgSelector;
    423   // struct {} ObjCMultiArgSelector;
    424   union {
    425     struct NT NamedType;
    426     struct CXXOpName CXXOperatorName;
    427     struct CXXLitOpName CXXLiteralOperatorName;
    428   };
    429 
    430   DeclarationNameLoc(DeclarationName Name);
    431   // FIXME: this should go away once all DNLocs are properly initialized.
    432   DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
    433 }; // struct DeclarationNameLoc
    434 
    435 
    436 /// DeclarationNameInfo - A collector data type for bundling together
    437 /// a DeclarationName and the correspnding source/type location info.
    438 struct DeclarationNameInfo {
    439 private:
    440   /// Name - The declaration name, also encoding name kind.
    441   DeclarationName Name;
    442   /// Loc - The main source location for the declaration name.
    443   SourceLocation NameLoc;
    444   /// Info - Further source/type location info for special kinds of names.
    445   DeclarationNameLoc LocInfo;
    446 
    447 public:
    448   // FIXME: remove it.
    449   DeclarationNameInfo() {}
    450 
    451   DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
    452     : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
    453 
    454   DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
    455                       DeclarationNameLoc LocInfo)
    456     : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
    457 
    458   /// getName - Returns the embedded declaration name.
    459   DeclarationName getName() const { return Name; }
    460   /// setName - Sets the embedded declaration name.
    461   void setName(DeclarationName N) { Name = N; }
    462 
    463   /// getLoc - Returns the main location of the declaration name.
    464   SourceLocation getLoc() const { return NameLoc; }
    465   /// setLoc - Sets the main location of the declaration name.
    466   void setLoc(SourceLocation L) { NameLoc = L; }
    467 
    468   const DeclarationNameLoc &getInfo() const { return LocInfo; }
    469   DeclarationNameLoc &getInfo() { return LocInfo; }
    470   void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
    471 
    472   /// getNamedTypeInfo - Returns the source type info associated to
    473   /// the name. Assumes it is a constructor, destructor or conversion.
    474   TypeSourceInfo *getNamedTypeInfo() const {
    475     assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
    476            Name.getNameKind() == DeclarationName::CXXDestructorName ||
    477            Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
    478     return LocInfo.NamedType.TInfo;
    479   }
    480   /// setNamedTypeInfo - Sets the source type info associated to
    481   /// the name. Assumes it is a constructor, destructor or conversion.
    482   void setNamedTypeInfo(TypeSourceInfo *TInfo) {
    483     assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
    484            Name.getNameKind() == DeclarationName::CXXDestructorName ||
    485            Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
    486     LocInfo.NamedType.TInfo = TInfo;
    487   }
    488 
    489   /// getCXXOperatorNameRange - Gets the range of the operator name
    490   /// (without the operator keyword). Assumes it is a (non-literal) operator.
    491   SourceRange getCXXOperatorNameRange() const {
    492     assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
    493     return SourceRange(
    494      SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
    495      SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
    496                        );
    497   }
    498   /// setCXXOperatorNameRange - Sets the range of the operator name
    499   /// (without the operator keyword). Assumes it is a C++ operator.
    500   void setCXXOperatorNameRange(SourceRange R) {
    501     assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
    502     LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
    503     LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
    504   }
    505 
    506   /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
    507   /// operator name (not the operator keyword).
    508   /// Assumes it is a literal operator.
    509   SourceLocation getCXXLiteralOperatorNameLoc() const {
    510     assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
    511     return SourceLocation::
    512       getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
    513   }
    514   /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
    515   /// operator name (not the operator keyword).
    516   /// Assumes it is a literal operator.
    517   void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
    518     assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
    519     LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
    520   }
    521 
    522   /// \brief Determine whether this name involves a template parameter.
    523   bool isInstantiationDependent() const;
    524 
    525   /// \brief Determine whether this name contains an unexpanded
    526   /// parameter pack.
    527   bool containsUnexpandedParameterPack() const;
    528 
    529   /// getAsString - Retrieve the human-readable string for this name.
    530   std::string getAsString() const;
    531 
    532   /// printName - Print the human-readable name to a stream.
    533   void printName(raw_ostream &OS) const;
    534 
    535   /// getBeginLoc - Retrieve the location of the first token.
    536   SourceLocation getBeginLoc() const { return NameLoc; }
    537   /// getEndLoc - Retrieve the location of the last token.
    538   SourceLocation getEndLoc() const;
    539   /// getSourceRange - The range of the declaration name.
    540   SourceRange getSourceRange() const LLVM_READONLY {
    541     return SourceRange(getLocStart(), getLocEnd());
    542   }
    543   SourceLocation getLocStart() const LLVM_READONLY {
    544     return getBeginLoc();
    545   }
    546   SourceLocation getLocEnd() const LLVM_READONLY {
    547     SourceLocation EndLoc = getEndLoc();
    548     return EndLoc.isValid() ? EndLoc : getLocStart();
    549   }
    550 };
    551 
    552 /// Insertion operator for diagnostics.  This allows sending DeclarationName's
    553 /// into a diagnostic with <<.
    554 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
    555                                            DeclarationName N) {
    556   DB.AddTaggedVal(N.getAsOpaqueInteger(),
    557                   DiagnosticsEngine::ak_declarationname);
    558   return DB;
    559 }
    560 
    561 /// Insertion operator for partial diagnostics.  This allows binding
    562 /// DeclarationName's into a partial diagnostic with <<.
    563 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
    564                                            DeclarationName N) {
    565   PD.AddTaggedVal(N.getAsOpaqueInteger(),
    566                   DiagnosticsEngine::ak_declarationname);
    567   return PD;
    568 }
    569 
    570 inline raw_ostream &operator<<(raw_ostream &OS,
    571                                      DeclarationNameInfo DNInfo) {
    572   DNInfo.printName(OS);
    573   return OS;
    574 }
    575 
    576 }  // end namespace clang
    577 
    578 namespace llvm {
    579 /// Define DenseMapInfo so that DeclarationNames can be used as keys
    580 /// in DenseMap and DenseSets.
    581 template<>
    582 struct DenseMapInfo<clang::DeclarationName> {
    583   static inline clang::DeclarationName getEmptyKey() {
    584     return clang::DeclarationName::getEmptyMarker();
    585   }
    586 
    587   static inline clang::DeclarationName getTombstoneKey() {
    588     return clang::DeclarationName::getTombstoneMarker();
    589   }
    590 
    591   static unsigned getHashValue(clang::DeclarationName Name) {
    592     return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
    593   }
    594 
    595   static inline bool
    596   isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
    597     return LHS == RHS;
    598   }
    599 };
    600 
    601 template <>
    602 struct isPodLike<clang::DeclarationName> { static const bool value = true; };
    603 
    604 }  // end namespace llvm
    605 
    606 #endif
    607