blob: 6586fb32787c12c92cfbd82734c029c61901ebc1 [file] [log] [blame]
Chris Lattner9950c802008-04-11 07:06:57 +00001//===- IdentifierResolver.cpp - Lexical Scope Name lookup -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +000010// This file implements the IdentifierResolver class, which is used for lexical
Douglas Gregorae2fbad2008-11-17 20:34:05 +000011// scoped lookup, based on declaration names.
Chris Lattner9950c802008-04-11 07:06:57 +000012//
13//===----------------------------------------------------------------------===//
14
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000015#include "clang/Sema/IdentifierResolver.h"
John McCallde6836a2010-08-24 07:21:54 +000016#include "clang/AST/Decl.h"
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +000017#include "clang/Basic/LangOptions.h"
Douglas Gregor935bc7a22011-10-27 09:33:13 +000018#include "clang/Lex/ExternalPreprocessorSource.h"
19#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000020#include "clang/Sema/Scope.h"
Chris Lattner9950c802008-04-11 07:06:57 +000021
22using namespace clang;
23
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000024//===----------------------------------------------------------------------===//
25// IdDeclInfoMap class
26//===----------------------------------------------------------------------===//
Chris Lattner9950c802008-04-11 07:06:57 +000027
Douglas Gregorae2fbad2008-11-17 20:34:05 +000028/// IdDeclInfoMap - Associates IdDeclInfos with declaration names.
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +000029/// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each
Chris Lattner9950c802008-04-11 07:06:57 +000030/// individual IdDeclInfo to heap.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +000031class IdentifierResolver::IdDeclInfoMap {
John McCall5f5cbf52010-02-15 19:38:00 +000032 static const unsigned int POOL_SIZE = 512;
33
34 /// We use our own linked-list implementation because it is sadly
35 /// impossible to add something to a pre-C++0x STL container without
36 /// a completely unnecessary copy.
37 struct IdDeclInfoPool {
38 IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {}
39
40 IdDeclInfoPool *Next;
41 IdDeclInfo Pool[POOL_SIZE];
42 };
43
44 IdDeclInfoPool *CurPool;
Chris Lattner9950c802008-04-11 07:06:57 +000045 unsigned int CurIndex;
Mike Stump11289f42009-09-09 15:08:12 +000046
Chris Lattner9950c802008-04-11 07:06:57 +000047public:
Craig Topperc3ec1492014-05-26 06:22:03 +000048 IdDeclInfoMap() : CurPool(nullptr), CurIndex(POOL_SIZE) {}
John McCall5f5cbf52010-02-15 19:38:00 +000049
50 ~IdDeclInfoMap() {
51 IdDeclInfoPool *Cur = CurPool;
52 while (IdDeclInfoPool *P = Cur) {
53 Cur = Cur->Next;
54 delete P;
55 }
56 }
Chris Lattner9950c802008-04-11 07:06:57 +000057
Douglas Gregorae2fbad2008-11-17 20:34:05 +000058 /// Returns the IdDeclInfo associated to the DeclarationName.
Chris Lattner9950c802008-04-11 07:06:57 +000059 /// It creates a new IdDeclInfo if one was not created before for this id.
Douglas Gregorae2fbad2008-11-17 20:34:05 +000060 IdDeclInfo &operator[](DeclarationName Name);
Chris Lattner9950c802008-04-11 07:06:57 +000061};
62
Argyrios Kyrtzidis25f54c72008-04-14 00:09:21 +000063
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000064//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000065// IdDeclInfo Implementation
66//===----------------------------------------------------------------------===//
67
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000068/// RemoveDecl - Remove the decl from the scope chain.
69/// The decl must already be part of the decl chain.
70void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) {
71 for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) {
72 if (D == *(I-1)) {
73 Decls.erase(I-1);
74 return;
75 }
76 }
77
David Blaikie83d382b2011-09-23 05:06:16 +000078 llvm_unreachable("Didn't find this decl on its identifier's chain!");
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000079}
80
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000081//===----------------------------------------------------------------------===//
82// IdentifierResolver Implementation
83//===----------------------------------------------------------------------===//
84
Douglas Gregor935bc7a22011-10-27 09:33:13 +000085IdentifierResolver::IdentifierResolver(Preprocessor &PP)
David Blaikiebbafb8a2012-03-11 07:00:24 +000086 : LangOpt(PP.getLangOpts()), PP(PP),
Douglas Gregor935bc7a22011-10-27 09:33:13 +000087 IdDeclInfos(new IdDeclInfoMap) {
Argyrios Kyrtzidisf4b92e62008-09-09 21:32:02 +000088}
Douglas Gregor935bc7a22011-10-27 09:33:13 +000089
Argyrios Kyrtzidis25f54c72008-04-14 00:09:21 +000090IdentifierResolver::~IdentifierResolver() {
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +000091 delete IdDeclInfos;
Argyrios Kyrtzidis25f54c72008-04-14 00:09:21 +000092}
Chris Lattner9950c802008-04-11 07:06:57 +000093
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000094/// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
95/// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
96/// true if 'D' belongs to the given declaration context.
Nico Weber555d1aa2012-12-17 03:51:09 +000097bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S,
Richard Smith72bcaec2013-12-05 04:30:04 +000098 bool AllowInlineNamespace) const {
Sebastian Redl50c68252010-08-31 00:36:30 +000099 Ctx = Ctx->getRedeclContext();
Douglas Gregor07665a62009-01-05 19:45:36 +0000100
James Molloy6f8780b2012-02-29 10:24:19 +0000101 if (Ctx->isFunctionOrMethod() || S->isFunctionPrototypeScope()) {
Douglas Gregor07665a62009-01-05 19:45:36 +0000102 // Ignore the scopes associated within transparent declaration contexts.
Ted Kremenekc37877d2013-10-08 17:08:03 +0000103 while (S->getEntity() && S->getEntity()->isTransparentContext())
Douglas Gregor07665a62009-01-05 19:45:36 +0000104 S = S->getParent();
105
John McCall48871652010-08-21 09:40:31 +0000106 if (S->isDeclScope(D))
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +0000107 return true;
108 if (LangOpt.CPlusPlus) {
Sebastian Redlb219c902008-12-21 16:41:36 +0000109 // C++ 3.3.2p3:
110 // The name declared in a catch exception-declaration is local to the
111 // handler and shall not be redeclared in the outermost block of the
112 // handler.
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +0000113 // C++ 3.3.2p4:
114 // Names declared in the for-init-statement, and in the condition of if,
115 // while, for, and switch statements are local to the if, while, for, or
116 // switch statement (including the controlled statement), and shall not be
117 // redeclared in a subsequent condition of that statement nor in the
118 // outermost block (or, for the if statement, any of the outermost blocks)
119 // of the controlled statement.
120 //
121 assert(S->getParent() && "No TUScope?");
David Blaikie1c9c9042012-11-10 01:04:23 +0000122 if (S->getParent()->getFlags() & Scope::ControlScope) {
David Blaikie1d617802012-11-12 22:25:41 +0000123 S = S->getParent();
124 if (S->isDeclScope(D))
125 return true;
David Blaikie1c9c9042012-11-10 01:04:23 +0000126 }
David Blaikie1d617802012-11-12 22:25:41 +0000127 if (S->getFlags() & Scope::FnTryCatchScope)
128 return S->getParent()->isDeclScope(D);
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +0000129 }
130 return false;
131 }
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +0000132
Richard Smith5971e8c2014-08-27 22:31:34 +0000133 // FIXME: If D is a local extern declaration, this check doesn't make sense;
134 // we should be checking its lexical context instead in that case, because
135 // that is its scope.
Douglas Gregordb446112011-03-07 16:54:27 +0000136 DeclContext *DCtx = D->getDeclContext()->getRedeclContext();
Richard Smith72bcaec2013-12-05 04:30:04 +0000137 return AllowInlineNamespace ? Ctx->InEnclosingNamespaceSetOf(DCtx)
138 : Ctx->Equals(DCtx);
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +0000139}
140
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +0000141/// AddDecl - Link the decl to its shadowed decl chain.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000142void IdentifierResolver::AddDecl(NamedDecl *D) {
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000143 DeclarationName Name = D->getDeclName();
Sebastian Redl671eee92010-07-30 17:25:10 +0000144 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000145 updatingIdentifier(*II);
Sebastian Redl671eee92010-07-30 17:25:10 +0000146
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000147 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattner9950c802008-04-11 07:06:57 +0000148
149 if (!Ptr) {
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000150 Name.setFETokenInfo(D);
Chris Lattner9950c802008-04-11 07:06:57 +0000151 return;
152 }
153
154 IdDeclInfo *IDI;
155
156 if (isDeclPtr(Ptr)) {
Craig Topperc3ec1492014-05-26 06:22:03 +0000157 Name.setFETokenInfo(nullptr);
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000158 IDI = &(*IdDeclInfos)[Name];
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000159 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
160 IDI->AddDecl(PrevD);
Chris Lattner9950c802008-04-11 07:06:57 +0000161 } else
162 IDI = toIdDeclInfo(Ptr);
163
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000164 IDI->AddDecl(D);
Chris Lattner9950c802008-04-11 07:06:57 +0000165}
166
Douglas Gregor46c04e72011-03-16 16:39:03 +0000167void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
168 DeclarationName Name = D->getDeclName();
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000169 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
170 updatingIdentifier(*II);
171
Douglas Gregor46c04e72011-03-16 16:39:03 +0000172 void *Ptr = Name.getFETokenInfo<void>();
173
Douglas Gregor33f352c2011-03-24 10:35:39 +0000174 if (!Ptr) {
Douglas Gregor88764cf2011-03-14 21:19:51 +0000175 AddDecl(D);
176 return;
177 }
Douglas Gregor88764cf2011-03-14 21:19:51 +0000178
Douglas Gregor33f352c2011-03-24 10:35:39 +0000179 if (isDeclPtr(Ptr)) {
180 // We only have a single declaration: insert before or after it,
181 // as appropriate.
182 if (Pos == iterator()) {
183 // Add the new declaration before the existing declaration.
184 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
185 RemoveDecl(PrevD);
186 AddDecl(D);
187 AddDecl(PrevD);
188 } else {
189 // Add new declaration after the existing declaration.
190 AddDecl(D);
191 }
192
193 return;
194 }
195
Douglas Gregor88764cf2011-03-14 21:19:51 +0000196 // General case: insert the declaration at the appropriate point in the
197 // list, which already has at least two elements.
198 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
Douglas Gregor46c04e72011-03-16 16:39:03 +0000199 if (Pos.isIterator()) {
200 IDI->InsertDecl(Pos.getIterator() + 1, D);
201 } else
Douglas Gregor88764cf2011-03-14 21:19:51 +0000202 IDI->InsertDecl(IDI->decls_begin(), D);
203}
204
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +0000205/// RemoveDecl - Unlink the decl from its shadowed decl chain.
Chris Lattner9950c802008-04-11 07:06:57 +0000206/// The decl must already be part of the decl chain.
207void IdentifierResolver::RemoveDecl(NamedDecl *D) {
208 assert(D && "null param passed");
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000209 DeclarationName Name = D->getDeclName();
Sebastian Redl671eee92010-07-30 17:25:10 +0000210 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000211 updatingIdentifier(*II);
Sebastian Redl671eee92010-07-30 17:25:10 +0000212
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000213 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattner9950c802008-04-11 07:06:57 +0000214
215 assert(Ptr && "Didn't find this decl on its identifier's chain!");
216
217 if (isDeclPtr(Ptr)) {
218 assert(D == Ptr && "Didn't find this decl on its identifier's chain!");
Craig Topperc3ec1492014-05-26 06:22:03 +0000219 Name.setFETokenInfo(nullptr);
Chris Lattner9950c802008-04-11 07:06:57 +0000220 return;
221 }
Mike Stump11289f42009-09-09 15:08:12 +0000222
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000223 return toIdDeclInfo(Ptr)->RemoveDecl(D);
Chris Lattner9950c802008-04-11 07:06:57 +0000224}
225
Douglas Gregored8f2882009-01-30 01:04:22 +0000226/// begin - Returns an iterator for decls with name 'Name'.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000227IdentifierResolver::iterator
Douglas Gregored8f2882009-01-30 01:04:22 +0000228IdentifierResolver::begin(DeclarationName Name) {
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000229 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
230 readingIdentifier(*II);
231
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000232 void *Ptr = Name.getFETokenInfo<void>();
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000233 if (!Ptr) return end();
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000234
Chris Lattner9631e182009-03-04 06:34:08 +0000235 if (isDeclPtr(Ptr))
236 return iterator(static_cast<NamedDecl*>(Ptr));
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000237
Chris Lattner9950c802008-04-11 07:06:57 +0000238 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000239
Douglas Gregor07665a62009-01-05 19:45:36 +0000240 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000241 if (I != IDI->decls_begin())
Douglas Gregored8f2882009-01-30 01:04:22 +0000242 return iterator(I-1);
Chris Lattner9631e182009-03-04 06:34:08 +0000243 // No decls found.
244 return end();
Chris Lattner9950c802008-04-11 07:06:57 +0000245}
246
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000247namespace {
248 enum DeclMatchKind {
249 DMK_Different,
250 DMK_Replace,
251 DMK_Ignore
252 };
253}
Douglas Gregora868bbd2009-04-21 22:25:48 +0000254
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000255/// \brief Compare two declarations to see whether they are different or,
256/// if they are the same, whether the new declaration should replace the
257/// existing declaration.
258static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) {
259 // If the declarations are identical, ignore the new one.
260 if (Existing == New)
261 return DMK_Ignore;
262
263 // If the declarations have different kinds, they're obviously different.
264 if (Existing->getKind() != New->getKind())
265 return DMK_Different;
266
267 // If the declarations are redeclarations of each other, keep the newest one.
268 if (Existing->getCanonicalDecl() == New->getCanonicalDecl()) {
Douglas Gregordcf25082013-02-11 18:16:18 +0000269 // If either of these is the most recent declaration, use it.
270 Decl *MostRecent = Existing->getMostRecentDecl();
271 if (Existing == MostRecent)
272 return DMK_Ignore;
273
274 if (New == MostRecent)
275 return DMK_Replace;
276
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000277 // If the existing declaration is somewhere in the previous declaration
278 // chain of the new declaration, then prefer the new declaration.
Aaron Ballman86c93902014-03-06 23:45:36 +0000279 for (auto RD : New->redecls()) {
280 if (RD == Existing)
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000281 return DMK_Replace;
282
283 if (RD->isCanonicalDecl())
284 break;
285 }
286
287 return DMK_Ignore;
Douglas Gregora868bbd2009-04-21 22:25:48 +0000288 }
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000289
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000290 return DMK_Different;
291}
Douglas Gregora868bbd2009-04-21 22:25:48 +0000292
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000293bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){
294 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor247afcc2012-01-24 15:24:38 +0000295 readingIdentifier(*II);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000296
297 void *Ptr = Name.getFETokenInfo<void>();
298
299 if (!Ptr) {
300 Name.setFETokenInfo(D);
301 return true;
302 }
303
Douglas Gregora868bbd2009-04-21 22:25:48 +0000304 IdDeclInfo *IDI;
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000305
Douglas Gregora868bbd2009-04-21 22:25:48 +0000306 if (isDeclPtr(Ptr)) {
Douglas Gregora868bbd2009-04-21 22:25:48 +0000307 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000308
309 switch (compareDeclarations(PrevD, D)) {
310 case DMK_Different:
311 break;
312
313 case DMK_Ignore:
314 return false;
315
316 case DMK_Replace:
317 Name.setFETokenInfo(D);
318 return true;
319 }
Craig Topperc3ec1492014-05-26 06:22:03 +0000320
321 Name.setFETokenInfo(nullptr);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000322 IDI = &(*IdDeclInfos)[Name];
323
324 // If the existing declaration is not visible in translation unit scope,
325 // then add the new top-level declaration first.
326 if (!PrevD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
327 IDI->AddDecl(D);
328 IDI->AddDecl(PrevD);
329 } else {
330 IDI->AddDecl(PrevD);
331 IDI->AddDecl(D);
332 }
333 return true;
334 }
335
336 IDI = toIdDeclInfo(Ptr);
Douglas Gregora868bbd2009-04-21 22:25:48 +0000337
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000338 // See whether this declaration is identical to any existing declarations.
339 // If not, find the right place to insert it.
340 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
341 IEnd = IDI->decls_end();
342 I != IEnd; ++I) {
343
344 switch (compareDeclarations(*I, D)) {
345 case DMK_Different:
346 break;
347
348 case DMK_Ignore:
349 return false;
350
351 case DMK_Replace:
352 *I = D;
353 return true;
354 }
355
356 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
357 // We've found a declaration that is not visible from the translation
358 // unit (it's in an inner scope). Insert our declaration here.
359 IDI->InsertDecl(I, D);
360 return true;
361 }
362 }
363
364 // Add the declaration to the end.
Douglas Gregora868bbd2009-04-21 22:25:48 +0000365 IDI->AddDecl(D);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000366 return true;
367}
368
369void IdentifierResolver::readingIdentifier(IdentifierInfo &II) {
370 if (II.isOutOfDate())
371 PP.getExternalSource()->updateOutOfDateIdentifier(II);
372}
373
374void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) {
375 if (II.isOutOfDate())
376 PP.getExternalSource()->updateOutOfDateIdentifier(II);
377
378 if (II.isFromAST())
379 II.setChangedSinceDeserialization();
Douglas Gregora868bbd2009-04-21 22:25:48 +0000380}
381
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +0000382//===----------------------------------------------------------------------===//
383// IdDeclInfoMap Implementation
384//===----------------------------------------------------------------------===//
385
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000386/// Returns the IdDeclInfo associated to the DeclarationName.
Chris Lattner9950c802008-04-11 07:06:57 +0000387/// It creates a new IdDeclInfo if one was not created before for this id.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000388IdentifierResolver::IdDeclInfo &
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000389IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
390 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattner9950c802008-04-11 07:06:57 +0000391
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000392 if (Ptr) return *toIdDeclInfo(Ptr);
Chris Lattner9950c802008-04-11 07:06:57 +0000393
John McCall5f5cbf52010-02-15 19:38:00 +0000394 if (CurIndex == POOL_SIZE) {
395 CurPool = new IdDeclInfoPool(CurPool);
Chris Lattner9950c802008-04-11 07:06:57 +0000396 CurIndex = 0;
397 }
John McCall5f5cbf52010-02-15 19:38:00 +0000398 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000399 Name.setFETokenInfo(reinterpret_cast<void*>(
Chris Lattner9950c802008-04-11 07:06:57 +0000400 reinterpret_cast<uintptr_t>(IDI) | 0x1)
401 );
402 ++CurIndex;
403 return *IDI;
404}
John McCallde6836a2010-08-24 07:21:54 +0000405
406void IdentifierResolver::iterator::incrementSlowCase() {
407 NamedDecl *D = **this;
408 void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
409 assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
410 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
411
412 BaseIter I = getIterator();
413 if (I != Info->decls_begin())
414 *this = iterator(I-1);
415 else // No more decls.
416 *this = iterator();
417}