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