Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:49

0001 //===- IdentifierTable.h - Hash table for identifier lookup -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 /// \file
0010 /// Defines the clang::IdentifierInfo, clang::IdentifierTable, and
0011 /// clang::Selector interfaces.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
0016 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
0017 
0018 #include "clang/Basic/Builtins.h"
0019 #include "clang/Basic/DiagnosticIDs.h"
0020 #include "clang/Basic/LLVM.h"
0021 #include "clang/Basic/TokenKinds.h"
0022 #include "llvm/ADT/DenseMapInfo.h"
0023 #include "llvm/ADT/FoldingSet.h"
0024 #include "llvm/ADT/PointerIntPair.h"
0025 #include "llvm/ADT/PointerUnion.h"
0026 #include "llvm/ADT/SmallString.h"
0027 #include "llvm/ADT/StringMap.h"
0028 #include "llvm/ADT/StringRef.h"
0029 #include "llvm/Support/Allocator.h"
0030 #include "llvm/Support/PointerLikeTypeTraits.h"
0031 #include "llvm/Support/type_traits.h"
0032 #include <cassert>
0033 #include <cstddef>
0034 #include <cstdint>
0035 #include <cstring>
0036 #include <string>
0037 #include <utility>
0038 
0039 namespace clang {
0040 
0041 class DeclarationName;
0042 class DeclarationNameTable;
0043 class IdentifierInfo;
0044 class LangOptions;
0045 class MultiKeywordSelector;
0046 class SourceLocation;
0047 
0048 enum class ReservedIdentifierStatus {
0049   NotReserved = 0,
0050   StartsWithUnderscoreAtGlobalScope,
0051   StartsWithUnderscoreAndIsExternC,
0052   StartsWithDoubleUnderscore,
0053   StartsWithUnderscoreFollowedByCapitalLetter,
0054   ContainsDoubleUnderscore,
0055 };
0056 
0057 enum class ReservedLiteralSuffixIdStatus {
0058   NotReserved = 0,
0059   NotStartsWithUnderscore,
0060   ContainsDoubleUnderscore,
0061 };
0062 
0063 /// Determine whether an identifier is reserved for use as a name at global
0064 /// scope. Such identifiers might be implementation-specific global functions
0065 /// or variables.
0066 inline bool isReservedAtGlobalScope(ReservedIdentifierStatus Status) {
0067   return Status != ReservedIdentifierStatus::NotReserved;
0068 }
0069 
0070 /// Determine whether an identifier is reserved in all contexts. Such
0071 /// identifiers might be implementation-specific keywords or macros, for
0072 /// example.
0073 inline bool isReservedInAllContexts(ReservedIdentifierStatus Status) {
0074   return Status != ReservedIdentifierStatus::NotReserved &&
0075          Status != ReservedIdentifierStatus::StartsWithUnderscoreAtGlobalScope &&
0076          Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC;
0077 }
0078 
0079 /// A simple pair of identifier info and location.
0080 using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;
0081 
0082 /// IdentifierInfo and other related classes are aligned to
0083 /// 8 bytes so that DeclarationName can use the lower 3 bits
0084 /// of a pointer to one of these classes.
0085 enum { IdentifierInfoAlignment = 8 };
0086 
0087 static constexpr int InterestingIdentifierBits = 16;
0088 
0089 /// The "layout" of InterestingIdentifier is:
0090 ///  - ObjCKeywordKind enumerators
0091 ///  - NotableIdentifierKind enumerators
0092 ///  - Builtin::ID enumerators
0093 ///  - NotInterestingIdentifier
0094 enum class InterestingIdentifier {
0095 #define OBJC_AT_KEYWORD(X) objc_##X,
0096 #include "clang/Basic/TokenKinds.def"
0097   NUM_OBJC_KEYWORDS,
0098 
0099 #define NOTABLE_IDENTIFIER(X) X,
0100 #include "clang/Basic/TokenKinds.def"
0101   NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS,
0102 
0103   NotBuiltin,
0104 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
0105 #include "clang/Basic/Builtins.inc"
0106   FirstTSBuiltin,
0107 
0108   NotInterestingIdentifier = 65534
0109 };
0110 
0111 /// One of these records is kept for each identifier that
0112 /// is lexed.  This contains information about whether the token was \#define'd,
0113 /// is a language keyword, or if it is a front-end token of some sort (e.g. a
0114 /// variable or function name).  The preprocessor keeps this information in a
0115 /// set, and all tok::identifier tokens have a pointer to one of these.
0116 /// It is aligned to 8 bytes because DeclarationName needs the lower 3 bits.
0117 class alignas(IdentifierInfoAlignment) IdentifierInfo {
0118   friend class IdentifierTable;
0119 
0120   // Front-end token ID or tok::identifier.
0121   LLVM_PREFERRED_TYPE(tok::TokenKind)
0122   unsigned TokenID : 9;
0123 
0124   LLVM_PREFERRED_TYPE(InterestingIdentifier)
0125   unsigned InterestingIdentifierID : InterestingIdentifierBits;
0126 
0127   // True if there is a #define for this.
0128   LLVM_PREFERRED_TYPE(bool)
0129   unsigned HasMacro : 1;
0130 
0131   // True if there was a #define for this.
0132   LLVM_PREFERRED_TYPE(bool)
0133   unsigned HadMacro : 1;
0134 
0135   // True if the identifier is a language extension.
0136   LLVM_PREFERRED_TYPE(bool)
0137   unsigned IsExtension : 1;
0138 
0139   // True if the identifier is a keyword in a newer or proposed Standard.
0140   LLVM_PREFERRED_TYPE(bool)
0141   unsigned IsFutureCompatKeyword : 1;
0142 
0143   // True if the identifier is poisoned.
0144   LLVM_PREFERRED_TYPE(bool)
0145   unsigned IsPoisoned : 1;
0146 
0147   // True if the identifier is a C++ operator keyword.
0148   LLVM_PREFERRED_TYPE(bool)
0149   unsigned IsCPPOperatorKeyword : 1;
0150 
0151   // Internal bit set by the member function RecomputeNeedsHandleIdentifier.
0152   // See comment about RecomputeNeedsHandleIdentifier for more info.
0153   LLVM_PREFERRED_TYPE(bool)
0154   unsigned NeedsHandleIdentifier : 1;
0155 
0156   // True if the identifier was loaded (at least partially) from an AST file.
0157   LLVM_PREFERRED_TYPE(bool)
0158   unsigned IsFromAST : 1;
0159 
0160   // True if the identifier has changed from the definition
0161   // loaded from an AST file.
0162   LLVM_PREFERRED_TYPE(bool)
0163   unsigned ChangedAfterLoad : 1;
0164 
0165   // True if the identifier's frontend information has changed from the
0166   // definition loaded from an AST file.
0167   LLVM_PREFERRED_TYPE(bool)
0168   unsigned FEChangedAfterLoad : 1;
0169 
0170   // True if revertTokenIDToIdentifier was called.
0171   LLVM_PREFERRED_TYPE(bool)
0172   unsigned RevertedTokenID : 1;
0173 
0174   // True if there may be additional information about
0175   // this identifier stored externally.
0176   LLVM_PREFERRED_TYPE(bool)
0177   unsigned OutOfDate : 1;
0178 
0179   // True if this is the 'import' contextual keyword.
0180   LLVM_PREFERRED_TYPE(bool)
0181   unsigned IsModulesImport : 1;
0182 
0183   // True if this is a mangled OpenMP variant name.
0184   LLVM_PREFERRED_TYPE(bool)
0185   unsigned IsMangledOpenMPVariantName : 1;
0186 
0187   // True if this is a deprecated macro.
0188   LLVM_PREFERRED_TYPE(bool)
0189   unsigned IsDeprecatedMacro : 1;
0190 
0191   // True if this macro is unsafe in headers.
0192   LLVM_PREFERRED_TYPE(bool)
0193   unsigned IsRestrictExpansion : 1;
0194 
0195   // True if this macro is final.
0196   LLVM_PREFERRED_TYPE(bool)
0197   unsigned IsFinal : 1;
0198 
0199   // 22 bits left in a 64-bit word.
0200 
0201   // Managed by the language front-end.
0202   void *FETokenInfo = nullptr;
0203 
0204   llvm::StringMapEntry<IdentifierInfo *> *Entry = nullptr;
0205 
0206   IdentifierInfo()
0207       : TokenID(tok::identifier),
0208         InterestingIdentifierID(llvm::to_underlying(
0209             InterestingIdentifier::NotInterestingIdentifier)),
0210         HasMacro(false), HadMacro(false), IsExtension(false),
0211         IsFutureCompatKeyword(false), IsPoisoned(false),
0212         IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
0213         IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
0214         RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
0215         IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
0216         IsRestrictExpansion(false), IsFinal(false) {}
0217 
0218 public:
0219   IdentifierInfo(const IdentifierInfo &) = delete;
0220   IdentifierInfo &operator=(const IdentifierInfo &) = delete;
0221   IdentifierInfo(IdentifierInfo &&) = delete;
0222   IdentifierInfo &operator=(IdentifierInfo &&) = delete;
0223 
0224   /// Return true if this is the identifier for the specified string.
0225   ///
0226   /// This is intended to be used for string literals only: II->isStr("foo").
0227   template <std::size_t StrLen>
0228   bool isStr(const char (&Str)[StrLen]) const {
0229     return getLength() == StrLen-1 &&
0230            memcmp(getNameStart(), Str, StrLen-1) == 0;
0231   }
0232 
0233   /// Return true if this is the identifier for the specified StringRef.
0234   bool isStr(llvm::StringRef Str) const {
0235     llvm::StringRef ThisStr(getNameStart(), getLength());
0236     return ThisStr == Str;
0237   }
0238 
0239   /// Return the beginning of the actual null-terminated string for this
0240   /// identifier.
0241   const char *getNameStart() const { return Entry->getKeyData(); }
0242 
0243   /// Efficiently return the length of this identifier info.
0244   unsigned getLength() const { return Entry->getKeyLength(); }
0245 
0246   /// Return the actual identifier string.
0247   StringRef getName() const {
0248     return StringRef(getNameStart(), getLength());
0249   }
0250 
0251   /// Return true if this identifier is \#defined to some other value.
0252   /// \note The current definition may be in a module and not currently visible.
0253   bool hasMacroDefinition() const {
0254     return HasMacro;
0255   }
0256   void setHasMacroDefinition(bool Val) {
0257     if (HasMacro == Val) return;
0258 
0259     HasMacro = Val;
0260     if (Val) {
0261       NeedsHandleIdentifier = true;
0262       HadMacro = true;
0263     } else {
0264       // If this is a final macro, make the deprecation and header unsafe bits
0265       // stick around after the undefinition so they apply to any redefinitions.
0266       if (!IsFinal) {
0267         // Because calling the setters of these calls recomputes, just set them
0268         // manually to avoid recomputing a bunch of times.
0269         IsDeprecatedMacro = false;
0270         IsRestrictExpansion = false;
0271       }
0272       RecomputeNeedsHandleIdentifier();
0273     }
0274   }
0275   /// Returns true if this identifier was \#defined to some value at any
0276   /// moment. In this case there should be an entry for the identifier in the
0277   /// macro history table in Preprocessor.
0278   bool hadMacroDefinition() const {
0279     return HadMacro;
0280   }
0281 
0282   bool isDeprecatedMacro() const { return IsDeprecatedMacro; }
0283 
0284   void setIsDeprecatedMacro(bool Val) {
0285     if (IsDeprecatedMacro == Val)
0286       return;
0287     IsDeprecatedMacro = Val;
0288     if (Val)
0289       NeedsHandleIdentifier = true;
0290     else
0291       RecomputeNeedsHandleIdentifier();
0292   }
0293 
0294   bool isRestrictExpansion() const { return IsRestrictExpansion; }
0295 
0296   void setIsRestrictExpansion(bool Val) {
0297     if (IsRestrictExpansion == Val)
0298       return;
0299     IsRestrictExpansion = Val;
0300     if (Val)
0301       NeedsHandleIdentifier = true;
0302     else
0303       RecomputeNeedsHandleIdentifier();
0304   }
0305 
0306   bool isFinal() const { return IsFinal; }
0307 
0308   void setIsFinal(bool Val) { IsFinal = Val; }
0309 
0310   /// If this is a source-language token (e.g. 'for'), this API
0311   /// can be used to cause the lexer to map identifiers to source-language
0312   /// tokens.
0313   tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
0314 
0315   /// True if revertTokenIDToIdentifier() was called.
0316   bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
0317 
0318   /// Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
0319   /// compatibility.
0320   ///
0321   /// TokenID is normally read-only but there are 2 instances where we revert it
0322   /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
0323   /// using this method so we can inform serialization about it.
0324   void revertTokenIDToIdentifier() {
0325     assert(TokenID != tok::identifier && "Already at tok::identifier");
0326     TokenID = tok::identifier;
0327     RevertedTokenID = true;
0328   }
0329   void revertIdentifierToTokenID(tok::TokenKind TK) {
0330     assert(TokenID == tok::identifier && "Should be at tok::identifier");
0331     TokenID = TK;
0332     RevertedTokenID = false;
0333   }
0334 
0335   /// Return the preprocessor keyword ID for this identifier.
0336   ///
0337   /// For example, "define" will return tok::pp_define.
0338   tok::PPKeywordKind getPPKeywordID() const;
0339 
0340   /// Return the Objective-C keyword ID for the this identifier.
0341   ///
0342   /// For example, 'class' will return tok::objc_class if ObjC is enabled.
0343   tok::ObjCKeywordKind getObjCKeywordID() const {
0344     assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
0345     auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
0346     if (Value < InterestingIdentifier::NUM_OBJC_KEYWORDS)
0347       return static_cast<tok::ObjCKeywordKind>(InterestingIdentifierID);
0348     return tok::objc_not_keyword;
0349   }
0350   void setObjCKeywordID(tok::ObjCKeywordKind ID) {
0351     assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
0352     InterestingIdentifierID = ID;
0353     assert(getObjCKeywordID() == ID && "ID too large for field!");
0354   }
0355 
0356   /// Return a value indicating whether this is a builtin function.
0357   unsigned getBuiltinID() const {
0358     auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
0359     if (Value >
0360             InterestingIdentifier::NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS &&
0361         Value != InterestingIdentifier::NotInterestingIdentifier) {
0362       auto FirstBuiltin =
0363           llvm::to_underlying(InterestingIdentifier::NotBuiltin);
0364       return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
0365     }
0366     return Builtin::ID::NotBuiltin;
0367   }
0368   void setBuiltinID(unsigned ID) {
0369     assert(ID != Builtin::ID::NotBuiltin);
0370     auto FirstBuiltin = llvm::to_underlying(InterestingIdentifier::NotBuiltin);
0371     InterestingIdentifierID = ID + FirstBuiltin;
0372     assert(getBuiltinID() == ID && "ID too large for field!");
0373   }
0374   void clearBuiltinID() {
0375     InterestingIdentifierID =
0376         llvm::to_underlying(InterestingIdentifier::NotInterestingIdentifier);
0377   }
0378 
0379   tok::NotableIdentifierKind getNotableIdentifierID() const {
0380     auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
0381     if (Value > InterestingIdentifier::NUM_OBJC_KEYWORDS &&
0382         Value <
0383             InterestingIdentifier::NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS) {
0384       auto FirstNotableIdentifier =
0385           1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
0386       return static_cast<tok::NotableIdentifierKind>(InterestingIdentifierID -
0387                                                      FirstNotableIdentifier);
0388     }
0389     return tok::not_notable;
0390   }
0391   void setNotableIdentifierID(unsigned ID) {
0392     assert(ID != tok::not_notable);
0393     auto FirstNotableIdentifier =
0394         1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
0395     InterestingIdentifierID = ID + FirstNotableIdentifier;
0396     assert(getNotableIdentifierID() == ID && "ID too large for field!");
0397   }
0398 
0399   unsigned getObjCOrBuiltinID() const { return InterestingIdentifierID; }
0400   void setObjCOrBuiltinID(unsigned ID) { InterestingIdentifierID = ID; }
0401 
0402   /// get/setExtension - Initialize information about whether or not this
0403   /// language token is an extension.  This controls extension warnings, and is
0404   /// only valid if a custom token ID is set.
0405   bool isExtensionToken() const { return IsExtension; }
0406   void setIsExtensionToken(bool Val) {
0407     IsExtension = Val;
0408     if (Val)
0409       NeedsHandleIdentifier = true;
0410     else
0411       RecomputeNeedsHandleIdentifier();
0412   }
0413 
0414   /// is/setIsFutureCompatKeyword - Initialize information about whether or not
0415   /// this language token is a keyword in a newer or proposed Standard. This
0416   /// controls compatibility warnings, and is only true when not parsing the
0417   /// corresponding Standard. Once a compatibility problem has been diagnosed
0418   /// with this keyword, the flag will be cleared.
0419   bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
0420   void setIsFutureCompatKeyword(bool Val) {
0421     IsFutureCompatKeyword = Val;
0422     if (Val)
0423       NeedsHandleIdentifier = true;
0424     else
0425       RecomputeNeedsHandleIdentifier();
0426   }
0427 
0428   /// setIsPoisoned - Mark this identifier as poisoned.  After poisoning, the
0429   /// Preprocessor will emit an error every time this token is used.
0430   void setIsPoisoned(bool Value = true) {
0431     IsPoisoned = Value;
0432     if (Value)
0433       NeedsHandleIdentifier = true;
0434     else
0435       RecomputeNeedsHandleIdentifier();
0436   }
0437 
0438   /// Return true if this token has been poisoned.
0439   bool isPoisoned() const { return IsPoisoned; }
0440 
0441   /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
0442   /// this identifier is a C++ alternate representation of an operator.
0443   void setIsCPlusPlusOperatorKeyword(bool Val = true) {
0444     IsCPPOperatorKeyword = Val;
0445   }
0446   bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
0447 
0448   /// Return true if this token is a keyword in the specified language.
0449   bool isKeyword(const LangOptions &LangOpts) const;
0450 
0451   /// Return true if this token is a C++ keyword in the specified
0452   /// language.
0453   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
0454 
0455   /// Get and set FETokenInfo. The language front-end is allowed to associate
0456   /// arbitrary metadata with this token.
0457   void *getFETokenInfo() const { return FETokenInfo; }
0458   void setFETokenInfo(void *T) { FETokenInfo = T; }
0459 
0460   /// Return true if the Preprocessor::HandleIdentifier must be called
0461   /// on a token of this identifier.
0462   ///
0463   /// If this returns false, we know that HandleIdentifier will not affect
0464   /// the token.
0465   bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
0466 
0467   /// Return true if the identifier in its current state was loaded
0468   /// from an AST file.
0469   bool isFromAST() const { return IsFromAST; }
0470 
0471   void setIsFromAST() { IsFromAST = true; }
0472 
0473   /// Determine whether this identifier has changed since it was loaded
0474   /// from an AST file.
0475   bool hasChangedSinceDeserialization() const {
0476     return ChangedAfterLoad;
0477   }
0478 
0479   /// Note that this identifier has changed since it was loaded from
0480   /// an AST file.
0481   void setChangedSinceDeserialization() {
0482     ChangedAfterLoad = true;
0483   }
0484 
0485   /// Determine whether the frontend token information for this
0486   /// identifier has changed since it was loaded from an AST file.
0487   bool hasFETokenInfoChangedSinceDeserialization() const {
0488     return FEChangedAfterLoad;
0489   }
0490 
0491   /// Note that the frontend token information for this identifier has
0492   /// changed since it was loaded from an AST file.
0493   void setFETokenInfoChangedSinceDeserialization() {
0494     FEChangedAfterLoad = true;
0495   }
0496 
0497   /// Determine whether the information for this identifier is out of
0498   /// date with respect to the external source.
0499   bool isOutOfDate() const { return OutOfDate; }
0500 
0501   /// Set whether the information for this identifier is out of
0502   /// date with respect to the external source.
0503   void setOutOfDate(bool OOD) {
0504     OutOfDate = OOD;
0505     if (OOD)
0506       NeedsHandleIdentifier = true;
0507     else
0508       RecomputeNeedsHandleIdentifier();
0509   }
0510 
0511   /// Determine whether this is the contextual keyword \c import.
0512   bool isModulesImport() const { return IsModulesImport; }
0513 
0514   /// Set whether this identifier is the contextual keyword \c import.
0515   void setModulesImport(bool I) {
0516     IsModulesImport = I;
0517     if (I)
0518       NeedsHandleIdentifier = true;
0519     else
0520       RecomputeNeedsHandleIdentifier();
0521   }
0522 
0523   /// Determine whether this is the mangled name of an OpenMP variant.
0524   bool isMangledOpenMPVariantName() const { return IsMangledOpenMPVariantName; }
0525 
0526   /// Set whether this is the mangled name of an OpenMP variant.
0527   void setMangledOpenMPVariantName(bool I) { IsMangledOpenMPVariantName = I; }
0528 
0529   /// Return true if this identifier is an editor placeholder.
0530   ///
0531   /// Editor placeholders are produced by the code-completion engine and are
0532   /// represented as characters between '<#' and '#>' in the source code. An
0533   /// example of auto-completed call with a placeholder parameter is shown
0534   /// below:
0535   /// \code
0536   ///   function(<#int x#>);
0537   /// \endcode
0538   bool isEditorPlaceholder() const {
0539     return getName().starts_with("<#") && getName().ends_with("#>");
0540   }
0541 
0542   /// Determine whether \p this is a name reserved for the implementation (C99
0543   /// 7.1.3, C++ [lib.global.names]).
0544   ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
0545 
0546   /// Determine whether \p this is a name reserved for future standardization or
0547   /// the implementation (C++ [usrlit.suffix]).
0548   ReservedLiteralSuffixIdStatus isReservedLiteralSuffixId() const;
0549 
0550   /// If the identifier is an "uglified" reserved name, return a cleaned form.
0551   /// e.g. _Foo => Foo. Otherwise, just returns the name.
0552   StringRef deuglifiedName() const;
0553   bool isPlaceholder() const {
0554     return getLength() == 1 && getNameStart()[0] == '_';
0555   }
0556 
0557   /// Provide less than operator for lexicographical sorting.
0558   bool operator<(const IdentifierInfo &RHS) const {
0559     return getName() < RHS.getName();
0560   }
0561 
0562 private:
0563   /// The Preprocessor::HandleIdentifier does several special (but rare)
0564   /// things to identifiers of various sorts.  For example, it changes the
0565   /// \c for keyword token from tok::identifier to tok::for.
0566   ///
0567   /// This method is very tied to the definition of HandleIdentifier.  Any
0568   /// change to it should be reflected here.
0569   void RecomputeNeedsHandleIdentifier() {
0570     NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
0571                             isExtensionToken() || isFutureCompatKeyword() ||
0572                             isOutOfDate() || isModulesImport();
0573   }
0574 };
0575 
0576 /// An RAII object for [un]poisoning an identifier within a scope.
0577 ///
0578 /// \p II is allowed to be null, in which case objects of this type have
0579 /// no effect.
0580 class PoisonIdentifierRAIIObject {
0581   IdentifierInfo *const II;
0582   const bool OldValue;
0583 
0584 public:
0585   PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
0586     : II(II), OldValue(II ? II->isPoisoned() : false) {
0587     if(II)
0588       II->setIsPoisoned(NewValue);
0589   }
0590 
0591   ~PoisonIdentifierRAIIObject() {
0592     if(II)
0593       II->setIsPoisoned(OldValue);
0594   }
0595 };
0596 
0597 /// An iterator that walks over all of the known identifiers
0598 /// in the lookup table.
0599 ///
0600 /// Since this iterator uses an abstract interface via virtual
0601 /// functions, it uses an object-oriented interface rather than the
0602 /// more standard C++ STL iterator interface. In this OO-style
0603 /// iteration, the single function \c Next() provides dereference,
0604 /// advance, and end-of-sequence checking in a single
0605 /// operation. Subclasses of this iterator type will provide the
0606 /// actual functionality.
0607 class IdentifierIterator {
0608 protected:
0609   IdentifierIterator() = default;
0610 
0611 public:
0612   IdentifierIterator(const IdentifierIterator &) = delete;
0613   IdentifierIterator &operator=(const IdentifierIterator &) = delete;
0614 
0615   virtual ~IdentifierIterator();
0616 
0617   /// Retrieve the next string in the identifier table and
0618   /// advances the iterator for the following string.
0619   ///
0620   /// \returns The next string in the identifier table. If there is
0621   /// no such string, returns an empty \c StringRef.
0622   virtual StringRef Next() = 0;
0623 };
0624 
0625 /// Provides lookups to, and iteration over, IdentiferInfo objects.
0626 class IdentifierInfoLookup {
0627 public:
0628   virtual ~IdentifierInfoLookup();
0629 
0630   /// Return the IdentifierInfo for the specified named identifier.
0631   ///
0632   /// Unlike the version in IdentifierTable, this returns a pointer instead
0633   /// of a reference.  If the pointer is null then the IdentifierInfo cannot
0634   /// be found.
0635   virtual IdentifierInfo* get(StringRef Name) = 0;
0636 
0637   /// Retrieve an iterator into the set of all identifiers
0638   /// known to this identifier lookup source.
0639   ///
0640   /// This routine provides access to all of the identifiers known to
0641   /// the identifier lookup, allowing access to the contents of the
0642   /// identifiers without introducing the overhead of constructing
0643   /// IdentifierInfo objects for each.
0644   ///
0645   /// \returns A new iterator into the set of known identifiers. The
0646   /// caller is responsible for deleting this iterator.
0647   virtual IdentifierIterator *getIdentifiers();
0648 };
0649 
0650 /// Implements an efficient mapping from strings to IdentifierInfo nodes.
0651 ///
0652 /// This has no other purpose, but this is an extremely performance-critical
0653 /// piece of the code, as each occurrence of every identifier goes through
0654 /// here when lexed.
0655 class IdentifierTable {
0656   // Shark shows that using MallocAllocator is *much* slower than using this
0657   // BumpPtrAllocator!
0658   using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
0659   HashTableTy HashTable;
0660 
0661   IdentifierInfoLookup* ExternalLookup;
0662 
0663 public:
0664   /// Create the identifier table.
0665   explicit IdentifierTable(IdentifierInfoLookup *ExternalLookup = nullptr);
0666 
0667   /// Create the identifier table, populating it with info about the
0668   /// language keywords for the language specified by \p LangOpts.
0669   explicit IdentifierTable(const LangOptions &LangOpts,
0670                            IdentifierInfoLookup *ExternalLookup = nullptr);
0671 
0672   /// Set the external identifier lookup mechanism.
0673   void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
0674     ExternalLookup = IILookup;
0675   }
0676 
0677   /// Retrieve the external identifier lookup object, if any.
0678   IdentifierInfoLookup *getExternalIdentifierLookup() const {
0679     return ExternalLookup;
0680   }
0681 
0682   llvm::BumpPtrAllocator& getAllocator() {
0683     return HashTable.getAllocator();
0684   }
0685 
0686   /// Return the identifier token info for the specified named
0687   /// identifier.
0688   IdentifierInfo &get(StringRef Name) {
0689     auto &Entry = *HashTable.try_emplace(Name, nullptr).first;
0690 
0691     IdentifierInfo *&II = Entry.second;
0692     if (II) return *II;
0693 
0694     // No entry; if we have an external lookup, look there first.
0695     if (ExternalLookup) {
0696       II = ExternalLookup->get(Name);
0697       if (II)
0698         return *II;
0699     }
0700 
0701     // Lookups failed, make a new IdentifierInfo.
0702     void *Mem = getAllocator().Allocate<IdentifierInfo>();
0703     II = new (Mem) IdentifierInfo();
0704 
0705     // Make sure getName() knows how to find the IdentifierInfo
0706     // contents.
0707     II->Entry = &Entry;
0708 
0709     return *II;
0710   }
0711 
0712   IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
0713     IdentifierInfo &II = get(Name);
0714     II.TokenID = TokenCode;
0715     assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
0716     return II;
0717   }
0718 
0719   /// Gets an IdentifierInfo for the given name without consulting
0720   ///        external sources.
0721   ///
0722   /// This is a version of get() meant for external sources that want to
0723   /// introduce or modify an identifier. If they called get(), they would
0724   /// likely end up in a recursion.
0725   IdentifierInfo &getOwn(StringRef Name) {
0726     auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
0727 
0728     IdentifierInfo *&II = Entry.second;
0729     if (II)
0730       return *II;
0731 
0732     // Lookups failed, make a new IdentifierInfo.
0733     void *Mem = getAllocator().Allocate<IdentifierInfo>();
0734     II = new (Mem) IdentifierInfo();
0735 
0736     // Make sure getName() knows how to find the IdentifierInfo
0737     // contents.
0738     II->Entry = &Entry;
0739 
0740     // If this is the 'import' contextual keyword, mark it as such.
0741     if (Name == "import")
0742       II->setModulesImport(true);
0743 
0744     return *II;
0745   }
0746 
0747   using iterator = HashTableTy::const_iterator;
0748   using const_iterator = HashTableTy::const_iterator;
0749 
0750   iterator begin() const { return HashTable.begin(); }
0751   iterator end() const   { return HashTable.end(); }
0752   unsigned size() const  { return HashTable.size(); }
0753 
0754   iterator find(StringRef Name) const { return HashTable.find(Name); }
0755 
0756   /// Print some statistics to stderr that indicate how well the
0757   /// hashing is doing.
0758   void PrintStats() const;
0759 
0760   /// Populate the identifier table with info about the language keywords
0761   /// for the language specified by \p LangOpts.
0762   void AddKeywords(const LangOptions &LangOpts);
0763 
0764   /// Returns the correct diagnostic to issue for a future-compat diagnostic
0765   /// warning. Note, this function assumes the identifier passed has already
0766   /// been determined to be a future compatible keyword.
0767   diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
0768                                      const LangOptions &LangOpts);
0769 };
0770 
0771 /// A family of Objective-C methods.
0772 ///
0773 /// These families have no inherent meaning in the language, but are
0774 /// nonetheless central enough in the existing implementations to
0775 /// merit direct AST support.  While, in theory, arbitrary methods can
0776 /// be considered to form families, we focus here on the methods
0777 /// involving allocation and retain-count management, as these are the
0778 /// most "core" and the most likely to be useful to diverse clients
0779 /// without extra information.
0780 ///
0781 /// Both selectors and actual method declarations may be classified
0782 /// into families.  Method families may impose additional restrictions
0783 /// beyond their selector name; for example, a method called '_init'
0784 /// that returns void is not considered to be in the 'init' family
0785 /// (but would be if it returned 'id').  It is also possible to
0786 /// explicitly change or remove a method's family.  Therefore the
0787 /// method's family should be considered the single source of truth.
0788 enum ObjCMethodFamily {
0789   /// No particular method family.
0790   OMF_None,
0791 
0792   // Selectors in these families may have arbitrary arity, may be
0793   // written with arbitrary leading underscores, and may have
0794   // additional CamelCase "words" in their first selector chunk
0795   // following the family name.
0796   OMF_alloc,
0797   OMF_copy,
0798   OMF_init,
0799   OMF_mutableCopy,
0800   OMF_new,
0801 
0802   // These families are singletons consisting only of the nullary
0803   // selector with the given name.
0804   OMF_autorelease,
0805   OMF_dealloc,
0806   OMF_finalize,
0807   OMF_release,
0808   OMF_retain,
0809   OMF_retainCount,
0810   OMF_self,
0811   OMF_initialize,
0812 
0813   // performSelector families
0814   OMF_performSelector
0815 };
0816 
0817 /// Enough bits to store any enumerator in ObjCMethodFamily or
0818 /// InvalidObjCMethodFamily.
0819 enum { ObjCMethodFamilyBitWidth = 4 };
0820 
0821 /// An invalid value of ObjCMethodFamily.
0822 enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
0823 
0824 /// A family of Objective-C methods.
0825 ///
0826 /// These are family of methods whose result type is initially 'id', but
0827 /// but are candidate for the result type to be changed to 'instancetype'.
0828 enum ObjCInstanceTypeFamily {
0829   OIT_None,
0830   OIT_Array,
0831   OIT_Dictionary,
0832   OIT_Singleton,
0833   OIT_Init,
0834   OIT_ReturnsSelf
0835 };
0836 
0837 enum ObjCStringFormatFamily {
0838   SFF_None,
0839   SFF_NSString,
0840   SFF_CFString
0841 };
0842 
0843 namespace detail {
0844 
0845 /// DeclarationNameExtra is used as a base of various uncommon special names.
0846 /// This class is needed since DeclarationName has not enough space to store
0847 /// the kind of every possible names. Therefore the kind of common names is
0848 /// stored directly in DeclarationName, and the kind of uncommon names is
0849 /// stored in DeclarationNameExtra. It is aligned to 8 bytes because
0850 /// DeclarationName needs the lower 3 bits to store the kind of common names.
0851 /// DeclarationNameExtra is tightly coupled to DeclarationName and any change
0852 /// here is very likely to require changes in DeclarationName(Table).
0853 class alignas(IdentifierInfoAlignment) DeclarationNameExtra {
0854   friend class clang::DeclarationName;
0855   friend class clang::DeclarationNameTable;
0856 
0857 protected:
0858   /// The kind of "extra" information stored in the DeclarationName. See
0859   /// @c ExtraKindOrNumArgs for an explanation of how these enumerator values
0860   /// are used. Note that DeclarationName depends on the numerical values
0861   /// of the enumerators in this enum. See DeclarationName::StoredNameKind
0862   /// for more info.
0863   enum ExtraKind {
0864     CXXDeductionGuideName,
0865     CXXLiteralOperatorName,
0866     CXXUsingDirective,
0867     ObjCMultiArgSelector
0868   };
0869 
0870   /// ExtraKindOrNumArgs has one of the following meaning:
0871   ///  * The kind of an uncommon C++ special name. This DeclarationNameExtra
0872   ///    is in this case in fact either a CXXDeductionGuideNameExtra or
0873   ///    a CXXLiteralOperatorIdName.
0874   ///
0875   ///  * It may be also name common to C++ using-directives (CXXUsingDirective),
0876   ///
0877   ///  * Otherwise it is ObjCMultiArgSelector+NumArgs, where NumArgs is
0878   ///    the number of arguments in the Objective-C selector, in which
0879   ///    case the DeclarationNameExtra is also a MultiKeywordSelector.
0880   unsigned ExtraKindOrNumArgs;
0881 
0882   DeclarationNameExtra(ExtraKind Kind) : ExtraKindOrNumArgs(Kind) {}
0883   DeclarationNameExtra(unsigned NumArgs)
0884       : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
0885 
0886   /// Return the corresponding ExtraKind.
0887   ExtraKind getKind() const {
0888     return static_cast<ExtraKind>(ExtraKindOrNumArgs >
0889                                           (unsigned)ObjCMultiArgSelector
0890                                       ? (unsigned)ObjCMultiArgSelector
0891                                       : ExtraKindOrNumArgs);
0892   }
0893 
0894   /// Return the number of arguments in an ObjC selector. Only valid when this
0895   /// is indeed an ObjCMultiArgSelector.
0896   unsigned getNumArgs() const {
0897     assert(ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector &&
0898            "getNumArgs called but this is not an ObjC selector!");
0899     return ExtraKindOrNumArgs - (unsigned)ObjCMultiArgSelector;
0900   }
0901 };
0902 
0903 } // namespace detail
0904 
0905 /// One of these variable length records is kept for each
0906 /// selector containing more than one keyword. We use a folding set
0907 /// to unique aggregate names (keyword selectors in ObjC parlance). Access to
0908 /// this class is provided strictly through Selector.
0909 class alignas(IdentifierInfoAlignment) MultiKeywordSelector
0910     : public detail::DeclarationNameExtra,
0911       public llvm::FoldingSetNode {
0912   MultiKeywordSelector(unsigned nKeys) : DeclarationNameExtra(nKeys) {}
0913 
0914 public:
0915   // Constructor for keyword selectors.
0916   MultiKeywordSelector(unsigned nKeys, const IdentifierInfo **IIV)
0917       : DeclarationNameExtra(nKeys) {
0918     assert((nKeys > 1) && "not a multi-keyword selector");
0919 
0920     // Fill in the trailing keyword array.
0921     const IdentifierInfo **KeyInfo =
0922         reinterpret_cast<const IdentifierInfo **>(this + 1);
0923     for (unsigned i = 0; i != nKeys; ++i)
0924       KeyInfo[i] = IIV[i];
0925   }
0926 
0927   // getName - Derive the full selector name and return it.
0928   std::string getName() const;
0929 
0930   using DeclarationNameExtra::getNumArgs;
0931 
0932   using keyword_iterator = const IdentifierInfo *const *;
0933 
0934   keyword_iterator keyword_begin() const {
0935     return reinterpret_cast<keyword_iterator>(this + 1);
0936   }
0937 
0938   keyword_iterator keyword_end() const {
0939     return keyword_begin() + getNumArgs();
0940   }
0941 
0942   const IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
0943     assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
0944     return keyword_begin()[i];
0945   }
0946 
0947   static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys,
0948                       unsigned NumArgs) {
0949     ID.AddInteger(NumArgs);
0950     for (unsigned i = 0; i != NumArgs; ++i)
0951       ID.AddPointer(ArgTys[i]);
0952   }
0953 
0954   void Profile(llvm::FoldingSetNodeID &ID) {
0955     Profile(ID, keyword_begin(), getNumArgs());
0956   }
0957 };
0958 
0959 /// Smart pointer class that efficiently represents Objective-C method
0960 /// names.
0961 ///
0962 /// This class will either point to an IdentifierInfo or a
0963 /// MultiKeywordSelector (which is private). This enables us to optimize
0964 /// selectors that take no arguments and selectors that take 1 argument, which
0965 /// accounts for 78% of all selectors in Cocoa.h.
0966 class Selector {
0967   friend class Diagnostic;
0968   friend class SelectorTable; // only the SelectorTable can create these
0969   friend class DeclarationName; // and the AST's DeclarationName.
0970 
0971   enum IdentifierInfoFlag {
0972     // Empty selector = 0. Note that these enumeration values must
0973     // correspond to the enumeration values of DeclarationName::StoredNameKind
0974     ZeroArg = 0x01,
0975     OneArg = 0x02,
0976     // IMPORTANT NOTE: see comments in InfoPtr (below) about this enumerator
0977     // value.
0978     MultiArg = 0x07,
0979   };
0980 
0981   /// IMPORTANT NOTE: the order of the types in this PointerUnion are
0982   /// important! The DeclarationName class has bidirectional conversion
0983   /// to/from Selector through an opaque pointer (void *) which corresponds
0984   /// to this PointerIntPair. The discriminator bit from the PointerUnion
0985   /// corresponds to the high bit in the MultiArg enumerator. So while this
0986   /// PointerIntPair only has two bits for the integer (and we mask off the
0987   /// high bit in `MultiArg` when it is used), that discrimator bit is
0988   /// still necessary for the opaque conversion. The discriminator bit
0989   /// from the PointerUnion and the two integer bits from the
0990   /// PointerIntPair are also exposed via the DeclarationName::StoredNameKind
0991   /// enumeration; see the comments in DeclarationName.h for more details.
0992   /// Do not reorder or add any arguments to this template
0993   /// without thoroughly understanding how tightly coupled these classes are.
0994   llvm::PointerIntPair<
0995       llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
0996       InfoPtr;
0997 
0998   Selector(const IdentifierInfo *II, unsigned nArgs) {
0999     assert(nArgs < 2 && "nArgs not equal to 0/1");
1000     InfoPtr.setPointerAndInt(II, nArgs + 1);
1001   }
1002 
1003   Selector(MultiKeywordSelector *SI) {
1004     // IMPORTANT NOTE: we mask off the upper bit of this value because we only
1005     // reserve two bits for the integer in the PointerIntPair. See the comments
1006     // in `InfoPtr` for more details.
1007     InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1008   }
1009 
1010   const IdentifierInfo *getAsIdentifierInfo() const {
1011     return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1012   }
1013 
1014   MultiKeywordSelector *getMultiKeywordSelector() const {
1015     return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1016   }
1017 
1018   unsigned getIdentifierInfoFlag() const {
1019     unsigned new_flags = InfoPtr.getInt();
1020     // IMPORTANT NOTE: We have to reconstitute this data rather than use the
1021     // value directly from the PointerIntPair. See the comments in `InfoPtr`
1022     // for more details.
1023     if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1024       new_flags |= MultiArg;
1025     return new_flags;
1026   }
1027 
1028   static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
1029 
1030   static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
1031 
1032 public:
1033   /// The default ctor should only be used when creating data structures that
1034   ///  will contain selectors.
1035   Selector() = default;
1036   explicit Selector(uintptr_t V) {
1037     InfoPtr.setFromOpaqueValue(reinterpret_cast<void *>(V));
1038   }
1039 
1040   /// operator==/!= - Indicate whether the specified selectors are identical.
1041   bool operator==(Selector RHS) const {
1042     return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1043   }
1044   bool operator!=(Selector RHS) const {
1045     return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1046   }
1047 
1048   void *getAsOpaquePtr() const { return InfoPtr.getOpaqueValue(); }
1049 
1050   /// Determine whether this is the empty selector.
1051   bool isNull() const { return InfoPtr.getOpaqueValue() == nullptr; }
1052 
1053   // Predicates to identify the selector type.
1054   bool isKeywordSelector() const { return InfoPtr.getInt() != ZeroArg; }
1055 
1056   bool isUnarySelector() const { return InfoPtr.getInt() == ZeroArg; }
1057 
1058   /// If this selector is the specific keyword selector described by Names.
1059   bool isKeywordSelector(ArrayRef<StringRef> Names) const;
1060 
1061   /// If this selector is the specific unary selector described by Name.
1062   bool isUnarySelector(StringRef Name) const;
1063 
1064   unsigned getNumArgs() const;
1065 
1066   /// Retrieve the identifier at a given position in the selector.
1067   ///
1068   /// Note that the identifier pointer returned may be NULL. Clients that only
1069   /// care about the text of the identifier string, and not the specific,
1070   /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
1071   /// an empty string when the identifier pointer would be NULL.
1072   ///
1073   /// \param argIndex The index for which we want to retrieve the identifier.
1074   /// This index shall be less than \c getNumArgs() unless this is a keyword
1075   /// selector, in which case 0 is the only permissible value.
1076   ///
1077   /// \returns the uniqued identifier for this slot, or NULL if this slot has
1078   /// no corresponding identifier.
1079   const IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
1080 
1081   /// Retrieve the name at a given position in the selector.
1082   ///
1083   /// \param argIndex The index for which we want to retrieve the name.
1084   /// This index shall be less than \c getNumArgs() unless this is a keyword
1085   /// selector, in which case 0 is the only permissible value.
1086   ///
1087   /// \returns the name for this slot, which may be the empty string if no
1088   /// name was supplied.
1089   StringRef getNameForSlot(unsigned argIndex) const;
1090 
1091   /// Derive the full selector name (e.g. "foo:bar:") and return
1092   /// it as an std::string.
1093   std::string getAsString() const;
1094 
1095   /// Prints the full selector name (e.g. "foo:bar:").
1096   void print(llvm::raw_ostream &OS) const;
1097 
1098   void dump() const;
1099 
1100   /// Derive the conventional family of this method.
1101   ObjCMethodFamily getMethodFamily() const {
1102     return getMethodFamilyImpl(*this);
1103   }
1104 
1105   ObjCStringFormatFamily getStringFormatFamily() const {
1106     return getStringFormatFamilyImpl(*this);
1107   }
1108 
1109   static Selector getEmptyMarker() {
1110     return Selector(uintptr_t(-1));
1111   }
1112 
1113   static Selector getTombstoneMarker() {
1114     return Selector(uintptr_t(-2));
1115   }
1116 
1117   static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
1118 };
1119 
1120 /// This table allows us to fully hide how we implement
1121 /// multi-keyword caching.
1122 class SelectorTable {
1123   // Actually a SelectorTableImpl
1124   void *Impl;
1125 
1126 public:
1127   SelectorTable();
1128   SelectorTable(const SelectorTable &) = delete;
1129   SelectorTable &operator=(const SelectorTable &) = delete;
1130   ~SelectorTable();
1131 
1132   /// Can create any sort of selector.
1133   ///
1134   /// \p NumArgs indicates whether this is a no argument selector "foo", a
1135   /// single argument selector "foo:" or multi-argument "foo:bar:".
1136   Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV);
1137 
1138   Selector getUnarySelector(const IdentifierInfo *ID) {
1139     return Selector(ID, 1);
1140   }
1141 
1142   Selector getNullarySelector(const IdentifierInfo *ID) {
1143     return Selector(ID, 0);
1144   }
1145 
1146   /// Return the total amount of memory allocated for managing selectors.
1147   size_t getTotalMemory() const;
1148 
1149   /// Return the default setter name for the given identifier.
1150   ///
1151   /// This is "set" + \p Name where the initial character of \p Name
1152   /// has been capitalized.
1153   static SmallString<64> constructSetterName(StringRef Name);
1154 
1155   /// Return the default setter selector for the given identifier.
1156   ///
1157   /// This is "set" + \p Name where the initial character of \p Name
1158   /// has been capitalized.
1159   static Selector constructSetterSelector(IdentifierTable &Idents,
1160                                           SelectorTable &SelTable,
1161                                           const IdentifierInfo *Name);
1162 
1163   /// Return the property name for the given setter selector.
1164   static std::string getPropertyNameFromSetterSelector(Selector Sel);
1165 };
1166 
1167 }  // namespace clang
1168 
1169 namespace llvm {
1170 
1171 /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
1172 /// DenseSets.
1173 template <>
1174 struct DenseMapInfo<clang::Selector> {
1175   static clang::Selector getEmptyKey() {
1176     return clang::Selector::getEmptyMarker();
1177   }
1178 
1179   static clang::Selector getTombstoneKey() {
1180     return clang::Selector::getTombstoneMarker();
1181   }
1182 
1183   static unsigned getHashValue(clang::Selector S);
1184 
1185   static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
1186     return LHS == RHS;
1187   }
1188 };
1189 
1190 template<>
1191 struct PointerLikeTypeTraits<clang::Selector> {
1192   static const void *getAsVoidPointer(clang::Selector P) {
1193     return P.getAsOpaquePtr();
1194   }
1195 
1196   static clang::Selector getFromVoidPointer(const void *P) {
1197     return clang::Selector(reinterpret_cast<uintptr_t>(P));
1198   }
1199 
1200   static constexpr int NumLowBitsAvailable = 0;
1201 };
1202 
1203 } // namespace llvm
1204 
1205 #endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H