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 | |
| 15 | #include "IdentifierResolver.h" |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 16 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 17 | #include <list> |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 18 | #include <vector> |
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 { |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 30 | static const unsigned int VECTOR_SIZE = 512; |
| 31 | // Holds vectors of IdDeclInfos that serve as 'pools'. |
| 32 | // New vectors are added when the current one is full. |
| 33 | std::list< std::vector<IdDeclInfo> > IDIVecs; |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 34 | unsigned int CurIndex; |
| 35 | |
| 36 | public: |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 37 | IdDeclInfoMap() : CurIndex(VECTOR_SIZE) {} |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 39 | /// Returns the IdDeclInfo associated to the DeclarationName. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 40 | /// 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] | 41 | IdDeclInfo &operator[](DeclarationName Name); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 44 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 45 | //===----------------------------------------------------------------------===// |
| 46 | // LookupContext Implementation |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | |
| 49 | /// getContext - Returns translation unit context for non ScopedDecls and |
| 50 | /// for EnumConstantDecls returns the parent context of their EnumDecl. |
| 51 | DeclContext *IdentifierResolver::LookupContext::getContext(Decl *D) { |
| 52 | DeclContext *Ctx; |
| 53 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 54 | if (EnumConstantDecl *EnumD = dyn_cast<EnumConstantDecl>(D)) { |
| 55 | Ctx = EnumD->getDeclContext()->getParent(); |
| 56 | } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 57 | Ctx = SD->getDeclContext(); |
| 58 | else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) |
| 59 | Ctx = Ovl->getDeclContext(); |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 60 | else |
| 61 | return TUCtx(); |
| 62 | |
Douglas Gregor | ce35607 | 2009-01-06 23:51:29 +0000 | [diff] [blame^] | 63 | Ctx = Ctx->getLookupContext(); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 64 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 65 | if (isa<TranslationUnitDecl>(Ctx)) |
| 66 | return TUCtx(); |
| 67 | |
| 68 | return Ctx; |
| 69 | } |
| 70 | |
| 71 | /// isEqOrContainedBy - Returns true of the given context is the same or a |
| 72 | /// parent of this one. |
| 73 | bool IdentifierResolver::LookupContext::isEqOrContainedBy( |
| 74 | const LookupContext &PC) const { |
| 75 | if (PC.isTU()) return true; |
| 76 | |
| 77 | for (LookupContext Next = *this; !Next.isTU(); Next = Next.getParent()) |
| 78 | if (Next.Ctx == PC.Ctx) return true; |
| 79 | |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | // IdDeclInfo Implementation |
| 86 | //===----------------------------------------------------------------------===// |
| 87 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 88 | /// AddShadowed - Add a decl by putting it directly above the 'Shadow' decl. |
| 89 | /// Later lookups will find the 'Shadow' decl first. The 'Shadow' decl must |
| 90 | /// be already added to the scope chain and must be in the same context as |
| 91 | /// the decl that we want to add. |
| 92 | void IdentifierResolver::IdDeclInfo::AddShadowed(NamedDecl *D, |
| 93 | NamedDecl *Shadow) { |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 94 | for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { |
| 95 | if (Shadow == *(I-1)) { |
| 96 | Decls.insert(I-1, D); |
| 97 | return; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | assert(0 && "Shadow wasn't in scope chain!"); |
| 102 | } |
| 103 | |
| 104 | /// RemoveDecl - Remove the decl from the scope chain. |
| 105 | /// The decl must already be part of the decl chain. |
| 106 | void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) { |
| 107 | for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { |
| 108 | if (D == *(I-1)) { |
| 109 | Decls.erase(I-1); |
| 110 | return; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | assert(0 && "Didn't find this decl on its identifier's chain!"); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | //===----------------------------------------------------------------------===// |
| 119 | // IdentifierResolver Implementation |
| 120 | //===----------------------------------------------------------------------===// |
| 121 | |
Argyrios Kyrtzidis | eb7c388 | 2008-09-09 21:32:02 +0000 | [diff] [blame] | 122 | IdentifierResolver::IdentifierResolver(const LangOptions &langOpt) |
| 123 | : LangOpt(langOpt), IdDeclInfos(new IdDeclInfoMap) { |
| 124 | } |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 125 | IdentifierResolver::~IdentifierResolver() { |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 126 | delete IdDeclInfos; |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 127 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 128 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 129 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 130 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 131 | /// true if 'D' belongs to the given declaration context. |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 132 | bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 133 | ASTContext &Context, Scope *S) const { |
Douglas Gregor | ce35607 | 2009-01-06 23:51:29 +0000 | [diff] [blame^] | 134 | Ctx = Ctx->getLookupContext(); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 135 | |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 136 | if (Ctx->isFunctionOrMethod()) { |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 137 | // Ignore the scopes associated within transparent declaration contexts. |
| 138 | while (S->getEntity() && |
| 139 | ((DeclContext *)S->getEntity())->isTransparentContext()) |
| 140 | S = S->getParent(); |
| 141 | |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 142 | if (S->isDeclScope(D)) |
| 143 | return true; |
| 144 | if (LangOpt.CPlusPlus) { |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 145 | // C++ 3.3.2p3: |
| 146 | // The name declared in a catch exception-declaration is local to the |
| 147 | // handler and shall not be redeclared in the outermost block of the |
| 148 | // handler. |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 149 | // C++ 3.3.2p4: |
| 150 | // Names declared in the for-init-statement, and in the condition of if, |
| 151 | // while, for, and switch statements are local to the if, while, for, or |
| 152 | // switch statement (including the controlled statement), and shall not be |
| 153 | // redeclared in a subsequent condition of that statement nor in the |
| 154 | // outermost block (or, for the if statement, any of the outermost blocks) |
| 155 | // of the controlled statement. |
| 156 | // |
| 157 | assert(S->getParent() && "No TUScope?"); |
| 158 | if (S->getParent()->getFlags() & Scope::ControlScope) |
| 159 | return S->getParent()->isDeclScope(D); |
| 160 | } |
| 161 | return false; |
| 162 | } |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 163 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 164 | return LookupContext(D) == LookupContext(Ctx->getPrimaryContext(Context)); |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 167 | /// AddDecl - Link the decl to its shadowed decl chain. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 168 | void IdentifierResolver::AddDecl(NamedDecl *D) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 169 | DeclarationName Name = D->getDeclName(); |
| 170 | void *Ptr = Name.getFETokenInfo<void>(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 171 | |
| 172 | if (!Ptr) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 173 | Name.setFETokenInfo(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | |
| 177 | IdDeclInfo *IDI; |
| 178 | |
| 179 | if (isDeclPtr(Ptr)) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 180 | Name.setFETokenInfo(NULL); |
| 181 | IDI = &(*IdDeclInfos)[Name]; |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 182 | NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); |
| 183 | IDI->AddDecl(PrevD); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 184 | } else |
| 185 | IDI = toIdDeclInfo(Ptr); |
| 186 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 187 | IDI->AddDecl(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 190 | /// AddShadowedDecl - Link the decl to its shadowed decl chain putting it |
Argyrios Kyrtzidis | 3d0d83a | 2008-05-15 17:26:35 +0000 | [diff] [blame] | 191 | /// after the decl that the iterator points to, thus the 'Shadow' decl will be |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 192 | /// encountered before the 'D' decl. |
| 193 | void IdentifierResolver::AddShadowedDecl(NamedDecl *D, NamedDecl *Shadow) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 194 | assert(D->getDeclName() == Shadow->getDeclName() && "Different ids!"); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 195 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 196 | DeclarationName Name = D->getDeclName(); |
| 197 | void *Ptr = Name.getFETokenInfo<void>(); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 198 | assert(Ptr && "No decl from Ptr ?"); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 199 | |
| 200 | IdDeclInfo *IDI; |
| 201 | |
| 202 | if (isDeclPtr(Ptr)) { |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 203 | Name.setFETokenInfo(NULL); |
| 204 | IDI = &(*IdDeclInfos)[Name]; |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 205 | NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); |
| 206 | assert(PrevD == Shadow && "Invalid shadow decl ?"); |
| 207 | IDI->AddDecl(D); |
| 208 | IDI->AddDecl(PrevD); |
| 209 | return; |
| 210 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 211 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 212 | IDI = toIdDeclInfo(Ptr); |
| 213 | IDI->AddShadowed(D, Shadow); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 216 | /// RemoveDecl - Unlink the decl from its shadowed decl chain. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 217 | /// The decl must already be part of the decl chain. |
| 218 | void IdentifierResolver::RemoveDecl(NamedDecl *D) { |
| 219 | assert(D && "null param passed"); |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 220 | DeclarationName Name = D->getDeclName(); |
| 221 | void *Ptr = Name.getFETokenInfo<void>(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 222 | |
| 223 | assert(Ptr && "Didn't find this decl on its identifier's chain!"); |
| 224 | |
| 225 | if (isDeclPtr(Ptr)) { |
| 226 | 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] | 227 | Name.setFETokenInfo(NULL); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 228 | return; |
| 229 | } |
| 230 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 231 | return toIdDeclInfo(Ptr)->RemoveDecl(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 234 | /// begin - Returns an iterator for decls with name 'Name', starting at |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 235 | /// declaration context 'Ctx'. If 'LookInParentCtx' is true, it will walk the |
| 236 | /// decls of parent declaration contexts too. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 237 | IdentifierResolver::iterator |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 238 | IdentifierResolver::begin(DeclarationName Name, const DeclContext *Ctx, |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 239 | bool LookInParentCtx) { |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 240 | assert(Ctx && "null param passed"); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 241 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 242 | void *Ptr = Name.getFETokenInfo<void>(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 243 | if (!Ptr) return end(); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 244 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 245 | if (isDeclPtr(Ptr)) { |
| 246 | NamedDecl *D = static_cast<NamedDecl*>(Ptr); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 247 | return iterator(D); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 248 | } |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 249 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 250 | IdDeclInfo *IDI = toIdDeclInfo(Ptr); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 251 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 252 | IdDeclInfo::DeclsTy::iterator I = IDI->decls_end(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 253 | if (I != IDI->decls_begin()) |
| 254 | return iterator(I-1, LookInParentCtx); |
| 255 | else // No decls found. |
| 256 | return end(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 259 | /// PreIncIter - Do a preincrement when 'Ptr' is a BaseIter. |
| 260 | void IdentifierResolver::iterator::PreIncIter() { |
| 261 | NamedDecl *D = **this; |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 262 | void *InfoPtr = D->getDeclName().getFETokenInfo<void>(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 263 | assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?"); |
| 264 | IdDeclInfo *Info = toIdDeclInfo(InfoPtr); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 265 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 266 | BaseIter I = getIterator(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 267 | if (I != Info->decls_begin()) |
| 268 | *this = iterator(I-1, LookInParentCtx()); |
| 269 | else // No more decls. |
| 270 | *this = end(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 273 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 274 | //===----------------------------------------------------------------------===// |
| 275 | // IdDeclInfoMap Implementation |
| 276 | //===----------------------------------------------------------------------===// |
| 277 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 278 | /// Returns the IdDeclInfo associated to the DeclarationName. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 279 | /// 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] | 280 | IdentifierResolver::IdDeclInfo & |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 281 | IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) { |
| 282 | void *Ptr = Name.getFETokenInfo<void>(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 283 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 284 | if (Ptr) return *toIdDeclInfo(Ptr); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 285 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 286 | if (CurIndex == VECTOR_SIZE) { |
| 287 | // Add a IdDeclInfo vector 'pool' |
Argyrios Kyrtzidis | 72e62b0 | 2008-04-12 12:38:58 +0000 | [diff] [blame] | 288 | IDIVecs.push_back(std::vector<IdDeclInfo>()); |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 289 | // Fill the vector |
| 290 | IDIVecs.back().resize(VECTOR_SIZE); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 291 | CurIndex = 0; |
| 292 | } |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 293 | IdDeclInfo *IDI = &IDIVecs.back()[CurIndex]; |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 294 | Name.setFETokenInfo(reinterpret_cast<void*>( |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 295 | reinterpret_cast<uintptr_t>(IDI) | 0x1) |
| 296 | ); |
| 297 | ++CurIndex; |
| 298 | return *IDI; |
| 299 | } |