blob: 16a61b7156fa8e24793568aa30143c85f0ffb417 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- IdentifierTable.cpp - Hash table for identifier lookup -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the IdentifierInfo, IdentifierVisitor, and
11// IdentifierTable interfaces.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattnerc7229c32007-10-07 08:58:51 +000015#include "clang/Basic/IdentifierTable.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Basic/LangOptions.h"
Steve Naroff29238a02007-10-05 18:42:47 +000017#include "llvm/ADT/FoldingSet.h"
Chris Lattner85994262007-10-05 20:15:24 +000018#include "llvm/ADT/DenseMap.h"
Daniel Dunbar76b61cc2009-10-17 18:13:02 +000019#include "llvm/Support/raw_ostream.h"
Chris Lattner3daed522009-03-02 22:20:04 +000020#include <cstdio>
Ted Kremenekc637e6b2007-10-23 22:18:37 +000021
Reid Spencer5f016e22007-07-11 17:01:13 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// IdentifierInfo Implementation
26//===----------------------------------------------------------------------===//
27
Ted Kremenekea9c26b2009-01-20 23:28:34 +000028IdentifierInfo::IdentifierInfo() {
Reid Spencer5f016e22007-07-11 17:01:13 +000029 TokenID = tok::identifier;
Douglas Gregor5142af32008-11-06 16:32:23 +000030 ObjCOrBuiltinID = 0;
Chris Lattner4365a7e2007-10-07 07:09:52 +000031 HasMacro = false;
Reid Spencer5f016e22007-07-11 17:01:13 +000032 IsExtension = false;
33 IsPoisoned = false;
Reid Spencer5f016e22007-07-11 17:01:13 +000034 IsCPPOperatorKeyword = false;
Chris Lattner6a170eb2009-01-21 07:43:11 +000035 NeedsHandleIdentifier = false;
Reid Spencer5f016e22007-07-11 17:01:13 +000036 FETokenInfo = 0;
Ted Kremenekea9c26b2009-01-20 23:28:34 +000037 Entry = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +000038}
39
Reid Spencer5f016e22007-07-11 17:01:13 +000040//===----------------------------------------------------------------------===//
41// IdentifierTable Implementation
42//===----------------------------------------------------------------------===//
43
Ted Kremenek72b1b152009-01-15 18:47:46 +000044IdentifierInfoLookup::~IdentifierInfoLookup() {}
45
Douglas Gregor8c5a7602009-04-25 23:30:02 +000046ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
47
Ted Kremenek72b1b152009-01-15 18:47:46 +000048IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
49 IdentifierInfoLookup* externalLookup)
50 : HashTable(8192), // Start with space for 8K identifiers.
51 ExternalLookup(externalLookup) {
Reid Spencer5f016e22007-07-11 17:01:13 +000052
53 // Populate the identifier table with info about keywords for the current
54 // language.
55 AddKeywords(LangOpts);
56}
57
58//===----------------------------------------------------------------------===//
59// Language Keyword Implementation
60//===----------------------------------------------------------------------===//
61
Eli Friedmaneb32fde2009-04-28 03:13:54 +000062// Constants for TokenKinds.def
63namespace {
64 enum {
65 KEYALL = 1,
66 KEYC99 = 2,
67 KEYCXX = 4,
68 KEYCXX0X = 8,
69 KEYGNU = 16,
Nate Begeman72b60e32009-06-25 23:25:15 +000070 KEYMS = 32,
John Thompson82287d12010-02-05 00:12:22 +000071 BOOLSUPPORT = 64,
72 KEYALTIVEC = 128
Eli Friedmaneb32fde2009-04-28 03:13:54 +000073 };
74}
75
Reid Spencer5f016e22007-07-11 17:01:13 +000076/// AddKeyword - This method is used to associate a token ID with specific
77/// identifiers because they are language keywords. This causes the lexer to
78/// automatically map matching identifiers to specialized token codes.
79///
Chris Lattnerd4b80f12007-07-16 04:18:29 +000080/// The C90/C99/CPP/CPP0x flags are set to 0 if the token should be
81/// enabled in the specified langauge, set to 1 if it is an extension
82/// in the specified language, and set to 2 if disabled in the
83/// specified language.
Reid Spencer5f016e22007-07-11 17:01:13 +000084static void AddKeyword(const char *Keyword, unsigned KWLen,
Eli Friedmaneb32fde2009-04-28 03:13:54 +000085 tok::TokenKind TokenCode, unsigned Flags,
Reid Spencer5f016e22007-07-11 17:01:13 +000086 const LangOptions &LangOpts, IdentifierTable &Table) {
Eli Friedmaneb32fde2009-04-28 03:13:54 +000087 unsigned AddResult = 0;
88 if (Flags & KEYALL) AddResult = 2;
89 else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2;
90 else if (LangOpts.CPlusPlus0x && (Flags & KEYCXX0X)) AddResult = 2;
91 else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
92 else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
93 else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
Chris Lattnere4f21422009-06-30 01:26:17 +000094 else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
John Thompson82287d12010-02-05 00:12:22 +000095 else if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) AddResult = 2;
Eli Friedmaneb32fde2009-04-28 03:13:54 +000096
97 // Don't add this keyword if disabled in this language.
98 if (AddResult == 0) return;
99
Reid Spencer5f016e22007-07-11 17:01:13 +0000100 IdentifierInfo &Info = Table.get(Keyword, Keyword+KWLen);
101 Info.setTokenID(TokenCode);
Eli Friedmaneb32fde2009-04-28 03:13:54 +0000102 Info.setIsExtensionToken(AddResult == 1);
Reid Spencer5f016e22007-07-11 17:01:13 +0000103}
104
Reid Spencer5f016e22007-07-11 17:01:13 +0000105/// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
106/// representations.
107static void AddCXXOperatorKeyword(const char *Keyword, unsigned KWLen,
108 tok::TokenKind TokenCode,
109 IdentifierTable &Table) {
110 IdentifierInfo &Info = Table.get(Keyword, Keyword + KWLen);
111 Info.setTokenID(TokenCode);
Ted Kremenekc637e6b2007-10-23 22:18:37 +0000112 Info.setIsCPlusPlusOperatorKeyword();
Reid Spencer5f016e22007-07-11 17:01:13 +0000113}
114
Mike Stump1eb44332009-09-09 15:08:12 +0000115/// AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or
Reid Spencer5f016e22007-07-11 17:01:13 +0000116/// "property".
Mike Stump1eb44332009-09-09 15:08:12 +0000117static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID,
Reid Spencer5f016e22007-07-11 17:01:13 +0000118 const char *Name, unsigned NameLen,
119 IdentifierTable &Table) {
120 Table.get(Name, Name+NameLen).setObjCKeywordID(ObjCID);
121}
122
123/// AddKeywords - Add all keywords to the symbol table.
124///
125void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000126 // Add keywords and tokens for the current language.
127#define KEYWORD(NAME, FLAGS) \
128 AddKeyword(#NAME, strlen(#NAME), tok::kw_ ## NAME, \
Eli Friedmaneb32fde2009-04-28 03:13:54 +0000129 FLAGS, LangOpts, *this);
130#define ALIAS(NAME, TOK, FLAGS) \
131 AddKeyword(NAME, strlen(NAME), tok::kw_ ## TOK, \
132 FLAGS, LangOpts, *this);
Reid Spencer5f016e22007-07-11 17:01:13 +0000133#define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
134 if (LangOpts.CXXOperatorNames) \
135 AddCXXOperatorKeyword(#NAME, strlen(#NAME), tok::ALIAS, *this);
136#define OBJC1_AT_KEYWORD(NAME) \
137 if (LangOpts.ObjC1) \
138 AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
139#define OBJC2_AT_KEYWORD(NAME) \
140 if (LangOpts.ObjC2) \
141 AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
142#include "clang/Basic/TokenKinds.def"
143}
144
Chris Lattner387b98d2007-10-07 07:52:34 +0000145tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
146 // We use a perfect hash function here involving the length of the keyword,
147 // the first and third character. For preprocessor ID's there are no
148 // collisions (if there were, the switch below would complain about duplicate
149 // case values). Note that this depends on 'if' being null terminated.
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Chris Lattner387b98d2007-10-07 07:52:34 +0000151#define HASH(LEN, FIRST, THIRD) \
152 (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
153#define CASE(LEN, FIRST, THIRD, NAME) \
154 case HASH(LEN, FIRST, THIRD): \
155 return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Chris Lattner387b98d2007-10-07 07:52:34 +0000157 unsigned Len = getLength();
Chris Lattnera31f0302007-10-10 20:59:57 +0000158 if (Len < 2) return tok::pp_not_keyword;
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000159 const char *Name = getNameStart();
Chris Lattner387b98d2007-10-07 07:52:34 +0000160 switch (HASH(Len, Name[0], Name[2])) {
161 default: return tok::pp_not_keyword;
162 CASE( 2, 'i', '\0', if);
163 CASE( 4, 'e', 'i', elif);
164 CASE( 4, 'e', 's', else);
165 CASE( 4, 'l', 'n', line);
166 CASE( 4, 's', 'c', sccs);
167 CASE( 5, 'e', 'd', endif);
168 CASE( 5, 'e', 'r', error);
169 CASE( 5, 'i', 'e', ident);
170 CASE( 5, 'i', 'd', ifdef);
171 CASE( 5, 'u', 'd', undef);
172
173 CASE( 6, 'a', 's', assert);
174 CASE( 6, 'd', 'f', define);
175 CASE( 6, 'i', 'n', ifndef);
176 CASE( 6, 'i', 'p', import);
177 CASE( 6, 'p', 'a', pragma);
178
179 CASE( 7, 'd', 'f', defined);
180 CASE( 7, 'i', 'c', include);
181 CASE( 7, 'w', 'r', warning);
182
183 CASE( 8, 'u', 'a', unassert);
184 CASE(12, 'i', 'c', include_next);
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Chris Lattnerb8e240e2009-04-08 18:24:34 +0000186 CASE(16, '_', 'i', __include_macros);
Chris Lattner387b98d2007-10-07 07:52:34 +0000187#undef CASE
188#undef HASH
189 }
190}
Reid Spencer5f016e22007-07-11 17:01:13 +0000191
192//===----------------------------------------------------------------------===//
193// Stats Implementation
194//===----------------------------------------------------------------------===//
195
196/// PrintStats - Print statistics about how well the identifier table is doing
197/// at hashing identifiers.
198void IdentifierTable::PrintStats() const {
199 unsigned NumBuckets = HashTable.getNumBuckets();
200 unsigned NumIdentifiers = HashTable.getNumItems();
201 unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
202 unsigned AverageIdentifierSize = 0;
203 unsigned MaxIdentifierLength = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000204
Reid Spencer5f016e22007-07-11 17:01:13 +0000205 // TODO: Figure out maximum times an identifier had to probe for -stats.
Ted Kremenekea9c26b2009-01-20 23:28:34 +0000206 for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
Reid Spencer5f016e22007-07-11 17:01:13 +0000207 I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
208 unsigned IdLen = I->getKeyLength();
209 AverageIdentifierSize += IdLen;
210 if (MaxIdentifierLength < IdLen)
211 MaxIdentifierLength = IdLen;
212 }
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Reid Spencer5f016e22007-07-11 17:01:13 +0000214 fprintf(stderr, "\n*** Identifier Table Stats:\n");
215 fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
216 fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
217 fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
218 NumIdentifiers/(double)NumBuckets);
219 fprintf(stderr, "Ave identifier length: %f\n",
220 (AverageIdentifierSize/(double)NumIdentifiers));
221 fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Reid Spencer5f016e22007-07-11 17:01:13 +0000223 // Compute statistics about the memory allocated for identifiers.
224 HashTable.getAllocator().PrintStats();
225}
Steve Naroff68d331a2007-09-27 14:38:14 +0000226
Steve Naroff29238a02007-10-05 18:42:47 +0000227//===----------------------------------------------------------------------===//
228// SelectorTable Implementation
229//===----------------------------------------------------------------------===//
230
Chris Lattner85994262007-10-05 20:15:24 +0000231unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
232 return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
233}
234
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000235namespace clang {
Steve Naroff29238a02007-10-05 18:42:47 +0000236/// MultiKeywordSelector - One of these variable length records is kept for each
237/// selector containing more than one keyword. We use a folding set
Mike Stump1eb44332009-09-09 15:08:12 +0000238/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
Steve Naroff29238a02007-10-05 18:42:47 +0000239/// this class is provided strictly through Selector.
Mike Stump1eb44332009-09-09 15:08:12 +0000240class MultiKeywordSelector
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000241 : public DeclarationNameExtra, public llvm::FoldingSetNode {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000242 MultiKeywordSelector(unsigned nKeys) {
243 ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
244 }
Mike Stump1eb44332009-09-09 15:08:12 +0000245public:
Steve Naroff29238a02007-10-05 18:42:47 +0000246 // Constructor for keyword selectors.
247 MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
248 assert((nKeys > 1) && "not a multi-keyword selector");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000249 ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
Mike Stump1eb44332009-09-09 15:08:12 +0000250
Steve Naroff29238a02007-10-05 18:42:47 +0000251 // Fill in the trailing keyword array.
252 IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
253 for (unsigned i = 0; i != nKeys; ++i)
254 KeyInfo[i] = IIV[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000255 }
256
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000257 // getName - Derive the full selector name and return it.
258 std::string getName() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000259
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000260 unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
Mike Stump1eb44332009-09-09 15:08:12 +0000261
Steve Naroff29238a02007-10-05 18:42:47 +0000262 typedef IdentifierInfo *const *keyword_iterator;
263 keyword_iterator keyword_begin() const {
264 return reinterpret_cast<keyword_iterator>(this+1);
265 }
Mike Stump1eb44332009-09-09 15:08:12 +0000266 keyword_iterator keyword_end() const {
267 return keyword_begin()+getNumArgs();
Steve Naroff29238a02007-10-05 18:42:47 +0000268 }
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000269 IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000270 assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
Steve Naroff29238a02007-10-05 18:42:47 +0000271 return keyword_begin()[i];
272 }
Mike Stump1eb44332009-09-09 15:08:12 +0000273 static void Profile(llvm::FoldingSetNodeID &ID,
Steve Naroff29238a02007-10-05 18:42:47 +0000274 keyword_iterator ArgTys, unsigned NumArgs) {
275 ID.AddInteger(NumArgs);
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000276 for (unsigned i = 0; i != NumArgs; ++i)
277 ID.AddPointer(ArgTys[i]);
Steve Naroff29238a02007-10-05 18:42:47 +0000278 }
279 void Profile(llvm::FoldingSetNodeID &ID) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000280 Profile(ID, keyword_begin(), getNumArgs());
Steve Naroff29238a02007-10-05 18:42:47 +0000281 }
282};
Chris Lattner85994262007-10-05 20:15:24 +0000283} // end namespace clang.
Steve Naroff29238a02007-10-05 18:42:47 +0000284
285unsigned Selector::getNumArgs() const {
286 unsigned IIF = getIdentifierInfoFlag();
287 if (IIF == ZeroArg)
288 return 0;
289 if (IIF == OneArg)
290 return 1;
291 // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
292 MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
Mike Stump1eb44332009-09-09 15:08:12 +0000293 return SI->getNumArgs();
Steve Naroff29238a02007-10-05 18:42:47 +0000294}
295
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000296IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
Douglas Gregor405bad02009-04-26 22:20:50 +0000297 if (getIdentifierInfoFlag()) {
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000298 assert(argIndex == 0 && "illegal keyword index");
Douglas Gregor405bad02009-04-26 22:20:50 +0000299 return getAsIdentifierInfo();
Steve Naroff29238a02007-10-05 18:42:47 +0000300 }
301 // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
302 MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
303 return SI->getIdentifierInfoForSlot(argIndex);
304}
305
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000306std::string MultiKeywordSelector::getName() const {
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000307 llvm::SmallString<256> Str;
308 llvm::raw_svector_ostream OS(Str);
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000309 for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
310 if (*I)
Daniel Dunbar01eb9b92009-10-18 21:17:35 +0000311 OS << (*I)->getName();
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000312 OS << ':';
Steve Naroff29238a02007-10-05 18:42:47 +0000313 }
Mike Stump1eb44332009-09-09 15:08:12 +0000314
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000315 return OS.str();
Steve Naroff29238a02007-10-05 18:42:47 +0000316}
317
Chris Lattner077bf5e2008-11-24 03:33:13 +0000318std::string Selector::getAsString() const {
Douglas Gregor405bad02009-04-26 22:20:50 +0000319 if (InfoPtr == 0)
320 return "<null selector>";
321
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000322 if (InfoPtr & ArgFlags) {
323 IdentifierInfo *II = getAsIdentifierInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000324
Ted Kremenek150ec292009-03-07 01:22:02 +0000325 // If the number of arguments is 0 then II is guaranteed to not be null.
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000326 if (getNumArgs() == 0)
Daniel Dunbar01eb9b92009-10-18 21:17:35 +0000327 return II->getName();
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000328
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000329 if (!II)
330 return ":";
331
Daniel Dunbar01eb9b92009-10-18 21:17:35 +0000332 return II->getName().str() + ":";
Steve Naroff29238a02007-10-05 18:42:47 +0000333 }
Mike Stump1eb44332009-09-09 15:08:12 +0000334
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000335 // We have a multiple keyword selector (no embedded flags).
336 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr)->getName();
Steve Naroff29238a02007-10-05 18:42:47 +0000337}
338
339
Chris Lattner5f7d2282009-03-04 05:35:38 +0000340namespace {
341 struct SelectorTableImpl {
342 llvm::FoldingSet<MultiKeywordSelector> Table;
343 llvm::BumpPtrAllocator Allocator;
344 };
345} // end anonymous namespace.
346
347static SelectorTableImpl &getSelectorTableImpl(void *P) {
348 return *static_cast<SelectorTableImpl*>(P);
349}
350
351
Chris Lattnerff384912007-10-07 02:00:24 +0000352Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
353 if (nKeys < 2)
354 return Selector(IIV[0], nKeys);
Mike Stump1eb44332009-09-09 15:08:12 +0000355
Chris Lattner5f7d2282009-03-04 05:35:38 +0000356 SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
Mike Stump1eb44332009-09-09 15:08:12 +0000357
Steve Naroff29238a02007-10-05 18:42:47 +0000358 // Unique selector, to guarantee there is one per name.
359 llvm::FoldingSetNodeID ID;
360 MultiKeywordSelector::Profile(ID, IIV, nKeys);
361
362 void *InsertPos = 0;
Chris Lattner5f7d2282009-03-04 05:35:38 +0000363 if (MultiKeywordSelector *SI =
364 SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
Steve Naroff29238a02007-10-05 18:42:47 +0000365 return Selector(SI);
Mike Stump1eb44332009-09-09 15:08:12 +0000366
Steve Naroff29238a02007-10-05 18:42:47 +0000367 // MultiKeywordSelector objects are not allocated with new because they have a
368 // variable size array (for parameter types) at the end of them.
Chris Lattner5f7d2282009-03-04 05:35:38 +0000369 unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
370 MultiKeywordSelector *SI =
Mike Stump1eb44332009-09-09 15:08:12 +0000371 (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
Chris Lattner5f7d2282009-03-04 05:35:38 +0000372 llvm::alignof<MultiKeywordSelector>());
Steve Naroff29238a02007-10-05 18:42:47 +0000373 new (SI) MultiKeywordSelector(nKeys, IIV);
Chris Lattner5f7d2282009-03-04 05:35:38 +0000374 SelTabImpl.Table.InsertNode(SI, InsertPos);
Steve Naroff29238a02007-10-05 18:42:47 +0000375 return Selector(SI);
376}
377
Steve Naroff29238a02007-10-05 18:42:47 +0000378SelectorTable::SelectorTable() {
Chris Lattner5f7d2282009-03-04 05:35:38 +0000379 Impl = new SelectorTableImpl();
Steve Naroff29238a02007-10-05 18:42:47 +0000380}
381
382SelectorTable::~SelectorTable() {
Chris Lattner5f7d2282009-03-04 05:35:38 +0000383 delete &getSelectorTableImpl(Impl);
Steve Naroff29238a02007-10-05 18:42:47 +0000384}
385
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000386const char *clang::getOperatorSpelling(OverloadedOperatorKind Operator) {
387 switch (Operator) {
388 case OO_None:
389 case NUM_OVERLOADED_OPERATORS:
390 return 0;
391
392#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
393 case OO_##Name: return Spelling;
394#include "clang/Basic/OperatorKinds.def"
395 }
396
397 return 0;
398}
399