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/OperatorKinds.h"
20 #include "clang/Basic/TokenKinds.h"
21 #include "clang/Basic/LLVM.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 {
149 void setHadMacroDefinition(bool Val) {
153 /// getTokenID - 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;
173 /// \brief Return the preprocessor keyword ID for this identifier.
175 /// For example, "define" will return tok::pp_define.
176 tok::PPKeywordKind getPPKeywordID() const;
178 /// \brief Return the Objective-C keyword ID for the this identifier.
180 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
181 tok::ObjCKeywordKind getObjCKeywordID() const {
182 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
183 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
185 return tok::objc_not_keyword;
187 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
189 /// getBuiltinID - Return a value indicating whether this is a builtin
190 /// function. 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
191 /// 2+ are specific builtin functions.
192 unsigned getBuiltinID() const {
193 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
194 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
198 void setBuiltinID(unsigned ID) {
199 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
200 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
201 && "ID too large for field!");
204 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
205 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
207 /// get/setExtension - Initialize information about whether or not this
208 /// language token is an extension. This controls extension warnings, and is
209 /// only valid if a custom token ID is set.
210 bool isExtensionToken() const { return IsExtension; }
211 void setIsExtensionToken(bool Val) {
214 NeedsHandleIdentifier = 1;
216 RecomputeNeedsHandleIdentifier();
219 /// is/setIsCXX11CompatKeyword - Initialize information about whether or not
220 /// this language token is a keyword in C++11. This controls compatibility
221 /// warnings, and is only true when not parsing C++11. Once a compatibility
222 /// problem has been diagnosed with this keyword, the flag will be cleared.
223 bool isCXX11CompatKeyword() const { return IsCXX11CompatKeyword; }
224 void setIsCXX11CompatKeyword(bool Val) {
225 IsCXX11CompatKeyword = Val;
227 NeedsHandleIdentifier = 1;
229 RecomputeNeedsHandleIdentifier();
232 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
233 /// Preprocessor will emit an error every time this token is used.
234 void setIsPoisoned(bool Value = true) {
237 NeedsHandleIdentifier = 1;
239 RecomputeNeedsHandleIdentifier();
242 /// isPoisoned - Return true if this token has been poisoned.
243 bool isPoisoned() const { return IsPoisoned; }
245 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
246 /// this identifier is a C++ alternate representation of an operator.
247 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
248 IsCPPOperatorKeyword = Val;
250 NeedsHandleIdentifier = 1;
252 RecomputeNeedsHandleIdentifier();
254 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
256 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
257 /// associate arbitrary metadata with this token.
259 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
260 void setFETokenInfo(void *T) { FETokenInfo = T; }
262 /// isHandleIdentifierCase - Return true if the Preprocessor::HandleIdentifier
263 /// must be called on a token of this identifier. If this returns false, we
264 /// know that HandleIdentifier will not affect the token.
265 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
267 /// isFromAST - Return true if the identifier in its current state was loaded
268 /// from an AST file.
269 bool isFromAST() const { return IsFromAST; }
271 void setIsFromAST() { IsFromAST = true; }
273 /// \brief Determine whether this identifier has changed since it was loaded
274 /// from an AST file.
275 bool hasChangedSinceDeserialization() const {
276 return ChangedAfterLoad;
279 /// \brief Note that this identifier has changed since it was loaded from
281 void setChangedSinceDeserialization() {
282 ChangedAfterLoad = true;
285 /// \brief Determine whether the information for this identifier is out of
286 /// date with respect to the external source.
287 bool isOutOfDate() const { return OutOfDate; }
289 /// \brief Set whether the information for this identifier is out of
290 /// date with respect to the external source.
291 void setOutOfDate(bool OOD) {
294 NeedsHandleIdentifier = true;
296 RecomputeNeedsHandleIdentifier();
299 /// \brief Determine whether this is the contextual keyword
300 /// '__experimental_modules_import'.
301 bool isModulesImport() const { return IsModulesImport; }
303 /// \brief Set whether this identifier is the contextual keyword
304 /// '__experimental_modules_import'.
305 void setModulesImport(bool I) {
308 NeedsHandleIdentifier = true;
310 RecomputeNeedsHandleIdentifier();
314 /// RecomputeNeedsHandleIdentifier - The Preprocessor::HandleIdentifier does
315 /// several special (but rare) things to identifiers of various sorts. For
316 /// example, it changes the "for" keyword token from tok::identifier to
319 /// This method is very tied to the definition of HandleIdentifier. Any
320 /// change to it should be reflected here.
321 void RecomputeNeedsHandleIdentifier() {
322 NeedsHandleIdentifier =
323 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
324 isExtensionToken() | isCXX11CompatKeyword() || isOutOfDate() ||
329 /// \brief an RAII object for [un]poisoning an identifier
330 /// within a certain scope. II is allowed to be null, in
331 /// which case, objects of this type have no effect.
332 class PoisonIdentifierRAIIObject {
333 IdentifierInfo *const II;
336 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
337 : II(II), OldValue(II ? II->isPoisoned() : false) {
339 II->setIsPoisoned(NewValue);
342 ~PoisonIdentifierRAIIObject() {
344 II->setIsPoisoned(OldValue);
348 /// \brief An iterator that walks over all of the known identifiers
349 /// in the lookup table.
351 /// Since this iterator uses an abstract interface via virtual
352 /// functions, it uses an object-oriented interface rather than the
353 /// more standard C++ STL iterator interface. In this OO-style
354 /// iteration, the single function \c Next() provides dereference,
355 /// advance, and end-of-sequence checking in a single
356 /// operation. Subclasses of this iterator type will provide the
357 /// actual functionality.
358 class IdentifierIterator {
360 IdentifierIterator(const IdentifierIterator &) LLVM_DELETED_FUNCTION;
361 void operator=(const IdentifierIterator &) LLVM_DELETED_FUNCTION;
364 IdentifierIterator() { }
367 virtual ~IdentifierIterator();
369 /// \brief Retrieve the next string in the identifier table and
370 /// advances the iterator for the following string.
372 /// \returns The next string in the identifier table. If there is
373 /// no such string, returns an empty \c StringRef.
374 virtual StringRef Next() = 0;
377 /// IdentifierInfoLookup - An abstract class used by IdentifierTable that
378 /// provides an interface for performing lookups from strings
379 /// (const char *) to IdentiferInfo objects.
380 class IdentifierInfoLookup {
382 virtual ~IdentifierInfoLookup();
384 /// get - Return the identifier token info for the specified named identifier.
385 /// Unlike the version in IdentifierTable, this returns a pointer instead
386 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot
388 virtual IdentifierInfo* get(StringRef Name) = 0;
390 /// \brief Retrieve an iterator into the set of all identifiers
391 /// known to this identifier lookup source.
393 /// This routine provides access to all of the identifiers known to
394 /// the identifier lookup, allowing access to the contents of the
395 /// identifiers without introducing the overhead of constructing
396 /// IdentifierInfo objects for each.
398 /// \returns A new iterator into the set of known identifiers. The
399 /// caller is responsible for deleting this iterator.
400 virtual IdentifierIterator *getIdentifiers() const;
403 /// \brief An abstract class used to resolve numerical identifier
404 /// references (meaningful only to some external source) into
405 /// IdentifierInfo pointers.
406 class ExternalIdentifierLookup {
408 virtual ~ExternalIdentifierLookup();
410 /// \brief Return the identifier associated with the given ID number.
412 /// The ID 0 is associated with the NULL identifier.
413 virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
416 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
418 /// This has no other purpose, but this is an extremely performance-critical
419 /// piece of the code, as each occurrence of every identifier goes through
421 class IdentifierTable {
422 // Shark shows that using MallocAllocator is *much* slower than using this
424 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
425 HashTableTy HashTable;
427 IdentifierInfoLookup* ExternalLookup;
430 /// \brief Create the identifier table, populating it with info about the
431 /// language keywords for the language specified by \p LangOpts.
432 IdentifierTable(const LangOptions &LangOpts,
433 IdentifierInfoLookup* externalLookup = 0);
435 /// \brief Set the external identifier lookup mechanism.
436 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
437 ExternalLookup = IILookup;
440 /// \brief Retrieve the external identifier lookup object, if any.
441 IdentifierInfoLookup *getExternalIdentifierLookup() const {
442 return ExternalLookup;
445 llvm::BumpPtrAllocator& getAllocator() {
446 return HashTable.getAllocator();
449 /// \brief Return the identifier token info for the specified named
451 IdentifierInfo &get(StringRef Name) {
452 llvm::StringMapEntry<IdentifierInfo*> &Entry =
453 HashTable.GetOrCreateValue(Name);
455 IdentifierInfo *II = Entry.getValue();
458 // No entry; if we have an external lookup, look there first.
459 if (ExternalLookup) {
460 II = ExternalLookup->get(Name);
462 // Cache in the StringMap for subsequent lookups.
468 // Lookups failed, make a new IdentifierInfo.
469 void *Mem = getAllocator().Allocate<IdentifierInfo>();
470 II = new (Mem) IdentifierInfo();
473 // Make sure getName() knows how to find the IdentifierInfo
480 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
481 IdentifierInfo &II = get(Name);
482 II.TokenID = TokenCode;
483 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
487 /// \brief Gets an IdentifierInfo for the given name without consulting
488 /// external sources.
490 /// This is a version of get() meant for external sources that want to
491 /// introduce or modify an identifier. If they called get(), they would
492 /// likely end up in a recursion.
493 IdentifierInfo &getOwn(StringRef Name) {
494 llvm::StringMapEntry<IdentifierInfo*> &Entry =
495 HashTable.GetOrCreateValue(Name);
497 IdentifierInfo *II = Entry.getValue();
500 // Lookups failed, make a new IdentifierInfo.
501 void *Mem = getAllocator().Allocate<IdentifierInfo>();
502 II = new (Mem) IdentifierInfo();
505 // Make sure getName() knows how to find the IdentifierInfo
509 // If this is the 'import' contextual keyword, mark it as such.
510 if (Name.equals("import"))
511 II->setModulesImport(true);
517 typedef HashTableTy::const_iterator iterator;
518 typedef HashTableTy::const_iterator const_iterator;
520 iterator begin() const { return HashTable.begin(); }
521 iterator end() const { return HashTable.end(); }
522 unsigned size() const { return HashTable.size(); }
524 /// \brief Print some statistics to stderr that indicate how well the
525 /// hashing is doing.
526 void PrintStats() const;
528 void AddKeywords(const LangOptions &LangOpts);
531 /// \brief A family of Objective-C methods.
533 /// These families have no inherent meaning in the language, but are
534 /// nonetheless central enough in the existing implementations to
535 /// merit direct AST support. While, in theory, arbitrary methods can
536 /// be considered to form families, we focus here on the methods
537 /// involving allocation and retain-count management, as these are the
538 /// most "core" and the most likely to be useful to diverse clients
539 /// without extra information.
541 /// Both selectors and actual method declarations may be classified
542 /// into families. Method families may impose additional restrictions
543 /// beyond their selector name; for example, a method called '_init'
544 /// that returns void is not considered to be in the 'init' family
545 /// (but would be if it returned 'id'). It is also possible to
546 /// explicitly change or remove a method's family. Therefore the
547 /// method's family should be considered the single source of truth.
548 enum ObjCMethodFamily {
549 /// \brief No particular method family.
552 // Selectors in these families may have arbitrary arity, may be
553 // written with arbitrary leading underscores, and may have
554 // additional CamelCase "words" in their first selector chunk
555 // following the family name.
562 // These families are singletons consisting only of the nullary
563 // selector with the given name.
572 // performSelector families
576 /// Enough bits to store any enumerator in ObjCMethodFamily or
577 /// InvalidObjCMethodFamily.
578 enum { ObjCMethodFamilyBitWidth = 4 };
580 /// \brief An invalid value of ObjCMethodFamily.
581 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
583 /// \brief Smart pointer class that efficiently represents Objective-C method
586 /// This class will either point to an IdentifierInfo or a
587 /// MultiKeywordSelector (which is private). This enables us to optimize
588 /// selectors that take no arguments and selectors that take 1 argument, which
589 /// accounts for 78% of all selectors in Cocoa.h.
591 friend class Diagnostic;
593 enum IdentifierInfoFlag {
594 // Empty selector = 0.
598 ArgFlags = ZeroArg|OneArg
600 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
602 Selector(IdentifierInfo *II, unsigned nArgs) {
603 InfoPtr = reinterpret_cast<uintptr_t>(II);
604 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
605 assert(nArgs < 2 && "nArgs not equal to 0/1");
608 Selector(MultiKeywordSelector *SI) {
609 InfoPtr = reinterpret_cast<uintptr_t>(SI);
610 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
614 IdentifierInfo *getAsIdentifierInfo() const {
615 if (getIdentifierInfoFlag() < MultiArg)
616 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
619 MultiKeywordSelector *getMultiKeywordSelector() const {
620 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
623 unsigned getIdentifierInfoFlag() const {
624 return InfoPtr & ArgFlags;
627 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
630 friend class SelectorTable; // only the SelectorTable can create these
631 friend class DeclarationName; // and the AST's DeclarationName.
633 /// The default ctor should only be used when creating data structures that
634 /// will contain selectors.
635 Selector() : InfoPtr(0) {}
636 Selector(uintptr_t V) : InfoPtr(V) {}
638 /// operator==/!= - Indicate whether the specified selectors are identical.
639 bool operator==(Selector RHS) const {
640 return InfoPtr == RHS.InfoPtr;
642 bool operator!=(Selector RHS) const {
643 return InfoPtr != RHS.InfoPtr;
645 void *getAsOpaquePtr() const {
646 return reinterpret_cast<void*>(InfoPtr);
649 /// \brief Determine whether this is the empty selector.
650 bool isNull() const { return InfoPtr == 0; }
652 // Predicates to identify the selector type.
653 bool isKeywordSelector() const {
654 return getIdentifierInfoFlag() != ZeroArg;
656 bool isUnarySelector() const {
657 return getIdentifierInfoFlag() == ZeroArg;
659 unsigned getNumArgs() const;
662 /// \brief Retrieve the identifier at a given position in the selector.
664 /// Note that the identifier pointer returned may be NULL. Clients that only
665 /// care about the text of the identifier string, and not the specific,
666 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
667 /// an empty string when the identifier pointer would be NULL.
669 /// \param argIndex The index for which we want to retrieve the identifier.
670 /// This index shall be less than \c getNumArgs() unless this is a keyword
671 /// selector, in which case 0 is the only permissible value.
673 /// \returns the uniqued identifier for this slot, or NULL if this slot has
674 /// no corresponding identifier.
675 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
677 /// \brief Retrieve the name at a given position in the selector.
679 /// \param argIndex The index for which we want to retrieve the name.
680 /// This index shall be less than \c getNumArgs() unless this is a keyword
681 /// selector, in which case 0 is the only permissible value.
683 /// \returns the name for this slot, which may be the empty string if no
684 /// name was supplied.
685 StringRef getNameForSlot(unsigned argIndex) const;
687 /// \brief Derive the full selector name (e.g. "foo:bar:") and return
688 /// it as an std::string.
689 // FIXME: Add a print method that uses a raw_ostream.
690 std::string getAsString() const;
692 /// \brief Derive the conventional family of this method.
693 ObjCMethodFamily getMethodFamily() const {
694 return getMethodFamilyImpl(*this);
697 static Selector getEmptyMarker() {
698 return Selector(uintptr_t(-1));
700 static Selector getTombstoneMarker() {
701 return Selector(uintptr_t(-2));
705 /// \brief This table allows us to fully hide how we implement
706 /// multi-keyword caching.
707 class SelectorTable {
708 void *Impl; // Actually a SelectorTableImpl
709 SelectorTable(const SelectorTable &) LLVM_DELETED_FUNCTION;
710 void operator=(const SelectorTable &) LLVM_DELETED_FUNCTION;
715 /// \brief Can create any sort of selector.
717 /// \p NumArgs indicates whether this is a no argument selector "foo", a
718 /// single argument selector "foo:" or multi-argument "foo:bar:".
719 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
721 Selector getUnarySelector(IdentifierInfo *ID) {
722 return Selector(ID, 1);
724 Selector getNullarySelector(IdentifierInfo *ID) {
725 return Selector(ID, 0);
728 /// \brief Return the total amount of memory allocated for managing selectors.
729 size_t getTotalMemory() const;
731 /// \brief Return the setter name for the given identifier.
733 /// This is "set" + \p Name where the initial character of \p Name
734 /// has been capitalized.
735 static Selector constructSetterName(IdentifierTable &Idents,
736 SelectorTable &SelTable,
737 const IdentifierInfo *Name);
740 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
741 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
742 /// private classes that describe different kinds of names.
743 class DeclarationNameExtra {
745 /// ExtraKind - The kind of "extra" information stored in the
746 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
747 /// how these enumerator values are used.
751 CXXConversionFunction,
752 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
754 #include "clang/Basic/OperatorKinds.def"
760 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
761 /// operator-id (if the value is one of the CXX* enumerators of
762 /// ExtraKind), in which case the DeclarationNameExtra is also a
763 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
764 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
765 /// it may be also name common to C++ using-directives (CXXUsingDirective),
766 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
767 /// arguments in the Objective-C selector, in which case the
768 /// DeclarationNameExtra is also a MultiKeywordSelector.
769 unsigned ExtraKindOrNumArgs;
772 } // end namespace clang
775 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
778 struct DenseMapInfo<clang::Selector> {
779 static inline clang::Selector getEmptyKey() {
780 return clang::Selector::getEmptyMarker();
782 static inline clang::Selector getTombstoneKey() {
783 return clang::Selector::getTombstoneMarker();
786 static unsigned getHashValue(clang::Selector S);
788 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
794 struct isPodLike<clang::Selector> { static const bool value = true; };
797 class PointerLikeTypeTraits<clang::Selector> {
799 static inline const void *getAsVoidPointer(clang::Selector P) {
800 return P.getAsOpaquePtr();
802 static inline clang::Selector getFromVoidPointer(const void *P) {
803 return clang::Selector(reinterpret_cast<uintptr_t>(P));
805 enum { NumLowBitsAvailable = 0 };
808 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
809 // are not guaranteed to be 8-byte aligned.
811 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
813 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
816 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
817 return static_cast<clang::IdentifierInfo*>(P);
819 enum { NumLowBitsAvailable = 1 };
823 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
825 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
828 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
829 return static_cast<const clang::IdentifierInfo*>(P);
831 enum { NumLowBitsAvailable = 1 };
834 } // end namespace llvm