blob: c081b0d4a936e1ccbcf3fb7e098ec29dd7fa6882 [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"
John McCall92b7f702010-03-11 07:50:04 +000018#include "clang/AST/DeclFriend.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000019#include "clang/AST/DeclObjC.h"
20#include "clang/AST/DeclTemplate.h"
John McCall0c01d182010-03-24 05:22:00 +000021#include "clang/AST/DependentDiagnostic.h"
Douglas Gregor2cf26342009-04-09 22:27:44 +000022#include "clang/AST/ExternalASTSource.h"
Eli Friedman56d29372008-06-07 16:52:53 +000023#include "clang/AST/ASTContext.h"
Douglas Gregor44b43212008-12-11 16:49:14 +000024#include "clang/AST/Type.h"
Sebastian Redld3a413d2009-04-26 20:35:05 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
Argyrios Kyrtzidis100050b2010-10-28 07:38:51 +000027#include "clang/AST/ASTMutationListener.h"
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000028#include "clang/Basic/TargetInfo.h"
Eli Friedman56d29372008-06-07 16:52:53 +000029#include "llvm/ADT/DenseMap.h"
Chris Lattner49f28ca2009-03-05 08:00:35 +000030#include "llvm/Support/raw_ostream.h"
Douglas Gregor6ed40e32008-12-23 21:05:05 +000031#include <algorithm>
Chris Lattner3daed522009-03-02 22:20:04 +000032#include <cstdio>
Douglas Gregor3fc749d2008-12-23 00:26:44 +000033#include <vector>
Eli Friedman56d29372008-06-07 16:52:53 +000034using namespace clang;
35
36//===----------------------------------------------------------------------===//
37// Statistics
38//===----------------------------------------------------------------------===//
39
Sean Hunt9a555912010-05-30 07:21:58 +000040#define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
41#define ABSTRACT_DECL(DECL)
42#include "clang/AST/DeclNodes.inc"
Eli Friedman56d29372008-06-07 16:52:53 +000043
44static bool StatSwitch = false;
45
Eli Friedman56d29372008-06-07 16:52:53 +000046const char *Decl::getDeclKindName() const {
47 switch (DeclKind) {
Sean Hunt9a555912010-05-30 07:21:58 +000048 default: assert(0 && "Declaration not in DeclNodes.inc!");
49#define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
50#define ABSTRACT_DECL(DECL)
51#include "clang/AST/DeclNodes.inc"
Eli Friedman56d29372008-06-07 16:52:53 +000052 }
53}
54
Douglas Gregor42738572010-03-05 00:26:45 +000055void Decl::setInvalidDecl(bool Invalid) {
56 InvalidDecl = Invalid;
57 if (Invalid) {
58 // Defensive maneuver for ill-formed code: we're likely not to make it to
59 // a point where we set the access specifier, so default it to "public"
60 // to avoid triggering asserts elsewhere in the front end.
61 setAccess(AS_public);
62 }
63}
64
Steve Naroff0a473932009-01-20 19:53:53 +000065const char *DeclContext::getDeclKindName() const {
66 switch (DeclKind) {
Sean Hunt9a555912010-05-30 07:21:58 +000067 default: assert(0 && "Declaration context not in DeclNodes.inc!");
68#define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
69#define ABSTRACT_DECL(DECL)
70#include "clang/AST/DeclNodes.inc"
Steve Naroff0a473932009-01-20 19:53:53 +000071 }
72}
73
Eli Friedman56d29372008-06-07 16:52:53 +000074bool Decl::CollectingStats(bool Enable) {
Kovarththanan Rajaratnam2024f4d2009-11-29 14:54:35 +000075 if (Enable) StatSwitch = true;
Eli Friedman56d29372008-06-07 16:52:53 +000076 return StatSwitch;
77}
78
79void Decl::PrintStats() {
80 fprintf(stderr, "*** Decl Stats:\n");
Mike Stump1eb44332009-09-09 15:08:12 +000081
Douglas Gregor64650af2009-02-02 23:39:07 +000082 int totalDecls = 0;
Sean Hunt9a555912010-05-30 07:21:58 +000083#define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
84#define ABSTRACT_DECL(DECL)
85#include "clang/AST/DeclNodes.inc"
Douglas Gregor64650af2009-02-02 23:39:07 +000086 fprintf(stderr, " %d decls total.\n", totalDecls);
Mike Stump1eb44332009-09-09 15:08:12 +000087
Douglas Gregor64650af2009-02-02 23:39:07 +000088 int totalBytes = 0;
Sean Hunt9a555912010-05-30 07:21:58 +000089#define DECL(DERIVED, BASE) \
90 if (n##DERIVED##s > 0) { \
91 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
92 fprintf(stderr, " %d " #DERIVED " decls, %d each (%d bytes)\n", \
93 n##DERIVED##s, (int)sizeof(DERIVED##Decl), \
94 (int)(n##DERIVED##s * sizeof(DERIVED##Decl))); \
Douglas Gregor64650af2009-02-02 23:39:07 +000095 }
Sean Hunt9a555912010-05-30 07:21:58 +000096#define ABSTRACT_DECL(DECL)
97#include "clang/AST/DeclNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +000098
Douglas Gregor64650af2009-02-02 23:39:07 +000099 fprintf(stderr, "Total bytes = %d\n", totalBytes);
Eli Friedman56d29372008-06-07 16:52:53 +0000100}
101
Sean Hunt9a555912010-05-30 07:21:58 +0000102void Decl::add(Kind k) {
Eli Friedman56d29372008-06-07 16:52:53 +0000103 switch (k) {
Sean Hunt9a555912010-05-30 07:21:58 +0000104 default: assert(0 && "Declaration not in DeclNodes.inc!");
105#define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
106#define ABSTRACT_DECL(DECL)
107#include "clang/AST/DeclNodes.inc"
Eli Friedman56d29372008-06-07 16:52:53 +0000108 }
109}
110
Anders Carlsson67e33202009-06-13 00:08:58 +0000111bool Decl::isTemplateParameterPack() const {
112 if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(this))
113 return TTP->isParameterPack();
Douglas Gregor10738d32010-12-23 23:51:58 +0000114 if (const NonTypeTemplateParmDecl *NTTP
Douglas Gregor61c4d282011-01-05 15:48:55 +0000115 = dyn_cast<NonTypeTemplateParmDecl>(this))
Douglas Gregor10738d32010-12-23 23:51:58 +0000116 return NTTP->isParameterPack();
Douglas Gregor61c4d282011-01-05 15:48:55 +0000117 if (const TemplateTemplateParmDecl *TTP
118 = dyn_cast<TemplateTemplateParmDecl>(this))
119 return TTP->isParameterPack();
Anders Carlsson67e33202009-06-13 00:08:58 +0000120 return false;
121}
122
Douglas Gregor1fe85ea2011-01-05 21:11:38 +0000123bool Decl::isParameterPack() const {
124 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(this))
125 return Parm->isParameterPack();
126
127 return isTemplateParameterPack();
128}
129
Douglas Gregore53060f2009-06-25 22:08:12 +0000130bool Decl::isFunctionOrFunctionTemplate() const {
John McCall9488ea12009-11-17 05:59:44 +0000131 if (const UsingShadowDecl *UD = dyn_cast<UsingShadowDecl>(this))
Anders Carlsson58badb72009-06-26 05:26:50 +0000132 return UD->getTargetDecl()->isFunctionOrFunctionTemplate();
Mike Stump1eb44332009-09-09 15:08:12 +0000133
Douglas Gregore53060f2009-06-25 22:08:12 +0000134 return isa<FunctionDecl>(this) || isa<FunctionTemplateDecl>(this);
135}
136
Douglas Gregor79c22782010-01-16 20:21:20 +0000137bool Decl::isDefinedOutsideFunctionOrMethod() const {
138 for (const DeclContext *DC = getDeclContext();
139 DC && !DC->isTranslationUnit();
140 DC = DC->getParent())
141 if (DC->isFunctionOrMethod())
142 return false;
143
144 return true;
145}
146
Douglas Gregor4c3e0ee2011-02-17 08:47:29 +0000147
Eli Friedman56d29372008-06-07 16:52:53 +0000148//===----------------------------------------------------------------------===//
Chris Lattner49f28ca2009-03-05 08:00:35 +0000149// PrettyStackTraceDecl Implementation
150//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +0000151
Chris Lattner49f28ca2009-03-05 08:00:35 +0000152void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const {
153 SourceLocation TheLoc = Loc;
154 if (TheLoc.isInvalid() && TheDecl)
155 TheLoc = TheDecl->getLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Chris Lattner49f28ca2009-03-05 08:00:35 +0000157 if (TheLoc.isValid()) {
158 TheLoc.print(OS, SM);
159 OS << ": ";
160 }
161
162 OS << Message;
163
Daniel Dunbarc5236562009-11-21 09:05:59 +0000164 if (const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl))
Chris Lattner49f28ca2009-03-05 08:00:35 +0000165 OS << " '" << DN->getQualifiedNameAsString() << '\'';
166 OS << '\n';
167}
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Chris Lattner49f28ca2009-03-05 08:00:35 +0000169//===----------------------------------------------------------------------===//
Eli Friedman56d29372008-06-07 16:52:53 +0000170// Decl Implementation
171//===----------------------------------------------------------------------===//
172
Douglas Gregorda2142f2011-02-19 18:51:44 +0000173// Out-of-line virtual method providing a home for Decl.
174Decl::~Decl() { }
Douglas Gregorf4a03cc2011-02-17 07:02:32 +0000175
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000176void Decl::setDeclContext(DeclContext *DC) {
Chris Lattneree219fd2009-03-29 06:06:59 +0000177 DeclCtx = DC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000178}
179
180void Decl::setLexicalDeclContext(DeclContext *DC) {
181 if (DC == getLexicalDeclContext())
182 return;
183
184 if (isInSemaDC()) {
Ted Kremenek94a39002009-12-01 00:07:10 +0000185 MultipleDC *MDC = new (getASTContext()) MultipleDC();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000186 MDC->SemanticDC = getDeclContext();
187 MDC->LexicalDC = DC;
Chris Lattneree219fd2009-03-29 06:06:59 +0000188 DeclCtx = MDC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000189 } else {
190 getMultipleDC()->LexicalDC = DC;
191 }
192}
193
John McCall9aeed322009-10-01 00:25:31 +0000194bool Decl::isInAnonymousNamespace() const {
195 const DeclContext *DC = getDeclContext();
196 do {
197 if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC))
198 if (ND->isAnonymousNamespace())
199 return true;
200 } while ((DC = DC->getParent()));
201
202 return false;
203}
204
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000205TranslationUnitDecl *Decl::getTranslationUnitDecl() {
Argyrios Kyrtzidis9b346692009-06-30 02:34:53 +0000206 if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this))
207 return TUD;
208
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000209 DeclContext *DC = getDeclContext();
210 assert(DC && "This decl is not contained in a translation unit!");
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000212 while (!DC->isTranslationUnit()) {
213 DC = DC->getParent();
214 assert(DC && "This decl is not contained in a translation unit!");
215 }
Mike Stump1eb44332009-09-09 15:08:12 +0000216
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000217 return cast<TranslationUnitDecl>(DC);
218}
219
220ASTContext &Decl::getASTContext() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000221 return getTranslationUnitDecl()->getASTContext();
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000222}
223
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000224ASTMutationListener *Decl::getASTMutationListener() const {
225 return getASTContext().getASTMutationListener();
226}
227
Douglas Gregorc070cc62010-06-17 23:14:26 +0000228bool Decl::isUsed(bool CheckUsedAttr) const {
Tanya Lattner12ead492010-02-17 02:17:21 +0000229 if (Used)
230 return true;
231
232 // Check for used attribute.
Douglas Gregorc070cc62010-06-17 23:14:26 +0000233 if (CheckUsedAttr && hasAttr<UsedAttr>())
Tanya Lattner12ead492010-02-17 02:17:21 +0000234 return true;
235
236 // Check redeclarations for used attribute.
237 for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
Douglas Gregorc070cc62010-06-17 23:14:26 +0000238 if ((CheckUsedAttr && I->hasAttr<UsedAttr>()) || I->Used)
Tanya Lattner12ead492010-02-17 02:17:21 +0000239 return true;
240 }
241
242 return false;
243}
244
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000245/// \brief Determine the availability of the given declaration based on
246/// the target platform.
247///
248/// When it returns an availability result other than \c AR_Available,
249/// if the \p Message parameter is non-NULL, it will be set to a
250/// string describing why the entity is unavailable.
251///
252/// FIXME: Make these strings localizable, since they end up in
253/// diagnostics.
254static AvailabilityResult CheckAvailability(ASTContext &Context,
255 const AvailabilityAttr *A,
256 std::string *Message) {
257 llvm::StringRef TargetPlatform = Context.Target.getPlatformName();
258 llvm::StringRef PrettyPlatformName
259 = AvailabilityAttr::getPrettyPlatformName(TargetPlatform);
260 if (PrettyPlatformName.empty())
261 PrettyPlatformName = TargetPlatform;
262
263 VersionTuple TargetMinVersion = Context.Target.getPlatformMinVersion();
264 if (TargetMinVersion.empty())
265 return AR_Available;
266
267 // Match the platform name.
268 if (A->getPlatform()->getName() != TargetPlatform)
269 return AR_Available;
270
Douglas Gregorb53e4172011-03-26 03:35:55 +0000271 // Make sure that this declaration has not been marked 'unavailable'.
272 if (A->getUnavailable()) {
273 if (Message) {
274 Message->clear();
275 llvm::raw_string_ostream Out(*Message);
276 Out << "not available on " << PrettyPlatformName;
277 }
278
279 return AR_Unavailable;
280 }
281
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000282 // Make sure that this declaration has already been introduced.
283 if (!A->getIntroduced().empty() &&
284 TargetMinVersion < A->getIntroduced()) {
285 if (Message) {
286 Message->clear();
287 llvm::raw_string_ostream Out(*Message);
288 Out << "introduced in " << PrettyPlatformName << ' '
289 << A->getIntroduced();
290 }
291
292 return AR_NotYetIntroduced;
293 }
294
295 // Make sure that this declaration hasn't been obsoleted.
296 if (!A->getObsoleted().empty() && TargetMinVersion >= A->getObsoleted()) {
297 if (Message) {
298 Message->clear();
299 llvm::raw_string_ostream Out(*Message);
300 Out << "obsoleted in " << PrettyPlatformName << ' '
301 << A->getObsoleted();
302 }
303
304 return AR_Unavailable;
305 }
306
307 // Make sure that this declaration hasn't been deprecated.
308 if (!A->getDeprecated().empty() && TargetMinVersion >= A->getDeprecated()) {
309 if (Message) {
310 Message->clear();
311 llvm::raw_string_ostream Out(*Message);
312 Out << "first deprecated in " << PrettyPlatformName << ' '
313 << A->getDeprecated();
314 }
315
316 return AR_Deprecated;
317 }
318
319 return AR_Available;
320}
321
322AvailabilityResult Decl::getAvailability(std::string *Message) const {
323 AvailabilityResult Result = AR_Available;
324 std::string ResultMessage;
325
326 for (attr_iterator A = attr_begin(), AEnd = attr_end(); A != AEnd; ++A) {
327 if (DeprecatedAttr *Deprecated = dyn_cast<DeprecatedAttr>(*A)) {
328 if (Result >= AR_Deprecated)
329 continue;
330
331 if (Message)
332 ResultMessage = Deprecated->getMessage();
333
334 Result = AR_Deprecated;
335 continue;
336 }
337
338 if (UnavailableAttr *Unavailable = dyn_cast<UnavailableAttr>(*A)) {
339 if (Message)
340 *Message = Unavailable->getMessage();
341 return AR_Unavailable;
342 }
343
344 if (AvailabilityAttr *Availability = dyn_cast<AvailabilityAttr>(*A)) {
345 AvailabilityResult AR = CheckAvailability(getASTContext(), Availability,
346 Message);
347
348 if (AR == AR_Unavailable)
349 return AR_Unavailable;
350
351 if (AR > Result) {
352 Result = AR;
353 if (Message)
354 ResultMessage.swap(*Message);
355 }
356 continue;
357 }
358 }
359
360 if (Message)
361 Message->swap(ResultMessage);
362 return Result;
363}
364
365bool Decl::canBeWeakImported(bool &IsDefinition) const {
366 IsDefinition = false;
367 if (const VarDecl *Var = dyn_cast<VarDecl>(this)) {
368 if (!Var->hasExternalStorage() || Var->getInit()) {
369 IsDefinition = true;
370 return false;
371 }
372 } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) {
373 if (FD->hasBody()) {
374 IsDefinition = true;
375 return false;
376 }
377 } else if (isa<ObjCPropertyDecl>(this) || isa<ObjCMethodDecl>(this))
378 return false;
379 else if (!(getASTContext().getLangOptions().ObjCNonFragileABI &&
380 isa<ObjCInterfaceDecl>(this)))
381 return false;
382
383 return true;
384}
385
386bool Decl::isWeakImported() const {
387 bool IsDefinition;
388 if (!canBeWeakImported(IsDefinition))
389 return false;
390
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000391 for (attr_iterator A = attr_begin(), AEnd = attr_end(); A != AEnd; ++A) {
392 if (isa<WeakImportAttr>(*A))
393 return true;
394
395 if (AvailabilityAttr *Availability = dyn_cast<AvailabilityAttr>(*A)) {
396 if (CheckAvailability(getASTContext(), Availability, 0)
397 == AR_NotYetIntroduced)
398 return true;
399 }
400 }
401
402 return false;
403}
Tanya Lattner12ead492010-02-17 02:17:21 +0000404
Chris Lattner769dbdf2009-03-27 20:18:19 +0000405unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
406 switch (DeclKind) {
John McCall9488ea12009-11-17 05:59:44 +0000407 case Function:
408 case CXXMethod:
409 case CXXConstructor:
410 case CXXDestructor:
411 case CXXConversion:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000412 case EnumConstant:
413 case Var:
414 case ImplicitParam:
415 case ParmVar:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000416 case NonTypeTemplateParm:
417 case ObjCMethod:
Daniel Dunbar00b40d32010-04-23 13:07:39 +0000418 case ObjCProperty:
Daniel Dunbar00b40d32010-04-23 13:07:39 +0000419 return IDNS_Ordinary;
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000420 case Label:
421 return IDNS_Label;
Francois Pichet87c2e122010-11-21 06:08:52 +0000422 case IndirectField:
423 return IDNS_Ordinary | IDNS_Member;
424
John McCall0d6b1642010-04-23 18:46:30 +0000425 case ObjCCompatibleAlias:
426 case ObjCInterface:
427 return IDNS_Ordinary | IDNS_Type;
428
429 case Typedef:
430 case UnresolvedUsingTypename:
431 case TemplateTypeParm:
432 return IDNS_Ordinary | IDNS_Type;
433
John McCall9488ea12009-11-17 05:59:44 +0000434 case UsingShadow:
435 return 0; // we'll actually overwrite this later
436
John McCall7ba107a2009-11-18 02:36:19 +0000437 case UnresolvedUsingValue:
John McCall7ba107a2009-11-18 02:36:19 +0000438 return IDNS_Ordinary | IDNS_Using;
John McCall9488ea12009-11-17 05:59:44 +0000439
440 case Using:
441 return IDNS_Using;
442
Chris Lattner769dbdf2009-03-27 20:18:19 +0000443 case ObjCProtocol:
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000444 return IDNS_ObjCProtocol;
Mike Stump1eb44332009-09-09 15:08:12 +0000445
Chris Lattner769dbdf2009-03-27 20:18:19 +0000446 case Field:
447 case ObjCAtDefsField:
448 case ObjCIvar:
449 return IDNS_Member;
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Chris Lattner769dbdf2009-03-27 20:18:19 +0000451 case Record:
452 case CXXRecord:
453 case Enum:
John McCall0d6b1642010-04-23 18:46:30 +0000454 return IDNS_Tag | IDNS_Type;
Mike Stump1eb44332009-09-09 15:08:12 +0000455
Chris Lattner769dbdf2009-03-27 20:18:19 +0000456 case Namespace:
John McCall0d6b1642010-04-23 18:46:30 +0000457 case NamespaceAlias:
458 return IDNS_Namespace;
459
Chris Lattner769dbdf2009-03-27 20:18:19 +0000460 case FunctionTemplate:
John McCall0d6b1642010-04-23 18:46:30 +0000461 return IDNS_Ordinary;
462
Chris Lattner769dbdf2009-03-27 20:18:19 +0000463 case ClassTemplate:
464 case TemplateTemplateParm:
John McCall0d6b1642010-04-23 18:46:30 +0000465 return IDNS_Ordinary | IDNS_Tag | IDNS_Type;
Mike Stump1eb44332009-09-09 15:08:12 +0000466
Chris Lattner769dbdf2009-03-27 20:18:19 +0000467 // Never have names.
John McCall02cace72009-08-28 07:59:38 +0000468 case Friend:
John McCalldd4a3b02009-09-16 22:47:08 +0000469 case FriendTemplate:
Abramo Bagnara6206d532010-06-05 05:09:32 +0000470 case AccessSpec:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000471 case LinkageSpec:
472 case FileScopeAsm:
473 case StaticAssert:
474 case ObjCClass:
Chris Lattner769dbdf2009-03-27 20:18:19 +0000475 case ObjCPropertyImpl:
476 case ObjCForwardProtocol:
477 case Block:
478 case TranslationUnit:
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000479
Chris Lattner769dbdf2009-03-27 20:18:19 +0000480 case UsingDirective:
481 case ClassTemplateSpecialization:
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000482 case ClassTemplatePartialSpecialization:
Douglas Gregorbd4187b2010-04-22 23:19:50 +0000483 case ObjCImplementation:
484 case ObjCCategory:
485 case ObjCCategoryImpl:
486 // Never looked up by name.
Chris Lattner769dbdf2009-03-27 20:18:19 +0000487 return 0;
488 }
John McCall9488ea12009-11-17 05:59:44 +0000489
490 return 0;
Eli Friedman56d29372008-06-07 16:52:53 +0000491}
492
Sean Huntcf807c42010-08-18 23:23:40 +0000493void Decl::setAttrs(const AttrVec &attrs) {
Argyrios Kyrtzidis1715bf52010-06-11 23:09:25 +0000494 assert(!HasAttrs && "Decl already contains attrs.");
495
Sean Huntcf807c42010-08-18 23:23:40 +0000496 AttrVec &AttrBlank = getASTContext().getDeclAttrs(this);
497 assert(AttrBlank.empty() && "HasAttrs was wrong?");
Argyrios Kyrtzidis1715bf52010-06-11 23:09:25 +0000498
499 AttrBlank = attrs;
500 HasAttrs = true;
501}
502
Sean Huntcf807c42010-08-18 23:23:40 +0000503void Decl::dropAttrs() {
Eli Friedman56d29372008-06-07 16:52:53 +0000504 if (!HasAttrs) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000505
Eli Friedman56d29372008-06-07 16:52:53 +0000506 HasAttrs = false;
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000507 getASTContext().eraseDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000508}
509
Sean Huntcf807c42010-08-18 23:23:40 +0000510const AttrVec &Decl::getAttrs() const {
511 assert(HasAttrs && "No attrs to get!");
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000512 return getASTContext().getDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000513}
514
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000515void Decl::swapAttrs(Decl *RHS) {
Eli Friedman56d29372008-06-07 16:52:53 +0000516 bool HasLHSAttr = this->HasAttrs;
517 bool HasRHSAttr = RHS->HasAttrs;
Mike Stump1eb44332009-09-09 15:08:12 +0000518
Eli Friedman56d29372008-06-07 16:52:53 +0000519 // Usually, neither decl has attrs, nothing to do.
520 if (!HasLHSAttr && !HasRHSAttr) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000521
Eli Friedman56d29372008-06-07 16:52:53 +0000522 // If 'this' has no attrs, swap the other way.
523 if (!HasLHSAttr)
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000524 return RHS->swapAttrs(this);
Mike Stump1eb44332009-09-09 15:08:12 +0000525
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000526 ASTContext &Context = getASTContext();
Mike Stump1eb44332009-09-09 15:08:12 +0000527
Eli Friedman56d29372008-06-07 16:52:53 +0000528 // Handle the case when both decls have attrs.
529 if (HasRHSAttr) {
Douglas Gregor68584ed2009-06-18 16:11:24 +0000530 std::swap(Context.getDeclAttrs(this), Context.getDeclAttrs(RHS));
Eli Friedman56d29372008-06-07 16:52:53 +0000531 return;
532 }
Mike Stump1eb44332009-09-09 15:08:12 +0000533
Eli Friedman56d29372008-06-07 16:52:53 +0000534 // Otherwise, LHS has an attr and RHS doesn't.
Douglas Gregor68584ed2009-06-18 16:11:24 +0000535 Context.getDeclAttrs(RHS) = Context.getDeclAttrs(this);
536 Context.eraseDeclAttrs(this);
Eli Friedman56d29372008-06-07 16:52:53 +0000537 this->HasAttrs = false;
538 RHS->HasAttrs = true;
539}
540
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000541Decl *Decl::castFromDeclContext (const DeclContext *D) {
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000542 Decl::Kind DK = D->getDeclKind();
543 switch(DK) {
Sean Hunt9a555912010-05-30 07:21:58 +0000544#define DECL(NAME, BASE)
545#define DECL_CONTEXT(NAME) \
546 case Decl::NAME: \
547 return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D));
548#define DECL_CONTEXT_BASE(NAME)
549#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000550 default:
Sean Hunt9a555912010-05-30 07:21:58 +0000551#define DECL(NAME, BASE)
552#define DECL_CONTEXT_BASE(NAME) \
553 if (DK >= first##NAME && DK <= last##NAME) \
554 return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D));
555#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000556 assert(false && "a decl that inherits DeclContext isn't handled");
557 return 0;
558 }
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000559}
560
561DeclContext *Decl::castToDeclContext(const Decl *D) {
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000562 Decl::Kind DK = D->getKind();
563 switch(DK) {
Sean Hunt9a555912010-05-30 07:21:58 +0000564#define DECL(NAME, BASE)
565#define DECL_CONTEXT(NAME) \
566 case Decl::NAME: \
567 return static_cast<NAME##Decl*>(const_cast<Decl*>(D));
568#define DECL_CONTEXT_BASE(NAME)
569#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000570 default:
Sean Hunt9a555912010-05-30 07:21:58 +0000571#define DECL(NAME, BASE)
572#define DECL_CONTEXT_BASE(NAME) \
573 if (DK >= first##NAME && DK <= last##NAME) \
574 return static_cast<NAME##Decl*>(const_cast<Decl*>(D));
575#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000576 assert(false && "a decl that inherits DeclContext isn't handled");
577 return 0;
578 }
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000579}
580
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000581SourceLocation Decl::getBodyRBrace() const {
Argyrios Kyrtzidis06a54a32010-07-07 11:31:19 +0000582 // Special handling of FunctionDecl to avoid de-serializing the body from PCH.
583 // FunctionDecl stores EndRangeLoc for this purpose.
584 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) {
585 const FunctionDecl *Definition;
586 if (FD->hasBody(Definition))
587 return Definition->getSourceRange().getEnd();
588 return SourceLocation();
589 }
590
Argyrios Kyrtzidis6717ef42010-07-07 11:31:27 +0000591 if (Stmt *Body = getBody())
592 return Body->getSourceRange().getEnd();
593
594 return SourceLocation();
Sebastian Redld3a413d2009-04-26 20:35:05 +0000595}
596
Anders Carlsson1329c272009-03-25 23:38:06 +0000597void Decl::CheckAccessDeclContext() const {
Douglas Gregor3a1c36c2010-12-02 00:22:25 +0000598#ifndef NDEBUG
John McCall46460a62010-01-20 21:53:11 +0000599 // Suppress this check if any of the following hold:
600 // 1. this is the translation unit (and thus has no parent)
601 // 2. this is a template parameter (and thus doesn't belong to its context)
Argyrios Kyrtzidisd580e562010-09-08 21:58:42 +0000602 // 3. this is a non-type template parameter
603 // 4. the context is not a record
604 // 5. it's invalid
605 // 6. it's a C++0x static_assert.
Anders Carlsson35eda442009-08-29 20:47:47 +0000606 if (isa<TranslationUnitDecl>(this) ||
Argyrios Kyrtzidis04aed0e2010-07-02 11:55:44 +0000607 isa<TemplateTypeParmDecl>(this) ||
Argyrios Kyrtzidisd580e562010-09-08 21:58:42 +0000608 isa<NonTypeTemplateParmDecl>(this) ||
Douglas Gregorfdd8ab12010-02-22 17:53:38 +0000609 !isa<CXXRecordDecl>(getDeclContext()) ||
Argyrios Kyrtzidis65b63ec2010-09-08 21:32:35 +0000610 isInvalidDecl() ||
611 isa<StaticAssertDecl>(this) ||
612 // FIXME: a ParmVarDecl can have ClassTemplateSpecialization
613 // as DeclContext (?).
Argyrios Kyrtzidisd580e562010-09-08 21:58:42 +0000614 isa<ParmVarDecl>(this) ||
615 // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have
616 // AS_none as access specifier.
617 isa<CXXRecordDecl>(this))
Anders Carlsson35eda442009-08-29 20:47:47 +0000618 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000619
620 assert(Access != AS_none &&
Anders Carlsson1329c272009-03-25 23:38:06 +0000621 "Access specifier is AS_none inside a record decl");
Douglas Gregor3a1c36c2010-12-02 00:22:25 +0000622#endif
Anders Carlsson1329c272009-03-25 23:38:06 +0000623}
624
John McCallaab9e312011-02-22 22:25:23 +0000625DeclContext *Decl::getNonClosureContext() {
626 DeclContext *DC = getDeclContext();
627
628 // This is basically "while (DC->isClosure()) DC = DC->getParent();"
629 // except that it's significantly more efficient to cast to a known
630 // decl type and call getDeclContext() than to call getParent().
631 do {
632 if (isa<BlockDecl>(DC)) {
633 DC = cast<BlockDecl>(DC)->getDeclContext();
634 continue;
635 }
636 } while (false);
637
638 assert(!DC->isClosure());
639 return DC;
640}
Anders Carlsson1329c272009-03-25 23:38:06 +0000641
Eli Friedman56d29372008-06-07 16:52:53 +0000642//===----------------------------------------------------------------------===//
643// DeclContext Implementation
644//===----------------------------------------------------------------------===//
645
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000646bool DeclContext::classof(const Decl *D) {
647 switch (D->getKind()) {
Sean Hunt9a555912010-05-30 07:21:58 +0000648#define DECL(NAME, BASE)
649#define DECL_CONTEXT(NAME) case Decl::NAME:
650#define DECL_CONTEXT_BASE(NAME)
651#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000652 return true;
653 default:
Sean Hunt9a555912010-05-30 07:21:58 +0000654#define DECL(NAME, BASE)
655#define DECL_CONTEXT_BASE(NAME) \
656 if (D->getKind() >= Decl::first##NAME && \
657 D->getKind() <= Decl::last##NAME) \
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000658 return true;
Sean Hunt9a555912010-05-30 07:21:58 +0000659#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +0000660 return false;
661 }
662}
663
Douglas Gregora2da7802010-07-25 18:38:02 +0000664DeclContext::~DeclContext() { }
Douglas Gregor44b43212008-12-11 16:49:14 +0000665
Douglas Gregore942bbe2009-09-10 16:57:35 +0000666/// \brief Find the parent context of this context that will be
667/// used for unqualified name lookup.
668///
669/// Generally, the parent lookup context is the semantic context. However, for
670/// a friend function the parent lookup context is the lexical context, which
671/// is the class in which the friend is declared.
672DeclContext *DeclContext::getLookupParent() {
673 // FIXME: Find a better way to identify friends
674 if (isa<FunctionDecl>(this))
Sebastian Redl7a126a42010-08-31 00:36:30 +0000675 if (getParent()->getRedeclContext()->isFileContext() &&
676 getLexicalParent()->getRedeclContext()->isRecord())
Douglas Gregore942bbe2009-09-10 16:57:35 +0000677 return getLexicalParent();
678
679 return getParent();
680}
681
Sebastian Redl410c4f22010-08-31 20:53:31 +0000682bool DeclContext::isInlineNamespace() const {
683 return isNamespace() &&
684 cast<NamespaceDecl>(this)->isInline();
685}
686
Douglas Gregorbc221632009-05-28 16:34:51 +0000687bool DeclContext::isDependentContext() const {
688 if (isFileContext())
689 return false;
690
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000691 if (isa<ClassTemplatePartialSpecializationDecl>(this))
692 return true;
693
Douglas Gregorbc221632009-05-28 16:34:51 +0000694 if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this))
695 if (Record->getDescribedClassTemplate())
696 return true;
697
John McCall0c01d182010-03-24 05:22:00 +0000698 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(this)) {
Douglas Gregorbc221632009-05-28 16:34:51 +0000699 if (Function->getDescribedFunctionTemplate())
700 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000701
John McCall0c01d182010-03-24 05:22:00 +0000702 // Friend function declarations are dependent if their *lexical*
703 // context is dependent.
704 if (cast<Decl>(this)->getFriendObjectKind())
705 return getLexicalParent()->isDependentContext();
706 }
707
Douglas Gregorbc221632009-05-28 16:34:51 +0000708 return getParent() && getParent()->isDependentContext();
709}
710
Douglas Gregor074149e2009-01-05 19:45:36 +0000711bool DeclContext::isTransparentContext() const {
712 if (DeclKind == Decl::Enum)
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000713 return !cast<EnumDecl>(this)->isScoped();
Douglas Gregor074149e2009-01-05 19:45:36 +0000714 else if (DeclKind == Decl::LinkageSpec)
715 return true;
Douglas Gregor074149e2009-01-05 19:45:36 +0000716
717 return false;
718}
719
John McCallac65c622010-10-26 04:59:26 +0000720bool DeclContext::isExternCContext() const {
721 const DeclContext *DC = this;
722 while (DC->DeclKind != Decl::TranslationUnit) {
723 if (DC->DeclKind == Decl::LinkageSpec)
724 return cast<LinkageSpecDecl>(DC)->getLanguage()
725 == LinkageSpecDecl::lang_c;
726 DC = DC->getParent();
727 }
728 return false;
729}
730
Sebastian Redl7a126a42010-08-31 00:36:30 +0000731bool DeclContext::Encloses(const DeclContext *DC) const {
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000732 if (getPrimaryContext() != this)
733 return getPrimaryContext()->Encloses(DC);
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000735 for (; DC; DC = DC->getParent())
736 if (DC->getPrimaryContext() == this)
737 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000738 return false;
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000739}
740
Steve Naroff0701bbb2009-01-08 17:28:14 +0000741DeclContext *DeclContext::getPrimaryContext() {
Douglas Gregor44b43212008-12-11 16:49:14 +0000742 switch (DeclKind) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000743 case Decl::TranslationUnit:
Douglas Gregor074149e2009-01-05 19:45:36 +0000744 case Decl::LinkageSpec:
Mike Stump1eb44332009-09-09 15:08:12 +0000745 case Decl::Block:
Douglas Gregor44b43212008-12-11 16:49:14 +0000746 // There is only one DeclContext for these entities.
747 return this;
748
749 case Decl::Namespace:
750 // The original namespace is our primary context.
751 return static_cast<NamespaceDecl*>(this)->getOriginalNamespace();
752
Douglas Gregor44b43212008-12-11 16:49:14 +0000753 case Decl::ObjCMethod:
754 return this;
755
756 case Decl::ObjCInterface:
Steve Naroff0701bbb2009-01-08 17:28:14 +0000757 case Decl::ObjCProtocol:
758 case Decl::ObjCCategory:
Douglas Gregor44b43212008-12-11 16:49:14 +0000759 // FIXME: Can Objective-C interfaces be forward-declared?
760 return this;
761
Steve Naroff0701bbb2009-01-08 17:28:14 +0000762 case Decl::ObjCImplementation:
763 case Decl::ObjCCategoryImpl:
764 return this;
765
Douglas Gregor44b43212008-12-11 16:49:14 +0000766 default:
Sean Hunt9a555912010-05-30 07:21:58 +0000767 if (DeclKind >= Decl::firstTag && DeclKind <= Decl::lastTag) {
Douglas Gregorcc636682009-02-17 23:15:12 +0000768 // If this is a tag type that has a definition or is currently
769 // being defined, that definition is our primary context.
John McCall3cb0ebd2010-03-10 03:28:59 +0000770 TagDecl *Tag = cast<TagDecl>(this);
771 assert(isa<TagType>(Tag->TypeForDecl) ||
772 isa<InjectedClassNameType>(Tag->TypeForDecl));
773
774 if (TagDecl *Def = Tag->getDefinition())
775 return Def;
776
777 if (!isa<InjectedClassNameType>(Tag->TypeForDecl)) {
778 const TagType *TagTy = cast<TagType>(Tag->TypeForDecl);
779 if (TagTy->isBeingDefined())
780 // FIXME: is it necessarily being defined in the decl
781 // that owns the type?
782 return TagTy->getDecl();
783 }
784
785 return Tag;
Douglas Gregorcc636682009-02-17 23:15:12 +0000786 }
787
Sean Hunt9a555912010-05-30 07:21:58 +0000788 assert(DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction &&
Douglas Gregor44b43212008-12-11 16:49:14 +0000789 "Unknown DeclContext kind");
790 return this;
791 }
792}
793
794DeclContext *DeclContext::getNextContext() {
795 switch (DeclKind) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000796 case Decl::Namespace:
797 // Return the next namespace
798 return static_cast<NamespaceDecl*>(this)->getNextNamespace();
799
800 default:
Douglas Gregor44b43212008-12-11 16:49:14 +0000801 return 0;
802 }
803}
804
Argyrios Kyrtzidiseb5e9982010-10-14 20:14:34 +0000805std::pair<Decl *, Decl *>
806DeclContext::BuildDeclChain(const llvm::SmallVectorImpl<Decl*> &Decls) {
807 // Build up a chain of declarations via the Decl::NextDeclInContext field.
808 Decl *FirstNewDecl = 0;
809 Decl *PrevDecl = 0;
810 for (unsigned I = 0, N = Decls.size(); I != N; ++I) {
811 Decl *D = Decls[I];
812 if (PrevDecl)
813 PrevDecl->NextDeclInContext = D;
814 else
815 FirstNewDecl = D;
816
817 PrevDecl = D;
818 }
819
820 return std::make_pair(FirstNewDecl, PrevDecl);
821}
822
Douglas Gregor2cf26342009-04-09 22:27:44 +0000823/// \brief Load the declarations within this lexical storage from an
824/// external source.
Mike Stump1eb44332009-09-09 15:08:12 +0000825void
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000826DeclContext::LoadLexicalDeclsFromExternalStorage() const {
827 ExternalASTSource *Source = getParentASTContext().getExternalSource();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000828 assert(hasExternalLexicalStorage() && Source && "No external storage?");
829
Argyrios Kyrtzidis0dbbc042010-07-30 10:03:23 +0000830 // Notify that we have a DeclContext that is initializing.
831 ExternalASTSource::Deserializing ADeclContext(Source);
832
John McCall76bd1f32010-06-01 09:23:16 +0000833 llvm::SmallVector<Decl*, 64> Decls;
834 if (Source->FindExternalLexicalDecls(this, Decls))
Douglas Gregor2cf26342009-04-09 22:27:44 +0000835 return;
836
837 // There is no longer any lexical storage in this context
838 ExternalLexicalStorage = false;
839
840 if (Decls.empty())
841 return;
842
Argyrios Kyrtzidiseb5e9982010-10-14 20:14:34 +0000843 // We may have already loaded just the fields of this record, in which case
844 // don't add the decls, just replace the FirstDecl/LastDecl chain.
845 if (const RecordDecl *RD = dyn_cast<RecordDecl>(this))
846 if (RD->LoadedFieldsFromExternalStorage) {
847 llvm::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls);
848 return;
849 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000850
851 // Splice the newly-read declarations into the beginning of the list
852 // of declarations.
Argyrios Kyrtzidiseb5e9982010-10-14 20:14:34 +0000853 Decl *ExternalFirst, *ExternalLast;
854 llvm::tie(ExternalFirst, ExternalLast) = BuildDeclChain(Decls);
855 ExternalLast->NextDeclInContext = FirstDecl;
856 FirstDecl = ExternalFirst;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000857 if (!LastDecl)
Argyrios Kyrtzidiseb5e9982010-10-14 20:14:34 +0000858 LastDecl = ExternalLast;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000859}
860
John McCall76bd1f32010-06-01 09:23:16 +0000861DeclContext::lookup_result
862ExternalASTSource::SetNoExternalVisibleDeclsForName(const DeclContext *DC,
863 DeclarationName Name) {
864 ASTContext &Context = DC->getParentASTContext();
865 StoredDeclsMap *Map;
866 if (!(Map = DC->LookupPtr))
867 Map = DC->CreateStoredDeclsMap(Context);
Douglas Gregor2cf26342009-04-09 22:27:44 +0000868
John McCall76bd1f32010-06-01 09:23:16 +0000869 StoredDeclsList &List = (*Map)[Name];
870 assert(List.isNull());
871 (void) List;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000872
John McCall76bd1f32010-06-01 09:23:16 +0000873 return DeclContext::lookup_result();
874}
Douglas Gregor2cf26342009-04-09 22:27:44 +0000875
John McCall76bd1f32010-06-01 09:23:16 +0000876DeclContext::lookup_result
877ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC,
John McCall76bd1f32010-06-01 09:23:16 +0000878 DeclarationName Name,
879 llvm::SmallVectorImpl<NamedDecl*> &Decls) {
880 ASTContext &Context = DC->getParentASTContext();;
881
882 StoredDeclsMap *Map;
883 if (!(Map = DC->LookupPtr))
884 Map = DC->CreateStoredDeclsMap(Context);
885
886 StoredDeclsList &List = (*Map)[Name];
887 for (unsigned I = 0, N = Decls.size(); I != N; ++I) {
888 if (List.isNull())
889 List.setOnlyValue(Decls[I]);
890 else
891 List.AddSubsequentDecl(Decls[I]);
892 }
893
Argyrios Kyrtzidis074dcc82010-08-20 16:04:35 +0000894 return List.getLookupResult();
John McCall76bd1f32010-06-01 09:23:16 +0000895}
896
Argyrios Kyrtzidisa60786b2010-08-20 23:35:55 +0000897void ExternalASTSource::MaterializeVisibleDeclsForName(const DeclContext *DC,
898 DeclarationName Name,
899 llvm::SmallVectorImpl<NamedDecl*> &Decls) {
900 assert(DC->LookupPtr);
901 StoredDeclsMap &Map = *DC->LookupPtr;
902
903 // If there's an entry in the table the visible decls for this name have
904 // already been deserialized.
905 if (Map.find(Name) == Map.end()) {
906 StoredDeclsList &List = Map[Name];
907 for (unsigned I = 0, N = Decls.size(); I != N; ++I) {
908 if (List.isNull())
909 List.setOnlyValue(Decls[I]);
910 else
911 List.AddSubsequentDecl(Decls[I]);
912 }
913 }
914}
915
Sebastian Redl681d7232010-07-27 00:17:23 +0000916DeclContext::decl_iterator DeclContext::noload_decls_begin() const {
917 return decl_iterator(FirstDecl);
918}
919
920DeclContext::decl_iterator DeclContext::noload_decls_end() const {
921 return decl_iterator();
922}
923
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000924DeclContext::decl_iterator DeclContext::decls_begin() const {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000925 if (hasExternalLexicalStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000926 LoadLexicalDeclsFromExternalStorage();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000927
928 // FIXME: Check whether we need to load some declarations from
929 // external storage.
Mike Stump1eb44332009-09-09 15:08:12 +0000930 return decl_iterator(FirstDecl);
Douglas Gregor6ab35242009-04-09 21:40:53 +0000931}
932
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000933DeclContext::decl_iterator DeclContext::decls_end() const {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000934 if (hasExternalLexicalStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000935 LoadLexicalDeclsFromExternalStorage();
Douglas Gregor2cf26342009-04-09 22:27:44 +0000936
Mike Stump1eb44332009-09-09 15:08:12 +0000937 return decl_iterator();
Douglas Gregor6ab35242009-04-09 21:40:53 +0000938}
939
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000940bool DeclContext::decls_empty() const {
Douglas Gregor8038d512009-04-10 17:25:41 +0000941 if (hasExternalLexicalStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000942 LoadLexicalDeclsFromExternalStorage();
Douglas Gregor8038d512009-04-10 17:25:41 +0000943
944 return !FirstDecl;
945}
946
John McCall9f54ad42009-12-10 09:41:52 +0000947void DeclContext::removeDecl(Decl *D) {
948 assert(D->getLexicalDeclContext() == this &&
949 "decl being removed from non-lexical context");
950 assert((D->NextDeclInContext || D == LastDecl) &&
951 "decl is not in decls list");
952
953 // Remove D from the decl chain. This is O(n) but hopefully rare.
954 if (D == FirstDecl) {
955 if (D == LastDecl)
956 FirstDecl = LastDecl = 0;
957 else
958 FirstDecl = D->NextDeclInContext;
959 } else {
960 for (Decl *I = FirstDecl; true; I = I->NextDeclInContext) {
961 assert(I && "decl not found in linked list");
962 if (I->NextDeclInContext == D) {
963 I->NextDeclInContext = D->NextDeclInContext;
964 if (D == LastDecl) LastDecl = I;
965 break;
966 }
967 }
968 }
969
970 // Mark that D is no longer in the decl chain.
971 D->NextDeclInContext = 0;
972
973 // Remove D from the lookup table if necessary.
974 if (isa<NamedDecl>(D)) {
975 NamedDecl *ND = cast<NamedDecl>(D);
976
John McCall0c01d182010-03-24 05:22:00 +0000977 StoredDeclsMap *Map = getPrimaryContext()->LookupPtr;
978 if (!Map) return;
John McCall9f54ad42009-12-10 09:41:52 +0000979
John McCall9f54ad42009-12-10 09:41:52 +0000980 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
981 assert(Pos != Map->end() && "no lookup entry for decl");
982 Pos->second.remove(ND);
983 }
984}
985
John McCall3f9a8a62009-08-11 06:59:38 +0000986void DeclContext::addHiddenDecl(Decl *D) {
Chris Lattner7f0be132009-02-20 00:56:18 +0000987 assert(D->getLexicalDeclContext() == this &&
988 "Decl inserted into wrong lexical context");
Mike Stump1eb44332009-09-09 15:08:12 +0000989 assert(!D->getNextDeclInContext() && D != LastDecl &&
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000990 "Decl already inserted into a DeclContext");
991
992 if (FirstDecl) {
Chris Lattner244a67d2009-03-28 06:04:26 +0000993 LastDecl->NextDeclInContext = D;
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000994 LastDecl = D;
995 } else {
996 FirstDecl = LastDecl = D;
997 }
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000998
999 // Notify a C++ record declaration that we've added a member, so it can
1000 // update it's class-specific state.
1001 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this))
1002 Record->addedMember(D);
John McCall3f9a8a62009-08-11 06:59:38 +00001003}
1004
1005void DeclContext::addDecl(Decl *D) {
1006 addHiddenDecl(D);
Douglas Gregor4afa39d2009-01-20 01:17:11 +00001007
1008 if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001009 ND->getDeclContext()->makeDeclVisibleInContext(ND);
Douglas Gregor44b43212008-12-11 16:49:14 +00001010}
1011
Douglas Gregor074149e2009-01-05 19:45:36 +00001012/// buildLookup - Build the lookup data structure with all of the
1013/// declarations in DCtx (and any other contexts linked to it or
1014/// transparent contexts nested within it).
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001015void DeclContext::buildLookup(DeclContext *DCtx) {
Douglas Gregor074149e2009-01-05 19:45:36 +00001016 for (; DCtx; DCtx = DCtx->getNextContext()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001017 for (decl_iterator D = DCtx->decls_begin(),
1018 DEnd = DCtx->decls_end();
Douglas Gregor4f3b8f82009-01-06 07:17:58 +00001019 D != DEnd; ++D) {
John McCall3f9a8a62009-08-11 06:59:38 +00001020 // Insert this declaration into the lookup structure, but only
1021 // if it's semantically in its decl context. During non-lazy
1022 // lookup building, this is implicitly enforced by addDecl.
Douglas Gregor4afa39d2009-01-20 01:17:11 +00001023 if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
John McCall3f9a8a62009-08-11 06:59:38 +00001024 if (D->getDeclContext() == DCtx)
1025 makeDeclVisibleInContextImpl(ND);
Douglas Gregor074149e2009-01-05 19:45:36 +00001026
Ted Kremenekc32b1d82009-11-17 22:58:30 +00001027 // Insert any forward-declared Objective-C interfaces into the lookup
1028 // data structure.
1029 if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(*D))
1030 for (ObjCClassDecl::iterator I = Class->begin(), IEnd = Class->end();
1031 I != IEnd; ++I)
Ted Kremenek321c22f2009-11-18 00:28:11 +00001032 makeDeclVisibleInContextImpl(I->getInterface());
Ted Kremenekc32b1d82009-11-17 22:58:30 +00001033
Sebastian Redl410c4f22010-08-31 20:53:31 +00001034 // If this declaration is itself a transparent declaration context or
1035 // inline namespace, add its members (recursively).
Douglas Gregor074149e2009-01-05 19:45:36 +00001036 if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D))
Sebastian Redl410c4f22010-08-31 20:53:31 +00001037 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001038 buildLookup(InnerCtx->getPrimaryContext());
Douglas Gregor074149e2009-01-05 19:45:36 +00001039 }
1040 }
1041}
1042
Mike Stump1eb44332009-09-09 15:08:12 +00001043DeclContext::lookup_result
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001044DeclContext::lookup(DeclarationName Name) {
Steve Naroff0701bbb2009-01-08 17:28:14 +00001045 DeclContext *PrimaryContext = getPrimaryContext();
Douglas Gregor44b43212008-12-11 16:49:14 +00001046 if (PrimaryContext != this)
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001047 return PrimaryContext->lookup(Name);
Douglas Gregor44b43212008-12-11 16:49:14 +00001048
John McCall76bd1f32010-06-01 09:23:16 +00001049 if (hasExternalVisibleStorage()) {
1050 // Check to see if we've already cached the lookup results.
1051 if (LookupPtr) {
1052 StoredDeclsMap::iterator I = LookupPtr->find(Name);
1053 if (I != LookupPtr->end())
Argyrios Kyrtzidis074dcc82010-08-20 16:04:35 +00001054 return I->second.getLookupResult();
John McCall76bd1f32010-06-01 09:23:16 +00001055 }
1056
1057 ExternalASTSource *Source = getParentASTContext().getExternalSource();
1058 return Source->FindExternalVisibleDeclsByName(this, Name);
1059 }
Douglas Gregor2cf26342009-04-09 22:27:44 +00001060
Douglas Gregor3fc749d2008-12-23 00:26:44 +00001061 /// If there is no lookup data structure, build one now by walking
Douglas Gregor44b43212008-12-11 16:49:14 +00001062 /// all of the linked DeclContexts (in declaration order!) and
1063 /// inserting their values.
Douglas Gregorc36c5402009-04-09 17:29:08 +00001064 if (!LookupPtr) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001065 buildLookup(this);
Douglas Gregor44b43212008-12-11 16:49:14 +00001066
Douglas Gregorc36c5402009-04-09 17:29:08 +00001067 if (!LookupPtr)
Douglas Gregora5fdd9c2010-05-11 06:18:17 +00001068 return lookup_result(lookup_iterator(0), lookup_iterator(0));
Douglas Gregorc36c5402009-04-09 17:29:08 +00001069 }
Douglas Gregor44b43212008-12-11 16:49:14 +00001070
John McCall0c01d182010-03-24 05:22:00 +00001071 StoredDeclsMap::iterator Pos = LookupPtr->find(Name);
1072 if (Pos == LookupPtr->end())
Douglas Gregora5fdd9c2010-05-11 06:18:17 +00001073 return lookup_result(lookup_iterator(0), lookup_iterator(0));
Argyrios Kyrtzidis074dcc82010-08-20 16:04:35 +00001074 return Pos->second.getLookupResult();
Douglas Gregor44b43212008-12-11 16:49:14 +00001075}
1076
Mike Stump1eb44332009-09-09 15:08:12 +00001077DeclContext::lookup_const_result
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001078DeclContext::lookup(DeclarationName Name) const {
1079 return const_cast<DeclContext*>(this)->lookup(Name);
Douglas Gregor44b43212008-12-11 16:49:14 +00001080}
1081
Sebastian Redl7a126a42010-08-31 00:36:30 +00001082DeclContext *DeclContext::getRedeclContext() {
Chris Lattner0cf2b192009-03-27 19:19:59 +00001083 DeclContext *Ctx = this;
Sebastian Redl410c4f22010-08-31 20:53:31 +00001084 // Skip through transparent contexts.
1085 while (Ctx->isTransparentContext())
Douglas Gregorce356072009-01-06 23:51:29 +00001086 Ctx = Ctx->getParent();
1087 return Ctx;
1088}
1089
Douglas Gregor88b70942009-02-25 22:02:03 +00001090DeclContext *DeclContext::getEnclosingNamespaceContext() {
1091 DeclContext *Ctx = this;
1092 // Skip through non-namespace, non-translation-unit contexts.
Sebastian Redl51a8a372010-08-31 00:36:23 +00001093 while (!Ctx->isFileContext())
Douglas Gregor88b70942009-02-25 22:02:03 +00001094 Ctx = Ctx->getParent();
1095 return Ctx->getPrimaryContext();
1096}
1097
Sebastian Redl7a126a42010-08-31 00:36:30 +00001098bool DeclContext::InEnclosingNamespaceSetOf(const DeclContext *O) const {
1099 // For non-file contexts, this is equivalent to Equals.
1100 if (!isFileContext())
1101 return O->Equals(this);
1102
1103 do {
1104 if (O->Equals(this))
1105 return true;
1106
1107 const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(O);
1108 if (!NS || !NS->isInline())
1109 break;
1110 O = NS->getParent();
1111 } while (O);
1112
1113 return false;
1114}
1115
John McCallab88d972009-08-31 22:39:49 +00001116void DeclContext::makeDeclVisibleInContext(NamedDecl *D, bool Recoverable) {
Douglas Gregorcc636682009-02-17 23:15:12 +00001117 // FIXME: This feels like a hack. Should DeclarationName support
1118 // template-ids, or is there a better way to keep specializations
1119 // from being visible?
Douglas Gregor9a299e02011-03-04 17:52:15 +00001120 if (isa<ClassTemplateSpecializationDecl>(D) || D->isTemplateParameter())
Douglas Gregorcc636682009-02-17 23:15:12 +00001121 return;
Eli Friedman6bc20132009-12-08 05:40:03 +00001122 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1123 if (FD->isFunctionTemplateSpecialization())
1124 return;
Douglas Gregorcc636682009-02-17 23:15:12 +00001125
Steve Naroff0701bbb2009-01-08 17:28:14 +00001126 DeclContext *PrimaryContext = getPrimaryContext();
Douglas Gregor44b43212008-12-11 16:49:14 +00001127 if (PrimaryContext != this) {
John McCallab88d972009-08-31 22:39:49 +00001128 PrimaryContext->makeDeclVisibleInContext(D, Recoverable);
Douglas Gregor44b43212008-12-11 16:49:14 +00001129 return;
1130 }
1131
1132 // If we already have a lookup data structure, perform the insertion
Argyrios Kyrtzidis5586b012010-07-04 21:44:25 +00001133 // into it. If we haven't deserialized externally stored decls, deserialize
1134 // them so we can add the decl. Otherwise, be lazy and don't build that
1135 // structure until someone asks for it.
1136 if (LookupPtr || !Recoverable || hasExternalVisibleStorage())
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001137 makeDeclVisibleInContextImpl(D);
Douglas Gregor074149e2009-01-05 19:45:36 +00001138
Sebastian Redl410c4f22010-08-31 20:53:31 +00001139 // If we are a transparent context or inline namespace, insert into our
1140 // parent context, too. This operation is recursive.
1141 if (isTransparentContext() || isInlineNamespace())
John McCallab88d972009-08-31 22:39:49 +00001142 getParent()->makeDeclVisibleInContext(D, Recoverable);
Argyrios Kyrtzidis100050b2010-10-28 07:38:51 +00001143
1144 Decl *DCAsDecl = cast<Decl>(this);
1145 // Notify that a decl was made visible unless it's a Tag being defined.
1146 if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
1147 if (ASTMutationListener *L = DCAsDecl->getASTMutationListener())
1148 L->AddedVisibleDecl(this, D);
Douglas Gregor44b43212008-12-11 16:49:14 +00001149}
1150
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001151void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) {
Douglas Gregor074149e2009-01-05 19:45:36 +00001152 // Skip unnamed declarations.
1153 if (!D->getDeclName())
1154 return;
1155
Douglas Gregorcc636682009-02-17 23:15:12 +00001156 // FIXME: This feels like a hack. Should DeclarationName support
1157 // template-ids, or is there a better way to keep specializations
1158 // from being visible?
Douglas Gregor9a299e02011-03-04 17:52:15 +00001159 if (isa<ClassTemplateSpecializationDecl>(D) || D->isTemplateParameter())
Douglas Gregorcc636682009-02-17 23:15:12 +00001160 return;
1161
Argyrios Kyrtzidis5586b012010-07-04 21:44:25 +00001162 ASTContext *C = 0;
1163 if (!LookupPtr) {
1164 C = &getParentASTContext();
1165 CreateStoredDeclsMap(*C);
1166 }
1167
Argyrios Kyrtzidis074dcc82010-08-20 16:04:35 +00001168 // If there is an external AST source, load any declarations it knows about
1169 // with this declaration's name.
1170 // If the lookup table contains an entry about this name it means that we
1171 // have already checked the external source.
1172 if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
1173 if (hasExternalVisibleStorage() &&
1174 LookupPtr->find(D->getDeclName()) == LookupPtr->end())
1175 Source->FindExternalVisibleDeclsByName(this, D->getDeclName());
1176
Douglas Gregor44b43212008-12-11 16:49:14 +00001177 // Insert this declaration into the map.
John McCall0c01d182010-03-24 05:22:00 +00001178 StoredDeclsList &DeclNameEntries = (*LookupPtr)[D->getDeclName()];
Chris Lattner67762a32009-02-20 01:44:05 +00001179 if (DeclNameEntries.isNull()) {
1180 DeclNameEntries.setOnlyValue(D);
Chris Lattnerbd6c8002009-02-19 07:00:44 +00001181 return;
Douglas Gregor44b43212008-12-11 16:49:14 +00001182 }
Chris Lattner91942502009-02-20 00:55:03 +00001183
Chris Lattnerbdc3d002009-02-20 01:10:07 +00001184 // If it is possible that this is a redeclaration, check to see if there is
1185 // already a decl for which declarationReplaces returns true. If there is
1186 // one, just replace it and return.
Argyrios Kyrtzidis074dcc82010-08-20 16:04:35 +00001187 if (DeclNameEntries.HandleRedeclaration(D))
Chris Lattner67762a32009-02-20 01:44:05 +00001188 return;
Mike Stump1eb44332009-09-09 15:08:12 +00001189
Chris Lattnerbd6c8002009-02-19 07:00:44 +00001190 // Put this declaration into the appropriate slot.
Chris Lattner67762a32009-02-20 01:44:05 +00001191 DeclNameEntries.AddSubsequentDecl(D);
Douglas Gregor44b43212008-12-11 16:49:14 +00001192}
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001193
Argyrios Kyrtzidisa60786b2010-08-20 23:35:55 +00001194void DeclContext::MaterializeVisibleDeclsFromExternalStorage() {
1195 ExternalASTSource *Source = getParentASTContext().getExternalSource();
1196 assert(hasExternalVisibleStorage() && Source && "No external storage?");
1197
1198 if (!LookupPtr)
1199 CreateStoredDeclsMap(getParentASTContext());
1200 Source->MaterializeVisibleDecls(this);
1201}
1202
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001203/// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
1204/// this context.
Mike Stump1eb44332009-09-09 15:08:12 +00001205DeclContext::udir_iterator_range
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001206DeclContext::getUsingDirectives() const {
1207 lookup_const_result Result = lookup(UsingDirectiveDecl::getName());
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001208 return udir_iterator_range(reinterpret_cast<udir_iterator>(Result.first),
1209 reinterpret_cast<udir_iterator>(Result.second));
1210}
Douglas Gregor2cf26342009-04-09 22:27:44 +00001211
Ted Kremenek3478eb62010-02-11 07:12:28 +00001212//===----------------------------------------------------------------------===//
1213// Creation and Destruction of StoredDeclsMaps. //
1214//===----------------------------------------------------------------------===//
1215
John McCall0c01d182010-03-24 05:22:00 +00001216StoredDeclsMap *DeclContext::CreateStoredDeclsMap(ASTContext &C) const {
1217 assert(!LookupPtr && "context already has a decls map");
1218 assert(getPrimaryContext() == this &&
1219 "creating decls map on non-primary context");
1220
1221 StoredDeclsMap *M;
1222 bool Dependent = isDependentContext();
1223 if (Dependent)
1224 M = new DependentStoredDeclsMap();
1225 else
1226 M = new StoredDeclsMap();
1227 M->Previous = C.LastSDM;
1228 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
1229 LookupPtr = M;
Ted Kremenek3478eb62010-02-11 07:12:28 +00001230 return M;
1231}
1232
1233void ASTContext::ReleaseDeclContextMaps() {
John McCall0c01d182010-03-24 05:22:00 +00001234 // It's okay to delete DependentStoredDeclsMaps via a StoredDeclsMap
1235 // pointer because the subclass doesn't add anything that needs to
1236 // be deleted.
John McCall0c01d182010-03-24 05:22:00 +00001237 StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
1238}
1239
1240void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {
1241 while (Map) {
1242 // Advance the iteration before we invalidate memory.
1243 llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
1244
1245 if (Dependent)
1246 delete static_cast<DependentStoredDeclsMap*>(Map);
1247 else
1248 delete Map;
1249
1250 Map = Next.getPointer();
1251 Dependent = Next.getInt();
1252 }
1253}
1254
John McCall0c01d182010-03-24 05:22:00 +00001255DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C,
1256 DeclContext *Parent,
1257 const PartialDiagnostic &PDiag) {
1258 assert(Parent->isDependentContext()
1259 && "cannot iterate dependent diagnostics of non-dependent context");
1260 Parent = Parent->getPrimaryContext();
1261 if (!Parent->LookupPtr)
1262 Parent->CreateStoredDeclsMap(C);
1263
1264 DependentStoredDeclsMap *Map
1265 = static_cast<DependentStoredDeclsMap*>(Parent->LookupPtr);
1266
Douglas Gregorb8365182010-03-29 23:56:53 +00001267 // Allocate the copy of the PartialDiagnostic via the ASTContext's
Douglas Gregorfe6b2d42010-03-29 23:34:08 +00001268 // BumpPtrAllocator, rather than the ASTContext itself.
Douglas Gregorb8365182010-03-29 23:56:53 +00001269 PartialDiagnostic::Storage *DiagStorage = 0;
1270 if (PDiag.hasStorage())
1271 DiagStorage = new (C) PartialDiagnostic::Storage;
1272
1273 DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
John McCall0c01d182010-03-24 05:22:00 +00001274
1275 // TODO: Maybe we shouldn't reverse the order during insertion.
1276 DD->NextDiagnostic = Map->FirstDiagnostic;
1277 Map->FirstDiagnostic = DD;
1278
1279 return DD;
Ted Kremenek3478eb62010-02-11 07:12:28 +00001280}