blob: dbd52dee1eea58080888a0aaa57695d4c398d67f [file] [log] [blame]
Eugene Zelenko9fbf6412018-02-21 01:45:26 +00001//===- IdentifierResolver.cpp - Lexical Scope Name lookup -----------------===//
Chris Lattner9950c802008-04-11 07:06:57 +00002//
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"
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000017#include "clang/AST/DeclBase.h"
18#include "clang/AST/DeclarationName.h"
19#include "clang/Basic/IdentifierTable.h"
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +000020#include "clang/Basic/LangOptions.h"
Douglas Gregor935bc7a22011-10-27 09:33:13 +000021#include "clang/Lex/ExternalPreprocessorSource.h"
22#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000023#include "clang/Sema/Scope.h"
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000024#include "llvm/Support/ErrorHandling.h"
25#include <cassert>
26#include <cstdint>
Chris Lattner9950c802008-04-11 07:06:57 +000027
28using namespace clang;
29
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000030//===----------------------------------------------------------------------===//
31// IdDeclInfoMap class
32//===----------------------------------------------------------------------===//
Chris Lattner9950c802008-04-11 07:06:57 +000033
Douglas Gregorae2fbad2008-11-17 20:34:05 +000034/// IdDeclInfoMap - Associates IdDeclInfos with declaration names.
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +000035/// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each
Chris Lattner9950c802008-04-11 07:06:57 +000036/// individual IdDeclInfo to heap.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +000037class IdentifierResolver::IdDeclInfoMap {
John McCall5f5cbf52010-02-15 19:38:00 +000038 static const unsigned int POOL_SIZE = 512;
39
40 /// We use our own linked-list implementation because it is sadly
41 /// impossible to add something to a pre-C++0x STL container without
42 /// a completely unnecessary copy.
43 struct IdDeclInfoPool {
John McCall5f5cbf52010-02-15 19:38:00 +000044 IdDeclInfoPool *Next;
45 IdDeclInfo Pool[POOL_SIZE];
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000046
47 IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {}
John McCall5f5cbf52010-02-15 19:38:00 +000048 };
49
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000050 IdDeclInfoPool *CurPool = nullptr;
51 unsigned int CurIndex = POOL_SIZE;
Mike Stump11289f42009-09-09 15:08:12 +000052
Chris Lattner9950c802008-04-11 07:06:57 +000053public:
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000054 IdDeclInfoMap() = default;
John McCall5f5cbf52010-02-15 19:38:00 +000055
56 ~IdDeclInfoMap() {
57 IdDeclInfoPool *Cur = CurPool;
58 while (IdDeclInfoPool *P = Cur) {
59 Cur = Cur->Next;
60 delete P;
61 }
62 }
Chris Lattner9950c802008-04-11 07:06:57 +000063
Douglas Gregorae2fbad2008-11-17 20:34:05 +000064 /// Returns the IdDeclInfo associated to the DeclarationName.
Chris Lattner9950c802008-04-11 07:06:57 +000065 /// It creates a new IdDeclInfo if one was not created before for this id.
Douglas Gregorae2fbad2008-11-17 20:34:05 +000066 IdDeclInfo &operator[](DeclarationName Name);
Chris Lattner9950c802008-04-11 07:06:57 +000067};
68
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000069//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000070// IdDeclInfo Implementation
71//===----------------------------------------------------------------------===//
72
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000073/// RemoveDecl - Remove the decl from the scope chain.
74/// The decl must already be part of the decl chain.
75void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) {
76 for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) {
77 if (D == *(I-1)) {
78 Decls.erase(I-1);
79 return;
80 }
81 }
82
David Blaikie83d382b2011-09-23 05:06:16 +000083 llvm_unreachable("Didn't find this decl on its identifier's chain!");
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000084}
85
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000086//===----------------------------------------------------------------------===//
87// IdentifierResolver Implementation
88//===----------------------------------------------------------------------===//
89
Douglas Gregor935bc7a22011-10-27 09:33:13 +000090IdentifierResolver::IdentifierResolver(Preprocessor &PP)
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000091 : LangOpt(PP.getLangOpts()), PP(PP), IdDeclInfos(new IdDeclInfoMap) {}
Douglas Gregor935bc7a22011-10-27 09:33:13 +000092
Argyrios Kyrtzidis25f54c72008-04-14 00:09:21 +000093IdentifierResolver::~IdentifierResolver() {
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +000094 delete IdDeclInfos;
Argyrios Kyrtzidis25f54c72008-04-14 00:09:21 +000095}
Chris Lattner9950c802008-04-11 07:06:57 +000096
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +000097/// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
98/// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
99/// true if 'D' belongs to the given declaration context.
Nico Weber555d1aa2012-12-17 03:51:09 +0000100bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S,
Richard Smith72bcaec2013-12-05 04:30:04 +0000101 bool AllowInlineNamespace) const {
Sebastian Redl50c68252010-08-31 00:36:30 +0000102 Ctx = Ctx->getRedeclContext();
Douglas Gregor07665a62009-01-05 19:45:36 +0000103
Richard Smith9e2341d2015-03-23 03:25:59 +0000104 if (Ctx->isFunctionOrMethod() || (S && S->isFunctionPrototypeScope())) {
Douglas Gregor07665a62009-01-05 19:45:36 +0000105 // Ignore the scopes associated within transparent declaration contexts.
Ted Kremenekc37877d2013-10-08 17:08:03 +0000106 while (S->getEntity() && S->getEntity()->isTransparentContext())
Douglas Gregor07665a62009-01-05 19:45:36 +0000107 S = S->getParent();
108
John McCall48871652010-08-21 09:40:31 +0000109 if (S->isDeclScope(D))
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +0000110 return true;
111 if (LangOpt.CPlusPlus) {
Sebastian Redlb219c902008-12-21 16:41:36 +0000112 // C++ 3.3.2p3:
113 // The name declared in a catch exception-declaration is local to the
114 // handler and shall not be redeclared in the outermost block of the
115 // handler.
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +0000116 // C++ 3.3.2p4:
117 // Names declared in the for-init-statement, and in the condition of if,
118 // while, for, and switch statements are local to the if, while, for, or
119 // switch statement (including the controlled statement), and shall not be
120 // redeclared in a subsequent condition of that statement nor in the
121 // outermost block (or, for the if statement, any of the outermost blocks)
122 // of the controlled statement.
123 //
124 assert(S->getParent() && "No TUScope?");
David Blaikie1c9c9042012-11-10 01:04:23 +0000125 if (S->getParent()->getFlags() & Scope::ControlScope) {
David Blaikie1d617802012-11-12 22:25:41 +0000126 S = S->getParent();
127 if (S->isDeclScope(D))
128 return true;
David Blaikie1c9c9042012-11-10 01:04:23 +0000129 }
David Blaikie1d617802012-11-12 22:25:41 +0000130 if (S->getFlags() & Scope::FnTryCatchScope)
131 return S->getParent()->isDeclScope(D);
Argyrios Kyrtzidis2bdac732008-09-09 21:57:58 +0000132 }
133 return false;
134 }
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +0000135
Richard Smith5971e8c2014-08-27 22:31:34 +0000136 // FIXME: If D is a local extern declaration, this check doesn't make sense;
137 // we should be checking its lexical context instead in that case, because
138 // that is its scope.
Douglas Gregordb446112011-03-07 16:54:27 +0000139 DeclContext *DCtx = D->getDeclContext()->getRedeclContext();
Richard Smith72bcaec2013-12-05 04:30:04 +0000140 return AllowInlineNamespace ? Ctx->InEnclosingNamespaceSetOf(DCtx)
141 : Ctx->Equals(DCtx);
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +0000142}
143
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +0000144/// AddDecl - Link the decl to its shadowed decl chain.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000145void IdentifierResolver::AddDecl(NamedDecl *D) {
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000146 DeclarationName Name = D->getDeclName();
Sebastian Redl671eee92010-07-30 17:25:10 +0000147 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000148 updatingIdentifier(*II);
Sebastian Redl671eee92010-07-30 17:25:10 +0000149
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000150 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattner9950c802008-04-11 07:06:57 +0000151
152 if (!Ptr) {
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000153 Name.setFETokenInfo(D);
Chris Lattner9950c802008-04-11 07:06:57 +0000154 return;
155 }
156
157 IdDeclInfo *IDI;
158
159 if (isDeclPtr(Ptr)) {
Craig Topperc3ec1492014-05-26 06:22:03 +0000160 Name.setFETokenInfo(nullptr);
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000161 IDI = &(*IdDeclInfos)[Name];
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000162 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000163 IDI->AddDecl(PrevD);
Chris Lattner9950c802008-04-11 07:06:57 +0000164 } else
165 IDI = toIdDeclInfo(Ptr);
166
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000167 IDI->AddDecl(D);
Chris Lattner9950c802008-04-11 07:06:57 +0000168}
169
Douglas Gregor46c04e72011-03-16 16:39:03 +0000170void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
171 DeclarationName Name = D->getDeclName();
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000172 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
173 updatingIdentifier(*II);
174
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000175 void *Ptr = Name.getFETokenInfo<void>();
Douglas Gregor46c04e72011-03-16 16:39:03 +0000176
Douglas Gregor33f352c2011-03-24 10:35:39 +0000177 if (!Ptr) {
Douglas Gregor88764cf2011-03-14 21:19:51 +0000178 AddDecl(D);
179 return;
180 }
Douglas Gregor88764cf2011-03-14 21:19:51 +0000181
Douglas Gregor33f352c2011-03-24 10:35:39 +0000182 if (isDeclPtr(Ptr)) {
183 // We only have a single declaration: insert before or after it,
184 // as appropriate.
185 if (Pos == iterator()) {
186 // Add the new declaration before the existing declaration.
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000187 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
Douglas Gregor33f352c2011-03-24 10:35:39 +0000188 RemoveDecl(PrevD);
189 AddDecl(D);
190 AddDecl(PrevD);
191 } else {
192 // Add new declaration after the existing declaration.
193 AddDecl(D);
194 }
195
196 return;
197 }
198
Douglas Gregor88764cf2011-03-14 21:19:51 +0000199 // General case: insert the declaration at the appropriate point in the
200 // list, which already has at least two elements.
201 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
Douglas Gregor46c04e72011-03-16 16:39:03 +0000202 if (Pos.isIterator()) {
203 IDI->InsertDecl(Pos.getIterator() + 1, D);
204 } else
Douglas Gregor88764cf2011-03-14 21:19:51 +0000205 IDI->InsertDecl(IDI->decls_begin(), D);
206}
207
Argyrios Kyrtzidisdfd52222008-04-12 01:50:47 +0000208/// RemoveDecl - Unlink the decl from its shadowed decl chain.
Chris Lattner9950c802008-04-11 07:06:57 +0000209/// The decl must already be part of the decl chain.
210void IdentifierResolver::RemoveDecl(NamedDecl *D) {
211 assert(D && "null param passed");
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000212 DeclarationName Name = D->getDeclName();
Sebastian Redl671eee92010-07-30 17:25:10 +0000213 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000214 updatingIdentifier(*II);
Sebastian Redl671eee92010-07-30 17:25:10 +0000215
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000216 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattner9950c802008-04-11 07:06:57 +0000217
218 assert(Ptr && "Didn't find this decl on its identifier's chain!");
219
220 if (isDeclPtr(Ptr)) {
221 assert(D == Ptr && "Didn't find this decl on its identifier's chain!");
Craig Topperc3ec1492014-05-26 06:22:03 +0000222 Name.setFETokenInfo(nullptr);
Chris Lattner9950c802008-04-11 07:06:57 +0000223 return;
224 }
Mike Stump11289f42009-09-09 15:08:12 +0000225
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000226 return toIdDeclInfo(Ptr)->RemoveDecl(D);
Chris Lattner9950c802008-04-11 07:06:57 +0000227}
228
Douglas Gregored8f2882009-01-30 01:04:22 +0000229/// begin - Returns an iterator for decls with name 'Name'.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000230IdentifierResolver::iterator
Douglas Gregored8f2882009-01-30 01:04:22 +0000231IdentifierResolver::begin(DeclarationName Name) {
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000232 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
233 readingIdentifier(*II);
234
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000235 void *Ptr = Name.getFETokenInfo<void>();
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000236 if (!Ptr) return end();
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000237
Chris Lattner9631e182009-03-04 06:34:08 +0000238 if (isDeclPtr(Ptr))
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000239 return iterator(static_cast<NamedDecl*>(Ptr));
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000240
Chris Lattner9950c802008-04-11 07:06:57 +0000241 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000242
Douglas Gregor07665a62009-01-05 19:45:36 +0000243 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
Argyrios Kyrtzidisef34aed2008-07-17 17:49:50 +0000244 if (I != IDI->decls_begin())
Douglas Gregored8f2882009-01-30 01:04:22 +0000245 return iterator(I-1);
Chris Lattner9631e182009-03-04 06:34:08 +0000246 // No decls found.
247 return end();
Chris Lattner9950c802008-04-11 07:06:57 +0000248}
249
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000250namespace {
Eugene Zelenko9fbf6412018-02-21 01:45:26 +0000251
252enum DeclMatchKind {
253 DMK_Different,
254 DMK_Replace,
255 DMK_Ignore
256};
257
258} // namespace
Douglas Gregora868bbd2009-04-21 22:25:48 +0000259
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000260/// Compare two declarations to see whether they are different or,
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000261/// if they are the same, whether the new declaration should replace the
262/// existing declaration.
263static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) {
264 // If the declarations are identical, ignore the new one.
265 if (Existing == New)
266 return DMK_Ignore;
267
268 // If the declarations have different kinds, they're obviously different.
269 if (Existing->getKind() != New->getKind())
270 return DMK_Different;
271
272 // If the declarations are redeclarations of each other, keep the newest one.
273 if (Existing->getCanonicalDecl() == New->getCanonicalDecl()) {
Richard Smithfe620d22015-03-05 23:24:12 +0000274 // If we're adding an imported declaration, don't replace another imported
275 // declaration.
276 if (Existing->isFromASTFile() && New->isFromASTFile())
277 return DMK_Different;
278
Douglas Gregordcf25082013-02-11 18:16:18 +0000279 // If either of these is the most recent declaration, use it.
280 Decl *MostRecent = Existing->getMostRecentDecl();
281 if (Existing == MostRecent)
282 return DMK_Ignore;
283
284 if (New == MostRecent)
285 return DMK_Replace;
286
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000287 // If the existing declaration is somewhere in the previous declaration
288 // chain of the new declaration, then prefer the new declaration.
Aaron Ballman86c93902014-03-06 23:45:36 +0000289 for (auto RD : New->redecls()) {
290 if (RD == Existing)
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000291 return DMK_Replace;
292
293 if (RD->isCanonicalDecl())
294 break;
295 }
296
297 return DMK_Ignore;
Douglas Gregora868bbd2009-04-21 22:25:48 +0000298 }
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000299
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000300 return DMK_Different;
301}
Douglas Gregora868bbd2009-04-21 22:25:48 +0000302
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000303bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){
304 if (IdentifierInfo *II = Name.getAsIdentifierInfo())
Douglas Gregor247afcc2012-01-24 15:24:38 +0000305 readingIdentifier(*II);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000306
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000307 void *Ptr = Name.getFETokenInfo<void>();
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000308
309 if (!Ptr) {
310 Name.setFETokenInfo(D);
311 return true;
312 }
313
Douglas Gregora868bbd2009-04-21 22:25:48 +0000314 IdDeclInfo *IDI;
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000315
Douglas Gregora868bbd2009-04-21 22:25:48 +0000316 if (isDeclPtr(Ptr)) {
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000317 NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000318
319 switch (compareDeclarations(PrevD, D)) {
320 case DMK_Different:
321 break;
322
323 case DMK_Ignore:
324 return false;
325
326 case DMK_Replace:
327 Name.setFETokenInfo(D);
328 return true;
329 }
Craig Topperc3ec1492014-05-26 06:22:03 +0000330
331 Name.setFETokenInfo(nullptr);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000332 IDI = &(*IdDeclInfos)[Name];
333
334 // If the existing declaration is not visible in translation unit scope,
335 // then add the new top-level declaration first.
336 if (!PrevD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
337 IDI->AddDecl(D);
338 IDI->AddDecl(PrevD);
339 } else {
340 IDI->AddDecl(PrevD);
341 IDI->AddDecl(D);
342 }
343 return true;
344 }
345
346 IDI = toIdDeclInfo(Ptr);
Douglas Gregora868bbd2009-04-21 22:25:48 +0000347
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000348 // See whether this declaration is identical to any existing declarations.
349 // If not, find the right place to insert it.
350 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
351 IEnd = IDI->decls_end();
352 I != IEnd; ++I) {
353
354 switch (compareDeclarations(*I, D)) {
355 case DMK_Different:
356 break;
357
358 case DMK_Ignore:
359 return false;
360
361 case DMK_Replace:
362 *I = D;
363 return true;
364 }
365
366 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
367 // We've found a declaration that is not visible from the translation
368 // unit (it's in an inner scope). Insert our declaration here.
369 IDI->InsertDecl(I, D);
370 return true;
371 }
372 }
373
374 // Add the declaration to the end.
Douglas Gregora868bbd2009-04-21 22:25:48 +0000375 IDI->AddDecl(D);
Douglas Gregor935bc7a22011-10-27 09:33:13 +0000376 return true;
377}
378
379void IdentifierResolver::readingIdentifier(IdentifierInfo &II) {
380 if (II.isOutOfDate())
381 PP.getExternalSource()->updateOutOfDateIdentifier(II);
382}
383
384void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) {
385 if (II.isOutOfDate())
386 PP.getExternalSource()->updateOutOfDateIdentifier(II);
387
388 if (II.isFromAST())
Richard Smithd79514e2016-02-05 19:03:40 +0000389 II.setFETokenInfoChangedSinceDeserialization();
Douglas Gregora868bbd2009-04-21 22:25:48 +0000390}
391
Argyrios Kyrtzidis4f11d782008-09-09 19:28:27 +0000392//===----------------------------------------------------------------------===//
393// IdDeclInfoMap Implementation
394//===----------------------------------------------------------------------===//
395
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000396/// Returns the IdDeclInfo associated to the DeclarationName.
Chris Lattner9950c802008-04-11 07:06:57 +0000397/// It creates a new IdDeclInfo if one was not created before for this id.
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000398IdentifierResolver::IdDeclInfo &
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000399IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000400 void *Ptr = Name.getFETokenInfo<void>();
Chris Lattner9950c802008-04-11 07:06:57 +0000401
Argyrios Kyrtzidisfa8e15b2008-05-09 23:39:43 +0000402 if (Ptr) return *toIdDeclInfo(Ptr);
Chris Lattner9950c802008-04-11 07:06:57 +0000403
John McCall5f5cbf52010-02-15 19:38:00 +0000404 if (CurIndex == POOL_SIZE) {
405 CurPool = new IdDeclInfoPool(CurPool);
Chris Lattner9950c802008-04-11 07:06:57 +0000406 CurIndex = 0;
407 }
John McCall5f5cbf52010-02-15 19:38:00 +0000408 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000409 Name.setFETokenInfo(reinterpret_cast<void*>(
Chris Lattner9950c802008-04-11 07:06:57 +0000410 reinterpret_cast<uintptr_t>(IDI) | 0x1)
411 );
412 ++CurIndex;
413 return *IDI;
414}
John McCallde6836a2010-08-24 07:21:54 +0000415
416void IdentifierResolver::iterator::incrementSlowCase() {
417 NamedDecl *D = **this;
Eugene Zelenko1e95bc02018-04-05 22:15:42 +0000418 void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
John McCallde6836a2010-08-24 07:21:54 +0000419 assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
420 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
421
422 BaseIter I = getIterator();
423 if (I != Info->decls_begin())
424 *this = iterator(I-1);
425 else // No more decls.
426 *this = iterator();
427}