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