blob: 7f5d972f07b78f1e9efa8ba9f9758db82ab3706a [file] [log] [blame]
Chris Lattnera2f42b12008-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 Kyrtzidis321f2782008-04-12 01:50:47 +000010// This file implements the IdentifierResolver class, which is used for lexical
Douglas Gregor2def4832008-11-17 20:34:05 +000011// scoped lookup, based on declaration names.
Chris Lattnera2f42b12008-04-11 07:06:57 +000012//
13//===----------------------------------------------------------------------===//
14
Douglas Gregore737f502010-08-12 20:07:10 +000015#include "clang/Sema/IdentifierResolver.h"
John McCall7cd088e2010-08-24 07:21:54 +000016#include "clang/AST/Decl.h"
Argyrios Kyrtzidisf99cb052008-09-09 21:57:58 +000017#include "clang/Basic/LangOptions.h"
Douglas Gregoreee242f2011-10-27 09:33:13 +000018#include "clang/Lex/ExternalPreprocessorSource.h"
19#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000020#include "clang/Sema/Scope.h"
Chris Lattnera2f42b12008-04-11 07:06:57 +000021
22using namespace clang;
23
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +000024//===----------------------------------------------------------------------===//
25// IdDeclInfoMap class
26//===----------------------------------------------------------------------===//
Chris Lattnera2f42b12008-04-11 07:06:57 +000027
Douglas Gregor2def4832008-11-17 20:34:05 +000028/// IdDeclInfoMap - Associates IdDeclInfos with declaration names.
Argyrios Kyrtzidis321f2782008-04-12 01:50:47 +000029/// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each
Chris Lattnera2f42b12008-04-11 07:06:57 +000030/// individual IdDeclInfo to heap.
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +000031class IdentifierResolver::IdDeclInfoMap {
John McCalleeb1cb42010-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 Lattnera2f42b12008-04-11 07:06:57 +000045 unsigned int CurIndex;
Mike Stump1eb44332009-09-09 15:08:12 +000046
Chris Lattnera2f42b12008-04-11 07:06:57 +000047public:
John McCalleeb1cb42010-02-15 19:38:00 +000048 IdDeclInfoMap() : CurPool(0), CurIndex(POOL_SIZE) {}
49
50 ~IdDeclInfoMap() {
51 IdDeclInfoPool *Cur = CurPool;
52 while (IdDeclInfoPool *P = Cur) {
53 Cur = Cur->Next;
54 delete P;
55 }
56 }
Chris Lattnera2f42b12008-04-11 07:06:57 +000057
Douglas Gregor2def4832008-11-17 20:34:05 +000058 /// Returns the IdDeclInfo associated to the DeclarationName.
Chris Lattnera2f42b12008-04-11 07:06:57 +000059 /// It creates a new IdDeclInfo if one was not created before for this id.
Douglas Gregor2def4832008-11-17 20:34:05 +000060 IdDeclInfo &operator[](DeclarationName Name);
Chris Lattnera2f42b12008-04-11 07:06:57 +000061};
62
Argyrios Kyrtzidis7bc198f2008-04-14 00:09:21 +000063
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +000064//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +000065// IdDeclInfo Implementation
66//===----------------------------------------------------------------------===//
67
Argyrios Kyrtzidis81bebb12008-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 Blaikieb219cfc2011-09-23 05:06:16 +000078 llvm_unreachable("Didn't find this decl on its identifier's chain!");
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +000079}
80
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +000081//===----------------------------------------------------------------------===//
82// IdentifierResolver Implementation
83//===----------------------------------------------------------------------===//
84
Douglas Gregoreee242f2011-10-27 09:33:13 +000085IdentifierResolver::IdentifierResolver(Preprocessor &PP)
David Blaikie4e4d0842012-03-11 07:00:24 +000086 : LangOpt(PP.getLangOpts()), PP(PP),
Douglas Gregoreee242f2011-10-27 09:33:13 +000087 IdDeclInfos(new IdDeclInfoMap) {
Argyrios Kyrtzidiseb7c3882008-09-09 21:32:02 +000088}
Douglas Gregoreee242f2011-10-27 09:33:13 +000089
Argyrios Kyrtzidis7bc198f2008-04-14 00:09:21 +000090IdentifierResolver::~IdentifierResolver() {
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +000091 delete IdDeclInfos;
Argyrios Kyrtzidis7bc198f2008-04-14 00:09:21 +000092}
Chris Lattnera2f42b12008-04-11 07:06:57 +000093
Argyrios Kyrtzidis81bebb12008-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 Weber355a1662012-12-17 03:51:09 +000097bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S,
Douglas Gregorcc209452011-03-07 16:54:27 +000098 bool ExplicitInstantiationOrSpecialization) const {
Sebastian Redl7a126a42010-08-31 00:36:30 +000099 Ctx = Ctx->getRedeclContext();
Douglas Gregor074149e2009-01-05 19:45:36 +0000100
James Molloy16f1f712012-02-29 10:24:19 +0000101 if (Ctx->isFunctionOrMethod() || S->isFunctionPrototypeScope()) {
Douglas Gregor074149e2009-01-05 19:45:36 +0000102 // Ignore the scopes associated within transparent declaration contexts.
Mike Stump1eb44332009-09-09 15:08:12 +0000103 while (S->getEntity() &&
Douglas Gregor074149e2009-01-05 19:45:36 +0000104 ((DeclContext *)S->getEntity())->isTransparentContext())
105 S = S->getParent();
106
John McCalld226f652010-08-21 09:40:31 +0000107 if (S->isDeclScope(D))
Argyrios Kyrtzidisf99cb052008-09-09 21:57:58 +0000108 return true;
109 if (LangOpt.CPlusPlus) {
Sebastian Redla0fd8652008-12-21 16:41:36 +0000110 // C++ 3.3.2p3:
111 // The name declared in a catch exception-declaration is local to the
112 // handler and shall not be redeclared in the outermost block of the
113 // handler.
Argyrios Kyrtzidisf99cb052008-09-09 21:57:58 +0000114 // C++ 3.3.2p4:
115 // Names declared in the for-init-statement, and in the condition of if,
116 // while, for, and switch statements are local to the if, while, for, or
117 // switch statement (including the controlled statement), and shall not be
118 // redeclared in a subsequent condition of that statement nor in the
119 // outermost block (or, for the if statement, any of the outermost blocks)
120 // of the controlled statement.
121 //
122 assert(S->getParent() && "No TUScope?");
David Blaikiec4027c82012-11-10 01:04:23 +0000123 if (S->getParent()->getFlags() & Scope::ControlScope) {
David Blaikie3a9fefe2012-11-12 22:25:41 +0000124 S = S->getParent();
125 if (S->isDeclScope(D))
126 return true;
David Blaikiec4027c82012-11-10 01:04:23 +0000127 }
David Blaikie3a9fefe2012-11-12 22:25:41 +0000128 if (S->getFlags() & Scope::FnTryCatchScope)
129 return S->getParent()->isDeclScope(D);
Argyrios Kyrtzidisf99cb052008-09-09 21:57:58 +0000130 }
131 return false;
132 }
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +0000133
Douglas Gregorcc209452011-03-07 16:54:27 +0000134 DeclContext *DCtx = D->getDeclContext()->getRedeclContext();
135 return ExplicitInstantiationOrSpecialization
136 ? Ctx->InEnclosingNamespaceSetOf(DCtx)
137 : Ctx->Equals(DCtx);
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +0000138}
139
Argyrios Kyrtzidis321f2782008-04-12 01:50:47 +0000140/// AddDecl - Link the decl to its shadowed decl chain.
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000141void IdentifierResolver::AddDecl(NamedDecl *D) {
Douglas Gregor2def4832008-11-17 20:34:05 +0000142 DeclarationName Name = D->getDeclName();
Sebastian Redl1450ef92010-07-30 17:25:10 +0000143 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregoreee242f2011-10-27 09:33:13 +0000144 updatingIdentifier(*II);
Sebastian Redl1450ef92010-07-30 17:25:10 +0000145
Douglas Gregor2def4832008-11-17 20:34:05 +0000146 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattnera2f42b12008-04-11 07:06:57 +0000147
148 if (!Ptr) {
Douglas Gregor2def4832008-11-17 20:34:05 +0000149 Name.setFETokenInfo(D);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000150 return;
151 }
152
153 IdDeclInfo *IDI;
154
155 if (isDeclPtr(Ptr)) {
Douglas Gregor2def4832008-11-17 20:34:05 +0000156 Name.setFETokenInfo(NULL);
157 IDI = &(*IdDeclInfos)[Name];
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000158 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
159 IDI->AddDecl(PrevD);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000160 } else
161 IDI = toIdDeclInfo(Ptr);
162
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000163 IDI->AddDecl(D);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000164}
165
Douglas Gregor250e7a72011-03-16 16:39:03 +0000166void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
167 DeclarationName Name = D->getDeclName();
Douglas Gregoreee242f2011-10-27 09:33:13 +0000168 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
169 updatingIdentifier(*II);
170
Douglas Gregor250e7a72011-03-16 16:39:03 +0000171 void *Ptr = Name.getFETokenInfo<void>();
172
Douglas Gregorfa7b8ce2011-03-24 10:35:39 +0000173 if (!Ptr) {
Douglas Gregor7cbc5582011-03-14 21:19:51 +0000174 AddDecl(D);
175 return;
176 }
Douglas Gregor7cbc5582011-03-14 21:19:51 +0000177
Douglas Gregorfa7b8ce2011-03-24 10:35:39 +0000178 if (isDeclPtr(Ptr)) {
179 // We only have a single declaration: insert before or after it,
180 // as appropriate.
181 if (Pos == iterator()) {
182 // Add the new declaration before the existing declaration.
183 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
184 RemoveDecl(PrevD);
185 AddDecl(D);
186 AddDecl(PrevD);
187 } else {
188 // Add new declaration after the existing declaration.
189 AddDecl(D);
190 }
191
192 return;
193 }
194
Douglas Gregor7cbc5582011-03-14 21:19:51 +0000195 // General case: insert the declaration at the appropriate point in the
196 // list, which already has at least two elements.
197 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
Douglas Gregor250e7a72011-03-16 16:39:03 +0000198 if (Pos.isIterator()) {
199 IDI->InsertDecl(Pos.getIterator() + 1, D);
200 } else
Douglas Gregor7cbc5582011-03-14 21:19:51 +0000201 IDI->InsertDecl(IDI->decls_begin(), D);
202}
203
Argyrios Kyrtzidis321f2782008-04-12 01:50:47 +0000204/// RemoveDecl - Unlink the decl from its shadowed decl chain.
Chris Lattnera2f42b12008-04-11 07:06:57 +0000205/// The decl must already be part of the decl chain.
206void IdentifierResolver::RemoveDecl(NamedDecl *D) {
207 assert(D && "null param passed");
Douglas Gregor2def4832008-11-17 20:34:05 +0000208 DeclarationName Name = D->getDeclName();
Sebastian Redl1450ef92010-07-30 17:25:10 +0000209 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregoreee242f2011-10-27 09:33:13 +0000210 updatingIdentifier(*II);
Sebastian Redl1450ef92010-07-30 17:25:10 +0000211
Douglas Gregor2def4832008-11-17 20:34:05 +0000212 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattnera2f42b12008-04-11 07:06:57 +0000213
214 assert(Ptr && "Didn't find this decl on its identifier's chain!");
215
216 if (isDeclPtr(Ptr)) {
217 assert(D == Ptr && "Didn't find this decl on its identifier's chain!");
Douglas Gregor2def4832008-11-17 20:34:05 +0000218 Name.setFETokenInfo(NULL);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000219 return;
220 }
Mike Stump1eb44332009-09-09 15:08:12 +0000221
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000222 return toIdDeclInfo(Ptr)->RemoveDecl(D);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000223}
224
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000225/// begin - Returns an iterator for decls with name 'Name'.
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000226IdentifierResolver::iterator
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000227IdentifierResolver::begin(DeclarationName Name) {
Douglas Gregoreee242f2011-10-27 09:33:13 +0000228 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
229 readingIdentifier(*II);
230
Douglas Gregor2def4832008-11-17 20:34:05 +0000231 void *Ptr = Name.getFETokenInfo<void>();
Argyrios Kyrtzidis90eb5392008-07-17 17:49:50 +0000232 if (!Ptr) return end();
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000233
Chris Lattner0b2b6e12009-03-04 06:34:08 +0000234 if (isDeclPtr(Ptr))
235 return iterator(static_cast<NamedDecl*>(Ptr));
Argyrios Kyrtzidis90eb5392008-07-17 17:49:50 +0000236
Chris Lattnera2f42b12008-04-11 07:06:57 +0000237 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
Argyrios Kyrtzidis90eb5392008-07-17 17:49:50 +0000238
Douglas Gregor074149e2009-01-05 19:45:36 +0000239 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
Argyrios Kyrtzidis90eb5392008-07-17 17:49:50 +0000240 if (I != IDI->decls_begin())
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000241 return iterator(I-1);
Chris Lattner0b2b6e12009-03-04 06:34:08 +0000242 // No decls found.
243 return end();
Chris Lattnera2f42b12008-04-11 07:06:57 +0000244}
245
Douglas Gregoreee242f2011-10-27 09:33:13 +0000246namespace {
247 enum DeclMatchKind {
248 DMK_Different,
249 DMK_Replace,
250 DMK_Ignore
251 };
252}
Douglas Gregor668c1a42009-04-21 22:25:48 +0000253
Douglas Gregoreee242f2011-10-27 09:33:13 +0000254/// \brief Compare two declarations to see whether they are different or,
255/// if they are the same, whether the new declaration should replace the
256/// existing declaration.
257static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) {
258 // If the declarations are identical, ignore the new one.
259 if (Existing == New)
260 return DMK_Ignore;
261
262 // If the declarations have different kinds, they're obviously different.
263 if (Existing->getKind() != New->getKind())
264 return DMK_Different;
265
266 // If the declarations are redeclarations of each other, keep the newest one.
267 if (Existing->getCanonicalDecl() == New->getCanonicalDecl()) {
Douglas Gregorf4e955b2013-02-11 18:16:18 +0000268 // If either of these is the most recent declaration, use it.
269 Decl *MostRecent = Existing->getMostRecentDecl();
270 if (Existing == MostRecent)
271 return DMK_Ignore;
272
273 if (New == MostRecent)
274 return DMK_Replace;
275
Douglas Gregoreee242f2011-10-27 09:33:13 +0000276 // If the existing declaration is somewhere in the previous declaration
277 // chain of the new declaration, then prefer the new declaration.
278 for (Decl::redecl_iterator RD = New->redecls_begin(),
279 RDEnd = New->redecls_end();
280 RD != RDEnd; ++RD) {
David Blaikie581deb32012-06-06 20:45:41 +0000281 if (*RD == Existing)
Douglas Gregoreee242f2011-10-27 09:33:13 +0000282 return DMK_Replace;
283
284 if (RD->isCanonicalDecl())
285 break;
286 }
287
288 return DMK_Ignore;
Douglas Gregor668c1a42009-04-21 22:25:48 +0000289 }
Douglas Gregoreee242f2011-10-27 09:33:13 +0000290
Douglas Gregoreee242f2011-10-27 09:33:13 +0000291 return DMK_Different;
292}
Douglas Gregor668c1a42009-04-21 22:25:48 +0000293
Douglas Gregoreee242f2011-10-27 09:33:13 +0000294bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){
295 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor5d5051f2012-01-24 15:24:38 +0000296 readingIdentifier(*II);
Douglas Gregoreee242f2011-10-27 09:33:13 +0000297
298 void *Ptr = Name.getFETokenInfo<void>();
299
300 if (!Ptr) {
301 Name.setFETokenInfo(D);
302 return true;
303 }
304
Douglas Gregor668c1a42009-04-21 22:25:48 +0000305 IdDeclInfo *IDI;
Douglas Gregoreee242f2011-10-27 09:33:13 +0000306
Douglas Gregor668c1a42009-04-21 22:25:48 +0000307 if (isDeclPtr(Ptr)) {
Douglas Gregor668c1a42009-04-21 22:25:48 +0000308 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
Douglas Gregoreee242f2011-10-27 09:33:13 +0000309
310 switch (compareDeclarations(PrevD, D)) {
311 case DMK_Different:
312 break;
313
314 case DMK_Ignore:
315 return false;
316
317 case DMK_Replace:
318 Name.setFETokenInfo(D);
319 return true;
320 }
321
322 Name.setFETokenInfo(NULL);
323 IDI = &(*IdDeclInfos)[Name];
324
325 // If the existing declaration is not visible in translation unit scope,
326 // then add the new top-level declaration first.
327 if (!PrevD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
328 IDI->AddDecl(D);
329 IDI->AddDecl(PrevD);
330 } else {
331 IDI->AddDecl(PrevD);
332 IDI->AddDecl(D);
333 }
334 return true;
335 }
336
337 IDI = toIdDeclInfo(Ptr);
Douglas Gregor668c1a42009-04-21 22:25:48 +0000338
Douglas Gregoreee242f2011-10-27 09:33:13 +0000339 // See whether this declaration is identical to any existing declarations.
340 // If not, find the right place to insert it.
341 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
342 IEnd = IDI->decls_end();
343 I != IEnd; ++I) {
344
345 switch (compareDeclarations(*I, D)) {
346 case DMK_Different:
347 break;
348
349 case DMK_Ignore:
350 return false;
351
352 case DMK_Replace:
353 *I = D;
354 return true;
355 }
356
357 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
358 // We've found a declaration that is not visible from the translation
359 // unit (it's in an inner scope). Insert our declaration here.
360 IDI->InsertDecl(I, D);
361 return true;
362 }
363 }
364
365 // Add the declaration to the end.
Douglas Gregor668c1a42009-04-21 22:25:48 +0000366 IDI->AddDecl(D);
Douglas Gregoreee242f2011-10-27 09:33:13 +0000367 return true;
368}
369
370void IdentifierResolver::readingIdentifier(IdentifierInfo &II) {
371 if (II.isOutOfDate())
372 PP.getExternalSource()->updateOutOfDateIdentifier(II);
373}
374
375void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) {
376 if (II.isOutOfDate())
377 PP.getExternalSource()->updateOutOfDateIdentifier(II);
378
379 if (II.isFromAST())
380 II.setChangedSinceDeserialization();
Douglas Gregor668c1a42009-04-21 22:25:48 +0000381}
382
Argyrios Kyrtzidis81bebb12008-09-09 19:28:27 +0000383//===----------------------------------------------------------------------===//
384// IdDeclInfoMap Implementation
385//===----------------------------------------------------------------------===//
386
Douglas Gregor2def4832008-11-17 20:34:05 +0000387/// Returns the IdDeclInfo associated to the DeclarationName.
Chris Lattnera2f42b12008-04-11 07:06:57 +0000388/// It creates a new IdDeclInfo if one was not created before for this id.
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000389IdentifierResolver::IdDeclInfo &
Douglas Gregor2def4832008-11-17 20:34:05 +0000390IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
391 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattnera2f42b12008-04-11 07:06:57 +0000392
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +0000393 if (Ptr) return *toIdDeclInfo(Ptr);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000394
John McCalleeb1cb42010-02-15 19:38:00 +0000395 if (CurIndex == POOL_SIZE) {
396 CurPool = new IdDeclInfoPool(CurPool);
Chris Lattnera2f42b12008-04-11 07:06:57 +0000397 CurIndex = 0;
398 }
John McCalleeb1cb42010-02-15 19:38:00 +0000399 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
Douglas Gregor2def4832008-11-17 20:34:05 +0000400 Name.setFETokenInfo(reinterpret_cast<void*>(
Chris Lattnera2f42b12008-04-11 07:06:57 +0000401 reinterpret_cast<uintptr_t>(IDI) | 0x1)
402 );
403 ++CurIndex;
404 return *IDI;
405}
John McCall7cd088e2010-08-24 07:21:54 +0000406
407void IdentifierResolver::iterator::incrementSlowCase() {
408 NamedDecl *D = **this;
409 void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
410 assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
411 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
412
413 BaseIter I = getIterator();
414 if (I != Info->decls_begin())
415 *this = iterator(I-1);
416 else // No more decls.
417 *this = iterator();
418}