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