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 RevertedTokenID : 1; // True if RevertTokenIDToIdentifier was
67 bool OutOfDate : 1; // True if there may be additional
68 // information about this identifier
70 bool IsModulesImport : 1; // True if this is the 'import' contextual
72 // 30 bit left in 64-bit word.
74 void *FETokenInfo; // Managed by the language front-end.
75 llvm::StringMapEntry<IdentifierInfo*> *Entry;
77 IdentifierInfo(const IdentifierInfo&) = delete;
78 void operator=(const IdentifierInfo&) = delete;
80 friend class IdentifierTable;
86 /// \brief Return true if this is the identifier for the specified string.
88 /// This is intended to be used for string literals only: II->isStr("foo").
89 template <std::size_t StrLen>
90 bool isStr(const char (&Str)[StrLen]) const {
91 return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1);
94 /// \brief Return the beginning of the actual null-terminated string for this
97 const char *getNameStart() const {
98 if (Entry) return Entry->getKeyData();
99 // FIXME: This is gross. It would be best not to embed specific details
100 // of the PTH file format here.
101 // The 'this' pointer really points to a
102 // std::pair<IdentifierInfo, const char*>, where internal pointer
103 // points to the external string data.
104 typedef std::pair<IdentifierInfo, const char*> actualtype;
105 return ((const actualtype*) this)->second;
108 /// \brief Efficiently return the length of this identifier info.
110 unsigned getLength() const {
111 if (Entry) return Entry->getKeyLength();
112 // FIXME: This is gross. It would be best not to embed specific details
113 // of the PTH file format here.
114 // The 'this' pointer really points to a
115 // std::pair<IdentifierInfo, const char*>, where internal pointer
116 // points to the external string data.
117 typedef std::pair<IdentifierInfo, const char*> actualtype;
118 const char* p = ((const actualtype*) this)->second - 2;
119 return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
122 /// \brief Return the actual identifier string.
123 StringRef getName() const {
124 return StringRef(getNameStart(), getLength());
127 /// \brief Return true if this identifier is \#defined to some other value.
128 /// \note The current definition may be in a module and not currently visible.
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 /// 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 /// \brief Return a value indicating whether this is a builtin function.
188 /// 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
189 /// 2+ are specific builtin functions.
190 unsigned getBuiltinID() const {
191 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
192 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
196 void setBuiltinID(unsigned ID) {
197 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
198 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
199 && "ID too large for field!");
202 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
203 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
205 /// get/setExtension - Initialize information about whether or not this
206 /// language token is an extension. This controls extension warnings, and is
207 /// only valid if a custom token ID is set.
208 bool isExtensionToken() const { return IsExtension; }
209 void setIsExtensionToken(bool Val) {
212 NeedsHandleIdentifier = 1;
214 RecomputeNeedsHandleIdentifier();
217 /// is/setIsFutureCompatKeyword - Initialize information about whether or not
218 /// this language token is a keyword in a newer or proposed Standard. This
219 /// controls compatibility warnings, and is only true when not parsing the
220 /// corresponding Standard. Once a compatibility problem has been diagnosed
221 /// with this keyword, the flag will be cleared.
222 bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
223 void setIsFutureCompatKeyword(bool Val) {
224 IsFutureCompatKeyword = Val;
226 NeedsHandleIdentifier = 1;
228 RecomputeNeedsHandleIdentifier();
231 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
232 /// Preprocessor will emit an error every time this token is used.
233 void setIsPoisoned(bool Value = true) {
236 NeedsHandleIdentifier = 1;
238 RecomputeNeedsHandleIdentifier();
241 /// \brief Return true if this token has been poisoned.
242 bool isPoisoned() const { return IsPoisoned; }
244 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
245 /// this identifier is a C++ alternate representation of an operator.
246 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
247 IsCPPOperatorKeyword = Val;
249 NeedsHandleIdentifier = 1;
251 RecomputeNeedsHandleIdentifier();
253 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
255 /// \brief Return true if this token is a keyword in the specified language.
256 bool isKeyword(const LangOptions &LangOpts);
258 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
259 /// associate arbitrary metadata with this token.
261 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
262 void setFETokenInfo(void *T) { FETokenInfo = T; }
264 /// \brief Return true if the Preprocessor::HandleIdentifier must be called
265 /// on a token of this identifier.
267 /// If this returns false, we know that HandleIdentifier will not affect
269 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
271 /// \brief Return true if the identifier in its current state was loaded
272 /// from an AST file.
273 bool isFromAST() const { return IsFromAST; }
275 void setIsFromAST() { IsFromAST = true; }
277 /// \brief Determine whether this identifier has changed since it was loaded
278 /// from an AST file.
279 bool hasChangedSinceDeserialization() const {
280 return ChangedAfterLoad;
283 /// \brief Note that this identifier has changed since it was loaded from
285 void setChangedSinceDeserialization() {
286 ChangedAfterLoad = true;
289 /// \brief Determine whether the information for this identifier is out of
290 /// date with respect to the external source.
291 bool isOutOfDate() const { return OutOfDate; }
293 /// \brief Set whether the information for this identifier is out of
294 /// date with respect to the external source.
295 void setOutOfDate(bool OOD) {
298 NeedsHandleIdentifier = true;
300 RecomputeNeedsHandleIdentifier();
303 /// \brief Determine whether this is the contextual keyword \c import.
304 bool isModulesImport() const { return IsModulesImport; }
306 /// \brief Set whether this identifier is the contextual keyword \c import.
307 void setModulesImport(bool I) {
310 NeedsHandleIdentifier = true;
312 RecomputeNeedsHandleIdentifier();
315 /// \brief Provide less than operator for lexicographical sorting.
316 bool operator<(const IdentifierInfo &RHS) const {
317 return getName() < RHS.getName();
321 /// The Preprocessor::HandleIdentifier does several special (but rare)
322 /// things to identifiers of various sorts. For example, it changes the
323 /// \c for keyword token from tok::identifier to tok::for.
325 /// This method is very tied to the definition of HandleIdentifier. Any
326 /// change to it should be reflected here.
327 void RecomputeNeedsHandleIdentifier() {
328 NeedsHandleIdentifier =
329 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
330 isExtensionToken() | isFutureCompatKeyword() || isOutOfDate() ||
335 /// \brief An RAII object for [un]poisoning an identifier within a scope.
337 /// \p II is allowed to be null, in which case objects of this type have
339 class PoisonIdentifierRAIIObject {
340 IdentifierInfo *const II;
343 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
344 : II(II), OldValue(II ? II->isPoisoned() : false) {
346 II->setIsPoisoned(NewValue);
349 ~PoisonIdentifierRAIIObject() {
351 II->setIsPoisoned(OldValue);
355 /// \brief An iterator that walks over all of the known identifiers
356 /// in the lookup table.
358 /// Since this iterator uses an abstract interface via virtual
359 /// functions, it uses an object-oriented interface rather than the
360 /// more standard C++ STL iterator interface. In this OO-style
361 /// iteration, the single function \c Next() provides dereference,
362 /// advance, and end-of-sequence checking in a single
363 /// operation. Subclasses of this iterator type will provide the
364 /// actual functionality.
365 class IdentifierIterator {
367 IdentifierIterator(const IdentifierIterator &) = delete;
368 void operator=(const IdentifierIterator &) = delete;
371 IdentifierIterator() { }
374 virtual ~IdentifierIterator();
376 /// \brief Retrieve the next string in the identifier table and
377 /// advances the iterator for the following string.
379 /// \returns The next string in the identifier table. If there is
380 /// no such string, returns an empty \c StringRef.
381 virtual StringRef Next() = 0;
384 /// \brief Provides lookups to, and iteration over, IdentiferInfo objects.
385 class IdentifierInfoLookup {
387 virtual ~IdentifierInfoLookup();
389 /// \brief Return the IdentifierInfo for the specified named identifier.
391 /// Unlike the version in IdentifierTable, this returns a pointer instead
392 /// of a reference. If the pointer is null then the IdentifierInfo cannot
394 virtual IdentifierInfo* get(StringRef Name) = 0;
396 /// \brief Retrieve an iterator into the set of all identifiers
397 /// known to this identifier lookup source.
399 /// This routine provides access to all of the identifiers known to
400 /// the identifier lookup, allowing access to the contents of the
401 /// identifiers without introducing the overhead of constructing
402 /// IdentifierInfo objects for each.
404 /// \returns A new iterator into the set of known identifiers. The
405 /// caller is responsible for deleting this iterator.
406 virtual IdentifierIterator *getIdentifiers();
409 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
411 /// This has no other purpose, but this is an extremely performance-critical
412 /// piece of the code, as each occurrence of every identifier goes through
414 class IdentifierTable {
415 // Shark shows that using MallocAllocator is *much* slower than using this
417 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
418 HashTableTy HashTable;
420 IdentifierInfoLookup* ExternalLookup;
423 /// \brief Create the identifier table, populating it with info about the
424 /// language keywords for the language specified by \p LangOpts.
425 IdentifierTable(const LangOptions &LangOpts,
426 IdentifierInfoLookup* externalLookup = nullptr);
428 /// \brief Set the external identifier lookup mechanism.
429 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
430 ExternalLookup = IILookup;
433 /// \brief Retrieve the external identifier lookup object, if any.
434 IdentifierInfoLookup *getExternalIdentifierLookup() const {
435 return ExternalLookup;
438 llvm::BumpPtrAllocator& getAllocator() {
439 return HashTable.getAllocator();
442 /// \brief Return the identifier token info for the specified named
444 IdentifierInfo &get(StringRef Name) {
445 auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
447 IdentifierInfo *&II = Entry.second;
450 // No entry; if we have an external lookup, look there first.
451 if (ExternalLookup) {
452 II = ExternalLookup->get(Name);
457 // Lookups failed, make a new IdentifierInfo.
458 void *Mem = getAllocator().Allocate<IdentifierInfo>();
459 II = new (Mem) IdentifierInfo();
461 // Make sure getName() knows how to find the IdentifierInfo
468 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
469 IdentifierInfo &II = get(Name);
470 II.TokenID = TokenCode;
471 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
475 /// \brief Gets an IdentifierInfo for the given name without consulting
476 /// external sources.
478 /// This is a version of get() meant for external sources that want to
479 /// introduce or modify an identifier. If they called get(), they would
480 /// likely end up in a recursion.
481 IdentifierInfo &getOwn(StringRef Name) {
482 auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
484 IdentifierInfo *&II = Entry.second;
488 // Lookups failed, make a new IdentifierInfo.
489 void *Mem = getAllocator().Allocate<IdentifierInfo>();
490 II = new (Mem) IdentifierInfo();
492 // Make sure getName() knows how to find the IdentifierInfo
496 // If this is the 'import' contextual keyword, mark it as such.
497 if (Name.equals("import"))
498 II->setModulesImport(true);
503 typedef HashTableTy::const_iterator iterator;
504 typedef HashTableTy::const_iterator const_iterator;
506 iterator begin() const { return HashTable.begin(); }
507 iterator end() const { return HashTable.end(); }
508 unsigned size() const { return HashTable.size(); }
510 /// \brief Print some statistics to stderr that indicate how well the
511 /// hashing is doing.
512 void PrintStats() const;
514 void AddKeywords(const LangOptions &LangOpts);
517 /// \brief A family of Objective-C methods.
519 /// These families have no inherent meaning in the language, but are
520 /// nonetheless central enough in the existing implementations to
521 /// merit direct AST support. While, in theory, arbitrary methods can
522 /// be considered to form families, we focus here on the methods
523 /// involving allocation and retain-count management, as these are the
524 /// most "core" and the most likely to be useful to diverse clients
525 /// without extra information.
527 /// Both selectors and actual method declarations may be classified
528 /// into families. Method families may impose additional restrictions
529 /// beyond their selector name; for example, a method called '_init'
530 /// that returns void is not considered to be in the 'init' family
531 /// (but would be if it returned 'id'). It is also possible to
532 /// explicitly change or remove a method's family. Therefore the
533 /// method's family should be considered the single source of truth.
534 enum ObjCMethodFamily {
535 /// \brief No particular method family.
538 // Selectors in these families may have arbitrary arity, may be
539 // written with arbitrary leading underscores, and may have
540 // additional CamelCase "words" in their first selector chunk
541 // following the family name.
548 // These families are singletons consisting only of the nullary
549 // selector with the given name.
559 // performSelector families
563 /// Enough bits to store any enumerator in ObjCMethodFamily or
564 /// InvalidObjCMethodFamily.
565 enum { ObjCMethodFamilyBitWidth = 4 };
567 /// \brief An invalid value of ObjCMethodFamily.
568 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
570 /// \brief A family of Objective-C methods.
572 /// These are family of methods whose result type is initially 'id', but
573 /// but are candidate for the result type to be changed to 'instancetype'.
574 enum ObjCInstanceTypeFamily {
583 enum ObjCStringFormatFamily {
589 /// \brief Smart pointer class that efficiently represents Objective-C method
592 /// This class will either point to an IdentifierInfo or a
593 /// MultiKeywordSelector (which is private). This enables us to optimize
594 /// selectors that take no arguments and selectors that take 1 argument, which
595 /// accounts for 78% of all selectors in Cocoa.h.
597 friend class Diagnostic;
599 enum IdentifierInfoFlag {
600 // Empty selector = 0.
604 ArgFlags = ZeroArg|OneArg
606 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
608 Selector(IdentifierInfo *II, unsigned nArgs) {
609 InfoPtr = reinterpret_cast<uintptr_t>(II);
610 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
611 assert(nArgs < 2 && "nArgs not equal to 0/1");
614 Selector(MultiKeywordSelector *SI) {
615 InfoPtr = reinterpret_cast<uintptr_t>(SI);
616 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
620 IdentifierInfo *getAsIdentifierInfo() const {
621 if (getIdentifierInfoFlag() < MultiArg)
622 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
625 MultiKeywordSelector *getMultiKeywordSelector() const {
626 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
629 unsigned getIdentifierInfoFlag() const {
630 return InfoPtr & ArgFlags;
633 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
635 static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
638 friend class SelectorTable; // only the SelectorTable can create these
639 friend class DeclarationName; // and the AST's DeclarationName.
641 /// The default ctor should only be used when creating data structures that
642 /// will contain selectors.
643 Selector() : InfoPtr(0) {}
644 Selector(uintptr_t V) : InfoPtr(V) {}
646 /// operator==/!= - Indicate whether the specified selectors are identical.
647 bool operator==(Selector RHS) const {
648 return InfoPtr == RHS.InfoPtr;
650 bool operator!=(Selector RHS) const {
651 return InfoPtr != RHS.InfoPtr;
653 void *getAsOpaquePtr() const {
654 return reinterpret_cast<void*>(InfoPtr);
657 /// \brief Determine whether this is the empty selector.
658 bool isNull() const { return InfoPtr == 0; }
660 // Predicates to identify the selector type.
661 bool isKeywordSelector() const {
662 return getIdentifierInfoFlag() != ZeroArg;
664 bool isUnarySelector() const {
665 return getIdentifierInfoFlag() == ZeroArg;
667 unsigned getNumArgs() const;
670 /// \brief Retrieve the identifier at a given position in the selector.
672 /// Note that the identifier pointer returned may be NULL. Clients that only
673 /// care about the text of the identifier string, and not the specific,
674 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
675 /// an empty string when the identifier pointer would be NULL.
677 /// \param argIndex The index for which we want to retrieve the identifier.
678 /// This index shall be less than \c getNumArgs() unless this is a keyword
679 /// selector, in which case 0 is the only permissible value.
681 /// \returns the uniqued identifier for this slot, or NULL if this slot has
682 /// no corresponding identifier.
683 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
685 /// \brief Retrieve the name at a given position in the selector.
687 /// \param argIndex The index for which we want to retrieve the name.
688 /// This index shall be less than \c getNumArgs() unless this is a keyword
689 /// selector, in which case 0 is the only permissible value.
691 /// \returns the name for this slot, which may be the empty string if no
692 /// name was supplied.
693 StringRef getNameForSlot(unsigned argIndex) const;
695 /// \brief Derive the full selector name (e.g. "foo:bar:") and return
696 /// it as an std::string.
697 std::string getAsString() const;
699 /// \brief Prints the full selector name (e.g. "foo:bar:").
700 void print(llvm::raw_ostream &OS) const;
702 /// \brief Derive the conventional family of this method.
703 ObjCMethodFamily getMethodFamily() const {
704 return getMethodFamilyImpl(*this);
707 ObjCStringFormatFamily getStringFormatFamily() const {
708 return getStringFormatFamilyImpl(*this);
711 static Selector getEmptyMarker() {
712 return Selector(uintptr_t(-1));
714 static Selector getTombstoneMarker() {
715 return Selector(uintptr_t(-2));
718 static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
721 /// \brief This table allows us to fully hide how we implement
722 /// multi-keyword caching.
723 class SelectorTable {
724 void *Impl; // Actually a SelectorTableImpl
725 SelectorTable(const SelectorTable &) = delete;
726 void operator=(const SelectorTable &) = delete;
731 /// \brief Can create any sort of selector.
733 /// \p NumArgs indicates whether this is a no argument selector "foo", a
734 /// single argument selector "foo:" or multi-argument "foo:bar:".
735 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
737 Selector getUnarySelector(IdentifierInfo *ID) {
738 return Selector(ID, 1);
740 Selector getNullarySelector(IdentifierInfo *ID) {
741 return Selector(ID, 0);
744 /// \brief Return the total amount of memory allocated for managing selectors.
745 size_t getTotalMemory() const;
747 /// \brief Return the default setter name for the given identifier.
749 /// This is "set" + \p Name where the initial character of \p Name
750 /// has been capitalized.
751 static SmallString<64> constructSetterName(StringRef Name);
753 /// \brief Return the default setter selector for the given identifier.
755 /// This is "set" + \p Name where the initial character of \p Name
756 /// has been capitalized.
757 static Selector constructSetterSelector(IdentifierTable &Idents,
758 SelectorTable &SelTable,
759 const IdentifierInfo *Name);
762 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
763 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
764 /// private classes that describe different kinds of names.
765 class DeclarationNameExtra {
767 /// ExtraKind - The kind of "extra" information stored in the
768 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
769 /// how these enumerator values are used.
773 CXXConversionFunction,
774 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
776 #include "clang/Basic/OperatorKinds.def"
782 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
783 /// operator-id (if the value is one of the CXX* enumerators of
784 /// ExtraKind), in which case the DeclarationNameExtra is also a
785 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
786 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
787 /// it may be also name common to C++ using-directives (CXXUsingDirective),
788 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
789 /// arguments in the Objective-C selector, in which case the
790 /// DeclarationNameExtra is also a MultiKeywordSelector.
791 unsigned ExtraKindOrNumArgs;
794 } // end namespace clang
797 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
800 struct DenseMapInfo<clang::Selector> {
801 static inline clang::Selector getEmptyKey() {
802 return clang::Selector::getEmptyMarker();
804 static inline clang::Selector getTombstoneKey() {
805 return clang::Selector::getTombstoneMarker();
808 static unsigned getHashValue(clang::Selector S);
810 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
816 struct isPodLike<clang::Selector> { static const bool value = true; };
818 template <typename T> class PointerLikeTypeTraits;
821 class PointerLikeTypeTraits<clang::Selector> {
823 static inline const void *getAsVoidPointer(clang::Selector P) {
824 return P.getAsOpaquePtr();
826 static inline clang::Selector getFromVoidPointer(const void *P) {
827 return clang::Selector(reinterpret_cast<uintptr_t>(P));
829 enum { NumLowBitsAvailable = 0 };
832 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
833 // are not guaranteed to be 8-byte aligned.
835 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
837 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
840 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
841 return static_cast<clang::IdentifierInfo*>(P);
843 enum { NumLowBitsAvailable = 1 };
847 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
849 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
852 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
853 return static_cast<const clang::IdentifierInfo*>(P);
855 enum { NumLowBitsAvailable = 1 };
858 } // end namespace llvm