IdentifierTable.h revision 85f3d76c0ecfdefcf83ea44a57b7a16119c8a045
1//===--- IdentifierTable.h - Hash table for identifier lookup ---*- 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 defines the IdentifierInfo, IdentifierTable, and Selector 11// interfaces. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 16#define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 17 18#include "clang/Basic/OperatorKinds.h" 19#include "clang/Basic/TokenKinds.h" 20#include "llvm/ADT/StringMap.h" 21#include "llvm/ADT/StringRef.h" 22#include "llvm/ADT/SmallString.h" 23#include "llvm/ADT/OwningPtr.h" 24#include "llvm/Support/PointerLikeTypeTraits.h" 25#include <cassert> 26#include <cctype> 27#include <string> 28 29namespace llvm { 30 template <typename T> struct DenseMapInfo; 31} 32 33namespace clang { 34 class LangOptions; 35 class IdentifierInfo; 36 class IdentifierTable; 37 class SourceLocation; 38 class MultiKeywordSelector; // private class used by Selector 39 class DeclarationName; // AST class that stores declaration names 40 41 /// IdentifierLocPair - A simple pair of identifier info and location. 42 typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair; 43 44 45/// IdentifierInfo - One of these records is kept for each identifier that 46/// is lexed. This contains information about whether the token was #define'd, 47/// is a language keyword, or if it is a front-end token of some sort (e.g. a 48/// variable or function name). The preprocessor keeps this information in a 49/// set, and all tok::identifier tokens have a pointer to one of these. 50class IdentifierInfo { 51 // Note: DON'T make TokenID a 'tok::TokenKind'; MSVC will treat it as a 52 // signed char and TokenKinds > 127 won't be handled correctly. 53 unsigned TokenID : 8; // Front-end token ID or tok::identifier. 54 // Objective-C keyword ('protocol' in '@protocol') or builtin (__builtin_inf). 55 // First NUM_OBJC_KEYWORDS values are for Objective-C, the remaining values 56 // are for builtins. 57 unsigned ObjCOrBuiltinID :11; 58 bool HasMacro : 1; // True if there is a #define for this. 59 bool IsExtension : 1; // True if identifier is a lang extension. 60 bool IsPoisoned : 1; // True if identifier is poisoned. 61 bool IsCPPOperatorKeyword : 1; // True if ident is a C++ operator keyword. 62 bool NeedsHandleIdentifier : 1; // See "RecomputeNeedsHandleIdentifier". 63 bool IsFromAST : 1; // True if identfier first appeared in an AST 64 // file and wasn't modified since. 65 bool RevertedTokenID : 1; // True if RevertTokenIDToIdentifier was 66 // called. 67 // 6 bits left in 32-bit word. 68 void *FETokenInfo; // Managed by the language front-end. 69 llvm::StringMapEntry<IdentifierInfo*> *Entry; 70 71 IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE. 72 void operator=(const IdentifierInfo&); // NONASSIGNABLE. 73 74 friend class IdentifierTable; 75 76public: 77 IdentifierInfo(); 78 79 80 /// isStr - Return true if this is the identifier for the specified string. 81 /// This is intended to be used for string literals only: II->isStr("foo"). 82 template <std::size_t StrLen> 83 bool isStr(const char (&Str)[StrLen]) const { 84 return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1); 85 } 86 87 /// getNameStart - Return the beginning of the actual string for this 88 /// identifier. The returned string is properly null terminated. 89 /// 90 const char *getNameStart() const { 91 if (Entry) return Entry->getKeyData(); 92 // FIXME: This is gross. It would be best not to embed specific details 93 // of the PTH file format here. 94 // The 'this' pointer really points to a 95 // std::pair<IdentifierInfo, const char*>, where internal pointer 96 // points to the external string data. 97 typedef std::pair<IdentifierInfo, const char*> actualtype; 98 return ((const actualtype*) this)->second; 99 } 100 101 /// getLength - Efficiently return the length of this identifier info. 102 /// 103 unsigned getLength() const { 104 if (Entry) return Entry->getKeyLength(); 105 // FIXME: This is gross. It would be best not to embed specific details 106 // of the PTH file format here. 107 // The 'this' pointer really points to a 108 // std::pair<IdentifierInfo, const char*>, where internal pointer 109 // points to the external string data. 110 typedef std::pair<IdentifierInfo, const char*> actualtype; 111 const char* p = ((const actualtype*) this)->second - 2; 112 return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1; 113 } 114 115 /// getName - Return the actual identifier string. 116 llvm::StringRef getName() const { 117 return llvm::StringRef(getNameStart(), getLength()); 118 } 119 120 /// hasMacroDefinition - Return true if this identifier is #defined to some 121 /// other value. 122 bool hasMacroDefinition() const { 123 return HasMacro; 124 } 125 void setHasMacroDefinition(bool Val) { 126 if (HasMacro == Val) return; 127 128 HasMacro = Val; 129 if (Val) 130 NeedsHandleIdentifier = 1; 131 else 132 RecomputeNeedsHandleIdentifier(); 133 IsFromAST = false; 134 } 135 136 /// getTokenID - If this is a source-language token (e.g. 'for'), this API 137 /// can be used to cause the lexer to map identifiers to source-language 138 /// tokens. 139 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; } 140 141 /// \brief True if RevertTokenIDToIdentifier() was called. 142 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; } 143 144 /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 145 /// compatibility. 146 /// 147 /// TokenID is normally read-only but there are 2 instances where we revert it 148 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens 149 /// using this method so we can inform serialization about it. 150 void RevertTokenIDToIdentifier() { 151 assert(TokenID != tok::identifier && "Already at tok::identifier"); 152 TokenID = tok::identifier; 153 RevertedTokenID = true; 154 } 155 156 /// getPPKeywordID - Return the preprocessor keyword ID for this identifier. 157 /// For example, "define" will return tok::pp_define. 158 tok::PPKeywordKind getPPKeywordID() const; 159 160 /// getObjCKeywordID - Return the Objective-C keyword ID for the this 161 /// identifier. For example, 'class' will return tok::objc_class if ObjC is 162 /// enabled. 163 tok::ObjCKeywordKind getObjCKeywordID() const { 164 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS) 165 return tok::ObjCKeywordKind(ObjCOrBuiltinID); 166 else 167 return tok::objc_not_keyword; 168 } 169 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; } 170 171 /// getBuiltinID - Return a value indicating whether this is a builtin 172 /// function. 0 is not-built-in. 1 is builtin-for-some-nonprimary-target. 173 /// 2+ are specific builtin functions. 174 unsigned getBuiltinID() const { 175 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS) 176 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS; 177 else 178 return 0; 179 } 180 void setBuiltinID(unsigned ID) { 181 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS; 182 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID 183 && "ID too large for field!"); 184 } 185 186 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; } 187 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; } 188 189 /// get/setExtension - Initialize information about whether or not this 190 /// language token is an extension. This controls extension warnings, and is 191 /// only valid if a custom token ID is set. 192 bool isExtensionToken() const { return IsExtension; } 193 void setIsExtensionToken(bool Val) { 194 IsExtension = Val; 195 if (Val) 196 NeedsHandleIdentifier = 1; 197 else 198 RecomputeNeedsHandleIdentifier(); 199 } 200 201 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the 202 /// Preprocessor will emit an error every time this token is used. 203 void setIsPoisoned(bool Value = true) { 204 IsPoisoned = Value; 205 if (Value) 206 NeedsHandleIdentifier = 1; 207 else 208 RecomputeNeedsHandleIdentifier(); 209 IsFromAST = false; 210 } 211 212 /// isPoisoned - Return true if this token has been poisoned. 213 bool isPoisoned() const { return IsPoisoned; } 214 215 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether 216 /// this identifier is a C++ alternate representation of an operator. 217 void setIsCPlusPlusOperatorKeyword(bool Val = true) { 218 IsCPPOperatorKeyword = Val; 219 if (Val) 220 NeedsHandleIdentifier = 1; 221 else 222 RecomputeNeedsHandleIdentifier(); 223 } 224 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; } 225 226 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to 227 /// associate arbitrary metadata with this token. 228 template<typename T> 229 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); } 230 void setFETokenInfo(void *T) { FETokenInfo = T; } 231 232 /// isHandleIdentifierCase - Return true if the Preprocessor::HandleIdentifier 233 /// must be called on a token of this identifier. If this returns false, we 234 /// know that HandleIdentifier will not affect the token. 235 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; } 236 237 /// isFromAST - Return true if the identifier in its current state was loaded 238 /// from an AST file. 239 bool isFromAST() const { return IsFromAST; } 240 241 void setIsFromAST(bool FromAST = true) { IsFromAST = FromAST; } 242 243private: 244 /// RecomputeNeedsHandleIdentifier - The Preprocessor::HandleIdentifier does 245 /// several special (but rare) things to identifiers of various sorts. For 246 /// example, it changes the "for" keyword token from tok::identifier to 247 /// tok::for. 248 /// 249 /// This method is very tied to the definition of HandleIdentifier. Any 250 /// change to it should be reflected here. 251 void RecomputeNeedsHandleIdentifier() { 252 NeedsHandleIdentifier = 253 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() | 254 isExtensionToken()); 255 } 256}; 257 258/// \brief An iterator that walks over all of the known identifiers 259/// in the lookup table. 260/// 261/// Since this iterator uses an abstract interface via virtual 262/// functions, it uses an object-oriented interface rather than the 263/// more standard C++ STL iterator interface. In this OO-style 264/// iteration, the single function \c Next() provides dereference, 265/// advance, and end-of-sequence checking in a single 266/// operation. Subclasses of this iterator type will provide the 267/// actual functionality. 268class IdentifierIterator { 269private: 270 IdentifierIterator(const IdentifierIterator&); // Do not implement 271 IdentifierIterator &operator=(const IdentifierIterator&); // Do not implement 272 273protected: 274 IdentifierIterator() { } 275 276public: 277 virtual ~IdentifierIterator(); 278 279 /// \brief Retrieve the next string in the identifier table and 280 /// advances the iterator for the following string. 281 /// 282 /// \returns The next string in the identifier table. If there is 283 /// no such string, returns an empty \c llvm::StringRef. 284 virtual llvm::StringRef Next() = 0; 285}; 286 287/// IdentifierInfoLookup - An abstract class used by IdentifierTable that 288/// provides an interface for performing lookups from strings 289/// (const char *) to IdentiferInfo objects. 290class IdentifierInfoLookup { 291public: 292 virtual ~IdentifierInfoLookup(); 293 294 /// get - Return the identifier token info for the specified named identifier. 295 /// Unlike the version in IdentifierTable, this returns a pointer instead 296 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot 297 /// be found. 298 virtual IdentifierInfo* get(llvm::StringRef Name) = 0; 299 300 /// \brief Retrieve an iterator into the set of all identifiers 301 /// known to this identifier lookup source. 302 /// 303 /// This routine provides access to all of the identifiers known to 304 /// the identifier lookup, allowing access to the contents of the 305 /// identifiers without introducing the overhead of constructing 306 /// IdentifierInfo objects for each. 307 /// 308 /// \returns A new iterator into the set of known identifiers. The 309 /// caller is responsible for deleting this iterator. 310 virtual IdentifierIterator *getIdentifiers() const; 311}; 312 313/// \brief An abstract class used to resolve numerical identifier 314/// references (meaningful only to some external source) into 315/// IdentifierInfo pointers. 316class ExternalIdentifierLookup { 317public: 318 virtual ~ExternalIdentifierLookup(); 319 320 /// \brief Return the identifier associated with the given ID number. 321 /// 322 /// The ID 0 is associated with the NULL identifier. 323 virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0; 324}; 325 326/// IdentifierTable - This table implements an efficient mapping from strings to 327/// IdentifierInfo nodes. It has no other purpose, but this is an 328/// extremely performance-critical piece of the code, as each occurrance of 329/// every identifier goes through here when lexed. 330class IdentifierTable { 331 // Shark shows that using MallocAllocator is *much* slower than using this 332 // BumpPtrAllocator! 333 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy; 334 HashTableTy HashTable; 335 336 IdentifierInfoLookup* ExternalLookup; 337 338public: 339 /// IdentifierTable ctor - Create the identifier table, populating it with 340 /// info about the language keywords for the language specified by LangOpts. 341 IdentifierTable(const LangOptions &LangOpts, 342 IdentifierInfoLookup* externalLookup = 0); 343 344 /// \brief Set the external identifier lookup mechanism. 345 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) { 346 ExternalLookup = IILookup; 347 } 348 349 /// \brief Retrieve the external identifier lookup object, if any. 350 IdentifierInfoLookup *getExternalIdentifierLookup() const { 351 return ExternalLookup; 352 } 353 354 llvm::BumpPtrAllocator& getAllocator() { 355 return HashTable.getAllocator(); 356 } 357 358 /// get - Return the identifier token info for the specified named identifier. 359 /// 360 IdentifierInfo &get(llvm::StringRef Name) { 361 llvm::StringMapEntry<IdentifierInfo*> &Entry = 362 HashTable.GetOrCreateValue(Name); 363 364 IdentifierInfo *II = Entry.getValue(); 365 if (II) return *II; 366 367 // No entry; if we have an external lookup, look there first. 368 if (ExternalLookup) { 369 II = ExternalLookup->get(Name); 370 if (II) { 371 // Cache in the StringMap for subsequent lookups. 372 Entry.setValue(II); 373 return *II; 374 } 375 } 376 377 // Lookups failed, make a new IdentifierInfo. 378 void *Mem = getAllocator().Allocate<IdentifierInfo>(); 379 II = new (Mem) IdentifierInfo(); 380 Entry.setValue(II); 381 382 // Make sure getName() knows how to find the IdentifierInfo 383 // contents. 384 II->Entry = &Entry; 385 386 return *II; 387 } 388 389 IdentifierInfo &get(llvm::StringRef Name, tok::TokenKind TokenCode) { 390 IdentifierInfo &II = get(Name); 391 II.TokenID = TokenCode; 392 return II; 393 } 394 395 IdentifierInfo &get(const char *NameStart, const char *NameEnd) { 396 return get(llvm::StringRef(NameStart, NameEnd-NameStart)); 397 } 398 399 IdentifierInfo &get(const char *Name, size_t NameLen) { 400 return get(llvm::StringRef(Name, NameLen)); 401 } 402 403 /// \brief Gets an IdentifierInfo for the given name without consulting 404 /// external sources. 405 /// 406 /// This is a version of get() meant for external sources that want to 407 /// introduce or modify an identifier. If they called get(), they would 408 /// likely end up in a recursion. 409 IdentifierInfo &getOwn(const char *NameStart, const char *NameEnd) { 410 llvm::StringMapEntry<IdentifierInfo*> &Entry = 411 HashTable.GetOrCreateValue(NameStart, NameEnd); 412 413 IdentifierInfo *II = Entry.getValue(); 414 if (!II) { 415 416 // Lookups failed, make a new IdentifierInfo. 417 void *Mem = getAllocator().Allocate<IdentifierInfo>(); 418 II = new (Mem) IdentifierInfo(); 419 Entry.setValue(II); 420 421 // Make sure getName() knows how to find the IdentifierInfo 422 // contents. 423 II->Entry = &Entry; 424 } 425 426 return *II; 427 } 428 IdentifierInfo &getOwn(llvm::StringRef Name) { 429 return getOwn(Name.begin(), Name.end()); 430 } 431 432 typedef HashTableTy::const_iterator iterator; 433 typedef HashTableTy::const_iterator const_iterator; 434 435 iterator begin() const { return HashTable.begin(); } 436 iterator end() const { return HashTable.end(); } 437 unsigned size() const { return HashTable.size(); } 438 439 /// PrintStats - Print some statistics to stderr that indicate how well the 440 /// hashing is doing. 441 void PrintStats() const; 442 443 void AddKeywords(const LangOptions &LangOpts); 444}; 445 446/// ObjCMethodFamily - A family of Objective-C methods. These 447/// families have no inherent meaning in the language, but are 448/// nonetheless central enough in the existing implementations to 449/// merit direct AST support. While, in theory, arbitrary methods can 450/// be considered to form families, we focus here on the methods 451/// involving allocation and retain-count management, as these are the 452/// most "core" and the most likely to be useful to diverse clients 453/// without extra information. 454/// 455/// Both selectors and actual method declarations may be classified 456/// into families. Method families may impose additional restrictions 457/// beyond their selector name; for example, a method called '_init' 458/// that returns void is not considered to be in the 'init' family 459/// (but would be if it returned 'id'). It is also possible to 460/// explicitly change or remove a method's family. Therefore the 461/// method's family should be considered the single source of truth. 462enum ObjCMethodFamily { 463 /// \brief No particular method family. 464 OMF_None, 465 466 // Selectors in these families may have arbitrary arity, may be 467 // written with arbitrary leading underscores, and may have 468 // additional CamelCase "words" in their first selector chunk 469 // following the family name. 470 OMF_alloc, 471 OMF_copy, 472 OMF_init, 473 OMF_mutableCopy, 474 OMF_new, 475 476 // These families are singletons consisting only of the nullary 477 // selector with the given name. 478 OMF_autorelease, 479 OMF_dealloc, 480 OMF_release, 481 OMF_retain, 482 OMF_retainCount 483}; 484 485/// Enough bits to store any enumerator in ObjCMethodFamily or 486/// InvalidObjCMethodFamily. 487enum { ObjCMethodFamilyBitWidth = 4 }; 488 489/// An invalid value of ObjCMethodFamily. 490enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 }; 491 492/// Selector - This smart pointer class efficiently represents Objective-C 493/// method names. This class will either point to an IdentifierInfo or a 494/// MultiKeywordSelector (which is private). This enables us to optimize 495/// selectors that take no arguments and selectors that take 1 argument, which 496/// accounts for 78% of all selectors in Cocoa.h. 497class Selector { 498 friend class DiagnosticInfo; 499 500 enum IdentifierInfoFlag { 501 // MultiKeywordSelector = 0. 502 ZeroArg = 0x1, 503 OneArg = 0x2, 504 ArgFlags = ZeroArg|OneArg 505 }; 506 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo. 507 508 Selector(IdentifierInfo *II, unsigned nArgs) { 509 InfoPtr = reinterpret_cast<uintptr_t>(II); 510 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); 511 assert(nArgs < 2 && "nArgs not equal to 0/1"); 512 InfoPtr |= nArgs+1; 513 } 514 Selector(MultiKeywordSelector *SI) { 515 InfoPtr = reinterpret_cast<uintptr_t>(SI); 516 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); 517 } 518 519 IdentifierInfo *getAsIdentifierInfo() const { 520 if (getIdentifierInfoFlag()) 521 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags); 522 return 0; 523 } 524 unsigned getIdentifierInfoFlag() const { 525 return InfoPtr & ArgFlags; 526 } 527 528 static ObjCMethodFamily getMethodFamilyImpl(Selector sel); 529 530public: 531 friend class SelectorTable; // only the SelectorTable can create these 532 friend class DeclarationName; // and the AST's DeclarationName. 533 534 /// The default ctor should only be used when creating data structures that 535 /// will contain selectors. 536 Selector() : InfoPtr(0) {} 537 Selector(uintptr_t V) : InfoPtr(V) {} 538 539 /// operator==/!= - Indicate whether the specified selectors are identical. 540 bool operator==(Selector RHS) const { 541 return InfoPtr == RHS.InfoPtr; 542 } 543 bool operator!=(Selector RHS) const { 544 return InfoPtr != RHS.InfoPtr; 545 } 546 void *getAsOpaquePtr() const { 547 return reinterpret_cast<void*>(InfoPtr); 548 } 549 550 /// \brief Determine whether this is the empty selector. 551 bool isNull() const { return InfoPtr == 0; } 552 553 // Predicates to identify the selector type. 554 bool isKeywordSelector() const { 555 return getIdentifierInfoFlag() != ZeroArg; 556 } 557 bool isUnarySelector() const { 558 return getIdentifierInfoFlag() == ZeroArg; 559 } 560 unsigned getNumArgs() const; 561 562 563 /// \brief Retrieve the identifier at a given position in the selector. 564 /// 565 /// Note that the identifier pointer returned may be NULL. Clients that only 566 /// care about the text of the identifier string, and not the specific, 567 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns 568 /// an empty string when the identifier pointer would be NULL. 569 /// 570 /// \param argIndex The index for which we want to retrieve the identifier. 571 /// This index shall be less than \c getNumArgs() unless this is a keyword 572 /// selector, in which case 0 is the only permissible value. 573 /// 574 /// \returns the uniqued identifier for this slot, or NULL if this slot has 575 /// no corresponding identifier. 576 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const; 577 578 /// \brief Retrieve the name at a given position in the selector. 579 /// 580 /// \param argIndex The index for which we want to retrieve the name. 581 /// This index shall be less than \c getNumArgs() unless this is a keyword 582 /// selector, in which case 0 is the only permissible value. 583 /// 584 /// \returns the name for this slot, which may be the empty string if no 585 /// name was supplied. 586 llvm::StringRef getNameForSlot(unsigned argIndex) const; 587 588 /// getAsString - Derive the full selector name (e.g. "foo:bar:") and return 589 /// it as an std::string. 590 std::string getAsString() const; 591 592 /// getMethodFamily - Derive the conventional family of this method. 593 ObjCMethodFamily getMethodFamily() const { 594 return getMethodFamilyImpl(*this); 595 } 596 597 static Selector getEmptyMarker() { 598 return Selector(uintptr_t(-1)); 599 } 600 static Selector getTombstoneMarker() { 601 return Selector(uintptr_t(-2)); 602 } 603}; 604 605/// SelectorTable - This table allows us to fully hide how we implement 606/// multi-keyword caching. 607class SelectorTable { 608 void *Impl; // Actually a SelectorTableImpl 609 SelectorTable(const SelectorTable&); // DISABLED: DO NOT IMPLEMENT 610 void operator=(const SelectorTable&); // DISABLED: DO NOT IMPLEMENT 611public: 612 SelectorTable(); 613 ~SelectorTable(); 614 615 /// getSelector - This can create any sort of selector. NumArgs indicates 616 /// whether this is a no argument selector "foo", a single argument selector 617 /// "foo:" or multi-argument "foo:bar:". 618 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV); 619 620 Selector getUnarySelector(IdentifierInfo *ID) { 621 return Selector(ID, 1); 622 } 623 Selector getNullarySelector(IdentifierInfo *ID) { 624 return Selector(ID, 0); 625 } 626 627 /// constructSetterName - Return the setter name for the given 628 /// identifier, i.e. "set" + Name where the initial character of Name 629 /// has been capitalized. 630 static Selector constructSetterName(IdentifierTable &Idents, 631 SelectorTable &SelTable, 632 const IdentifierInfo *Name) { 633 llvm::SmallString<100> SelectorName; 634 SelectorName = "set"; 635 SelectorName += Name->getName(); 636 SelectorName[3] = toupper(SelectorName[3]); 637 IdentifierInfo *SetterName = &Idents.get(SelectorName); 638 return SelTable.getUnarySelector(SetterName); 639 } 640}; 641 642/// DeclarationNameExtra - Common base of the MultiKeywordSelector, 643/// CXXSpecialName, and CXXOperatorIdName classes, all of which are 644/// private classes that describe different kinds of names. 645class DeclarationNameExtra { 646public: 647 /// ExtraKind - The kind of "extra" information stored in the 648 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of 649 /// how these enumerator values are used. 650 enum ExtraKind { 651 CXXConstructor = 0, 652 CXXDestructor, 653 CXXConversionFunction, 654#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 655 CXXOperator##Name, 656#include "clang/Basic/OperatorKinds.def" 657 CXXLiteralOperator, 658 CXXUsingDirective, 659 NUM_EXTRA_KINDS 660 }; 661 662 /// ExtraKindOrNumArgs - Either the kind of C++ special name or 663 /// operator-id (if the value is one of the CXX* enumerators of 664 /// ExtraKind), in which case the DeclarationNameExtra is also a 665 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or 666 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName, 667 /// it may be also name common to C++ using-directives (CXXUsingDirective), 668 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of 669 /// arguments in the Objective-C selector, in which case the 670 /// DeclarationNameExtra is also a MultiKeywordSelector. 671 unsigned ExtraKindOrNumArgs; 672}; 673 674} // end namespace clang 675 676namespace llvm { 677/// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and 678/// DenseSets. 679template <> 680struct DenseMapInfo<clang::Selector> { 681 static inline clang::Selector getEmptyKey() { 682 return clang::Selector::getEmptyMarker(); 683 } 684 static inline clang::Selector getTombstoneKey() { 685 return clang::Selector::getTombstoneMarker(); 686 } 687 688 static unsigned getHashValue(clang::Selector S); 689 690 static bool isEqual(clang::Selector LHS, clang::Selector RHS) { 691 return LHS == RHS; 692 } 693}; 694 695template <> 696struct isPodLike<clang::Selector> { static const bool value = true; }; 697 698template<> 699class PointerLikeTypeTraits<clang::Selector> { 700public: 701 static inline const void *getAsVoidPointer(clang::Selector P) { 702 return P.getAsOpaquePtr(); 703 } 704 static inline clang::Selector getFromVoidPointer(const void *P) { 705 return clang::Selector(reinterpret_cast<uintptr_t>(P)); 706 } 707 enum { NumLowBitsAvailable = 0 }; 708}; 709 710// Provide PointerLikeTypeTraits for IdentifierInfo pointers, which 711// are not guaranteed to be 8-byte aligned. 712template<> 713class PointerLikeTypeTraits<clang::IdentifierInfo*> { 714public: 715 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) { 716 return P; 717 } 718 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) { 719 return static_cast<clang::IdentifierInfo*>(P); 720 } 721 enum { NumLowBitsAvailable = 1 }; 722}; 723 724template<> 725class PointerLikeTypeTraits<const clang::IdentifierInfo*> { 726public: 727 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) { 728 return P; 729 } 730 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) { 731 return static_cast<const clang::IdentifierInfo*>(P); 732 } 733 enum { NumLowBitsAvailable = 1 }; 734}; 735 736} // end namespace llvm 737#endif 738