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 //===----------------------------------------------------------------------===//
10 // This file defines the IdentifierInfo, IdentifierTable, and Selector
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
18 #include "clang/Basic/OperatorKinds.h"
19 #include "clang/Basic/TokenKinds.h"
20 #include "clang/Basic/LLVM.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/OwningPtr.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 /// IdentifierLocPair - A simple pair of identifier info and location.
41 typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
44 /// IdentifierInfo - 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 IsExtension : 1; // True if identifier is a lang extension.
57 bool IsCXX11CompatKeyword : 1; // True if identifier is a keyword in C++11.
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 // 1 bit left in 32-bit word.
74 void *FETokenInfo; // Managed by the language front-end.
75 llvm::StringMapEntry<IdentifierInfo*> *Entry;
77 IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE.
78 void operator=(const IdentifierInfo&); // NONASSIGNABLE.
80 friend class IdentifierTable;
86 /// isStr - Return true if this is the identifier for the specified string.
87 /// This is intended to be used for string literals only: II->isStr("foo").
88 template <std::size_t StrLen>
89 bool isStr(const char (&Str)[StrLen]) const {
90 return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1);
93 /// getNameStart - Return the beginning of the actual string for this
94 /// identifier. The returned string is properly null terminated.
96 const char *getNameStart() const {
97 if (Entry) return Entry->getKeyData();
98 // FIXME: This is gross. It would be best not to embed specific details
99 // of the PTH file format here.
100 // The 'this' pointer really points to a
101 // std::pair<IdentifierInfo, const char*>, where internal pointer
102 // points to the external string data.
103 typedef std::pair<IdentifierInfo, const char*> actualtype;
104 return ((const actualtype*) this)->second;
107 /// getLength - Efficiently return the length of this identifier info.
109 unsigned getLength() const {
110 if (Entry) return Entry->getKeyLength();
111 // FIXME: This is gross. It would be best not to embed specific details
112 // of the PTH file format here.
113 // The 'this' pointer really points to a
114 // std::pair<IdentifierInfo, const char*>, where internal pointer
115 // points to the external string data.
116 typedef std::pair<IdentifierInfo, const char*> actualtype;
117 const char* p = ((const actualtype*) this)->second - 2;
118 return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
121 /// getName - Return the actual identifier string.
122 StringRef getName() const {
123 return StringRef(getNameStart(), getLength());
126 /// hasMacroDefinition - Return true if this identifier is #defined to some
128 bool hasMacroDefinition() const {
131 void setHasMacroDefinition(bool Val) {
132 if (HasMacro == Val) return;
136 NeedsHandleIdentifier = 1;
138 RecomputeNeedsHandleIdentifier();
141 /// getTokenID - If this is a source-language token (e.g. 'for'), this API
142 /// can be used to cause the lexer to map identifiers to source-language
144 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
146 /// \brief True if RevertTokenIDToIdentifier() was called.
147 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
149 /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
152 /// TokenID is normally read-only but there are 2 instances where we revert it
153 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
154 /// using this method so we can inform serialization about it.
155 void RevertTokenIDToIdentifier() {
156 assert(TokenID != tok::identifier && "Already at tok::identifier");
157 TokenID = tok::identifier;
158 RevertedTokenID = true;
161 /// getPPKeywordID - Return the preprocessor keyword ID for this identifier.
162 /// For example, "define" will return tok::pp_define.
163 tok::PPKeywordKind getPPKeywordID() const;
165 /// getObjCKeywordID - Return the Objective-C keyword ID for the this
166 /// identifier. For example, 'class' will return tok::objc_class if ObjC is
168 tok::ObjCKeywordKind getObjCKeywordID() const {
169 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
170 return tok::ObjCKeywordKind(ObjCOrBuiltinID);
172 return tok::objc_not_keyword;
174 void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
176 /// getBuiltinID - Return a value indicating whether this is a builtin
177 /// function. 0 is not-built-in. 1 is builtin-for-some-nonprimary-target.
178 /// 2+ are specific builtin functions.
179 unsigned getBuiltinID() const {
180 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
181 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
185 void setBuiltinID(unsigned ID) {
186 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
187 assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
188 && "ID too large for field!");
191 unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
192 void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
194 /// get/setExtension - Initialize information about whether or not this
195 /// language token is an extension. This controls extension warnings, and is
196 /// only valid if a custom token ID is set.
197 bool isExtensionToken() const { return IsExtension; }
198 void setIsExtensionToken(bool Val) {
201 NeedsHandleIdentifier = 1;
203 RecomputeNeedsHandleIdentifier();
206 /// is/setIsCXX11CompatKeyword - Initialize information about whether or not
207 /// this language token is a keyword in C++11. This controls compatibility
208 /// warnings, and is only true when not parsing C++11. Once a compatibility
209 /// problem has been diagnosed with this keyword, the flag will be cleared.
210 bool isCXX11CompatKeyword() const { return IsCXX11CompatKeyword; }
211 void setIsCXX11CompatKeyword(bool Val) {
212 IsCXX11CompatKeyword = Val;
214 NeedsHandleIdentifier = 1;
216 RecomputeNeedsHandleIdentifier();
219 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
220 /// Preprocessor will emit an error every time this token is used.
221 void setIsPoisoned(bool Value = true) {
224 NeedsHandleIdentifier = 1;
226 RecomputeNeedsHandleIdentifier();
229 /// isPoisoned - Return true if this token has been poisoned.
230 bool isPoisoned() const { return IsPoisoned; }
232 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
233 /// this identifier is a C++ alternate representation of an operator.
234 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
235 IsCPPOperatorKeyword = Val;
237 NeedsHandleIdentifier = 1;
239 RecomputeNeedsHandleIdentifier();
241 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
243 /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
244 /// associate arbitrary metadata with this token.
246 T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
247 void setFETokenInfo(void *T) { FETokenInfo = T; }
249 /// isHandleIdentifierCase - Return true if the Preprocessor::HandleIdentifier
250 /// must be called on a token of this identifier. If this returns false, we
251 /// know that HandleIdentifier will not affect the token.
252 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
254 /// isFromAST - Return true if the identifier in its current state was loaded
255 /// from an AST file.
256 bool isFromAST() const { return IsFromAST; }
258 void setIsFromAST() { IsFromAST = true; }
260 /// \brief Determine whether this identifier has changed since it was loaded
261 /// from an AST file.
262 bool hasChangedSinceDeserialization() const {
263 return ChangedAfterLoad;
266 /// \brief Note that this identifier has changed since it was loaded from
268 void setChangedSinceDeserialization() {
269 ChangedAfterLoad = true;
272 /// \brief Determine whether the information for this identifier is out of
273 /// date with respect to the external source.
274 bool isOutOfDate() const { return OutOfDate; }
276 /// \brief Set whether the information for this identifier is out of
277 /// date with respect to the external source.
278 void setOutOfDate(bool OOD) {
281 NeedsHandleIdentifier = true;
283 RecomputeNeedsHandleIdentifier();
286 /// \brief Determine whether this is the contextual keyword
287 /// '__experimental_modules_import'.
288 bool isModulesImport() const { return IsModulesImport; }
290 /// \brief Set whether this identifier is the contextual keyword
291 /// '__experimental_modules_import'.
292 void setModulesImport(bool I) {
295 NeedsHandleIdentifier = true;
297 RecomputeNeedsHandleIdentifier();
301 /// RecomputeNeedsHandleIdentifier - The Preprocessor::HandleIdentifier does
302 /// several special (but rare) things to identifiers of various sorts. For
303 /// example, it changes the "for" keyword token from tok::identifier to
306 /// This method is very tied to the definition of HandleIdentifier. Any
307 /// change to it should be reflected here.
308 void RecomputeNeedsHandleIdentifier() {
309 NeedsHandleIdentifier =
310 (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
311 isExtensionToken() | isCXX11CompatKeyword() || isOutOfDate() ||
316 /// \brief an RAII object for [un]poisoning an identifier
317 /// within a certain scope. II is allowed to be null, in
318 /// which case, objects of this type have no effect.
319 class PoisonIdentifierRAIIObject {
320 IdentifierInfo *const II;
323 PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
324 : II(II), OldValue(II ? II->isPoisoned() : false) {
326 II->setIsPoisoned(NewValue);
329 ~PoisonIdentifierRAIIObject() {
331 II->setIsPoisoned(OldValue);
335 /// \brief An iterator that walks over all of the known identifiers
336 /// in the lookup table.
338 /// Since this iterator uses an abstract interface via virtual
339 /// functions, it uses an object-oriented interface rather than the
340 /// more standard C++ STL iterator interface. In this OO-style
341 /// iteration, the single function \c Next() provides dereference,
342 /// advance, and end-of-sequence checking in a single
343 /// operation. Subclasses of this iterator type will provide the
344 /// actual functionality.
345 class IdentifierIterator {
347 IdentifierIterator(const IdentifierIterator&); // Do not implement
348 IdentifierIterator &operator=(const IdentifierIterator&); // Do not implement
351 IdentifierIterator() { }
354 virtual ~IdentifierIterator();
356 /// \brief Retrieve the next string in the identifier table and
357 /// advances the iterator for the following string.
359 /// \returns The next string in the identifier table. If there is
360 /// no such string, returns an empty \c StringRef.
361 virtual StringRef Next() = 0;
364 /// IdentifierInfoLookup - An abstract class used by IdentifierTable that
365 /// provides an interface for performing lookups from strings
366 /// (const char *) to IdentiferInfo objects.
367 class IdentifierInfoLookup {
369 virtual ~IdentifierInfoLookup();
371 /// get - Return the identifier token info for the specified named identifier.
372 /// Unlike the version in IdentifierTable, this returns a pointer instead
373 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot
375 virtual IdentifierInfo* get(StringRef Name) = 0;
377 /// \brief Retrieve an iterator into the set of all identifiers
378 /// known to this identifier lookup source.
380 /// This routine provides access to all of the identifiers known to
381 /// the identifier lookup, allowing access to the contents of the
382 /// identifiers without introducing the overhead of constructing
383 /// IdentifierInfo objects for each.
385 /// \returns A new iterator into the set of known identifiers. The
386 /// caller is responsible for deleting this iterator.
387 virtual IdentifierIterator *getIdentifiers() const;
390 /// \brief An abstract class used to resolve numerical identifier
391 /// references (meaningful only to some external source) into
392 /// IdentifierInfo pointers.
393 class ExternalIdentifierLookup {
395 virtual ~ExternalIdentifierLookup();
397 /// \brief Return the identifier associated with the given ID number.
399 /// The ID 0 is associated with the NULL identifier.
400 virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
403 /// IdentifierTable - This table implements an efficient mapping from strings to
404 /// IdentifierInfo nodes. It has no other purpose, but this is an
405 /// extremely performance-critical piece of the code, as each occurrence of
406 /// every identifier goes through here when lexed.
407 class IdentifierTable {
408 // Shark shows that using MallocAllocator is *much* slower than using this
410 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
411 HashTableTy HashTable;
413 IdentifierInfoLookup* ExternalLookup;
416 /// IdentifierTable ctor - Create the identifier table, populating it with
417 /// info about the language keywords for the language specified by LangOpts.
418 IdentifierTable(const LangOptions &LangOpts,
419 IdentifierInfoLookup* externalLookup = 0);
421 /// \brief Set the external identifier lookup mechanism.
422 void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
423 ExternalLookup = IILookup;
426 /// \brief Retrieve the external identifier lookup object, if any.
427 IdentifierInfoLookup *getExternalIdentifierLookup() const {
428 return ExternalLookup;
431 llvm::BumpPtrAllocator& getAllocator() {
432 return HashTable.getAllocator();
435 /// get - Return the identifier token info for the specified named identifier.
437 IdentifierInfo &get(StringRef Name) {
438 llvm::StringMapEntry<IdentifierInfo*> &Entry =
439 HashTable.GetOrCreateValue(Name);
441 IdentifierInfo *II = Entry.getValue();
444 // No entry; if we have an external lookup, look there first.
445 if (ExternalLookup) {
446 II = ExternalLookup->get(Name);
448 // Cache in the StringMap for subsequent lookups.
454 // Lookups failed, make a new IdentifierInfo.
455 void *Mem = getAllocator().Allocate<IdentifierInfo>();
456 II = new (Mem) IdentifierInfo();
459 // Make sure getName() knows how to find the IdentifierInfo
466 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
467 IdentifierInfo &II = get(Name);
468 II.TokenID = TokenCode;
469 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
473 /// \brief Gets an IdentifierInfo for the given name without consulting
474 /// external sources.
476 /// This is a version of get() meant for external sources that want to
477 /// introduce or modify an identifier. If they called get(), they would
478 /// likely end up in a recursion.
479 IdentifierInfo &getOwn(StringRef Name) {
480 llvm::StringMapEntry<IdentifierInfo*> &Entry =
481 HashTable.GetOrCreateValue(Name);
483 IdentifierInfo *II = Entry.getValue();
486 // Lookups failed, make a new IdentifierInfo.
487 void *Mem = getAllocator().Allocate<IdentifierInfo>();
488 II = new (Mem) IdentifierInfo();
491 // Make sure getName() knows how to find the IdentifierInfo
495 // If this is the 'import' contextual keyword, mark it as such.
496 if (Name.equals("import"))
497 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 /// PrintStats - 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 /// ObjCMethodFamily - A family of Objective-C methods. These
518 /// families have no inherent meaning in the language, but are
519 /// nonetheless central enough in the existing implementations to
520 /// merit direct AST support. While, in theory, arbitrary methods can
521 /// be considered to form families, we focus here on the methods
522 /// involving allocation and retain-count management, as these are the
523 /// most "core" and the most likely to be useful to diverse clients
524 /// without extra information.
526 /// Both selectors and actual method declarations may be classified
527 /// into families. Method families may impose additional restrictions
528 /// beyond their selector name; for example, a method called '_init'
529 /// that returns void is not considered to be in the 'init' family
530 /// (but would be if it returned 'id'). It is also possible to
531 /// explicitly change or remove a method's family. Therefore the
532 /// method's family should be considered the single source of truth.
533 enum ObjCMethodFamily {
534 /// \brief No particular method family.
537 // Selectors in these families may have arbitrary arity, may be
538 // written with arbitrary leading underscores, and may have
539 // additional CamelCase "words" in their first selector chunk
540 // following the family name.
547 // These families are singletons consisting only of the nullary
548 // selector with the given name.
557 // performSelector families
561 /// Enough bits to store any enumerator in ObjCMethodFamily or
562 /// InvalidObjCMethodFamily.
563 enum { ObjCMethodFamilyBitWidth = 4 };
565 /// An invalid value of ObjCMethodFamily.
566 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
568 /// Selector - This smart pointer class efficiently represents Objective-C
569 /// method names. This class will either point to an IdentifierInfo or a
570 /// MultiKeywordSelector (which is private). This enables us to optimize
571 /// selectors that take no arguments and selectors that take 1 argument, which
572 /// accounts for 78% of all selectors in Cocoa.h.
574 friend class Diagnostic;
576 enum IdentifierInfoFlag {
577 // MultiKeywordSelector = 0.
580 ArgFlags = ZeroArg|OneArg
582 uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
584 Selector(IdentifierInfo *II, unsigned nArgs) {
585 InfoPtr = reinterpret_cast<uintptr_t>(II);
586 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
587 assert(nArgs < 2 && "nArgs not equal to 0/1");
590 Selector(MultiKeywordSelector *SI) {
591 InfoPtr = reinterpret_cast<uintptr_t>(SI);
592 assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
595 IdentifierInfo *getAsIdentifierInfo() const {
596 if (getIdentifierInfoFlag())
597 return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
600 unsigned getIdentifierInfoFlag() const {
601 return InfoPtr & ArgFlags;
604 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
607 friend class SelectorTable; // only the SelectorTable can create these
608 friend class DeclarationName; // and the AST's DeclarationName.
610 /// The default ctor should only be used when creating data structures that
611 /// will contain selectors.
612 Selector() : InfoPtr(0) {}
613 Selector(uintptr_t V) : InfoPtr(V) {}
615 /// operator==/!= - Indicate whether the specified selectors are identical.
616 bool operator==(Selector RHS) const {
617 return InfoPtr == RHS.InfoPtr;
619 bool operator!=(Selector RHS) const {
620 return InfoPtr != RHS.InfoPtr;
622 void *getAsOpaquePtr() const {
623 return reinterpret_cast<void*>(InfoPtr);
626 /// \brief Determine whether this is the empty selector.
627 bool isNull() const { return InfoPtr == 0; }
629 // Predicates to identify the selector type.
630 bool isKeywordSelector() const {
631 return getIdentifierInfoFlag() != ZeroArg;
633 bool isUnarySelector() const {
634 return getIdentifierInfoFlag() == ZeroArg;
636 unsigned getNumArgs() const;
639 /// \brief Retrieve the identifier at a given position in the selector.
641 /// Note that the identifier pointer returned may be NULL. Clients that only
642 /// care about the text of the identifier string, and not the specific,
643 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
644 /// an empty string when the identifier pointer would be NULL.
646 /// \param argIndex The index for which we want to retrieve the identifier.
647 /// This index shall be less than \c getNumArgs() unless this is a keyword
648 /// selector, in which case 0 is the only permissible value.
650 /// \returns the uniqued identifier for this slot, or NULL if this slot has
651 /// no corresponding identifier.
652 IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
654 /// \brief Retrieve the name at a given position in the selector.
656 /// \param argIndex The index for which we want to retrieve the name.
657 /// This index shall be less than \c getNumArgs() unless this is a keyword
658 /// selector, in which case 0 is the only permissible value.
660 /// \returns the name for this slot, which may be the empty string if no
661 /// name was supplied.
662 StringRef getNameForSlot(unsigned argIndex) const;
664 /// getAsString - Derive the full selector name (e.g. "foo:bar:") and return
665 /// it as an std::string.
666 std::string getAsString() const;
668 /// getMethodFamily - Derive the conventional family of this method.
669 ObjCMethodFamily getMethodFamily() const {
670 return getMethodFamilyImpl(*this);
673 static Selector getEmptyMarker() {
674 return Selector(uintptr_t(-1));
676 static Selector getTombstoneMarker() {
677 return Selector(uintptr_t(-2));
681 /// SelectorTable - This table allows us to fully hide how we implement
682 /// multi-keyword caching.
683 class SelectorTable {
684 void *Impl; // Actually a SelectorTableImpl
685 SelectorTable(const SelectorTable&); // DISABLED: DO NOT IMPLEMENT
686 void operator=(const SelectorTable&); // DISABLED: DO NOT IMPLEMENT
691 /// getSelector - This can create any sort of selector. NumArgs indicates
692 /// whether this is a no argument selector "foo", a single argument selector
693 /// "foo:" or multi-argument "foo:bar:".
694 Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
696 Selector getUnarySelector(IdentifierInfo *ID) {
697 return Selector(ID, 1);
699 Selector getNullarySelector(IdentifierInfo *ID) {
700 return Selector(ID, 0);
703 /// Return the total amount of memory allocated for managing selectors.
704 size_t getTotalMemory() const;
706 /// constructSetterName - Return the setter name for the given
707 /// identifier, i.e. "set" + Name where the initial character of Name
708 /// has been capitalized.
709 static Selector constructSetterName(IdentifierTable &Idents,
710 SelectorTable &SelTable,
711 const IdentifierInfo *Name);
714 /// DeclarationNameExtra - Common base of the MultiKeywordSelector,
715 /// CXXSpecialName, and CXXOperatorIdName classes, all of which are
716 /// private classes that describe different kinds of names.
717 class DeclarationNameExtra {
719 /// ExtraKind - The kind of "extra" information stored in the
720 /// DeclarationName. See @c ExtraKindOrNumArgs for an explanation of
721 /// how these enumerator values are used.
725 CXXConversionFunction,
726 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
728 #include "clang/Basic/OperatorKinds.def"
734 /// ExtraKindOrNumArgs - Either the kind of C++ special name or
735 /// operator-id (if the value is one of the CXX* enumerators of
736 /// ExtraKind), in which case the DeclarationNameExtra is also a
737 /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
738 /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
739 /// it may be also name common to C++ using-directives (CXXUsingDirective),
740 /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
741 /// arguments in the Objective-C selector, in which case the
742 /// DeclarationNameExtra is also a MultiKeywordSelector.
743 unsigned ExtraKindOrNumArgs;
746 } // end namespace clang
749 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
752 struct DenseMapInfo<clang::Selector> {
753 static inline clang::Selector getEmptyKey() {
754 return clang::Selector::getEmptyMarker();
756 static inline clang::Selector getTombstoneKey() {
757 return clang::Selector::getTombstoneMarker();
760 static unsigned getHashValue(clang::Selector S);
762 static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
768 struct isPodLike<clang::Selector> { static const bool value = true; };
771 class PointerLikeTypeTraits<clang::Selector> {
773 static inline const void *getAsVoidPointer(clang::Selector P) {
774 return P.getAsOpaquePtr();
776 static inline clang::Selector getFromVoidPointer(const void *P) {
777 return clang::Selector(reinterpret_cast<uintptr_t>(P));
779 enum { NumLowBitsAvailable = 0 };
782 // Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
783 // are not guaranteed to be 8-byte aligned.
785 class PointerLikeTypeTraits<clang::IdentifierInfo*> {
787 static inline void *getAsVoidPointer(clang::IdentifierInfo* P) {
790 static inline clang::IdentifierInfo *getFromVoidPointer(void *P) {
791 return static_cast<clang::IdentifierInfo*>(P);
793 enum { NumLowBitsAvailable = 1 };
797 class PointerLikeTypeTraits<const clang::IdentifierInfo*> {
799 static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
802 static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
803 return static_cast<const clang::IdentifierInfo*>(P);
805 enum { NumLowBitsAvailable = 1 };
808 } // end namespace llvm