Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 1 | //===- 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 Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 10 | // This file implements the IdentifierResolver class, which is used for lexical |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 11 | // scoped lookup, based on declaration names. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 15 | #include "clang/Sema/IdentifierResolver.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 16 | #include "clang/Sema/Scope.h" |
| 17 | #include "clang/AST/Decl.h" |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 18 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
| 23 | // IdDeclInfoMap class |
| 24 | //===----------------------------------------------------------------------===// |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 25 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 26 | /// IdDeclInfoMap - Associates IdDeclInfos with declaration names. |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 27 | /// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 28 | /// individual IdDeclInfo to heap. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 29 | class IdentifierResolver::IdDeclInfoMap { |
John McCall | eeb1cb4 | 2010-02-15 19:38:00 +0000 | [diff] [blame] | 30 | static const unsigned int POOL_SIZE = 512; |
| 31 | |
| 32 | /// We use our own linked-list implementation because it is sadly |
| 33 | /// impossible to add something to a pre-C++0x STL container without |
| 34 | /// a completely unnecessary copy. |
| 35 | struct IdDeclInfoPool { |
| 36 | IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {} |
| 37 | |
| 38 | IdDeclInfoPool *Next; |
| 39 | IdDeclInfo Pool[POOL_SIZE]; |
| 40 | }; |
| 41 | |
| 42 | IdDeclInfoPool *CurPool; |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 43 | unsigned int CurIndex; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 44 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 45 | public: |
John McCall | eeb1cb4 | 2010-02-15 19:38:00 +0000 | [diff] [blame] | 46 | IdDeclInfoMap() : CurPool(0), CurIndex(POOL_SIZE) {} |
| 47 | |
| 48 | ~IdDeclInfoMap() { |
| 49 | IdDeclInfoPool *Cur = CurPool; |
| 50 | while (IdDeclInfoPool *P = Cur) { |
| 51 | Cur = Cur->Next; |
| 52 | delete P; |
| 53 | } |
| 54 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 55 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 56 | /// Returns the IdDeclInfo associated to the DeclarationName. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 57 | /// It creates a new IdDeclInfo if one was not created before for this id. |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 58 | IdDeclInfo &operator[](DeclarationName Name); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 61 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 62 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 63 | // IdDeclInfo Implementation |
| 64 | //===----------------------------------------------------------------------===// |
| 65 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 66 | /// RemoveDecl - Remove the decl from the scope chain. |
| 67 | /// The decl must already be part of the decl chain. |
| 68 | void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) { |
| 69 | for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { |
| 70 | if (D == *(I-1)) { |
| 71 | Decls.erase(I-1); |
| 72 | return; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | assert(0 && "Didn't find this decl on its identifier's chain!"); |
| 77 | } |
| 78 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | bool |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 80 | IdentifierResolver::IdDeclInfo::ReplaceDecl(NamedDecl *Old, NamedDecl *New) { |
| 81 | for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { |
| 82 | if (Old == *(I-1)) { |
| 83 | *(I - 1) = New; |
| 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return false; |
| 89 | } |
| 90 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 91 | |
| 92 | //===----------------------------------------------------------------------===// |
| 93 | // IdentifierResolver Implementation |
| 94 | //===----------------------------------------------------------------------===// |
| 95 | |
Argyrios Kyrtzidis | eb7c388 | 2008-09-09 21:32:02 +0000 | [diff] [blame] | 96 | IdentifierResolver::IdentifierResolver(const LangOptions &langOpt) |
| 97 | : LangOpt(langOpt), IdDeclInfos(new IdDeclInfoMap) { |
| 98 | } |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 99 | IdentifierResolver::~IdentifierResolver() { |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 100 | delete IdDeclInfos; |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 101 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 102 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 103 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 104 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 105 | /// true if 'D' belongs to the given declaration context. |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 106 | bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 107 | ASTContext &Context, Scope *S) const { |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 108 | Ctx = Ctx->getRedeclContext(); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 109 | |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 110 | if (Ctx->isFunctionOrMethod()) { |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 111 | // Ignore the scopes associated within transparent declaration contexts. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | while (S->getEntity() && |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 113 | ((DeclContext *)S->getEntity())->isTransparentContext()) |
| 114 | S = S->getParent(); |
| 115 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 116 | if (S->isDeclScope(D)) |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 117 | return true; |
| 118 | if (LangOpt.CPlusPlus) { |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 119 | // C++ 3.3.2p3: |
| 120 | // The name declared in a catch exception-declaration is local to the |
| 121 | // handler and shall not be redeclared in the outermost block of the |
| 122 | // handler. |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 123 | // C++ 3.3.2p4: |
| 124 | // Names declared in the for-init-statement, and in the condition of if, |
| 125 | // while, for, and switch statements are local to the if, while, for, or |
| 126 | // switch statement (including the controlled statement), and shall not be |
| 127 | // redeclared in a subsequent condition of that statement nor in the |
| 128 | // outermost block (or, for the if statement, any of the outermost blocks) |
| 129 | // of the controlled statement. |
| 130 | // |
| 131 | assert(S->getParent() && "No TUScope?"); |
| 132 | if (S->getParent()->getFlags() & Scope::ControlScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 133 | return S->getParent()->isDeclScope(D); |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 134 | } |
| 135 | return false; |
| 136 | } |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 137 | |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 138 | return D->getDeclContext()->getRedeclContext()->Equals(Ctx); |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 141 | /// AddDecl - Link the decl to its shadowed decl chain. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 142 | void IdentifierResolver::AddDecl(NamedDecl *D) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 143 | DeclarationName Name = D->getDeclName(); |
Sebastian Redl | 1450ef9 | 2010-07-30 17:25:10 +0000 | [diff] [blame] | 144 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 145 | II->setIsFromAST(false); |
Sebastian Redl | 1450ef9 | 2010-07-30 17:25:10 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 147 | void *Ptr = Name.getFETokenInfo<void>(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 148 | |
| 149 | if (!Ptr) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 150 | Name.setFETokenInfo(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
| 154 | IdDeclInfo *IDI; |
| 155 | |
| 156 | if (isDeclPtr(Ptr)) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 157 | Name.setFETokenInfo(NULL); |
| 158 | IDI = &(*IdDeclInfos)[Name]; |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 159 | NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); |
| 160 | IDI->AddDecl(PrevD); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 161 | } else |
| 162 | IDI = toIdDeclInfo(Ptr); |
| 163 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 164 | IDI->AddDecl(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 167 | /// RemoveDecl - Unlink the decl from its shadowed decl chain. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 168 | /// The decl must already be part of the decl chain. |
| 169 | void IdentifierResolver::RemoveDecl(NamedDecl *D) { |
| 170 | assert(D && "null param passed"); |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 171 | DeclarationName Name = D->getDeclName(); |
Sebastian Redl | 1450ef9 | 2010-07-30 17:25:10 +0000 | [diff] [blame] | 172 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 173 | II->setIsFromAST(false); |
Sebastian Redl | 1450ef9 | 2010-07-30 17:25:10 +0000 | [diff] [blame] | 174 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 175 | void *Ptr = Name.getFETokenInfo<void>(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 176 | |
| 177 | assert(Ptr && "Didn't find this decl on its identifier's chain!"); |
| 178 | |
| 179 | if (isDeclPtr(Ptr)) { |
| 180 | assert(D == Ptr && "Didn't find this decl on its identifier's chain!"); |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 181 | Name.setFETokenInfo(NULL); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 182 | return; |
| 183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 185 | return toIdDeclInfo(Ptr)->RemoveDecl(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 188 | bool IdentifierResolver::ReplaceDecl(NamedDecl *Old, NamedDecl *New) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | assert(Old->getDeclName() == New->getDeclName() && |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 190 | "Cannot replace a decl with another decl of a different name"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 191 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 192 | DeclarationName Name = Old->getDeclName(); |
Sebastian Redl | 1450ef9 | 2010-07-30 17:25:10 +0000 | [diff] [blame] | 193 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 194 | II->setIsFromAST(false); |
Sebastian Redl | 1450ef9 | 2010-07-30 17:25:10 +0000 | [diff] [blame] | 195 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 196 | void *Ptr = Name.getFETokenInfo<void>(); |
| 197 | |
| 198 | if (!Ptr) |
| 199 | return false; |
| 200 | |
| 201 | if (isDeclPtr(Ptr)) { |
| 202 | if (Ptr == Old) { |
| 203 | Name.setFETokenInfo(New); |
| 204 | return true; |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 209 | return toIdDeclInfo(Ptr)->ReplaceDecl(Old, New); |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 212 | /// begin - Returns an iterator for decls with name 'Name'. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 213 | IdentifierResolver::iterator |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 214 | IdentifierResolver::begin(DeclarationName Name) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 215 | void *Ptr = Name.getFETokenInfo<void>(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 216 | if (!Ptr) return end(); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 0b2b6e1 | 2009-03-04 06:34:08 +0000 | [diff] [blame] | 218 | if (isDeclPtr(Ptr)) |
| 219 | return iterator(static_cast<NamedDecl*>(Ptr)); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 220 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 221 | IdDeclInfo *IDI = toIdDeclInfo(Ptr); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 222 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 223 | IdDeclInfo::DeclsTy::iterator I = IDI->decls_end(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 224 | if (I != IDI->decls_begin()) |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 225 | return iterator(I-1); |
Chris Lattner | 0b2b6e1 | 2009-03-04 06:34:08 +0000 | [diff] [blame] | 226 | // No decls found. |
| 227 | return end(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 | void IdentifierResolver::AddDeclToIdentifierChain(IdentifierInfo *II, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 231 | NamedDecl *D) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 232 | II->setIsFromAST(false); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 233 | void *Ptr = II->getFETokenInfo<void>(); |
| 234 | |
| 235 | if (!Ptr) { |
| 236 | II->setFETokenInfo(D); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | IdDeclInfo *IDI; |
| 241 | |
| 242 | if (isDeclPtr(Ptr)) { |
| 243 | II->setFETokenInfo(NULL); |
| 244 | IDI = &(*IdDeclInfos)[II]; |
| 245 | NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); |
| 246 | IDI->AddDecl(PrevD); |
| 247 | } else |
| 248 | IDI = toIdDeclInfo(Ptr); |
| 249 | |
| 250 | IDI->AddDecl(D); |
| 251 | } |
| 252 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 253 | //===----------------------------------------------------------------------===// |
| 254 | // IdDeclInfoMap Implementation |
| 255 | //===----------------------------------------------------------------------===// |
| 256 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 257 | /// Returns the IdDeclInfo associated to the DeclarationName. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 258 | /// It creates a new IdDeclInfo if one was not created before for this id. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 259 | IdentifierResolver::IdDeclInfo & |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 260 | IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) { |
| 261 | void *Ptr = Name.getFETokenInfo<void>(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 262 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 263 | if (Ptr) return *toIdDeclInfo(Ptr); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 264 | |
John McCall | eeb1cb4 | 2010-02-15 19:38:00 +0000 | [diff] [blame] | 265 | if (CurIndex == POOL_SIZE) { |
| 266 | CurPool = new IdDeclInfoPool(CurPool); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 267 | CurIndex = 0; |
| 268 | } |
John McCall | eeb1cb4 | 2010-02-15 19:38:00 +0000 | [diff] [blame] | 269 | IdDeclInfo *IDI = &CurPool->Pool[CurIndex]; |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 270 | Name.setFETokenInfo(reinterpret_cast<void*>( |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 271 | reinterpret_cast<uintptr_t>(IDI) | 0x1) |
| 272 | ); |
| 273 | ++CurIndex; |
| 274 | return *IDI; |
| 275 | } |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 276 | |
| 277 | void IdentifierResolver::iterator::incrementSlowCase() { |
| 278 | NamedDecl *D = **this; |
| 279 | void *InfoPtr = D->getDeclName().getFETokenInfo<void>(); |
| 280 | assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?"); |
| 281 | IdDeclInfo *Info = toIdDeclInfo(InfoPtr); |
| 282 | |
| 283 | BaseIter I = getIterator(); |
| 284 | if (I != Info->decls_begin()) |
| 285 | *this = iterator(I-1); |
| 286 | else // No more decls. |
| 287 | *this = iterator(); |
| 288 | } |