blob: 93c260fdbe17a180ed6b030778887cc26347915d [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"
Chris Lattner3daed522009-03-02 22:20:04 +000019#include <cstdio>
Ted Kremenekc637e6b2007-10-23 22:18:37 +000020
Reid Spencer5f016e22007-07-11 17:01:13 +000021using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// IdentifierInfo Implementation
25//===----------------------------------------------------------------------===//
26
Ted Kremenekea9c26b2009-01-20 23:28:34 +000027IdentifierInfo::IdentifierInfo() {
Reid Spencer5f016e22007-07-11 17:01:13 +000028 TokenID = tok::identifier;
Douglas Gregor5142af32008-11-06 16:32:23 +000029 ObjCOrBuiltinID = 0;
Chris Lattner4365a7e2007-10-07 07:09:52 +000030 HasMacro = false;
Reid Spencer5f016e22007-07-11 17:01:13 +000031 IsExtension = false;
32 IsPoisoned = false;
Reid Spencer5f016e22007-07-11 17:01:13 +000033 IsCPPOperatorKeyword = false;
Chris Lattner6a170eb2009-01-21 07:43:11 +000034 NeedsHandleIdentifier = false;
Reid Spencer5f016e22007-07-11 17:01:13 +000035 FETokenInfo = 0;
Ted Kremenekea9c26b2009-01-20 23:28:34 +000036 Entry = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +000037}
38
Reid Spencer5f016e22007-07-11 17:01:13 +000039//===----------------------------------------------------------------------===//
40// IdentifierTable Implementation
41//===----------------------------------------------------------------------===//
42
Ted Kremenek72b1b152009-01-15 18:47:46 +000043IdentifierInfoLookup::~IdentifierInfoLookup() {}
44
Douglas Gregor8c5a7602009-04-25 23:30:02 +000045ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
46
Ted Kremenek72b1b152009-01-15 18:47:46 +000047IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
48 IdentifierInfoLookup* externalLookup)
49 : HashTable(8192), // Start with space for 8K identifiers.
50 ExternalLookup(externalLookup) {
Reid Spencer5f016e22007-07-11 17:01:13 +000051
52 // Populate the identifier table with info about keywords for the current
53 // language.
54 AddKeywords(LangOpts);
55}
56
57//===----------------------------------------------------------------------===//
58// Language Keyword Implementation
59//===----------------------------------------------------------------------===//
60
Eli Friedmaneb32fde2009-04-28 03:13:54 +000061// Constants for TokenKinds.def
62namespace {
63 enum {
64 KEYALL = 1,
65 KEYC99 = 2,
66 KEYCXX = 4,
67 KEYCXX0X = 8,
68 KEYGNU = 16,
Nate Begeman72b60e32009-06-25 23:25:15 +000069 KEYMS = 32,
70 BOOLSUPPORT = 64
Eli Friedmaneb32fde2009-04-28 03:13:54 +000071 };
72}
73
Reid Spencer5f016e22007-07-11 17:01:13 +000074/// AddKeyword - This method is used to associate a token ID with specific
75/// identifiers because they are language keywords. This causes the lexer to
76/// automatically map matching identifiers to specialized token codes.
77///
Chris Lattnerd4b80f12007-07-16 04:18:29 +000078/// The C90/C99/CPP/CPP0x flags are set to 0 if the token should be
79/// enabled in the specified langauge, set to 1 if it is an extension
80/// in the specified language, and set to 2 if disabled in the
81/// specified language.
Reid Spencer5f016e22007-07-11 17:01:13 +000082static void AddKeyword(const char *Keyword, unsigned KWLen,
Eli Friedmaneb32fde2009-04-28 03:13:54 +000083 tok::TokenKind TokenCode, unsigned Flags,
Reid Spencer5f016e22007-07-11 17:01:13 +000084 const LangOptions &LangOpts, IdentifierTable &Table) {
Eli Friedmaneb32fde2009-04-28 03:13:54 +000085 unsigned AddResult = 0;
86 if (Flags & KEYALL) AddResult = 2;
87 else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2;
88 else if (LangOpts.CPlusPlus0x && (Flags & KEYCXX0X)) AddResult = 2;
89 else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
90 else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
91 else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
Chris Lattnere4f21422009-06-30 01:26:17 +000092 else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
Eli Friedmaneb32fde2009-04-28 03:13:54 +000093
94 // Don't add this keyword if disabled in this language.
95 if (AddResult == 0) return;
96
Reid Spencer5f016e22007-07-11 17:01:13 +000097 IdentifierInfo &Info = Table.get(Keyword, Keyword+KWLen);
98 Info.setTokenID(TokenCode);
Eli Friedmaneb32fde2009-04-28 03:13:54 +000099 Info.setIsExtensionToken(AddResult == 1);
Reid Spencer5f016e22007-07-11 17:01:13 +0000100}
101
Reid Spencer5f016e22007-07-11 17:01:13 +0000102/// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
103/// representations.
104static void AddCXXOperatorKeyword(const char *Keyword, unsigned KWLen,
105 tok::TokenKind TokenCode,
106 IdentifierTable &Table) {
107 IdentifierInfo &Info = Table.get(Keyword, Keyword + KWLen);
108 Info.setTokenID(TokenCode);
Ted Kremenekc637e6b2007-10-23 22:18:37 +0000109 Info.setIsCPlusPlusOperatorKeyword();
Reid Spencer5f016e22007-07-11 17:01:13 +0000110}
111
Mike Stump1eb44332009-09-09 15:08:12 +0000112/// AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or
Reid Spencer5f016e22007-07-11 17:01:13 +0000113/// "property".
Mike Stump1eb44332009-09-09 15:08:12 +0000114static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID,
Reid Spencer5f016e22007-07-11 17:01:13 +0000115 const char *Name, unsigned NameLen,
116 IdentifierTable &Table) {
117 Table.get(Name, Name+NameLen).setObjCKeywordID(ObjCID);
118}
119
120/// AddKeywords - Add all keywords to the symbol table.
121///
122void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000123 // Add keywords and tokens for the current language.
124#define KEYWORD(NAME, FLAGS) \
125 AddKeyword(#NAME, strlen(#NAME), tok::kw_ ## NAME, \
Eli Friedmaneb32fde2009-04-28 03:13:54 +0000126 FLAGS, LangOpts, *this);
127#define ALIAS(NAME, TOK, FLAGS) \
128 AddKeyword(NAME, strlen(NAME), tok::kw_ ## TOK, \
129 FLAGS, LangOpts, *this);
Reid Spencer5f016e22007-07-11 17:01:13 +0000130#define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
131 if (LangOpts.CXXOperatorNames) \
132 AddCXXOperatorKeyword(#NAME, strlen(#NAME), tok::ALIAS, *this);
133#define OBJC1_AT_KEYWORD(NAME) \
134 if (LangOpts.ObjC1) \
135 AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
136#define OBJC2_AT_KEYWORD(NAME) \
137 if (LangOpts.ObjC2) \
138 AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
139#include "clang/Basic/TokenKinds.def"
140}
141
Chris Lattner387b98d2007-10-07 07:52:34 +0000142tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
143 // We use a perfect hash function here involving the length of the keyword,
144 // the first and third character. For preprocessor ID's there are no
145 // collisions (if there were, the switch below would complain about duplicate
146 // case values). Note that this depends on 'if' being null terminated.
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Chris Lattner387b98d2007-10-07 07:52:34 +0000148#define HASH(LEN, FIRST, THIRD) \
149 (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
150#define CASE(LEN, FIRST, THIRD, NAME) \
151 case HASH(LEN, FIRST, THIRD): \
152 return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Chris Lattner387b98d2007-10-07 07:52:34 +0000154 unsigned Len = getLength();
Chris Lattnera31f0302007-10-10 20:59:57 +0000155 if (Len < 2) return tok::pp_not_keyword;
Chris Lattner387b98d2007-10-07 07:52:34 +0000156 const char *Name = getName();
157 switch (HASH(Len, Name[0], Name[2])) {
158 default: return tok::pp_not_keyword;
159 CASE( 2, 'i', '\0', if);
160 CASE( 4, 'e', 'i', elif);
161 CASE( 4, 'e', 's', else);
162 CASE( 4, 'l', 'n', line);
163 CASE( 4, 's', 'c', sccs);
164 CASE( 5, 'e', 'd', endif);
165 CASE( 5, 'e', 'r', error);
166 CASE( 5, 'i', 'e', ident);
167 CASE( 5, 'i', 'd', ifdef);
168 CASE( 5, 'u', 'd', undef);
169
170 CASE( 6, 'a', 's', assert);
171 CASE( 6, 'd', 'f', define);
172 CASE( 6, 'i', 'n', ifndef);
173 CASE( 6, 'i', 'p', import);
174 CASE( 6, 'p', 'a', pragma);
175
176 CASE( 7, 'd', 'f', defined);
177 CASE( 7, 'i', 'c', include);
178 CASE( 7, 'w', 'r', warning);
179
180 CASE( 8, 'u', 'a', unassert);
181 CASE(12, 'i', 'c', include_next);
Mike Stump1eb44332009-09-09 15:08:12 +0000182
Chris Lattnerb8e240e2009-04-08 18:24:34 +0000183 CASE(16, '_', 'i', __include_macros);
Chris Lattner387b98d2007-10-07 07:52:34 +0000184#undef CASE
185#undef HASH
186 }
187}
Reid Spencer5f016e22007-07-11 17:01:13 +0000188
189//===----------------------------------------------------------------------===//
190// Stats Implementation
191//===----------------------------------------------------------------------===//
192
193/// PrintStats - Print statistics about how well the identifier table is doing
194/// at hashing identifiers.
195void IdentifierTable::PrintStats() const {
196 unsigned NumBuckets = HashTable.getNumBuckets();
197 unsigned NumIdentifiers = HashTable.getNumItems();
198 unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
199 unsigned AverageIdentifierSize = 0;
200 unsigned MaxIdentifierLength = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000201
Reid Spencer5f016e22007-07-11 17:01:13 +0000202 // TODO: Figure out maximum times an identifier had to probe for -stats.
Ted Kremenekea9c26b2009-01-20 23:28:34 +0000203 for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
Reid Spencer5f016e22007-07-11 17:01:13 +0000204 I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
205 unsigned IdLen = I->getKeyLength();
206 AverageIdentifierSize += IdLen;
207 if (MaxIdentifierLength < IdLen)
208 MaxIdentifierLength = IdLen;
209 }
Mike Stump1eb44332009-09-09 15:08:12 +0000210
Reid Spencer5f016e22007-07-11 17:01:13 +0000211 fprintf(stderr, "\n*** Identifier Table Stats:\n");
212 fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
213 fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
214 fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
215 NumIdentifiers/(double)NumBuckets);
216 fprintf(stderr, "Ave identifier length: %f\n",
217 (AverageIdentifierSize/(double)NumIdentifiers));
218 fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
Mike Stump1eb44332009-09-09 15:08:12 +0000219
Reid Spencer5f016e22007-07-11 17:01:13 +0000220 // Compute statistics about the memory allocated for identifiers.
221 HashTable.getAllocator().PrintStats();
222}
Steve Naroff68d331a2007-09-27 14:38:14 +0000223
Steve Naroff29238a02007-10-05 18:42:47 +0000224//===----------------------------------------------------------------------===//
225// SelectorTable Implementation
226//===----------------------------------------------------------------------===//
227
Chris Lattner85994262007-10-05 20:15:24 +0000228unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
229 return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
230}
231
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000232namespace clang {
Steve Naroff29238a02007-10-05 18:42:47 +0000233/// MultiKeywordSelector - One of these variable length records is kept for each
234/// selector containing more than one keyword. We use a folding set
Mike Stump1eb44332009-09-09 15:08:12 +0000235/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
Steve Naroff29238a02007-10-05 18:42:47 +0000236/// this class is provided strictly through Selector.
Mike Stump1eb44332009-09-09 15:08:12 +0000237class MultiKeywordSelector
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000238 : public DeclarationNameExtra, public llvm::FoldingSetNode {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000239 MultiKeywordSelector(unsigned nKeys) {
240 ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
241 }
Mike Stump1eb44332009-09-09 15:08:12 +0000242public:
Steve Naroff29238a02007-10-05 18:42:47 +0000243 // Constructor for keyword selectors.
244 MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
245 assert((nKeys > 1) && "not a multi-keyword selector");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000246 ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
Mike Stump1eb44332009-09-09 15:08:12 +0000247
Steve Naroff29238a02007-10-05 18:42:47 +0000248 // Fill in the trailing keyword array.
249 IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
250 for (unsigned i = 0; i != nKeys; ++i)
251 KeyInfo[i] = IIV[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000252 }
253
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000254 // getName - Derive the full selector name and return it.
255 std::string getName() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000256
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000257 unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
Mike Stump1eb44332009-09-09 15:08:12 +0000258
Steve Naroff29238a02007-10-05 18:42:47 +0000259 typedef IdentifierInfo *const *keyword_iterator;
260 keyword_iterator keyword_begin() const {
261 return reinterpret_cast<keyword_iterator>(this+1);
262 }
Mike Stump1eb44332009-09-09 15:08:12 +0000263 keyword_iterator keyword_end() const {
264 return keyword_begin()+getNumArgs();
Steve Naroff29238a02007-10-05 18:42:47 +0000265 }
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000266 IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000267 assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
Steve Naroff29238a02007-10-05 18:42:47 +0000268 return keyword_begin()[i];
269 }
Mike Stump1eb44332009-09-09 15:08:12 +0000270 static void Profile(llvm::FoldingSetNodeID &ID,
Steve Naroff29238a02007-10-05 18:42:47 +0000271 keyword_iterator ArgTys, unsigned NumArgs) {
272 ID.AddInteger(NumArgs);
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000273 for (unsigned i = 0; i != NumArgs; ++i)
274 ID.AddPointer(ArgTys[i]);
Steve Naroff29238a02007-10-05 18:42:47 +0000275 }
276 void Profile(llvm::FoldingSetNodeID &ID) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000277 Profile(ID, keyword_begin(), getNumArgs());
Steve Naroff29238a02007-10-05 18:42:47 +0000278 }
279};
Chris Lattner85994262007-10-05 20:15:24 +0000280} // end namespace clang.
Steve Naroff29238a02007-10-05 18:42:47 +0000281
282unsigned Selector::getNumArgs() const {
283 unsigned IIF = getIdentifierInfoFlag();
284 if (IIF == ZeroArg)
285 return 0;
286 if (IIF == OneArg)
287 return 1;
288 // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
289 MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
Mike Stump1eb44332009-09-09 15:08:12 +0000290 return SI->getNumArgs();
Steve Naroff29238a02007-10-05 18:42:47 +0000291}
292
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000293IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
Douglas Gregor405bad02009-04-26 22:20:50 +0000294 if (getIdentifierInfoFlag()) {
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000295 assert(argIndex == 0 && "illegal keyword index");
Douglas Gregor405bad02009-04-26 22:20:50 +0000296 return getAsIdentifierInfo();
Steve Naroff29238a02007-10-05 18:42:47 +0000297 }
298 // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
299 MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
300 return SI->getIdentifierInfoForSlot(argIndex);
301}
302
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000303std::string MultiKeywordSelector::getName() const {
304 std::string Result;
305 unsigned Length = 0;
306 for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
307 if (*I)
308 Length += (*I)->getLength();
309 ++Length; // :
Steve Naroff29238a02007-10-05 18:42:47 +0000310 }
Mike Stump1eb44332009-09-09 15:08:12 +0000311
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000312 Result.reserve(Length);
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000314 for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
315 if (*I)
316 Result.insert(Result.end(), (*I)->getName(),
317 (*I)->getName()+(*I)->getLength());
318 Result.push_back(':');
319 }
Mike Stump1eb44332009-09-09 15:08:12 +0000320
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000321 return Result;
Steve Naroff29238a02007-10-05 18:42:47 +0000322}
323
Chris Lattner077bf5e2008-11-24 03:33:13 +0000324std::string Selector::getAsString() const {
Douglas Gregor405bad02009-04-26 22:20:50 +0000325 if (InfoPtr == 0)
326 return "<null selector>";
327
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000328 if (InfoPtr & ArgFlags) {
329 IdentifierInfo *II = getAsIdentifierInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000330
Ted Kremenek150ec292009-03-07 01:22:02 +0000331 // If the number of arguments is 0 then II is guaranteed to not be null.
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000332 if (getNumArgs() == 0)
Ted Kremenek150ec292009-03-07 01:22:02 +0000333 return II->getName();
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000334
335 std::string Res = II ? II->getName() : "";
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000336 Res += ":";
337 return Res;
Steve Naroff29238a02007-10-05 18:42:47 +0000338 }
Mike Stump1eb44332009-09-09 15:08:12 +0000339
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000340 // We have a multiple keyword selector (no embedded flags).
341 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr)->getName();
Steve Naroff29238a02007-10-05 18:42:47 +0000342}
343
344
Chris Lattner5f7d2282009-03-04 05:35:38 +0000345namespace {
346 struct SelectorTableImpl {
347 llvm::FoldingSet<MultiKeywordSelector> Table;
348 llvm::BumpPtrAllocator Allocator;
349 };
350} // end anonymous namespace.
351
352static SelectorTableImpl &getSelectorTableImpl(void *P) {
353 return *static_cast<SelectorTableImpl*>(P);
354}
355
356
Chris Lattnerff384912007-10-07 02:00:24 +0000357Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
358 if (nKeys < 2)
359 return Selector(IIV[0], nKeys);
Mike Stump1eb44332009-09-09 15:08:12 +0000360
Chris Lattner5f7d2282009-03-04 05:35:38 +0000361 SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
Mike Stump1eb44332009-09-09 15:08:12 +0000362
Steve Naroff29238a02007-10-05 18:42:47 +0000363 // Unique selector, to guarantee there is one per name.
364 llvm::FoldingSetNodeID ID;
365 MultiKeywordSelector::Profile(ID, IIV, nKeys);
366
367 void *InsertPos = 0;
Chris Lattner5f7d2282009-03-04 05:35:38 +0000368 if (MultiKeywordSelector *SI =
369 SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
Steve Naroff29238a02007-10-05 18:42:47 +0000370 return Selector(SI);
Mike Stump1eb44332009-09-09 15:08:12 +0000371
Steve Naroff29238a02007-10-05 18:42:47 +0000372 // MultiKeywordSelector objects are not allocated with new because they have a
373 // variable size array (for parameter types) at the end of them.
Chris Lattner5f7d2282009-03-04 05:35:38 +0000374 unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
375 MultiKeywordSelector *SI =
Mike Stump1eb44332009-09-09 15:08:12 +0000376 (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
Chris Lattner5f7d2282009-03-04 05:35:38 +0000377 llvm::alignof<MultiKeywordSelector>());
Steve Naroff29238a02007-10-05 18:42:47 +0000378 new (SI) MultiKeywordSelector(nKeys, IIV);
Chris Lattner5f7d2282009-03-04 05:35:38 +0000379 SelTabImpl.Table.InsertNode(SI, InsertPos);
Steve Naroff29238a02007-10-05 18:42:47 +0000380 return Selector(SI);
381}
382
Steve Naroff29238a02007-10-05 18:42:47 +0000383SelectorTable::SelectorTable() {
Chris Lattner5f7d2282009-03-04 05:35:38 +0000384 Impl = new SelectorTableImpl();
Steve Naroff29238a02007-10-05 18:42:47 +0000385}
386
387SelectorTable::~SelectorTable() {
Chris Lattner5f7d2282009-03-04 05:35:38 +0000388 delete &getSelectorTableImpl(Impl);
Steve Naroff29238a02007-10-05 18:42:47 +0000389}
390