clang API Documentation

DeclarationName.h
Go to the documentation of this file.
00001 //===-- DeclarationName.h - Representation of declaration names -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the DeclarationName and DeclarationNameTable classes.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
00014 #define LLVM_CLANG_AST_DECLARATIONNAME_H
00015 
00016 #include "clang/Basic/IdentifierTable.h"
00017 #include "clang/AST/Type.h"
00018 #include "clang/AST/CanonicalType.h"
00019 #include "clang/Basic/PartialDiagnostic.h"
00020 #include "llvm/Support/Compiler.h"
00021 
00022 namespace llvm {
00023   template <typename T> struct DenseMapInfo;
00024 }
00025 
00026 namespace clang {
00027   class CXXSpecialName;
00028   class CXXOperatorIdName;
00029   class CXXLiteralOperatorIdName;
00030   class DeclarationNameExtra;
00031   class IdentifierInfo;
00032   class MultiKeywordSelector;
00033   class UsingDirectiveDecl;
00034   class TypeSourceInfo;
00035 
00036 /// DeclarationName - The name of a declaration. In the common case,
00037 /// this just stores an IdentifierInfo pointer to a normal
00038 /// name. However, it also provides encodings for Objective-C
00039 /// selectors (optimizing zero- and one-argument selectors, which make
00040 /// up 78% percent of all selectors in Cocoa.h) and special C++ names
00041 /// for constructors, destructors, and conversion functions.
00042 class DeclarationName {
00043 public:
00044   /// NameKind - The kind of name this object contains.
00045   enum NameKind {
00046     Identifier,
00047     ObjCZeroArgSelector,
00048     ObjCOneArgSelector,
00049     ObjCMultiArgSelector,
00050     CXXConstructorName,
00051     CXXDestructorName,
00052     CXXConversionFunctionName,
00053     CXXOperatorName,
00054     CXXLiteralOperatorName,
00055     CXXUsingDirective
00056   };
00057 
00058 private:
00059   /// StoredNameKind - The kind of name that is actually stored in the
00060   /// upper bits of the Ptr field. This is only used internally.
00061   ///
00062   /// Note: The entries here are synchronized with the entries in Selector,
00063   /// for efficient translation between the two.
00064   enum StoredNameKind {
00065     StoredIdentifier = 0,
00066     StoredObjCZeroArgSelector = 0x01,
00067     StoredObjCOneArgSelector = 0x02,
00068     StoredDeclarationNameExtra = 0x03,
00069     PtrMask = 0x03
00070   };
00071 
00072   /// Ptr - The lowest two bits are used to express what kind of name
00073   /// we're actually storing, using the values of NameKind. Depending
00074   /// on the kind of name this is, the upper bits of Ptr may have one
00075   /// of several different meanings:
00076   ///
00077   ///   StoredIdentifier - The name is a normal identifier, and Ptr is
00078   ///   a normal IdentifierInfo pointer.
00079   ///
00080   ///   StoredObjCZeroArgSelector - The name is an Objective-C
00081   ///   selector with zero arguments, and Ptr is an IdentifierInfo
00082   ///   pointer pointing to the selector name.
00083   ///
00084   ///   StoredObjCOneArgSelector - The name is an Objective-C selector
00085   ///   with one argument, and Ptr is an IdentifierInfo pointer
00086   ///   pointing to the selector name.
00087   ///
00088   ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
00089   ///   DeclarationNameExtra structure, whose first value will tell us
00090   ///   whether this is an Objective-C selector, C++ operator-id name,
00091   ///   or special C++ name.
00092   uintptr_t Ptr;
00093 
00094   /// getStoredNameKind - Return the kind of object that is stored in
00095   /// Ptr.
00096   StoredNameKind getStoredNameKind() const {
00097     return static_cast<StoredNameKind>(Ptr & PtrMask);
00098   }
00099 
00100   /// getExtra - Get the "extra" information associated with this
00101   /// multi-argument selector or C++ special name.
00102   DeclarationNameExtra *getExtra() const {
00103     assert(getStoredNameKind() == StoredDeclarationNameExtra &&
00104            "Declaration name does not store an Extra structure");
00105     return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask);
00106   }
00107 
00108   /// getAsCXXSpecialName - If the stored pointer is actually a
00109   /// CXXSpecialName, returns a pointer to it. Otherwise, returns
00110   /// a NULL pointer.
00111   CXXSpecialName *getAsCXXSpecialName() const {
00112     NameKind Kind = getNameKind();
00113     if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName)
00114       return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask);
00115     return 0;
00116   }
00117 
00118   /// getAsCXXOperatorIdName
00119   CXXOperatorIdName *getAsCXXOperatorIdName() const {
00120     if (getNameKind() == CXXOperatorName)
00121       return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask);
00122     return 0;
00123   }
00124 
00125   CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
00126     if (getNameKind() == CXXLiteralOperatorName)
00127       return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask);
00128     return 0;
00129   }
00130 
00131   // Construct a declaration name from the name of a C++ constructor,
00132   // destructor, or conversion function.
00133   DeclarationName(CXXSpecialName *Name)
00134     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
00135     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName");
00136     Ptr |= StoredDeclarationNameExtra;
00137   }
00138 
00139   // Construct a declaration name from the name of a C++ overloaded
00140   // operator.
00141   DeclarationName(CXXOperatorIdName *Name)
00142     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
00143     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId");
00144     Ptr |= StoredDeclarationNameExtra;
00145   }
00146 
00147   DeclarationName(CXXLiteralOperatorIdName *Name)
00148     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
00149     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId");
00150     Ptr |= StoredDeclarationNameExtra;
00151   }
00152 
00153   /// Construct a declaration name from a raw pointer.
00154   DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
00155 
00156   friend class DeclarationNameTable;
00157   friend class NamedDecl;
00158 
00159   /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer
00160   /// for this name as a void pointer if it's not an identifier.
00161   void *getFETokenInfoAsVoidSlow() const;
00162 
00163 public:
00164   /// DeclarationName - Used to create an empty selector.
00165   DeclarationName() : Ptr(0) { }
00166 
00167   // Construct a declaration name from an IdentifierInfo *.
00168   DeclarationName(const IdentifierInfo *II)
00169     : Ptr(reinterpret_cast<uintptr_t>(II)) {
00170     assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
00171   }
00172 
00173   // Construct a declaration name from an Objective-C selector.
00174   DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { }
00175 
00176   /// getUsingDirectiveName - Return name for all using-directives.
00177   static DeclarationName getUsingDirectiveName();
00178 
00179   // operator bool() - Evaluates true when this declaration name is
00180   // non-empty.
00181   operator bool() const {
00182     return ((Ptr & PtrMask) != 0) ||
00183            (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
00184   }
00185 
00186   /// Predicate functions for querying what type of name this is.
00187   bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
00188   bool isObjCZeroArgSelector() const {
00189     return getStoredNameKind() == StoredObjCZeroArgSelector;
00190   }
00191   bool isObjCOneArgSelector() const {
00192     return getStoredNameKind() == StoredObjCOneArgSelector;
00193   }
00194 
00195   /// getNameKind - Determine what kind of name this is.
00196   NameKind getNameKind() const;
00197 
00198   /// \brief Determines whether the name itself is dependent, e.g., because it 
00199   /// involves a C++ type that is itself dependent.
00200   ///
00201   /// Note that this does not capture all of the notions of "dependent name",
00202   /// because an identifier can be a dependent name if it is used as the 
00203   /// callee in a call expression with dependent arguments.
00204   bool isDependentName() const;
00205   
00206   /// getNameAsString - Retrieve the human-readable string for this name.
00207   std::string getAsString() const;
00208 
00209   /// printName - Print the human-readable name to a stream.
00210   void printName(raw_ostream &OS) const;
00211 
00212   /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
00213   /// this declaration name, or NULL if this declaration name isn't a
00214   /// simple identifier.
00215   IdentifierInfo *getAsIdentifierInfo() const {
00216     if (isIdentifier())
00217       return reinterpret_cast<IdentifierInfo *>(Ptr);
00218     return 0;
00219   }
00220 
00221   /// getAsOpaqueInteger - Get the representation of this declaration
00222   /// name as an opaque integer.
00223   uintptr_t getAsOpaqueInteger() const { return Ptr; }
00224 
00225   /// getAsOpaquePtr - Get the representation of this declaration name as
00226   /// an opaque pointer.
00227   void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); }
00228 
00229   static DeclarationName getFromOpaquePtr(void *P) {
00230     DeclarationName N;
00231     N.Ptr = reinterpret_cast<uintptr_t> (P);
00232     return N;
00233   }
00234 
00235   static DeclarationName getFromOpaqueInteger(uintptr_t P) {
00236     DeclarationName N;
00237     N.Ptr = P;
00238     return N;
00239   }
00240 
00241   /// getCXXNameType - If this name is one of the C++ names (of a
00242   /// constructor, destructor, or conversion function), return the
00243   /// type associated with that name.
00244   QualType getCXXNameType() const;
00245 
00246   /// getCXXOverloadedOperator - If this name is the name of an
00247   /// overloadable operator in C++ (e.g., @c operator+), retrieve the
00248   /// kind of overloaded operator.
00249   OverloadedOperatorKind getCXXOverloadedOperator() const;
00250 
00251   /// getCXXLiteralIdentifier - If this name is the name of a literal
00252   /// operator, retrieve the identifier associated with it.
00253   IdentifierInfo *getCXXLiteralIdentifier() const;
00254 
00255   /// getObjCSelector - Get the Objective-C selector stored in this
00256   /// declaration name.
00257   Selector getObjCSelector() const {
00258     assert((getNameKind() == ObjCZeroArgSelector ||
00259             getNameKind() == ObjCOneArgSelector ||
00260             getNameKind() == ObjCMultiArgSelector ||
00261             Ptr == 0) && "Not a selector!");
00262     return Selector(Ptr);
00263   }
00264 
00265   /// getFETokenInfo/setFETokenInfo - The language front-end is
00266   /// allowed to associate arbitrary metadata with some kinds of
00267   /// declaration names, including normal identifiers and C++
00268   /// constructors, destructors, and conversion functions.
00269   template<typename T>
00270   T *getFETokenInfo() const {
00271     if (const IdentifierInfo *Info = getAsIdentifierInfo())
00272       return Info->getFETokenInfo<T>();
00273     return static_cast<T*>(getFETokenInfoAsVoidSlow());
00274   }
00275 
00276   void setFETokenInfo(void *T);
00277 
00278   /// operator== - Determine whether the specified names are identical..
00279   friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
00280     return LHS.Ptr == RHS.Ptr;
00281   }
00282 
00283   /// operator!= - Determine whether the specified names are different.
00284   friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
00285     return LHS.Ptr != RHS.Ptr;
00286   }
00287 
00288   static DeclarationName getEmptyMarker() {
00289     return DeclarationName(uintptr_t(-1));
00290   }
00291 
00292   static DeclarationName getTombstoneMarker() {
00293     return DeclarationName(uintptr_t(-2));
00294   }
00295 
00296   static int compare(DeclarationName LHS, DeclarationName RHS);
00297   
00298   void dump() const;
00299 };
00300 
00301 /// Ordering on two declaration names. If both names are identifiers,
00302 /// this provides a lexicographical ordering.
00303 inline bool operator<(DeclarationName LHS, DeclarationName RHS) {
00304   return DeclarationName::compare(LHS, RHS) < 0;
00305 }
00306 
00307 /// Ordering on two declaration names. If both names are identifiers,
00308 /// this provides a lexicographical ordering.
00309 inline bool operator>(DeclarationName LHS, DeclarationName RHS) {
00310   return DeclarationName::compare(LHS, RHS) > 0;
00311 }
00312 
00313 /// Ordering on two declaration names. If both names are identifiers,
00314 /// this provides a lexicographical ordering.
00315 inline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
00316   return DeclarationName::compare(LHS, RHS) <= 0;
00317 }
00318 
00319 /// Ordering on two declaration names. If both names are identifiers,
00320 /// this provides a lexicographical ordering.
00321 inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
00322   return DeclarationName::compare(LHS, RHS) >= 0;
00323 }
00324 
00325 /// DeclarationNameTable - Used to store and retrieve DeclarationName
00326 /// instances for the various kinds of declaration names, e.g., normal
00327 /// identifiers, C++ constructor names, etc. This class contains
00328 /// uniqued versions of each of the C++ special names, which can be
00329 /// retrieved using its member functions (e.g.,
00330 /// getCXXConstructorName).
00331 class DeclarationNameTable {
00332   const ASTContext &Ctx;
00333   void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
00334   CXXOperatorIdName *CXXOperatorNames; // Operator names
00335   void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
00336 
00337   DeclarationNameTable(const DeclarationNameTable&);            // NONCOPYABLE
00338   DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE
00339 
00340 public:
00341   DeclarationNameTable(const ASTContext &C);
00342   ~DeclarationNameTable();
00343 
00344   /// getIdentifier - Create a declaration name that is a simple
00345   /// identifier.
00346   DeclarationName getIdentifier(const IdentifierInfo *ID) {
00347     return DeclarationName(ID);
00348   }
00349 
00350   /// getCXXConstructorName - Returns the name of a C++ constructor
00351   /// for the given Type.
00352   DeclarationName getCXXConstructorName(CanQualType Ty) {
00353     return getCXXSpecialName(DeclarationName::CXXConstructorName, 
00354                              Ty.getUnqualifiedType());
00355   }
00356 
00357   /// getCXXDestructorName - Returns the name of a C++ destructor
00358   /// for the given Type.
00359   DeclarationName getCXXDestructorName(CanQualType Ty) {
00360     return getCXXSpecialName(DeclarationName::CXXDestructorName, 
00361                              Ty.getUnqualifiedType());
00362   }
00363 
00364   /// getCXXConversionFunctionName - Returns the name of a C++
00365   /// conversion function for the given Type.
00366   DeclarationName getCXXConversionFunctionName(CanQualType Ty) {
00367     return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty);
00368   }
00369 
00370   /// getCXXSpecialName - Returns a declaration name for special kind
00371   /// of C++ name, e.g., for a constructor, destructor, or conversion
00372   /// function.
00373   DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
00374                                     CanQualType Ty);
00375 
00376   /// getCXXOperatorName - Get the name of the overloadable C++
00377   /// operator corresponding to Op.
00378   DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
00379 
00380   /// getCXXLiteralOperatorName - Get the name of the literal operator function
00381   /// with II as the identifier.
00382   DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
00383 };
00384 
00385 /// DeclarationNameLoc - Additional source/type location info
00386 /// for a declaration name. Needs a DeclarationName in order
00387 /// to be interpreted correctly.
00388 struct DeclarationNameLoc {
00389   union {
00390     // The source location for identifier stored elsewhere.
00391     // struct {} Identifier;
00392 
00393     // Type info for constructors, destructors and conversion functions.
00394     // Locations (if any) for the tilde (destructor) or operator keyword
00395     // (conversion) are stored elsewhere.
00396     struct {
00397       TypeSourceInfo* TInfo;
00398     } NamedType;
00399 
00400     // The location (if any) of the operator keyword is stored elsewhere.
00401     struct {
00402       unsigned BeginOpNameLoc;
00403       unsigned EndOpNameLoc;
00404     } CXXOperatorName;
00405 
00406     // The location (if any) of the operator keyword is stored elsewhere.
00407     struct {
00408       unsigned OpNameLoc;
00409     } CXXLiteralOperatorName;
00410 
00411     // struct {} CXXUsingDirective;
00412     // struct {} ObjCZeroArgSelector;
00413     // struct {} ObjCOneArgSelector;
00414     // struct {} ObjCMultiArgSelector;
00415   };
00416 
00417   DeclarationNameLoc(DeclarationName Name);
00418   // FIXME: this should go away once all DNLocs are properly initialized.
00419   DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
00420 }; // struct DeclarationNameLoc
00421 
00422 
00423 /// DeclarationNameInfo - A collector data type for bundling together
00424 /// a DeclarationName and the correspnding source/type location info.
00425 struct DeclarationNameInfo {
00426 private:
00427   /// Name - The declaration name, also encoding name kind.
00428   DeclarationName Name;
00429   /// Loc - The main source location for the declaration name.
00430   SourceLocation NameLoc;
00431   /// Info - Further source/type location info for special kinds of names.
00432   DeclarationNameLoc LocInfo;
00433 
00434 public:
00435   // FIXME: remove it.
00436   DeclarationNameInfo() {}
00437 
00438   DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
00439     : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
00440 
00441   DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
00442                       DeclarationNameLoc LocInfo)
00443     : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
00444 
00445   /// getName - Returns the embedded declaration name.
00446   DeclarationName getName() const { return Name; }
00447   /// setName - Sets the embedded declaration name.
00448   void setName(DeclarationName N) { Name = N; }
00449 
00450   /// getLoc - Returns the main location of the declaration name.
00451   SourceLocation getLoc() const { return NameLoc; }
00452   /// setLoc - Sets the main location of the declaration name.
00453   void setLoc(SourceLocation L) { NameLoc = L; }
00454 
00455   const DeclarationNameLoc &getInfo() const { return LocInfo; }
00456   DeclarationNameLoc &getInfo() { return LocInfo; }
00457   void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
00458 
00459   /// getNamedTypeInfo - Returns the source type info associated to
00460   /// the name. Assumes it is a constructor, destructor or conversion.
00461   TypeSourceInfo *getNamedTypeInfo() const {
00462     assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
00463            Name.getNameKind() == DeclarationName::CXXDestructorName ||
00464            Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
00465     return LocInfo.NamedType.TInfo;
00466   }
00467   /// setNamedTypeInfo - Sets the source type info associated to
00468   /// the name. Assumes it is a constructor, destructor or conversion.
00469   void setNamedTypeInfo(TypeSourceInfo *TInfo) {
00470     assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
00471            Name.getNameKind() == DeclarationName::CXXDestructorName ||
00472            Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
00473     LocInfo.NamedType.TInfo = TInfo;
00474   }
00475 
00476   /// getCXXOperatorNameRange - Gets the range of the operator name
00477   /// (without the operator keyword). Assumes it is a (non-literal) operator.
00478   SourceRange getCXXOperatorNameRange() const {
00479     assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
00480     return SourceRange(
00481      SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
00482      SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
00483                        );
00484   }
00485   /// setCXXOperatorNameRange - Sets the range of the operator name
00486   /// (without the operator keyword). Assumes it is a C++ operator.
00487   void setCXXOperatorNameRange(SourceRange R) {
00488     assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
00489     LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
00490     LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
00491   }
00492 
00493   /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
00494   /// operator name (not the operator keyword).
00495   /// Assumes it is a literal operator.
00496   SourceLocation getCXXLiteralOperatorNameLoc() const {
00497     assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
00498     return SourceLocation::
00499       getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
00500   }
00501   /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
00502   /// operator name (not the operator keyword).
00503   /// Assumes it is a literal operator.
00504   void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
00505     assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
00506     LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
00507   }
00508 
00509   /// \brief Determine whether this name involves a template parameter.
00510   bool isInstantiationDependent() const;
00511   
00512   /// \brief Determine whether this name contains an unexpanded
00513   /// parameter pack.
00514   bool containsUnexpandedParameterPack() const;
00515 
00516   /// getAsString - Retrieve the human-readable string for this name.
00517   std::string getAsString() const;
00518 
00519   /// printName - Print the human-readable name to a stream.
00520   void printName(raw_ostream &OS) const;
00521 
00522   /// getBeginLoc - Retrieve the location of the first token.
00523   SourceLocation getBeginLoc() const { return NameLoc; }
00524   /// getEndLoc - Retrieve the location of the last token.
00525   SourceLocation getEndLoc() const;
00526   /// getSourceRange - The range of the declaration name.
00527   SourceRange getSourceRange() const LLVM_READONLY {
00528     SourceLocation BeginLoc = getBeginLoc();
00529     SourceLocation EndLoc = getEndLoc();
00530     return SourceRange(BeginLoc, EndLoc.isValid() ? EndLoc : BeginLoc);
00531   }
00532   SourceLocation getLocStart() const LLVM_READONLY {
00533     return getBeginLoc();
00534   }
00535   SourceLocation getLocEnd() const LLVM_READONLY {
00536     SourceLocation EndLoc = getEndLoc();
00537     return EndLoc.isValid() ? EndLoc : getLocStart();
00538   }
00539 };
00540 
00541 /// Insertion operator for diagnostics.  This allows sending DeclarationName's
00542 /// into a diagnostic with <<.
00543 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
00544                                            DeclarationName N) {
00545   DB.AddTaggedVal(N.getAsOpaqueInteger(),
00546                   DiagnosticsEngine::ak_declarationname);
00547   return DB;
00548 }
00549 
00550 /// Insertion operator for partial diagnostics.  This allows binding
00551 /// DeclarationName's into a partial diagnostic with <<.
00552 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
00553                                            DeclarationName N) {
00554   PD.AddTaggedVal(N.getAsOpaqueInteger(),
00555                   DiagnosticsEngine::ak_declarationname);
00556   return PD;
00557 }
00558 
00559 inline raw_ostream &operator<<(raw_ostream &OS,
00560                                      DeclarationNameInfo DNInfo) {
00561   DNInfo.printName(OS);
00562   return OS;
00563 }
00564 
00565 }  // end namespace clang
00566 
00567 namespace llvm {
00568 /// Define DenseMapInfo so that DeclarationNames can be used as keys
00569 /// in DenseMap and DenseSets.
00570 template<>
00571 struct DenseMapInfo<clang::DeclarationName> {
00572   static inline clang::DeclarationName getEmptyKey() {
00573     return clang::DeclarationName::getEmptyMarker();
00574   }
00575 
00576   static inline clang::DeclarationName getTombstoneKey() {
00577     return clang::DeclarationName::getTombstoneMarker();
00578   }
00579 
00580   static unsigned getHashValue(clang::DeclarationName Name) {
00581     return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
00582   }
00583 
00584   static inline bool
00585   isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
00586     return LHS == RHS;
00587   }
00588 };
00589 
00590 template <>
00591 struct isPodLike<clang::DeclarationName> { static const bool value = true; };
00592 
00593 }  // end namespace llvm
00594 
00595 #endif