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