1 //===--- IdentifierTable.h - Hash table for identifier lookup ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the IdentifierInfo, IdentifierTable, and Selector
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
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"
30 template <typename T> struct DenseMapInfo;
36 class IdentifierTable;
38 class MultiKeywordSelector; // private class used by Selector
39 class DeclarationName; // AST class that stores declaration names
41 /// IdentifierLocPair - A simple pair of identifier info and location.
42 typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
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.
50 class 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
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
67 // 6 bits left in 32-bit word.
68 void *FETokenInfo; // Managed by the language front-end.
69 llvm::StringMapEntry<IdentifierInfo*> *Entry;
71 IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE.
72 void operator=(const IdentifierInfo&); // NONASSIGNABLE.
74 friend class IdentifierTable;
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);
87 /// getNameStart - Return the beginning of the actual string for this
88 /// identifier. The returned string is properly null terminated.
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;
101 /// getLength - Efficiently return the length of this identifier info.
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;
115 /// getName - Return the actual identifier string.
116 llvm::StringRef getName() const {
117 return llvm::StringRef(getNameStart(), getLength());
120 /// hasMacroDefinition - Return true if this identifier is #defined to some
122 bool hasMacroDefinition() const {
125 void setHasMacroDefinition(bool Val) {
126 if (HasMacro == Val) return;
130 NeedsHandleIdentifier = 1;
132 RecomputeNeedsHandleIdentifier();
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
139 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
141 /// \brief True if RevertTokenIDToIdentifier() was called.
142 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
144 /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
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;
156 /// getPPKeywordID - Return the preprocessor keyword ID for this identifier.
157 /// For example, "define" will return tok::pp_define.
158 tok::PPKeywordKind getPPKeywordID() const;
160 /// getObjCKeywordID - Return the Objective-C keyword ID for the this
161 /// identifier. For example, 'class' will return tok::objc_class if ObjC is
163 tok::ObjCKeywordKind getObjCKeywordID() const {
164 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
165 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
167 return tok::objc_not_keyword;
169 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
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;
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!");
186 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
187 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
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) {
196 NeedsHandleIdentifier = 1;
198 RecomputeNeedsHandleIdentifier();
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) {
206 NeedsHandleIdentifier = 1;
208 RecomputeNeedsHandleIdentifier();
212 /// isPoisoned - Return true if this token has been poisoned.
213 bool isPoisoned() const { return IsPoisoned; }
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;
220 NeedsHandleIdentifier = 1;
222 RecomputeNeedsHandleIdentifier();
224 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
226 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
227 /// associate arbitrary metadata with this token.
229 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
230 void setFETokenInfo(void *T) { FETokenInfo = T; }
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; }
237 /// isFromAST - Return true if the identifier in its current state was loaded
238 /// from an AST file.
239 bool isFromAST() const { return IsFromAST; }
241 void setIsFromAST(bool FromAST = true) { IsFromAST = FromAST; }
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
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() |
258 /// \brief an RAII object for [un]poisoning an identifier
259 /// within a certain scope. II is allowed to be null, in
260 /// which case, objects of this type have no effect.
261 class PoisonIdentifierRAIIObject {
262 IdentifierInfo *const II;
265 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
266 : II(II), OldValue(II ? II->isPoisoned() : false) {
268 II->setIsPoisoned(NewValue);
271 ~PoisonIdentifierRAIIObject() {
273 II->setIsPoisoned(OldValue);
277 /// \brief An iterator that walks over all of the known identifiers
278 /// in the lookup table.
280 /// Since this iterator uses an abstract interface via virtual
281 /// functions, it uses an object-oriented interface rather than the
282 /// more standard C++ STL iterator interface. In this OO-style
283 /// iteration, the single function \c Next() provides dereference,
284 /// advance, and end-of-sequence checking in a single
285 /// operation. Subclasses of this iterator type will provide the
286 /// actual functionality.
287 class IdentifierIterator {
289 IdentifierIterator(const IdentifierIterator&); // Do not implement
290 IdentifierIterator &operator=(const IdentifierIterator&); // Do not implement
293 IdentifierIterator() { }
296 virtual ~IdentifierIterator();
298 /// \brief Retrieve the next string in the identifier table and
299 /// advances the iterator for the following string.
301 /// \returns The next string in the identifier table. If there is
302 /// no such string, returns an empty \c llvm::StringRef.
303 virtual llvm::StringRef Next() = 0;
306 /// IdentifierInfoLookup - An abstract class used by IdentifierTable that
307 /// provides an interface for performing lookups from strings
308 /// (const char *) to IdentiferInfo objects.
309 class IdentifierInfoLookup {
311 virtual ~IdentifierInfoLookup();
313 /// get - Return the identifier token info for the specified named identifier.
314 /// Unlike the version in IdentifierTable, this returns a pointer instead
315 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot
317 virtual IdentifierInfo* get(llvm::StringRef Name) = 0;
319 /// \brief Retrieve an iterator into the set of all identifiers
320 /// known to this identifier lookup source.
322 /// This routine provides access to all of the identifiers known to
323 /// the identifier lookup, allowing access to the contents of the
324 /// identifiers without introducing the overhead of constructing
325 /// IdentifierInfo objects for each.
327 /// \returns A new iterator into the set of known identifiers. The
328 /// caller is responsible for deleting this iterator.
329 virtual IdentifierIterator *getIdentifiers() const;
332 /// \brief An abstract class used to resolve numerical identifier
333 /// references (meaningful only to some external source) into
334 /// IdentifierInfo pointers.
335 class ExternalIdentifierLookup {
337 virtual ~ExternalIdentifierLookup();
339 /// \brief Return the identifier associated with the given ID number.
341 /// The ID 0 is associated with the NULL identifier.
342 virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
345 /// IdentifierTable - This table implements an efficient mapping from strings to
346 /// IdentifierInfo nodes. It has no other purpose, but this is an
347 /// extremely performance-critical piece of the code, as each occurrence of
348 /// every identifier goes through here when lexed.
349 class IdentifierTable {
350 // Shark shows that using MallocAllocator is *much* slower than using this
352 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
353 HashTableTy HashTable;
355 IdentifierInfoLookup* ExternalLookup;
358 /// IdentifierTable ctor - Create the identifier table, populating it with
359 /// info about the language keywords for the language specified by LangOpts.
360 IdentifierTable(const LangOptions &LangOpts,
361 IdentifierInfoLookup* externalLookup = 0);
363 /// \brief Set the external identifier lookup mechanism.
364 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
365 ExternalLookup = IILookup;
368 /// \brief Retrieve the external identifier lookup object, if any.
369 IdentifierInfoLookup *getExternalIdentifierLookup() const {
370 return ExternalLookup;
373 llvm::BumpPtrAllocator& getAllocator() {
374 return HashTable.getAllocator();
377 /// get - Return the identifier token info for the specified named identifier.
379 IdentifierInfo &get(llvm::StringRef Name) {
380 llvm::StringMapEntry<IdentifierInfo*> &Entry =
381 HashTable.GetOrCreateValue(Name);
383 IdentifierInfo *II = Entry.getValue();
386 // No entry; if we have an external lookup, look there first.
387 if (ExternalLookup) {
388 II = ExternalLookup->get(Name);
390 // Cache in the StringMap for subsequent lookups.
396 // Lookups failed, make a new IdentifierInfo.
397 void *Mem = getAllocator().Allocate<IdentifierInfo>();
398 II = new (Mem) IdentifierInfo();
401 // Make sure getName() knows how to find the IdentifierInfo
408 IdentifierInfo &get(llvm::StringRef Name, tok::TokenKind TokenCode) {
409 IdentifierInfo &II = get(Name);
410 II.TokenID = TokenCode;
414 /// \brief Gets an IdentifierInfo for the given name without consulting
415 /// external sources.
417 /// This is a version of get() meant for external sources that want to
418 /// introduce or modify an identifier. If they called get(), they would
419 /// likely end up in a recursion.
420 IdentifierInfo &getOwn(llvm::StringRef Name) {
421 llvm::StringMapEntry<IdentifierInfo*> &Entry =
422 HashTable.GetOrCreateValue(Name);
424 IdentifierInfo *II = Entry.getValue();
427 // Lookups failed, make a new IdentifierInfo.
428 void *Mem = getAllocator().Allocate<IdentifierInfo>();
429 II = new (Mem) IdentifierInfo();
432 // Make sure getName() knows how to find the IdentifierInfo
440 typedef HashTableTy::const_iterator iterator;
441 typedef HashTableTy::const_iterator const_iterator;
443 iterator begin() const { return HashTable.begin(); }
444 iterator end() const { return HashTable.end(); }
445 unsigned size() const { return HashTable.size(); }
447 /// PrintStats - Print some statistics to stderr that indicate how well the
448 /// hashing is doing.
449 void PrintStats() const;
451 void AddKeywords(const LangOptions &LangOpts);
454 /// ObjCMethodFamily - A family of Objective-C methods. These
455 /// families have no inherent meaning in the language, but are
456 /// nonetheless central enough in the existing implementations to
457 /// merit direct AST support. While, in theory, arbitrary methods can
458 /// be considered to form families, we focus here on the methods
459 /// involving allocation and retain-count management, as these are the
460 /// most "core" and the most likely to be useful to diverse clients
461 /// without extra information.
463 /// Both selectors and actual method declarations may be classified
464 /// into families. Method families may impose additional restrictions
465 /// beyond their selector name; for example, a method called '_init'
466 /// that returns void is not considered to be in the 'init' family
467 /// (but would be if it returned 'id'). It is also possible to
468 /// explicitly change or remove a method's family. Therefore the
469 /// method's family should be considered the single source of truth.
470 enum ObjCMethodFamily {
471 /// \brief No particular method family.
474 // Selectors in these families may have arbitrary arity, may be
475 // written with arbitrary leading underscores, and may have
476 // additional CamelCase "words" in their first selector chunk
477 // following the family name.
484 // These families are singletons consisting only of the nullary
485 // selector with the given name.
493 // performSelector families
497 /// Enough bits to store any enumerator in ObjCMethodFamily or
498 /// InvalidObjCMethodFamily.
499 enum { ObjCMethodFamilyBitWidth = 4 };
501 /// An invalid value of ObjCMethodFamily.
502 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
504 /// Selector - This smart pointer class efficiently represents Objective-C
505 /// method names. This class will either point to an IdentifierInfo or a
506 /// MultiKeywordSelector (which is private). This enables us to optimize
507 /// selectors that take no arguments and selectors that take 1 argument, which
508 /// accounts for 78% of all selectors in Cocoa.h.
510 friend class DiagnosticInfo;
512 enum IdentifierInfoFlag {
513 // MultiKeywordSelector = 0.
516 ArgFlags = ZeroArg|OneArg
518 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
520 Selector(IdentifierInfo *II, unsigned nArgs) {
521 InfoPtr = reinterpret_cast<uintptr_t>(II);
522 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
523 assert(nArgs < 2 && "nArgs not equal to 0/1");
526 Selector(MultiKeywordSelector *SI) {
527 InfoPtr = reinterpret_cast<uintptr_t>(SI);
528 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
531 IdentifierInfo *getAsIdentifierInfo() const {
532 if (getIdentifierInfoFlag())
533 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
536 unsigned getIdentifierInfoFlag() const {
537 return InfoPtr & ArgFlags;
540 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
543 friend class SelectorTable; // only the SelectorTable can create these
544 friend class DeclarationName; // and the AST's DeclarationName.
546 /// The default ctor should only be used when creating data structures that
547 /// will contain selectors.
548 Selector() : InfoPtr(0) {}
549 Selector(uintptr_t V) : InfoPtr(V) {}
551 /// operator==/!= - Indicate whether the specified selectors are identical.
552 bool operator==(Selector RHS) const {
553 return InfoPtr == RHS.InfoPtr;
555 bool operator!=(Selector RHS) const {
556 return InfoPtr != RHS.InfoPtr;
558 void *getAsOpaquePtr() const {
559 return reinterpret_cast<void*>(InfoPtr);
562 /// \brief Determine whether this is the empty selector.
563 bool isNull() const { return InfoPtr == 0; }
565 // Predicates to identify the selector type.
566 bool isKeywordSelector() const {
567 return getIdentifierInfoFlag() != ZeroArg;
569 bool isUnarySelector() const {
570 return getIdentifierInfoFlag() == ZeroArg;
572 unsigned getNumArgs() const;
575 /// \brief Retrieve the identifier at a given position in the selector.
577 /// Note that the identifier pointer returned may be NULL. Clients that only
578 /// care about the text of the identifier string, and not the specific,
579 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
580 /// an empty string when the identifier pointer would be NULL.
582 /// \param argIndex The index for which we want to retrieve the identifier.
583 /// This index shall be less than \c getNumArgs() unless this is a keyword
584 /// selector, in which case 0 is the only permissible value.
586 /// \returns the uniqued identifier for this slot, or NULL if this slot has
587 /// no corresponding identifier.
588 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
590 /// \brief Retrieve the name at a given position in the selector.
592 /// \param argIndex The index for which we want to retrieve the name.
593 /// This index shall be less than \c getNumArgs() unless this is a keyword
594 /// selector, in which case 0 is the only permissible value.
596 /// \returns the name for this slot, which may be the empty string if no
597 /// name was supplied.
598 llvm::StringRef getNameForSlot(unsigned argIndex) const;
600 /// getAsString - Derive the full selector name (e.g. "foo:bar:") and return
601 /// it as an std::string.
602 std::string getAsString() const;
604 /// getMethodFamily - Derive the conventional family of this method.
605 ObjCMethodFamily getMethodFamily() const {
606 return getMethodFamilyImpl(*this);
609 static Selector getEmptyMarker() {
610 return Selector(uintptr_t(-1));
612 static Selector getTombstoneMarker() {
613 return Selector(uintptr_t(-2));
617 /// SelectorTable - This table allows us to fully hide how we implement
618 /// multi-keyword caching.
619 class SelectorTable {
620 void *Impl; // Actually a SelectorTableImpl
621 SelectorTable(const SelectorTable&); // DISABLED: DO NOT IMPLEMENT
622 void operator=(const SelectorTable&); // DISABLED: DO NOT IMPLEMENT
627 /// getSelector - This can create any sort of selector. NumArgs indicates
628 /// whether this is a no argument selector "foo", a single argument selector
629 /// "foo:" or multi-argument "foo:bar:".
630 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
632 Selector getUnarySelector(IdentifierInfo *ID) {
633 return Selector(ID, 1);
635 Selector getNullarySelector(IdentifierInfo *ID) {
636 return Selector(ID, 0);
639 /// Return the total amount of memory allocated for managing selectors.
640 size_t getTotalMemory() const;
642 /// constructSetterName - Return the setter name for the given
643 /// identifier, i.e. "set" + Name where the initial character of Name
644 /// has been capitalized.
645 static Selector constructSetterName(IdentifierTable &Idents,
646 SelectorTable &SelTable,
647 const IdentifierInfo *Name) {
648 llvm::SmallString<100> SelectorName;
649 SelectorName = "set";
650 SelectorName += Name->getName();
651 SelectorName[3] = toupper(SelectorName[3]);
652 IdentifierInfo *SetterName = &Idents.get(SelectorName);
653 return SelTable.getUnarySelector(SetterName);
657 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
658 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
659 /// private classes that describe different kinds of names.
660 class DeclarationNameExtra {
662 /// ExtraKind - The kind of "extra" information stored in the
663 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
664 /// how these enumerator values are used.
668 CXXConversionFunction,
669 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
671 #include "clang/Basic/OperatorKinds.def"
677 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
678 /// operator-id (if the value is one of the CXX* enumerators of
679 /// ExtraKind), in which case the DeclarationNameExtra is also a
680 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
681 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
682 /// it may be also name common to C++ using-directives (CXXUsingDirective),
683 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
684 /// arguments in the Objective-C selector, in which case the
685 /// DeclarationNameExtra is also a MultiKeywordSelector.
686 unsigned ExtraKindOrNumArgs;
689 } // end namespace clang
692 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
695 struct DenseMapInfo<clang::Selector> {
696 static inline clang::Selector getEmptyKey() {
697 return clang::Selector::getEmptyMarker();
699 static inline clang::Selector getTombstoneKey() {
700 return clang::Selector::getTombstoneMarker();
703 static unsigned getHashValue(clang::Selector S);
705 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
711 struct isPodLike<clang::Selector> { static const bool value = true; };
714 class PointerLikeTypeTraits<clang::Selector> {
716 static inline const void *getAsVoidPointer(clang::Selector P) {
717 return P.getAsOpaquePtr();
719 static inline clang::Selector getFromVoidPointer(const void *P) {
720 return clang::Selector(reinterpret_cast<uintptr_t>(P));
722 enum { NumLowBitsAvailable = 0 };
725 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
726 // are not guaranteed to be 8-byte aligned.
728 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
730 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
733 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
734 return static_cast<clang::IdentifierInfo*>(P);
736 enum { NumLowBitsAvailable = 1 };
740 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
742 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
745 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
746 return static_cast<const clang::IdentifierInfo*>(P);
748 enum { NumLowBitsAvailable = 1 };
751 } // end namespace llvm