Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 1 | //===--- 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 Gregor | 8bd3c2e | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 15 | #include "clang/AST/Decl.h" |
Douglas Gregor | b1fe2c9 | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | 2951e14 | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclCXX.h" |
John McCall | bbbbe4e | 2010-03-11 07:50:04 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclFriend.h" |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 21 | #include "clang/AST/DependentDiagnostic.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExternalASTSource.h" |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 24 | #include "clang/AST/Type.h" |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 25 | #include "clang/AST/Stmt.h" |
| 26 | #include "clang/AST/StmtCXX.h" |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 27 | #include "clang/AST/ASTMutationListener.h" |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 8b9ccca | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 30 | #include <algorithm> |
Chris Lattner | c25d8a7 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 31 | #include <cstdio> |
Douglas Gregor | 55297ac | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 32 | #include <vector> |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 33 | using namespace clang; |
| 34 | |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | // Statistics |
| 37 | //===----------------------------------------------------------------------===// |
| 38 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 39 | #define DECL(DERIVED, BASE) static int n##DERIVED##s = 0; |
| 40 | #define ABSTRACT_DECL(DECL) |
| 41 | #include "clang/AST/DeclNodes.inc" |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 42 | |
| 43 | static bool StatSwitch = false; |
| 44 | |
Douglas Gregor | 00716e8 | 2011-02-17 08:12:32 +0000 | [diff] [blame^] | 45 | namespace { |
| 46 | template<typename Class> |
| 47 | inline SourceRange getSourceRangeImpl(const Decl *D, |
| 48 | SourceRange (Class::*)() const) { |
| 49 | return static_cast<const Class *>(D)->getSourceRange(); |
| 50 | } |
| 51 | |
| 52 | inline SourceRange getSourceRangeImpl(const Decl *D, |
| 53 | SourceRange (Decl::*)() const) { |
| 54 | return D->getLocation(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | SourceRange Decl::getSourceRange() const { |
| 59 | switch (getKind()) { |
| 60 | #define ABSTRACT_DECL(Type) |
| 61 | #define DECL(Type, Base) \ |
| 62 | case Type: return getSourceRangeImpl(this, &Type##Decl::getSourceRange); |
| 63 | #include "clang/AST/DeclNodes.inc" |
| 64 | } |
| 65 | |
| 66 | return getLocation(); |
| 67 | } |
| 68 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 69 | const char *Decl::getDeclKindName() const { |
| 70 | switch (DeclKind) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 71 | default: assert(0 && "Declaration not in DeclNodes.inc!"); |
| 72 | #define DECL(DERIVED, BASE) case DERIVED: return #DERIVED; |
| 73 | #define ABSTRACT_DECL(DECL) |
| 74 | #include "clang/AST/DeclNodes.inc" |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Douglas Gregor | 90d4717 | 2010-03-05 00:26:45 +0000 | [diff] [blame] | 78 | void Decl::setInvalidDecl(bool Invalid) { |
| 79 | InvalidDecl = Invalid; |
| 80 | if (Invalid) { |
| 81 | // Defensive maneuver for ill-formed code: we're likely not to make it to |
| 82 | // a point where we set the access specifier, so default it to "public" |
| 83 | // to avoid triggering asserts elsewhere in the front end. |
| 84 | setAccess(AS_public); |
| 85 | } |
| 86 | } |
| 87 | |
Steve Naroff | 5faaef7 | 2009-01-20 19:53:53 +0000 | [diff] [blame] | 88 | const char *DeclContext::getDeclKindName() const { |
| 89 | switch (DeclKind) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 90 | default: assert(0 && "Declaration context not in DeclNodes.inc!"); |
| 91 | #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED; |
| 92 | #define ABSTRACT_DECL(DECL) |
| 93 | #include "clang/AST/DeclNodes.inc" |
Steve Naroff | 5faaef7 | 2009-01-20 19:53:53 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 97 | bool Decl::CollectingStats(bool Enable) { |
Kovarththanan Rajaratnam | 130f7f9 | 2009-11-29 14:54:35 +0000 | [diff] [blame] | 98 | if (Enable) StatSwitch = true; |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 99 | return StatSwitch; |
| 100 | } |
| 101 | |
| 102 | void Decl::PrintStats() { |
| 103 | fprintf(stderr, "*** Decl Stats:\n"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 104 | |
Douglas Gregor | 8bd3c2e | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 105 | int totalDecls = 0; |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 106 | #define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s; |
| 107 | #define ABSTRACT_DECL(DECL) |
| 108 | #include "clang/AST/DeclNodes.inc" |
Douglas Gregor | 8bd3c2e | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 109 | fprintf(stderr, " %d decls total.\n", totalDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | |
Douglas Gregor | 8bd3c2e | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 111 | int totalBytes = 0; |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 112 | #define DECL(DERIVED, BASE) \ |
| 113 | if (n##DERIVED##s > 0) { \ |
| 114 | totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \ |
| 115 | fprintf(stderr, " %d " #DERIVED " decls, %d each (%d bytes)\n", \ |
| 116 | n##DERIVED##s, (int)sizeof(DERIVED##Decl), \ |
| 117 | (int)(n##DERIVED##s * sizeof(DERIVED##Decl))); \ |
Douglas Gregor | 8bd3c2e | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 118 | } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 119 | #define ABSTRACT_DECL(DECL) |
| 120 | #include "clang/AST/DeclNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 8bd3c2e | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 122 | fprintf(stderr, "Total bytes = %d\n", totalBytes); |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 125 | void Decl::add(Kind k) { |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 126 | switch (k) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 127 | default: assert(0 && "Declaration not in DeclNodes.inc!"); |
| 128 | #define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break; |
| 129 | #define ABSTRACT_DECL(DECL) |
| 130 | #include "clang/AST/DeclNodes.inc" |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Anders Carlsson | aa73b91 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 134 | bool Decl::isTemplateParameterPack() const { |
| 135 | if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(this)) |
| 136 | return TTP->isParameterPack(); |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 137 | if (const NonTypeTemplateParmDecl *NTTP |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 138 | = dyn_cast<NonTypeTemplateParmDecl>(this)) |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 139 | return NTTP->isParameterPack(); |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 140 | if (const TemplateTemplateParmDecl *TTP |
| 141 | = dyn_cast<TemplateTemplateParmDecl>(this)) |
| 142 | return TTP->isParameterPack(); |
Anders Carlsson | aa73b91 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 143 | return false; |
| 144 | } |
| 145 | |
Douglas Gregor | 3c6bd2a | 2011-01-05 21:11:38 +0000 | [diff] [blame] | 146 | bool Decl::isParameterPack() const { |
| 147 | if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(this)) |
| 148 | return Parm->isParameterPack(); |
| 149 | |
| 150 | return isTemplateParameterPack(); |
| 151 | } |
| 152 | |
Douglas Gregor | ad3f2fc | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 153 | bool Decl::isFunctionOrFunctionTemplate() const { |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 154 | if (const UsingShadowDecl *UD = dyn_cast<UsingShadowDecl>(this)) |
Anders Carlsson | f057cb2 | 2009-06-26 05:26:50 +0000 | [diff] [blame] | 155 | return UD->getTargetDecl()->isFunctionOrFunctionTemplate(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | |
Douglas Gregor | ad3f2fc | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 157 | return isa<FunctionDecl>(this) || isa<FunctionTemplateDecl>(this); |
| 158 | } |
| 159 | |
Douglas Gregor | f5974fa | 2010-01-16 20:21:20 +0000 | [diff] [blame] | 160 | bool Decl::isDefinedOutsideFunctionOrMethod() const { |
| 161 | for (const DeclContext *DC = getDeclContext(); |
| 162 | DC && !DC->isTranslationUnit(); |
| 163 | DC = DC->getParent()) |
| 164 | if (DC->isFunctionOrMethod()) |
| 165 | return false; |
| 166 | |
| 167 | return true; |
| 168 | } |
| 169 | |
Douglas Gregor | 7edc20a | 2011-02-17 07:58:36 +0000 | [diff] [blame] | 170 | namespace { |
| 171 | template<typename Class, typename Result> |
| 172 | inline Result *getSpecificCanonicalDecl(Decl *D, Result *(Class::*Get)()) { |
| 173 | return (llvm::cast<Class>(D)->*Get)(); |
| 174 | } |
| 175 | |
| 176 | inline Decl *getSpecificCanonicalDecl(Decl *D, Decl *(Decl::*)()) { |
| 177 | // No specific implementation. |
| 178 | return D; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | Decl *Decl::getCanonicalDecl() { |
| 183 | switch (getKind()) { |
| 184 | #define ABSTRACT_DECL(Type) |
| 185 | #define DECL(Type, Base) \ |
| 186 | case Type: \ |
| 187 | return getSpecificCanonicalDecl(this, &Type##Decl::getCanonicalDecl); |
| 188 | #include "clang/AST/DeclNodes.inc" |
| 189 | } |
Douglas Gregor | 7edc20a | 2011-02-17 07:58:36 +0000 | [diff] [blame] | 190 | |
Douglas Gregor | 00716e8 | 2011-02-17 08:12:32 +0000 | [diff] [blame^] | 191 | return this; |
Douglas Gregor | 7edc20a | 2011-02-17 07:58:36 +0000 | [diff] [blame] | 192 | } |
Douglas Gregor | f5974fa | 2010-01-16 20:21:20 +0000 | [diff] [blame] | 193 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 194 | //===----------------------------------------------------------------------===// |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 195 | // PrettyStackTraceDecl Implementation |
| 196 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 198 | void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const { |
| 199 | SourceLocation TheLoc = Loc; |
| 200 | if (TheLoc.isInvalid() && TheDecl) |
| 201 | TheLoc = TheDecl->getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 203 | if (TheLoc.isValid()) { |
| 204 | TheLoc.print(OS, SM); |
| 205 | OS << ": "; |
| 206 | } |
| 207 | |
| 208 | OS << Message; |
| 209 | |
Daniel Dunbar | 4f1054e | 2009-11-21 09:05:59 +0000 | [diff] [blame] | 210 | if (const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 211 | OS << " '" << DN->getQualifiedNameAsString() << '\''; |
| 212 | OS << '\n'; |
| 213 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 214 | |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 215 | //===----------------------------------------------------------------------===// |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 216 | // Decl Implementation |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 219 | // Out-of-line virtual method providing a home for Decl. |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 220 | Decl::~Decl() { } |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 221 | |
Douglas Gregor | a43942a | 2011-02-17 07:02:32 +0000 | [diff] [blame] | 222 | bool Decl::isOutOfLine() const { |
| 223 | if (const VarDecl *VD = dyn_cast<VarDecl>(this)) |
| 224 | return VD->isOutOfLine(); |
| 225 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 226 | return FD->isOutOfLine(); |
| 227 | |
| 228 | return getLexicalDeclContext() != getDeclContext(); |
| 229 | } |
| 230 | |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 231 | void Decl::setDeclContext(DeclContext *DC) { |
| 232 | if (isOutOfSemaDC()) |
| 233 | delete getMultipleDC(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Chris Lattner | b81eb05 | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 235 | DeclCtx = DC; |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void Decl::setLexicalDeclContext(DeclContext *DC) { |
| 239 | if (DC == getLexicalDeclContext()) |
| 240 | return; |
| 241 | |
| 242 | if (isInSemaDC()) { |
Ted Kremenek | f8c12a3 | 2009-12-01 00:07:10 +0000 | [diff] [blame] | 243 | MultipleDC *MDC = new (getASTContext()) MultipleDC(); |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 244 | MDC->SemanticDC = getDeclContext(); |
| 245 | MDC->LexicalDC = DC; |
Chris Lattner | b81eb05 | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 246 | DeclCtx = MDC; |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 247 | } else { |
| 248 | getMultipleDC()->LexicalDC = DC; |
| 249 | } |
| 250 | } |
| 251 | |
John McCall | 4fa5342 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 252 | bool Decl::isInAnonymousNamespace() const { |
| 253 | const DeclContext *DC = getDeclContext(); |
| 254 | do { |
| 255 | if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC)) |
| 256 | if (ND->isAnonymousNamespace()) |
| 257 | return true; |
| 258 | } while ((DC = DC->getParent())); |
| 259 | |
| 260 | return false; |
| 261 | } |
| 262 | |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 263 | TranslationUnitDecl *Decl::getTranslationUnitDecl() { |
Argyrios Kyrtzidis | 4e1a72b | 2009-06-30 02:34:53 +0000 | [diff] [blame] | 264 | if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this)) |
| 265 | return TUD; |
| 266 | |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 267 | DeclContext *DC = getDeclContext(); |
| 268 | assert(DC && "This decl is not contained in a translation unit!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 269 | |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 270 | while (!DC->isTranslationUnit()) { |
| 271 | DC = DC->getParent(); |
| 272 | assert(DC && "This decl is not contained in a translation unit!"); |
| 273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 274 | |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 275 | return cast<TranslationUnitDecl>(DC); |
| 276 | } |
| 277 | |
| 278 | ASTContext &Decl::getASTContext() const { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 279 | return getTranslationUnitDecl()->getASTContext(); |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 282 | ASTMutationListener *Decl::getASTMutationListener() const { |
| 283 | return getASTContext().getASTMutationListener(); |
| 284 | } |
| 285 | |
Douglas Gregor | ebada077 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 286 | bool Decl::isUsed(bool CheckUsedAttr) const { |
Tanya Lattner | 8aefcbe | 2010-02-17 02:17:21 +0000 | [diff] [blame] | 287 | if (Used) |
| 288 | return true; |
| 289 | |
| 290 | // Check for used attribute. |
Douglas Gregor | ebada077 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 291 | if (CheckUsedAttr && hasAttr<UsedAttr>()) |
Tanya Lattner | 8aefcbe | 2010-02-17 02:17:21 +0000 | [diff] [blame] | 292 | return true; |
| 293 | |
| 294 | // Check redeclarations for used attribute. |
| 295 | for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) { |
Douglas Gregor | ebada077 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 296 | if ((CheckUsedAttr && I->hasAttr<UsedAttr>()) || I->Used) |
Tanya Lattner | 8aefcbe | 2010-02-17 02:17:21 +0000 | [diff] [blame] | 297 | return true; |
| 298 | } |
| 299 | |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 304 | unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { |
| 305 | switch (DeclKind) { |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 306 | case Function: |
| 307 | case CXXMethod: |
| 308 | case CXXConstructor: |
| 309 | case CXXDestructor: |
| 310 | case CXXConversion: |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 311 | case EnumConstant: |
| 312 | case Var: |
| 313 | case ImplicitParam: |
| 314 | case ParmVar: |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 315 | case NonTypeTemplateParm: |
| 316 | case ObjCMethod: |
Daniel Dunbar | 45b2d8a | 2010-04-23 13:07:39 +0000 | [diff] [blame] | 317 | case ObjCProperty: |
Daniel Dunbar | 45b2d8a | 2010-04-23 13:07:39 +0000 | [diff] [blame] | 318 | return IDNS_Ordinary; |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 319 | case Label: |
| 320 | return IDNS_Label; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 321 | case IndirectField: |
| 322 | return IDNS_Ordinary | IDNS_Member; |
| 323 | |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 324 | case ObjCCompatibleAlias: |
| 325 | case ObjCInterface: |
| 326 | return IDNS_Ordinary | IDNS_Type; |
| 327 | |
| 328 | case Typedef: |
| 329 | case UnresolvedUsingTypename: |
| 330 | case TemplateTypeParm: |
| 331 | return IDNS_Ordinary | IDNS_Type; |
| 332 | |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 333 | case UsingShadow: |
| 334 | return 0; // we'll actually overwrite this later |
| 335 | |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 336 | case UnresolvedUsingValue: |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 337 | return IDNS_Ordinary | IDNS_Using; |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 338 | |
| 339 | case Using: |
| 340 | return IDNS_Using; |
| 341 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 342 | case ObjCProtocol: |
Douglas Gregor | 79947a2 | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 343 | return IDNS_ObjCProtocol; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 345 | case Field: |
| 346 | case ObjCAtDefsField: |
| 347 | case ObjCIvar: |
| 348 | return IDNS_Member; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 350 | case Record: |
| 351 | case CXXRecord: |
| 352 | case Enum: |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 353 | return IDNS_Tag | IDNS_Type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 355 | case Namespace: |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 356 | case NamespaceAlias: |
| 357 | return IDNS_Namespace; |
| 358 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 359 | case FunctionTemplate: |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 360 | return IDNS_Ordinary; |
| 361 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 362 | case ClassTemplate: |
| 363 | case TemplateTemplateParm: |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 364 | return IDNS_Ordinary | IDNS_Tag | IDNS_Type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 366 | // Never have names. |
John McCall | aa74a0c | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 367 | case Friend: |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 368 | case FriendTemplate: |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 369 | case AccessSpec: |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 370 | case LinkageSpec: |
| 371 | case FileScopeAsm: |
| 372 | case StaticAssert: |
| 373 | case ObjCClass: |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 374 | case ObjCPropertyImpl: |
| 375 | case ObjCForwardProtocol: |
| 376 | case Block: |
| 377 | case TranslationUnit: |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 378 | |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 379 | case UsingDirective: |
| 380 | case ClassTemplateSpecialization: |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 381 | case ClassTemplatePartialSpecialization: |
Douglas Gregor | e93525e | 2010-04-22 23:19:50 +0000 | [diff] [blame] | 382 | case ObjCImplementation: |
| 383 | case ObjCCategory: |
| 384 | case ObjCCategoryImpl: |
| 385 | // Never looked up by name. |
Chris Lattner | 8e09719 | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 386 | return 0; |
| 387 | } |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 388 | |
| 389 | return 0; |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 392 | void Decl::setAttrs(const AttrVec &attrs) { |
Argyrios Kyrtzidis | 9116717 | 2010-06-11 23:09:25 +0000 | [diff] [blame] | 393 | assert(!HasAttrs && "Decl already contains attrs."); |
| 394 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 395 | AttrVec &AttrBlank = getASTContext().getDeclAttrs(this); |
| 396 | assert(AttrBlank.empty() && "HasAttrs was wrong?"); |
Argyrios Kyrtzidis | 9116717 | 2010-06-11 23:09:25 +0000 | [diff] [blame] | 397 | |
| 398 | AttrBlank = attrs; |
| 399 | HasAttrs = true; |
| 400 | } |
| 401 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 402 | void Decl::dropAttrs() { |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 403 | if (!HasAttrs) return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 405 | HasAttrs = false; |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 406 | getASTContext().eraseDeclAttrs(this); |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 409 | const AttrVec &Decl::getAttrs() const { |
| 410 | assert(HasAttrs && "No attrs to get!"); |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 411 | return getASTContext().getDeclAttrs(this); |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 414 | void Decl::swapAttrs(Decl *RHS) { |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 415 | bool HasLHSAttr = this->HasAttrs; |
| 416 | bool HasRHSAttr = RHS->HasAttrs; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 418 | // Usually, neither decl has attrs, nothing to do. |
| 419 | if (!HasLHSAttr && !HasRHSAttr) return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 421 | // If 'this' has no attrs, swap the other way. |
| 422 | if (!HasLHSAttr) |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 423 | return RHS->swapAttrs(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 | |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 425 | ASTContext &Context = getASTContext(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 427 | // Handle the case when both decls have attrs. |
| 428 | if (HasRHSAttr) { |
Douglas Gregor | 78bd61f | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 429 | std::swap(Context.getDeclAttrs(this), Context.getDeclAttrs(RHS)); |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 430 | return; |
| 431 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 433 | // Otherwise, LHS has an attr and RHS doesn't. |
Douglas Gregor | 78bd61f | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 434 | Context.getDeclAttrs(RHS) = Context.getDeclAttrs(this); |
| 435 | Context.eraseDeclAttrs(this); |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 436 | this->HasAttrs = false; |
| 437 | RHS->HasAttrs = true; |
| 438 | } |
| 439 | |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 440 | Decl *Decl::castFromDeclContext (const DeclContext *D) { |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 441 | Decl::Kind DK = D->getDeclKind(); |
| 442 | switch(DK) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 443 | #define DECL(NAME, BASE) |
| 444 | #define DECL_CONTEXT(NAME) \ |
| 445 | case Decl::NAME: \ |
| 446 | return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D)); |
| 447 | #define DECL_CONTEXT_BASE(NAME) |
| 448 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 449 | default: |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 450 | #define DECL(NAME, BASE) |
| 451 | #define DECL_CONTEXT_BASE(NAME) \ |
| 452 | if (DK >= first##NAME && DK <= last##NAME) \ |
| 453 | return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D)); |
| 454 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 455 | assert(false && "a decl that inherits DeclContext isn't handled"); |
| 456 | return 0; |
| 457 | } |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | DeclContext *Decl::castToDeclContext(const Decl *D) { |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 461 | Decl::Kind DK = D->getKind(); |
| 462 | switch(DK) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 463 | #define DECL(NAME, BASE) |
| 464 | #define DECL_CONTEXT(NAME) \ |
| 465 | case Decl::NAME: \ |
| 466 | return static_cast<NAME##Decl*>(const_cast<Decl*>(D)); |
| 467 | #define DECL_CONTEXT_BASE(NAME) |
| 468 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 469 | default: |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 470 | #define DECL(NAME, BASE) |
| 471 | #define DECL_CONTEXT_BASE(NAME) \ |
| 472 | if (DK >= first##NAME && DK <= last##NAME) \ |
| 473 | return static_cast<NAME##Decl*>(const_cast<Decl*>(D)); |
| 474 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 475 | assert(false && "a decl that inherits DeclContext isn't handled"); |
| 476 | return 0; |
| 477 | } |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Douglas Gregor | f7b2c93 | 2011-02-17 07:13:24 +0000 | [diff] [blame] | 480 | Stmt *Decl::getBody() const { |
| 481 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 482 | return FD->getBody(); |
| 483 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(this)) |
| 484 | return MD->getBody(); |
| 485 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(this)) |
| 486 | return BD->getBody(); |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | bool Decl::hasBody() const { |
| 492 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 493 | return FD->hasBody(); |
| 494 | |
| 495 | return getBody() != 0; |
| 496 | } |
| 497 | |
Argyrios Kyrtzidis | ddcd132 | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 498 | SourceLocation Decl::getBodyRBrace() const { |
Argyrios Kyrtzidis | 36ea322 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 499 | // Special handling of FunctionDecl to avoid de-serializing the body from PCH. |
| 500 | // FunctionDecl stores EndRangeLoc for this purpose. |
| 501 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) { |
| 502 | const FunctionDecl *Definition; |
| 503 | if (FD->hasBody(Definition)) |
| 504 | return Definition->getSourceRange().getEnd(); |
| 505 | return SourceLocation(); |
| 506 | } |
| 507 | |
Argyrios Kyrtzidis | 6fbc8fa | 2010-07-07 11:31:27 +0000 | [diff] [blame] | 508 | if (Stmt *Body = getBody()) |
| 509 | return Body->getSourceRange().getEnd(); |
| 510 | |
| 511 | return SourceLocation(); |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Anders Carlsson | a28908d | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 514 | void Decl::CheckAccessDeclContext() const { |
Douglas Gregor | 4b00d3b | 2010-12-02 00:22:25 +0000 | [diff] [blame] | 515 | #ifndef NDEBUG |
John McCall | 401982f | 2010-01-20 21:53:11 +0000 | [diff] [blame] | 516 | // Suppress this check if any of the following hold: |
| 517 | // 1. this is the translation unit (and thus has no parent) |
| 518 | // 2. this is a template parameter (and thus doesn't belong to its context) |
Argyrios Kyrtzidis | e177863 | 2010-09-08 21:58:42 +0000 | [diff] [blame] | 519 | // 3. this is a non-type template parameter |
| 520 | // 4. the context is not a record |
| 521 | // 5. it's invalid |
| 522 | // 6. it's a C++0x static_assert. |
Anders Carlsson | adf36b2 | 2009-08-29 20:47:47 +0000 | [diff] [blame] | 523 | if (isa<TranslationUnitDecl>(this) || |
Argyrios Kyrtzidis | a45855f | 2010-07-02 11:55:44 +0000 | [diff] [blame] | 524 | isa<TemplateTypeParmDecl>(this) || |
Argyrios Kyrtzidis | e177863 | 2010-09-08 21:58:42 +0000 | [diff] [blame] | 525 | isa<NonTypeTemplateParmDecl>(this) || |
Douglas Gregor | 2b76dd9 | 2010-02-22 17:53:38 +0000 | [diff] [blame] | 526 | !isa<CXXRecordDecl>(getDeclContext()) || |
Argyrios Kyrtzidis | 260b4a8 | 2010-09-08 21:32:35 +0000 | [diff] [blame] | 527 | isInvalidDecl() || |
| 528 | isa<StaticAssertDecl>(this) || |
| 529 | // FIXME: a ParmVarDecl can have ClassTemplateSpecialization |
| 530 | // as DeclContext (?). |
Argyrios Kyrtzidis | e177863 | 2010-09-08 21:58:42 +0000 | [diff] [blame] | 531 | isa<ParmVarDecl>(this) || |
| 532 | // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have |
| 533 | // AS_none as access specifier. |
| 534 | isa<CXXRecordDecl>(this)) |
Anders Carlsson | adf36b2 | 2009-08-29 20:47:47 +0000 | [diff] [blame] | 535 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | |
| 537 | assert(Access != AS_none && |
Anders Carlsson | a28908d | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 538 | "Access specifier is AS_none inside a record decl"); |
Douglas Gregor | 4b00d3b | 2010-12-02 00:22:25 +0000 | [diff] [blame] | 539 | #endif |
Anders Carlsson | a28908d | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Anders Carlsson | a28908d | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 542 | |
Eli Friedman | 7dbab8a | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 543 | //===----------------------------------------------------------------------===// |
| 544 | // DeclContext Implementation |
| 545 | //===----------------------------------------------------------------------===// |
| 546 | |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 547 | bool DeclContext::classof(const Decl *D) { |
| 548 | switch (D->getKind()) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 549 | #define DECL(NAME, BASE) |
| 550 | #define DECL_CONTEXT(NAME) case Decl::NAME: |
| 551 | #define DECL_CONTEXT_BASE(NAME) |
| 552 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 553 | return true; |
| 554 | default: |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 555 | #define DECL(NAME, BASE) |
| 556 | #define DECL_CONTEXT_BASE(NAME) \ |
| 557 | if (D->getKind() >= Decl::first##NAME && \ |
| 558 | D->getKind() <= Decl::last##NAME) \ |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 559 | return true; |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 560 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | afe24c8 | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 561 | return false; |
| 562 | } |
| 563 | } |
| 564 | |
Douglas Gregor | 9c832f7 | 2010-07-25 18:38:02 +0000 | [diff] [blame] | 565 | DeclContext::~DeclContext() { } |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 566 | |
Douglas Gregor | 7f737c0 | 2009-09-10 16:57:35 +0000 | [diff] [blame] | 567 | /// \brief Find the parent context of this context that will be |
| 568 | /// used for unqualified name lookup. |
| 569 | /// |
| 570 | /// Generally, the parent lookup context is the semantic context. However, for |
| 571 | /// a friend function the parent lookup context is the lexical context, which |
| 572 | /// is the class in which the friend is declared. |
| 573 | DeclContext *DeclContext::getLookupParent() { |
| 574 | // FIXME: Find a better way to identify friends |
| 575 | if (isa<FunctionDecl>(this)) |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 576 | if (getParent()->getRedeclContext()->isFileContext() && |
| 577 | getLexicalParent()->getRedeclContext()->isRecord()) |
Douglas Gregor | 7f737c0 | 2009-09-10 16:57:35 +0000 | [diff] [blame] | 578 | return getLexicalParent(); |
| 579 | |
| 580 | return getParent(); |
| 581 | } |
| 582 | |
Sebastian Redl | bd59576 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 583 | bool DeclContext::isInlineNamespace() const { |
| 584 | return isNamespace() && |
| 585 | cast<NamespaceDecl>(this)->isInline(); |
| 586 | } |
| 587 | |
Douglas Gregor | 9e927ab | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 588 | bool DeclContext::isDependentContext() const { |
| 589 | if (isFileContext()) |
| 590 | return false; |
| 591 | |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 592 | if (isa<ClassTemplatePartialSpecializationDecl>(this)) |
| 593 | return true; |
| 594 | |
Douglas Gregor | 9e927ab | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 595 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this)) |
| 596 | if (Record->getDescribedClassTemplate()) |
| 597 | return true; |
| 598 | |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 599 | if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(this)) { |
Douglas Gregor | 9e927ab | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 600 | if (Function->getDescribedFunctionTemplate()) |
| 601 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 603 | // Friend function declarations are dependent if their *lexical* |
| 604 | // context is dependent. |
| 605 | if (cast<Decl>(this)->getFriendObjectKind()) |
| 606 | return getLexicalParent()->isDependentContext(); |
| 607 | } |
| 608 | |
Douglas Gregor | 9e927ab | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 609 | return getParent() && getParent()->isDependentContext(); |
| 610 | } |
| 611 | |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 612 | bool DeclContext::isTransparentContext() const { |
| 613 | if (DeclKind == Decl::Enum) |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 614 | return !cast<EnumDecl>(this)->isScoped(); |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 615 | else if (DeclKind == Decl::LinkageSpec) |
| 616 | return true; |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 617 | |
| 618 | return false; |
| 619 | } |
| 620 | |
John McCall | 5fe8412 | 2010-10-26 04:59:26 +0000 | [diff] [blame] | 621 | bool DeclContext::isExternCContext() const { |
| 622 | const DeclContext *DC = this; |
| 623 | while (DC->DeclKind != Decl::TranslationUnit) { |
| 624 | if (DC->DeclKind == Decl::LinkageSpec) |
| 625 | return cast<LinkageSpecDecl>(DC)->getLanguage() |
| 626 | == LinkageSpecDecl::lang_c; |
| 627 | DC = DC->getParent(); |
| 628 | } |
| 629 | return false; |
| 630 | } |
| 631 | |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 632 | bool DeclContext::Encloses(const DeclContext *DC) const { |
Douglas Gregor | e985a3b | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 633 | if (getPrimaryContext() != this) |
| 634 | return getPrimaryContext()->Encloses(DC); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | e985a3b | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 636 | for (; DC; DC = DC->getParent()) |
| 637 | if (DC->getPrimaryContext() == this) |
| 638 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | return false; |
Douglas Gregor | e985a3b | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 642 | DeclContext *DeclContext::getPrimaryContext() { |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 643 | switch (DeclKind) { |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 644 | case Decl::TranslationUnit: |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 645 | case Decl::LinkageSpec: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | case Decl::Block: |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 647 | // There is only one DeclContext for these entities. |
| 648 | return this; |
| 649 | |
| 650 | case Decl::Namespace: |
| 651 | // The original namespace is our primary context. |
| 652 | return static_cast<NamespaceDecl*>(this)->getOriginalNamespace(); |
| 653 | |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 654 | case Decl::ObjCMethod: |
| 655 | return this; |
| 656 | |
| 657 | case Decl::ObjCInterface: |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 658 | case Decl::ObjCProtocol: |
| 659 | case Decl::ObjCCategory: |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 660 | // FIXME: Can Objective-C interfaces be forward-declared? |
| 661 | return this; |
| 662 | |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 663 | case Decl::ObjCImplementation: |
| 664 | case Decl::ObjCCategoryImpl: |
| 665 | return this; |
| 666 | |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 667 | default: |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 668 | if (DeclKind >= Decl::firstTag && DeclKind <= Decl::lastTag) { |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 669 | // If this is a tag type that has a definition or is currently |
| 670 | // being defined, that definition is our primary context. |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 671 | TagDecl *Tag = cast<TagDecl>(this); |
| 672 | assert(isa<TagType>(Tag->TypeForDecl) || |
| 673 | isa<InjectedClassNameType>(Tag->TypeForDecl)); |
| 674 | |
| 675 | if (TagDecl *Def = Tag->getDefinition()) |
| 676 | return Def; |
| 677 | |
| 678 | if (!isa<InjectedClassNameType>(Tag->TypeForDecl)) { |
| 679 | const TagType *TagTy = cast<TagType>(Tag->TypeForDecl); |
| 680 | if (TagTy->isBeingDefined()) |
| 681 | // FIXME: is it necessarily being defined in the decl |
| 682 | // that owns the type? |
| 683 | return TagTy->getDecl(); |
| 684 | } |
| 685 | |
| 686 | return Tag; |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 689 | assert(DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction && |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 690 | "Unknown DeclContext kind"); |
| 691 | return this; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | DeclContext *DeclContext::getNextContext() { |
| 696 | switch (DeclKind) { |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 697 | case Decl::Namespace: |
| 698 | // Return the next namespace |
| 699 | return static_cast<NamespaceDecl*>(this)->getNextNamespace(); |
| 700 | |
| 701 | default: |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 702 | return 0; |
| 703 | } |
| 704 | } |
| 705 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 706 | std::pair<Decl *, Decl *> |
| 707 | DeclContext::BuildDeclChain(const llvm::SmallVectorImpl<Decl*> &Decls) { |
| 708 | // Build up a chain of declarations via the Decl::NextDeclInContext field. |
| 709 | Decl *FirstNewDecl = 0; |
| 710 | Decl *PrevDecl = 0; |
| 711 | for (unsigned I = 0, N = Decls.size(); I != N; ++I) { |
| 712 | Decl *D = Decls[I]; |
| 713 | if (PrevDecl) |
| 714 | PrevDecl->NextDeclInContext = D; |
| 715 | else |
| 716 | FirstNewDecl = D; |
| 717 | |
| 718 | PrevDecl = D; |
| 719 | } |
| 720 | |
| 721 | return std::make_pair(FirstNewDecl, PrevDecl); |
| 722 | } |
| 723 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 724 | /// \brief Load the declarations within this lexical storage from an |
| 725 | /// external source. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | void |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 727 | DeclContext::LoadLexicalDeclsFromExternalStorage() const { |
| 728 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 729 | assert(hasExternalLexicalStorage() && Source && "No external storage?"); |
| 730 | |
Argyrios Kyrtzidis | 98d045e | 2010-07-30 10:03:23 +0000 | [diff] [blame] | 731 | // Notify that we have a DeclContext that is initializing. |
| 732 | ExternalASTSource::Deserializing ADeclContext(Source); |
| 733 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 734 | llvm::SmallVector<Decl*, 64> Decls; |
| 735 | if (Source->FindExternalLexicalDecls(this, Decls)) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 736 | return; |
| 737 | |
| 738 | // There is no longer any lexical storage in this context |
| 739 | ExternalLexicalStorage = false; |
| 740 | |
| 741 | if (Decls.empty()) |
| 742 | return; |
| 743 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 744 | // We may have already loaded just the fields of this record, in which case |
| 745 | // don't add the decls, just replace the FirstDecl/LastDecl chain. |
| 746 | if (const RecordDecl *RD = dyn_cast<RecordDecl>(this)) |
| 747 | if (RD->LoadedFieldsFromExternalStorage) { |
| 748 | llvm::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls); |
| 749 | return; |
| 750 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 751 | |
| 752 | // Splice the newly-read declarations into the beginning of the list |
| 753 | // of declarations. |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 754 | Decl *ExternalFirst, *ExternalLast; |
| 755 | llvm::tie(ExternalFirst, ExternalLast) = BuildDeclChain(Decls); |
| 756 | ExternalLast->NextDeclInContext = FirstDecl; |
| 757 | FirstDecl = ExternalFirst; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 758 | if (!LastDecl) |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 759 | LastDecl = ExternalLast; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 760 | } |
| 761 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 762 | DeclContext::lookup_result |
| 763 | ExternalASTSource::SetNoExternalVisibleDeclsForName(const DeclContext *DC, |
| 764 | DeclarationName Name) { |
| 765 | ASTContext &Context = DC->getParentASTContext(); |
| 766 | StoredDeclsMap *Map; |
| 767 | if (!(Map = DC->LookupPtr)) |
| 768 | Map = DC->CreateStoredDeclsMap(Context); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 769 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 770 | StoredDeclsList &List = (*Map)[Name]; |
| 771 | assert(List.isNull()); |
| 772 | (void) List; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 773 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 774 | return DeclContext::lookup_result(); |
| 775 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 776 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 777 | DeclContext::lookup_result |
| 778 | ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 779 | DeclarationName Name, |
| 780 | llvm::SmallVectorImpl<NamedDecl*> &Decls) { |
| 781 | ASTContext &Context = DC->getParentASTContext();; |
| 782 | |
| 783 | StoredDeclsMap *Map; |
| 784 | if (!(Map = DC->LookupPtr)) |
| 785 | Map = DC->CreateStoredDeclsMap(Context); |
| 786 | |
| 787 | StoredDeclsList &List = (*Map)[Name]; |
| 788 | for (unsigned I = 0, N = Decls.size(); I != N; ++I) { |
| 789 | if (List.isNull()) |
| 790 | List.setOnlyValue(Decls[I]); |
| 791 | else |
| 792 | List.AddSubsequentDecl(Decls[I]); |
| 793 | } |
| 794 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 795 | return List.getLookupResult(); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 798 | void ExternalASTSource::MaterializeVisibleDeclsForName(const DeclContext *DC, |
| 799 | DeclarationName Name, |
| 800 | llvm::SmallVectorImpl<NamedDecl*> &Decls) { |
| 801 | assert(DC->LookupPtr); |
| 802 | StoredDeclsMap &Map = *DC->LookupPtr; |
| 803 | |
| 804 | // If there's an entry in the table the visible decls for this name have |
| 805 | // already been deserialized. |
| 806 | if (Map.find(Name) == Map.end()) { |
| 807 | StoredDeclsList &List = Map[Name]; |
| 808 | for (unsigned I = 0, N = Decls.size(); I != N; ++I) { |
| 809 | if (List.isNull()) |
| 810 | List.setOnlyValue(Decls[I]); |
| 811 | else |
| 812 | List.AddSubsequentDecl(Decls[I]); |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 817 | DeclContext::decl_iterator DeclContext::noload_decls_begin() const { |
| 818 | return decl_iterator(FirstDecl); |
| 819 | } |
| 820 | |
| 821 | DeclContext::decl_iterator DeclContext::noload_decls_end() const { |
| 822 | return decl_iterator(); |
| 823 | } |
| 824 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 825 | DeclContext::decl_iterator DeclContext::decls_begin() const { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 826 | if (hasExternalLexicalStorage()) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 827 | LoadLexicalDeclsFromExternalStorage(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 828 | |
| 829 | // FIXME: Check whether we need to load some declarations from |
| 830 | // external storage. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | return decl_iterator(FirstDecl); |
Douglas Gregor | bcced4e | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 834 | DeclContext::decl_iterator DeclContext::decls_end() const { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 835 | if (hasExternalLexicalStorage()) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 836 | LoadLexicalDeclsFromExternalStorage(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 837 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | return decl_iterator(); |
Douglas Gregor | bcced4e | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 841 | bool DeclContext::decls_empty() const { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 842 | if (hasExternalLexicalStorage()) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 843 | LoadLexicalDeclsFromExternalStorage(); |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 844 | |
| 845 | return !FirstDecl; |
| 846 | } |
| 847 | |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 848 | void DeclContext::removeDecl(Decl *D) { |
| 849 | assert(D->getLexicalDeclContext() == this && |
| 850 | "decl being removed from non-lexical context"); |
| 851 | assert((D->NextDeclInContext || D == LastDecl) && |
| 852 | "decl is not in decls list"); |
| 853 | |
| 854 | // Remove D from the decl chain. This is O(n) but hopefully rare. |
| 855 | if (D == FirstDecl) { |
| 856 | if (D == LastDecl) |
| 857 | FirstDecl = LastDecl = 0; |
| 858 | else |
| 859 | FirstDecl = D->NextDeclInContext; |
| 860 | } else { |
| 861 | for (Decl *I = FirstDecl; true; I = I->NextDeclInContext) { |
| 862 | assert(I && "decl not found in linked list"); |
| 863 | if (I->NextDeclInContext == D) { |
| 864 | I->NextDeclInContext = D->NextDeclInContext; |
| 865 | if (D == LastDecl) LastDecl = I; |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | // Mark that D is no longer in the decl chain. |
| 872 | D->NextDeclInContext = 0; |
| 873 | |
| 874 | // Remove D from the lookup table if necessary. |
| 875 | if (isa<NamedDecl>(D)) { |
| 876 | NamedDecl *ND = cast<NamedDecl>(D); |
| 877 | |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 878 | StoredDeclsMap *Map = getPrimaryContext()->LookupPtr; |
| 879 | if (!Map) return; |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 880 | |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 881 | StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName()); |
| 882 | assert(Pos != Map->end() && "no lookup entry for decl"); |
| 883 | Pos->second.remove(ND); |
| 884 | } |
| 885 | } |
| 886 | |
John McCall | d1e9d83 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 887 | void DeclContext::addHiddenDecl(Decl *D) { |
Chris Lattner | 33f219d | 2009-02-20 00:56:18 +0000 | [diff] [blame] | 888 | assert(D->getLexicalDeclContext() == this && |
| 889 | "Decl inserted into wrong lexical context"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | assert(!D->getNextDeclInContext() && D != LastDecl && |
Douglas Gregor | 020713e | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 891 | "Decl already inserted into a DeclContext"); |
| 892 | |
| 893 | if (FirstDecl) { |
Chris Lattner | fcd33a6 | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 894 | LastDecl->NextDeclInContext = D; |
Douglas Gregor | 020713e | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 895 | LastDecl = D; |
| 896 | } else { |
| 897 | FirstDecl = LastDecl = D; |
| 898 | } |
Douglas Gregor | a1ce1f8 | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 899 | |
| 900 | // Notify a C++ record declaration that we've added a member, so it can |
| 901 | // update it's class-specific state. |
| 902 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this)) |
| 903 | Record->addedMember(D); |
John McCall | d1e9d83 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | void DeclContext::addDecl(Decl *D) { |
| 907 | addHiddenDecl(D); |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 908 | |
| 909 | if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 910 | ND->getDeclContext()->makeDeclVisibleInContext(ND); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 913 | /// buildLookup - Build the lookup data structure with all of the |
| 914 | /// declarations in DCtx (and any other contexts linked to it or |
| 915 | /// transparent contexts nested within it). |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 916 | void DeclContext::buildLookup(DeclContext *DCtx) { |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 917 | for (; DCtx; DCtx = DCtx->getNextContext()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 918 | for (decl_iterator D = DCtx->decls_begin(), |
| 919 | DEnd = DCtx->decls_end(); |
Douglas Gregor | d05cb41 | 2009-01-06 07:17:58 +0000 | [diff] [blame] | 920 | D != DEnd; ++D) { |
John McCall | d1e9d83 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 921 | // Insert this declaration into the lookup structure, but only |
| 922 | // if it's semantically in its decl context. During non-lazy |
| 923 | // lookup building, this is implicitly enforced by addDecl. |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 924 | if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) |
John McCall | d1e9d83 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 925 | if (D->getDeclContext() == DCtx) |
| 926 | makeDeclVisibleInContextImpl(ND); |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 927 | |
Ted Kremenek | 707ece6 | 2009-11-17 22:58:30 +0000 | [diff] [blame] | 928 | // Insert any forward-declared Objective-C interfaces into the lookup |
| 929 | // data structure. |
| 930 | if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(*D)) |
| 931 | for (ObjCClassDecl::iterator I = Class->begin(), IEnd = Class->end(); |
| 932 | I != IEnd; ++I) |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 933 | makeDeclVisibleInContextImpl(I->getInterface()); |
Ted Kremenek | 707ece6 | 2009-11-17 22:58:30 +0000 | [diff] [blame] | 934 | |
Sebastian Redl | bd59576 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 935 | // If this declaration is itself a transparent declaration context or |
| 936 | // inline namespace, add its members (recursively). |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 937 | if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D)) |
Sebastian Redl | bd59576 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 938 | if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace()) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 939 | buildLookup(InnerCtx->getPrimaryContext()); |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | DeclContext::lookup_result |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 945 | DeclContext::lookup(DeclarationName Name) { |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 946 | DeclContext *PrimaryContext = getPrimaryContext(); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 947 | if (PrimaryContext != this) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 948 | return PrimaryContext->lookup(Name); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 949 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 950 | if (hasExternalVisibleStorage()) { |
| 951 | // Check to see if we've already cached the lookup results. |
| 952 | if (LookupPtr) { |
| 953 | StoredDeclsMap::iterator I = LookupPtr->find(Name); |
| 954 | if (I != LookupPtr->end()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 955 | return I->second.getLookupResult(); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
| 959 | return Source->FindExternalVisibleDeclsByName(this, Name); |
| 960 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 961 | |
Douglas Gregor | 55297ac | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 962 | /// If there is no lookup data structure, build one now by walking |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 963 | /// all of the linked DeclContexts (in declaration order!) and |
| 964 | /// inserting their values. |
Douglas Gregor | 9615ec2 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 965 | if (!LookupPtr) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 966 | buildLookup(this); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 967 | |
Douglas Gregor | 9615ec2 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 968 | if (!LookupPtr) |
Douglas Gregor | 10dc8aa | 2010-05-11 06:18:17 +0000 | [diff] [blame] | 969 | return lookup_result(lookup_iterator(0), lookup_iterator(0)); |
Douglas Gregor | 9615ec2 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 970 | } |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 971 | |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 972 | StoredDeclsMap::iterator Pos = LookupPtr->find(Name); |
| 973 | if (Pos == LookupPtr->end()) |
Douglas Gregor | 10dc8aa | 2010-05-11 06:18:17 +0000 | [diff] [blame] | 974 | return lookup_result(lookup_iterator(0), lookup_iterator(0)); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 975 | return Pos->second.getLookupResult(); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | DeclContext::lookup_const_result |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 979 | DeclContext::lookup(DeclarationName Name) const { |
| 980 | return const_cast<DeclContext*>(this)->lookup(Name); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 983 | DeclContext *DeclContext::getRedeclContext() { |
Chris Lattner | 17a1bfa | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 984 | DeclContext *Ctx = this; |
Sebastian Redl | bd59576 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 985 | // Skip through transparent contexts. |
| 986 | while (Ctx->isTransparentContext()) |
Douglas Gregor | 6ad0ef5 | 2009-01-06 23:51:29 +0000 | [diff] [blame] | 987 | Ctx = Ctx->getParent(); |
| 988 | return Ctx; |
| 989 | } |
| 990 | |
Douglas Gregor | f47b911 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 991 | DeclContext *DeclContext::getEnclosingNamespaceContext() { |
| 992 | DeclContext *Ctx = this; |
| 993 | // Skip through non-namespace, non-translation-unit contexts. |
Sebastian Redl | 4f08c96 | 2010-08-31 00:36:23 +0000 | [diff] [blame] | 994 | while (!Ctx->isFileContext()) |
Douglas Gregor | f47b911 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 995 | Ctx = Ctx->getParent(); |
| 996 | return Ctx->getPrimaryContext(); |
| 997 | } |
| 998 | |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 999 | bool DeclContext::InEnclosingNamespaceSetOf(const DeclContext *O) const { |
| 1000 | // For non-file contexts, this is equivalent to Equals. |
| 1001 | if (!isFileContext()) |
| 1002 | return O->Equals(this); |
| 1003 | |
| 1004 | do { |
| 1005 | if (O->Equals(this)) |
| 1006 | return true; |
| 1007 | |
| 1008 | const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(O); |
| 1009 | if (!NS || !NS->isInline()) |
| 1010 | break; |
| 1011 | O = NS->getParent(); |
| 1012 | } while (O); |
| 1013 | |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
John McCall | 759e32b | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 1017 | void DeclContext::makeDeclVisibleInContext(NamedDecl *D, bool Recoverable) { |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1018 | // FIXME: This feels like a hack. Should DeclarationName support |
| 1019 | // template-ids, or is there a better way to keep specializations |
| 1020 | // from being visible? |
| 1021 | if (isa<ClassTemplateSpecializationDecl>(D)) |
| 1022 | return; |
Eli Friedman | 7316819 | 2009-12-08 05:40:03 +0000 | [diff] [blame] | 1023 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 1024 | if (FD->isFunctionTemplateSpecialization()) |
| 1025 | return; |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1026 | |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1027 | DeclContext *PrimaryContext = getPrimaryContext(); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1028 | if (PrimaryContext != this) { |
John McCall | 759e32b | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 1029 | PrimaryContext->makeDeclVisibleInContext(D, Recoverable); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | // If we already have a lookup data structure, perform the insertion |
Argyrios Kyrtzidis | e51e554 | 2010-07-04 21:44:25 +0000 | [diff] [blame] | 1034 | // into it. If we haven't deserialized externally stored decls, deserialize |
| 1035 | // them so we can add the decl. Otherwise, be lazy and don't build that |
| 1036 | // structure until someone asks for it. |
| 1037 | if (LookupPtr || !Recoverable || hasExternalVisibleStorage()) |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1038 | makeDeclVisibleInContextImpl(D); |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1039 | |
Sebastian Redl | bd59576 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 1040 | // If we are a transparent context or inline namespace, insert into our |
| 1041 | // parent context, too. This operation is recursive. |
| 1042 | if (isTransparentContext() || isInlineNamespace()) |
John McCall | 759e32b | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 1043 | getParent()->makeDeclVisibleInContext(D, Recoverable); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 1044 | |
| 1045 | Decl *DCAsDecl = cast<Decl>(this); |
| 1046 | // Notify that a decl was made visible unless it's a Tag being defined. |
| 1047 | if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined())) |
| 1048 | if (ASTMutationListener *L = DCAsDecl->getASTMutationListener()) |
| 1049 | L->AddedVisibleDecl(this, D); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1052 | void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1053 | // Skip unnamed declarations. |
| 1054 | if (!D->getDeclName()) |
| 1055 | return; |
| 1056 | |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1057 | // FIXME: This feels like a hack. Should DeclarationName support |
| 1058 | // template-ids, or is there a better way to keep specializations |
| 1059 | // from being visible? |
| 1060 | if (isa<ClassTemplateSpecializationDecl>(D)) |
| 1061 | return; |
| 1062 | |
Argyrios Kyrtzidis | e51e554 | 2010-07-04 21:44:25 +0000 | [diff] [blame] | 1063 | ASTContext *C = 0; |
| 1064 | if (!LookupPtr) { |
| 1065 | C = &getParentASTContext(); |
| 1066 | CreateStoredDeclsMap(*C); |
| 1067 | } |
| 1068 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1069 | // If there is an external AST source, load any declarations it knows about |
| 1070 | // with this declaration's name. |
| 1071 | // If the lookup table contains an entry about this name it means that we |
| 1072 | // have already checked the external source. |
| 1073 | if (ExternalASTSource *Source = getParentASTContext().getExternalSource()) |
| 1074 | if (hasExternalVisibleStorage() && |
| 1075 | LookupPtr->find(D->getDeclName()) == LookupPtr->end()) |
| 1076 | Source->FindExternalVisibleDeclsByName(this, D->getDeclName()); |
| 1077 | |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1078 | // Insert this declaration into the map. |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1079 | StoredDeclsList &DeclNameEntries = (*LookupPtr)[D->getDeclName()]; |
Chris Lattner | caae716 | 2009-02-20 01:44:05 +0000 | [diff] [blame] | 1080 | if (DeclNameEntries.isNull()) { |
| 1081 | DeclNameEntries.setOnlyValue(D); |
Chris Lattner | dfd6b3d | 2009-02-19 07:00:44 +0000 | [diff] [blame] | 1082 | return; |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1083 | } |
Chris Lattner | 24e24d5 | 2009-02-20 00:55:03 +0000 | [diff] [blame] | 1084 | |
Chris Lattner | 29578f3 | 2009-02-20 01:10:07 +0000 | [diff] [blame] | 1085 | // If it is possible that this is a redeclaration, check to see if there is |
| 1086 | // already a decl for which declarationReplaces returns true. If there is |
| 1087 | // one, just replace it and return. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1088 | if (DeclNameEntries.HandleRedeclaration(D)) |
Chris Lattner | caae716 | 2009-02-20 01:44:05 +0000 | [diff] [blame] | 1089 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Chris Lattner | dfd6b3d | 2009-02-19 07:00:44 +0000 | [diff] [blame] | 1091 | // Put this declaration into the appropriate slot. |
Chris Lattner | caae716 | 2009-02-20 01:44:05 +0000 | [diff] [blame] | 1092 | DeclNameEntries.AddSubsequentDecl(D); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1093 | } |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1094 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 1095 | void DeclContext::MaterializeVisibleDeclsFromExternalStorage() { |
| 1096 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
| 1097 | assert(hasExternalVisibleStorage() && Source && "No external storage?"); |
| 1098 | |
| 1099 | if (!LookupPtr) |
| 1100 | CreateStoredDeclsMap(getParentASTContext()); |
| 1101 | Source->MaterializeVisibleDecls(this); |
| 1102 | } |
| 1103 | |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1104 | /// Returns iterator range [First, Last) of UsingDirectiveDecls stored within |
| 1105 | /// this context. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | DeclContext::udir_iterator_range |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1107 | DeclContext::getUsingDirectives() const { |
| 1108 | lookup_const_result Result = lookup(UsingDirectiveDecl::getName()); |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1109 | return udir_iterator_range(reinterpret_cast<udir_iterator>(Result.first), |
| 1110 | reinterpret_cast<udir_iterator>(Result.second)); |
| 1111 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1112 | |
Ted Kremenek | da4e0d3 | 2010-02-11 07:12:28 +0000 | [diff] [blame] | 1113 | //===----------------------------------------------------------------------===// |
| 1114 | // Creation and Destruction of StoredDeclsMaps. // |
| 1115 | //===----------------------------------------------------------------------===// |
| 1116 | |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1117 | StoredDeclsMap *DeclContext::CreateStoredDeclsMap(ASTContext &C) const { |
| 1118 | assert(!LookupPtr && "context already has a decls map"); |
| 1119 | assert(getPrimaryContext() == this && |
| 1120 | "creating decls map on non-primary context"); |
| 1121 | |
| 1122 | StoredDeclsMap *M; |
| 1123 | bool Dependent = isDependentContext(); |
| 1124 | if (Dependent) |
| 1125 | M = new DependentStoredDeclsMap(); |
| 1126 | else |
| 1127 | M = new StoredDeclsMap(); |
| 1128 | M->Previous = C.LastSDM; |
| 1129 | C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent); |
| 1130 | LookupPtr = M; |
Ted Kremenek | da4e0d3 | 2010-02-11 07:12:28 +0000 | [diff] [blame] | 1131 | return M; |
| 1132 | } |
| 1133 | |
| 1134 | void ASTContext::ReleaseDeclContextMaps() { |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1135 | // It's okay to delete DependentStoredDeclsMaps via a StoredDeclsMap |
| 1136 | // pointer because the subclass doesn't add anything that needs to |
| 1137 | // be deleted. |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1138 | StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt()); |
| 1139 | } |
| 1140 | |
| 1141 | void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) { |
| 1142 | while (Map) { |
| 1143 | // Advance the iteration before we invalidate memory. |
| 1144 | llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous; |
| 1145 | |
| 1146 | if (Dependent) |
| 1147 | delete static_cast<DependentStoredDeclsMap*>(Map); |
| 1148 | else |
| 1149 | delete Map; |
| 1150 | |
| 1151 | Map = Next.getPointer(); |
| 1152 | Dependent = Next.getInt(); |
| 1153 | } |
| 1154 | } |
| 1155 | |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1156 | DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C, |
| 1157 | DeclContext *Parent, |
| 1158 | const PartialDiagnostic &PDiag) { |
| 1159 | assert(Parent->isDependentContext() |
| 1160 | && "cannot iterate dependent diagnostics of non-dependent context"); |
| 1161 | Parent = Parent->getPrimaryContext(); |
| 1162 | if (!Parent->LookupPtr) |
| 1163 | Parent->CreateStoredDeclsMap(C); |
| 1164 | |
| 1165 | DependentStoredDeclsMap *Map |
| 1166 | = static_cast<DependentStoredDeclsMap*>(Parent->LookupPtr); |
| 1167 | |
Douglas Gregor | a55530e | 2010-03-29 23:56:53 +0000 | [diff] [blame] | 1168 | // Allocate the copy of the PartialDiagnostic via the ASTContext's |
Douglas Gregor | 8933623 | 2010-03-29 23:34:08 +0000 | [diff] [blame] | 1169 | // BumpPtrAllocator, rather than the ASTContext itself. |
Douglas Gregor | a55530e | 2010-03-29 23:56:53 +0000 | [diff] [blame] | 1170 | PartialDiagnostic::Storage *DiagStorage = 0; |
| 1171 | if (PDiag.hasStorage()) |
| 1172 | DiagStorage = new (C) PartialDiagnostic::Storage; |
| 1173 | |
| 1174 | DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag, DiagStorage); |
John McCall | c62bb64 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1175 | |
| 1176 | // TODO: Maybe we shouldn't reverse the order during insertion. |
| 1177 | DD->NextDiagnostic = Map->FirstDiagnostic; |
| 1178 | Map->FirstDiagnostic = DD; |
| 1179 | |
| 1180 | return DD; |
Ted Kremenek | da4e0d3 | 2010-02-11 07:12:28 +0000 | [diff] [blame] | 1181 | } |