blob: 12436c5c4fe73bdb9ebc35357ae9ccb697a4b8d3 [file] [log] [blame]
Sebastian Redl904c9c82010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner698f9252009-04-27 05:27:42 +00002//
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//
Sebastian Redlc43b54c2010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner698f9252009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redl6ab7cd82010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Douglas Gregor0f753232011-12-22 01:48:48 +000017#include "clang/Sema/IdentifierResolver.h"
18#include "clang/Sema/Sema.h"
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000019#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner698f9252009-04-27 05:27:42 +000020#include "clang/AST/ASTConsumer.h"
21#include "clang/AST/ASTContext.h"
22#include "clang/AST/DeclVisitor.h"
23#include "clang/AST/DeclGroup.h"
Chris Lattner6ad9ac02010-05-07 21:43:38 +000024#include "clang/AST/DeclCXX.h"
25#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000026#include "clang/AST/Expr.h"
27using namespace clang;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000028using namespace clang::serialization;
Chris Lattner698f9252009-04-27 05:27:42 +000029
30//===----------------------------------------------------------------------===//
31// Declaration deserialization
32//===----------------------------------------------------------------------===//
33
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000034namespace clang {
Sebastian Redld527cc02010-08-18 23:56:48 +000035 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redlc43b54c2010-08-18 23:56:43 +000036 ASTReader &Reader;
Douglas Gregor1a4761e2011-11-30 23:21:26 +000037 ModuleFile &F;
Sebastian Redl577d4792010-07-22 22:43:28 +000038 llvm::BitstreamCursor &Cursor;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000039 const DeclID ThisDeclID;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +000040 const unsigned RawLocation;
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000041 typedef ASTReader::RecordData RecordData;
42 const RecordData &Record;
Chris Lattner698f9252009-04-27 05:27:42 +000043 unsigned &Idx;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000044 TypeID TypeIDForTypeDecl;
Douglas Gregor67da6f62011-03-05 01:35:54 +000045
46 DeclID DeclContextIDForTemplateParmDecl;
47 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner698f9252009-04-27 05:27:42 +000048
Sebastian Redl577d4792010-07-22 22:43:28 +000049 uint64_t GetCurrentCursorOffset();
Douglas Gregor409448c2011-07-21 22:35:25 +000050
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000051 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000052 return Reader.ReadSourceLocation(F, R, I);
53 }
Douglas Gregor409448c2011-07-21 22:35:25 +000054
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000055 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000056 return Reader.ReadSourceRange(F, R, I);
57 }
Douglas Gregor409448c2011-07-21 22:35:25 +000058
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000059 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000060 return Reader.GetTypeSourceInfo(F, R, I);
61 }
Douglas Gregor409448c2011-07-21 22:35:25 +000062
63 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
64 return Reader.ReadDeclID(F, R, I);
65 }
66
67 Decl *ReadDecl(const RecordData &R, unsigned &I) {
68 return Reader.ReadDecl(F, R, I);
69 }
70
71 template<typename T>
72 T *ReadDeclAs(const RecordData &R, unsigned &I) {
73 return Reader.ReadDeclAs<T>(F, R, I);
74 }
75
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000076 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000077 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000078 Reader.ReadQualifierInfo(F, Info, R, I);
79 }
Douglas Gregor409448c2011-07-21 22:35:25 +000080
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000081 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000082 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000083 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
84 }
Douglas Gregor409448c2011-07-21 22:35:25 +000085
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000086 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000087 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000088 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
89 }
Sebastian Redl577d4792010-07-22 22:43:28 +000090
Douglas Gregorecc2c092011-12-01 22:20:10 +000091 serialization::SubmoduleID readSubmoduleID(const RecordData &R,
92 unsigned &I) {
93 if (I >= R.size())
94 return 0;
95
96 return Reader.getGlobalSubmoduleID(F, R[I++]);
97 }
98
Douglas Gregor15de72c2011-12-02 23:23:56 +000099 Module *readModule(const RecordData &R, unsigned &I) {
100 return Reader.getSubmodule(readSubmoduleID(R, I));
101 }
102
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000103 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
104 const RecordData &R, unsigned &I);
105
106 void InitializeCXXDefinitionData(CXXRecordDecl *D,
107 CXXRecordDecl *DefinitionDecl,
108 const RecordData &Record, unsigned &Idx);
Douglas Gregor0f753232011-12-22 01:48:48 +0000109
110 /// \brief RAII class used to capture the first ID within a redeclaration
111 /// chain and to introduce it into the list of pending redeclaration chains
112 /// on destruction.
113 ///
114 /// The caller can choose not to introduce this ID into the redeclaration
115 /// chain by calling \c suppress().
116 class RedeclarableResult {
117 ASTReader &Reader;
118 GlobalDeclID FirstID;
119 mutable bool Owning;
120
121 RedeclarableResult &operator=(RedeclarableResult&); // DO NOT IMPLEMENT
122
123 public:
124 RedeclarableResult(ASTReader &Reader, GlobalDeclID FirstID)
125 : Reader(Reader), FirstID(FirstID), Owning(true) { }
126
127 RedeclarableResult(const RedeclarableResult &Other)
128 : Reader(Other.Reader), FirstID(Other.FirstID), Owning(Other.Owning)
129 {
130 Other.Owning = false;
131 }
132
133 ~RedeclarableResult() {
Douglas Gregorbf1739c2011-12-22 22:05:07 +0000134 // FIXME: We want to suppress this when the declaration is local to
135 // a function, since there's no reason to search other AST files
136 // for redeclarations (they can't exist). However, this is hard to
137 // do locally because the declaration hasn't necessarily loaded its
138 // declaration context yet. Also, local externs still have the function
139 // as their (semantic) declaration context, which is wrong and would
140 // break this optimize.
141
Douglas Gregor0f753232011-12-22 01:48:48 +0000142 if (FirstID && Owning && Reader.PendingDeclChainsKnown.insert(FirstID))
143 Reader.PendingDeclChains.push_back(FirstID);
144 }
145
146 /// \brief Retrieve the first ID.
147 GlobalDeclID getFirstID() const { return FirstID; }
148
149 /// \brief Do not introduce this declaration ID into the set of pending
150 /// declaration chains.
151 void suppress() {
152 Owning = false;
153 }
154 };
155
156 /// \brief Class used to capture the result of searching for an existing
157 /// declaration of a specific kind and name, along with the ability
158 /// to update the place where this result was found (the declaration
159 /// chain hanging off an identifier or the DeclContext we searched in)
160 /// if requested.
161 class FindExistingResult {
162 ASTReader &Reader;
163 NamedDecl *New;
164 NamedDecl *Existing;
165 mutable bool AddResult;
166
167 FindExistingResult &operator=(FindExistingResult&); // DO NOT IMPLEMENT
168
169 public:
170 FindExistingResult(ASTReader &Reader)
171 : Reader(Reader), New(0), Existing(0), AddResult(false) { }
172
173 FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing)
174 : Reader(Reader), New(New), Existing(Existing), AddResult(true) { }
175
176 FindExistingResult(const FindExistingResult &Other)
177 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
178 AddResult(Other.AddResult)
179 {
180 Other.AddResult = false;
181 }
182
183 ~FindExistingResult();
184
185 operator NamedDecl*() const { return Existing; }
186
187 template<typename T>
188 operator T*() const { return dyn_cast_or_null<T>(Existing); }
189 };
190
191 FindExistingResult findExisting(NamedDecl *D);
192
Chris Lattner698f9252009-04-27 05:27:42 +0000193 public:
Douglas Gregor1a4761e2011-11-30 23:21:26 +0000194 ASTDeclReader(ASTReader &Reader, ModuleFile &F,
Sebastian Redlc3632732010-10-05 15:59:54 +0000195 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000196 unsigned RawLocation,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000197 const RecordData &Record, unsigned &Idx)
Sebastian Redlc3632732010-10-05 15:59:54 +0000198 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000199 RawLocation(RawLocation), Record(Record), Idx(Idx),
200 TypeIDForTypeDecl(0) { }
Chris Lattner698f9252009-04-27 05:27:42 +0000201
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +0000202 static void attachPreviousDecl(Decl *D, Decl *previous);
Douglas Gregora1be2782011-12-17 23:38:30 +0000203 static void attachLatestDecl(Decl *D, Decl *latest);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +0000204
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000205 void Visit(Decl *D);
206
Douglas Gregor1a4761e2011-11-30 23:21:26 +0000207 void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redlf79a7192011-04-29 08:19:30 +0000208 const RecordData &Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000209
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +0000210 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
211 ObjCCategoryDecl *Next) {
212 Cat->NextClassCategory = Next;
213 }
214
Chris Lattner698f9252009-04-27 05:27:42 +0000215 void VisitDecl(Decl *D);
216 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
217 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000218 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregor0cef4832010-02-21 18:22:14 +0000219 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000220 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
221 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000222 void VisitTypeDecl(TypeDecl *TD);
Douglas Gregor0f456822011-12-19 14:40:25 +0000223 void VisitTypedefNameDecl(TypedefNameDecl *TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000224 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000225 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000226 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000227 void VisitTagDecl(TagDecl *TD);
228 void VisitEnumDecl(EnumDecl *ED);
229 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000230 void VisitCXXRecordDecl(CXXRecordDecl *D);
231 void VisitClassTemplateSpecializationDecl(
232 ClassTemplateSpecializationDecl *D);
233 void VisitClassTemplatePartialSpecializationDecl(
234 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redl14c36332011-08-31 13:59:56 +0000235 void VisitClassScopeFunctionSpecializationDecl(
236 ClassScopeFunctionSpecializationDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000237 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000238 void VisitValueDecl(ValueDecl *VD);
239 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000240 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000241 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +0000242 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000243 void VisitCXXMethodDecl(CXXMethodDecl *D);
244 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
245 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
246 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000247 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet87c2e122010-11-21 06:08:52 +0000248 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000249 void VisitVarDecl(VarDecl *VD);
250 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
251 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000252 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
253 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000254 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000255 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000256 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000257 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000258 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000259 void VisitUsingDecl(UsingDecl *D);
260 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000261 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000262 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregor15de72c2011-12-02 23:23:56 +0000263 void VisitImportDecl(ImportDecl *D);
Abramo Bagnara6206d532010-06-05 05:09:32 +0000264 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000265 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000266 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
267 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000268 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000269
Chris Lattner698f9252009-04-27 05:27:42 +0000270 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Douglas Gregor0f753232011-12-22 01:48:48 +0000271
272 template <typename T>
273 RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000274
Sean Hunt9a555912010-05-30 07:21:58 +0000275 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-04-27 05:27:42 +0000276 void VisitObjCMethodDecl(ObjCMethodDecl *D);
277 void VisitObjCContainerDecl(ObjCContainerDecl *D);
278 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
279 void VisitObjCIvarDecl(ObjCIvarDecl *D);
280 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
281 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000282 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
283 void VisitObjCImplDecl(ObjCImplDecl *D);
284 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
285 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
286 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
287 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
288 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
289 };
290}
291
Sebastian Redld527cc02010-08-18 23:56:48 +0000292uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregor8f1231b2011-07-22 06:10:01 +0000293 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redl577d4792010-07-22 22:43:28 +0000294}
295
Sebastian Redld527cc02010-08-18 23:56:48 +0000296void ASTDeclReader::Visit(Decl *D) {
297 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000298
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000299 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
300 if (DD->DeclInfo) {
301 DeclaratorDecl::ExtInfo *Info =
302 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
303 Info->TInfo =
304 GetTypeSourceInfo(Record, Idx);
305 }
306 else {
307 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
308 }
309 }
310
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000311 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000312 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor1ab55e92010-12-10 17:03:06 +0000313 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Douglas Gregor0af55012011-12-16 03:12:41 +0000314 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
315 // if we have a fully initialized TypeDecl, we can safely read its type now.
316 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000317 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
318 // FunctionDecl's body was written last after all other Stmts/Exprs.
319 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000320 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000321 } else if (D->isTemplateParameter()) {
322 // If we have a fully initialized template parameter, we can now
323 // set its DeclContext.
324 D->setDeclContext(
325 cast_or_null<DeclContext>(
326 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
327 D->setLexicalDeclContext(
328 cast_or_null<DeclContext>(
329 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000330 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000331}
332
Sebastian Redld527cc02010-08-18 23:56:48 +0000333void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor67da6f62011-03-05 01:35:54 +0000334 if (D->isTemplateParameter()) {
335 // We don't want to deserialize the DeclContext of a template
336 // parameter immediately, because the template parameter might be
337 // used in the formulation of its DeclContext. Use the translation
338 // unit DeclContext as a placeholder.
Douglas Gregor409448c2011-07-21 22:35:25 +0000339 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
340 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000341 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000342 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000343 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
344 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor67da6f62011-03-05 01:35:54 +0000345 }
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000346 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner698f9252009-04-27 05:27:42 +0000347 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000348 if (Record[Idx++]) { // hasAttrs
Sean Huntcf807c42010-08-18 23:23:40 +0000349 AttrVec Attrs;
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000350 Reader.ReadAttributes(F, Attrs, Record, Idx);
Sean Huntcf807c42010-08-18 23:23:40 +0000351 D->setAttrs(Attrs);
352 }
Chris Lattner698f9252009-04-27 05:27:42 +0000353 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000354 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis6b6b42a2011-04-19 19:51:10 +0000355 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidisc14a03d2011-11-23 20:27:36 +0000356 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000357 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor08e0bc12011-09-10 00:09:20 +0000358 D->FromASTFile = true;
Douglas Gregor8d267c52011-09-09 02:06:17 +0000359 D->ModulePrivate = Record[Idx++];
Douglas Gregorecc2c092011-12-01 22:20:10 +0000360
361 // Determine whether this declaration is part of a (sub)module. If so, it
362 // may not yet be visible.
363 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
364 // Module-private declarations are never visible, so there is no work to do.
365 if (!D->ModulePrivate) {
366 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
367 if (Owner->NameVisibility != Module::AllVisible) {
368 // The owning module is not visible. Mark this declaration as
369 // module-private,
370 D->ModulePrivate = true;
371
372 // Note that this declaration was hidden because its owning module is
373 // not yet visible.
374 Reader.HiddenNamesMap[Owner].push_back(D);
375 }
376 }
377 }
378 }
Chris Lattner698f9252009-04-27 05:27:42 +0000379}
380
Sebastian Redld527cc02010-08-18 23:56:48 +0000381void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +0000382 llvm_unreachable("Translation units are not serialized");
Chris Lattner698f9252009-04-27 05:27:42 +0000383}
384
Sebastian Redld527cc02010-08-18 23:56:48 +0000385void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner698f9252009-04-27 05:27:42 +0000386 VisitDecl(ND);
Douglas Gregor393f2492011-07-22 00:38:23 +0000387 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000388}
389
Sebastian Redld527cc02010-08-18 23:56:48 +0000390void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000391 VisitNamedDecl(TD);
Abramo Bagnara344577e2011-03-06 15:48:19 +0000392 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000393 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor393f2492011-07-22 00:38:23 +0000394 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000395}
396
Douglas Gregor0f456822011-12-19 14:40:25 +0000397void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregora1be2782011-12-17 23:38:30 +0000398 VisitRedeclarable(TD);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000399 VisitTypeDecl(TD);
Douglas Gregor0f456822011-12-19 14:40:25 +0000400 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
401}
402
403void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
404 VisitTypedefNameDecl(TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000405}
406
Richard Smith162e1c12011-04-15 14:24:37 +0000407void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Douglas Gregor0f456822011-12-19 14:40:25 +0000408 VisitTypedefNameDecl(TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000409}
410
Sebastian Redld527cc02010-08-18 23:56:48 +0000411void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000412 VisitRedeclarable(TD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000413 VisitTypeDecl(TD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000414 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000415 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCall5e1cdac2011-10-07 06:10:15 +0000416 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000417 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis717a20b2011-09-30 22:11:31 +0000418 TD->setFreeStanding(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000419 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000420 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor35942772011-09-09 21:34:22 +0000421 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000422 ReadQualifierInfo(*Info, Record, Idx);
Richard Smith162e1c12011-04-15 14:24:37 +0000423 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000424 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000425 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000426}
427
Sebastian Redld527cc02010-08-18 23:56:48 +0000428void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000429 VisitTagDecl(ED);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000430 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
431 ED->setIntegerTypeSourceInfo(TI);
432 else
Douglas Gregor393f2492011-07-22 00:38:23 +0000433 ED->setIntegerType(Reader.readType(F, Record, Idx));
434 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall1b5a6182010-05-06 08:49:23 +0000435 ED->setNumPositiveBits(Record[Idx++]);
436 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000437 ED->IsScoped = Record[Idx++];
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000438 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000439 ED->IsFixed = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000440 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000441}
442
Sebastian Redld527cc02010-08-18 23:56:48 +0000443void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000444 VisitTagDecl(RD);
445 RD->setHasFlexibleArrayMember(Record[Idx++]);
446 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000447 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000448}
449
Sebastian Redld527cc02010-08-18 23:56:48 +0000450void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000451 VisitNamedDecl(VD);
Douglas Gregor393f2492011-07-22 00:38:23 +0000452 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000453}
454
Sebastian Redld527cc02010-08-18 23:56:48 +0000455void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000456 VisitValueDecl(ECD);
457 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000458 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000459 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
460}
461
Sebastian Redld527cc02010-08-18 23:56:48 +0000462void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000463 VisitValueDecl(DD);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000464 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000465 if (Record[Idx++]) { // hasExtInfo
466 DeclaratorDecl::ExtInfo *Info
Douglas Gregor35942772011-09-09 21:34:22 +0000467 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000468 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000469 DD->DeclInfo = Info;
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000470 }
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000471}
472
Sebastian Redld527cc02010-08-18 23:56:48 +0000473void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000474 VisitRedeclarable(FD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000475 VisitDeclaratorDecl(FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000476
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000477 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000478 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000479 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000480 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000481 case FunctionDecl::TK_NonTemplate:
482 break;
483 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000484 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
485 Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000486 break;
487 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000488 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000489 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000490 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000491 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000492 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
493 break;
494 }
495 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000496 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
497 Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000498 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
499
500 // Template arguments.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000501 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000502 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000503
504 // Template args as written.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000505 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000506 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000507 bool HasTemplateArgumentsAsWritten = Record[Idx++];
508 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000509 unsigned NumTemplateArgLocs = Record[Idx++];
510 TemplArgLocs.reserve(NumTemplateArgLocs);
511 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000512 TemplArgLocs.push_back(
Sebastian Redlc3632732010-10-05 15:59:54 +0000513 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000514
Sebastian Redlc3632732010-10-05 15:59:54 +0000515 LAngleLoc = ReadSourceLocation(Record, Idx);
516 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000517 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000518
Sebastian Redlc3632732010-10-05 15:59:54 +0000519 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000520
Douglas Gregor35942772011-09-09 21:34:22 +0000521 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000522 TemplateArgumentList *TemplArgList
Douglas Gregor910f8002010-11-07 23:05:16 +0000523 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000524 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000525 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000526 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000527 FunctionTemplateSpecializationInfo *FTInfo
528 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
529 TemplArgList,
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000530 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
531 POI);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000532 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000533
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000534 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000535 // The template that contains the specializations set. It's not safe to
536 // use getCanonicalDecl on Template since it may still be initializing.
537 FunctionTemplateDecl *CanonTemplate
Douglas Gregor409448c2011-07-21 22:35:25 +0000538 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000539 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
540 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
541 // FunctionTemplateSpecializationInfo's Profile().
542 // We avoid getASTContext because a decl in the parent hierarchy may
543 // be initializing.
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000544 llvm::FoldingSetNodeID ID;
545 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
546 TemplArgs.size(), C);
547 void *InsertPos = 0;
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000548 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000549 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000550 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000551 }
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000552 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000553 }
554 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
555 // Templates.
556 UnresolvedSet<8> TemplDecls;
557 unsigned NumTemplates = Record[Idx++];
558 while (NumTemplates--)
Douglas Gregor409448c2011-07-21 22:35:25 +0000559 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000560
561 // Templates args.
562 TemplateArgumentListInfo TemplArgs;
563 unsigned NumArgs = Record[Idx++];
564 while (NumArgs--)
Sebastian Redlc3632732010-10-05 15:59:54 +0000565 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
566 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
567 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000568
Douglas Gregor35942772011-09-09 21:34:22 +0000569 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000570 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000571 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000572 }
573 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000574
Sebastian Redld527cc02010-08-18 23:56:48 +0000575 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000576 // after everything else is read.
577
Douglas Gregor381d34e2010-12-06 18:36:25 +0000578 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000579 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregor8f150942010-12-09 16:59:22 +0000580 FD->IsInline = Record[Idx++];
581 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000582 FD->IsVirtualAsWritten = Record[Idx++];
583 FD->IsPure = Record[Idx++];
584 FD->HasInheritedPrototype = Record[Idx++];
585 FD->HasWrittenPrototype = Record[Idx++];
586 FD->IsDeleted = Record[Idx++];
587 FD->IsTrivial = Record[Idx++];
Sean Hunt2be7e902011-05-12 22:46:29 +0000588 FD->IsDefaulted = Record[Idx++];
589 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000590 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smithaf1fc7a2011-08-15 21:04:07 +0000591 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000592 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000593
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000594 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000595 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000596 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000597 Params.reserve(NumParams);
598 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000599 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000600 FD->setParams(Reader.getContext(), Params);
Chris Lattner698f9252009-04-27 05:27:42 +0000601}
602
Sebastian Redld527cc02010-08-18 23:56:48 +0000603void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000604 VisitNamedDecl(MD);
605 if (Record[Idx++]) {
606 // In practice, this won't be executed (since method definitions
607 // don't occur in header files).
Sebastian Redlc3632732010-10-05 15:59:54 +0000608 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor409448c2011-07-21 22:35:25 +0000609 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
610 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000611 }
612 MD->setInstanceMethod(Record[Idx++]);
613 MD->setVariadic(Record[Idx++]);
614 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000615 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000616
617 MD->IsRedeclaration = Record[Idx++];
618 MD->HasRedeclaration = Record[Idx++];
619 if (MD->HasRedeclaration)
620 Reader.getContext().setObjCMethodRedeclaration(MD,
621 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
622
Chris Lattner698f9252009-04-27 05:27:42 +0000623 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
624 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000625 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000626 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000627 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
628 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000629 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000630 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000631 Params.reserve(NumParams);
632 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000633 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000634
635 MD->SelLocsKind = Record[Idx++];
636 unsigned NumStoredSelLocs = Record[Idx++];
637 SmallVector<SourceLocation, 16> SelLocs;
638 SelLocs.reserve(NumStoredSelLocs);
639 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
640 SelLocs.push_back(ReadSourceLocation(Record, Idx));
641
642 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner698f9252009-04-27 05:27:42 +0000643}
644
Sebastian Redld527cc02010-08-18 23:56:48 +0000645void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000646 VisitNamedDecl(CD);
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000647 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
648 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000649}
650
Sebastian Redld527cc02010-08-18 23:56:48 +0000651void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregorcce54aa2011-12-22 19:44:59 +0000652 // Record the declaration -> global ID mapping.
653 Reader.DeclToID[ID] = ThisDeclID;
654
Douglas Gregor0f753232011-12-22 01:48:48 +0000655 RedeclarableResult Redecl = VisitRedeclarable(ID);
Chris Lattner698f9252009-04-27 05:27:42 +0000656 VisitObjCContainerDecl(ID);
Douglas Gregor0af55012011-12-16 03:12:41 +0000657 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Douglas Gregorcce54aa2011-12-22 19:44:59 +0000658
Douglas Gregor0f753232011-12-22 01:48:48 +0000659 // Determine whether we need to merge this declaration with another @interface
660 // with the same name.
661 // FIXME: Not needed unless the module file graph is a DAG.
662 if (FindExistingResult ExistingRes = findExisting(ID)) {
663 if (ObjCInterfaceDecl *Existing = ExistingRes) {
664 ObjCInterfaceDecl *ExistingCanon = Existing->getCanonicalDecl();
665 ObjCInterfaceDecl *IDCanon = ID->getCanonicalDecl();
666 if (ExistingCanon != IDCanon) {
667 // Have our redeclaration link point back at the canonical declaration
668 // of the existing declaration, so that this declaration has the
669 // appropriate canonical declaration.
670 ID->RedeclLink = ObjCInterfaceDecl::PreviousDeclLink(ExistingCanon);
671
Douglas Gregorcce54aa2011-12-22 19:44:59 +0000672 // Don't introduce IDCanon into the set of pending declaration chains.
673 Redecl.suppress();
674
675 // Introduce ExistingCanon into the set of pending declaration chains,
676 // if in fact it came from a module file.
677 if (ExistingCanon->isFromASTFile()) {
678 GlobalDeclID ExistingCanonID = Reader.DeclToID[ExistingCanon];
679 assert(ExistingCanonID && "Unrecorded canonical declaration ID?");
680 if (Reader.PendingDeclChainsKnown.insert(ExistingCanonID))
681 Reader.PendingDeclChains.push_back(ExistingCanonID);
682 }
683
Douglas Gregor0f753232011-12-22 01:48:48 +0000684 // If this declaration was the canonical declaration, make a note of
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +0000685 // that. We accept the linear algorithm here because the number of
686 // unique canonical declarations of an entity should always be tiny.
687 if (IDCanon == ID) {
688 SmallVectorImpl<DeclID> &Merged = Reader.MergedDecls[ExistingCanon];
689 if (std::find(Merged.begin(), Merged.end(), Redecl.getFirstID())
690 == Merged.end())
691 Merged.push_back(Redecl.getFirstID());
692 }
Douglas Gregor0f753232011-12-22 01:48:48 +0000693 }
694 }
695 }
696
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000697 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
698 if (ID == Def) {
699 // Read the definition.
700 ID->allocateDefinitionData();
701
702 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
703
704 // Read the superclass.
705 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
706 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
707
Douglas Gregor05c272f2011-12-15 22:34:59 +0000708 Data.EndLoc = ReadSourceLocation(Record, Idx);
709
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000710 // Read the directly referenced protocols and their SourceLocations.
711 unsigned NumProtocols = Record[Idx++];
712 SmallVector<ObjCProtocolDecl *, 16> Protocols;
713 Protocols.reserve(NumProtocols);
714 for (unsigned I = 0; I != NumProtocols; ++I)
715 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
716 SmallVector<SourceLocation, 16> ProtoLocs;
717 ProtoLocs.reserve(NumProtocols);
718 for (unsigned I = 0; I != NumProtocols; ++I)
719 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
720 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
721 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000722
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000723 // Read the transitive closure of protocols referenced by this class.
724 NumProtocols = Record[Idx++];
725 Protocols.clear();
726 Protocols.reserve(NumProtocols);
727 for (unsigned I = 0; I != NumProtocols; ++I)
728 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
729 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
730 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000731
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000732 // Read the ivars.
733 unsigned NumIvars = Record[Idx++];
734 SmallVector<ObjCIvarDecl *, 16> IVars;
735 IVars.reserve(NumIvars);
736 for (unsigned I = 0; I != NumIvars; ++I)
737 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
738
739 // Read the categories.
740 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000741
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000742 // We will rebuild this list lazily.
743 ID->setIvarList(0);
744
Douglas Gregor21cf08b2011-12-19 20:51:16 +0000745 // Note that we have deserialized a definition.
746 Reader.PendingDefinitions.insert(ID);
747 } else if (Def && Def->Data) {
748 ID->Data = Def->Data;
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000749 }
Chris Lattner698f9252009-04-27 05:27:42 +0000750}
751
Sebastian Redld527cc02010-08-18 23:56:48 +0000752void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000753 VisitFieldDecl(IVD);
754 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000755 // This field will be built lazily.
756 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000757 bool synth = Record[Idx++];
758 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000759}
760
Sebastian Redld527cc02010-08-18 23:56:48 +0000761void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Douglas Gregordba93612012-01-01 21:47:52 +0000762 // Record the declaration -> global ID mapping.
763 Reader.DeclToID[PD] = ThisDeclID;
764
765 RedeclarableResult Redecl = VisitRedeclarable(PD);
Chris Lattner698f9252009-04-27 05:27:42 +0000766 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000767 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000768 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000769 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +0000770
Douglas Gregordba93612012-01-01 21:47:52 +0000771 // Determine whether we need to merge this declaration with another @protocol
772 // with the same name.
773 // FIXME: Not needed unless the module file graph is a DAG.
774 if (FindExistingResult ExistingRes = findExisting(PD)) {
775 if (ObjCProtocolDecl *Existing = ExistingRes) {
776 ObjCProtocolDecl *ExistingCanon = Existing->getCanonicalDecl();
777 ObjCProtocolDecl *PDCanon = PD->getCanonicalDecl();
778 if (ExistingCanon != PDCanon) {
779 // Have our redeclaration link point back at the canonical declaration
780 // of the existing declaration, so that this declaration has the
781 // appropriate canonical declaration.
782 PD->RedeclLink = ObjCProtocolDecl::PreviousDeclLink(ExistingCanon);
783
784 // Don't introduce IDCanon into the set of pending declaration chains.
785 Redecl.suppress();
786
787 // Introduce ExistingCanon into the set of pending declaration chains,
788 // if in fact it came from a module file.
789 if (ExistingCanon->isFromASTFile()) {
790 GlobalDeclID ExistingCanonID = Reader.DeclToID[ExistingCanon];
791 assert(ExistingCanonID && "Unrecorded canonical declaration ID?");
792 if (Reader.PendingDeclChainsKnown.insert(ExistingCanonID))
793 Reader.PendingDeclChains.push_back(ExistingCanonID);
794 }
795
796 // If this declaration was the canonical declaration, make a note of
797 // that. We accept the linear algorithm here because the number of
798 // unique canonical declarations of an entity should always be tiny.
799 if (PDCanon == PD) {
800 SmallVectorImpl<DeclID> &Merged = Reader.MergedDecls[ExistingCanon];
801 if (std::find(Merged.begin(), Merged.end(), Redecl.getFirstID())
802 == Merged.end())
803 Merged.push_back(Redecl.getFirstID());
804 }
805 }
806 }
807 }
808
809
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +0000810 ObjCProtocolDecl *Def = ReadDeclAs<ObjCProtocolDecl>(Record, Idx);
811 if (PD == Def) {
812 // Read the definition.
813 PD->allocateDefinitionData();
814
815 unsigned NumProtoRefs = Record[Idx++];
816 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
817 ProtoRefs.reserve(NumProtoRefs);
818 for (unsigned I = 0; I != NumProtoRefs; ++I)
819 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
820 SmallVector<SourceLocation, 16> ProtoLocs;
821 ProtoLocs.reserve(NumProtoRefs);
822 for (unsigned I = 0; I != NumProtoRefs; ++I)
823 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
824 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
825 Reader.getContext());
826
Douglas Gregor1d784b22012-01-01 19:51:50 +0000827 // Note that we have deserialized a definition.
828 Reader.PendingDefinitions.insert(PD);
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +0000829 } else if (Def && Def->Data) {
830 PD->Data = Def->Data;
831 }
Chris Lattner698f9252009-04-27 05:27:42 +0000832}
833
Sebastian Redld527cc02010-08-18 23:56:48 +0000834void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000835 VisitFieldDecl(FD);
836}
837
Sebastian Redld527cc02010-08-18 23:56:48 +0000838void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000839 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000840 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000841 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000842 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000843 ProtoRefs.reserve(NumProtoRefs);
844 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000845 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000846 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000847 ProtoLocs.reserve(NumProtoRefs);
848 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000849 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000850 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000851 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000852 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000853 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000854 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000855}
856
Sebastian Redld527cc02010-08-18 23:56:48 +0000857void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000858 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000859 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000860}
861
Sebastian Redld527cc02010-08-18 23:56:48 +0000862void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000863 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000864 D->setAtLoc(ReadSourceLocation(Record, Idx));
865 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000866 // FIXME: stable encoding
867 D->setPropertyAttributes(
868 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000869 D->setPropertyAttributesAsWritten(
870 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000871 // FIXME: stable encoding
872 D->setPropertyImplementation(
873 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000874 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
875 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000876 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
877 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
878 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000879}
880
Sebastian Redld527cc02010-08-18 23:56:48 +0000881void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000882 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000883 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000884}
885
Sebastian Redld527cc02010-08-18 23:56:48 +0000886void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000887 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000888 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +0000889 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000890}
891
Sebastian Redld527cc02010-08-18 23:56:48 +0000892void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000893 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000894 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000895 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000896 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000897 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000898}
899
900
Sebastian Redld527cc02010-08-18 23:56:48 +0000901void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000902 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000903 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000904 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
905 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000906 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000907 D->setGetterCXXConstructor(Reader.ReadExpr(F));
908 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000909}
910
Sebastian Redld527cc02010-08-18 23:56:48 +0000911void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000912 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000913 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000914 int BitWidthOrInitializer = Record[Idx++];
915 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000916 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000917 else if (BitWidthOrInitializer == 2)
918 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000919 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000920 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000921 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000922 }
Chris Lattner698f9252009-04-27 05:27:42 +0000923}
924
Francois Pichet87c2e122010-11-21 06:08:52 +0000925void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
926 VisitValueDecl(FD);
927
928 FD->ChainingSize = Record[Idx++];
929 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000930 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000931
932 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000933 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000934}
935
Sebastian Redld527cc02010-08-18 23:56:48 +0000936void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000937 VisitRedeclarable(VD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000938 VisitDeclaratorDecl(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000939 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
940 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
941 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
942 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
943 VD->VarDeclBits.ExceptionVar = Record[Idx++];
944 VD->VarDeclBits.NRVOVariable = Record[Idx++];
945 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000946 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smith099e7f62011-12-19 06:19:21 +0000947 if (uint64_t Val = Record[Idx++]) {
Sebastian Redlc3632732010-10-05 15:59:54 +0000948 VD->setInit(Reader.ReadExpr(F));
Richard Smith099e7f62011-12-19 06:19:21 +0000949 if (Val > 1) {
950 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
951 Eval->CheckedICE = true;
952 Eval->IsICE = Val == 3;
953 }
954 }
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000955
956 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000957 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000958 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000959 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000960 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000961 }
Chris Lattner698f9252009-04-27 05:27:42 +0000962}
963
Sebastian Redld527cc02010-08-18 23:56:48 +0000964void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000965 VisitVarDecl(PD);
966}
967
Sebastian Redld527cc02010-08-18 23:56:48 +0000968void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000969 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000970 unsigned isObjCMethodParam = Record[Idx++];
971 unsigned scopeDepth = Record[Idx++];
972 unsigned scopeIndex = Record[Idx++];
973 unsigned declQualifier = Record[Idx++];
974 if (isObjCMethodParam) {
975 assert(scopeDepth == 0);
976 PD->setObjCMethodScopeInfo(scopeIndex);
977 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
978 } else {
979 PD->setScopeInfo(scopeDepth, scopeIndex);
980 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000981 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
982 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000983 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000984 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000985}
986
Sebastian Redld527cc02010-08-18 23:56:48 +0000987void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000988 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000989 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000990 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000991}
992
Sebastian Redld527cc02010-08-18 23:56:48 +0000993void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000994 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000995 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
996 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000997 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000998 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000999 Params.reserve(NumParams);
1000 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +00001001 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +00001002 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +00001003
1004 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +00001005 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +00001006 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +00001007 captures.reserve(numCaptures);
1008 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001009 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +00001010 unsigned flags = Record[Idx++];
1011 bool byRef = (flags & 1);
1012 bool nested = (flags & 2);
1013 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
1014
1015 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
1016 }
Douglas Gregor35942772011-09-09 21:34:22 +00001017 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +00001018 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +00001019}
1020
Sebastian Redld527cc02010-08-18 23:56:48 +00001021void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001022 VisitDecl(D);
1023 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001024 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +00001025 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001026}
1027
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001028void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
1029 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +00001030 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001031}
1032
1033
Sebastian Redld527cc02010-08-18 23:56:48 +00001034void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001035 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +00001036 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001037 D->LocStart = ReadSourceLocation(Record, Idx);
1038 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +00001039 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001040
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001041 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001042 // FIXME: Modules will likely have trouble with pointing directly at
1043 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +00001044 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +00001045 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001046}
1047
Sebastian Redld527cc02010-08-18 23:56:48 +00001048void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001049 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001050 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +00001051 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001052 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001053 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001054}
1055
Sebastian Redld527cc02010-08-18 23:56:48 +00001056void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001057 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001058 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +00001059 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001060 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001061 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001062 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +00001063 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001064 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001065}
1066
Sebastian Redld527cc02010-08-18 23:56:48 +00001067void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001068 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +00001069 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
1070 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
1071 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001072 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +00001073 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001074}
1075
Sebastian Redld527cc02010-08-18 23:56:48 +00001076void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001077 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001078 D->UsingLoc = ReadSourceLocation(Record, Idx);
1079 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +00001080 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001081 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
1082 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001083}
1084
Sebastian Redld527cc02010-08-18 23:56:48 +00001085void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001086 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001087 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +00001088 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001089 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001090}
1091
Sebastian Redld527cc02010-08-18 23:56:48 +00001092void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001093 UnresolvedUsingTypenameDecl *D) {
1094 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001095 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +00001096 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001097}
1098
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001099void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001100 struct CXXRecordDecl::DefinitionData &Data,
1101 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001102 Data.UserDeclaredConstructor = Record[Idx++];
1103 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001104 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001105 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001106 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001107 Data.UserDeclaredDestructor = Record[Idx++];
1108 Data.Aggregate = Record[Idx++];
1109 Data.PlainOldData = Record[Idx++];
1110 Data.Empty = Record[Idx++];
1111 Data.Polymorphic = Record[Idx++];
1112 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +00001113 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +00001114 Data.HasNoNonEmptyBases = Record[Idx++];
1115 Data.HasPrivateFields = Record[Idx++];
1116 Data.HasProtectedFields = Record[Idx++];
1117 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +00001118 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +00001119 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +00001120 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001121 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +00001122 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001123 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +00001124 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001125 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +00001126 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001127 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +00001128 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001129 Data.DeclaredDefaultConstructor = Record[Idx++];
1130 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001131 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001132 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001133 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001134 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +00001135 Data.FailedImplicitMoveConstructor = Record[Idx++];
1136 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +00001137
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001138 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +00001139 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +00001140 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001141 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +00001142 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +00001143 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +00001144
Douglas Gregor409448c2011-07-21 22:35:25 +00001145 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
1146 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001147 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +00001148 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001149}
1150
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001151void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
1152 CXXRecordDecl *DefinitionDecl,
1153 const RecordData &Record,
1154 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +00001155 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +00001156
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +00001157 if (D == DefinitionDecl) {
1158 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001159 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00001160
Douglas Gregorfc529f72011-12-19 19:00:47 +00001161 // Note that we have deserialized a definition.
1162 Reader.PendingDefinitions.insert(D);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00001163 } else if (DefinitionDecl && DefinitionDecl->DefinitionData) {
1164 D->DefinitionData = DefinitionDecl->DefinitionData;
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +00001165 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001166}
1167
1168void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1169 VisitRecordDecl(D);
1170
Douglas Gregor409448c2011-07-21 22:35:25 +00001171 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001172 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1173
Douglas Gregor35942772011-09-09 21:34:22 +00001174 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +00001175
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001176 enum CXXRecKind {
1177 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1178 };
1179 switch ((CXXRecKind)Record[Idx++]) {
1180 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001181 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001182 case CXXRecNotTemplate:
1183 break;
1184 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +00001185 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001186 break;
1187 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001188 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001189 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001190 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +00001191 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1192 MSI->setPointOfInstantiation(POI);
1193 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001194 break;
1195 }
1196 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +00001197
1198 // Load the key function to avoid deserializing every method so we can
1199 // compute it.
John McCall5e1cdac2011-10-07 06:10:15 +00001200 if (D->IsCompleteDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001201 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +00001202 C.KeyFunctions[D] = Key;
1203 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001204}
1205
Sebastian Redld527cc02010-08-18 23:56:48 +00001206void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001207 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001208 unsigned NumOverridenMethods = Record[Idx++];
1209 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001210 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1211 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +00001212 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001213 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001214 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001215}
1216
Sebastian Redld527cc02010-08-18 23:56:48 +00001217void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001218 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001219
1220 D->IsExplicitSpecified = Record[Idx++];
1221 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001222 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1223 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001224}
1225
Sebastian Redld527cc02010-08-18 23:56:48 +00001226void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001227 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001228
1229 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001230 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001231}
1232
Sebastian Redld527cc02010-08-18 23:56:48 +00001233void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001234 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001235 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001236}
1237
Douglas Gregor15de72c2011-12-02 23:23:56 +00001238void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1239 VisitDecl(D);
1240 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1241 D->ImportedAndComplete.setInt(Record[Idx++]);
1242 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1243 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1244 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1245 ++Idx;
1246}
1247
Sebastian Redld527cc02010-08-18 23:56:48 +00001248void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001249 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001250 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001251}
1252
Sebastian Redld527cc02010-08-18 23:56:48 +00001253void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001254 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001255 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001256 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001257 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001258 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001259 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001260 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001261 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001262}
1263
Sebastian Redld527cc02010-08-18 23:56:48 +00001264void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001265 VisitDecl(D);
1266 unsigned NumParams = Record[Idx++];
1267 D->NumParams = NumParams;
1268 D->Params = new TemplateParameterList*[NumParams];
1269 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001270 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001271 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001272 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001273 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001274 D->Friend = GetTypeSourceInfo(Record, Idx);
1275 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001276}
1277
Sebastian Redld527cc02010-08-18 23:56:48 +00001278void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001279 VisitNamedDecl(D);
1280
Douglas Gregor409448c2011-07-21 22:35:25 +00001281 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001282 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001283 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001284 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001285}
1286
Sebastian Redld527cc02010-08-18 23:56:48 +00001287void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001288 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1289 // can be used while this is still initializing.
Douglas Gregorfc529f72011-12-19 19:00:47 +00001290 enum RedeclKind { FirstDeclaration, FirstInFile, PointsToPrevious };
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001291 RedeclKind Kind = (RedeclKind)Record[Idx++];
1292
1293 // Determine the first declaration ID.
1294 DeclID FirstDeclID;
1295 switch (Kind) {
1296 case FirstDeclaration: {
1297 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001298
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001299 // Since this is the first declaration of the template, fill in the
1300 // information for the 'common' pointer.
1301 if (D->CommonOrPrev.isNull()) {
1302 RedeclarableTemplateDecl::CommonBase *Common
1303 = D->newCommon(Reader.getContext());
1304 Common->Latest = D;
1305 D->CommonOrPrev = Common;
1306 }
Douglas Gregor0f753232011-12-22 01:48:48 +00001307
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001308 if (RedeclarableTemplateDecl *RTD
Douglas Gregor0f753232011-12-22 01:48:48 +00001309 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001310 assert(RTD->getKind() == D->getKind() &&
1311 "InstantiatedFromMemberTemplate kind mismatch");
1312 D->setInstantiatedFromMemberTemplateImpl(RTD);
1313 if (Record[Idx++])
1314 D->setMemberSpecialization();
1315 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001316 break;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001317 }
Douglas Gregorfc529f72011-12-19 19:00:47 +00001318
1319 case FirstInFile:
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001320 case PointsToPrevious: {
1321 FirstDeclID = ReadDeclID(Record, Idx);
1322 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1323
1324 RedeclarableTemplateDecl *FirstDecl
1325 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1326
1327 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1328 // We temporarily set the first (canonical) declaration as the previous one
1329 // which is the one that matters and mark the real previous DeclID to be
1330 // loaded and attached later on.
1331 D->CommonOrPrev = FirstDecl;
1332
Douglas Gregorfc529f72011-12-19 19:00:47 +00001333 if (Kind == PointsToPrevious) {
1334 // Make a note that we need to wire up this declaration to its
1335 // previous declaration, later. We don't need to do this for the first
1336 // declaration in any given module file, because those will be wired
1337 // together later.
1338 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PrevDeclID));
1339 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001340 break;
1341 }
1342 }
1343
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001344 VisitTemplateDecl(D);
1345 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001346}
1347
Sebastian Redld527cc02010-08-18 23:56:48 +00001348void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001349 VisitRedeclarableTemplateDecl(D);
1350
1351 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001352 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1353 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001354 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001355 SpecIDs.push_back(0);
1356
1357 // Specializations.
1358 unsigned Size = Record[Idx++];
1359 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001360 for (unsigned I = 0; I != Size; ++I)
1361 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001362
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001363 // Partial specializations.
1364 Size = Record[Idx++];
1365 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001366 for (unsigned I = 0; I != Size; ++I)
1367 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001368
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001369 if (SpecIDs[0]) {
1370 typedef serialization::DeclID DeclID;
1371
1372 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1373 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001374 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001375 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1376 SpecIDs.size() * sizeof(DeclID));
1377 }
1378
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001379 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001380 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001381}
1382
Sebastian Redld527cc02010-08-18 23:56:48 +00001383void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001384 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001385 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001386
Douglas Gregor35942772011-09-09 21:34:22 +00001387 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001388 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001389 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001390 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001391 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001392 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001393 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001394 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001395 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1396 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001397 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1398 = new (C) ClassTemplateSpecializationDecl::
1399 SpecializedPartialSpecialization();
1400 PS->PartialSpecialization
1401 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1402 PS->TemplateArgs = ArgList;
1403 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001404 }
1405 }
1406
1407 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001408 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001409 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1410 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1411 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001412 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1413 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001414 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001415 }
1416
Chris Lattner5f9e2722011-07-23 10:55:15 +00001417 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001418 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001419 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1420 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001421 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001422 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001423
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001424 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001425 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001426 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001427 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1428 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001429 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001430 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001431 }
1432 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001433}
1434
Sebastian Redld527cc02010-08-18 23:56:48 +00001435void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001436 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001437 VisitClassTemplateSpecializationDecl(D);
1438
Douglas Gregor35942772011-09-09 21:34:22 +00001439 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001440 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001441
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001442 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001443 if (NumArgs) {
1444 D->NumArgsAsWritten = NumArgs;
1445 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1446 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001447 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001448 }
1449
1450 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001451
1452 // These are read/set from/to the first declaration.
1453 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001454 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001455 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001456 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001457 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001458}
1459
Sebastian Redl14c36332011-08-31 13:59:56 +00001460void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1461 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001462 VisitDecl(D);
1463 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1464}
1465
Sebastian Redld527cc02010-08-18 23:56:48 +00001466void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001467 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001468
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001469 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001470 // This FunctionTemplateDecl owns a CommonPtr; read it.
1471
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001472 // Read the function specialization declarations.
1473 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001474 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001475 unsigned NumSpecs = Record[Idx++];
1476 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001477 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001478 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001479}
1480
Sebastian Redld527cc02010-08-18 23:56:48 +00001481void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001482 VisitTypeDecl(D);
1483
1484 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001485
1486 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001487 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001488 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001489}
1490
Sebastian Redld527cc02010-08-18 23:56:48 +00001491void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001492 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001493 // TemplateParmPosition.
1494 D->setDepth(Record[Idx++]);
1495 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001496 if (D->isExpandedParameterPack()) {
1497 void **Data = reinterpret_cast<void **>(D + 1);
1498 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001499 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001500 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1501 }
1502 } else {
1503 // Rest of NonTypeTemplateParmDecl.
1504 D->ParameterPack = Record[Idx++];
1505 if (Record[Idx++]) {
1506 Expr *DefArg = Reader.ReadExpr(F);
1507 bool Inherited = Record[Idx++];
1508 D->setDefaultArgument(DefArg, Inherited);
1509 }
1510 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001511}
1512
Sebastian Redld527cc02010-08-18 23:56:48 +00001513void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001514 VisitTemplateDecl(D);
1515 // TemplateParmPosition.
1516 D->setDepth(Record[Idx++]);
1517 D->setPosition(Record[Idx++]);
1518 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001519 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001520 bool IsInherited = Record[Idx++];
1521 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001522 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001523}
1524
Richard Smith3e4c6c42011-05-05 21:57:07 +00001525void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1526 VisitRedeclarableTemplateDecl(D);
1527}
1528
Sebastian Redld527cc02010-08-18 23:56:48 +00001529void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001530 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001531 D->AssertExpr = Reader.ReadExpr(F);
1532 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001533 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001534}
1535
Mike Stump1eb44332009-09-09 15:08:12 +00001536std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001537ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001538 uint64_t LexicalOffset = Record[Idx++];
1539 uint64_t VisibleOffset = Record[Idx++];
1540 return std::make_pair(LexicalOffset, VisibleOffset);
1541}
1542
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001543template <typename T>
Douglas Gregor0f753232011-12-22 01:48:48 +00001544ASTDeclReader::RedeclarableResult
1545ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Douglas Gregorfc529f72011-12-19 19:00:47 +00001546 enum RedeclKind { FirstDeclaration = 0, FirstInFile, PointsToPrevious };
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001547 RedeclKind Kind = (RedeclKind)Record[Idx++];
Douglas Gregora1be2782011-12-17 23:38:30 +00001548
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001549 DeclID FirstDeclID;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001550 switch (Kind) {
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001551 case FirstDeclaration:
1552 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001553 break;
Douglas Gregorfc529f72011-12-19 19:00:47 +00001554
1555 case FirstInFile:
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001556 case PointsToPrevious: {
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001557 FirstDeclID = ReadDeclID(Record, Idx);
1558 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1559
1560 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
Douglas Gregora1be2782011-12-17 23:38:30 +00001561
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001562 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1563 // We temporarily set the first (canonical) declaration as the previous one
1564 // which is the one that matters and mark the real previous DeclID to be
1565 // loaded & attached later on.
Douglas Gregord488b3a2011-10-26 17:53:41 +00001566 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Douglas Gregord488b3a2011-10-26 17:53:41 +00001567
Douglas Gregorfc529f72011-12-19 19:00:47 +00001568 if (Kind == PointsToPrevious) {
1569 // Make a note that we need to wire up this declaration to its
1570 // previous declaration, later. We don't need to do this for the first
1571 // declaration in any given module file, because those will be wired
1572 // together later.
1573 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1574 PrevDeclID));
1575 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001576 break;
1577 }
Douglas Gregord488b3a2011-10-26 17:53:41 +00001578 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001579
Douglas Gregor0f753232011-12-22 01:48:48 +00001580 // The result structure takes care of note that we need to load the
1581 // other declaration chains for this ID.
1582 return RedeclarableResult(Reader, FirstDeclID);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001583}
1584
Chris Lattner698f9252009-04-27 05:27:42 +00001585//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001586// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001587//===----------------------------------------------------------------------===//
1588
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001589/// \brief Reads attributes from the current stream position.
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001590void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001591 const RecordData &Record, unsigned &Idx) {
1592 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001593 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001594 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001595 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001596
Sean Huntcf807c42010-08-18 23:23:40 +00001597#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001598
1599 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001600 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001601 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001602}
1603
1604//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001605// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001606//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001607
1608/// \brief Note that we have loaded the declaration with the given
1609/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001610///
Chris Lattner698f9252009-04-27 05:27:42 +00001611/// This routine notes that this declaration has already been loaded,
1612/// so that future GetDecl calls will return this declaration rather
1613/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001614inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001615 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1616 DeclsLoaded[Index] = D;
1617}
1618
1619
1620/// \brief Determine whether the consumer will be interested in seeing
1621/// this declaration (via HandleTopLevelDecl).
1622///
1623/// This routine should return true for anything that might affect
1624/// code generation, e.g., inline function definitions, Objective-C
1625/// declarations with metadata, etc.
1626static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001627 // An ObjCMethodDecl is never considered as "interesting" because its
1628 // implementation container always is.
1629
Douglas Gregor94da1582011-09-10 00:22:34 +00001630 if (isa<FileScopeAsmDecl>(D) ||
1631 isa<ObjCProtocolDecl>(D) ||
1632 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001633 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001634 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001635 return Var->isFileVarDecl() &&
1636 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001637 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001638 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001639
1640 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001641}
1642
Douglas Gregor96e973f2011-07-20 00:27:43 +00001643/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001644ASTReader::RecordLocation
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001645ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001646 // See if there's an override.
1647 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidisef23b602011-10-31 07:20:15 +00001648 if (It != ReplacedDecls.end()) {
1649 RawLocation = It->second.RawLoc;
1650 return RecordLocation(It->second.Mod, It->second.Offset);
1651 }
Sebastian Redl0b17c612010-08-13 00:28:03 +00001652
Douglas Gregor96e973f2011-07-20 00:27:43 +00001653 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1654 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001655 ModuleFile *M = I->second;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001656 const DeclOffset &
1657 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1658 RawLocation = DOffs.Loc;
1659 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001660}
1661
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001662ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001663 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001664 = GlobalBitOffsetsMap.find(GlobalOffset);
1665
1666 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1667 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1668}
1669
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001670uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregore92b8a12011-08-04 00:01:48 +00001671 return LocalOffset + M.GlobalBitOffset;
1672}
1673
Douglas Gregor0f753232011-12-22 01:48:48 +00001674/// \brief Determine whether the two declarations refer to the same entity.
1675static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
1676 assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
1677
1678 if (X == Y)
1679 return true;
1680
1681 // Must have the same kind.
1682 if (X->getKind() != Y->getKind())
1683 return false;
1684
1685 // Must be in the same context.
1686 if (!X->getDeclContext()->getRedeclContext()->Equals(
1687 Y->getDeclContext()->getRedeclContext()))
1688 return false;
1689
Douglas Gregordba93612012-01-01 21:47:52 +00001690 // Objective-C classes and protocols with the same name always match.
1691 if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X))
Douglas Gregor0f753232011-12-22 01:48:48 +00001692 return true;
1693
1694 // FIXME: Many other cases to implement.
1695 return false;
1696}
1697
1698ASTDeclReader::FindExistingResult::~FindExistingResult() {
1699 if (!AddResult)
1700 return;
1701
1702 DeclContext *DC = New->getDeclContext()->getRedeclContext();
1703 if (DC->isTranslationUnit() && Reader.SemaObj) {
1704 if (!Existing) {
1705 Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName());
1706 }
1707 }
1708}
1709
1710ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
1711 DeclContext *DC = D->getDeclContext()->getRedeclContext();
1712 if (!DC->isFileContext())
1713 return FindExistingResult(Reader);
1714
1715 if (DC->isTranslationUnit() && Reader.SemaObj) {
1716 IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver;
1717 for (IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()),
1718 IEnd = IdResolver.end();
1719 I != IEnd; ++I) {
1720 if (isSameEntity(*I, D))
1721 return FindExistingResult(Reader, D, *I);
1722 }
1723 }
1724
1725 // FIXME: Search in the DeclContext.
1726
1727 return FindExistingResult(Reader, D, /*Existing=*/0);
1728}
1729
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001730void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1731 assert(D && previous);
1732 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1733 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1734 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1735 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1736 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1737 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
Douglas Gregora1be2782011-12-17 23:38:30 +00001738 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1739 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
1740 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregor0af55012011-12-16 03:12:41 +00001741 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
Douglas Gregor1d784b22012-01-01 19:51:50 +00001742 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
1743 PD->RedeclLink.setPointer(cast<ObjCProtocolDecl>(previous));
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001744 } else {
1745 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1746 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1747 }
1748}
1749
Douglas Gregora1be2782011-12-17 23:38:30 +00001750void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
1751 assert(D && Latest);
1752 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1753 TD->RedeclLink
1754 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
1755 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1756 FD->RedeclLink
1757 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
1758 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1759 VD->RedeclLink
1760 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
1761 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1762 TD->RedeclLink
1763 = Redeclarable<TypedefNameDecl>::LatestDeclLink(
1764 cast<TypedefNameDecl>(Latest));
1765 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
1766 ID->RedeclLink
1767 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
1768 cast<ObjCInterfaceDecl>(Latest));
Douglas Gregor1d784b22012-01-01 19:51:50 +00001769 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
1770 PD->RedeclLink
1771 = Redeclarable<ObjCProtocolDecl>::LatestDeclLink(
1772 cast<ObjCProtocolDecl>(Latest));
Douglas Gregora1be2782011-12-17 23:38:30 +00001773 } else {
1774 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1775 TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest);
1776 }
1777}
1778
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +00001779ASTReader::MergedDeclsMap::iterator
1780ASTReader::combineStoredMergedDecls(Decl *Canon, GlobalDeclID CanonID) {
1781 // If we don't have any stored merged declarations, just look in the
1782 // merged declarations set.
1783 StoredMergedDeclsMap::iterator StoredPos = StoredMergedDecls.find(CanonID);
1784 if (StoredPos == StoredMergedDecls.end())
1785 return MergedDecls.find(Canon);
1786
1787 // Append the stored merged declarations to the merged declarations set.
1788 MergedDeclsMap::iterator Pos = MergedDecls.find(Canon);
1789 if (Pos == MergedDecls.end())
1790 Pos = MergedDecls.insert(std::make_pair(Canon,
1791 SmallVector<DeclID, 2>())).first;
1792 Pos->second.append(StoredPos->second.begin(), StoredPos->second.end());
1793 StoredMergedDecls.erase(StoredPos);
1794
1795 // Sort and uniquify the set of merged declarations.
1796 llvm::array_pod_sort(Pos->second.begin(), Pos->second.end());
1797 Pos->second.erase(std::unique(Pos->second.begin(), Pos->second.end()),
1798 Pos->second.end());
1799 return Pos;
1800}
1801
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001802void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1803 Decl *previous = GetDecl(ID);
1804 ASTDeclReader::attachPreviousDecl(D, previous);
1805}
1806
Sebastian Redld527cc02010-08-18 23:56:48 +00001807/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001808Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001809 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001810 unsigned RawLocation = 0;
1811 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redlc3632732010-10-05 15:59:54 +00001812 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001813 // Keep track of where we are in the stream, then jump back there
1814 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001815 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001816
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001817 ReadingKindTracker ReadingKind(Read_Decl, *this);
1818
Douglas Gregord89275b2009-07-06 18:54:52 +00001819 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001820 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001821
Sebastian Redlc3632732010-10-05 15:59:54 +00001822 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001823 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001824 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001825 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001826 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001827
Chris Lattnerda930612009-04-27 05:58:23 +00001828 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001829 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001830 case DECL_CONTEXT_LEXICAL:
1831 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001832 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001833 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001834 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001835 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001836 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001837 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001838 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001839 0, 0);
1840 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001841 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001842 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001843 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001844 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001845 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001846 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001847 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001848 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001849 0, llvm::APSInt());
1850 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001851 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001852 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001853 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001854 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001855 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001856 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001857 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001858 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001859 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001860 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001861 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001862 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001863 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001864 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001865 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001866 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001867 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001868 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001869 SourceLocation(), 0,
1870 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001871 SourceLocation(), 0);
1872 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001873 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001874 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001875 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1876 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001877 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001878 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001879 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001880 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001881 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001882 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001883 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001884 SourceLocation(), 0, 0);
1885 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001886 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001887 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001888 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001889 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001890 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001891 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001892 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001893 SourceLocation(),
1894 NestedNameSpecifierLoc(),
1895 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001896 DeclarationName());
1897 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001898 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001899 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001900 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001901 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001902 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001903 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001904 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001905 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001906 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001907 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001908 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001909 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001910 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001911 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001912 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001913 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001914 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001915 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001916 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001917 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001918 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001919 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001920 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001921 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001922 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001923 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001924 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001925 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001926 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001927 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001928 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001929 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001930 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001931 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001932 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001933 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001934 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001935 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001936 Decl::EmptyShell());
1937 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001938 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001939 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001940 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001941 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001942 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001943 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001944 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001945 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001946 SourceLocation(), 0, 0, 0, QualType(),
1947 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001948 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001949 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001950 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001951 SourceLocation(), 0, 0, 0, QualType(),
1952 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001953 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001954 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001955 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001956 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001957 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001958 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001959 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001960 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001961 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001962 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001963 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001964 break;
1965
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001966 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001967 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001968 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001969 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001970 case DECL_OBJC_INTERFACE:
Douglas Gregor0af55012011-12-16 03:12:41 +00001971 D = ObjCInterfaceDecl::CreateEmpty(Context);
Chris Lattner698f9252009-04-27 05:27:42 +00001972 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001973 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001974 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001975 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001976 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001977 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001978 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Douglas Gregor27c6da22012-01-01 20:30:41 +00001979 SourceLocation(), 0, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001980 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001981 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001982 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001983 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001984 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001985 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001986 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001987 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001988 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001989 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +00001990 SourceLocation(), SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001991 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001992 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001993 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1994 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001995 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001996 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001997 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001998 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001999 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00002000 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00002001 0);
Chris Lattner698f9252009-04-27 05:27:42 +00002002 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002003 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00002004 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00002005 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00002006 ObjCPropertyImplDecl::Dynamic, 0,
2007 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00002008 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002009 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00002010 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00002011 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00002012 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00002013 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00002014 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00002015 0, 0);
2016 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002017 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00002018 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00002019 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00002020 break;
2021
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002022 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00002023 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00002024 break;
2025
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002026 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00002027 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00002028 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00002029 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002030 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00002031 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00002032 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00002033 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002034 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00002035 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00002036 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00002037 case DECL_CXX_BASE_SPECIFIERS:
2038 Error("attempt to read a C++ base-specifier record as a declaration");
2039 return 0;
Douglas Gregor15de72c2011-12-02 23:23:56 +00002040 case DECL_IMPORT:
2041 // Note: last entry of the ImportDecl record is the number of stored source
2042 // locations.
2043 D = ImportDecl::CreateEmpty(Context, Record.back());
2044 break;
Chris Lattner698f9252009-04-27 05:27:42 +00002045 }
Chris Lattner698f9252009-04-27 05:27:42 +00002046
Sebastian Redld527cc02010-08-18 23:56:48 +00002047 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00002048 LoadedDecl(Index, D);
2049 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00002050
2051 // If this declaration is also a declaration context, get the
2052 // offsets for its tables of lexical and visible declarations.
2053 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
2054 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
2055 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00002056 if (Offsets.first != 0)
2057 DC->setHasExternalLexicalStorage(true);
2058 if (Offsets.second != 0)
2059 DC->setHasExternalVisibleStorage(true);
2060 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
2061 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00002062 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00002063 }
Sebastian Redle1dde812010-08-24 00:50:04 +00002064
Sebastian Redl024e1c42011-04-24 16:27:54 +00002065 // Now add the pending visible updates for this decl context, if it has any.
2066 DeclContextVisibleUpdatesPending::iterator I =
2067 PendingVisibleUpdates.find(ID);
2068 if (I != PendingVisibleUpdates.end()) {
2069 // There are updates. This means the context has external visible
2070 // storage, even if the original stored version didn't.
2071 DC->setHasExternalVisibleStorage(true);
2072 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00002073 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
2074 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00002075 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00002076 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00002077 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00002078 }
2079 }
2080 assert(Idx == Record.size());
2081
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002082 // Load any relevant update records.
2083 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis5a174992011-11-14 07:07:59 +00002084
2085 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002086 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis5a174992011-11-14 07:07:59 +00002087 PendingChainedObjCCategories.push_back(
2088 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002089
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002090 // If we have deserialized a declaration that has a definition the
2091 // AST consumer might need to know about, queue it.
2092 // We don't pass it to the consumer immediately because we may be in recursive
2093 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00002094 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00002095 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00002096
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002097 return D;
2098}
2099
2100void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002101 // The declaration may have been modified by files later in the chain.
2102 // If this is the case, read the record containing the updates from each file
2103 // and pass it to ASTDeclReader to make the modifications.
2104 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
2105 if (UpdI != DeclUpdateOffsets.end()) {
2106 FileOffsetsTy &UpdateOffsets = UpdI->second;
2107 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002108 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002109 ModuleFile *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002110 uint64_t Offset = I->second;
2111 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
2112 SavedStreamPosition SavedPosition(Cursor);
2113 Cursor.JumpToBit(Offset);
2114 RecordData Record;
2115 unsigned Code = Cursor.ReadCode();
2116 unsigned RecCode = Cursor.ReadRecord(Code, Record);
2117 (void)RecCode;
2118 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002119
2120 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00002121 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00002122 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002123 }
2124 }
Chris Lattner698f9252009-04-27 05:27:42 +00002125}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002126
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002127namespace {
Douglas Gregora1be2782011-12-17 23:38:30 +00002128 struct CompareLocalRedeclarationsInfoToID {
2129 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) {
2130 return X.FirstID < Y;
2131 }
2132
2133 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) {
2134 return X < Y.FirstID;
2135 }
2136
2137 bool operator()(const LocalRedeclarationsInfo &X,
2138 const LocalRedeclarationsInfo &Y) {
2139 return X.FirstID < Y.FirstID;
2140 }
2141 bool operator()(DeclID X, DeclID Y) {
2142 return X < Y;
2143 }
2144 };
2145
Douglas Gregor0f753232011-12-22 01:48:48 +00002146 /// \brief Module visitor class that finds all of the redeclarations of a
2147 ///
Douglas Gregora1be2782011-12-17 23:38:30 +00002148 class RedeclChainVisitor {
2149 ASTReader &Reader;
Douglas Gregor0f753232011-12-22 01:48:48 +00002150 SmallVectorImpl<DeclID> &SearchDecls;
2151 GlobalDeclID CanonID;
Douglas Gregora1be2782011-12-17 23:38:30 +00002152 llvm::SmallVector<std::pair<Decl *, Decl *>, 4> Chains;
2153
2154 public:
Douglas Gregor0f753232011-12-22 01:48:48 +00002155 RedeclChainVisitor(ASTReader &Reader, SmallVectorImpl<DeclID> &SearchDecls,
2156 GlobalDeclID CanonID)
2157 : Reader(Reader), SearchDecls(SearchDecls), CanonID(CanonID) { }
Douglas Gregora1be2782011-12-17 23:38:30 +00002158
2159 static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
2160 if (Preorder)
2161 return false;
2162
2163 return static_cast<RedeclChainVisitor *>(UserData)->visit(M);
2164 }
2165
Douglas Gregor0f753232011-12-22 01:48:48 +00002166 void searchForID(ModuleFile &M, GlobalDeclID GlobalID) {
Douglas Gregora1be2782011-12-17 23:38:30 +00002167 // Map global ID of the first declaration down to the local ID
2168 // used in this module file.
Douglas Gregor0f753232011-12-22 01:48:48 +00002169 DeclID ID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalID);
2170 if (!ID)
2171 return;
Douglas Gregora1be2782011-12-17 23:38:30 +00002172
2173 // Perform a binary search to find the local redeclarations for this
2174 // declaration (if any).
2175 const LocalRedeclarationsInfo *Result
2176 = std::lower_bound(M.RedeclarationsInfo,
2177 M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos,
Douglas Gregor0f753232011-12-22 01:48:48 +00002178 ID, CompareLocalRedeclarationsInfoToID());
Douglas Gregora1be2782011-12-17 23:38:30 +00002179 if (Result == M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos ||
Douglas Gregor0f753232011-12-22 01:48:48 +00002180 Result->FirstID != ID) {
2181 // If we have a previously-canonical singleton declaration that was
2182 // merged into another redeclaration chain, create a trivial chain
2183 // for this single declaration so that it will get wired into the
2184 // complete redeclaration chain.
2185 if (GlobalID != CanonID &&
2186 GlobalID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID &&
2187 GlobalID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls) {
2188 if (Decl *D = Reader.GetDecl(GlobalID))
2189 Chains.push_back(std::make_pair(D, D));
2190 }
2191
2192 return;
2193 }
2194
Douglas Gregora1be2782011-12-17 23:38:30 +00002195 // Dig out the starting/ending declarations.
2196 Decl *FirstLocalDecl = Reader.GetLocalDecl(M, Result->FirstLocalID);
2197 Decl *LastLocalDecl = Reader.GetLocalDecl(M, Result->LastLocalID);
2198 if (!FirstLocalDecl || !LastLocalDecl)
Douglas Gregor0f753232011-12-22 01:48:48 +00002199 return;
Douglas Gregora1be2782011-12-17 23:38:30 +00002200
2201 // Append this redeclaration chain to the list.
2202 Chains.push_back(std::make_pair(FirstLocalDecl, LastLocalDecl));
Douglas Gregor0f753232011-12-22 01:48:48 +00002203 }
2204
2205 bool visit(ModuleFile &M) {
2206 // Visit each of the declarations.
2207 for (unsigned I = 0, N = SearchDecls.size(); I != N; ++I)
2208 searchForID(M, SearchDecls[I]);
Douglas Gregora1be2782011-12-17 23:38:30 +00002209 return false;
2210 }
2211
2212 ArrayRef<std::pair<Decl *, Decl *> > getChains() const {
2213 return Chains;
2214 }
2215
2216 void addParsed(Decl *FirstParsedDecl, Decl *LastParsedDecl) {
2217 Chains.push_back(std::make_pair(FirstParsedDecl, LastParsedDecl));
2218 }
2219 };
2220}
2221
2222/// \brief Retrieve the previous declaration to D.
2223static Decl *getPreviousDecl(Decl *D) {
2224 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2225 return TD->getPreviousDeclaration();
2226 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2227 return FD->getPreviousDeclaration();
2228 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2229 return VD->getPreviousDeclaration();
2230 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2231 return TD->getPreviousDeclaration();
2232 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2233 return ID->getPreviousDeclaration();
Douglas Gregor1d784b22012-01-01 19:51:50 +00002234 if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
2235 return PD->getPreviousDeclaration();
Douglas Gregora1be2782011-12-17 23:38:30 +00002236
2237 return cast<RedeclarableTemplateDecl>(D)->getPreviousDeclaration();
2238}
2239
2240/// \brief Retrieve the most recent declaration of D.
2241static Decl *getMostRecentDecl(Decl *D) {
2242 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2243 return TD->getMostRecentDeclaration();
2244 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2245 return FD->getMostRecentDeclaration();
2246 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2247 return VD->getMostRecentDeclaration();
2248 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2249 return TD->getMostRecentDeclaration();
2250 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2251 return ID->getMostRecentDeclaration();
Douglas Gregor1d784b22012-01-01 19:51:50 +00002252 if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
2253 return PD->getMostRecentDeclaration();
Douglas Gregora1be2782011-12-17 23:38:30 +00002254
2255 return cast<RedeclarableTemplateDecl>(D)->getMostRecentDeclaration();
2256}
2257
2258void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
Douglas Gregor0f753232011-12-22 01:48:48 +00002259 Decl *D = GetDecl(ID);
2260 Decl *CanonDecl = D->getCanonicalDecl();
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +00002261
Douglas Gregor0f753232011-12-22 01:48:48 +00002262 // Determine the set of declaration IDs we'll be searching for.
2263 llvm::SmallVector<DeclID, 1> SearchDecls;
2264 GlobalDeclID CanonID = 0;
2265 if (D == CanonDecl) {
2266 SearchDecls.push_back(ID); // Always first.
2267 CanonID = ID;
2268 }
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +00002269 MergedDeclsMap::iterator MergedPos = combineStoredMergedDecls(CanonDecl, ID);
Douglas Gregor0f753232011-12-22 01:48:48 +00002270 if (MergedPos != MergedDecls.end())
2271 SearchDecls.append(MergedPos->second.begin(), MergedPos->second.end());
2272
Douglas Gregora1be2782011-12-17 23:38:30 +00002273 // Build up the list of redeclaration chains.
Douglas Gregor0f753232011-12-22 01:48:48 +00002274 RedeclChainVisitor Visitor(*this, SearchDecls, CanonID);
Douglas Gregora1be2782011-12-17 23:38:30 +00002275 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor);
2276
2277 // Retrieve the chains.
2278 ArrayRef<std::pair<Decl *, Decl *> > Chains = Visitor.getChains();
2279 if (Chains.empty())
2280 return;
Douglas Gregor0f753232011-12-22 01:48:48 +00002281
Douglas Gregora1be2782011-12-17 23:38:30 +00002282 // Capture all of the parsed declarations and put them at the end.
2283 Decl *MostRecent = getMostRecentDecl(CanonDecl);
2284 Decl *FirstParsed = MostRecent;
2285 if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) {
2286 Decl *Current = MostRecent;
2287 while (Decl *Prev = getPreviousDecl(Current)) {
Douglas Gregor0f753232011-12-22 01:48:48 +00002288 if (Prev == CanonDecl)
2289 break;
2290
Douglas Gregora1be2782011-12-17 23:38:30 +00002291 if (Prev->isFromASTFile()) {
2292 Current = Prev;
2293 continue;
2294 }
Douglas Gregor0f753232011-12-22 01:48:48 +00002295
Douglas Gregora1be2782011-12-17 23:38:30 +00002296 // Chain all of the parsed declarations together.
2297 ASTDeclReader::attachPreviousDecl(FirstParsed, Prev);
2298 FirstParsed = Prev;
2299 Current = Prev;
2300 }
2301
2302 Visitor.addParsed(FirstParsed, MostRecent);
2303 }
Douglas Gregor0f753232011-12-22 01:48:48 +00002304
Douglas Gregora1be2782011-12-17 23:38:30 +00002305 // Hook up the separate chains.
2306 Chains = Visitor.getChains();
Douglas Gregor0f753232011-12-22 01:48:48 +00002307 if (Chains[0].first != CanonDecl)
2308 ASTDeclReader::attachPreviousDecl(Chains[0].first, CanonDecl);
Douglas Gregora1be2782011-12-17 23:38:30 +00002309 for (unsigned I = 1, N = Chains.size(); I != N; ++I)
2310 ASTDeclReader::attachPreviousDecl(Chains[I].first, Chains[I-1].second);
2311 ASTDeclReader::attachLatestDecl(CanonDecl, Chains.back().second);
2312}
2313
2314namespace {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002315 /// \brief Given an ObjC interface, goes through the modules and links to the
2316 /// interface all the categories for it.
2317 class ObjCChainedCategoriesVisitor {
2318 ASTReader &Reader;
2319 serialization::GlobalDeclID InterfaceID;
2320 ObjCInterfaceDecl *Interface;
2321 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
2322 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
2323
2324 public:
2325 ObjCChainedCategoriesVisitor(ASTReader &Reader,
2326 serialization::GlobalDeclID InterfaceID,
2327 ObjCInterfaceDecl *Interface)
2328 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
2329 GlobHeadCat(0), GlobTailCat(0) { }
2330
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002331 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002332 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
2333 }
2334
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002335 bool visit(ModuleFile &M) {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002336 if (Reader.isDeclIDFromModule(InterfaceID, M))
2337 return true; // We reached the module where the interface originated
2338 // from. Stop traversing the imported modules.
2339
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002340 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002341 I = M.ChainedObjCCategories.find(InterfaceID);
2342 if (I == M.ChainedObjCCategories.end())
2343 return false;
2344
2345 ObjCCategoryDecl *
2346 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
2347 ObjCCategoryDecl *
2348 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
2349
2350 addCategories(HeadCat, TailCat);
2351 return false;
2352 }
2353
2354 void addCategories(ObjCCategoryDecl *HeadCat,
2355 ObjCCategoryDecl *TailCat = 0) {
2356 if (!HeadCat) {
2357 assert(!TailCat);
2358 return;
2359 }
2360
2361 if (!TailCat) {
2362 TailCat = HeadCat;
2363 while (TailCat->getNextClassCategory())
2364 TailCat = TailCat->getNextClassCategory();
2365 }
2366
2367 if (!GlobHeadCat) {
2368 GlobHeadCat = HeadCat;
2369 GlobTailCat = TailCat;
2370 } else {
2371 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
2372 GlobTailCat = TailCat;
2373 }
2374
2375 llvm::DenseSet<DeclarationName> Checked;
2376 for (ObjCCategoryDecl *Cat = HeadCat,
2377 *CatEnd = TailCat->getNextClassCategory();
2378 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
2379 if (Checked.count(Cat->getDeclName()))
2380 continue;
2381 Checked.insert(Cat->getDeclName());
2382 checkForDuplicate(Cat);
2383 }
2384 }
2385
2386 /// \brief Warns for duplicate categories that come from different modules.
2387 void checkForDuplicate(ObjCCategoryDecl *Cat) {
2388 DeclarationName Name = Cat->getDeclName();
2389 // Find the top category with the same name. We do not want to warn for
2390 // duplicates along the established chain because there were already
2391 // warnings for them when the module was created. We only want to warn for
2392 // duplicates between non-dependent modules:
2393 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00002394 // MT //
2395 // / \ //
2396 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002397 //
2398 // We want to warn for duplicates between ML and MR,not between ML and MT.
2399 //
2400 // FIXME: We should not warn for duplicates in diamond:
2401 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00002402 // MT //
2403 // / \ //
2404 // ML MR //
2405 // \ / //
2406 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002407 //
2408 // If there are duplicates in ML/MR, there will be warning when creating
2409 // MB *and* when importing MB. We should not warn when importing.
2410 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
2411 Next = Next->getNextClassCategory()) {
2412 if (Next->getDeclName() == Name)
2413 Cat = Next;
2414 }
2415
2416 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2417 if (!PrevCat)
2418 PrevCat = Cat;
2419
2420 if (PrevCat != Cat) {
2421 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2422 << Interface->getDeclName() << Name;
2423 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2424 }
2425 }
2426
2427 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2428 };
2429}
2430
2431void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2432 ObjCInterfaceDecl *D) {
2433 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2434 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2435 // Also add the categories that the interface already links to.
2436 Visitor.addCategories(D->getCategoryList());
2437 D->setCategoryList(Visitor.getHeadCategory());
2438}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002439
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002440void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redlf79a7192011-04-29 08:19:30 +00002441 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002442 unsigned Idx = 0;
2443 while (Idx < Record.size()) {
2444 switch ((DeclUpdateKind)Record[Idx++]) {
2445 case UPD_CXX_SET_DEFINITIONDATA: {
2446 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00002447 CXXRecordDecl *DefinitionDecl
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002448 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002449 assert(!RD->DefinitionData && "DefinitionData is already set!");
2450 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2451 break;
2452 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00002453
2454 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002455 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00002456 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00002457
2458 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2459 // It will be added to the template's specializations set when loaded.
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002460 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00002461 break;
2462
2463 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00002464 NamespaceDecl *Anon
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002465 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00002466 // Guard against these being loaded out of original order. Don't use
2467 // getNextNamespace(), since it tries to access the context and can't in
2468 // the middle of deserialization.
2469 if (!Anon->NextNamespace) {
2470 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2471 TU->setAnonymousNamespace(Anon);
2472 else
2473 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2474 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00002475 break;
2476 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00002477
2478 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2479 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002480 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redlf79a7192011-04-29 08:19:30 +00002481 break;
Douglas Gregor53df7a12011-12-15 18:03:09 +00002482
2483 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2484 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2485 ObjCInterfaceDecl *Def
2486 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00002487 if (Def->Data)
Douglas Gregor26fec632011-12-15 18:17:27 +00002488 ID->Data = Def->Data;
Douglas Gregor53df7a12011-12-15 18:03:09 +00002489 break;
2490 }
Douglas Gregor1d784b22012-01-01 19:51:50 +00002491
2492 case UPD_OBJC_SET_PROTOCOL_DEFINITIONDATA: {
2493 ObjCProtocolDecl *ID = cast<ObjCProtocolDecl>(D);
2494 ObjCProtocolDecl *Def
2495 = Reader.ReadDeclAs<ObjCProtocolDecl>(ModuleFile, Record, Idx);
2496 if (Def->Data)
2497 ID->Data = Def->Data;
2498 break;
2499 }
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002500 }
2501 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002502}