blob: a3c5c4a408d8df982eb7e1819816832b14f5f606 [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,
71 BOOLSUPPORT = 64
Eli Friedmaneb32fde2009-04-28 03:13:54 +000072 };
73}
74
Reid Spencer5f016e22007-07-11 17:01:13 +000075/// AddKeyword - This method is used to associate a token ID with specific
76/// identifiers because they are language keywords. This causes the lexer to
77/// automatically map matching identifiers to specialized token codes.
78///
Chris Lattnerd4b80f12007-07-16 04:18:29 +000079/// The C90/C99/CPP/CPP0x flags are set to 0 if the token should be
80/// enabled in the specified langauge, set to 1 if it is an extension
81/// in the specified language, and set to 2 if disabled in the
82/// specified language.
Reid Spencer5f016e22007-07-11 17:01:13 +000083static void AddKeyword(const char *Keyword, unsigned KWLen,
Eli Friedmaneb32fde2009-04-28 03:13:54 +000084 tok::TokenKind TokenCode, unsigned Flags,
Reid Spencer5f016e22007-07-11 17:01:13 +000085 const LangOptions &LangOpts, IdentifierTable &Table) {
Eli Friedmaneb32fde2009-04-28 03:13:54 +000086 unsigned AddResult = 0;
87 if (Flags & KEYALL) AddResult = 2;
88 else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2;
89 else if (LangOpts.CPlusPlus0x && (Flags & KEYCXX0X)) AddResult = 2;
90 else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
91 else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
92 else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
Chris Lattnere4f21422009-06-30 01:26:17 +000093 else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
Eli Friedmaneb32fde2009-04-28 03:13:54 +000094
95 // Don't add this keyword if disabled in this language.
96 if (AddResult == 0) return;
97
Reid Spencer5f016e22007-07-11 17:01:13 +000098 IdentifierInfo &Info = Table.get(Keyword, Keyword+KWLen);
99 Info.setTokenID(TokenCode);
Eli Friedmaneb32fde2009-04-28 03:13:54 +0000100 Info.setIsExtensionToken(AddResult == 1);
Reid Spencer5f016e22007-07-11 17:01:13 +0000101}
102
Reid Spencer5f016e22007-07-11 17:01:13 +0000103/// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
104/// representations.
105static void AddCXXOperatorKeyword(const char *Keyword, unsigned KWLen,
106 tok::TokenKind TokenCode,
107 IdentifierTable &Table) {
108 IdentifierInfo &Info = Table.get(Keyword, Keyword + KWLen);
109 Info.setTokenID(TokenCode);
Ted Kremenekc637e6b2007-10-23 22:18:37 +0000110 Info.setIsCPlusPlusOperatorKeyword();
Reid Spencer5f016e22007-07-11 17:01:13 +0000111}
112
Mike Stump1eb44332009-09-09 15:08:12 +0000113/// AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or
Reid Spencer5f016e22007-07-11 17:01:13 +0000114/// "property".
Mike Stump1eb44332009-09-09 15:08:12 +0000115static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID,
Reid Spencer5f016e22007-07-11 17:01:13 +0000116 const char *Name, unsigned NameLen,
117 IdentifierTable &Table) {
118 Table.get(Name, Name+NameLen).setObjCKeywordID(ObjCID);
119}
120
121/// AddKeywords - Add all keywords to the symbol table.
122///
123void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000124 // Add keywords and tokens for the current language.
125#define KEYWORD(NAME, FLAGS) \
126 AddKeyword(#NAME, strlen(#NAME), tok::kw_ ## NAME, \
Eli Friedmaneb32fde2009-04-28 03:13:54 +0000127 FLAGS, LangOpts, *this);
128#define ALIAS(NAME, TOK, FLAGS) \
129 AddKeyword(NAME, strlen(NAME), tok::kw_ ## TOK, \
130 FLAGS, LangOpts, *this);
Reid Spencer5f016e22007-07-11 17:01:13 +0000131#define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
132 if (LangOpts.CXXOperatorNames) \
133 AddCXXOperatorKeyword(#NAME, strlen(#NAME), tok::ALIAS, *this);
134#define OBJC1_AT_KEYWORD(NAME) \
135 if (LangOpts.ObjC1) \
136 AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
137#define OBJC2_AT_KEYWORD(NAME) \
138 if (LangOpts.ObjC2) \
139 AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
140#include "clang/Basic/TokenKinds.def"
141}
142
Chris Lattner387b98d2007-10-07 07:52:34 +0000143tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
144 // We use a perfect hash function here involving the length of the keyword,
145 // the first and third character. For preprocessor ID's there are no
146 // collisions (if there were, the switch below would complain about duplicate
147 // case values). Note that this depends on 'if' being null terminated.
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Chris Lattner387b98d2007-10-07 07:52:34 +0000149#define HASH(LEN, FIRST, THIRD) \
150 (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
151#define CASE(LEN, FIRST, THIRD, NAME) \
152 case HASH(LEN, FIRST, THIRD): \
153 return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Chris Lattner387b98d2007-10-07 07:52:34 +0000155 unsigned Len = getLength();
Chris Lattnera31f0302007-10-10 20:59:57 +0000156 if (Len < 2) return tok::pp_not_keyword;
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000157 const char *Name = getNameStart();
Chris Lattner387b98d2007-10-07 07:52:34 +0000158 switch (HASH(Len, Name[0], Name[2])) {
159 default: return tok::pp_not_keyword;
160 CASE( 2, 'i', '\0', if);
161 CASE( 4, 'e', 'i', elif);
162 CASE( 4, 'e', 's', else);
163 CASE( 4, 'l', 'n', line);
164 CASE( 4, 's', 'c', sccs);
165 CASE( 5, 'e', 'd', endif);
166 CASE( 5, 'e', 'r', error);
167 CASE( 5, 'i', 'e', ident);
168 CASE( 5, 'i', 'd', ifdef);
169 CASE( 5, 'u', 'd', undef);
170
171 CASE( 6, 'a', 's', assert);
172 CASE( 6, 'd', 'f', define);
173 CASE( 6, 'i', 'n', ifndef);
174 CASE( 6, 'i', 'p', import);
175 CASE( 6, 'p', 'a', pragma);
176
177 CASE( 7, 'd', 'f', defined);
178 CASE( 7, 'i', 'c', include);
179 CASE( 7, 'w', 'r', warning);
180
181 CASE( 8, 'u', 'a', unassert);
182 CASE(12, 'i', 'c', include_next);
Mike Stump1eb44332009-09-09 15:08:12 +0000183
Chris Lattnerb8e240e2009-04-08 18:24:34 +0000184 CASE(16, '_', 'i', __include_macros);
Chris Lattner387b98d2007-10-07 07:52:34 +0000185#undef CASE
186#undef HASH
187 }
188}
Reid Spencer5f016e22007-07-11 17:01:13 +0000189
190//===----------------------------------------------------------------------===//
191// Stats Implementation
192//===----------------------------------------------------------------------===//
193
194/// PrintStats - Print statistics about how well the identifier table is doing
195/// at hashing identifiers.
196void IdentifierTable::PrintStats() const {
197 unsigned NumBuckets = HashTable.getNumBuckets();
198 unsigned NumIdentifiers = HashTable.getNumItems();
199 unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
200 unsigned AverageIdentifierSize = 0;
201 unsigned MaxIdentifierLength = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000202
Reid Spencer5f016e22007-07-11 17:01:13 +0000203 // TODO: Figure out maximum times an identifier had to probe for -stats.
Ted Kremenekea9c26b2009-01-20 23:28:34 +0000204 for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
Reid Spencer5f016e22007-07-11 17:01:13 +0000205 I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
206 unsigned IdLen = I->getKeyLength();
207 AverageIdentifierSize += IdLen;
208 if (MaxIdentifierLength < IdLen)
209 MaxIdentifierLength = IdLen;
210 }
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Reid Spencer5f016e22007-07-11 17:01:13 +0000212 fprintf(stderr, "\n*** Identifier Table Stats:\n");
213 fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
214 fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
215 fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
216 NumIdentifiers/(double)NumBuckets);
217 fprintf(stderr, "Ave identifier length: %f\n",
218 (AverageIdentifierSize/(double)NumIdentifiers));
219 fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Reid Spencer5f016e22007-07-11 17:01:13 +0000221 // Compute statistics about the memory allocated for identifiers.
222 HashTable.getAllocator().PrintStats();
223}
Steve Naroff68d331a2007-09-27 14:38:14 +0000224
Steve Naroff29238a02007-10-05 18:42:47 +0000225//===----------------------------------------------------------------------===//
226// SelectorTable Implementation
227//===----------------------------------------------------------------------===//
228
Chris Lattner85994262007-10-05 20:15:24 +0000229unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
230 return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
231}
232
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000233namespace clang {
Steve Naroff29238a02007-10-05 18:42:47 +0000234/// MultiKeywordSelector - One of these variable length records is kept for each
235/// selector containing more than one keyword. We use a folding set
Mike Stump1eb44332009-09-09 15:08:12 +0000236/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
Steve Naroff29238a02007-10-05 18:42:47 +0000237/// this class is provided strictly through Selector.
Mike Stump1eb44332009-09-09 15:08:12 +0000238class MultiKeywordSelector
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000239 : public DeclarationNameExtra, public llvm::FoldingSetNode {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000240 MultiKeywordSelector(unsigned nKeys) {
241 ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
242 }
Mike Stump1eb44332009-09-09 15:08:12 +0000243public:
Steve Naroff29238a02007-10-05 18:42:47 +0000244 // Constructor for keyword selectors.
245 MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
246 assert((nKeys > 1) && "not a multi-keyword selector");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000247 ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
Mike Stump1eb44332009-09-09 15:08:12 +0000248
Steve Naroff29238a02007-10-05 18:42:47 +0000249 // Fill in the trailing keyword array.
250 IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
251 for (unsigned i = 0; i != nKeys; ++i)
252 KeyInfo[i] = IIV[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000253 }
254
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000255 // getName - Derive the full selector name and return it.
256 std::string getName() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000258 unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
Mike Stump1eb44332009-09-09 15:08:12 +0000259
Steve Naroff29238a02007-10-05 18:42:47 +0000260 typedef IdentifierInfo *const *keyword_iterator;
261 keyword_iterator keyword_begin() const {
262 return reinterpret_cast<keyword_iterator>(this+1);
263 }
Mike Stump1eb44332009-09-09 15:08:12 +0000264 keyword_iterator keyword_end() const {
265 return keyword_begin()+getNumArgs();
Steve Naroff29238a02007-10-05 18:42:47 +0000266 }
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000267 IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000268 assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
Steve Naroff29238a02007-10-05 18:42:47 +0000269 return keyword_begin()[i];
270 }
Mike Stump1eb44332009-09-09 15:08:12 +0000271 static void Profile(llvm::FoldingSetNodeID &ID,
Steve Naroff29238a02007-10-05 18:42:47 +0000272 keyword_iterator ArgTys, unsigned NumArgs) {
273 ID.AddInteger(NumArgs);
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000274 for (unsigned i = 0; i != NumArgs; ++i)
275 ID.AddPointer(ArgTys[i]);
Steve Naroff29238a02007-10-05 18:42:47 +0000276 }
277 void Profile(llvm::FoldingSetNodeID &ID) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000278 Profile(ID, keyword_begin(), getNumArgs());
Steve Naroff29238a02007-10-05 18:42:47 +0000279 }
280};
Chris Lattner85994262007-10-05 20:15:24 +0000281} // end namespace clang.
Steve Naroff29238a02007-10-05 18:42:47 +0000282
283unsigned Selector::getNumArgs() const {
284 unsigned IIF = getIdentifierInfoFlag();
285 if (IIF == ZeroArg)
286 return 0;
287 if (IIF == OneArg)
288 return 1;
289 // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
290 MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
Mike Stump1eb44332009-09-09 15:08:12 +0000291 return SI->getNumArgs();
Steve Naroff29238a02007-10-05 18:42:47 +0000292}
293
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000294IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
Douglas Gregor405bad02009-04-26 22:20:50 +0000295 if (getIdentifierInfoFlag()) {
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000296 assert(argIndex == 0 && "illegal keyword index");
Douglas Gregor405bad02009-04-26 22:20:50 +0000297 return getAsIdentifierInfo();
Steve Naroff29238a02007-10-05 18:42:47 +0000298 }
299 // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
300 MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
301 return SI->getIdentifierInfoForSlot(argIndex);
302}
303
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000304std::string MultiKeywordSelector::getName() const {
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000305 llvm::SmallString<256> Str;
306 llvm::raw_svector_ostream OS(Str);
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000307 for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
308 if (*I)
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000309 OS << (*I)->getNameStr();
310 OS << ':';
Steve Naroff29238a02007-10-05 18:42:47 +0000311 }
Mike Stump1eb44332009-09-09 15:08:12 +0000312
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000313 return OS.str();
Steve Naroff29238a02007-10-05 18:42:47 +0000314}
315
Chris Lattner077bf5e2008-11-24 03:33:13 +0000316std::string Selector::getAsString() const {
Douglas Gregor405bad02009-04-26 22:20:50 +0000317 if (InfoPtr == 0)
318 return "<null selector>";
319
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000320 if (InfoPtr & ArgFlags) {
321 IdentifierInfo *II = getAsIdentifierInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000322
Ted Kremenek150ec292009-03-07 01:22:02 +0000323 // If the number of arguments is 0 then II is guaranteed to not be null.
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000324 if (getNumArgs() == 0)
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000325 return II->getNameStr();
Ted Kremenekf5ed3962009-03-06 23:36:28 +0000326
Daniel Dunbar76b61cc2009-10-17 18:13:02 +0000327 if (!II)
328 return ":";
329
330 return II->getNameStr().str() + ":";
Steve Naroff29238a02007-10-05 18:42:47 +0000331 }
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Chris Lattnerf836e3f2007-10-07 01:33:16 +0000333 // We have a multiple keyword selector (no embedded flags).
334 return reinterpret_cast<MultiKeywordSelector *>(InfoPtr)->getName();
Steve Naroff29238a02007-10-05 18:42:47 +0000335}
336
337
Chris Lattner5f7d2282009-03-04 05:35:38 +0000338namespace {
339 struct SelectorTableImpl {
340 llvm::FoldingSet<MultiKeywordSelector> Table;
341 llvm::BumpPtrAllocator Allocator;
342 };
343} // end anonymous namespace.
344
345static SelectorTableImpl &getSelectorTableImpl(void *P) {
346 return *static_cast<SelectorTableImpl*>(P);
347}
348
349
Chris Lattnerff384912007-10-07 02:00:24 +0000350Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
351 if (nKeys < 2)
352 return Selector(IIV[0], nKeys);
Mike Stump1eb44332009-09-09 15:08:12 +0000353
Chris Lattner5f7d2282009-03-04 05:35:38 +0000354 SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
Mike Stump1eb44332009-09-09 15:08:12 +0000355
Steve Naroff29238a02007-10-05 18:42:47 +0000356 // Unique selector, to guarantee there is one per name.
357 llvm::FoldingSetNodeID ID;
358 MultiKeywordSelector::Profile(ID, IIV, nKeys);
359
360 void *InsertPos = 0;
Chris Lattner5f7d2282009-03-04 05:35:38 +0000361 if (MultiKeywordSelector *SI =
362 SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
Steve Naroff29238a02007-10-05 18:42:47 +0000363 return Selector(SI);
Mike Stump1eb44332009-09-09 15:08:12 +0000364
Steve Naroff29238a02007-10-05 18:42:47 +0000365 // MultiKeywordSelector objects are not allocated with new because they have a
366 // variable size array (for parameter types) at the end of them.
Chris Lattner5f7d2282009-03-04 05:35:38 +0000367 unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
368 MultiKeywordSelector *SI =
Mike Stump1eb44332009-09-09 15:08:12 +0000369 (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
Chris Lattner5f7d2282009-03-04 05:35:38 +0000370 llvm::alignof<MultiKeywordSelector>());
Steve Naroff29238a02007-10-05 18:42:47 +0000371 new (SI) MultiKeywordSelector(nKeys, IIV);
Chris Lattner5f7d2282009-03-04 05:35:38 +0000372 SelTabImpl.Table.InsertNode(SI, InsertPos);
Steve Naroff29238a02007-10-05 18:42:47 +0000373 return Selector(SI);
374}
375
Steve Naroff29238a02007-10-05 18:42:47 +0000376SelectorTable::SelectorTable() {
Chris Lattner5f7d2282009-03-04 05:35:38 +0000377 Impl = new SelectorTableImpl();
Steve Naroff29238a02007-10-05 18:42:47 +0000378}
379
380SelectorTable::~SelectorTable() {
Chris Lattner5f7d2282009-03-04 05:35:38 +0000381 delete &getSelectorTableImpl(Impl);
Steve Naroff29238a02007-10-05 18:42:47 +0000382}
383