blob: 224bf877ad249c6dd81baa8b8c06e2d7944d5fa9 [file] [log] [blame]
Eli Friedman56d29372008-06-07 16:52:53 +00001//===--- DeclBase.cpp - Declaration AST Node Implementation ---------------===//
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//
10// This file implements the Decl and DeclContext classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclBase.h"
Douglas Gregor64650af2009-02-02 23:39:07 +000015#include "clang/AST/Decl.h"
Douglas Gregorc2ee10d2009-04-07 17:20:56 +000016#include "clang/AST/DeclContextInternals.h"
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000017#include "clang/AST/DeclCXX.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000018#include "clang/AST/DeclObjC.h"
19#include "clang/AST/DeclTemplate.h"
Douglas Gregor2cf26342009-04-09 22:27:44 +000020#include "clang/AST/ExternalASTSource.h"
Eli Friedman56d29372008-06-07 16:52:53 +000021#include "clang/AST/ASTContext.h"
Douglas Gregor44b43212008-12-11 16:49:14 +000022#include "clang/AST/Type.h"
Sebastian Redld3a413d2009-04-26 20:35:05 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
Eli Friedman56d29372008-06-07 16:52:53 +000025#include "llvm/ADT/DenseMap.h"
Chris Lattner49f28ca2009-03-05 08:00:35 +000026#include "llvm/Support/raw_ostream.h"
Douglas Gregor6ed40e32008-12-23 21:05:05 +000027#include <algorithm>
Chris Lattner3daed522009-03-02 22:20:04 +000028#include <cstdio>
Douglas Gregor3fc749d2008-12-23 00:26:44 +000029#include <vector>
Eli Friedman56d29372008-06-07 16:52:53 +000030using namespace clang;
31
32//===----------------------------------------------------------------------===//
33// Statistics
34//===----------------------------------------------------------------------===//
35
Douglas Gregor64650af2009-02-02 23:39:07 +000036#define DECL(Derived, Base) static int n##Derived##s = 0;
37#include "clang/AST/DeclNodes.def"
Eli Friedman56d29372008-06-07 16:52:53 +000038
39static bool StatSwitch = false;
40
Eli Friedman56d29372008-06-07 16:52:53 +000041const char *Decl::getDeclKindName() const {
42 switch (DeclKind) {
Douglas Gregor64650af2009-02-02 23:39:07 +000043 default: assert(0 && "Declaration not in DeclNodes.def!");
44#define DECL(Derived, Base) case Derived: return #Derived;
45#include "clang/AST/DeclNodes.def"
Eli Friedman56d29372008-06-07 16:52:53 +000046 }
47}
48
Steve Naroff0a473932009-01-20 19:53:53 +000049const char *DeclContext::getDeclKindName() const {
50 switch (DeclKind) {
Douglas Gregor64650af2009-02-02 23:39:07 +000051 default: assert(0 && "Declaration context not in DeclNodes.def!");
Argyrios Kyrtzidis1ad4dd72009-02-16 14:28:33 +000052#define DECL(Derived, Base) case Decl::Derived: return #Derived;
Douglas Gregor64650af2009-02-02 23:39:07 +000053#include "clang/AST/DeclNodes.def"
Steve Naroff0a473932009-01-20 19:53:53 +000054 }
55}
56
Eli Friedman56d29372008-06-07 16:52:53 +000057bool Decl::CollectingStats(bool Enable) {
58 if (Enable)
59 StatSwitch = true;
60 return StatSwitch;
61}
62
63void Decl::PrintStats() {
64 fprintf(stderr, "*** Decl Stats:\n");
Mike Stump1eb44332009-09-09 15:08:12 +000065
Douglas Gregor64650af2009-02-02 23:39:07 +000066 int totalDecls = 0;
67#define DECL(Derived, Base) totalDecls += n##Derived##s;
68#include "clang/AST/DeclNodes.def"
69 fprintf(stderr, " %d decls total.\n", totalDecls);
Mike Stump1eb44332009-09-09 15:08:12 +000070
Douglas Gregor64650af2009-02-02 23:39:07 +000071 int totalBytes = 0;
72#define DECL(Derived, Base) \
73 if (n##Derived##s > 0) { \
74 totalBytes += (int)(n##Derived##s * sizeof(Derived##Decl)); \
75 fprintf(stderr, " %d " #Derived " decls, %d each (%d bytes)\n", \
76 n##Derived##s, (int)sizeof(Derived##Decl), \
77 (int)(n##Derived##s * sizeof(Derived##Decl))); \
78 }
79#include "clang/AST/DeclNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +000080
Douglas Gregor64650af2009-02-02 23:39:07 +000081 fprintf(stderr, "Total bytes = %d\n", totalBytes);
Eli Friedman56d29372008-06-07 16:52:53 +000082}
83
84void Decl::addDeclKind(Kind k) {
85 switch (k) {
Douglas Gregor64650af2009-02-02 23:39:07 +000086 default: assert(0 && "Declaration not in DeclNodes.def!");
87#define DECL(Derived, Base) case Derived: ++n##Derived##s; break;
88#include "clang/AST/DeclNodes.def"
Eli Friedman56d29372008-06-07 16:52:53 +000089 }
90}
91
Anders Carlsson67e33202009-06-13 00:08:58 +000092bool Decl::isTemplateParameterPack() const {
93 if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(this))
94 return TTP->isParameterPack();
Mike Stump1eb44332009-09-09 15:08:12 +000095
Anders Carlsson67e33202009-06-13 00:08:58 +000096 return false;
97}
98
Douglas Gregore53060f2009-06-25 22:08:12 +000099bool Decl::isFunctionOrFunctionTemplate() const {
Anders Carlsson58badb72009-06-26 05:26:50 +0000100 if (const UsingDecl *UD = dyn_cast<UsingDecl>(this))
101 return UD->getTargetDecl()->isFunctionOrFunctionTemplate();
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Douglas Gregore53060f2009-06-25 22:08:12 +0000103 return isa<FunctionDecl>(this) || isa<FunctionTemplateDecl>(this);
104}
105
Eli Friedman56d29372008-06-07 16:52:53 +0000106//===----------------------------------------------------------------------===//
Chris Lattner49f28ca2009-03-05 08:00:35 +0000107// PrettyStackTraceDecl Implementation
108//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +0000109
Chris Lattner49f28ca2009-03-05 08:00:35 +0000110void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const {
111 SourceLocation TheLoc = Loc;
112 if (TheLoc.isInvalid() && TheDecl)
113 TheLoc = TheDecl->getLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000114
Chris Lattner49f28ca2009-03-05 08:00:35 +0000115 if (TheLoc.isValid()) {
116 TheLoc.print(OS, SM);
117 OS << ": ";
118 }
119
120 OS << Message;
121
122 if (NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl))
123 OS << " '" << DN->getQualifiedNameAsString() << '\'';
124 OS << '\n';
125}
Mike Stump1eb44332009-09-09 15:08:12 +0000126
Chris Lattner49f28ca2009-03-05 08:00:35 +0000127//===----------------------------------------------------------------------===//
Eli Friedman56d29372008-06-07 16:52:53 +0000128// Decl Implementation
129//===----------------------------------------------------------------------===//
130
Chris Lattner769dbdf2009-03-27 20:18:19 +0000131// Out-of-line virtual method providing a home for Decl.
132Decl::~Decl() {
133 if (isOutOfSemaDC())
134 delete getMultipleDC();
Mike Stump1eb44332009-09-09 15:08:12 +0000135
Chris Lattner769dbdf2009-03-27 20:18:19 +0000136 assert(!HasAttrs && "attributes should have been freed by Destroy");
137}
138
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000139void Decl::setDeclContext(DeclContext *DC) {
140 if (isOutOfSemaDC())
141 delete getMultipleDC();
Mike Stump1eb44332009-09-09 15:08:12 +0000142
Chris Lattneree219fd2009-03-29 06:06:59 +0000143 DeclCtx = DC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000144}
145
146void Decl::setLexicalDeclContext(DeclContext *DC) {
147 if (DC == getLexicalDeclContext())
148 return;
149
150 if (isInSemaDC()) {
151 MultipleDC *MDC = new MultipleDC();
152 MDC->SemanticDC = getDeclContext();
153 MDC->LexicalDC = DC;
Chris Lattneree219fd2009-03-29 06:06:59 +0000154 DeclCtx = MDC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000155 } else {
156 getMultipleDC()->LexicalDC = DC;
157 }
158}
159
John McCall9aeed322009-10-01 00:25:31 +0000160bool Decl::isInAnonymousNamespace() const {
161 const DeclContext *DC = getDeclContext();
162 do {
163 if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC))
164 if (ND->isAnonymousNamespace())
165 return true;
166 } while ((DC = DC->getParent()));
167
168 return false;
169}
170
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000171TranslationUnitDecl *Decl::getTranslationUnitDecl() {
Argyrios Kyrtzidis9b346692009-06-30 02:34:53 +0000172 if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this))
173 return TUD;
174
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000175 DeclContext *DC = getDeclContext();
176 assert(DC && "This decl is not contained in a translation unit!");
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000178 while (!DC->isTranslationUnit()) {
179 DC = DC->getParent();
180 assert(DC && "This decl is not contained in a translation unit!");
181 }
Mike Stump1eb44332009-09-09 15:08:12 +0000182
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000183 return cast<TranslationUnitDecl>(DC);
184}
185
186ASTContext &Decl::getASTContext() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000187 return getTranslationUnitDecl()->getASTContext();
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000188}
189
Chris Lattner769dbdf2009-03-27 20:18:19 +0000190unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
191 switch (DeclKind) {
Mike Stump1eb44332009-09-09 15:08:12 +0000192 default:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000193 if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast)
194 return IDNS_Ordinary;
195 assert(0 && "Unknown decl kind!");
196 case OverloadedFunction:
197 case Typedef:
198 case EnumConstant:
199 case Var:
200 case ImplicitParam:
201 case ParmVar:
202 case OriginalParmVar:
203 case NonTypeTemplateParm:
Douglas Gregor9cfbe482009-06-20 00:51:54 +0000204 case Using:
Anders Carlsson665b49c2009-08-28 05:30:28 +0000205 case UnresolvedUsing:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000206 case ObjCMethod:
207 case ObjCContainer:
208 case ObjCCategory:
209 case ObjCInterface:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000210 case ObjCProperty:
211 case ObjCCompatibleAlias:
212 return IDNS_Ordinary;
John McCall3f9a8a62009-08-11 06:59:38 +0000213
Chris Lattner769dbdf2009-03-27 20:18:19 +0000214 case ObjCProtocol:
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000215 return IDNS_ObjCProtocol;
Mike Stump1eb44332009-09-09 15:08:12 +0000216
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000217 case ObjCImplementation:
218 return IDNS_ObjCImplementation;
219
220 case ObjCCategoryImpl:
221 return IDNS_ObjCCategoryImpl;
222
Chris Lattner769dbdf2009-03-27 20:18:19 +0000223 case Field:
224 case ObjCAtDefsField:
225 case ObjCIvar:
226 return IDNS_Member;
Mike Stump1eb44332009-09-09 15:08:12 +0000227
Chris Lattner769dbdf2009-03-27 20:18:19 +0000228 case Record:
229 case CXXRecord:
230 case Enum:
231 case TemplateTypeParm:
232 return IDNS_Tag;
Mike Stump1eb44332009-09-09 15:08:12 +0000233
Chris Lattner769dbdf2009-03-27 20:18:19 +0000234 case Namespace:
235 case Template:
236 case FunctionTemplate:
237 case ClassTemplate:
238 case TemplateTemplateParm:
Anders Carlssonfaf0e872009-03-28 23:02:53 +0000239 case NamespaceAlias:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000240 return IDNS_Tag | IDNS_Ordinary;
Mike Stump1eb44332009-09-09 15:08:12 +0000241
Chris Lattner769dbdf2009-03-27 20:18:19 +0000242 // Never have names.
John McCall02cace72009-08-28 07:59:38 +0000243 case Friend:
John McCalldd4a3b02009-09-16 22:47:08 +0000244 case FriendTemplate:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000245 case LinkageSpec:
246 case FileScopeAsm:
247 case StaticAssert:
248 case ObjCClass:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000249 case ObjCPropertyImpl:
250 case ObjCForwardProtocol:
251 case Block:
252 case TranslationUnit:
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000253
Chris Lattner769dbdf2009-03-27 20:18:19 +0000254 // Aren't looked up?
255 case UsingDirective:
256 case ClassTemplateSpecialization:
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000257 case ClassTemplatePartialSpecialization:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000258 return 0;
259 }
Eli Friedman56d29372008-06-07 16:52:53 +0000260}
261
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000262void Decl::addAttr(Attr *NewAttr) {
263 Attr *&ExistingAttr = getASTContext().getDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000264
265 NewAttr->setNext(ExistingAttr);
266 ExistingAttr = NewAttr;
Mike Stump1eb44332009-09-09 15:08:12 +0000267
Eli Friedman56d29372008-06-07 16:52:53 +0000268 HasAttrs = true;
269}
270
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000271void Decl::invalidateAttrs() {
Eli Friedman56d29372008-06-07 16:52:53 +0000272 if (!HasAttrs) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000273
Eli Friedman56d29372008-06-07 16:52:53 +0000274 HasAttrs = false;
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000275 getASTContext().eraseDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000276}
277
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000278const Attr *Decl::getAttrsImpl() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000279 assert(HasAttrs && "getAttrs() should verify this!");
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000280 return getASTContext().getDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000281}
282
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000283void Decl::swapAttrs(Decl *RHS) {
Eli Friedman56d29372008-06-07 16:52:53 +0000284 bool HasLHSAttr = this->HasAttrs;
285 bool HasRHSAttr = RHS->HasAttrs;
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Eli Friedman56d29372008-06-07 16:52:53 +0000287 // Usually, neither decl has attrs, nothing to do.
288 if (!HasLHSAttr && !HasRHSAttr) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000289
Eli Friedman56d29372008-06-07 16:52:53 +0000290 // If 'this' has no attrs, swap the other way.
291 if (!HasLHSAttr)
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000292 return RHS->swapAttrs(this);
Mike Stump1eb44332009-09-09 15:08:12 +0000293
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000294 ASTContext &Context = getASTContext();
Mike Stump1eb44332009-09-09 15:08:12 +0000295
Eli Friedman56d29372008-06-07 16:52:53 +0000296 // Handle the case when both decls have attrs.
297 if (HasRHSAttr) {
Douglas Gregor68584ed2009-06-18 16:11:24 +0000298 std::swap(Context.getDeclAttrs(this), Context.getDeclAttrs(RHS));
Eli Friedman56d29372008-06-07 16:52:53 +0000299 return;
300 }
Mike Stump1eb44332009-09-09 15:08:12 +0000301
Eli Friedman56d29372008-06-07 16:52:53 +0000302 // Otherwise, LHS has an attr and RHS doesn't.
Douglas Gregor68584ed2009-06-18 16:11:24 +0000303 Context.getDeclAttrs(RHS) = Context.getDeclAttrs(this);
304 Context.eraseDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000305 this->HasAttrs = false;
306 RHS->HasAttrs = true;
307}
308
309
Chris Lattnercc581472009-03-04 06:05:19 +0000310void Decl::Destroy(ASTContext &C) {
311 // Free attributes for this decl.
312 if (HasAttrs) {
Douglas Gregor68584ed2009-06-18 16:11:24 +0000313 C.getDeclAttrs(this)->Destroy(C);
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000314 invalidateAttrs();
Chris Lattnercc581472009-03-04 06:05:19 +0000315 HasAttrs = false;
316 }
Mike Stump1eb44332009-09-09 15:08:12 +0000317
Douglas Gregora0fc55f2009-01-13 19:47:12 +0000318#if 0
Douglas Gregor00ad0ef2009-01-20 04:25:11 +0000319 // FIXME: Once ownership is fully understood, we can enable this code
320 if (DeclContext *DC = dyn_cast<DeclContext>(this))
321 DC->decls_begin()->Destroy(C);
Eli Friedman56d29372008-06-07 16:52:53 +0000322
Chris Lattner244a67d2009-03-28 06:04:26 +0000323 // Observe the unrolled recursion. By setting N->NextDeclInContext = 0x0
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000324 // within the loop, only the Destroy method for the first Decl
325 // will deallocate all of the Decls in a chain.
Mike Stump1eb44332009-09-09 15:08:12 +0000326
Chris Lattner244a67d2009-03-28 06:04:26 +0000327 Decl* N = getNextDeclInContext();
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000329 while (N) {
Chris Lattner244a67d2009-03-28 06:04:26 +0000330 Decl* Tmp = N->getNextDeclInContext();
331 N->NextDeclInContext = 0;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000332 N->Destroy(C);
333 N = Tmp;
Mike Stump1eb44332009-09-09 15:08:12 +0000334 }
Douglas Gregora0fc55f2009-01-13 19:47:12 +0000335
Eli Friedman56d29372008-06-07 16:52:53 +0000336 this->~Decl();
Steve Naroff3e970492009-01-27 21:25:57 +0000337 C.Deallocate((void *)this);
Douglas Gregor00ad0ef2009-01-20 04:25:11 +0000338#endif
Eli Friedman56d29372008-06-07 16:52:53 +0000339}
340
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000341Decl *Decl::castFromDeclContext (const DeclContext *D) {
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000342 Decl::Kind DK = D->getDeclKind();
343 switch(DK) {
344#define DECL_CONTEXT(Name) \
345 case Decl::Name: \
346 return static_cast<Name##Decl*>(const_cast<DeclContext*>(D));
347#define DECL_CONTEXT_BASE(Name)
348#include "clang/AST/DeclNodes.def"
349 default:
350#define DECL_CONTEXT_BASE(Name) \
351 if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \
352 return static_cast<Name##Decl*>(const_cast<DeclContext*>(D));
353#include "clang/AST/DeclNodes.def"
354 assert(false && "a decl that inherits DeclContext isn't handled");
355 return 0;
356 }
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000357}
358
359DeclContext *Decl::castToDeclContext(const Decl *D) {
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000360 Decl::Kind DK = D->getKind();
361 switch(DK) {
362#define DECL_CONTEXT(Name) \
363 case Decl::Name: \
364 return static_cast<Name##Decl*>(const_cast<Decl*>(D));
365#define DECL_CONTEXT_BASE(Name)
366#include "clang/AST/DeclNodes.def"
367 default:
368#define DECL_CONTEXT_BASE(Name) \
369 if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \
370 return static_cast<Name##Decl*>(const_cast<Decl*>(D));
371#include "clang/AST/DeclNodes.def"
372 assert(false && "a decl that inherits DeclContext isn't handled");
373 return 0;
374 }
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000375}
376
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000377CompoundStmt* Decl::getCompoundBody() const {
378 return dyn_cast_or_null<CompoundStmt>(getBody());
Sebastian Redld3a413d2009-04-26 20:35:05 +0000379}
380
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000381SourceLocation Decl::getBodyRBrace() const {
382 Stmt *Body = getBody();
Sebastian Redld3a413d2009-04-26 20:35:05 +0000383 if (!Body)
384 return SourceLocation();
385 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Body))
386 return CS->getRBracLoc();
387 assert(isa<CXXTryStmt>(Body) &&
388 "Body can only be CompoundStmt or CXXTryStmt");
389 return cast<CXXTryStmt>(Body)->getSourceRange().getEnd();
390}
391
Anders Carlsson1329c272009-03-25 23:38:06 +0000392#ifndef NDEBUG
393void Decl::CheckAccessDeclContext() const {
Anders Carlsson35eda442009-08-29 20:47:47 +0000394 // If the decl is the toplevel translation unit or if we're not in a
395 // record decl context, we don't need to check anything.
396 if (isa<TranslationUnitDecl>(this) ||
397 !isa<CXXRecordDecl>(getDeclContext()))
398 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000399
400 assert(Access != AS_none &&
Anders Carlsson1329c272009-03-25 23:38:06 +0000401 "Access specifier is AS_none inside a record decl");
402}
403
404#endif
405
Eli Friedman56d29372008-06-07 16:52:53 +0000406//===----------------------------------------------------------------------===//
407// DeclContext Implementation
408//===----------------------------------------------------------------------===//
409
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000410bool DeclContext::classof(const Decl *D) {
411 switch (D->getKind()) {
412#define DECL_CONTEXT(Name) case Decl::Name:
413#define DECL_CONTEXT_BASE(Name)
414#include "clang/AST/DeclNodes.def"
415 return true;
416 default:
417#define DECL_CONTEXT_BASE(Name) \
418 if (D->getKind() >= Decl::Name##First && \
419 D->getKind() <= Decl::Name##Last) \
420 return true;
421#include "clang/AST/DeclNodes.def"
422 return false;
423 }
424}
425
Douglas Gregor44b43212008-12-11 16:49:14 +0000426DeclContext::~DeclContext() {
Douglas Gregorc36c5402009-04-09 17:29:08 +0000427 delete static_cast<StoredDeclsMap*>(LookupPtr);
Douglas Gregor44b43212008-12-11 16:49:14 +0000428}
429
430void DeclContext::DestroyDecls(ASTContext &C) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000431 for (decl_iterator D = decls_begin(); D != decls_end(); )
Douglas Gregor00ad0ef2009-01-20 04:25:11 +0000432 (*D++)->Destroy(C);
Douglas Gregor44b43212008-12-11 16:49:14 +0000433}
434
Douglas Gregore942bbe2009-09-10 16:57:35 +0000435/// \brief Find the parent context of this context that will be
436/// used for unqualified name lookup.
437///
438/// Generally, the parent lookup context is the semantic context. However, for
439/// a friend function the parent lookup context is the lexical context, which
440/// is the class in which the friend is declared.
441DeclContext *DeclContext::getLookupParent() {
442 // FIXME: Find a better way to identify friends
443 if (isa<FunctionDecl>(this))
444 if (getParent()->getLookupContext()->isFileContext() &&
445 getLexicalParent()->getLookupContext()->isRecord())
446 return getLexicalParent();
447
448 return getParent();
449}
450
Douglas Gregorbc221632009-05-28 16:34:51 +0000451bool DeclContext::isDependentContext() const {
452 if (isFileContext())
453 return false;
454
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000455 if (isa<ClassTemplatePartialSpecializationDecl>(this))
456 return true;
457
Douglas Gregorbc221632009-05-28 16:34:51 +0000458 if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this))
459 if (Record->getDescribedClassTemplate())
460 return true;
461
462 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(this))
463 if (Function->getDescribedFunctionTemplate())
464 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000465
Douglas Gregorbc221632009-05-28 16:34:51 +0000466 return getParent() && getParent()->isDependentContext();
467}
468
Douglas Gregor074149e2009-01-05 19:45:36 +0000469bool DeclContext::isTransparentContext() const {
470 if (DeclKind == Decl::Enum)
471 return true; // FIXME: Check for C++0x scoped enums
472 else if (DeclKind == Decl::LinkageSpec)
473 return true;
Douglas Gregor65100792009-02-26 00:02:51 +0000474 else if (DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast)
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000475 return cast<RecordDecl>(this)->isAnonymousStructOrUnion();
Douglas Gregor074149e2009-01-05 19:45:36 +0000476 else if (DeclKind == Decl::Namespace)
477 return false; // FIXME: Check for C++0x inline namespaces
478
479 return false;
480}
481
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000482bool DeclContext::Encloses(DeclContext *DC) {
483 if (getPrimaryContext() != this)
484 return getPrimaryContext()->Encloses(DC);
Mike Stump1eb44332009-09-09 15:08:12 +0000485
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000486 for (; DC; DC = DC->getParent())
487 if (DC->getPrimaryContext() == this)
488 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000489 return false;
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000490}
491
Steve Naroff0701bbb2009-01-08 17:28:14 +0000492DeclContext *DeclContext::getPrimaryContext() {
Douglas Gregor44b43212008-12-11 16:49:14 +0000493 switch (DeclKind) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000494 case Decl::TranslationUnit:
Douglas Gregor074149e2009-01-05 19:45:36 +0000495 case Decl::LinkageSpec:
Mike Stump1eb44332009-09-09 15:08:12 +0000496 case Decl::Block:
Douglas Gregor44b43212008-12-11 16:49:14 +0000497 // There is only one DeclContext for these entities.
498 return this;
499
500 case Decl::Namespace:
501 // The original namespace is our primary context.
502 return static_cast<NamespaceDecl*>(this)->getOriginalNamespace();
503
Douglas Gregor44b43212008-12-11 16:49:14 +0000504 case Decl::ObjCMethod:
505 return this;
506
507 case Decl::ObjCInterface:
Steve Naroff0701bbb2009-01-08 17:28:14 +0000508 case Decl::ObjCProtocol:
509 case Decl::ObjCCategory:
Douglas Gregor44b43212008-12-11 16:49:14 +0000510 // FIXME: Can Objective-C interfaces be forward-declared?
511 return this;
512
Steve Naroff0701bbb2009-01-08 17:28:14 +0000513 case Decl::ObjCImplementation:
514 case Decl::ObjCCategoryImpl:
515 return this;
516
Douglas Gregor44b43212008-12-11 16:49:14 +0000517 default:
Douglas Gregorcc636682009-02-17 23:15:12 +0000518 if (DeclKind >= Decl::TagFirst && DeclKind <= Decl::TagLast) {
519 // If this is a tag type that has a definition or is currently
520 // being defined, that definition is our primary context.
Ted Kremenek6217b802009-07-29 21:53:49 +0000521 if (const TagType *TagT =cast<TagDecl>(this)->TypeForDecl->getAs<TagType>())
Mike Stump1eb44332009-09-09 15:08:12 +0000522 if (TagT->isBeingDefined() ||
Douglas Gregorcc636682009-02-17 23:15:12 +0000523 (TagT->getDecl() && TagT->getDecl()->isDefinition()))
524 return TagT->getDecl();
525 return this;
526 }
527
Douglas Gregor44b43212008-12-11 16:49:14 +0000528 assert(DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast &&
529 "Unknown DeclContext kind");
530 return this;
531 }
532}
533
534DeclContext *DeclContext::getNextContext() {
535 switch (DeclKind) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000536 case Decl::Namespace:
537 // Return the next namespace
538 return static_cast<NamespaceDecl*>(this)->getNextNamespace();
539
540 default:
Douglas Gregor44b43212008-12-11 16:49:14 +0000541 return 0;
542 }
543}
544
Douglas Gregor2cf26342009-04-09 22:27:44 +0000545/// \brief Load the declarations within this lexical storage from an
546/// external source.
Mike Stump1eb44332009-09-09 15:08:12 +0000547void
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000548DeclContext::LoadLexicalDeclsFromExternalStorage() const {
549 ExternalASTSource *Source = getParentASTContext().getExternalSource();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000550 assert(hasExternalLexicalStorage() && Source && "No external storage?");
551
Eli Friedmanb0156ea2009-04-27 23:43:36 +0000552 llvm::SmallVector<uint32_t, 64> Decls;
Mike Stump1eb44332009-09-09 15:08:12 +0000553 if (Source->ReadDeclsLexicallyInContext(const_cast<DeclContext *>(this),
Douglas Gregor2cf26342009-04-09 22:27:44 +0000554 Decls))
555 return;
556
557 // There is no longer any lexical storage in this context
558 ExternalLexicalStorage = false;
559
560 if (Decls.empty())
561 return;
562
563 // Resolve all of the declaration IDs into declarations, building up
564 // a chain of declarations via the Decl::NextDeclInContext field.
565 Decl *FirstNewDecl = 0;
566 Decl *PrevDecl = 0;
567 for (unsigned I = 0, N = Decls.size(); I != N; ++I) {
568 Decl *D = Source->GetDecl(Decls[I]);
569 if (PrevDecl)
570 PrevDecl->NextDeclInContext = D;
571 else
572 FirstNewDecl = D;
573
574 PrevDecl = D;
575 }
576
577 // Splice the newly-read declarations into the beginning of the list
578 // of declarations.
579 PrevDecl->NextDeclInContext = FirstDecl;
580 FirstDecl = FirstNewDecl;
581 if (!LastDecl)
582 LastDecl = PrevDecl;
583}
584
Mike Stump1eb44332009-09-09 15:08:12 +0000585void
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000586DeclContext::LoadVisibleDeclsFromExternalStorage() const {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000587 DeclContext *This = const_cast<DeclContext *>(this);
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000588 ExternalASTSource *Source = getParentASTContext().getExternalSource();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000589 assert(hasExternalVisibleStorage() && Source && "No external storage?");
590
591 llvm::SmallVector<VisibleDeclaration, 64> Decls;
592 if (Source->ReadDeclsVisibleInContext(This, Decls))
593 return;
594
595 // There is no longer any visible storage in this context
596 ExternalVisibleStorage = false;
597
598 // Load the declaration IDs for all of the names visible in this
599 // context.
600 assert(!LookupPtr && "Have a lookup map before de-serialization?");
601 StoredDeclsMap *Map = new StoredDeclsMap;
602 LookupPtr = Map;
603 for (unsigned I = 0, N = Decls.size(); I != N; ++I) {
604 (*Map)[Decls[I].Name].setFromDeclIDs(Decls[I].Declarations);
605 }
606}
607
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000608DeclContext::decl_iterator DeclContext::decls_begin() const {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000609 if (hasExternalLexicalStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000610 LoadLexicalDeclsFromExternalStorage();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000611
612 // FIXME: Check whether we need to load some declarations from
613 // external storage.
Mike Stump1eb44332009-09-09 15:08:12 +0000614 return decl_iterator(FirstDecl);
Douglas Gregor6ab35242009-04-09 21:40:53 +0000615}
616
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000617DeclContext::decl_iterator DeclContext::decls_end() const {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000618 if (hasExternalLexicalStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000619 LoadLexicalDeclsFromExternalStorage();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000620
Mike Stump1eb44332009-09-09 15:08:12 +0000621 return decl_iterator();
Douglas Gregor6ab35242009-04-09 21:40:53 +0000622}
623
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000624bool DeclContext::decls_empty() const {
Douglas Gregor8038d512009-04-10 17:25:41 +0000625 if (hasExternalLexicalStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000626 LoadLexicalDeclsFromExternalStorage();
Douglas Gregor8038d512009-04-10 17:25:41 +0000627
628 return !FirstDecl;
629}
630
John McCall3f9a8a62009-08-11 06:59:38 +0000631void DeclContext::addHiddenDecl(Decl *D) {
Chris Lattner7f0be132009-02-20 00:56:18 +0000632 assert(D->getLexicalDeclContext() == this &&
633 "Decl inserted into wrong lexical context");
Mike Stump1eb44332009-09-09 15:08:12 +0000634 assert(!D->getNextDeclInContext() && D != LastDecl &&
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000635 "Decl already inserted into a DeclContext");
636
637 if (FirstDecl) {
Chris Lattner244a67d2009-03-28 06:04:26 +0000638 LastDecl->NextDeclInContext = D;
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000639 LastDecl = D;
640 } else {
641 FirstDecl = LastDecl = D;
642 }
John McCall3f9a8a62009-08-11 06:59:38 +0000643}
644
645void DeclContext::addDecl(Decl *D) {
646 addHiddenDecl(D);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000647
648 if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000649 ND->getDeclContext()->makeDeclVisibleInContext(ND);
Douglas Gregor44b43212008-12-11 16:49:14 +0000650}
651
Douglas Gregor074149e2009-01-05 19:45:36 +0000652/// buildLookup - Build the lookup data structure with all of the
653/// declarations in DCtx (and any other contexts linked to it or
654/// transparent contexts nested within it).
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000655void DeclContext::buildLookup(DeclContext *DCtx) {
Douglas Gregor074149e2009-01-05 19:45:36 +0000656 for (; DCtx; DCtx = DCtx->getNextContext()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000657 for (decl_iterator D = DCtx->decls_begin(),
658 DEnd = DCtx->decls_end();
Douglas Gregor4f3b8f82009-01-06 07:17:58 +0000659 D != DEnd; ++D) {
John McCall3f9a8a62009-08-11 06:59:38 +0000660 // Insert this declaration into the lookup structure, but only
661 // if it's semantically in its decl context. During non-lazy
662 // lookup building, this is implicitly enforced by addDecl.
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000663 if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
John McCall3f9a8a62009-08-11 06:59:38 +0000664 if (D->getDeclContext() == DCtx)
665 makeDeclVisibleInContextImpl(ND);
Douglas Gregor074149e2009-01-05 19:45:36 +0000666
667 // If this declaration is itself a transparent declaration context,
668 // add its members (recursively).
669 if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D))
670 if (InnerCtx->isTransparentContext())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000671 buildLookup(InnerCtx->getPrimaryContext());
Douglas Gregor074149e2009-01-05 19:45:36 +0000672 }
673 }
674}
675
Mike Stump1eb44332009-09-09 15:08:12 +0000676DeclContext::lookup_result
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000677DeclContext::lookup(DeclarationName Name) {
Steve Naroff0701bbb2009-01-08 17:28:14 +0000678 DeclContext *PrimaryContext = getPrimaryContext();
Douglas Gregor44b43212008-12-11 16:49:14 +0000679 if (PrimaryContext != this)
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000680 return PrimaryContext->lookup(Name);
Douglas Gregor44b43212008-12-11 16:49:14 +0000681
Douglas Gregor2cf26342009-04-09 22:27:44 +0000682 if (hasExternalVisibleStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000683 LoadVisibleDeclsFromExternalStorage();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000684
Douglas Gregor3fc749d2008-12-23 00:26:44 +0000685 /// If there is no lookup data structure, build one now by walking
Douglas Gregor44b43212008-12-11 16:49:14 +0000686 /// all of the linked DeclContexts (in declaration order!) and
687 /// inserting their values.
Douglas Gregorc36c5402009-04-09 17:29:08 +0000688 if (!LookupPtr) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000689 buildLookup(this);
Douglas Gregor44b43212008-12-11 16:49:14 +0000690
Douglas Gregorc36c5402009-04-09 17:29:08 +0000691 if (!LookupPtr)
Chris Lattner91942502009-02-20 00:55:03 +0000692 return lookup_result(0, 0);
Douglas Gregorc36c5402009-04-09 17:29:08 +0000693 }
Douglas Gregor44b43212008-12-11 16:49:14 +0000694
Douglas Gregorc36c5402009-04-09 17:29:08 +0000695 StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(LookupPtr);
696 StoredDeclsMap::iterator Pos = Map->find(Name);
697 if (Pos == Map->end())
698 return lookup_result(0, 0);
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000699 return Pos->second.getLookupResult(getParentASTContext());
Douglas Gregor44b43212008-12-11 16:49:14 +0000700}
701
Mike Stump1eb44332009-09-09 15:08:12 +0000702DeclContext::lookup_const_result
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000703DeclContext::lookup(DeclarationName Name) const {
704 return const_cast<DeclContext*>(this)->lookup(Name);
Douglas Gregor44b43212008-12-11 16:49:14 +0000705}
706
Chris Lattner0cf2b192009-03-27 19:19:59 +0000707DeclContext *DeclContext::getLookupContext() {
708 DeclContext *Ctx = this;
Douglas Gregor72de6672009-01-08 20:45:30 +0000709 // Skip through transparent contexts.
Douglas Gregorce356072009-01-06 23:51:29 +0000710 while (Ctx->isTransparentContext())
711 Ctx = Ctx->getParent();
712 return Ctx;
713}
714
Douglas Gregor88b70942009-02-25 22:02:03 +0000715DeclContext *DeclContext::getEnclosingNamespaceContext() {
716 DeclContext *Ctx = this;
717 // Skip through non-namespace, non-translation-unit contexts.
718 while (!Ctx->isFileContext() || Ctx->isTransparentContext())
719 Ctx = Ctx->getParent();
720 return Ctx->getPrimaryContext();
721}
722
John McCallab88d972009-08-31 22:39:49 +0000723void DeclContext::makeDeclVisibleInContext(NamedDecl *D, bool Recoverable) {
Douglas Gregorcc636682009-02-17 23:15:12 +0000724 // FIXME: This feels like a hack. Should DeclarationName support
725 // template-ids, or is there a better way to keep specializations
726 // from being visible?
727 if (isa<ClassTemplateSpecializationDecl>(D))
728 return;
729
Steve Naroff0701bbb2009-01-08 17:28:14 +0000730 DeclContext *PrimaryContext = getPrimaryContext();
Douglas Gregor44b43212008-12-11 16:49:14 +0000731 if (PrimaryContext != this) {
John McCallab88d972009-08-31 22:39:49 +0000732 PrimaryContext->makeDeclVisibleInContext(D, Recoverable);
Douglas Gregor44b43212008-12-11 16:49:14 +0000733 return;
734 }
735
736 // If we already have a lookup data structure, perform the insertion
737 // into it. Otherwise, be lazy and don't build that structure until
738 // someone asks for it.
John McCallab88d972009-08-31 22:39:49 +0000739 if (LookupPtr || !Recoverable)
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000740 makeDeclVisibleInContextImpl(D);
Douglas Gregor074149e2009-01-05 19:45:36 +0000741
Douglas Gregor074149e2009-01-05 19:45:36 +0000742 // If we are a transparent context, insert into our parent context,
743 // too. This operation is recursive.
744 if (isTransparentContext())
John McCallab88d972009-08-31 22:39:49 +0000745 getParent()->makeDeclVisibleInContext(D, Recoverable);
Douglas Gregor44b43212008-12-11 16:49:14 +0000746}
747
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000748void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) {
Douglas Gregor074149e2009-01-05 19:45:36 +0000749 // Skip unnamed declarations.
750 if (!D->getDeclName())
751 return;
752
Douglas Gregorcc636682009-02-17 23:15:12 +0000753 // FIXME: This feels like a hack. Should DeclarationName support
754 // template-ids, or is there a better way to keep specializations
755 // from being visible?
756 if (isa<ClassTemplateSpecializationDecl>(D))
757 return;
758
Douglas Gregorc36c5402009-04-09 17:29:08 +0000759 if (!LookupPtr)
760 LookupPtr = new StoredDeclsMap;
Douglas Gregor44b43212008-12-11 16:49:14 +0000761
762 // Insert this declaration into the map.
Douglas Gregorc36c5402009-04-09 17:29:08 +0000763 StoredDeclsMap &Map = *static_cast<StoredDeclsMap*>(LookupPtr);
Chris Lattner67762a32009-02-20 01:44:05 +0000764 StoredDeclsList &DeclNameEntries = Map[D->getDeclName()];
765 if (DeclNameEntries.isNull()) {
766 DeclNameEntries.setOnlyValue(D);
Chris Lattnerbd6c8002009-02-19 07:00:44 +0000767 return;
Douglas Gregor44b43212008-12-11 16:49:14 +0000768 }
Chris Lattner91942502009-02-20 00:55:03 +0000769
Chris Lattnerbdc3d002009-02-20 01:10:07 +0000770 // If it is possible that this is a redeclaration, check to see if there is
771 // already a decl for which declarationReplaces returns true. If there is
772 // one, just replace it and return.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000773 if (DeclNameEntries.HandleRedeclaration(getParentASTContext(), D))
Chris Lattner67762a32009-02-20 01:44:05 +0000774 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000775
Chris Lattnerbd6c8002009-02-19 07:00:44 +0000776 // Put this declaration into the appropriate slot.
Chris Lattner67762a32009-02-20 01:44:05 +0000777 DeclNameEntries.AddSubsequentDecl(D);
Douglas Gregor44b43212008-12-11 16:49:14 +0000778}
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000779
780/// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
781/// this context.
Mike Stump1eb44332009-09-09 15:08:12 +0000782DeclContext::udir_iterator_range
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000783DeclContext::getUsingDirectives() const {
784 lookup_const_result Result = lookup(UsingDirectiveDecl::getName());
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000785 return udir_iterator_range(reinterpret_cast<udir_iterator>(Result.first),
786 reinterpret_cast<udir_iterator>(Result.second));
787}
Douglas Gregor2cf26342009-04-09 22:27:44 +0000788
789void StoredDeclsList::materializeDecls(ASTContext &Context) {
790 if (isNull())
791 return;
792
793 switch ((DataKind)(Data & 0x03)) {
794 case DK_Decl:
795 case DK_Decl_Vector:
796 break;
797
798 case DK_DeclID: {
799 // Resolve this declaration ID to an actual declaration by
800 // querying the external AST source.
801 unsigned DeclID = Data >> 2;
802
803 ExternalASTSource *Source = Context.getExternalSource();
804 assert(Source && "No external AST source available!");
805
806 Data = reinterpret_cast<uintptr_t>(Source->GetDecl(DeclID));
807 break;
808 }
809
810 case DK_ID_Vector: {
811 // We have a vector of declaration IDs. Resolve all of them to
812 // actual declarations.
813 VectorTy &Vector = *getAsVector();
814 ExternalASTSource *Source = Context.getExternalSource();
815 assert(Source && "No external AST source available!");
816
817 for (unsigned I = 0, N = Vector.size(); I != N; ++I)
818 Vector[I] = reinterpret_cast<uintptr_t>(Source->GetDecl(Vector[I]));
819
820 Data = (Data & ~0x03) | DK_Decl_Vector;
821 break;
822 }
823 }
824}