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 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::IdentifierInfo, clang::IdentifierTable, and
12 /// clang::Selector interfaces.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
17 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/OperatorKinds.h"
21 #include "clang/Basic/TokenKinds.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/PointerLikeTypeTraits.h"
29 template <typename T> struct DenseMapInfo;
35 class IdentifierTable;
37 class MultiKeywordSelector; // private class used by Selector
38 class DeclarationName; // AST class that stores declaration names
40 /// \brief A simple pair of identifier info and location.
41 typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
44 /// One of these records is kept for each identifier that
45 /// is lexed. This contains information about whether the token was \#define'd,
46 /// is a language keyword, or if it is a front-end token of some sort (e.g. a
47 /// variable or function name). The preprocessor keeps this information in a
48 /// set, and all tok::identifier tokens have a pointer to one of these.
49 class IdentifierInfo {
50 unsigned TokenID : 9; // Front-end token ID or tok::identifier.
51 // Objective-C keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
52 // First NUM_OBJC_KEYWORDS values are for Objective-C, the remaining values
54 unsigned ObjCOrBuiltinID :11;
55 bool HasMacro : 1; // True if there is a #define for this.
56 bool HadMacro : 1; // True if there was a #define for this.
57 bool IsExtension : 1; // True if identifier is a lang extension.
58 bool IsCXX11CompatKeyword : 1; // True if identifier is a keyword in C++11.
59 bool IsPoisoned : 1; // True if identifier is poisoned.
60 bool IsCPPOperatorKeyword : 1; // True if ident is a C++ operator keyword.
61 bool NeedsHandleIdentifier : 1; // See "RecomputeNeedsHandleIdentifier".
62 bool IsFromAST : 1; // True if identifier was loaded (at least
63 // partially) from an AST file.
64 bool ChangedAfterLoad : 1; // True if identifier has changed from the
65 // definition loaded from an AST file.
66 bool RevertedTokenID : 1; // True if RevertTokenIDToIdentifier was
68 bool OutOfDate : 1; // True if there may be additional
69 // information about this identifier
71 bool IsModulesImport : 1; // True if this is the 'import' contextual
73 // 32-bit word is filled.
75 void *FETokenInfo; // Managed by the language front-end.
76 llvm::StringMapEntry<IdentifierInfo*> *Entry;
78 IdentifierInfo(const IdentifierInfo&) LLVM_DELETED_FUNCTION;
79 void operator=(const IdentifierInfo&) LLVM_DELETED_FUNCTION;
81 friend class IdentifierTable;
87 /// \brief Return true if this is the identifier for the specified string.
89 /// This is intended to be used for string literals only: II->isStr("foo").
90 template <std::size_t StrLen>
91 bool isStr(const char (&Str)[StrLen]) const {
92 return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1);
95 /// \brief Return the beginning of the actual null-terminated string for this
98 const char *getNameStart() const {
99 if (Entry) return Entry->getKeyData();
100 // FIXME: This is gross. It would be best not to embed specific details
101 // of the PTH file format here.
102 // The 'this' pointer really points to a
103 // std::pair<IdentifierInfo, const char*>, where internal pointer
104 // points to the external string data.
105 typedef std::pair<IdentifierInfo, const char*> actualtype;
106 return ((const actualtype*) this)->second;
109 /// \brief Efficiently return the length of this identifier info.
111 unsigned getLength() const {
112 if (Entry) return Entry->getKeyLength();
113 // FIXME: This is gross. It would be best not to embed specific details
114 // of the PTH file format here.
115 // The 'this' pointer really points to a
116 // std::pair<IdentifierInfo, const char*>, where internal pointer
117 // points to the external string data.
118 typedef std::pair<IdentifierInfo, const char*> actualtype;
119 const char* p = ((const actualtype*) this)->second - 2;
120 return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
123 /// \brief Return the actual identifier string.
124 StringRef getName() const {
125 return StringRef(getNameStart(), getLength());
128 /// \brief Return true if this identifier is \#defined to some other value.
129 bool hasMacroDefinition() const {
132 void setHasMacroDefinition(bool Val) {
133 if (HasMacro == Val) return;
137 NeedsHandleIdentifier = 1;
140 RecomputeNeedsHandleIdentifier();
143 /// \brief Returns true if this identifier was \#defined to some value at any
144 /// moment. In this case there should be an entry for the identifier in the
145 /// macro history table in Preprocessor.
146 bool hadMacroDefinition() const {
150 /// getTokenID - If this is a source-language token (e.g. 'for'), this API
151 /// can be used to cause the lexer to map identifiers to source-language
153 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
155 /// \brief True if RevertTokenIDToIdentifier() was called.
156 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
158 /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
161 /// TokenID is normally read-only but there are 2 instances where we revert it
162 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
163 /// using this method so we can inform serialization about it.
164 void RevertTokenIDToIdentifier() {
165 assert(TokenID != tok::identifier && "Already at tok::identifier");
166 TokenID = tok::identifier;
167 RevertedTokenID = true;
170 /// \brief Return the preprocessor keyword ID for this identifier.
172 /// For example, "define" will return tok::pp_define.
173 tok::PPKeywordKind getPPKeywordID() const;
175 /// \brief Return the Objective-C keyword ID for the this identifier.
177 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
178 tok::ObjCKeywordKind getObjCKeywordID() const {
179 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
180 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
182 return tok::objc_not_keyword;
184 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
186 /// getBuiltinID - Return a value indicating whether this is a builtin
187 /// function. 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
188 /// 2+ are specific builtin functions.
189 unsigned getBuiltinID() const {
190 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
191 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
195 void setBuiltinID(unsigned ID) {
196 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
197 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
198 && "ID too large for field!");
201 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
202 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
204 /// get/setExtension - Initialize information about whether or not this
205 /// language token is an extension. This controls extension warnings, and is
206 /// only valid if a custom token ID is set.
207 bool isExtensionToken() const { return IsExtension; }
208 void setIsExtensionToken(bool Val) {
211 NeedsHandleIdentifier = 1;
213 RecomputeNeedsHandleIdentifier();
216 /// is/setIsCXX11CompatKeyword - Initialize information about whether or not
217 /// this language token is a keyword in C++11. This controls compatibility
218 /// warnings, and is only true when not parsing C++11. Once a compatibility
219 /// problem has been diagnosed with this keyword, the flag will be cleared.
220 bool isCXX11CompatKeyword() const { return IsCXX11CompatKeyword; }
221 void setIsCXX11CompatKeyword(bool Val) {
222 IsCXX11CompatKeyword = Val;
224 NeedsHandleIdentifier = 1;
226 RecomputeNeedsHandleIdentifier();
229 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
230 /// Preprocessor will emit an error every time this token is used.
231 void setIsPoisoned(bool Value = true) {
234 NeedsHandleIdentifier = 1;
236 RecomputeNeedsHandleIdentifier();
239 /// isPoisoned - Return true if this token has been poisoned.
240 bool isPoisoned() const { return IsPoisoned; }
242 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
243 /// this identifier is a C++ alternate representation of an operator.
244 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
245 IsCPPOperatorKeyword = Val;
247 NeedsHandleIdentifier = 1;
249 RecomputeNeedsHandleIdentifier();
251 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
253 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
254 /// associate arbitrary metadata with this token.
256 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
257 void setFETokenInfo(void *T) { FETokenInfo = T; }
259 /// isHandleIdentifierCase - Return true if the Preprocessor::HandleIdentifier
260 /// must be called on a token of this identifier. If this returns false, we
261 /// know that HandleIdentifier will not affect the token.
262 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
264 /// isFromAST - Return true if the identifier in its current state was loaded
265 /// from an AST file.
266 bool isFromAST() const { return IsFromAST; }
268 void setIsFromAST() { IsFromAST = true; }
270 /// \brief Determine whether this identifier has changed since it was loaded
271 /// from an AST file.
272 bool hasChangedSinceDeserialization() const {
273 return ChangedAfterLoad;
276 /// \brief Note that this identifier has changed since it was loaded from
278 void setChangedSinceDeserialization() {
279 ChangedAfterLoad = true;
282 /// \brief Determine whether the information for this identifier is out of
283 /// date with respect to the external source.
284 bool isOutOfDate() const { return OutOfDate; }
286 /// \brief Set whether the information for this identifier is out of
287 /// date with respect to the external source.
288 void setOutOfDate(bool OOD) {
291 NeedsHandleIdentifier = true;
293 RecomputeNeedsHandleIdentifier();
296 /// \brief Determine whether this is the contextual keyword
298 bool isModulesImport() const { return IsModulesImport; }
300 /// \brief Set whether this identifier is the contextual keyword
302 void setModulesImport(bool I) {
305 NeedsHandleIdentifier = true;
307 RecomputeNeedsHandleIdentifier();
311 /// RecomputeNeedsHandleIdentifier - The Preprocessor::HandleIdentifier does
312 /// several special (but rare) things to identifiers of various sorts. For
313 /// example, it changes the "for" keyword token from tok::identifier to
316 /// This method is very tied to the definition of HandleIdentifier. Any
317 /// change to it should be reflected here.
318 void RecomputeNeedsHandleIdentifier() {
319 NeedsHandleIdentifier =
320 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
321 isExtensionToken() | isCXX11CompatKeyword() || isOutOfDate() ||
326 /// \brief an RAII object for [un]poisoning an identifier
327 /// within a certain scope. II is allowed to be null, in
328 /// which case, objects of this type have no effect.
329 class PoisonIdentifierRAIIObject {
330 IdentifierInfo *const II;
333 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
334 : II(II), OldValue(II ? II->isPoisoned() : false) {
336 II->setIsPoisoned(NewValue);
339 ~PoisonIdentifierRAIIObject() {
341 II->setIsPoisoned(OldValue);
345 /// \brief An iterator that walks over all of the known identifiers
346 /// in the lookup table.
348 /// Since this iterator uses an abstract interface via virtual
349 /// functions, it uses an object-oriented interface rather than the
350 /// more standard C++ STL iterator interface. In this OO-style
351 /// iteration, the single function \c Next() provides dereference,
352 /// advance, and end-of-sequence checking in a single
353 /// operation. Subclasses of this iterator type will provide the
354 /// actual functionality.
355 class IdentifierIterator {
357 IdentifierIterator(const IdentifierIterator &) LLVM_DELETED_FUNCTION;
358 void operator=(const IdentifierIterator &) LLVM_DELETED_FUNCTION;
361 IdentifierIterator() { }
364 virtual ~IdentifierIterator();
366 /// \brief Retrieve the next string in the identifier table and
367 /// advances the iterator for the following string.
369 /// \returns The next string in the identifier table. If there is
370 /// no such string, returns an empty \c StringRef.
371 virtual StringRef Next() = 0;
374 /// IdentifierInfoLookup - An abstract class used by IdentifierTable that
375 /// provides an interface for performing lookups from strings
376 /// (const char *) to IdentiferInfo objects.
377 class IdentifierInfoLookup {
379 virtual ~IdentifierInfoLookup();
381 /// get - Return the identifier token info for the specified named identifier.
382 /// Unlike the version in IdentifierTable, this returns a pointer instead
383 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot
385 virtual IdentifierInfo* get(StringRef Name) = 0;
387 /// \brief Retrieve an iterator into the set of all identifiers
388 /// known to this identifier lookup source.
390 /// This routine provides access to all of the identifiers known to
391 /// the identifier lookup, allowing access to the contents of the
392 /// identifiers without introducing the overhead of constructing
393 /// IdentifierInfo objects for each.
395 /// \returns A new iterator into the set of known identifiers. The
396 /// caller is responsible for deleting this iterator.
397 virtual IdentifierIterator *getIdentifiers();
400 /// \brief An abstract class used to resolve numerical identifier
401 /// references (meaningful only to some external source) into
402 /// IdentifierInfo pointers.
403 class ExternalIdentifierLookup {
405 virtual ~ExternalIdentifierLookup();
407 /// \brief Return the identifier associated with the given ID number.
409 /// The ID 0 is associated with the NULL identifier.
410 virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
413 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
415 /// This has no other purpose, but this is an extremely performance-critical
416 /// piece of the code, as each occurrence of every identifier goes through
418 class IdentifierTable {
419 // Shark shows that using MallocAllocator is *much* slower than using this
421 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
422 HashTableTy HashTable;
424 IdentifierInfoLookup* ExternalLookup;
427 /// \brief Create the identifier table, populating it with info about the
428 /// language keywords for the language specified by \p LangOpts.
429 IdentifierTable(const LangOptions &LangOpts,
430 IdentifierInfoLookup* externalLookup = 0);
432 /// \brief Set the external identifier lookup mechanism.
433 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
434 ExternalLookup = IILookup;
437 /// \brief Retrieve the external identifier lookup object, if any.
438 IdentifierInfoLookup *getExternalIdentifierLookup() const {
439 return ExternalLookup;
442 llvm::BumpPtrAllocator& getAllocator() {
443 return HashTable.getAllocator();
446 /// \brief Return the identifier token info for the specified named
448 IdentifierInfo &get(StringRef Name) {
449 llvm::StringMapEntry<IdentifierInfo*> &Entry =
450 HashTable.GetOrCreateValue(Name);
452 IdentifierInfo *II = Entry.getValue();
455 // No entry; if we have an external lookup, look there first.
456 if (ExternalLookup) {
457 II = ExternalLookup->get(Name);
459 // Cache in the StringMap for subsequent lookups.
465 // Lookups failed, make a new IdentifierInfo.
466 void *Mem = getAllocator().Allocate<IdentifierInfo>();
467 II = new (Mem) IdentifierInfo();
470 // Make sure getName() knows how to find the IdentifierInfo
477 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
478 IdentifierInfo &II = get(Name);
479 II.TokenID = TokenCode;
480 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
484 /// \brief Gets an IdentifierInfo for the given name without consulting
485 /// external sources.
487 /// This is a version of get() meant for external sources that want to
488 /// introduce or modify an identifier. If they called get(), they would
489 /// likely end up in a recursion.
490 IdentifierInfo &getOwn(StringRef Name) {
491 llvm::StringMapEntry<IdentifierInfo*> &Entry =
492 HashTable.GetOrCreateValue(Name);
494 IdentifierInfo *II = Entry.getValue();
497 // Lookups failed, make a new IdentifierInfo.
498 void *Mem = getAllocator().Allocate<IdentifierInfo>();
499 II = new (Mem) IdentifierInfo();
502 // Make sure getName() knows how to find the IdentifierInfo
506 // If this is the 'import' contextual keyword, mark it as such.
507 if (Name.equals("import"))
508 II->setModulesImport(true);
514 typedef HashTableTy::const_iterator iterator;
515 typedef HashTableTy::const_iterator const_iterator;
517 iterator begin() const { return HashTable.begin(); }
518 iterator end() const { return HashTable.end(); }
519 unsigned size() const { return HashTable.size(); }
521 /// \brief Print some statistics to stderr that indicate how well the
522 /// hashing is doing.
523 void PrintStats() const;
525 void AddKeywords(const LangOptions &LangOpts);
528 /// \brief A family of Objective-C methods.
530 /// These families have no inherent meaning in the language, but are
531 /// nonetheless central enough in the existing implementations to
532 /// merit direct AST support. While, in theory, arbitrary methods can
533 /// be considered to form families, we focus here on the methods
534 /// involving allocation and retain-count management, as these are the
535 /// most "core" and the most likely to be useful to diverse clients
536 /// without extra information.
538 /// Both selectors and actual method declarations may be classified
539 /// into families. Method families may impose additional restrictions
540 /// beyond their selector name; for example, a method called '_init'
541 /// that returns void is not considered to be in the 'init' family
542 /// (but would be if it returned 'id'). It is also possible to
543 /// explicitly change or remove a method's family. Therefore the
544 /// method's family should be considered the single source of truth.
545 enum ObjCMethodFamily {
546 /// \brief No particular method family.
549 // Selectors in these families may have arbitrary arity, may be
550 // written with arbitrary leading underscores, and may have
551 // additional CamelCase "words" in their first selector chunk
552 // following the family name.
559 // These families are singletons consisting only of the nullary
560 // selector with the given name.
569 // performSelector families
573 /// Enough bits to store any enumerator in ObjCMethodFamily or
574 /// InvalidObjCMethodFamily.
575 enum { ObjCMethodFamilyBitWidth = 4 };
577 /// \brief An invalid value of ObjCMethodFamily.
578 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
580 /// \brief Smart pointer class that efficiently represents Objective-C method
583 /// This class will either point to an IdentifierInfo or a
584 /// MultiKeywordSelector (which is private). This enables us to optimize
585 /// selectors that take no arguments and selectors that take 1 argument, which
586 /// accounts for 78% of all selectors in Cocoa.h.
588 friend class Diagnostic;
590 enum IdentifierInfoFlag {
591 // Empty selector = 0.
595 ArgFlags = ZeroArg|OneArg
597 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
599 Selector(IdentifierInfo *II, unsigned nArgs) {
600 InfoPtr = reinterpret_cast<uintptr_t>(II);
601 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
602 assert(nArgs < 2 && "nArgs not equal to 0/1");
605 Selector(MultiKeywordSelector *SI) {
606 InfoPtr = reinterpret_cast<uintptr_t>(SI);
607 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
611 IdentifierInfo *getAsIdentifierInfo() const {
612 if (getIdentifierInfoFlag() < MultiArg)
613 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
616 MultiKeywordSelector *getMultiKeywordSelector() const {
617 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
620 unsigned getIdentifierInfoFlag() const {
621 return InfoPtr & ArgFlags;
624 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
627 friend class SelectorTable; // only the SelectorTable can create these
628 friend class DeclarationName; // and the AST's DeclarationName.
630 /// The default ctor should only be used when creating data structures that
631 /// will contain selectors.
632 Selector() : InfoPtr(0) {}
633 Selector(uintptr_t V) : InfoPtr(V) {}
635 /// operator==/!= - Indicate whether the specified selectors are identical.
636 bool operator==(Selector RHS) const {
637 return InfoPtr == RHS.InfoPtr;
639 bool operator!=(Selector RHS) const {
640 return InfoPtr != RHS.InfoPtr;
642 void *getAsOpaquePtr() const {
643 return reinterpret_cast<void*>(InfoPtr);
646 /// \brief Determine whether this is the empty selector.
647 bool isNull() const { return InfoPtr == 0; }
649 // Predicates to identify the selector type.
650 bool isKeywordSelector() const {
651 return getIdentifierInfoFlag() != ZeroArg;
653 bool isUnarySelector() const {
654 return getIdentifierInfoFlag() == ZeroArg;
656 unsigned getNumArgs() const;
659 /// \brief Retrieve the identifier at a given position in the selector.
661 /// Note that the identifier pointer returned may be NULL. Clients that only
662 /// care about the text of the identifier string, and not the specific,
663 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
664 /// an empty string when the identifier pointer would be NULL.
666 /// \param argIndex The index for which we want to retrieve the identifier.
667 /// This index shall be less than \c getNumArgs() unless this is a keyword
668 /// selector, in which case 0 is the only permissible value.
670 /// \returns the uniqued identifier for this slot, or NULL if this slot has
671 /// no corresponding identifier.
672 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
674 /// \brief Retrieve the name at a given position in the selector.
676 /// \param argIndex The index for which we want to retrieve the name.
677 /// This index shall be less than \c getNumArgs() unless this is a keyword
678 /// selector, in which case 0 is the only permissible value.
680 /// \returns the name for this slot, which may be the empty string if no
681 /// name was supplied.
682 StringRef getNameForSlot(unsigned argIndex) const;
684 /// \brief Derive the full selector name (e.g. "foo:bar:") and return
685 /// it as an std::string.
686 // FIXME: Add a print method that uses a raw_ostream.
687 std::string getAsString() const;
689 /// \brief Derive the conventional family of this method.
690 ObjCMethodFamily getMethodFamily() const {
691 return getMethodFamilyImpl(*this);
694 static Selector getEmptyMarker() {
695 return Selector(uintptr_t(-1));
697 static Selector getTombstoneMarker() {
698 return Selector(uintptr_t(-2));
702 /// \brief This table allows us to fully hide how we implement
703 /// multi-keyword caching.
704 class SelectorTable {
705 void *Impl; // Actually a SelectorTableImpl
706 SelectorTable(const SelectorTable &) LLVM_DELETED_FUNCTION;
707 void operator=(const SelectorTable &) LLVM_DELETED_FUNCTION;
712 /// \brief Can create any sort of selector.
714 /// \p NumArgs indicates whether this is a no argument selector "foo", a
715 /// single argument selector "foo:" or multi-argument "foo:bar:".
716 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
718 Selector getUnarySelector(IdentifierInfo *ID) {
719 return Selector(ID, 1);
721 Selector getNullarySelector(IdentifierInfo *ID) {
722 return Selector(ID, 0);
725 /// \brief Return the total amount of memory allocated for managing selectors.
726 size_t getTotalMemory() const;
728 /// \brief Return the setter name for the given identifier.
730 /// This is "set" + \p Name where the initial character of \p Name
731 /// has been capitalized.
732 static Selector constructSetterName(IdentifierTable &Idents,
733 SelectorTable &SelTable,
734 const IdentifierInfo *Name);
737 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
738 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
739 /// private classes that describe different kinds of names.
740 class DeclarationNameExtra {
742 /// ExtraKind - The kind of "extra" information stored in the
743 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
744 /// how these enumerator values are used.
748 CXXConversionFunction,
749 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
751 #include "clang/Basic/OperatorKinds.def"
757 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
758 /// operator-id (if the value is one of the CXX* enumerators of
759 /// ExtraKind), in which case the DeclarationNameExtra is also a
760 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
761 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
762 /// it may be also name common to C++ using-directives (CXXUsingDirective),
763 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
764 /// arguments in the Objective-C selector, in which case the
765 /// DeclarationNameExtra is also a MultiKeywordSelector.
766 unsigned ExtraKindOrNumArgs;
769 } // end namespace clang
772 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
775 struct DenseMapInfo<clang::Selector> {
776 static inline clang::Selector getEmptyKey() {
777 return clang::Selector::getEmptyMarker();
779 static inline clang::Selector getTombstoneKey() {
780 return clang::Selector::getTombstoneMarker();
783 static unsigned getHashValue(clang::Selector S);
785 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
791 struct isPodLike<clang::Selector> { static const bool value = true; };
794 class PointerLikeTypeTraits<clang::Selector> {
796 static inline const void *getAsVoidPointer(clang::Selector P) {
797 return P.getAsOpaquePtr();
799 static inline clang::Selector getFromVoidPointer(const void *P) {
800 return clang::Selector(reinterpret_cast<uintptr_t>(P));
802 enum { NumLowBitsAvailable = 0 };
805 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
806 // are not guaranteed to be 8-byte aligned.
808 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
810 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
813 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
814 return static_cast<clang::IdentifierInfo*>(P);
816 enum { NumLowBitsAvailable = 1 };
820 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
822 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
825 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
826 return static_cast<const clang::IdentifierInfo*>(P);
828 enum { NumLowBitsAvailable = 1 };
831 } // end namespace llvm