1 //===--- IdentifierTable.h - Hash table for identifier lookup ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::IdentifierInfo, clang::IdentifierTable, and
12 /// clang::Selector interfaces.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
17 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/OperatorKinds.h"
21 #include "clang/Basic/TokenKinds.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/PointerLikeTypeTraits.h"
30 template <typename T> struct DenseMapInfo;
36 class IdentifierTable;
38 class MultiKeywordSelector; // private class used by Selector
39 class DeclarationName; // AST class that stores declaration names
41 /// \brief A simple pair of identifier info and location.
42 typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
45 /// One of these records is kept for each identifier that
46 /// is lexed. This contains information about whether the token was \#define'd,
47 /// is a language keyword, or if it is a front-end token of some sort (e.g. a
48 /// variable or function name). The preprocessor keeps this information in a
49 /// set, and all tok::identifier tokens have a pointer to one of these.
50 class IdentifierInfo {
51 unsigned TokenID : 9; // Front-end token ID or tok::identifier.
52 // Objective-C keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
53 // First NUM_OBJC_KEYWORDS values are for Objective-C, the remaining values
55 unsigned ObjCOrBuiltinID :11;
56 bool HasMacro : 1; // True if there is a #define for this.
57 bool HadMacro : 1; // True if there was a #define for this.
58 bool IsExtension : 1; // True if identifier is a lang extension.
59 bool IsCXX11CompatKeyword : 1; // True if identifier is a keyword in C++11.
60 bool IsPoisoned : 1; // True if identifier is poisoned.
61 bool IsCPPOperatorKeyword : 1; // True if ident is a C++ operator keyword.
62 bool NeedsHandleIdentifier : 1; // See "RecomputeNeedsHandleIdentifier".
63 bool IsFromAST : 1; // True if identifier was loaded (at least
64 // partially) from an AST file.
65 bool ChangedAfterLoad : 1; // True if identifier has changed from the
66 // definition loaded from an AST file.
67 bool RevertedTokenID : 1; // True if RevertTokenIDToIdentifier was
69 bool OutOfDate : 1; // True if there may be additional
70 // information about this identifier
72 bool IsModulesImport : 1; // True if this is the 'import' contextual
74 // 32-bit word is filled.
76 void *FETokenInfo; // Managed by the language front-end.
77 llvm::StringMapEntry<IdentifierInfo*> *Entry;
79 IdentifierInfo(const IdentifierInfo&) LLVM_DELETED_FUNCTION;
80 void operator=(const IdentifierInfo&) LLVM_DELETED_FUNCTION;
82 friend class IdentifierTable;
88 /// \brief Return true if this is the identifier for the specified string.
90 /// This is intended to be used for string literals only: II->isStr("foo").
91 template <std::size_t StrLen>
92 bool isStr(const char (&Str)[StrLen]) const {
93 return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1);
96 /// \brief Return the beginning of the actual null-terminated string for this
99 const char *getNameStart() const {
100 if (Entry) return Entry->getKeyData();
101 // FIXME: This is gross. It would be best not to embed specific details
102 // of the PTH file format here.
103 // The 'this' pointer really points to a
104 // std::pair<IdentifierInfo, const char*>, where internal pointer
105 // points to the external string data.
106 typedef std::pair<IdentifierInfo, const char*> actualtype;
107 return ((const actualtype*) this)->second;
110 /// \brief Efficiently return the length of this identifier info.
112 unsigned getLength() const {
113 if (Entry) return Entry->getKeyLength();
114 // FIXME: This is gross. It would be best not to embed specific details
115 // of the PTH file format here.
116 // The 'this' pointer really points to a
117 // std::pair<IdentifierInfo, const char*>, where internal pointer
118 // points to the external string data.
119 typedef std::pair<IdentifierInfo, const char*> actualtype;
120 const char* p = ((const actualtype*) this)->second - 2;
121 return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
124 /// \brief Return the actual identifier string.
125 StringRef getName() const {
126 return StringRef(getNameStart(), getLength());
129 /// \brief Return true if this identifier is \#defined to some other value.
130 bool hasMacroDefinition() const {
133 void setHasMacroDefinition(bool Val) {
134 if (HasMacro == Val) return;
138 NeedsHandleIdentifier = 1;
141 RecomputeNeedsHandleIdentifier();
144 /// \brief Returns true if this identifier was \#defined to some value at any
145 /// moment. In this case there should be an entry for the identifier in the
146 /// macro history table in Preprocessor.
147 bool hadMacroDefinition() const {
151 /// If this is a source-language token (e.g. 'for'), this API
152 /// can be used to cause the lexer to map identifiers to source-language
154 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
156 /// \brief True if RevertTokenIDToIdentifier() was called.
157 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
159 /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
162 /// TokenID is normally read-only but there are 2 instances where we revert it
163 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
164 /// using this method so we can inform serialization about it.
165 void RevertTokenIDToIdentifier() {
166 assert(TokenID != tok::identifier && "Already at tok::identifier");
167 TokenID = tok::identifier;
168 RevertedTokenID = true;
171 /// \brief Return the preprocessor keyword ID for this identifier.
173 /// For example, "define" will return tok::pp_define.
174 tok::PPKeywordKind getPPKeywordID() const;
176 /// \brief Return the Objective-C keyword ID for the this identifier.
178 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
179 tok::ObjCKeywordKind getObjCKeywordID() const {
180 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
181 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
183 return tok::objc_not_keyword;
185 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
187 /// \brief Return a value indicating whether this is a builtin function.
189 /// 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
190 /// 2+ are specific builtin functions.
191 unsigned getBuiltinID() const {
192 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
193 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
197 void setBuiltinID(unsigned ID) {
198 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
199 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
200 && "ID too large for field!");
203 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
204 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
206 /// get/setExtension - Initialize information about whether or not this
207 /// language token is an extension. This controls extension warnings, and is
208 /// only valid if a custom token ID is set.
209 bool isExtensionToken() const { return IsExtension; }
210 void setIsExtensionToken(bool Val) {
213 NeedsHandleIdentifier = 1;
215 RecomputeNeedsHandleIdentifier();
218 /// is/setIsCXX11CompatKeyword - Initialize information about whether or not
219 /// this language token is a keyword in C++11. This controls compatibility
220 /// warnings, and is only true when not parsing C++11. Once a compatibility
221 /// problem has been diagnosed with this keyword, the flag will be cleared.
222 bool isCXX11CompatKeyword() const { return IsCXX11CompatKeyword; }
223 void setIsCXX11CompatKeyword(bool Val) {
224 IsCXX11CompatKeyword = 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 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
256 /// associate arbitrary metadata with this token.
258 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
259 void setFETokenInfo(void *T) { FETokenInfo = T; }
261 /// \brief Return true if the Preprocessor::HandleIdentifier must be called
262 /// on a token of this identifier.
264 /// If this returns false, we know that HandleIdentifier will not affect
266 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
268 /// \brief Return true if the identifier in its current state was loaded
269 /// from an AST file.
270 bool isFromAST() const { return IsFromAST; }
272 void setIsFromAST() { IsFromAST = true; }
274 /// \brief Determine whether this identifier has changed since it was loaded
275 /// from an AST file.
276 bool hasChangedSinceDeserialization() const {
277 return ChangedAfterLoad;
280 /// \brief Note that this identifier has changed since it was loaded from
282 void setChangedSinceDeserialization() {
283 ChangedAfterLoad = true;
286 /// \brief Determine whether the information for this identifier is out of
287 /// date with respect to the external source.
288 bool isOutOfDate() const { return OutOfDate; }
290 /// \brief Set whether the information for this identifier is out of
291 /// date with respect to the external source.
292 void setOutOfDate(bool OOD) {
295 NeedsHandleIdentifier = true;
297 RecomputeNeedsHandleIdentifier();
300 /// \brief Determine whether this is the contextual keyword \c import.
301 bool isModulesImport() const { return IsModulesImport; }
303 /// \brief Set whether this identifier is the contextual keyword \c import.
304 void setModulesImport(bool I) {
307 NeedsHandleIdentifier = true;
309 RecomputeNeedsHandleIdentifier();
313 /// The Preprocessor::HandleIdentifier does several special (but rare)
314 /// things to identifiers of various sorts. For example, it changes the
315 /// \c for keyword token from tok::identifier to tok::for.
317 /// This method is very tied to the definition of HandleIdentifier. Any
318 /// change to it should be reflected here.
319 void RecomputeNeedsHandleIdentifier() {
320 NeedsHandleIdentifier =
321 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
322 isExtensionToken() | isCXX11CompatKeyword() || isOutOfDate() ||
327 /// \brief An RAII object for [un]poisoning an identifier within a scope.
329 /// \p II is allowed to be null, in which case objects of this type have
331 class PoisonIdentifierRAIIObject {
332 IdentifierInfo *const II;
335 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
336 : II(II), OldValue(II ? II->isPoisoned() : false) {
338 II->setIsPoisoned(NewValue);
341 ~PoisonIdentifierRAIIObject() {
343 II->setIsPoisoned(OldValue);
347 /// \brief An iterator that walks over all of the known identifiers
348 /// in the lookup table.
350 /// Since this iterator uses an abstract interface via virtual
351 /// functions, it uses an object-oriented interface rather than the
352 /// more standard C++ STL iterator interface. In this OO-style
353 /// iteration, the single function \c Next() provides dereference,
354 /// advance, and end-of-sequence checking in a single
355 /// operation. Subclasses of this iterator type will provide the
356 /// actual functionality.
357 class IdentifierIterator {
359 IdentifierIterator(const IdentifierIterator &) LLVM_DELETED_FUNCTION;
360 void operator=(const IdentifierIterator &) LLVM_DELETED_FUNCTION;
363 IdentifierIterator() { }
366 virtual ~IdentifierIterator();
368 /// \brief Retrieve the next string in the identifier table and
369 /// advances the iterator for the following string.
371 /// \returns The next string in the identifier table. If there is
372 /// no such string, returns an empty \c StringRef.
373 virtual StringRef Next() = 0;
376 /// \brief Provides lookups to, and iteration over, IdentiferInfo objects.
377 class IdentifierInfoLookup {
379 virtual ~IdentifierInfoLookup();
381 /// \brief Return the IdentifierInfo for the specified named identifier.
383 /// Unlike the version in IdentifierTable, this returns a pointer instead
384 /// of a reference. If the pointer is null then the IdentifierInfo cannot
386 virtual IdentifierInfo* get(StringRef Name) = 0;
388 /// \brief Retrieve an iterator into the set of all identifiers
389 /// known to this identifier lookup source.
391 /// This routine provides access to all of the identifiers known to
392 /// the identifier lookup, allowing access to the contents of the
393 /// identifiers without introducing the overhead of constructing
394 /// IdentifierInfo objects for each.
396 /// \returns A new iterator into the set of known identifiers. The
397 /// caller is responsible for deleting this iterator.
398 virtual IdentifierIterator *getIdentifiers();
401 /// \brief An abstract class used to resolve numerical identifier
402 /// references (meaningful only to some external source) into
403 /// IdentifierInfo pointers.
404 class ExternalIdentifierLookup {
406 virtual ~ExternalIdentifierLookup();
408 /// \brief Return the identifier associated with the given ID number.
410 /// The ID 0 is associated with the NULL identifier.
411 virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
414 /// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
416 /// This has no other purpose, but this is an extremely performance-critical
417 /// piece of the code, as each occurrence of every identifier goes through
419 class IdentifierTable {
420 // Shark shows that using MallocAllocator is *much* slower than using this
422 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
423 HashTableTy HashTable;
425 IdentifierInfoLookup* ExternalLookup;
428 /// \brief Create the identifier table, populating it with info about the
429 /// language keywords for the language specified by \p LangOpts.
430 IdentifierTable(const LangOptions &LangOpts,
431 IdentifierInfoLookup* externalLookup = 0);
433 /// \brief Set the external identifier lookup mechanism.
434 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
435 ExternalLookup = IILookup;
438 /// \brief Retrieve the external identifier lookup object, if any.
439 IdentifierInfoLookup *getExternalIdentifierLookup() const {
440 return ExternalLookup;
443 llvm::BumpPtrAllocator& getAllocator() {
444 return HashTable.getAllocator();
447 /// \brief Return the identifier token info for the specified named
449 IdentifierInfo &get(StringRef Name) {
450 llvm::StringMapEntry<IdentifierInfo*> &Entry =
451 HashTable.GetOrCreateValue(Name);
453 IdentifierInfo *II = Entry.getValue();
456 // No entry; if we have an external lookup, look there first.
457 if (ExternalLookup) {
458 II = ExternalLookup->get(Name);
460 // Cache in the StringMap for subsequent lookups.
466 // Lookups failed, make a new IdentifierInfo.
467 void *Mem = getAllocator().Allocate<IdentifierInfo>();
468 II = new (Mem) IdentifierInfo();
471 // Make sure getName() knows how to find the IdentifierInfo
478 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
479 IdentifierInfo &II = get(Name);
480 II.TokenID = TokenCode;
481 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
485 /// \brief Gets an IdentifierInfo for the given name without consulting
486 /// external sources.
488 /// This is a version of get() meant for external sources that want to
489 /// introduce or modify an identifier. If they called get(), they would
490 /// likely end up in a recursion.
491 IdentifierInfo &getOwn(StringRef Name) {
492 llvm::StringMapEntry<IdentifierInfo*> &Entry =
493 HashTable.GetOrCreateValue(Name);
495 IdentifierInfo *II = Entry.getValue();
498 // Lookups failed, make a new IdentifierInfo.
499 void *Mem = getAllocator().Allocate<IdentifierInfo>();
500 II = new (Mem) IdentifierInfo();
503 // Make sure getName() knows how to find the IdentifierInfo
507 // If this is the 'import' contextual keyword, mark it as such.
508 if (Name.equals("import"))
509 II->setModulesImport(true);
515 typedef HashTableTy::const_iterator iterator;
516 typedef HashTableTy::const_iterator const_iterator;
518 iterator begin() const { return HashTable.begin(); }
519 iterator end() const { return HashTable.end(); }
520 unsigned size() const { return HashTable.size(); }
522 /// \brief Print some statistics to stderr that indicate how well the
523 /// hashing is doing.
524 void PrintStats() const;
526 void AddKeywords(const LangOptions &LangOpts);
529 /// \brief A family of Objective-C methods.
531 /// These families have no inherent meaning in the language, but are
532 /// nonetheless central enough in the existing implementations to
533 /// merit direct AST support. While, in theory, arbitrary methods can
534 /// be considered to form families, we focus here on the methods
535 /// involving allocation and retain-count management, as these are the
536 /// most "core" and the most likely to be useful to diverse clients
537 /// without extra information.
539 /// Both selectors and actual method declarations may be classified
540 /// into families. Method families may impose additional restrictions
541 /// beyond their selector name; for example, a method called '_init'
542 /// that returns void is not considered to be in the 'init' family
543 /// (but would be if it returned 'id'). It is also possible to
544 /// explicitly change or remove a method's family. Therefore the
545 /// method's family should be considered the single source of truth.
546 enum ObjCMethodFamily {
547 /// \brief No particular method family.
550 // Selectors in these families may have arbitrary arity, may be
551 // written with arbitrary leading underscores, and may have
552 // additional CamelCase "words" in their first selector chunk
553 // following the family name.
560 // These families are singletons consisting only of the nullary
561 // selector with the given name.
570 // performSelector families
574 /// Enough bits to store any enumerator in ObjCMethodFamily or
575 /// InvalidObjCMethodFamily.
576 enum { ObjCMethodFamilyBitWidth = 4 };
578 /// \brief An invalid value of ObjCMethodFamily.
579 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
581 /// \brief A family of Objective-C methods.
583 /// These are family of methods whose result type is initially 'id', but
584 /// but are candidate for the result type to be changed to 'instancetype'.
585 enum ObjCInstanceTypeFamily {
594 /// \brief Smart pointer class that efficiently represents Objective-C method
597 /// This class will either point to an IdentifierInfo or a
598 /// MultiKeywordSelector (which is private). This enables us to optimize
599 /// selectors that take no arguments and selectors that take 1 argument, which
600 /// accounts for 78% of all selectors in Cocoa.h.
602 friend class Diagnostic;
604 enum IdentifierInfoFlag {
605 // Empty selector = 0.
609 ArgFlags = ZeroArg|OneArg
611 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
613 Selector(IdentifierInfo *II, unsigned nArgs) {
614 InfoPtr = reinterpret_cast<uintptr_t>(II);
615 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
616 assert(nArgs < 2 && "nArgs not equal to 0/1");
619 Selector(MultiKeywordSelector *SI) {
620 InfoPtr = reinterpret_cast<uintptr_t>(SI);
621 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
625 IdentifierInfo *getAsIdentifierInfo() const {
626 if (getIdentifierInfoFlag() < MultiArg)
627 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
630 MultiKeywordSelector *getMultiKeywordSelector() const {
631 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
634 unsigned getIdentifierInfoFlag() const {
635 return InfoPtr & ArgFlags;
638 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
641 friend class SelectorTable; // only the SelectorTable can create these
642 friend class DeclarationName; // and the AST's DeclarationName.
644 /// The default ctor should only be used when creating data structures that
645 /// will contain selectors.
646 Selector() : InfoPtr(0) {}
647 Selector(uintptr_t V) : InfoPtr(V) {}
649 /// operator==/!= - Indicate whether the specified selectors are identical.
650 bool operator==(Selector RHS) const {
651 return InfoPtr == RHS.InfoPtr;
653 bool operator!=(Selector RHS) const {
654 return InfoPtr != RHS.InfoPtr;
656 void *getAsOpaquePtr() const {
657 return reinterpret_cast<void*>(InfoPtr);
660 /// \brief Determine whether this is the empty selector.
661 bool isNull() const { return InfoPtr == 0; }
663 // Predicates to identify the selector type.
664 bool isKeywordSelector() const {
665 return getIdentifierInfoFlag() != ZeroArg;
667 bool isUnarySelector() const {
668 return getIdentifierInfoFlag() == ZeroArg;
670 unsigned getNumArgs() const;
673 /// \brief Retrieve the identifier at a given position in the selector.
675 /// Note that the identifier pointer returned may be NULL. Clients that only
676 /// care about the text of the identifier string, and not the specific,
677 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
678 /// an empty string when the identifier pointer would be NULL.
680 /// \param argIndex The index for which we want to retrieve the identifier.
681 /// This index shall be less than \c getNumArgs() unless this is a keyword
682 /// selector, in which case 0 is the only permissible value.
684 /// \returns the uniqued identifier for this slot, or NULL if this slot has
685 /// no corresponding identifier.
686 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
688 /// \brief Retrieve the name at a given position in the selector.
690 /// \param argIndex The index for which we want to retrieve the name.
691 /// This index shall be less than \c getNumArgs() unless this is a keyword
692 /// selector, in which case 0 is the only permissible value.
694 /// \returns the name for this slot, which may be the empty string if no
695 /// name was supplied.
696 StringRef getNameForSlot(unsigned argIndex) const;
698 /// \brief Derive the full selector name (e.g. "foo:bar:") and return
699 /// it as an std::string.
700 // FIXME: Add a print method that uses a raw_ostream.
701 std::string getAsString() const;
703 /// \brief Derive the conventional family of this method.
704 ObjCMethodFamily getMethodFamily() const {
705 return getMethodFamilyImpl(*this);
708 static Selector getEmptyMarker() {
709 return Selector(uintptr_t(-1));
711 static Selector getTombstoneMarker() {
712 return Selector(uintptr_t(-2));
715 static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
718 /// \brief This table allows us to fully hide how we implement
719 /// multi-keyword caching.
720 class SelectorTable {
721 void *Impl; // Actually a SelectorTableImpl
722 SelectorTable(const SelectorTable &) LLVM_DELETED_FUNCTION;
723 void operator=(const SelectorTable &) LLVM_DELETED_FUNCTION;
728 /// \brief Can create any sort of selector.
730 /// \p NumArgs indicates whether this is a no argument selector "foo", a
731 /// single argument selector "foo:" or multi-argument "foo:bar:".
732 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
734 Selector getUnarySelector(IdentifierInfo *ID) {
735 return Selector(ID, 1);
737 Selector getNullarySelector(IdentifierInfo *ID) {
738 return Selector(ID, 0);
741 /// \brief Return the total amount of memory allocated for managing selectors.
742 size_t getTotalMemory() const;
744 /// \brief Return the default setter name for the given identifier.
746 /// This is "set" + \p Name where the initial character of \p Name
747 /// has been capitalized.
748 static SmallString<64> constructSetterName(StringRef Name);
750 /// \brief Return the default setter selector for the given identifier.
752 /// This is "set" + \p Name where the initial character of \p Name
753 /// has been capitalized.
754 static Selector constructSetterSelector(IdentifierTable &Idents,
755 SelectorTable &SelTable,
756 const IdentifierInfo *Name);
759 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
760 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
761 /// private classes that describe different kinds of names.
762 class DeclarationNameExtra {
764 /// ExtraKind - The kind of "extra" information stored in the
765 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
766 /// how these enumerator values are used.
770 CXXConversionFunction,
771 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
773 #include "clang/Basic/OperatorKinds.def"
779 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
780 /// operator-id (if the value is one of the CXX* enumerators of
781 /// ExtraKind), in which case the DeclarationNameExtra is also a
782 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
783 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
784 /// it may be also name common to C++ using-directives (CXXUsingDirective),
785 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
786 /// arguments in the Objective-C selector, in which case the
787 /// DeclarationNameExtra is also a MultiKeywordSelector.
788 unsigned ExtraKindOrNumArgs;
791 } // end namespace clang
794 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
797 struct DenseMapInfo<clang::Selector> {
798 static inline clang::Selector getEmptyKey() {
799 return clang::Selector::getEmptyMarker();
801 static inline clang::Selector getTombstoneKey() {
802 return clang::Selector::getTombstoneMarker();
805 static unsigned getHashValue(clang::Selector S);
807 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
813 struct isPodLike<clang::Selector> { static const bool value = true; };
816 class PointerLikeTypeTraits<clang::Selector> {
818 static inline const void *getAsVoidPointer(clang::Selector P) {
819 return P.getAsOpaquePtr();
821 static inline clang::Selector getFromVoidPointer(const void *P) {
822 return clang::Selector(reinterpret_cast<uintptr_t>(P));
824 enum { NumLowBitsAvailable = 0 };
827 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
828 // are not guaranteed to be 8-byte aligned.
830 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
832 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
835 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
836 return static_cast<clang::IdentifierInfo*>(P);
838 enum { NumLowBitsAvailable = 1 };
842 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
844 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
847 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
848 return static_cast<const clang::IdentifierInfo*>(P);
850 enum { NumLowBitsAvailable = 1 };
853 } // end namespace llvm