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;
169 void revertIdentifierToTokenID(tok::TokenKind TK) {
170 assert(TokenID == tok::identifier && "Should be at tok::identifier");
172 RevertedTokenID = false;
175 /// \brief Return the preprocessor keyword ID for this identifier.
177 /// For example, "define" will return tok::pp_define.
178 tok::PPKeywordKind getPPKeywordID() const;
180 /// \brief Return the Objective-C keyword ID for the this identifier.
182 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
183 tok::ObjCKeywordKind getObjCKeywordID() const {
184 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
185 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
187 return tok::objc_not_keyword;
189 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
191 /// \brief True if setNotBuiltin() was called.
192 bool hasRevertedBuiltin() const {
193 return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
196 /// \brief Revert the identifier to a non-builtin identifier. We do this if
197 /// the name of a known builtin library function is used to declare that
198 /// function, but an unexpected type is specified.
199 void revertBuiltin() {
203 /// \brief Return a value indicating whether this is a builtin function.
205 /// 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
206 /// 2+ are specific builtin functions.
207 unsigned getBuiltinID() const {
208 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
209 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
213 void setBuiltinID(unsigned ID) {
214 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
215 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
216 && "ID too large for field!");
219 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
220 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
222 /// get/setExtension - Initialize information about whether or not this
223 /// language token is an extension. This controls extension warnings, and is
224 /// only valid if a custom token ID is set.
225 bool isExtensionToken() const { return IsExtension; }
226 void setIsExtensionToken(bool Val) {
229 NeedsHandleIdentifier = 1;
231 RecomputeNeedsHandleIdentifier();
234 /// is/setIsFutureCompatKeyword - Initialize information about whether or not
235 /// this language token is a keyword in a newer or proposed Standard. This
236 /// controls compatibility warnings, and is only true when not parsing the
237 /// corresponding Standard. Once a compatibility problem has been diagnosed
238 /// with this keyword, the flag will be cleared.
239 bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
240 void setIsFutureCompatKeyword(bool Val) {
241 IsFutureCompatKeyword = Val;
243 NeedsHandleIdentifier = 1;
245 RecomputeNeedsHandleIdentifier();
248 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
249 /// Preprocessor will emit an error every time this token is used.
250 void setIsPoisoned(bool Value = true) {
253 NeedsHandleIdentifier = 1;
255 RecomputeNeedsHandleIdentifier();
258 /// \brief Return true if this token has been poisoned.
259 bool isPoisoned() const { return IsPoisoned; }
261 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
262 /// this identifier is a C++ alternate representation of an operator.
263 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
264 IsCPPOperatorKeyword = Val;
266 NeedsHandleIdentifier = 1;
268 RecomputeNeedsHandleIdentifier();
270 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
272 /// \brief Return true if this token is a keyword in the specified language.
273 bool isKeyword(const LangOptions &LangOpts);
275 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
276 /// associate arbitrary metadata with this token.
278 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
279 void setFETokenInfo(void *T) { FETokenInfo = T; }
281 /// \brief Return true if the Preprocessor::HandleIdentifier must be called
282 /// on a token of this identifier.
284 /// If this returns false, we know that HandleIdentifier will not affect
286 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
288 /// \brief Return true if the identifier in its current state was loaded
289 /// from an AST file.
290 bool isFromAST() const { return IsFromAST; }
292 void setIsFromAST() { IsFromAST = true; }
294 /// \brief Determine whether this identifier has changed since it was loaded
295 /// from an AST file.
296 bool hasChangedSinceDeserialization() const {
297 return ChangedAfterLoad;
300 /// \brief Note that this identifier has changed since it was loaded from
302 void setChangedSinceDeserialization() {
303 ChangedAfterLoad = true;
306 /// \brief Determine whether the information for this identifier is out of
307 /// date with respect to the external source.
308 bool isOutOfDate() const { return OutOfDate; }
310 /// \brief Set whether the information for this identifier is out of
311 /// date with respect to the external source.
312 void setOutOfDate(bool OOD) {
315 NeedsHandleIdentifier = true;
317 RecomputeNeedsHandleIdentifier();
320 /// \brief Determine whether this is the contextual keyword \c import.
321 bool isModulesImport() const { return IsModulesImport; }
323 /// \brief Set whether this identifier is the contextual keyword \c import.
324 void setModulesImport(bool I) {
327 NeedsHandleIdentifier = true;
329 RecomputeNeedsHandleIdentifier();
332 /// \brief Provide less than operator for lexicographical sorting.
333 bool operator<(const IdentifierInfo &RHS) const {
334 return getName() < RHS.getName();
338 /// The Preprocessor::HandleIdentifier does several special (but rare)
339 /// things to identifiers of various sorts. For example, it changes the
340 /// \c for keyword token from tok::identifier to tok::for.
342 /// This method is very tied to the definition of HandleIdentifier. Any
343 /// change to it should be reflected here.
344 void RecomputeNeedsHandleIdentifier() {
345 NeedsHandleIdentifier =
346 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
347 isExtensionToken() | isFutureCompatKeyword() || isOutOfDate() ||
352 /// \brief An RAII object for [un]poisoning an identifier within a scope.
354 /// \p II is allowed to be null, in which case objects of this type have
356 class PoisonIdentifierRAIIObject {
357 IdentifierInfo *const II;
360 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
361 : II(II), OldValue(II ? II->isPoisoned() : false) {
363 II->setIsPoisoned(NewValue);
366 ~PoisonIdentifierRAIIObject() {
368 II->setIsPoisoned(OldValue);
372 /// \brief An iterator that walks over all of the known identifiers
373 /// in the lookup table.
375 /// Since this iterator uses an abstract interface via virtual
376 /// functions, it uses an object-oriented interface rather than the
377 /// more standard C++ STL iterator interface. In this OO-style
378 /// iteration, the single function \c Next() provides dereference,
379 /// advance, and end-of-sequence checking in a single
380 /// operation. Subclasses of this iterator type will provide the
381 /// actual functionality.
382 class IdentifierIterator {
384 IdentifierIterator(const IdentifierIterator &) = delete;
385 void operator=(const IdentifierIterator &) = delete;
388 IdentifierIterator() { }
391 virtual ~IdentifierIterator();
393 /// \brief Retrieve the next string in the identifier table and
394 /// advances the iterator for the following string.
396 /// \returns The next string in the identifier table. If there is
397 /// no such string, returns an empty \c StringRef.
398 virtual StringRef Next() = 0;
401 /// \brief Provides lookups to, and iteration over, IdentiferInfo objects.
402 class IdentifierInfoLookup {
404 virtual ~IdentifierInfoLookup();
406 /// \brief Return the IdentifierInfo for the specified named identifier.
408 /// Unlike the version in IdentifierTable, this returns a pointer instead
409 /// of a reference. If the pointer is null then the IdentifierInfo cannot
411 virtual IdentifierInfo* get(StringRef Name) = 0;
413 /// \brief Retrieve an iterator into the set of all identifiers
414 /// known to this identifier lookup source.
416 /// This routine provides access to all of the identifiers known to
417 /// the identifier lookup, allowing access to the contents of the
418 /// identifiers without introducing the overhead of constructing
419 /// IdentifierInfo objects for each.
421 /// \returns A new iterator into the set of known identifiers. The
422 /// caller is responsible for deleting this iterator.
423 virtual IdentifierIterator *getIdentifiers();
426 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
428 /// This has no other purpose, but this is an extremely performance-critical
429 /// piece of the code, as each occurrence of every identifier goes through
431 class IdentifierTable {
432 // Shark shows that using MallocAllocator is *much* slower than using this
434 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
435 HashTableTy HashTable;
437 IdentifierInfoLookup* ExternalLookup;
440 /// \brief Create the identifier table, populating it with info about the
441 /// language keywords for the language specified by \p LangOpts.
442 IdentifierTable(const LangOptions &LangOpts,
443 IdentifierInfoLookup* externalLookup = nullptr);
445 /// \brief Set the external identifier lookup mechanism.
446 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
447 ExternalLookup = IILookup;
450 /// \brief Retrieve the external identifier lookup object, if any.
451 IdentifierInfoLookup *getExternalIdentifierLookup() const {
452 return ExternalLookup;
455 llvm::BumpPtrAllocator& getAllocator() {
456 return HashTable.getAllocator();
459 /// \brief Return the identifier token info for the specified named
461 IdentifierInfo &get(StringRef Name) {
462 auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
464 IdentifierInfo *&II = Entry.second;
467 // No entry; if we have an external lookup, look there first.
468 if (ExternalLookup) {
469 II = ExternalLookup->get(Name);
474 // Lookups failed, make a new IdentifierInfo.
475 void *Mem = getAllocator().Allocate<IdentifierInfo>();
476 II = new (Mem) IdentifierInfo();
478 // Make sure getName() knows how to find the IdentifierInfo
485 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
486 IdentifierInfo &II = get(Name);
487 II.TokenID = TokenCode;
488 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
492 /// \brief Gets an IdentifierInfo for the given name without consulting
493 /// external sources.
495 /// This is a version of get() meant for external sources that want to
496 /// introduce or modify an identifier. If they called get(), they would
497 /// likely end up in a recursion.
498 IdentifierInfo &getOwn(StringRef Name) {
499 auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
501 IdentifierInfo *&II = Entry.second;
505 // Lookups failed, make a new IdentifierInfo.
506 void *Mem = getAllocator().Allocate<IdentifierInfo>();
507 II = new (Mem) IdentifierInfo();
509 // Make sure getName() knows how to find the IdentifierInfo
513 // If this is the 'import' contextual keyword, mark it as such.
514 if (Name.equals("import"))
515 II->setModulesImport(true);
520 typedef HashTableTy::const_iterator iterator;
521 typedef HashTableTy::const_iterator const_iterator;
523 iterator begin() const { return HashTable.begin(); }
524 iterator end() const { return HashTable.end(); }
525 unsigned size() const { return HashTable.size(); }
527 /// \brief Print some statistics to stderr that indicate how well the
528 /// hashing is doing.
529 void PrintStats() const;
531 void AddKeywords(const LangOptions &LangOpts);
534 /// \brief A family of Objective-C methods.
536 /// These families have no inherent meaning in the language, but are
537 /// nonetheless central enough in the existing implementations to
538 /// merit direct AST support. While, in theory, arbitrary methods can
539 /// be considered to form families, we focus here on the methods
540 /// involving allocation and retain-count management, as these are the
541 /// most "core" and the most likely to be useful to diverse clients
542 /// without extra information.
544 /// Both selectors and actual method declarations may be classified
545 /// into families. Method families may impose additional restrictions
546 /// beyond their selector name; for example, a method called '_init'
547 /// that returns void is not considered to be in the 'init' family
548 /// (but would be if it returned 'id'). It is also possible to
549 /// explicitly change or remove a method's family. Therefore the
550 /// method's family should be considered the single source of truth.
551 enum ObjCMethodFamily {
552 /// \brief No particular method family.
555 // Selectors in these families may have arbitrary arity, may be
556 // written with arbitrary leading underscores, and may have
557 // additional CamelCase "words" in their first selector chunk
558 // following the family name.
565 // These families are singletons consisting only of the nullary
566 // selector with the given name.
576 // performSelector families
580 /// Enough bits to store any enumerator in ObjCMethodFamily or
581 /// InvalidObjCMethodFamily.
582 enum { ObjCMethodFamilyBitWidth = 4 };
584 /// \brief An invalid value of ObjCMethodFamily.
585 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
587 /// \brief A family of Objective-C methods.
589 /// These are family of methods whose result type is initially 'id', but
590 /// but are candidate for the result type to be changed to 'instancetype'.
591 enum ObjCInstanceTypeFamily {
600 enum ObjCStringFormatFamily {
606 /// \brief Smart pointer class that efficiently represents Objective-C method
609 /// This class will either point to an IdentifierInfo or a
610 /// MultiKeywordSelector (which is private). This enables us to optimize
611 /// selectors that take no arguments and selectors that take 1 argument, which
612 /// accounts for 78% of all selectors in Cocoa.h.
614 friend class Diagnostic;
616 enum IdentifierInfoFlag {
617 // Empty selector = 0.
621 ArgFlags = ZeroArg|OneArg
623 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
625 Selector(IdentifierInfo *II, unsigned nArgs) {
626 InfoPtr = reinterpret_cast<uintptr_t>(II);
627 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
628 assert(nArgs < 2 && "nArgs not equal to 0/1");
631 Selector(MultiKeywordSelector *SI) {
632 InfoPtr = reinterpret_cast<uintptr_t>(SI);
633 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
637 IdentifierInfo *getAsIdentifierInfo() const {
638 if (getIdentifierInfoFlag() < MultiArg)
639 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
642 MultiKeywordSelector *getMultiKeywordSelector() const {
643 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
646 unsigned getIdentifierInfoFlag() const {
647 return InfoPtr & ArgFlags;
650 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
652 static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
655 friend class SelectorTable; // only the SelectorTable can create these
656 friend class DeclarationName; // and the AST's DeclarationName.
658 /// The default ctor should only be used when creating data structures that
659 /// will contain selectors.
660 Selector() : InfoPtr(0) {}
661 Selector(uintptr_t V) : InfoPtr(V) {}
663 /// operator==/!= - Indicate whether the specified selectors are identical.
664 bool operator==(Selector RHS) const {
665 return InfoPtr == RHS.InfoPtr;
667 bool operator!=(Selector RHS) const {
668 return InfoPtr != RHS.InfoPtr;
670 void *getAsOpaquePtr() const {
671 return reinterpret_cast<void*>(InfoPtr);
674 /// \brief Determine whether this is the empty selector.
675 bool isNull() const { return InfoPtr == 0; }
677 // Predicates to identify the selector type.
678 bool isKeywordSelector() const {
679 return getIdentifierInfoFlag() != ZeroArg;
681 bool isUnarySelector() const {
682 return getIdentifierInfoFlag() == ZeroArg;
684 unsigned getNumArgs() const;
687 /// \brief Retrieve the identifier at a given position in the selector.
689 /// Note that the identifier pointer returned may be NULL. Clients that only
690 /// care about the text of the identifier string, and not the specific,
691 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
692 /// an empty string when the identifier pointer would be NULL.
694 /// \param argIndex The index for which we want to retrieve the identifier.
695 /// This index shall be less than \c getNumArgs() unless this is a keyword
696 /// selector, in which case 0 is the only permissible value.
698 /// \returns the uniqued identifier for this slot, or NULL if this slot has
699 /// no corresponding identifier.
700 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
702 /// \brief Retrieve the name at a given position in the selector.
704 /// \param argIndex The index for which we want to retrieve the name.
705 /// This index shall be less than \c getNumArgs() unless this is a keyword
706 /// selector, in which case 0 is the only permissible value.
708 /// \returns the name for this slot, which may be the empty string if no
709 /// name was supplied.
710 StringRef getNameForSlot(unsigned argIndex) const;
712 /// \brief Derive the full selector name (e.g. "foo:bar:") and return
713 /// it as an std::string.
714 std::string getAsString() const;
716 /// \brief Prints the full selector name (e.g. "foo:bar:").
717 void print(llvm::raw_ostream &OS) const;
719 /// \brief Derive the conventional family of this method.
720 ObjCMethodFamily getMethodFamily() const {
721 return getMethodFamilyImpl(*this);
724 ObjCStringFormatFamily getStringFormatFamily() const {
725 return getStringFormatFamilyImpl(*this);
728 static Selector getEmptyMarker() {
729 return Selector(uintptr_t(-1));
731 static Selector getTombstoneMarker() {
732 return Selector(uintptr_t(-2));
735 static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
738 /// \brief This table allows us to fully hide how we implement
739 /// multi-keyword caching.
740 class SelectorTable {
741 void *Impl; // Actually a SelectorTableImpl
742 SelectorTable(const SelectorTable &) = delete;
743 void operator=(const SelectorTable &) = delete;
748 /// \brief Can create any sort of selector.
750 /// \p NumArgs indicates whether this is a no argument selector "foo", a
751 /// single argument selector "foo:" or multi-argument "foo:bar:".
752 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
754 Selector getUnarySelector(IdentifierInfo *ID) {
755 return Selector(ID, 1);
757 Selector getNullarySelector(IdentifierInfo *ID) {
758 return Selector(ID, 0);
761 /// \brief Return the total amount of memory allocated for managing selectors.
762 size_t getTotalMemory() const;
764 /// \brief Return the default setter name for the given identifier.
766 /// This is "set" + \p Name where the initial character of \p Name
767 /// has been capitalized.
768 static SmallString<64> constructSetterName(StringRef Name);
770 /// \brief Return the default setter selector for the given identifier.
772 /// This is "set" + \p Name where the initial character of \p Name
773 /// has been capitalized.
774 static Selector constructSetterSelector(IdentifierTable &Idents,
775 SelectorTable &SelTable,
776 const IdentifierInfo *Name);
779 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
780 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
781 /// private classes that describe different kinds of names.
782 class DeclarationNameExtra {
784 /// ExtraKind - The kind of "extra" information stored in the
785 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
786 /// how these enumerator values are used.
790 CXXConversionFunction,
791 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
793 #include "clang/Basic/OperatorKinds.def"
799 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
800 /// operator-id (if the value is one of the CXX* enumerators of
801 /// ExtraKind), in which case the DeclarationNameExtra is also a
802 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
803 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
804 /// it may be also name common to C++ using-directives (CXXUsingDirective),
805 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
806 /// arguments in the Objective-C selector, in which case the
807 /// DeclarationNameExtra is also a MultiKeywordSelector.
808 unsigned ExtraKindOrNumArgs;
811 } // end namespace clang
814 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
817 struct DenseMapInfo<clang::Selector> {
818 static inline clang::Selector getEmptyKey() {
819 return clang::Selector::getEmptyMarker();
821 static inline clang::Selector getTombstoneKey() {
822 return clang::Selector::getTombstoneMarker();
825 static unsigned getHashValue(clang::Selector S);
827 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
833 struct isPodLike<clang::Selector> { static const bool value = true; };
835 template <typename T> class PointerLikeTypeTraits;
838 class PointerLikeTypeTraits<clang::Selector> {
840 static inline const void *getAsVoidPointer(clang::Selector P) {
841 return P.getAsOpaquePtr();
843 static inline clang::Selector getFromVoidPointer(const void *P) {
844 return clang::Selector(reinterpret_cast<uintptr_t>(P));
846 enum { NumLowBitsAvailable = 0 };
849 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
850 // are not guaranteed to be 8-byte aligned.
852 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
854 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
857 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
858 return static_cast<clang::IdentifierInfo*>(P);
860 enum { NumLowBitsAvailable = 1 };
864 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
866 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
869 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
870 return static_cast<const clang::IdentifierInfo*>(P);
872 enum { NumLowBitsAvailable = 1 };
875 } // end namespace llvm