Eli Friedman | 56d2937 | 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 | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 15 | #include "clang/AST/Decl.h" |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" |
| 19 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExternalASTSource.h" |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 23 | #include "clang/AST/Stmt.h" |
| 24 | #include "clang/AST/StmtCXX.h" |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 6ed40e3 | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 27 | #include <algorithm> |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 28 | #include <cstdio> |
Douglas Gregor | 3fc749d | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 29 | #include <vector> |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 30 | using namespace clang; |
| 31 | |
| 32 | //===----------------------------------------------------------------------===// |
| 33 | // Statistics |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 36 | #define DECL(Derived, Base) static int n##Derived##s = 0; |
| 37 | #include "clang/AST/DeclNodes.def" |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 38 | |
| 39 | static bool StatSwitch = false; |
| 40 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 41 | const char *Decl::getDeclKindName() const { |
| 42 | switch (DeclKind) { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 43 | default: assert(0 && "Declaration not in DeclNodes.def!"); |
| 44 | #define DECL(Derived, Base) case Derived: return #Derived; |
| 45 | #include "clang/AST/DeclNodes.def" |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
Steve Naroff | 0a47393 | 2009-01-20 19:53:53 +0000 | [diff] [blame] | 49 | const char *DeclContext::getDeclKindName() const { |
| 50 | switch (DeclKind) { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 51 | default: assert(0 && "Declaration context not in DeclNodes.def!"); |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 52 | #define DECL(Derived, Base) case Decl::Derived: return #Derived; |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 53 | #include "clang/AST/DeclNodes.def" |
Steve Naroff | 0a47393 | 2009-01-20 19:53:53 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 57 | bool Decl::CollectingStats(bool Enable) { |
Kovarththanan Rajaratnam | 2024f4d | 2009-11-29 14:54:35 +0000 | [diff] [blame] | 58 | if (Enable) StatSwitch = true; |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 59 | return StatSwitch; |
| 60 | } |
| 61 | |
| 62 | void Decl::PrintStats() { |
| 63 | fprintf(stderr, "*** Decl Stats:\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 64 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 65 | int totalDecls = 0; |
| 66 | #define DECL(Derived, Base) totalDecls += n##Derived##s; |
| 67 | #include "clang/AST/DeclNodes.def" |
| 68 | fprintf(stderr, " %d decls total.\n", totalDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 70 | int totalBytes = 0; |
| 71 | #define DECL(Derived, Base) \ |
| 72 | if (n##Derived##s > 0) { \ |
| 73 | totalBytes += (int)(n##Derived##s * sizeof(Derived##Decl)); \ |
| 74 | fprintf(stderr, " %d " #Derived " decls, %d each (%d bytes)\n", \ |
| 75 | n##Derived##s, (int)sizeof(Derived##Decl), \ |
| 76 | (int)(n##Derived##s * sizeof(Derived##Decl))); \ |
| 77 | } |
| 78 | #include "clang/AST/DeclNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 80 | fprintf(stderr, "Total bytes = %d\n", totalBytes); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void Decl::addDeclKind(Kind k) { |
| 84 | switch (k) { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 85 | default: assert(0 && "Declaration not in DeclNodes.def!"); |
| 86 | #define DECL(Derived, Base) case Derived: ++n##Derived##s; break; |
| 87 | #include "clang/AST/DeclNodes.def" |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 91 | bool Decl::isTemplateParameterPack() const { |
| 92 | if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(this)) |
| 93 | return TTP->isParameterPack(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 95 | return false; |
| 96 | } |
| 97 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 98 | bool Decl::isFunctionOrFunctionTemplate() const { |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 99 | if (const UsingShadowDecl *UD = dyn_cast<UsingShadowDecl>(this)) |
Anders Carlsson | 58badb7 | 2009-06-26 05:26:50 +0000 | [diff] [blame] | 100 | return UD->getTargetDecl()->isFunctionOrFunctionTemplate(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 102 | return isa<FunctionDecl>(this) || isa<FunctionTemplateDecl>(this); |
| 103 | } |
| 104 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 105 | //===----------------------------------------------------------------------===// |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 106 | // PrettyStackTraceDecl Implementation |
| 107 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 109 | void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const { |
| 110 | SourceLocation TheLoc = Loc; |
| 111 | if (TheLoc.isInvalid() && TheDecl) |
| 112 | TheLoc = TheDecl->getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 114 | if (TheLoc.isValid()) { |
| 115 | TheLoc.print(OS, SM); |
| 116 | OS << ": "; |
| 117 | } |
| 118 | |
| 119 | OS << Message; |
| 120 | |
Daniel Dunbar | c523656 | 2009-11-21 09:05:59 +0000 | [diff] [blame] | 121 | if (const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 122 | OS << " '" << DN->getQualifiedNameAsString() << '\''; |
| 123 | OS << '\n'; |
| 124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 126 | //===----------------------------------------------------------------------===// |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 127 | // Decl Implementation |
| 128 | //===----------------------------------------------------------------------===// |
| 129 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 130 | // Out-of-line virtual method providing a home for Decl. |
| 131 | Decl::~Decl() { |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 132 | assert(!HasAttrs && "attributes should have been freed by Destroy"); |
| 133 | } |
| 134 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 135 | void Decl::setDeclContext(DeclContext *DC) { |
| 136 | if (isOutOfSemaDC()) |
| 137 | delete getMultipleDC(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 139 | DeclCtx = DC; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void Decl::setLexicalDeclContext(DeclContext *DC) { |
| 143 | if (DC == getLexicalDeclContext()) |
| 144 | return; |
| 145 | |
| 146 | if (isInSemaDC()) { |
Ted Kremenek | 94a3900 | 2009-12-01 00:07:10 +0000 | [diff] [blame] | 147 | MultipleDC *MDC = new (getASTContext()) MultipleDC(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 148 | MDC->SemanticDC = getDeclContext(); |
| 149 | MDC->LexicalDC = DC; |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 150 | DeclCtx = MDC; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 151 | } else { |
| 152 | getMultipleDC()->LexicalDC = DC; |
| 153 | } |
| 154 | } |
| 155 | |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 156 | bool Decl::isInAnonymousNamespace() const { |
| 157 | const DeclContext *DC = getDeclContext(); |
| 158 | do { |
| 159 | if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC)) |
| 160 | if (ND->isAnonymousNamespace()) |
| 161 | return true; |
| 162 | } while ((DC = DC->getParent())); |
| 163 | |
| 164 | return false; |
| 165 | } |
| 166 | |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 167 | TranslationUnitDecl *Decl::getTranslationUnitDecl() { |
Argyrios Kyrtzidis | 9b34669 | 2009-06-30 02:34:53 +0000 | [diff] [blame] | 168 | if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this)) |
| 169 | return TUD; |
| 170 | |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 171 | DeclContext *DC = getDeclContext(); |
| 172 | assert(DC && "This decl is not contained in a translation unit!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 174 | while (!DC->isTranslationUnit()) { |
| 175 | DC = DC->getParent(); |
| 176 | assert(DC && "This decl is not contained in a translation unit!"); |
| 177 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 179 | return cast<TranslationUnitDecl>(DC); |
| 180 | } |
| 181 | |
| 182 | ASTContext &Decl::getASTContext() const { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | return getTranslationUnitDecl()->getASTContext(); |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 186 | unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { |
| 187 | switch (DeclKind) { |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 188 | case Function: |
| 189 | case CXXMethod: |
| 190 | case CXXConstructor: |
| 191 | case CXXDestructor: |
| 192 | case CXXConversion: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 193 | case Typedef: |
| 194 | case EnumConstant: |
| 195 | case Var: |
| 196 | case ImplicitParam: |
| 197 | case ParmVar: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 198 | case NonTypeTemplateParm: |
| 199 | case ObjCMethod: |
| 200 | case ObjCContainer: |
| 201 | case ObjCCategory: |
| 202 | case ObjCInterface: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 203 | case ObjCProperty: |
| 204 | case ObjCCompatibleAlias: |
| 205 | return IDNS_Ordinary; |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 206 | |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 207 | case UsingShadow: |
| 208 | return 0; // we'll actually overwrite this later |
| 209 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 210 | case UnresolvedUsingValue: |
| 211 | case UnresolvedUsingTypename: |
| 212 | return IDNS_Ordinary | IDNS_Using; |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 213 | |
| 214 | case Using: |
| 215 | return IDNS_Using; |
| 216 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 217 | case ObjCProtocol: |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 218 | return IDNS_ObjCProtocol; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 219 | |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 220 | case ObjCImplementation: |
| 221 | return IDNS_ObjCImplementation; |
| 222 | |
| 223 | case ObjCCategoryImpl: |
| 224 | return IDNS_ObjCCategoryImpl; |
| 225 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 226 | case Field: |
| 227 | case ObjCAtDefsField: |
| 228 | case ObjCIvar: |
| 229 | return IDNS_Member; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 231 | case Record: |
| 232 | case CXXRecord: |
| 233 | case Enum: |
| 234 | case TemplateTypeParm: |
| 235 | return IDNS_Tag; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 236 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 237 | case Namespace: |
| 238 | case Template: |
| 239 | case FunctionTemplate: |
| 240 | case ClassTemplate: |
| 241 | case TemplateTemplateParm: |
Anders Carlsson | faf0e87 | 2009-03-28 23:02:53 +0000 | [diff] [blame] | 242 | case NamespaceAlias: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 243 | return IDNS_Tag | IDNS_Ordinary; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 245 | // Never have names. |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 246 | case Friend: |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 247 | case FriendTemplate: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 248 | case LinkageSpec: |
| 249 | case FileScopeAsm: |
| 250 | case StaticAssert: |
| 251 | case ObjCClass: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 252 | case ObjCPropertyImpl: |
| 253 | case ObjCForwardProtocol: |
| 254 | case Block: |
| 255 | case TranslationUnit: |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 257 | // Aren't looked up? |
| 258 | case UsingDirective: |
| 259 | case ClassTemplateSpecialization: |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 260 | case ClassTemplatePartialSpecialization: |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 261 | return 0; |
| 262 | } |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 263 | |
| 264 | return 0; |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 267 | void Decl::addAttr(Attr *NewAttr) { |
| 268 | Attr *&ExistingAttr = getASTContext().getDeclAttrs(this); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 269 | |
| 270 | NewAttr->setNext(ExistingAttr); |
| 271 | ExistingAttr = NewAttr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 273 | HasAttrs = true; |
| 274 | } |
| 275 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 276 | void Decl::invalidateAttrs() { |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 277 | if (!HasAttrs) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 279 | HasAttrs = false; |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 280 | getASTContext().eraseDeclAttrs(this); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 283 | const Attr *Decl::getAttrsImpl() const { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | assert(HasAttrs && "getAttrs() should verify this!"); |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 285 | return getASTContext().getDeclAttrs(this); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 288 | void Decl::swapAttrs(Decl *RHS) { |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 289 | bool HasLHSAttr = this->HasAttrs; |
| 290 | bool HasRHSAttr = RHS->HasAttrs; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 292 | // Usually, neither decl has attrs, nothing to do. |
| 293 | if (!HasLHSAttr && !HasRHSAttr) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 294 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 295 | // If 'this' has no attrs, swap the other way. |
| 296 | if (!HasLHSAttr) |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 297 | return RHS->swapAttrs(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 299 | ASTContext &Context = getASTContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 300 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 301 | // Handle the case when both decls have attrs. |
| 302 | if (HasRHSAttr) { |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 303 | std::swap(Context.getDeclAttrs(this), Context.getDeclAttrs(RHS)); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 304 | return; |
| 305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 306 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 307 | // Otherwise, LHS has an attr and RHS doesn't. |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 308 | Context.getDeclAttrs(RHS) = Context.getDeclAttrs(this); |
| 309 | Context.eraseDeclAttrs(this); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 310 | this->HasAttrs = false; |
| 311 | RHS->HasAttrs = true; |
| 312 | } |
| 313 | |
| 314 | |
Chris Lattner | cc58147 | 2009-03-04 06:05:19 +0000 | [diff] [blame] | 315 | void Decl::Destroy(ASTContext &C) { |
| 316 | // Free attributes for this decl. |
| 317 | if (HasAttrs) { |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 318 | C.getDeclAttrs(this)->Destroy(C); |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 319 | invalidateAttrs(); |
Chris Lattner | cc58147 | 2009-03-04 06:05:19 +0000 | [diff] [blame] | 320 | HasAttrs = false; |
| 321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | a0fc55f | 2009-01-13 19:47:12 +0000 | [diff] [blame] | 323 | #if 0 |
Douglas Gregor | 00ad0ef | 2009-01-20 04:25:11 +0000 | [diff] [blame] | 324 | // FIXME: Once ownership is fully understood, we can enable this code |
| 325 | if (DeclContext *DC = dyn_cast<DeclContext>(this)) |
| 326 | DC->decls_begin()->Destroy(C); |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 327 | |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 328 | // Observe the unrolled recursion. By setting N->NextDeclInContext = 0x0 |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 329 | // within the loop, only the Destroy method for the first Decl |
| 330 | // will deallocate all of the Decls in a chain. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 332 | Decl* N = getNextDeclInContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 333 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 334 | while (N) { |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 335 | Decl* Tmp = N->getNextDeclInContext(); |
| 336 | N->NextDeclInContext = 0; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 337 | N->Destroy(C); |
| 338 | N = Tmp; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | } |
Douglas Gregor | a0fc55f | 2009-01-13 19:47:12 +0000 | [diff] [blame] | 340 | |
Ted Kremenek | 94a3900 | 2009-12-01 00:07:10 +0000 | [diff] [blame] | 341 | if (isOutOfSemaDC()) |
| 342 | delete (C) getMultipleDC(); |
| 343 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 344 | this->~Decl(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 345 | C.Deallocate((void *)this); |
Ted Kremenek | 94a3900 | 2009-12-01 00:07:10 +0000 | [diff] [blame] | 346 | #endif |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 349 | Decl *Decl::castFromDeclContext (const DeclContext *D) { |
Argyrios Kyrtzidis | 3d7641e | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 350 | Decl::Kind DK = D->getDeclKind(); |
| 351 | switch(DK) { |
| 352 | #define DECL_CONTEXT(Name) \ |
| 353 | case Decl::Name: \ |
| 354 | return static_cast<Name##Decl*>(const_cast<DeclContext*>(D)); |
| 355 | #define DECL_CONTEXT_BASE(Name) |
| 356 | #include "clang/AST/DeclNodes.def" |
| 357 | default: |
| 358 | #define DECL_CONTEXT_BASE(Name) \ |
| 359 | if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \ |
| 360 | return static_cast<Name##Decl*>(const_cast<DeclContext*>(D)); |
| 361 | #include "clang/AST/DeclNodes.def" |
| 362 | assert(false && "a decl that inherits DeclContext isn't handled"); |
| 363 | return 0; |
| 364 | } |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | DeclContext *Decl::castToDeclContext(const Decl *D) { |
Argyrios Kyrtzidis | 3d7641e | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 368 | Decl::Kind DK = D->getKind(); |
| 369 | switch(DK) { |
| 370 | #define DECL_CONTEXT(Name) \ |
| 371 | case Decl::Name: \ |
| 372 | return static_cast<Name##Decl*>(const_cast<Decl*>(D)); |
| 373 | #define DECL_CONTEXT_BASE(Name) |
| 374 | #include "clang/AST/DeclNodes.def" |
| 375 | default: |
| 376 | #define DECL_CONTEXT_BASE(Name) \ |
| 377 | if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \ |
| 378 | return static_cast<Name##Decl*>(const_cast<Decl*>(D)); |
| 379 | #include "clang/AST/DeclNodes.def" |
| 380 | assert(false && "a decl that inherits DeclContext isn't handled"); |
| 381 | return 0; |
| 382 | } |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 385 | CompoundStmt* Decl::getCompoundBody() const { |
| 386 | return dyn_cast_or_null<CompoundStmt>(getBody()); |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 389 | SourceLocation Decl::getBodyRBrace() const { |
| 390 | Stmt *Body = getBody(); |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 391 | if (!Body) |
| 392 | return SourceLocation(); |
| 393 | if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Body)) |
| 394 | return CS->getRBracLoc(); |
| 395 | assert(isa<CXXTryStmt>(Body) && |
| 396 | "Body can only be CompoundStmt or CXXTryStmt"); |
| 397 | return cast<CXXTryStmt>(Body)->getSourceRange().getEnd(); |
| 398 | } |
| 399 | |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 400 | #ifndef NDEBUG |
| 401 | void Decl::CheckAccessDeclContext() const { |
Anders Carlsson | 35eda44 | 2009-08-29 20:47:47 +0000 | [diff] [blame] | 402 | // If the decl is the toplevel translation unit or if we're not in a |
| 403 | // record decl context, we don't need to check anything. |
| 404 | if (isa<TranslationUnitDecl>(this) || |
| 405 | !isa<CXXRecordDecl>(getDeclContext())) |
| 406 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 407 | |
| 408 | assert(Access != AS_none && |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 409 | "Access specifier is AS_none inside a record decl"); |
| 410 | } |
| 411 | |
| 412 | #endif |
| 413 | |
Eli Friedman | 56d2937 | 2008-06-07 16:52:53 +0000 | [diff] [blame] | 414 | //===----------------------------------------------------------------------===// |
| 415 | // DeclContext Implementation |
| 416 | //===----------------------------------------------------------------------===// |
| 417 | |
Argyrios Kyrtzidis | 3d7641e | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 418 | bool DeclContext::classof(const Decl *D) { |
| 419 | switch (D->getKind()) { |
| 420 | #define DECL_CONTEXT(Name) case Decl::Name: |
| 421 | #define DECL_CONTEXT_BASE(Name) |
| 422 | #include "clang/AST/DeclNodes.def" |
| 423 | return true; |
| 424 | default: |
| 425 | #define DECL_CONTEXT_BASE(Name) \ |
| 426 | if (D->getKind() >= Decl::Name##First && \ |
| 427 | D->getKind() <= Decl::Name##Last) \ |
| 428 | return true; |
| 429 | #include "clang/AST/DeclNodes.def" |
| 430 | return false; |
| 431 | } |
| 432 | } |
| 433 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 434 | DeclContext::~DeclContext() { |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 435 | delete static_cast<StoredDeclsMap*>(LookupPtr); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void DeclContext::DestroyDecls(ASTContext &C) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 439 | for (decl_iterator D = decls_begin(); D != decls_end(); ) |
Douglas Gregor | 00ad0ef | 2009-01-20 04:25:11 +0000 | [diff] [blame] | 440 | (*D++)->Destroy(C); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Douglas Gregor | e942bbe | 2009-09-10 16:57:35 +0000 | [diff] [blame] | 443 | /// \brief Find the parent context of this context that will be |
| 444 | /// used for unqualified name lookup. |
| 445 | /// |
| 446 | /// Generally, the parent lookup context is the semantic context. However, for |
| 447 | /// a friend function the parent lookup context is the lexical context, which |
| 448 | /// is the class in which the friend is declared. |
| 449 | DeclContext *DeclContext::getLookupParent() { |
| 450 | // FIXME: Find a better way to identify friends |
| 451 | if (isa<FunctionDecl>(this)) |
| 452 | if (getParent()->getLookupContext()->isFileContext() && |
| 453 | getLexicalParent()->getLookupContext()->isRecord()) |
| 454 | return getLexicalParent(); |
| 455 | |
| 456 | return getParent(); |
| 457 | } |
| 458 | |
Douglas Gregor | bc22163 | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 459 | bool DeclContext::isDependentContext() const { |
| 460 | if (isFileContext()) |
| 461 | return false; |
| 462 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 463 | if (isa<ClassTemplatePartialSpecializationDecl>(this)) |
| 464 | return true; |
| 465 | |
Douglas Gregor | bc22163 | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 466 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this)) |
| 467 | if (Record->getDescribedClassTemplate()) |
| 468 | return true; |
| 469 | |
| 470 | if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(this)) |
| 471 | if (Function->getDescribedFunctionTemplate()) |
| 472 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 473 | |
Douglas Gregor | bc22163 | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 474 | return getParent() && getParent()->isDependentContext(); |
| 475 | } |
| 476 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 477 | bool DeclContext::isTransparentContext() const { |
| 478 | if (DeclKind == Decl::Enum) |
| 479 | return true; // FIXME: Check for C++0x scoped enums |
| 480 | else if (DeclKind == Decl::LinkageSpec) |
| 481 | return true; |
Douglas Gregor | 6510079 | 2009-02-26 00:02:51 +0000 | [diff] [blame] | 482 | else if (DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast) |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 483 | return cast<RecordDecl>(this)->isAnonymousStructOrUnion(); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 484 | else if (DeclKind == Decl::Namespace) |
| 485 | return false; // FIXME: Check for C++0x inline namespaces |
| 486 | |
| 487 | return false; |
| 488 | } |
| 489 | |
Douglas Gregor | 6dd38da | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 490 | bool DeclContext::Encloses(DeclContext *DC) { |
| 491 | if (getPrimaryContext() != this) |
| 492 | return getPrimaryContext()->Encloses(DC); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | |
Douglas Gregor | 6dd38da | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 494 | for (; DC; DC = DC->getParent()) |
| 495 | if (DC->getPrimaryContext() == this) |
| 496 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | return false; |
Douglas Gregor | 6dd38da | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 500 | DeclContext *DeclContext::getPrimaryContext() { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 501 | switch (DeclKind) { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 502 | case Decl::TranslationUnit: |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 503 | case Decl::LinkageSpec: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | case Decl::Block: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 505 | // There is only one DeclContext for these entities. |
| 506 | return this; |
| 507 | |
| 508 | case Decl::Namespace: |
| 509 | // The original namespace is our primary context. |
| 510 | return static_cast<NamespaceDecl*>(this)->getOriginalNamespace(); |
| 511 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 512 | case Decl::ObjCMethod: |
| 513 | return this; |
| 514 | |
| 515 | case Decl::ObjCInterface: |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 516 | case Decl::ObjCProtocol: |
| 517 | case Decl::ObjCCategory: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 518 | // FIXME: Can Objective-C interfaces be forward-declared? |
| 519 | return this; |
| 520 | |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 521 | case Decl::ObjCImplementation: |
| 522 | case Decl::ObjCCategoryImpl: |
| 523 | return this; |
| 524 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 525 | default: |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 526 | if (DeclKind >= Decl::TagFirst && DeclKind <= Decl::TagLast) { |
| 527 | // If this is a tag type that has a definition or is currently |
| 528 | // being defined, that definition is our primary context. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 529 | if (const TagType *TagT =cast<TagDecl>(this)->TypeForDecl->getAs<TagType>()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | if (TagT->isBeingDefined() || |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 531 | (TagT->getDecl() && TagT->getDecl()->isDefinition())) |
| 532 | return TagT->getDecl(); |
| 533 | return this; |
| 534 | } |
| 535 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 536 | assert(DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast && |
| 537 | "Unknown DeclContext kind"); |
| 538 | return this; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | DeclContext *DeclContext::getNextContext() { |
| 543 | switch (DeclKind) { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 544 | case Decl::Namespace: |
| 545 | // Return the next namespace |
| 546 | return static_cast<NamespaceDecl*>(this)->getNextNamespace(); |
| 547 | |
| 548 | default: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | } |
| 552 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 553 | /// \brief Load the declarations within this lexical storage from an |
| 554 | /// external source. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | void |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 556 | DeclContext::LoadLexicalDeclsFromExternalStorage() const { |
| 557 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 558 | assert(hasExternalLexicalStorage() && Source && "No external storage?"); |
| 559 | |
Eli Friedman | b0156ea | 2009-04-27 23:43:36 +0000 | [diff] [blame] | 560 | llvm::SmallVector<uint32_t, 64> Decls; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 561 | if (Source->ReadDeclsLexicallyInContext(const_cast<DeclContext *>(this), |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 562 | Decls)) |
| 563 | return; |
| 564 | |
| 565 | // There is no longer any lexical storage in this context |
| 566 | ExternalLexicalStorage = false; |
| 567 | |
| 568 | if (Decls.empty()) |
| 569 | return; |
| 570 | |
| 571 | // Resolve all of the declaration IDs into declarations, building up |
| 572 | // a chain of declarations via the Decl::NextDeclInContext field. |
| 573 | Decl *FirstNewDecl = 0; |
| 574 | Decl *PrevDecl = 0; |
| 575 | for (unsigned I = 0, N = Decls.size(); I != N; ++I) { |
| 576 | Decl *D = Source->GetDecl(Decls[I]); |
| 577 | if (PrevDecl) |
| 578 | PrevDecl->NextDeclInContext = D; |
| 579 | else |
| 580 | FirstNewDecl = D; |
| 581 | |
| 582 | PrevDecl = D; |
| 583 | } |
| 584 | |
| 585 | // Splice the newly-read declarations into the beginning of the list |
| 586 | // of declarations. |
| 587 | PrevDecl->NextDeclInContext = FirstDecl; |
| 588 | FirstDecl = FirstNewDecl; |
| 589 | if (!LastDecl) |
| 590 | LastDecl = PrevDecl; |
| 591 | } |
| 592 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | void |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 594 | DeclContext::LoadVisibleDeclsFromExternalStorage() const { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 595 | DeclContext *This = const_cast<DeclContext *>(this); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 596 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 597 | assert(hasExternalVisibleStorage() && Source && "No external storage?"); |
| 598 | |
| 599 | llvm::SmallVector<VisibleDeclaration, 64> Decls; |
| 600 | if (Source->ReadDeclsVisibleInContext(This, Decls)) |
| 601 | return; |
| 602 | |
| 603 | // There is no longer any visible storage in this context |
| 604 | ExternalVisibleStorage = false; |
| 605 | |
| 606 | // Load the declaration IDs for all of the names visible in this |
| 607 | // context. |
| 608 | assert(!LookupPtr && "Have a lookup map before de-serialization?"); |
| 609 | StoredDeclsMap *Map = new StoredDeclsMap; |
| 610 | LookupPtr = Map; |
| 611 | for (unsigned I = 0, N = Decls.size(); I != N; ++I) { |
| 612 | (*Map)[Decls[I].Name].setFromDeclIDs(Decls[I].Declarations); |
| 613 | } |
| 614 | } |
| 615 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 616 | DeclContext::decl_iterator DeclContext::decls_begin() const { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 617 | if (hasExternalLexicalStorage()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 618 | LoadLexicalDeclsFromExternalStorage(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 619 | |
| 620 | // FIXME: Check whether we need to load some declarations from |
| 621 | // external storage. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 622 | return decl_iterator(FirstDecl); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 625 | DeclContext::decl_iterator DeclContext::decls_end() const { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 626 | if (hasExternalLexicalStorage()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 627 | LoadLexicalDeclsFromExternalStorage(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 628 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 629 | return decl_iterator(); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 632 | bool DeclContext::decls_empty() const { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 633 | if (hasExternalLexicalStorage()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 634 | LoadLexicalDeclsFromExternalStorage(); |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 635 | |
| 636 | return !FirstDecl; |
| 637 | } |
| 638 | |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame^] | 639 | void DeclContext::removeDecl(Decl *D) { |
| 640 | assert(D->getLexicalDeclContext() == this && |
| 641 | "decl being removed from non-lexical context"); |
| 642 | assert((D->NextDeclInContext || D == LastDecl) && |
| 643 | "decl is not in decls list"); |
| 644 | |
| 645 | // Remove D from the decl chain. This is O(n) but hopefully rare. |
| 646 | if (D == FirstDecl) { |
| 647 | if (D == LastDecl) |
| 648 | FirstDecl = LastDecl = 0; |
| 649 | else |
| 650 | FirstDecl = D->NextDeclInContext; |
| 651 | } else { |
| 652 | for (Decl *I = FirstDecl; true; I = I->NextDeclInContext) { |
| 653 | assert(I && "decl not found in linked list"); |
| 654 | if (I->NextDeclInContext == D) { |
| 655 | I->NextDeclInContext = D->NextDeclInContext; |
| 656 | if (D == LastDecl) LastDecl = I; |
| 657 | break; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | // Mark that D is no longer in the decl chain. |
| 663 | D->NextDeclInContext = 0; |
| 664 | |
| 665 | // Remove D from the lookup table if necessary. |
| 666 | if (isa<NamedDecl>(D)) { |
| 667 | NamedDecl *ND = cast<NamedDecl>(D); |
| 668 | |
| 669 | void *OpaqueMap = getPrimaryContext()->LookupPtr; |
| 670 | if (!OpaqueMap) return; |
| 671 | |
| 672 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(OpaqueMap); |
| 673 | StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName()); |
| 674 | assert(Pos != Map->end() && "no lookup entry for decl"); |
| 675 | Pos->second.remove(ND); |
| 676 | } |
| 677 | } |
| 678 | |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 679 | void DeclContext::addHiddenDecl(Decl *D) { |
Chris Lattner | 7f0be13 | 2009-02-20 00:56:18 +0000 | [diff] [blame] | 680 | assert(D->getLexicalDeclContext() == this && |
| 681 | "Decl inserted into wrong lexical context"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 682 | assert(!D->getNextDeclInContext() && D != LastDecl && |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 683 | "Decl already inserted into a DeclContext"); |
| 684 | |
| 685 | if (FirstDecl) { |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 686 | LastDecl->NextDeclInContext = D; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 687 | LastDecl = D; |
| 688 | } else { |
| 689 | FirstDecl = LastDecl = D; |
| 690 | } |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | void DeclContext::addDecl(Decl *D) { |
| 694 | addHiddenDecl(D); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 695 | |
| 696 | if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 697 | ND->getDeclContext()->makeDeclVisibleInContext(ND); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 700 | /// buildLookup - Build the lookup data structure with all of the |
| 701 | /// declarations in DCtx (and any other contexts linked to it or |
| 702 | /// transparent contexts nested within it). |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 703 | void DeclContext::buildLookup(DeclContext *DCtx) { |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 704 | for (; DCtx; DCtx = DCtx->getNextContext()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | for (decl_iterator D = DCtx->decls_begin(), |
| 706 | DEnd = DCtx->decls_end(); |
Douglas Gregor | 4f3b8f8 | 2009-01-06 07:17:58 +0000 | [diff] [blame] | 707 | D != DEnd; ++D) { |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 708 | // Insert this declaration into the lookup structure, but only |
| 709 | // if it's semantically in its decl context. During non-lazy |
| 710 | // lookup building, this is implicitly enforced by addDecl. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 711 | if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 712 | if (D->getDeclContext() == DCtx) |
| 713 | makeDeclVisibleInContextImpl(ND); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 714 | |
Ted Kremenek | c32b1d8 | 2009-11-17 22:58:30 +0000 | [diff] [blame] | 715 | // Insert any forward-declared Objective-C interfaces into the lookup |
| 716 | // data structure. |
| 717 | if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(*D)) |
| 718 | for (ObjCClassDecl::iterator I = Class->begin(), IEnd = Class->end(); |
| 719 | I != IEnd; ++I) |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 720 | makeDeclVisibleInContextImpl(I->getInterface()); |
Ted Kremenek | c32b1d8 | 2009-11-17 22:58:30 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 722 | // If this declaration is itself a transparent declaration context, |
| 723 | // add its members (recursively). |
| 724 | if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D)) |
| 725 | if (InnerCtx->isTransparentContext()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 726 | buildLookup(InnerCtx->getPrimaryContext()); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | DeclContext::lookup_result |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 732 | DeclContext::lookup(DeclarationName Name) { |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 733 | DeclContext *PrimaryContext = getPrimaryContext(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 734 | if (PrimaryContext != this) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 735 | return PrimaryContext->lookup(Name); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 736 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 737 | if (hasExternalVisibleStorage()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 738 | LoadVisibleDeclsFromExternalStorage(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 739 | |
Douglas Gregor | 3fc749d | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 740 | /// If there is no lookup data structure, build one now by walking |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 741 | /// all of the linked DeclContexts (in declaration order!) and |
| 742 | /// inserting their values. |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 743 | if (!LookupPtr) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 744 | buildLookup(this); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 746 | if (!LookupPtr) |
Chris Lattner | 9194250 | 2009-02-20 00:55:03 +0000 | [diff] [blame] | 747 | return lookup_result(0, 0); |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 748 | } |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 749 | |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 750 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(LookupPtr); |
| 751 | StoredDeclsMap::iterator Pos = Map->find(Name); |
| 752 | if (Pos == Map->end()) |
| 753 | return lookup_result(0, 0); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 754 | return Pos->second.getLookupResult(getParentASTContext()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | DeclContext::lookup_const_result |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 758 | DeclContext::lookup(DeclarationName Name) const { |
| 759 | return const_cast<DeclContext*>(this)->lookup(Name); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 762 | DeclContext *DeclContext::getLookupContext() { |
| 763 | DeclContext *Ctx = this; |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 764 | // Skip through transparent contexts. |
Douglas Gregor | ce35607 | 2009-01-06 23:51:29 +0000 | [diff] [blame] | 765 | while (Ctx->isTransparentContext()) |
| 766 | Ctx = Ctx->getParent(); |
| 767 | return Ctx; |
| 768 | } |
| 769 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 770 | DeclContext *DeclContext::getEnclosingNamespaceContext() { |
| 771 | DeclContext *Ctx = this; |
| 772 | // Skip through non-namespace, non-translation-unit contexts. |
| 773 | while (!Ctx->isFileContext() || Ctx->isTransparentContext()) |
| 774 | Ctx = Ctx->getParent(); |
| 775 | return Ctx->getPrimaryContext(); |
| 776 | } |
| 777 | |
John McCall | ab88d97 | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 778 | void DeclContext::makeDeclVisibleInContext(NamedDecl *D, bool Recoverable) { |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 779 | // FIXME: This feels like a hack. Should DeclarationName support |
| 780 | // template-ids, or is there a better way to keep specializations |
| 781 | // from being visible? |
| 782 | if (isa<ClassTemplateSpecializationDecl>(D)) |
| 783 | return; |
Eli Friedman | 6bc2013 | 2009-12-08 05:40:03 +0000 | [diff] [blame] | 784 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 785 | if (FD->isFunctionTemplateSpecialization()) |
| 786 | return; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 787 | |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 788 | DeclContext *PrimaryContext = getPrimaryContext(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 789 | if (PrimaryContext != this) { |
John McCall | ab88d97 | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 790 | PrimaryContext->makeDeclVisibleInContext(D, Recoverable); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 791 | return; |
| 792 | } |
| 793 | |
| 794 | // If we already have a lookup data structure, perform the insertion |
| 795 | // into it. Otherwise, be lazy and don't build that structure until |
| 796 | // someone asks for it. |
John McCall | ab88d97 | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 797 | if (LookupPtr || !Recoverable) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 798 | makeDeclVisibleInContextImpl(D); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 800 | // If we are a transparent context, insert into our parent context, |
| 801 | // too. This operation is recursive. |
| 802 | if (isTransparentContext()) |
John McCall | ab88d97 | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 803 | getParent()->makeDeclVisibleInContext(D, Recoverable); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 806 | void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 807 | // Skip unnamed declarations. |
| 808 | if (!D->getDeclName()) |
| 809 | return; |
| 810 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 811 | // FIXME: This feels like a hack. Should DeclarationName support |
| 812 | // template-ids, or is there a better way to keep specializations |
| 813 | // from being visible? |
| 814 | if (isa<ClassTemplateSpecializationDecl>(D)) |
| 815 | return; |
| 816 | |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 817 | if (!LookupPtr) |
| 818 | LookupPtr = new StoredDeclsMap; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 819 | |
| 820 | // Insert this declaration into the map. |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 821 | StoredDeclsMap &Map = *static_cast<StoredDeclsMap*>(LookupPtr); |
Chris Lattner | 67762a3 | 2009-02-20 01:44:05 +0000 | [diff] [blame] | 822 | StoredDeclsList &DeclNameEntries = Map[D->getDeclName()]; |
| 823 | if (DeclNameEntries.isNull()) { |
| 824 | DeclNameEntries.setOnlyValue(D); |
Chris Lattner | bd6c800 | 2009-02-19 07:00:44 +0000 | [diff] [blame] | 825 | return; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 826 | } |
Chris Lattner | 9194250 | 2009-02-20 00:55:03 +0000 | [diff] [blame] | 827 | |
Chris Lattner | bdc3d00 | 2009-02-20 01:10:07 +0000 | [diff] [blame] | 828 | // If it is possible that this is a redeclaration, check to see if there is |
| 829 | // already a decl for which declarationReplaces returns true. If there is |
| 830 | // one, just replace it and return. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 831 | if (DeclNameEntries.HandleRedeclaration(getParentASTContext(), D)) |
Chris Lattner | 67762a3 | 2009-02-20 01:44:05 +0000 | [diff] [blame] | 832 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Chris Lattner | bd6c800 | 2009-02-19 07:00:44 +0000 | [diff] [blame] | 834 | // Put this declaration into the appropriate slot. |
Chris Lattner | 67762a3 | 2009-02-20 01:44:05 +0000 | [diff] [blame] | 835 | DeclNameEntries.AddSubsequentDecl(D); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 836 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 837 | |
| 838 | /// Returns iterator range [First, Last) of UsingDirectiveDecls stored within |
| 839 | /// this context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | DeclContext::udir_iterator_range |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 841 | DeclContext::getUsingDirectives() const { |
| 842 | lookup_const_result Result = lookup(UsingDirectiveDecl::getName()); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 843 | return udir_iterator_range(reinterpret_cast<udir_iterator>(Result.first), |
| 844 | reinterpret_cast<udir_iterator>(Result.second)); |
| 845 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 846 | |
| 847 | void StoredDeclsList::materializeDecls(ASTContext &Context) { |
| 848 | if (isNull()) |
| 849 | return; |
| 850 | |
| 851 | switch ((DataKind)(Data & 0x03)) { |
| 852 | case DK_Decl: |
| 853 | case DK_Decl_Vector: |
| 854 | break; |
| 855 | |
| 856 | case DK_DeclID: { |
| 857 | // Resolve this declaration ID to an actual declaration by |
| 858 | // querying the external AST source. |
| 859 | unsigned DeclID = Data >> 2; |
| 860 | |
| 861 | ExternalASTSource *Source = Context.getExternalSource(); |
| 862 | assert(Source && "No external AST source available!"); |
| 863 | |
| 864 | Data = reinterpret_cast<uintptr_t>(Source->GetDecl(DeclID)); |
| 865 | break; |
| 866 | } |
| 867 | |
| 868 | case DK_ID_Vector: { |
| 869 | // We have a vector of declaration IDs. Resolve all of them to |
| 870 | // actual declarations. |
| 871 | VectorTy &Vector = *getAsVector(); |
| 872 | ExternalASTSource *Source = Context.getExternalSource(); |
| 873 | assert(Source && "No external AST source available!"); |
| 874 | |
| 875 | for (unsigned I = 0, N = Vector.size(); I != N; ++I) |
| 876 | Vector[I] = reinterpret_cast<uintptr_t>(Source->GetDecl(Vector[I])); |
| 877 | |
| 878 | Data = (Data & ~0x03) | DK_Decl_Vector; |
| 879 | break; |
| 880 | } |
| 881 | } |
| 882 | } |