clang API Documentation

IdentifierTable.cpp
Go to the documentation of this file.
00001 //===--- IdentifierTable.cpp - Hash table for identifier lookup -----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the IdentifierInfo, IdentifierVisitor, and
00011 // IdentifierTable interfaces.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "clang/Basic/CharInfo.h"
00016 #include "clang/Basic/IdentifierTable.h"
00017 #include "clang/Basic/LangOptions.h"
00018 #include "clang/Basic/OperatorKinds.h"
00019 #include "llvm/ADT/DenseMap.h"
00020 #include "llvm/ADT/FoldingSet.h"
00021 #include "llvm/ADT/SmallString.h"
00022 #include "llvm/Support/ErrorHandling.h"
00023 #include "llvm/Support/raw_ostream.h"
00024 #include <cstdio>
00025 
00026 using namespace clang;
00027 
00028 //===----------------------------------------------------------------------===//
00029 // IdentifierInfo Implementation
00030 //===----------------------------------------------------------------------===//
00031 
00032 IdentifierInfo::IdentifierInfo() {
00033   TokenID = tok::identifier;
00034   ObjCOrBuiltinID = 0;
00035   HasMacro = false;
00036   HadMacro = false;
00037   IsExtension = false;
00038   IsCXX11CompatKeyword = false;
00039   IsPoisoned = false;
00040   IsCPPOperatorKeyword = false;
00041   NeedsHandleIdentifier = false;
00042   IsFromAST = false;
00043   ChangedAfterLoad = false;
00044   RevertedTokenID = false;
00045   OutOfDate = false;
00046   IsModulesImport = false;
00047   FETokenInfo = nullptr;
00048   Entry = nullptr;
00049 }
00050 
00051 //===----------------------------------------------------------------------===//
00052 // IdentifierTable Implementation
00053 //===----------------------------------------------------------------------===//
00054 
00055 IdentifierIterator::~IdentifierIterator() { }
00056 
00057 IdentifierInfoLookup::~IdentifierInfoLookup() {}
00058 
00059 namespace {
00060   /// \brief A simple identifier lookup iterator that represents an
00061   /// empty sequence of identifiers.
00062   class EmptyLookupIterator : public IdentifierIterator
00063   {
00064   public:
00065     StringRef Next() override { return StringRef(); }
00066   };
00067 }
00068 
00069 IdentifierIterator *IdentifierInfoLookup::getIdentifiers() {
00070   return new EmptyLookupIterator();
00071 }
00072 
00073 ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
00074 
00075 IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
00076                                  IdentifierInfoLookup* externalLookup)
00077   : HashTable(8192), // Start with space for 8K identifiers.
00078     ExternalLookup(externalLookup) {
00079 
00080   // Populate the identifier table with info about keywords for the current
00081   // language.
00082   AddKeywords(LangOpts);
00083       
00084 
00085   // Add the '_experimental_modules_import' contextual keyword.
00086   get("import").setModulesImport(true);
00087 }
00088 
00089 //===----------------------------------------------------------------------===//
00090 // Language Keyword Implementation
00091 //===----------------------------------------------------------------------===//
00092 
00093 // Constants for TokenKinds.def
00094 namespace {
00095   enum {
00096     KEYC99 = 0x1,
00097     KEYCXX = 0x2,
00098     KEYCXX11 = 0x4,
00099     KEYGNU = 0x8,
00100     KEYMS = 0x10,
00101     BOOLSUPPORT = 0x20,
00102     KEYALTIVEC = 0x40,
00103     KEYNOCXX = 0x80,
00104     KEYBORLAND = 0x100,
00105     KEYOPENCL = 0x200,
00106     KEYC11 = 0x400,
00107     KEYARC = 0x800,
00108     KEYNOMS = 0x01000,
00109     WCHARSUPPORT = 0x02000,
00110     HALFSUPPORT = 0x04000,
00111     KEYALL = (0xffff & ~KEYNOMS) // Because KEYNOMS is used to exclude.
00112   };
00113 
00114   /// \brief How a keyword is treated in the selected standard.
00115   enum KeywordStatus {
00116     KS_Disabled,    // Disabled
00117     KS_Extension,   // Is an extension
00118     KS_Enabled,     // Enabled
00119     KS_Future       // Is a keyword in future standard
00120   };
00121 }
00122 
00123 /// \brief Translates flags as specified in TokenKinds.def into keyword status
00124 /// in the given language standard.
00125 static KeywordStatus GetKeywordStatus(const LangOptions &LangOpts,
00126                                       unsigned Flags) {
00127   if (Flags == KEYALL) return KS_Enabled;
00128   if (LangOpts.CPlusPlus && (Flags & KEYCXX)) return KS_Enabled;
00129   if (LangOpts.CPlusPlus11 && (Flags & KEYCXX11)) return KS_Enabled;
00130   if (LangOpts.C99 && (Flags & KEYC99)) return KS_Enabled;
00131   if (LangOpts.GNUKeywords && (Flags & KEYGNU)) return KS_Extension;
00132   if (LangOpts.MicrosoftExt && (Flags & KEYMS)) return KS_Extension;
00133   if (LangOpts.Borland && (Flags & KEYBORLAND)) return KS_Extension;
00134   if (LangOpts.Bool && (Flags & BOOLSUPPORT)) return KS_Enabled;
00135   if (LangOpts.Half && (Flags & HALFSUPPORT)) return KS_Enabled;
00136   if (LangOpts.WChar && (Flags & WCHARSUPPORT)) return KS_Enabled;
00137   if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) return KS_Enabled;
00138   if (LangOpts.OpenCL && (Flags & KEYOPENCL)) return KS_Enabled;
00139   if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) return KS_Enabled;
00140   if (LangOpts.C11 && (Flags & KEYC11)) return KS_Enabled;
00141   // We treat bridge casts as objective-C keywords so we can warn on them
00142   // in non-arc mode.
00143   if (LangOpts.ObjC2 && (Flags & KEYARC)) return KS_Enabled;
00144   if (LangOpts.CPlusPlus && (Flags & KEYCXX11)) return KS_Future;
00145   return KS_Disabled;
00146 }
00147 
00148 /// AddKeyword - This method is used to associate a token ID with specific
00149 /// identifiers because they are language keywords.  This causes the lexer to
00150 /// automatically map matching identifiers to specialized token codes.
00151 static void AddKeyword(StringRef Keyword,
00152                        tok::TokenKind TokenCode, unsigned Flags,
00153                        const LangOptions &LangOpts, IdentifierTable &Table) {
00154   KeywordStatus AddResult = GetKeywordStatus(LangOpts, Flags);
00155 
00156   // Don't add this keyword under MSVCCompat.
00157   if (LangOpts.MSVCCompat && (Flags & KEYNOMS))
00158      return;
00159   // Don't add this keyword if disabled in this language.
00160   if (AddResult == KS_Disabled) return;
00161 
00162   IdentifierInfo &Info =
00163       Table.get(Keyword, AddResult == KS_Future ? tok::identifier : TokenCode);
00164   Info.setIsExtensionToken(AddResult == KS_Extension);
00165   Info.setIsCXX11CompatKeyword(AddResult == KS_Future);
00166 }
00167 
00168 /// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
00169 /// representations.
00170 static void AddCXXOperatorKeyword(StringRef Keyword,
00171                                   tok::TokenKind TokenCode,
00172                                   IdentifierTable &Table) {
00173   IdentifierInfo &Info = Table.get(Keyword, TokenCode);
00174   Info.setIsCPlusPlusOperatorKeyword();
00175 }
00176 
00177 /// AddObjCKeyword - Register an Objective-C \@keyword like "class" "selector"
00178 /// or "property".
00179 static void AddObjCKeyword(StringRef Name,
00180                            tok::ObjCKeywordKind ObjCID,
00181                            IdentifierTable &Table) {
00182   Table.get(Name).setObjCKeywordID(ObjCID);
00183 }
00184 
00185 /// AddKeywords - Add all keywords to the symbol table.
00186 ///
00187 void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
00188   // Add keywords and tokens for the current language.
00189 #define KEYWORD(NAME, FLAGS) \
00190   AddKeyword(StringRef(#NAME), tok::kw_ ## NAME,  \
00191              FLAGS, LangOpts, *this);
00192 #define ALIAS(NAME, TOK, FLAGS) \
00193   AddKeyword(StringRef(NAME), tok::kw_ ## TOK,  \
00194              FLAGS, LangOpts, *this);
00195 #define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
00196   if (LangOpts.CXXOperatorNames)          \
00197     AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this);
00198 #define OBJC1_AT_KEYWORD(NAME) \
00199   if (LangOpts.ObjC1)          \
00200     AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
00201 #define OBJC2_AT_KEYWORD(NAME) \
00202   if (LangOpts.ObjC2)          \
00203     AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
00204 #define TESTING_KEYWORD(NAME, FLAGS)
00205 #include "clang/Basic/TokenKinds.def"
00206 
00207   if (LangOpts.ParseUnknownAnytype)
00208     AddKeyword("__unknown_anytype", tok::kw___unknown_anytype, KEYALL,
00209                LangOpts, *this);
00210 }
00211 
00212 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
00213   // We use a perfect hash function here involving the length of the keyword,
00214   // the first and third character.  For preprocessor ID's there are no
00215   // collisions (if there were, the switch below would complain about duplicate
00216   // case values).  Note that this depends on 'if' being null terminated.
00217 
00218 #define HASH(LEN, FIRST, THIRD) \
00219   (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
00220 #define CASE(LEN, FIRST, THIRD, NAME) \
00221   case HASH(LEN, FIRST, THIRD): \
00222     return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
00223 
00224   unsigned Len = getLength();
00225   if (Len < 2) return tok::pp_not_keyword;
00226   const char *Name = getNameStart();
00227   switch (HASH(Len, Name[0], Name[2])) {
00228   default: return tok::pp_not_keyword;
00229   CASE( 2, 'i', '\0', if);
00230   CASE( 4, 'e', 'i', elif);
00231   CASE( 4, 'e', 's', else);
00232   CASE( 4, 'l', 'n', line);
00233   CASE( 4, 's', 'c', sccs);
00234   CASE( 5, 'e', 'd', endif);
00235   CASE( 5, 'e', 'r', error);
00236   CASE( 5, 'i', 'e', ident);
00237   CASE( 5, 'i', 'd', ifdef);
00238   CASE( 5, 'u', 'd', undef);
00239 
00240   CASE( 6, 'a', 's', assert);
00241   CASE( 6, 'd', 'f', define);
00242   CASE( 6, 'i', 'n', ifndef);
00243   CASE( 6, 'i', 'p', import);
00244   CASE( 6, 'p', 'a', pragma);
00245       
00246   CASE( 7, 'd', 'f', defined);
00247   CASE( 7, 'i', 'c', include);
00248   CASE( 7, 'w', 'r', warning);
00249 
00250   CASE( 8, 'u', 'a', unassert);
00251   CASE(12, 'i', 'c', include_next);
00252 
00253   CASE(14, '_', 'p', __public_macro);
00254       
00255   CASE(15, '_', 'p', __private_macro);
00256 
00257   CASE(16, '_', 'i', __include_macros);
00258 #undef CASE
00259 #undef HASH
00260   }
00261 }
00262 
00263 //===----------------------------------------------------------------------===//
00264 // Stats Implementation
00265 //===----------------------------------------------------------------------===//
00266 
00267 /// PrintStats - Print statistics about how well the identifier table is doing
00268 /// at hashing identifiers.
00269 void IdentifierTable::PrintStats() const {
00270   unsigned NumBuckets = HashTable.getNumBuckets();
00271   unsigned NumIdentifiers = HashTable.getNumItems();
00272   unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
00273   unsigned AverageIdentifierSize = 0;
00274   unsigned MaxIdentifierLength = 0;
00275 
00276   // TODO: Figure out maximum times an identifier had to probe for -stats.
00277   for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
00278        I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
00279     unsigned IdLen = I->getKeyLength();
00280     AverageIdentifierSize += IdLen;
00281     if (MaxIdentifierLength < IdLen)
00282       MaxIdentifierLength = IdLen;
00283   }
00284 
00285   fprintf(stderr, "\n*** Identifier Table Stats:\n");
00286   fprintf(stderr, "# Identifiers:   %d\n", NumIdentifiers);
00287   fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
00288   fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
00289           NumIdentifiers/(double)NumBuckets);
00290   fprintf(stderr, "Ave identifier length: %f\n",
00291           (AverageIdentifierSize/(double)NumIdentifiers));
00292   fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
00293 
00294   // Compute statistics about the memory allocated for identifiers.
00295   HashTable.getAllocator().PrintStats();
00296 }
00297 
00298 //===----------------------------------------------------------------------===//
00299 // SelectorTable Implementation
00300 //===----------------------------------------------------------------------===//
00301 
00302 unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
00303   return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
00304 }
00305 
00306 namespace clang {
00307 /// MultiKeywordSelector - One of these variable length records is kept for each
00308 /// selector containing more than one keyword. We use a folding set
00309 /// to unique aggregate names (keyword selectors in ObjC parlance). Access to
00310 /// this class is provided strictly through Selector.
00311 class MultiKeywordSelector
00312   : public DeclarationNameExtra, public llvm::FoldingSetNode {
00313   MultiKeywordSelector(unsigned nKeys) {
00314     ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
00315   }
00316 public:
00317   // Constructor for keyword selectors.
00318   MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
00319     assert((nKeys > 1) && "not a multi-keyword selector");
00320     ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
00321 
00322     // Fill in the trailing keyword array.
00323     IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
00324     for (unsigned i = 0; i != nKeys; ++i)
00325       KeyInfo[i] = IIV[i];
00326   }
00327 
00328   // getName - Derive the full selector name and return it.
00329   std::string getName() const;
00330 
00331   unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
00332 
00333   typedef IdentifierInfo *const *keyword_iterator;
00334   keyword_iterator keyword_begin() const {
00335     return reinterpret_cast<keyword_iterator>(this+1);
00336   }
00337   keyword_iterator keyword_end() const {
00338     return keyword_begin()+getNumArgs();
00339   }
00340   IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
00341     assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
00342     return keyword_begin()[i];
00343   }
00344   static void Profile(llvm::FoldingSetNodeID &ID,
00345                       keyword_iterator ArgTys, unsigned NumArgs) {
00346     ID.AddInteger(NumArgs);
00347     for (unsigned i = 0; i != NumArgs; ++i)
00348       ID.AddPointer(ArgTys[i]);
00349   }
00350   void Profile(llvm::FoldingSetNodeID &ID) {
00351     Profile(ID, keyword_begin(), getNumArgs());
00352   }
00353 };
00354 } // end namespace clang.
00355 
00356 unsigned Selector::getNumArgs() const {
00357   unsigned IIF = getIdentifierInfoFlag();
00358   if (IIF <= ZeroArg)
00359     return 0;
00360   if (IIF == OneArg)
00361     return 1;
00362   // We point to a MultiKeywordSelector.
00363   MultiKeywordSelector *SI = getMultiKeywordSelector();
00364   return SI->getNumArgs();
00365 }
00366 
00367 IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
00368   if (getIdentifierInfoFlag() < MultiArg) {
00369     assert(argIndex == 0 && "illegal keyword index");
00370     return getAsIdentifierInfo();
00371   }
00372   // We point to a MultiKeywordSelector.
00373   MultiKeywordSelector *SI = getMultiKeywordSelector();
00374   return SI->getIdentifierInfoForSlot(argIndex);
00375 }
00376 
00377 StringRef Selector::getNameForSlot(unsigned int argIndex) const {
00378   IdentifierInfo *II = getIdentifierInfoForSlot(argIndex);
00379   return II? II->getName() : StringRef();
00380 }
00381 
00382 std::string MultiKeywordSelector::getName() const {
00383   SmallString<256> Str;
00384   llvm::raw_svector_ostream OS(Str);
00385   for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
00386     if (*I)
00387       OS << (*I)->getName();
00388     OS << ':';
00389   }
00390 
00391   return OS.str();
00392 }
00393 
00394 std::string Selector::getAsString() const {
00395   if (InfoPtr == 0)
00396     return "<null selector>";
00397 
00398   if (getIdentifierInfoFlag() < MultiArg) {
00399     IdentifierInfo *II = getAsIdentifierInfo();
00400 
00401     // If the number of arguments is 0 then II is guaranteed to not be null.
00402     if (getNumArgs() == 0)
00403       return II->getName();
00404 
00405     if (!II)
00406       return ":";
00407 
00408     return II->getName().str() + ":";
00409   }
00410 
00411   // We have a multiple keyword selector.
00412   return getMultiKeywordSelector()->getName();
00413 }
00414 
00415 void Selector::print(llvm::raw_ostream &OS) const {
00416   OS << getAsString();
00417 }
00418 
00419 /// Interpreting the given string using the normal CamelCase
00420 /// conventions, determine whether the given string starts with the
00421 /// given "word", which is assumed to end in a lowercase letter.
00422 static bool startsWithWord(StringRef name, StringRef word) {
00423   if (name.size() < word.size()) return false;
00424   return ((name.size() == word.size() || !isLowercase(name[word.size()])) &&
00425           name.startswith(word));
00426 }
00427 
00428 ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
00429   IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
00430   if (!first) return OMF_None;
00431 
00432   StringRef name = first->getName();
00433   if (sel.isUnarySelector()) {
00434     if (name == "autorelease") return OMF_autorelease;
00435     if (name == "dealloc") return OMF_dealloc;
00436     if (name == "finalize") return OMF_finalize;
00437     if (name == "release") return OMF_release;
00438     if (name == "retain") return OMF_retain;
00439     if (name == "retainCount") return OMF_retainCount;
00440     if (name == "self") return OMF_self;
00441     if (name == "initialize") return OMF_initialize;
00442   }
00443  
00444   if (name == "performSelector") return OMF_performSelector;
00445 
00446   // The other method families may begin with a prefix of underscores.
00447   while (!name.empty() && name.front() == '_')
00448     name = name.substr(1);
00449 
00450   if (name.empty()) return OMF_None;
00451   switch (name.front()) {
00452   case 'a':
00453     if (startsWithWord(name, "alloc")) return OMF_alloc;
00454     break;
00455   case 'c':
00456     if (startsWithWord(name, "copy")) return OMF_copy;
00457     break;
00458   case 'i':
00459     if (startsWithWord(name, "init")) return OMF_init;
00460     break;
00461   case 'm':
00462     if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
00463     break;
00464   case 'n':
00465     if (startsWithWord(name, "new")) return OMF_new;
00466     break;
00467   default:
00468     break;
00469   }
00470 
00471   return OMF_None;
00472 }
00473 
00474 ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
00475   IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
00476   if (!first) return OIT_None;
00477   
00478   StringRef name = first->getName();
00479   
00480   if (name.empty()) return OIT_None;
00481   switch (name.front()) {
00482     case 'a':
00483       if (startsWithWord(name, "array")) return OIT_Array;
00484       break;
00485     case 'd':
00486       if (startsWithWord(name, "default")) return OIT_ReturnsSelf;
00487       if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
00488       break;
00489     case 's':
00490       if (startsWithWord(name, "shared")) return OIT_ReturnsSelf;
00491       if (startsWithWord(name, "standard")) return OIT_Singleton;
00492     case 'i':
00493       if (startsWithWord(name, "init")) return OIT_Init;
00494     default:
00495       break;
00496   }
00497   return OIT_None;
00498 }
00499 
00500 ObjCStringFormatFamily Selector::getStringFormatFamilyImpl(Selector sel) {
00501   IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
00502   if (!first) return SFF_None;
00503   
00504   StringRef name = first->getName();
00505   
00506   switch (name.front()) {
00507     case 'a':
00508       if (name == "appendFormat") return SFF_NSString;
00509       break;
00510       
00511     case 'i':
00512       if (name == "initWithFormat") return SFF_NSString;
00513       break;
00514       
00515     case 'l':
00516       if (name == "localizedStringWithFormat") return SFF_NSString;
00517       break;
00518       
00519     case 's':
00520       if (name == "stringByAppendingFormat" ||
00521           name == "stringWithFormat") return SFF_NSString;
00522       break;
00523   }
00524   return SFF_None;
00525 }
00526 
00527 namespace {
00528   struct SelectorTableImpl {
00529     llvm::FoldingSet<MultiKeywordSelector> Table;
00530     llvm::BumpPtrAllocator Allocator;
00531   };
00532 } // end anonymous namespace.
00533 
00534 static SelectorTableImpl &getSelectorTableImpl(void *P) {
00535   return *static_cast<SelectorTableImpl*>(P);
00536 }
00537 
00538 SmallString<64>
00539 SelectorTable::constructSetterName(StringRef Name) {
00540   SmallString<64> SetterName("set");
00541   SetterName += Name;
00542   SetterName[3] = toUppercase(SetterName[3]);
00543   return SetterName;
00544 }
00545 
00546 Selector
00547 SelectorTable::constructSetterSelector(IdentifierTable &Idents,
00548                                        SelectorTable &SelTable,
00549                                        const IdentifierInfo *Name) {
00550   IdentifierInfo *SetterName =
00551     &Idents.get(constructSetterName(Name->getName()));
00552   return SelTable.getUnarySelector(SetterName);
00553 }
00554 
00555 size_t SelectorTable::getTotalMemory() const {
00556   SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
00557   return SelTabImpl.Allocator.getTotalMemory();
00558 }
00559 
00560 Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
00561   if (nKeys < 2)
00562     return Selector(IIV[0], nKeys);
00563 
00564   SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
00565 
00566   // Unique selector, to guarantee there is one per name.
00567   llvm::FoldingSetNodeID ID;
00568   MultiKeywordSelector::Profile(ID, IIV, nKeys);
00569 
00570   void *InsertPos = nullptr;
00571   if (MultiKeywordSelector *SI =
00572         SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
00573     return Selector(SI);
00574 
00575   // MultiKeywordSelector objects are not allocated with new because they have a
00576   // variable size array (for parameter types) at the end of them.
00577   unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
00578   MultiKeywordSelector *SI =
00579     (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
00580                                          llvm::alignOf<MultiKeywordSelector>());
00581   new (SI) MultiKeywordSelector(nKeys, IIV);
00582   SelTabImpl.Table.InsertNode(SI, InsertPos);
00583   return Selector(SI);
00584 }
00585 
00586 SelectorTable::SelectorTable() {
00587   Impl = new SelectorTableImpl();
00588 }
00589 
00590 SelectorTable::~SelectorTable() {
00591   delete &getSelectorTableImpl(Impl);
00592 }
00593 
00594 const char *clang::getOperatorSpelling(OverloadedOperatorKind Operator) {
00595   switch (Operator) {
00596   case OO_None:
00597   case NUM_OVERLOADED_OPERATORS:
00598     return nullptr;
00599 
00600 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
00601   case OO_##Name: return Spelling;
00602 #include "clang/Basic/OperatorKinds.def"
00603   }
00604 
00605   llvm_unreachable("Invalid OverloadedOperatorKind!");
00606 }