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 |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 11 | // scoped lookup, based on identifier. |
| 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 | |
| 26 | /// IdDeclInfoMap - Associates IdDeclInfos with Identifiers. |
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 | |
| 39 | /// Returns the IdDeclInfo associated to the IdentifierInfo. |
| 40 | /// It creates a new IdDeclInfo if one was not created before for this id. |
| 41 | IdDeclInfo &operator[](IdentifierInfo *II); |
| 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 | |
| 54 | if (CXXFieldDecl *FD = dyn_cast<CXXFieldDecl>(D)) |
| 55 | return FD->getParent(); |
| 56 | |
| 57 | if (EnumConstantDecl *EnumD = dyn_cast<EnumConstantDecl>(D)) { |
| 58 | Ctx = EnumD->getDeclContext()->getParent(); |
| 59 | } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 60 | Ctx = SD->getDeclContext(); |
| 61 | else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) |
| 62 | Ctx = Ovl->getDeclContext(); |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 63 | else |
| 64 | return TUCtx(); |
| 65 | |
| 66 | if (isa<TranslationUnitDecl>(Ctx)) |
| 67 | return TUCtx(); |
| 68 | |
| 69 | return Ctx; |
| 70 | } |
| 71 | |
| 72 | /// isEqOrContainedBy - Returns true of the given context is the same or a |
| 73 | /// parent of this one. |
| 74 | bool IdentifierResolver::LookupContext::isEqOrContainedBy( |
| 75 | const LookupContext &PC) const { |
| 76 | if (PC.isTU()) return true; |
| 77 | |
| 78 | for (LookupContext Next = *this; !Next.isTU(); Next = Next.getParent()) |
| 79 | if (Next.Ctx == PC.Ctx) return true; |
| 80 | |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | // IdDeclInfo Implementation |
| 87 | //===----------------------------------------------------------------------===// |
| 88 | |
| 89 | /// FindContext - Returns an iterator pointing just after the decl that is |
| 90 | /// in the given context or in a parent of it. The search is in reverse |
| 91 | /// order, from end to begin. |
| 92 | IdentifierResolver::IdDeclInfo::DeclsTy::iterator |
| 93 | IdentifierResolver::IdDeclInfo::FindContext(const LookupContext &Ctx, |
| 94 | const DeclsTy::iterator &Start) { |
| 95 | for (DeclsTy::iterator I = Start; I != Decls.begin(); --I) { |
| 96 | if (Ctx.isEqOrContainedBy(LookupContext(*(I-1)))) |
| 97 | return I; |
| 98 | } |
| 99 | |
| 100 | return Decls.begin(); |
| 101 | } |
| 102 | |
| 103 | /// AddShadowed - Add a decl by putting it directly above the 'Shadow' decl. |
| 104 | /// Later lookups will find the 'Shadow' decl first. The 'Shadow' decl must |
| 105 | /// be already added to the scope chain and must be in the same context as |
| 106 | /// the decl that we want to add. |
| 107 | void IdentifierResolver::IdDeclInfo::AddShadowed(NamedDecl *D, |
| 108 | NamedDecl *Shadow) { |
| 109 | assert(LookupContext(D) == LookupContext(Shadow) && |
| 110 | "Decl and Shadow not in same context!"); |
| 111 | |
| 112 | for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { |
| 113 | if (Shadow == *(I-1)) { |
| 114 | Decls.insert(I-1, D); |
| 115 | return; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | assert(0 && "Shadow wasn't in scope chain!"); |
| 120 | } |
| 121 | |
| 122 | /// RemoveDecl - Remove the decl from the scope chain. |
| 123 | /// The decl must already be part of the decl chain. |
| 124 | void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) { |
| 125 | for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) { |
| 126 | if (D == *(I-1)) { |
| 127 | Decls.erase(I-1); |
| 128 | return; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | assert(0 && "Didn't find this decl on its identifier's chain!"); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | //===----------------------------------------------------------------------===// |
| 137 | // IdentifierResolver Implementation |
| 138 | //===----------------------------------------------------------------------===// |
| 139 | |
Argyrios Kyrtzidis | eb7c388 | 2008-09-09 21:32:02 +0000 | [diff] [blame] | 140 | IdentifierResolver::IdentifierResolver(const LangOptions &langOpt) |
| 141 | : LangOpt(langOpt), IdDeclInfos(new IdDeclInfoMap) { |
| 142 | } |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 143 | IdentifierResolver::~IdentifierResolver() { |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 144 | delete IdDeclInfos; |
Argyrios Kyrtzidis | 7bc198f | 2008-04-14 00:09:21 +0000 | [diff] [blame] | 145 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 146 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 147 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 148 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 149 | /// true if 'D' belongs to the given declaration context. |
Argyrios Kyrtzidis | f99cb05 | 2008-09-09 21:57:58 +0000 | [diff] [blame] | 150 | bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, |
| 151 | Scope *S) const { |
| 152 | if (Ctx->isFunctionOrMethod()) { |
| 153 | if (S->isDeclScope(D)) |
| 154 | return true; |
| 155 | if (LangOpt.CPlusPlus) { |
| 156 | // C++ 3.3.2p4: |
| 157 | // Names declared in the for-init-statement, and in the condition of if, |
| 158 | // while, for, and switch statements are local to the if, while, for, or |
| 159 | // switch statement (including the controlled statement), and shall not be |
| 160 | // redeclared in a subsequent condition of that statement nor in the |
| 161 | // outermost block (or, for the if statement, any of the outermost blocks) |
| 162 | // of the controlled statement. |
| 163 | // |
| 164 | assert(S->getParent() && "No TUScope?"); |
| 165 | if (S->getParent()->getFlags() & Scope::ControlScope) |
| 166 | return S->getParent()->isDeclScope(D); |
| 167 | } |
| 168 | return false; |
| 169 | } |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 170 | |
| 171 | return LookupContext(D) == LookupContext(Ctx); |
| 172 | } |
| 173 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 174 | /// AddDecl - Link the decl to its shadowed decl chain. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 175 | void IdentifierResolver::AddDecl(NamedDecl *D) { |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 176 | IdentifierInfo *II = D->getIdentifier(); |
| 177 | void *Ptr = II->getFETokenInfo<void>(); |
| 178 | |
| 179 | if (!Ptr) { |
| 180 | II->setFETokenInfo(D); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | IdDeclInfo *IDI; |
| 185 | |
| 186 | if (isDeclPtr(Ptr)) { |
| 187 | II->setFETokenInfo(NULL); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 188 | IDI = &(*IdDeclInfos)[II]; |
| 189 | NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); |
| 190 | IDI->AddDecl(PrevD); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 191 | } else |
| 192 | IDI = toIdDeclInfo(Ptr); |
| 193 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 194 | IDI->AddDecl(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 197 | /// AddShadowedDecl - Link the decl to its shadowed decl chain putting it |
Argyrios Kyrtzidis | 3d0d83a | 2008-05-15 17:26:35 +0000 | [diff] [blame] | 198 | /// 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] | 199 | /// encountered before the 'D' decl. |
| 200 | void IdentifierResolver::AddShadowedDecl(NamedDecl *D, NamedDecl *Shadow) { |
| 201 | assert(D->getIdentifier() == Shadow->getIdentifier() && "Different ids!"); |
| 202 | assert(LookupContext(D) == LookupContext(Shadow) && "Different context!"); |
| 203 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 204 | IdentifierInfo *II = D->getIdentifier(); |
| 205 | void *Ptr = II->getFETokenInfo<void>(); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 206 | assert(Ptr && "No decl from Ptr ?"); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 207 | |
| 208 | IdDeclInfo *IDI; |
| 209 | |
| 210 | if (isDeclPtr(Ptr)) { |
| 211 | II->setFETokenInfo(NULL); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 212 | IDI = &(*IdDeclInfos)[II]; |
| 213 | NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); |
| 214 | assert(PrevD == Shadow && "Invalid shadow decl ?"); |
| 215 | IDI->AddDecl(D); |
| 216 | IDI->AddDecl(PrevD); |
| 217 | return; |
| 218 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 219 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 220 | IDI = toIdDeclInfo(Ptr); |
| 221 | IDI->AddShadowed(D, Shadow); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 224 | /// RemoveDecl - Unlink the decl from its shadowed decl chain. |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 225 | /// The decl must already be part of the decl chain. |
| 226 | void IdentifierResolver::RemoveDecl(NamedDecl *D) { |
| 227 | assert(D && "null param passed"); |
| 228 | IdentifierInfo *II = D->getIdentifier(); |
| 229 | void *Ptr = II->getFETokenInfo<void>(); |
| 230 | |
| 231 | assert(Ptr && "Didn't find this decl on its identifier's chain!"); |
| 232 | |
| 233 | if (isDeclPtr(Ptr)) { |
| 234 | assert(D == Ptr && "Didn't find this decl on its identifier's chain!"); |
| 235 | II->setFETokenInfo(NULL); |
| 236 | return; |
| 237 | } |
| 238 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 239 | return toIdDeclInfo(Ptr)->RemoveDecl(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 242 | /// begin - Returns an iterator for decls of identifier 'II', starting at |
| 243 | /// declaration context 'Ctx'. If 'LookInParentCtx' is true, it will walk the |
| 244 | /// decls of parent declaration contexts too. |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 245 | IdentifierResolver::iterator |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 246 | IdentifierResolver::begin(const IdentifierInfo *II, const DeclContext *Ctx, |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 247 | bool LookInParentCtx) { |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 248 | assert(Ctx && "null param passed"); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 249 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 250 | void *Ptr = II->getFETokenInfo<void>(); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 251 | if (!Ptr) return end(); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 252 | |
| 253 | LookupContext LC(Ctx); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 254 | |
| 255 | if (isDeclPtr(Ptr)) { |
| 256 | NamedDecl *D = static_cast<NamedDecl*>(Ptr); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 257 | LookupContext DC(D); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 258 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 259 | if (( LookInParentCtx && LC.isEqOrContainedBy(DC)) || |
| 260 | (!LookInParentCtx && LC == DC)) |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 261 | return iterator(D); |
| 262 | else |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 263 | return end(); |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 264 | } |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 265 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 266 | IdDeclInfo *IDI = toIdDeclInfo(Ptr); |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 267 | |
| 268 | IdDeclInfo::DeclsTy::iterator I; |
| 269 | if (LookInParentCtx) |
| 270 | I = IDI->FindContext(LC); |
| 271 | else { |
| 272 | for (I = IDI->decls_end(); I != IDI->decls_begin(); --I) |
| 273 | if (LookupContext(*(I-1)) == LC) |
| 274 | break; |
| 275 | } |
| 276 | |
| 277 | if (I != IDI->decls_begin()) |
| 278 | return iterator(I-1, LookInParentCtx); |
| 279 | else // No decls found. |
| 280 | return end(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 283 | /// PreIncIter - Do a preincrement when 'Ptr' is a BaseIter. |
| 284 | void IdentifierResolver::iterator::PreIncIter() { |
| 285 | NamedDecl *D = **this; |
| 286 | LookupContext Ctx(D); |
| 287 | void *InfoPtr = D->getIdentifier()->getFETokenInfo<void>(); |
| 288 | assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?"); |
| 289 | IdDeclInfo *Info = toIdDeclInfo(InfoPtr); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 290 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 291 | BaseIter I = getIterator(); |
| 292 | if (LookInParentCtx()) |
| 293 | I = Info->FindContext(Ctx, I); |
| 294 | else { |
| 295 | if (I != Info->decls_begin() && LookupContext(*(I-1)) != Ctx) { |
| 296 | // The next decl is in different declaration context. |
| 297 | // Skip remaining decls and set the iterator to the end. |
| 298 | I = Info->decls_begin(); |
| 299 | } |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Argyrios Kyrtzidis | 90eb539 | 2008-07-17 17:49:50 +0000 | [diff] [blame] | 302 | if (I != Info->decls_begin()) |
| 303 | *this = iterator(I-1, LookInParentCtx()); |
| 304 | else // No more decls. |
| 305 | *this = end(); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 308 | |
Argyrios Kyrtzidis | 81bebb1 | 2008-09-09 19:28:27 +0000 | [diff] [blame] | 309 | //===----------------------------------------------------------------------===// |
| 310 | // IdDeclInfoMap Implementation |
| 311 | //===----------------------------------------------------------------------===// |
| 312 | |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 313 | /// Returns the IdDeclInfo associated to the IdentifierInfo. |
| 314 | /// 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] | 315 | IdentifierResolver::IdDeclInfo & |
| 316 | IdentifierResolver::IdDeclInfoMap::operator[](IdentifierInfo *II) { |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 317 | assert (II && "null IdentifierInfo passed"); |
| 318 | void *Ptr = II->getFETokenInfo<void>(); |
| 319 | |
Argyrios Kyrtzidis | 00bc645 | 2008-05-09 23:39:43 +0000 | [diff] [blame] | 320 | if (Ptr) return *toIdDeclInfo(Ptr); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 321 | |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 322 | if (CurIndex == VECTOR_SIZE) { |
| 323 | // Add a IdDeclInfo vector 'pool' |
Argyrios Kyrtzidis | 72e62b0 | 2008-04-12 12:38:58 +0000 | [diff] [blame] | 324 | IDIVecs.push_back(std::vector<IdDeclInfo>()); |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 325 | // Fill the vector |
| 326 | IDIVecs.back().resize(VECTOR_SIZE); |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 327 | CurIndex = 0; |
| 328 | } |
Argyrios Kyrtzidis | 321f278 | 2008-04-12 01:50:47 +0000 | [diff] [blame] | 329 | IdDeclInfo *IDI = &IDIVecs.back()[CurIndex]; |
Chris Lattner | a2f42b1 | 2008-04-11 07:06:57 +0000 | [diff] [blame] | 330 | II->setFETokenInfo(reinterpret_cast<void*>( |
| 331 | reinterpret_cast<uintptr_t>(IDI) | 0x1) |
| 332 | ); |
| 333 | ++CurIndex; |
| 334 | return *IDI; |
| 335 | } |