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/TokenKinds.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
27 template <typename T> struct DenseMapInfo;
33 class IdentifierTable;
35 class MultiKeywordSelector; // private class used by Selector
36 class DeclarationName; // AST class that stores declaration names
38 /// \brief A simple pair of identifier info and location.
39 typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
42 /// One of these records is kept for each identifier that
43 /// is lexed. This contains information about whether the token was \#define'd,
44 /// is a language keyword, or if it is a front-end token of some sort (e.g. a
45 /// variable or function name). The preprocessor keeps this information in a
46 /// set, and all tok::identifier tokens have a pointer to one of these.
47 class IdentifierInfo {
48 unsigned TokenID : 9; // Front-end token ID or tok::identifier.
49 // Objective-C keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
50 // First NUM_OBJC_KEYWORDS values are for Objective-C, the remaining values
52 unsigned ObjCOrBuiltinID :13;
53 bool HasMacro : 1; // True if there is a #define for this.
54 bool HadMacro : 1; // True if there was a #define for this.
55 bool IsExtension : 1; // True if identifier is a lang extension.
56 bool IsFutureCompatKeyword : 1; // True if identifier is a keyword in a
57 // newer Standard or proposed Standard.
58 bool IsPoisoned : 1; // True if identifier is poisoned.
59 bool IsCPPOperatorKeyword : 1; // True if ident is a C++ operator keyword.
60 bool NeedsHandleIdentifier : 1; // See "RecomputeNeedsHandleIdentifier".
61 bool IsFromAST : 1; // True if identifier was loaded (at least
62 // partially) from an AST file.
63 bool ChangedAfterLoad : 1; // True if identifier has changed from the
64 // definition loaded from an AST file.
65 bool FEChangedAfterLoad : 1; // True if identifier's frontend information
66 // has changed from the definition loaded
68 bool RevertedTokenID : 1; // True if revertTokenIDToIdentifier was
70 bool OutOfDate : 1; // True if there may be additional
71 // information about this identifier
73 bool IsModulesImport : 1; // True if this is the 'import' contextual
75 // 29 bit left in 64-bit word.
77 void *FETokenInfo; // Managed by the language front-end.
78 llvm::StringMapEntry<IdentifierInfo*> *Entry;
80 IdentifierInfo(const IdentifierInfo&) = delete;
81 void operator=(const IdentifierInfo&) = delete;
83 friend class IdentifierTable;
89 /// \brief Return true if this is the identifier for the specified string.
91 /// This is intended to be used for string literals only: II->isStr("foo").
92 template <std::size_t StrLen>
93 bool isStr(const char (&Str)[StrLen]) const {
94 return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1);
97 /// \brief Return the beginning of the actual null-terminated string for this
100 const char *getNameStart() const {
101 if (Entry) return Entry->getKeyData();
102 // FIXME: This is gross. It would be best not to embed specific details
103 // of the PTH file format here.
104 // The 'this' pointer really points to a
105 // std::pair<IdentifierInfo, const char*>, where internal pointer
106 // points to the external string data.
107 typedef std::pair<IdentifierInfo, const char*> actualtype;
108 return ((const actualtype*) this)->second;
111 /// \brief Efficiently return the length of this identifier info.
113 unsigned getLength() const {
114 if (Entry) return Entry->getKeyLength();
115 // FIXME: This is gross. It would be best not to embed specific details
116 // of the PTH file format here.
117 // The 'this' pointer really points to a
118 // std::pair<IdentifierInfo, const char*>, where internal pointer
119 // points to the external string data.
120 typedef std::pair<IdentifierInfo, const char*> actualtype;
121 const char* p = ((const actualtype*) this)->second - 2;
122 return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
125 /// \brief Return the actual identifier string.
126 StringRef getName() const {
127 return StringRef(getNameStart(), getLength());
130 /// \brief Return true if this identifier is \#defined to some other value.
131 /// \note The current definition may be in a module and not currently visible.
132 bool hasMacroDefinition() const {
135 void setHasMacroDefinition(bool Val) {
136 if (HasMacro == Val) return;
140 NeedsHandleIdentifier = 1;
143 RecomputeNeedsHandleIdentifier();
146 /// \brief Returns true if this identifier was \#defined to some value at any
147 /// moment. In this case there should be an entry for the identifier in the
148 /// macro history table in Preprocessor.
149 bool hadMacroDefinition() const {
153 /// If this is a source-language token (e.g. 'for'), this API
154 /// can be used to cause the lexer to map identifiers to source-language
156 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
158 /// \brief True if revertTokenIDToIdentifier() was called.
159 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
161 /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
164 /// TokenID is normally read-only but there are 2 instances where we revert it
165 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
166 /// using this method so we can inform serialization about it.
167 void revertTokenIDToIdentifier() {
168 assert(TokenID != tok::identifier && "Already at tok::identifier");
169 TokenID = tok::identifier;
170 RevertedTokenID = true;
172 void revertIdentifierToTokenID(tok::TokenKind TK) {
173 assert(TokenID == tok::identifier && "Should be at tok::identifier");
175 RevertedTokenID = false;
178 /// \brief Return the preprocessor keyword ID for this identifier.
180 /// For example, "define" will return tok::pp_define.
181 tok::PPKeywordKind getPPKeywordID() const;
183 /// \brief Return the Objective-C keyword ID for the this identifier.
185 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
186 tok::ObjCKeywordKind getObjCKeywordID() const {
187 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
188 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
190 return tok::objc_not_keyword;
192 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
194 /// \brief True if setNotBuiltin() was called.
195 bool hasRevertedBuiltin() const {
196 return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
199 /// \brief Revert the identifier to a non-builtin identifier. We do this if
200 /// the name of a known builtin library function is used to declare that
201 /// function, but an unexpected type is specified.
202 void revertBuiltin() {
206 /// \brief Return a value indicating whether this is a builtin function.
208 /// 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
209 /// 2+ are specific builtin functions.
210 unsigned getBuiltinID() const {
211 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
212 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
216 void setBuiltinID(unsigned ID) {
217 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
218 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
219 && "ID too large for field!");
222 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
223 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
225 /// get/setExtension - Initialize information about whether or not this
226 /// language token is an extension. This controls extension warnings, and is
227 /// only valid if a custom token ID is set.
228 bool isExtensionToken() const { return IsExtension; }
229 void setIsExtensionToken(bool Val) {
232 NeedsHandleIdentifier = 1;
234 RecomputeNeedsHandleIdentifier();
237 /// is/setIsFutureCompatKeyword - Initialize information about whether or not
238 /// this language token is a keyword in a newer or proposed Standard. This
239 /// controls compatibility warnings, and is only true when not parsing the
240 /// corresponding Standard. Once a compatibility problem has been diagnosed
241 /// with this keyword, the flag will be cleared.
242 bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
243 void setIsFutureCompatKeyword(bool Val) {
244 IsFutureCompatKeyword = Val;
246 NeedsHandleIdentifier = 1;
248 RecomputeNeedsHandleIdentifier();
251 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
252 /// Preprocessor will emit an error every time this token is used.
253 void setIsPoisoned(bool Value = true) {
256 NeedsHandleIdentifier = 1;
258 RecomputeNeedsHandleIdentifier();
261 /// \brief Return true if this token has been poisoned.
262 bool isPoisoned() const { return IsPoisoned; }
264 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
265 /// this identifier is a C++ alternate representation of an operator.
266 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
267 IsCPPOperatorKeyword = Val;
269 NeedsHandleIdentifier = 1;
271 RecomputeNeedsHandleIdentifier();
273 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
275 /// \brief Return true if this token is a keyword in the specified language.
276 bool isKeyword(const LangOptions &LangOpts);
278 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
279 /// associate arbitrary metadata with this token.
281 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
282 void setFETokenInfo(void *T) { FETokenInfo = T; }
284 /// \brief Return true if the Preprocessor::HandleIdentifier must be called
285 /// on a token of this identifier.
287 /// If this returns false, we know that HandleIdentifier will not affect
289 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
291 /// \brief Return true if the identifier in its current state was loaded
292 /// from an AST file.
293 bool isFromAST() const { return IsFromAST; }
295 void setIsFromAST() { IsFromAST = true; }
297 /// \brief Determine whether this identifier has changed since it was loaded
298 /// from an AST file.
299 bool hasChangedSinceDeserialization() const {
300 return ChangedAfterLoad;
303 /// \brief Note that this identifier has changed since it was loaded from
305 void setChangedSinceDeserialization() {
306 ChangedAfterLoad = true;
309 /// \brief Determine whether the frontend token information for this
310 /// identifier has changed since it was loaded from an AST file.
311 bool hasFETokenInfoChangedSinceDeserialization() const {
312 return FEChangedAfterLoad;
315 /// \brief Note that the frontend token information for this identifier has
316 /// changed since it was loaded from an AST file.
317 void setFETokenInfoChangedSinceDeserialization() {
318 FEChangedAfterLoad = true;
321 /// \brief Determine whether the information for this identifier is out of
322 /// date with respect to the external source.
323 bool isOutOfDate() const { return OutOfDate; }
325 /// \brief Set whether the information for this identifier is out of
326 /// date with respect to the external source.
327 void setOutOfDate(bool OOD) {
330 NeedsHandleIdentifier = true;
332 RecomputeNeedsHandleIdentifier();
335 /// \brief Determine whether this is the contextual keyword \c import.
336 bool isModulesImport() const { return IsModulesImport; }
338 /// \brief Set whether this identifier is the contextual keyword \c import.
339 void setModulesImport(bool I) {
342 NeedsHandleIdentifier = true;
344 RecomputeNeedsHandleIdentifier();
347 /// \brief Provide less than operator for lexicographical sorting.
348 bool operator<(const IdentifierInfo &RHS) const {
349 return getName() < RHS.getName();
353 /// The Preprocessor::HandleIdentifier does several special (but rare)
354 /// things to identifiers of various sorts. For example, it changes the
355 /// \c for keyword token from tok::identifier to tok::for.
357 /// This method is very tied to the definition of HandleIdentifier. Any
358 /// change to it should be reflected here.
359 void RecomputeNeedsHandleIdentifier() {
360 NeedsHandleIdentifier =
361 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
362 isExtensionToken() | isFutureCompatKeyword() || isOutOfDate() ||
367 /// \brief An RAII object for [un]poisoning an identifier within a scope.
369 /// \p II is allowed to be null, in which case objects of this type have
371 class PoisonIdentifierRAIIObject {
372 IdentifierInfo *const II;
375 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
376 : II(II), OldValue(II ? II->isPoisoned() : false) {
378 II->setIsPoisoned(NewValue);
381 ~PoisonIdentifierRAIIObject() {
383 II->setIsPoisoned(OldValue);
387 /// \brief An iterator that walks over all of the known identifiers
388 /// in the lookup table.
390 /// Since this iterator uses an abstract interface via virtual
391 /// functions, it uses an object-oriented interface rather than the
392 /// more standard C++ STL iterator interface. In this OO-style
393 /// iteration, the single function \c Next() provides dereference,
394 /// advance, and end-of-sequence checking in a single
395 /// operation. Subclasses of this iterator type will provide the
396 /// actual functionality.
397 class IdentifierIterator {
399 IdentifierIterator(const IdentifierIterator &) = delete;
400 void operator=(const IdentifierIterator &) = delete;
403 IdentifierIterator() { }
406 virtual ~IdentifierIterator();
408 /// \brief Retrieve the next string in the identifier table and
409 /// advances the iterator for the following string.
411 /// \returns The next string in the identifier table. If there is
412 /// no such string, returns an empty \c StringRef.
413 virtual StringRef Next() = 0;
416 /// \brief Provides lookups to, and iteration over, IdentiferInfo objects.
417 class IdentifierInfoLookup {
419 virtual ~IdentifierInfoLookup();
421 /// \brief Return the IdentifierInfo for the specified named identifier.
423 /// Unlike the version in IdentifierTable, this returns a pointer instead
424 /// of a reference. If the pointer is null then the IdentifierInfo cannot
426 virtual IdentifierInfo* get(StringRef Name) = 0;
428 /// \brief Retrieve an iterator into the set of all identifiers
429 /// known to this identifier lookup source.
431 /// This routine provides access to all of the identifiers known to
432 /// the identifier lookup, allowing access to the contents of the
433 /// identifiers without introducing the overhead of constructing
434 /// IdentifierInfo objects for each.
436 /// \returns A new iterator into the set of known identifiers. The
437 /// caller is responsible for deleting this iterator.
438 virtual IdentifierIterator *getIdentifiers();
441 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
443 /// This has no other purpose, but this is an extremely performance-critical
444 /// piece of the code, as each occurrence of every identifier goes through
446 class IdentifierTable {
447 // Shark shows that using MallocAllocator is *much* slower than using this
449 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
450 HashTableTy HashTable;
452 IdentifierInfoLookup* ExternalLookup;
455 /// \brief Create the identifier table, populating it with info about the
456 /// language keywords for the language specified by \p LangOpts.
457 IdentifierTable(const LangOptions &LangOpts,
458 IdentifierInfoLookup* externalLookup = nullptr);
460 /// \brief Set the external identifier lookup mechanism.
461 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
462 ExternalLookup = IILookup;
465 /// \brief Retrieve the external identifier lookup object, if any.
466 IdentifierInfoLookup *getExternalIdentifierLookup() const {
467 return ExternalLookup;
470 llvm::BumpPtrAllocator& getAllocator() {
471 return HashTable.getAllocator();
474 /// \brief Return the identifier token info for the specified named
476 IdentifierInfo &get(StringRef Name) {
477 auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
479 IdentifierInfo *&II = Entry.second;
482 // No entry; if we have an external lookup, look there first.
483 if (ExternalLookup) {
484 II = ExternalLookup->get(Name);
489 // Lookups failed, make a new IdentifierInfo.
490 void *Mem = getAllocator().Allocate<IdentifierInfo>();
491 II = new (Mem) IdentifierInfo();
493 // Make sure getName() knows how to find the IdentifierInfo
500 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
501 IdentifierInfo &II = get(Name);
502 II.TokenID = TokenCode;
503 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
507 /// \brief Gets an IdentifierInfo for the given name without consulting
508 /// external sources.
510 /// This is a version of get() meant for external sources that want to
511 /// introduce or modify an identifier. If they called get(), they would
512 /// likely end up in a recursion.
513 IdentifierInfo &getOwn(StringRef Name) {
514 auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
516 IdentifierInfo *&II = Entry.second;
520 // Lookups failed, make a new IdentifierInfo.
521 void *Mem = getAllocator().Allocate<IdentifierInfo>();
522 II = new (Mem) IdentifierInfo();
524 // Make sure getName() knows how to find the IdentifierInfo
528 // If this is the 'import' contextual keyword, mark it as such.
529 if (Name.equals("import"))
530 II->setModulesImport(true);
535 typedef HashTableTy::const_iterator iterator;
536 typedef HashTableTy::const_iterator const_iterator;
538 iterator begin() const { return HashTable.begin(); }
539 iterator end() const { return HashTable.end(); }
540 unsigned size() const { return HashTable.size(); }
542 /// \brief Print some statistics to stderr that indicate how well the
543 /// hashing is doing.
544 void PrintStats() const;
546 void AddKeywords(const LangOptions &LangOpts);
549 /// \brief A family of Objective-C methods.
551 /// These families have no inherent meaning in the language, but are
552 /// nonetheless central enough in the existing implementations to
553 /// merit direct AST support. While, in theory, arbitrary methods can
554 /// be considered to form families, we focus here on the methods
555 /// involving allocation and retain-count management, as these are the
556 /// most "core" and the most likely to be useful to diverse clients
557 /// without extra information.
559 /// Both selectors and actual method declarations may be classified
560 /// into families. Method families may impose additional restrictions
561 /// beyond their selector name; for example, a method called '_init'
562 /// that returns void is not considered to be in the 'init' family
563 /// (but would be if it returned 'id'). It is also possible to
564 /// explicitly change or remove a method's family. Therefore the
565 /// method's family should be considered the single source of truth.
566 enum ObjCMethodFamily {
567 /// \brief No particular method family.
570 // Selectors in these families may have arbitrary arity, may be
571 // written with arbitrary leading underscores, and may have
572 // additional CamelCase "words" in their first selector chunk
573 // following the family name.
580 // These families are singletons consisting only of the nullary
581 // selector with the given name.
591 // performSelector families
595 /// Enough bits to store any enumerator in ObjCMethodFamily or
596 /// InvalidObjCMethodFamily.
597 enum { ObjCMethodFamilyBitWidth = 4 };
599 /// \brief An invalid value of ObjCMethodFamily.
600 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
602 /// \brief A family of Objective-C methods.
604 /// These are family of methods whose result type is initially 'id', but
605 /// but are candidate for the result type to be changed to 'instancetype'.
606 enum ObjCInstanceTypeFamily {
615 enum ObjCStringFormatFamily {
621 /// \brief Smart pointer class that efficiently represents Objective-C method
624 /// This class will either point to an IdentifierInfo or a
625 /// MultiKeywordSelector (which is private). This enables us to optimize
626 /// selectors that take no arguments and selectors that take 1 argument, which
627 /// accounts for 78% of all selectors in Cocoa.h.
629 friend class Diagnostic;
631 enum IdentifierInfoFlag {
632 // Empty selector = 0.
636 ArgFlags = ZeroArg|OneArg
638 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
640 Selector(IdentifierInfo *II, unsigned nArgs) {
641 InfoPtr = reinterpret_cast<uintptr_t>(II);
642 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
643 assert(nArgs < 2 && "nArgs not equal to 0/1");
646 Selector(MultiKeywordSelector *SI) {
647 InfoPtr = reinterpret_cast<uintptr_t>(SI);
648 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
652 IdentifierInfo *getAsIdentifierInfo() const {
653 if (getIdentifierInfoFlag() < MultiArg)
654 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
657 MultiKeywordSelector *getMultiKeywordSelector() const {
658 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
661 unsigned getIdentifierInfoFlag() const {
662 return InfoPtr & ArgFlags;
665 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
667 static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
670 friend class SelectorTable; // only the SelectorTable can create these
671 friend class DeclarationName; // and the AST's DeclarationName.
673 /// The default ctor should only be used when creating data structures that
674 /// will contain selectors.
675 Selector() : InfoPtr(0) {}
676 Selector(uintptr_t V) : InfoPtr(V) {}
678 /// operator==/!= - Indicate whether the specified selectors are identical.
679 bool operator==(Selector RHS) const {
680 return InfoPtr == RHS.InfoPtr;
682 bool operator!=(Selector RHS) const {
683 return InfoPtr != RHS.InfoPtr;
685 void *getAsOpaquePtr() const {
686 return reinterpret_cast<void*>(InfoPtr);
689 /// \brief Determine whether this is the empty selector.
690 bool isNull() const { return InfoPtr == 0; }
692 // Predicates to identify the selector type.
693 bool isKeywordSelector() const {
694 return getIdentifierInfoFlag() != ZeroArg;
696 bool isUnarySelector() const {
697 return getIdentifierInfoFlag() == ZeroArg;
699 unsigned getNumArgs() const;
702 /// \brief Retrieve the identifier at a given position in the selector.
704 /// Note that the identifier pointer returned may be NULL. Clients that only
705 /// care about the text of the identifier string, and not the specific,
706 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
707 /// an empty string when the identifier pointer would be NULL.
709 /// \param argIndex The index for which we want to retrieve the identifier.
710 /// This index shall be less than \c getNumArgs() unless this is a keyword
711 /// selector, in which case 0 is the only permissible value.
713 /// \returns the uniqued identifier for this slot, or NULL if this slot has
714 /// no corresponding identifier.
715 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
717 /// \brief Retrieve the name at a given position in the selector.
719 /// \param argIndex The index for which we want to retrieve the name.
720 /// This index shall be less than \c getNumArgs() unless this is a keyword
721 /// selector, in which case 0 is the only permissible value.
723 /// \returns the name for this slot, which may be the empty string if no
724 /// name was supplied.
725 StringRef getNameForSlot(unsigned argIndex) const;
727 /// \brief Derive the full selector name (e.g. "foo:bar:") and return
728 /// it as an std::string.
729 std::string getAsString() const;
731 /// \brief Prints the full selector name (e.g. "foo:bar:").
732 void print(llvm::raw_ostream &OS) const;
734 /// \brief Derive the conventional family of this method.
735 ObjCMethodFamily getMethodFamily() const {
736 return getMethodFamilyImpl(*this);
739 ObjCStringFormatFamily getStringFormatFamily() const {
740 return getStringFormatFamilyImpl(*this);
743 static Selector getEmptyMarker() {
744 return Selector(uintptr_t(-1));
746 static Selector getTombstoneMarker() {
747 return Selector(uintptr_t(-2));
750 static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
753 /// \brief This table allows us to fully hide how we implement
754 /// multi-keyword caching.
755 class SelectorTable {
756 void *Impl; // Actually a SelectorTableImpl
757 SelectorTable(const SelectorTable &) = delete;
758 void operator=(const SelectorTable &) = delete;
763 /// \brief Can create any sort of selector.
765 /// \p NumArgs indicates whether this is a no argument selector "foo", a
766 /// single argument selector "foo:" or multi-argument "foo:bar:".
767 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
769 Selector getUnarySelector(IdentifierInfo *ID) {
770 return Selector(ID, 1);
772 Selector getNullarySelector(IdentifierInfo *ID) {
773 return Selector(ID, 0);
776 /// \brief Return the total amount of memory allocated for managing selectors.
777 size_t getTotalMemory() const;
779 /// \brief Return the default setter name for the given identifier.
781 /// This is "set" + \p Name where the initial character of \p Name
782 /// has been capitalized.
783 static SmallString<64> constructSetterName(StringRef Name);
785 /// \brief Return the default setter selector for the given identifier.
787 /// This is "set" + \p Name where the initial character of \p Name
788 /// has been capitalized.
789 static Selector constructSetterSelector(IdentifierTable &Idents,
790 SelectorTable &SelTable,
791 const IdentifierInfo *Name);
794 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
795 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
796 /// private classes that describe different kinds of names.
797 class DeclarationNameExtra {
799 /// ExtraKind - The kind of "extra" information stored in the
800 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
801 /// how these enumerator values are used.
805 CXXConversionFunction,
806 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
808 #include "clang/Basic/OperatorKinds.def"
814 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
815 /// operator-id (if the value is one of the CXX* enumerators of
816 /// ExtraKind), in which case the DeclarationNameExtra is also a
817 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
818 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
819 /// it may be also name common to C++ using-directives (CXXUsingDirective),
820 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
821 /// arguments in the Objective-C selector, in which case the
822 /// DeclarationNameExtra is also a MultiKeywordSelector.
823 unsigned ExtraKindOrNumArgs;
826 } // end namespace clang
829 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
832 struct DenseMapInfo<clang::Selector> {
833 static inline clang::Selector getEmptyKey() {
834 return clang::Selector::getEmptyMarker();
836 static inline clang::Selector getTombstoneKey() {
837 return clang::Selector::getTombstoneMarker();
840 static unsigned getHashValue(clang::Selector S);
842 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
848 struct isPodLike<clang::Selector> { static const bool value = true; };
850 template <typename T> class PointerLikeTypeTraits;
853 class PointerLikeTypeTraits<clang::Selector> {
855 static inline const void *getAsVoidPointer(clang::Selector P) {
856 return P.getAsOpaquePtr();
858 static inline clang::Selector getFromVoidPointer(const void *P) {
859 return clang::Selector(reinterpret_cast<uintptr_t>(P));
861 enum { NumLowBitsAvailable = 0 };
864 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
865 // are not guaranteed to be 8-byte aligned.
867 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
869 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
872 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
873 return static_cast<clang::IdentifierInfo*>(P);
875 enum { NumLowBitsAvailable = 1 };
879 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
881 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
884 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
885 return static_cast<const clang::IdentifierInfo*>(P);
887 enum { NumLowBitsAvailable = 1 };
890 } // end namespace llvm