xref: /aosp_15_r20/external/clang/lib/Sema/IdentifierResolver.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //===- IdentifierResolver.cpp - Lexical Scope Name lookup -------*- C++ -*-===//
2*67e74705SXin Li //
3*67e74705SXin Li //                     The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li //
10*67e74705SXin Li // This file implements the IdentifierResolver class, which is used for lexical
11*67e74705SXin Li // scoped lookup, based on declaration names.
12*67e74705SXin Li //
13*67e74705SXin Li //===----------------------------------------------------------------------===//
14*67e74705SXin Li 
15*67e74705SXin Li #include "clang/Sema/IdentifierResolver.h"
16*67e74705SXin Li #include "clang/AST/Decl.h"
17*67e74705SXin Li #include "clang/Basic/LangOptions.h"
18*67e74705SXin Li #include "clang/Lex/ExternalPreprocessorSource.h"
19*67e74705SXin Li #include "clang/Lex/Preprocessor.h"
20*67e74705SXin Li #include "clang/Sema/Scope.h"
21*67e74705SXin Li 
22*67e74705SXin Li using namespace clang;
23*67e74705SXin Li 
24*67e74705SXin Li //===----------------------------------------------------------------------===//
25*67e74705SXin Li // IdDeclInfoMap class
26*67e74705SXin Li //===----------------------------------------------------------------------===//
27*67e74705SXin Li 
28*67e74705SXin Li /// IdDeclInfoMap - Associates IdDeclInfos with declaration names.
29*67e74705SXin Li /// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each
30*67e74705SXin Li /// individual IdDeclInfo to heap.
31*67e74705SXin Li class IdentifierResolver::IdDeclInfoMap {
32*67e74705SXin Li   static const unsigned int POOL_SIZE = 512;
33*67e74705SXin Li 
34*67e74705SXin Li   /// We use our own linked-list implementation because it is sadly
35*67e74705SXin Li   /// impossible to add something to a pre-C++0x STL container without
36*67e74705SXin Li   /// a completely unnecessary copy.
37*67e74705SXin Li   struct IdDeclInfoPool {
IdDeclInfoPoolIdentifierResolver::IdDeclInfoMap::IdDeclInfoPool38*67e74705SXin Li     IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {}
39*67e74705SXin Li 
40*67e74705SXin Li     IdDeclInfoPool *Next;
41*67e74705SXin Li     IdDeclInfo Pool[POOL_SIZE];
42*67e74705SXin Li   };
43*67e74705SXin Li 
44*67e74705SXin Li   IdDeclInfoPool *CurPool;
45*67e74705SXin Li   unsigned int CurIndex;
46*67e74705SXin Li 
47*67e74705SXin Li public:
IdDeclInfoMap()48*67e74705SXin Li   IdDeclInfoMap() : CurPool(nullptr), CurIndex(POOL_SIZE) {}
49*67e74705SXin Li 
~IdDeclInfoMap()50*67e74705SXin Li   ~IdDeclInfoMap() {
51*67e74705SXin Li     IdDeclInfoPool *Cur = CurPool;
52*67e74705SXin Li     while (IdDeclInfoPool *P = Cur) {
53*67e74705SXin Li       Cur = Cur->Next;
54*67e74705SXin Li       delete P;
55*67e74705SXin Li     }
56*67e74705SXin Li   }
57*67e74705SXin Li 
58*67e74705SXin Li   /// Returns the IdDeclInfo associated to the DeclarationName.
59*67e74705SXin Li   /// It creates a new IdDeclInfo if one was not created before for this id.
60*67e74705SXin Li   IdDeclInfo &operator[](DeclarationName Name);
61*67e74705SXin Li };
62*67e74705SXin Li 
63*67e74705SXin Li 
64*67e74705SXin Li //===----------------------------------------------------------------------===//
65*67e74705SXin Li // IdDeclInfo Implementation
66*67e74705SXin Li //===----------------------------------------------------------------------===//
67*67e74705SXin Li 
68*67e74705SXin Li /// RemoveDecl - Remove the decl from the scope chain.
69*67e74705SXin Li /// The decl must already be part of the decl chain.
RemoveDecl(NamedDecl * D)70*67e74705SXin Li void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) {
71*67e74705SXin Li   for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) {
72*67e74705SXin Li     if (D == *(I-1)) {
73*67e74705SXin Li       Decls.erase(I-1);
74*67e74705SXin Li       return;
75*67e74705SXin Li     }
76*67e74705SXin Li   }
77*67e74705SXin Li 
78*67e74705SXin Li   llvm_unreachable("Didn't find this decl on its identifier's chain!");
79*67e74705SXin Li }
80*67e74705SXin Li 
81*67e74705SXin Li //===----------------------------------------------------------------------===//
82*67e74705SXin Li // IdentifierResolver Implementation
83*67e74705SXin Li //===----------------------------------------------------------------------===//
84*67e74705SXin Li 
IdentifierResolver(Preprocessor & PP)85*67e74705SXin Li IdentifierResolver::IdentifierResolver(Preprocessor &PP)
86*67e74705SXin Li   : LangOpt(PP.getLangOpts()), PP(PP),
87*67e74705SXin Li     IdDeclInfos(new IdDeclInfoMap) {
88*67e74705SXin Li }
89*67e74705SXin Li 
~IdentifierResolver()90*67e74705SXin Li IdentifierResolver::~IdentifierResolver() {
91*67e74705SXin Li   delete IdDeclInfos;
92*67e74705SXin Li }
93*67e74705SXin Li 
94*67e74705SXin Li /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
95*67e74705SXin Li /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
96*67e74705SXin Li /// true if 'D' belongs to the given declaration context.
isDeclInScope(Decl * D,DeclContext * Ctx,Scope * S,bool AllowInlineNamespace) const97*67e74705SXin Li bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S,
98*67e74705SXin Li                                        bool AllowInlineNamespace) const {
99*67e74705SXin Li   Ctx = Ctx->getRedeclContext();
100*67e74705SXin Li 
101*67e74705SXin Li   if (Ctx->isFunctionOrMethod() || (S && S->isFunctionPrototypeScope())) {
102*67e74705SXin Li     // Ignore the scopes associated within transparent declaration contexts.
103*67e74705SXin Li     while (S->getEntity() && S->getEntity()->isTransparentContext())
104*67e74705SXin Li       S = S->getParent();
105*67e74705SXin Li 
106*67e74705SXin Li     if (S->isDeclScope(D))
107*67e74705SXin Li       return true;
108*67e74705SXin Li     if (LangOpt.CPlusPlus) {
109*67e74705SXin Li       // C++ 3.3.2p3:
110*67e74705SXin Li       // The name declared in a catch exception-declaration is local to the
111*67e74705SXin Li       // handler and shall not be redeclared in the outermost block of the
112*67e74705SXin Li       // handler.
113*67e74705SXin Li       // C++ 3.3.2p4:
114*67e74705SXin Li       // Names declared in the for-init-statement, and in the condition of if,
115*67e74705SXin Li       // while, for, and switch statements are local to the if, while, for, or
116*67e74705SXin Li       // switch statement (including the controlled statement), and shall not be
117*67e74705SXin Li       // redeclared in a subsequent condition of that statement nor in the
118*67e74705SXin Li       // outermost block (or, for the if statement, any of the outermost blocks)
119*67e74705SXin Li       // of the controlled statement.
120*67e74705SXin Li       //
121*67e74705SXin Li       assert(S->getParent() && "No TUScope?");
122*67e74705SXin Li       if (S->getParent()->getFlags() & Scope::ControlScope) {
123*67e74705SXin Li         S = S->getParent();
124*67e74705SXin Li         if (S->isDeclScope(D))
125*67e74705SXin Li           return true;
126*67e74705SXin Li       }
127*67e74705SXin Li       if (S->getFlags() & Scope::FnTryCatchScope)
128*67e74705SXin Li         return S->getParent()->isDeclScope(D);
129*67e74705SXin Li     }
130*67e74705SXin Li     return false;
131*67e74705SXin Li   }
132*67e74705SXin Li 
133*67e74705SXin Li   // FIXME: If D is a local extern declaration, this check doesn't make sense;
134*67e74705SXin Li   // we should be checking its lexical context instead in that case, because
135*67e74705SXin Li   // that is its scope.
136*67e74705SXin Li   DeclContext *DCtx = D->getDeclContext()->getRedeclContext();
137*67e74705SXin Li   return AllowInlineNamespace ? Ctx->InEnclosingNamespaceSetOf(DCtx)
138*67e74705SXin Li                               : Ctx->Equals(DCtx);
139*67e74705SXin Li }
140*67e74705SXin Li 
141*67e74705SXin Li /// AddDecl - Link the decl to its shadowed decl chain.
AddDecl(NamedDecl * D)142*67e74705SXin Li void IdentifierResolver::AddDecl(NamedDecl *D) {
143*67e74705SXin Li   DeclarationName Name = D->getDeclName();
144*67e74705SXin Li   if (IdentifierInfo *II = Name.getAsIdentifierInfo())
145*67e74705SXin Li     updatingIdentifier(*II);
146*67e74705SXin Li 
147*67e74705SXin Li   void *Ptr = Name.getFETokenInfo<void>();
148*67e74705SXin Li 
149*67e74705SXin Li   if (!Ptr) {
150*67e74705SXin Li     Name.setFETokenInfo(D);
151*67e74705SXin Li     return;
152*67e74705SXin Li   }
153*67e74705SXin Li 
154*67e74705SXin Li   IdDeclInfo *IDI;
155*67e74705SXin Li 
156*67e74705SXin Li   if (isDeclPtr(Ptr)) {
157*67e74705SXin Li     Name.setFETokenInfo(nullptr);
158*67e74705SXin Li     IDI = &(*IdDeclInfos)[Name];
159*67e74705SXin Li     NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
160*67e74705SXin Li     IDI->AddDecl(PrevD);
161*67e74705SXin Li   } else
162*67e74705SXin Li     IDI = toIdDeclInfo(Ptr);
163*67e74705SXin Li 
164*67e74705SXin Li   IDI->AddDecl(D);
165*67e74705SXin Li }
166*67e74705SXin Li 
InsertDeclAfter(iterator Pos,NamedDecl * D)167*67e74705SXin Li void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
168*67e74705SXin Li   DeclarationName Name = D->getDeclName();
169*67e74705SXin Li   if (IdentifierInfo *II = Name.getAsIdentifierInfo())
170*67e74705SXin Li     updatingIdentifier(*II);
171*67e74705SXin Li 
172*67e74705SXin Li   void *Ptr = Name.getFETokenInfo<void>();
173*67e74705SXin Li 
174*67e74705SXin Li   if (!Ptr) {
175*67e74705SXin Li     AddDecl(D);
176*67e74705SXin Li     return;
177*67e74705SXin Li   }
178*67e74705SXin Li 
179*67e74705SXin Li   if (isDeclPtr(Ptr)) {
180*67e74705SXin Li     // We only have a single declaration: insert before or after it,
181*67e74705SXin Li     // as appropriate.
182*67e74705SXin Li     if (Pos == iterator()) {
183*67e74705SXin Li       // Add the new declaration before the existing declaration.
184*67e74705SXin Li       NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
185*67e74705SXin Li       RemoveDecl(PrevD);
186*67e74705SXin Li       AddDecl(D);
187*67e74705SXin Li       AddDecl(PrevD);
188*67e74705SXin Li     } else {
189*67e74705SXin Li       // Add new declaration after the existing declaration.
190*67e74705SXin Li       AddDecl(D);
191*67e74705SXin Li     }
192*67e74705SXin Li 
193*67e74705SXin Li     return;
194*67e74705SXin Li   }
195*67e74705SXin Li 
196*67e74705SXin Li   // General case: insert the declaration at the appropriate point in the
197*67e74705SXin Li   // list, which already has at least two elements.
198*67e74705SXin Li   IdDeclInfo *IDI = toIdDeclInfo(Ptr);
199*67e74705SXin Li   if (Pos.isIterator()) {
200*67e74705SXin Li     IDI->InsertDecl(Pos.getIterator() + 1, D);
201*67e74705SXin Li   } else
202*67e74705SXin Li     IDI->InsertDecl(IDI->decls_begin(), D);
203*67e74705SXin Li }
204*67e74705SXin Li 
205*67e74705SXin Li /// RemoveDecl - Unlink the decl from its shadowed decl chain.
206*67e74705SXin Li /// The decl must already be part of the decl chain.
RemoveDecl(NamedDecl * D)207*67e74705SXin Li void IdentifierResolver::RemoveDecl(NamedDecl *D) {
208*67e74705SXin Li   assert(D && "null param passed");
209*67e74705SXin Li   DeclarationName Name = D->getDeclName();
210*67e74705SXin Li   if (IdentifierInfo *II = Name.getAsIdentifierInfo())
211*67e74705SXin Li     updatingIdentifier(*II);
212*67e74705SXin Li 
213*67e74705SXin Li   void *Ptr = Name.getFETokenInfo<void>();
214*67e74705SXin Li 
215*67e74705SXin Li   assert(Ptr && "Didn't find this decl on its identifier's chain!");
216*67e74705SXin Li 
217*67e74705SXin Li   if (isDeclPtr(Ptr)) {
218*67e74705SXin Li     assert(D == Ptr && "Didn't find this decl on its identifier's chain!");
219*67e74705SXin Li     Name.setFETokenInfo(nullptr);
220*67e74705SXin Li     return;
221*67e74705SXin Li   }
222*67e74705SXin Li 
223*67e74705SXin Li   return toIdDeclInfo(Ptr)->RemoveDecl(D);
224*67e74705SXin Li }
225*67e74705SXin Li 
226*67e74705SXin Li /// begin - Returns an iterator for decls with name 'Name'.
227*67e74705SXin Li IdentifierResolver::iterator
begin(DeclarationName Name)228*67e74705SXin Li IdentifierResolver::begin(DeclarationName Name) {
229*67e74705SXin Li   if (IdentifierInfo *II = Name.getAsIdentifierInfo())
230*67e74705SXin Li     readingIdentifier(*II);
231*67e74705SXin Li 
232*67e74705SXin Li   void *Ptr = Name.getFETokenInfo<void>();
233*67e74705SXin Li   if (!Ptr) return end();
234*67e74705SXin Li 
235*67e74705SXin Li   if (isDeclPtr(Ptr))
236*67e74705SXin Li     return iterator(static_cast<NamedDecl*>(Ptr));
237*67e74705SXin Li 
238*67e74705SXin Li   IdDeclInfo *IDI = toIdDeclInfo(Ptr);
239*67e74705SXin Li 
240*67e74705SXin Li   IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
241*67e74705SXin Li   if (I != IDI->decls_begin())
242*67e74705SXin Li     return iterator(I-1);
243*67e74705SXin Li   // No decls found.
244*67e74705SXin Li   return end();
245*67e74705SXin Li }
246*67e74705SXin Li 
247*67e74705SXin Li namespace {
248*67e74705SXin Li   enum DeclMatchKind {
249*67e74705SXin Li     DMK_Different,
250*67e74705SXin Li     DMK_Replace,
251*67e74705SXin Li     DMK_Ignore
252*67e74705SXin Li   };
253*67e74705SXin Li }
254*67e74705SXin Li 
255*67e74705SXin Li /// \brief Compare two declarations to see whether they are different or,
256*67e74705SXin Li /// if they are the same, whether the new declaration should replace the
257*67e74705SXin Li /// existing declaration.
compareDeclarations(NamedDecl * Existing,NamedDecl * New)258*67e74705SXin Li static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) {
259*67e74705SXin Li   // If the declarations are identical, ignore the new one.
260*67e74705SXin Li   if (Existing == New)
261*67e74705SXin Li     return DMK_Ignore;
262*67e74705SXin Li 
263*67e74705SXin Li   // If the declarations have different kinds, they're obviously different.
264*67e74705SXin Li   if (Existing->getKind() != New->getKind())
265*67e74705SXin Li     return DMK_Different;
266*67e74705SXin Li 
267*67e74705SXin Li   // If the declarations are redeclarations of each other, keep the newest one.
268*67e74705SXin Li   if (Existing->getCanonicalDecl() == New->getCanonicalDecl()) {
269*67e74705SXin Li     // If we're adding an imported declaration, don't replace another imported
270*67e74705SXin Li     // declaration.
271*67e74705SXin Li     if (Existing->isFromASTFile() && New->isFromASTFile())
272*67e74705SXin Li       return DMK_Different;
273*67e74705SXin Li 
274*67e74705SXin Li     // If either of these is the most recent declaration, use it.
275*67e74705SXin Li     Decl *MostRecent = Existing->getMostRecentDecl();
276*67e74705SXin Li     if (Existing == MostRecent)
277*67e74705SXin Li       return DMK_Ignore;
278*67e74705SXin Li 
279*67e74705SXin Li     if (New == MostRecent)
280*67e74705SXin Li       return DMK_Replace;
281*67e74705SXin Li 
282*67e74705SXin Li     // If the existing declaration is somewhere in the previous declaration
283*67e74705SXin Li     // chain of the new declaration, then prefer the new declaration.
284*67e74705SXin Li     for (auto RD : New->redecls()) {
285*67e74705SXin Li       if (RD == Existing)
286*67e74705SXin Li         return DMK_Replace;
287*67e74705SXin Li 
288*67e74705SXin Li       if (RD->isCanonicalDecl())
289*67e74705SXin Li         break;
290*67e74705SXin Li     }
291*67e74705SXin Li 
292*67e74705SXin Li     return DMK_Ignore;
293*67e74705SXin Li   }
294*67e74705SXin Li 
295*67e74705SXin Li   return DMK_Different;
296*67e74705SXin Li }
297*67e74705SXin Li 
tryAddTopLevelDecl(NamedDecl * D,DeclarationName Name)298*67e74705SXin Li bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){
299*67e74705SXin Li   if (IdentifierInfo *II = Name.getAsIdentifierInfo())
300*67e74705SXin Li     readingIdentifier(*II);
301*67e74705SXin Li 
302*67e74705SXin Li   void *Ptr = Name.getFETokenInfo<void>();
303*67e74705SXin Li 
304*67e74705SXin Li   if (!Ptr) {
305*67e74705SXin Li     Name.setFETokenInfo(D);
306*67e74705SXin Li     return true;
307*67e74705SXin Li   }
308*67e74705SXin Li 
309*67e74705SXin Li   IdDeclInfo *IDI;
310*67e74705SXin Li 
311*67e74705SXin Li   if (isDeclPtr(Ptr)) {
312*67e74705SXin Li     NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
313*67e74705SXin Li 
314*67e74705SXin Li     switch (compareDeclarations(PrevD, D)) {
315*67e74705SXin Li     case DMK_Different:
316*67e74705SXin Li       break;
317*67e74705SXin Li 
318*67e74705SXin Li     case DMK_Ignore:
319*67e74705SXin Li       return false;
320*67e74705SXin Li 
321*67e74705SXin Li     case DMK_Replace:
322*67e74705SXin Li       Name.setFETokenInfo(D);
323*67e74705SXin Li       return true;
324*67e74705SXin Li     }
325*67e74705SXin Li 
326*67e74705SXin Li     Name.setFETokenInfo(nullptr);
327*67e74705SXin Li     IDI = &(*IdDeclInfos)[Name];
328*67e74705SXin Li 
329*67e74705SXin Li     // If the existing declaration is not visible in translation unit scope,
330*67e74705SXin Li     // then add the new top-level declaration first.
331*67e74705SXin Li     if (!PrevD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
332*67e74705SXin Li       IDI->AddDecl(D);
333*67e74705SXin Li       IDI->AddDecl(PrevD);
334*67e74705SXin Li     } else {
335*67e74705SXin Li       IDI->AddDecl(PrevD);
336*67e74705SXin Li       IDI->AddDecl(D);
337*67e74705SXin Li     }
338*67e74705SXin Li     return true;
339*67e74705SXin Li   }
340*67e74705SXin Li 
341*67e74705SXin Li   IDI = toIdDeclInfo(Ptr);
342*67e74705SXin Li 
343*67e74705SXin Li   // See whether this declaration is identical to any existing declarations.
344*67e74705SXin Li   // If not, find the right place to insert it.
345*67e74705SXin Li   for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
346*67e74705SXin Li                                   IEnd = IDI->decls_end();
347*67e74705SXin Li        I != IEnd; ++I) {
348*67e74705SXin Li 
349*67e74705SXin Li     switch (compareDeclarations(*I, D)) {
350*67e74705SXin Li     case DMK_Different:
351*67e74705SXin Li       break;
352*67e74705SXin Li 
353*67e74705SXin Li     case DMK_Ignore:
354*67e74705SXin Li       return false;
355*67e74705SXin Li 
356*67e74705SXin Li     case DMK_Replace:
357*67e74705SXin Li       *I = D;
358*67e74705SXin Li       return true;
359*67e74705SXin Li     }
360*67e74705SXin Li 
361*67e74705SXin Li     if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
362*67e74705SXin Li       // We've found a declaration that is not visible from the translation
363*67e74705SXin Li       // unit (it's in an inner scope). Insert our declaration here.
364*67e74705SXin Li       IDI->InsertDecl(I, D);
365*67e74705SXin Li       return true;
366*67e74705SXin Li     }
367*67e74705SXin Li   }
368*67e74705SXin Li 
369*67e74705SXin Li   // Add the declaration to the end.
370*67e74705SXin Li   IDI->AddDecl(D);
371*67e74705SXin Li   return true;
372*67e74705SXin Li }
373*67e74705SXin Li 
readingIdentifier(IdentifierInfo & II)374*67e74705SXin Li void IdentifierResolver::readingIdentifier(IdentifierInfo &II) {
375*67e74705SXin Li   if (II.isOutOfDate())
376*67e74705SXin Li     PP.getExternalSource()->updateOutOfDateIdentifier(II);
377*67e74705SXin Li }
378*67e74705SXin Li 
updatingIdentifier(IdentifierInfo & II)379*67e74705SXin Li void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) {
380*67e74705SXin Li   if (II.isOutOfDate())
381*67e74705SXin Li     PP.getExternalSource()->updateOutOfDateIdentifier(II);
382*67e74705SXin Li 
383*67e74705SXin Li   if (II.isFromAST())
384*67e74705SXin Li     II.setFETokenInfoChangedSinceDeserialization();
385*67e74705SXin Li }
386*67e74705SXin Li 
387*67e74705SXin Li //===----------------------------------------------------------------------===//
388*67e74705SXin Li // IdDeclInfoMap Implementation
389*67e74705SXin Li //===----------------------------------------------------------------------===//
390*67e74705SXin Li 
391*67e74705SXin Li /// Returns the IdDeclInfo associated to the DeclarationName.
392*67e74705SXin Li /// It creates a new IdDeclInfo if one was not created before for this id.
393*67e74705SXin Li IdentifierResolver::IdDeclInfo &
operator [](DeclarationName Name)394*67e74705SXin Li IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
395*67e74705SXin Li   void *Ptr = Name.getFETokenInfo<void>();
396*67e74705SXin Li 
397*67e74705SXin Li   if (Ptr) return *toIdDeclInfo(Ptr);
398*67e74705SXin Li 
399*67e74705SXin Li   if (CurIndex == POOL_SIZE) {
400*67e74705SXin Li     CurPool = new IdDeclInfoPool(CurPool);
401*67e74705SXin Li     CurIndex = 0;
402*67e74705SXin Li   }
403*67e74705SXin Li   IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
404*67e74705SXin Li   Name.setFETokenInfo(reinterpret_cast<void*>(
405*67e74705SXin Li                               reinterpret_cast<uintptr_t>(IDI) | 0x1)
406*67e74705SXin Li                                                                      );
407*67e74705SXin Li   ++CurIndex;
408*67e74705SXin Li   return *IDI;
409*67e74705SXin Li }
410*67e74705SXin Li 
incrementSlowCase()411*67e74705SXin Li void IdentifierResolver::iterator::incrementSlowCase() {
412*67e74705SXin Li   NamedDecl *D = **this;
413*67e74705SXin Li   void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
414*67e74705SXin Li   assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
415*67e74705SXin Li   IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
416*67e74705SXin Li 
417*67e74705SXin Li   BaseIter I = getIterator();
418*67e74705SXin Li   if (I != Info->decls_begin())
419*67e74705SXin Li     *this = iterator(I-1);
420*67e74705SXin Li   else // No more decls.
421*67e74705SXin Li     *this = iterator();
422*67e74705SXin Li }
423