blob: 38b69413ac0638c6dc3e175ea4d0435f27071b90 [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 VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
283 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
284 void VisitObjCImplDecl(ObjCImplDecl *D);
285 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
286 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
287 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
288 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
289 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
290 };
291}
292
Sebastian Redld527cc02010-08-18 23:56:48 +0000293uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregor8f1231b2011-07-22 06:10:01 +0000294 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redl577d4792010-07-22 22:43:28 +0000295}
296
Sebastian Redld527cc02010-08-18 23:56:48 +0000297void ASTDeclReader::Visit(Decl *D) {
298 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000299
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000300 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
301 if (DD->DeclInfo) {
302 DeclaratorDecl::ExtInfo *Info =
303 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
304 Info->TInfo =
305 GetTypeSourceInfo(Record, Idx);
306 }
307 else {
308 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
309 }
310 }
311
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000312 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000313 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor1ab55e92010-12-10 17:03:06 +0000314 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Douglas Gregor0af55012011-12-16 03:12:41 +0000315 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
316 // if we have a fully initialized TypeDecl, we can safely read its type now.
317 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000318 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
319 // FunctionDecl's body was written last after all other Stmts/Exprs.
320 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000321 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000322 } else if (D->isTemplateParameter()) {
323 // If we have a fully initialized template parameter, we can now
324 // set its DeclContext.
325 D->setDeclContext(
326 cast_or_null<DeclContext>(
327 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
328 D->setLexicalDeclContext(
329 cast_or_null<DeclContext>(
330 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000331 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000332}
333
Sebastian Redld527cc02010-08-18 23:56:48 +0000334void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor67da6f62011-03-05 01:35:54 +0000335 if (D->isTemplateParameter()) {
336 // We don't want to deserialize the DeclContext of a template
337 // parameter immediately, because the template parameter might be
338 // used in the formulation of its DeclContext. Use the translation
339 // unit DeclContext as a placeholder.
Douglas Gregor409448c2011-07-21 22:35:25 +0000340 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
341 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000342 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000343 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000344 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
345 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor67da6f62011-03-05 01:35:54 +0000346 }
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000347 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner698f9252009-04-27 05:27:42 +0000348 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000349 if (Record[Idx++]) { // hasAttrs
Sean Huntcf807c42010-08-18 23:23:40 +0000350 AttrVec Attrs;
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000351 Reader.ReadAttributes(F, Attrs, Record, Idx);
Sean Huntcf807c42010-08-18 23:23:40 +0000352 D->setAttrs(Attrs);
353 }
Chris Lattner698f9252009-04-27 05:27:42 +0000354 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000355 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis6b6b42a2011-04-19 19:51:10 +0000356 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidisc14a03d2011-11-23 20:27:36 +0000357 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000358 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor08e0bc12011-09-10 00:09:20 +0000359 D->FromASTFile = true;
Douglas Gregor8d267c52011-09-09 02:06:17 +0000360 D->ModulePrivate = Record[Idx++];
Douglas Gregorecc2c092011-12-01 22:20:10 +0000361
362 // Determine whether this declaration is part of a (sub)module. If so, it
363 // may not yet be visible.
364 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
365 // Module-private declarations are never visible, so there is no work to do.
366 if (!D->ModulePrivate) {
367 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
368 if (Owner->NameVisibility != Module::AllVisible) {
369 // The owning module is not visible. Mark this declaration as
370 // module-private,
371 D->ModulePrivate = true;
372
373 // Note that this declaration was hidden because its owning module is
374 // not yet visible.
375 Reader.HiddenNamesMap[Owner].push_back(D);
376 }
377 }
378 }
379 }
Chris Lattner698f9252009-04-27 05:27:42 +0000380}
381
Sebastian Redld527cc02010-08-18 23:56:48 +0000382void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +0000383 llvm_unreachable("Translation units are not serialized");
Chris Lattner698f9252009-04-27 05:27:42 +0000384}
385
Sebastian Redld527cc02010-08-18 23:56:48 +0000386void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner698f9252009-04-27 05:27:42 +0000387 VisitDecl(ND);
Douglas Gregor393f2492011-07-22 00:38:23 +0000388 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000389}
390
Sebastian Redld527cc02010-08-18 23:56:48 +0000391void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000392 VisitNamedDecl(TD);
Abramo Bagnara344577e2011-03-06 15:48:19 +0000393 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000394 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor393f2492011-07-22 00:38:23 +0000395 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000396}
397
Douglas Gregor0f456822011-12-19 14:40:25 +0000398void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregora1be2782011-12-17 23:38:30 +0000399 VisitRedeclarable(TD);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000400 VisitTypeDecl(TD);
Douglas Gregor0f456822011-12-19 14:40:25 +0000401 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
402}
403
404void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
405 VisitTypedefNameDecl(TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000406}
407
Richard Smith162e1c12011-04-15 14:24:37 +0000408void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Douglas Gregor0f456822011-12-19 14:40:25 +0000409 VisitTypedefNameDecl(TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000410}
411
Sebastian Redld527cc02010-08-18 23:56:48 +0000412void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000413 VisitRedeclarable(TD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000414 VisitTypeDecl(TD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000415 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000416 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCall5e1cdac2011-10-07 06:10:15 +0000417 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000418 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis717a20b2011-09-30 22:11:31 +0000419 TD->setFreeStanding(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000420 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000421 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor35942772011-09-09 21:34:22 +0000422 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000423 ReadQualifierInfo(*Info, Record, Idx);
Richard Smith162e1c12011-04-15 14:24:37 +0000424 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000425 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000426 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000427}
428
Sebastian Redld527cc02010-08-18 23:56:48 +0000429void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000430 VisitTagDecl(ED);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000431 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
432 ED->setIntegerTypeSourceInfo(TI);
433 else
Douglas Gregor393f2492011-07-22 00:38:23 +0000434 ED->setIntegerType(Reader.readType(F, Record, Idx));
435 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall1b5a6182010-05-06 08:49:23 +0000436 ED->setNumPositiveBits(Record[Idx++]);
437 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000438 ED->IsScoped = Record[Idx++];
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000439 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000440 ED->IsFixed = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000441 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000442}
443
Sebastian Redld527cc02010-08-18 23:56:48 +0000444void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000445 VisitTagDecl(RD);
446 RD->setHasFlexibleArrayMember(Record[Idx++]);
447 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000448 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000449}
450
Sebastian Redld527cc02010-08-18 23:56:48 +0000451void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000452 VisitNamedDecl(VD);
Douglas Gregor393f2492011-07-22 00:38:23 +0000453 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000454}
455
Sebastian Redld527cc02010-08-18 23:56:48 +0000456void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000457 VisitValueDecl(ECD);
458 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000459 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000460 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
461}
462
Sebastian Redld527cc02010-08-18 23:56:48 +0000463void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000464 VisitValueDecl(DD);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000465 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000466 if (Record[Idx++]) { // hasExtInfo
467 DeclaratorDecl::ExtInfo *Info
Douglas Gregor35942772011-09-09 21:34:22 +0000468 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000469 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000470 DD->DeclInfo = Info;
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000471 }
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000472}
473
Sebastian Redld527cc02010-08-18 23:56:48 +0000474void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000475 VisitRedeclarable(FD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000476 VisitDeclaratorDecl(FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000477
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000478 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000479 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000480 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000481 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000482 case FunctionDecl::TK_NonTemplate:
483 break;
484 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000485 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
486 Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000487 break;
488 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000489 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000490 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000491 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000492 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000493 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
494 break;
495 }
496 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000497 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
498 Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000499 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
500
501 // Template arguments.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000502 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000503 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000504
505 // Template args as written.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000506 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000507 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000508 bool HasTemplateArgumentsAsWritten = Record[Idx++];
509 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000510 unsigned NumTemplateArgLocs = Record[Idx++];
511 TemplArgLocs.reserve(NumTemplateArgLocs);
512 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000513 TemplArgLocs.push_back(
Sebastian Redlc3632732010-10-05 15:59:54 +0000514 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000515
Sebastian Redlc3632732010-10-05 15:59:54 +0000516 LAngleLoc = ReadSourceLocation(Record, Idx);
517 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000518 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000519
Sebastian Redlc3632732010-10-05 15:59:54 +0000520 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000521
Douglas Gregor35942772011-09-09 21:34:22 +0000522 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000523 TemplateArgumentList *TemplArgList
Douglas Gregor910f8002010-11-07 23:05:16 +0000524 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000525 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000526 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000527 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000528 FunctionTemplateSpecializationInfo *FTInfo
529 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
530 TemplArgList,
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000531 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
532 POI);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000533 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000534
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000535 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000536 // The template that contains the specializations set. It's not safe to
537 // use getCanonicalDecl on Template since it may still be initializing.
538 FunctionTemplateDecl *CanonTemplate
Douglas Gregor409448c2011-07-21 22:35:25 +0000539 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000540 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
541 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
542 // FunctionTemplateSpecializationInfo's Profile().
543 // We avoid getASTContext because a decl in the parent hierarchy may
544 // be initializing.
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000545 llvm::FoldingSetNodeID ID;
546 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
547 TemplArgs.size(), C);
548 void *InsertPos = 0;
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000549 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000550 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000551 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000552 }
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000553 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000554 }
555 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
556 // Templates.
557 UnresolvedSet<8> TemplDecls;
558 unsigned NumTemplates = Record[Idx++];
559 while (NumTemplates--)
Douglas Gregor409448c2011-07-21 22:35:25 +0000560 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000561
562 // Templates args.
563 TemplateArgumentListInfo TemplArgs;
564 unsigned NumArgs = Record[Idx++];
565 while (NumArgs--)
Sebastian Redlc3632732010-10-05 15:59:54 +0000566 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
567 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
568 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000569
Douglas Gregor35942772011-09-09 21:34:22 +0000570 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000571 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000572 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000573 }
574 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000575
Sebastian Redld527cc02010-08-18 23:56:48 +0000576 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000577 // after everything else is read.
578
Douglas Gregor381d34e2010-12-06 18:36:25 +0000579 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000580 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregor8f150942010-12-09 16:59:22 +0000581 FD->IsInline = Record[Idx++];
582 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000583 FD->IsVirtualAsWritten = Record[Idx++];
584 FD->IsPure = Record[Idx++];
585 FD->HasInheritedPrototype = Record[Idx++];
586 FD->HasWrittenPrototype = Record[Idx++];
587 FD->IsDeleted = Record[Idx++];
588 FD->IsTrivial = Record[Idx++];
Sean Hunt2be7e902011-05-12 22:46:29 +0000589 FD->IsDefaulted = Record[Idx++];
590 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000591 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smithaf1fc7a2011-08-15 21:04:07 +0000592 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000593 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000594
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000595 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000596 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000597 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000598 Params.reserve(NumParams);
599 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000600 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000601 FD->setParams(Reader.getContext(), Params);
Chris Lattner698f9252009-04-27 05:27:42 +0000602}
603
Sebastian Redld527cc02010-08-18 23:56:48 +0000604void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000605 VisitNamedDecl(MD);
606 if (Record[Idx++]) {
607 // In practice, this won't be executed (since method definitions
608 // don't occur in header files).
Sebastian Redlc3632732010-10-05 15:59:54 +0000609 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor409448c2011-07-21 22:35:25 +0000610 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
611 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000612 }
613 MD->setInstanceMethod(Record[Idx++]);
614 MD->setVariadic(Record[Idx++]);
615 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000616 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000617
618 MD->IsRedeclaration = Record[Idx++];
619 MD->HasRedeclaration = Record[Idx++];
620 if (MD->HasRedeclaration)
621 Reader.getContext().setObjCMethodRedeclaration(MD,
622 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
623
Chris Lattner698f9252009-04-27 05:27:42 +0000624 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
625 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000626 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000627 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000628 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
629 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000630 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000631 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000632 Params.reserve(NumParams);
633 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000634 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000635
636 MD->SelLocsKind = Record[Idx++];
637 unsigned NumStoredSelLocs = Record[Idx++];
638 SmallVector<SourceLocation, 16> SelLocs;
639 SelLocs.reserve(NumStoredSelLocs);
640 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
641 SelLocs.push_back(ReadSourceLocation(Record, Idx));
642
643 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner698f9252009-04-27 05:27:42 +0000644}
645
Sebastian Redld527cc02010-08-18 23:56:48 +0000646void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000647 VisitNamedDecl(CD);
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000648 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
649 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000650}
651
Sebastian Redld527cc02010-08-18 23:56:48 +0000652void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregorcce54aa2011-12-22 19:44:59 +0000653 // Record the declaration -> global ID mapping.
654 Reader.DeclToID[ID] = ThisDeclID;
655
Douglas Gregor0f753232011-12-22 01:48:48 +0000656 RedeclarableResult Redecl = VisitRedeclarable(ID);
Chris Lattner698f9252009-04-27 05:27:42 +0000657 VisitObjCContainerDecl(ID);
Douglas Gregor0af55012011-12-16 03:12:41 +0000658 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Douglas Gregorcce54aa2011-12-22 19:44:59 +0000659
Douglas Gregor0f753232011-12-22 01:48:48 +0000660 // Determine whether we need to merge this declaration with another @interface
661 // with the same name.
662 // FIXME: Not needed unless the module file graph is a DAG.
663 if (FindExistingResult ExistingRes = findExisting(ID)) {
664 if (ObjCInterfaceDecl *Existing = ExistingRes) {
665 ObjCInterfaceDecl *ExistingCanon = Existing->getCanonicalDecl();
666 ObjCInterfaceDecl *IDCanon = ID->getCanonicalDecl();
667 if (ExistingCanon != IDCanon) {
668 // Have our redeclaration link point back at the canonical declaration
669 // of the existing declaration, so that this declaration has the
670 // appropriate canonical declaration.
671 ID->RedeclLink = ObjCInterfaceDecl::PreviousDeclLink(ExistingCanon);
672
Douglas Gregorcce54aa2011-12-22 19:44:59 +0000673 // Don't introduce IDCanon into the set of pending declaration chains.
674 Redecl.suppress();
675
676 // Introduce ExistingCanon into the set of pending declaration chains,
677 // if in fact it came from a module file.
678 if (ExistingCanon->isFromASTFile()) {
679 GlobalDeclID ExistingCanonID = Reader.DeclToID[ExistingCanon];
680 assert(ExistingCanonID && "Unrecorded canonical declaration ID?");
681 if (Reader.PendingDeclChainsKnown.insert(ExistingCanonID))
682 Reader.PendingDeclChains.push_back(ExistingCanonID);
683 }
684
Douglas Gregor0f753232011-12-22 01:48:48 +0000685 // If this declaration was the canonical declaration, make a note of
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +0000686 // that. We accept the linear algorithm here because the number of
687 // unique canonical declarations of an entity should always be tiny.
688 if (IDCanon == ID) {
689 SmallVectorImpl<DeclID> &Merged = Reader.MergedDecls[ExistingCanon];
690 if (std::find(Merged.begin(), Merged.end(), Redecl.getFirstID())
691 == Merged.end())
692 Merged.push_back(Redecl.getFirstID());
693 }
Douglas Gregor0f753232011-12-22 01:48:48 +0000694 }
695 }
696 }
697
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000698 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
699 if (ID == Def) {
700 // Read the definition.
701 ID->allocateDefinitionData();
702
703 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
704
705 // Read the superclass.
706 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
707 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
708
Douglas Gregor05c272f2011-12-15 22:34:59 +0000709 Data.EndLoc = ReadSourceLocation(Record, Idx);
710
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000711 // Read the directly referenced protocols and their SourceLocations.
712 unsigned NumProtocols = Record[Idx++];
713 SmallVector<ObjCProtocolDecl *, 16> Protocols;
714 Protocols.reserve(NumProtocols);
715 for (unsigned I = 0; I != NumProtocols; ++I)
716 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
717 SmallVector<SourceLocation, 16> ProtoLocs;
718 ProtoLocs.reserve(NumProtocols);
719 for (unsigned I = 0; I != NumProtocols; ++I)
720 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
721 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
722 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000723
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000724 // Read the transitive closure of protocols referenced by this class.
725 NumProtocols = Record[Idx++];
726 Protocols.clear();
727 Protocols.reserve(NumProtocols);
728 for (unsigned I = 0; I != NumProtocols; ++I)
729 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
730 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
731 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000732
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000733 // Read the ivars.
734 unsigned NumIvars = Record[Idx++];
735 SmallVector<ObjCIvarDecl *, 16> IVars;
736 IVars.reserve(NumIvars);
737 for (unsigned I = 0; I != NumIvars; ++I)
738 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
739
740 // Read the categories.
741 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000742
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000743 // We will rebuild this list lazily.
744 ID->setIvarList(0);
745
Douglas Gregor21cf08b2011-12-19 20:51:16 +0000746 // Note that we have deserialized a definition.
747 Reader.PendingDefinitions.insert(ID);
748 } else if (Def && Def->Data) {
749 ID->Data = Def->Data;
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000750 }
Chris Lattner698f9252009-04-27 05:27:42 +0000751}
752
Sebastian Redld527cc02010-08-18 23:56:48 +0000753void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000754 VisitFieldDecl(IVD);
755 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000756 // This field will be built lazily.
757 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000758 bool synth = Record[Idx++];
759 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000760}
761
Sebastian Redld527cc02010-08-18 23:56:48 +0000762void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Douglas Gregor1d784b22012-01-01 19:51:50 +0000763 VisitRedeclarable(PD);
Chris Lattner698f9252009-04-27 05:27:42 +0000764 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000765 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000766 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000767 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +0000768
769 ObjCProtocolDecl *Def = ReadDeclAs<ObjCProtocolDecl>(Record, Idx);
770 if (PD == Def) {
771 // Read the definition.
772 PD->allocateDefinitionData();
773
774 unsigned NumProtoRefs = Record[Idx++];
775 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
776 ProtoRefs.reserve(NumProtoRefs);
777 for (unsigned I = 0; I != NumProtoRefs; ++I)
778 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
779 SmallVector<SourceLocation, 16> ProtoLocs;
780 ProtoLocs.reserve(NumProtoRefs);
781 for (unsigned I = 0; I != NumProtoRefs; ++I)
782 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
783 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
784 Reader.getContext());
785
Douglas Gregor1d784b22012-01-01 19:51:50 +0000786 // Note that we have deserialized a definition.
787 Reader.PendingDefinitions.insert(PD);
Douglas Gregor5e2a1ff2012-01-01 19:29:29 +0000788 } else if (Def && Def->Data) {
789 PD->Data = Def->Data;
790 }
Chris Lattner698f9252009-04-27 05:27:42 +0000791}
792
Sebastian Redld527cc02010-08-18 23:56:48 +0000793void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000794 VisitFieldDecl(FD);
795}
796
Sebastian Redld527cc02010-08-18 23:56:48 +0000797void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000798 VisitDecl(FPD);
799 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000800 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000801 ProtoRefs.reserve(NumProtoRefs);
802 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000803 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000804 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000805 ProtoLocs.reserve(NumProtoRefs);
806 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000807 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000808 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000809 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000810}
811
Sebastian Redld527cc02010-08-18 23:56:48 +0000812void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000813 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000814 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000815 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000816 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000817 ProtoRefs.reserve(NumProtoRefs);
818 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000819 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000820 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000821 ProtoLocs.reserve(NumProtoRefs);
822 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000823 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000824 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000825 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000826 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000827 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000828 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000829}
830
Sebastian Redld527cc02010-08-18 23:56:48 +0000831void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000832 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000833 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000834}
835
Sebastian Redld527cc02010-08-18 23:56:48 +0000836void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000837 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000838 D->setAtLoc(ReadSourceLocation(Record, Idx));
839 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000840 // FIXME: stable encoding
841 D->setPropertyAttributes(
842 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000843 D->setPropertyAttributesAsWritten(
844 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000845 // FIXME: stable encoding
846 D->setPropertyImplementation(
847 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000848 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
849 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000850 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
851 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
852 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000853}
854
Sebastian Redld527cc02010-08-18 23:56:48 +0000855void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000856 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000857 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000858}
859
Sebastian Redld527cc02010-08-18 23:56:48 +0000860void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000861 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000862 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +0000863 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000864}
865
Sebastian Redld527cc02010-08-18 23:56:48 +0000866void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000867 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000868 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000869 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000870 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000871 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000872}
873
874
Sebastian Redld527cc02010-08-18 23:56:48 +0000875void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000876 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000877 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000878 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
879 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000880 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000881 D->setGetterCXXConstructor(Reader.ReadExpr(F));
882 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000883}
884
Sebastian Redld527cc02010-08-18 23:56:48 +0000885void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000886 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000887 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000888 int BitWidthOrInitializer = Record[Idx++];
889 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000890 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000891 else if (BitWidthOrInitializer == 2)
892 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000893 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000894 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000895 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000896 }
Chris Lattner698f9252009-04-27 05:27:42 +0000897}
898
Francois Pichet87c2e122010-11-21 06:08:52 +0000899void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
900 VisitValueDecl(FD);
901
902 FD->ChainingSize = Record[Idx++];
903 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000904 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000905
906 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000907 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000908}
909
Sebastian Redld527cc02010-08-18 23:56:48 +0000910void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000911 VisitRedeclarable(VD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000912 VisitDeclaratorDecl(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000913 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
914 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
915 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
916 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
917 VD->VarDeclBits.ExceptionVar = Record[Idx++];
918 VD->VarDeclBits.NRVOVariable = Record[Idx++];
919 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000920 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smith099e7f62011-12-19 06:19:21 +0000921 if (uint64_t Val = Record[Idx++]) {
Sebastian Redlc3632732010-10-05 15:59:54 +0000922 VD->setInit(Reader.ReadExpr(F));
Richard Smith099e7f62011-12-19 06:19:21 +0000923 if (Val > 1) {
924 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
925 Eval->CheckedICE = true;
926 Eval->IsICE = Val == 3;
927 }
928 }
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000929
930 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000931 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000932 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000933 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000934 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000935 }
Chris Lattner698f9252009-04-27 05:27:42 +0000936}
937
Sebastian Redld527cc02010-08-18 23:56:48 +0000938void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000939 VisitVarDecl(PD);
940}
941
Sebastian Redld527cc02010-08-18 23:56:48 +0000942void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000943 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000944 unsigned isObjCMethodParam = Record[Idx++];
945 unsigned scopeDepth = Record[Idx++];
946 unsigned scopeIndex = Record[Idx++];
947 unsigned declQualifier = Record[Idx++];
948 if (isObjCMethodParam) {
949 assert(scopeDepth == 0);
950 PD->setObjCMethodScopeInfo(scopeIndex);
951 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
952 } else {
953 PD->setScopeInfo(scopeDepth, scopeIndex);
954 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000955 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
956 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000957 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000958 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000959}
960
Sebastian Redld527cc02010-08-18 23:56:48 +0000961void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000962 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000963 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000964 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000965}
966
Sebastian Redld527cc02010-08-18 23:56:48 +0000967void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000968 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000969 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
970 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000971 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000972 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000973 Params.reserve(NumParams);
974 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000975 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000976 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000977
978 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000979 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000980 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000981 captures.reserve(numCaptures);
982 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000983 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +0000984 unsigned flags = Record[Idx++];
985 bool byRef = (flags & 1);
986 bool nested = (flags & 2);
987 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
988
989 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
990 }
Douglas Gregor35942772011-09-09 21:34:22 +0000991 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000992 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000993}
994
Sebastian Redld527cc02010-08-18 23:56:48 +0000995void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000996 VisitDecl(D);
997 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000998 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000999 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001000}
1001
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001002void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
1003 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +00001004 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001005}
1006
1007
Sebastian Redld527cc02010-08-18 23:56:48 +00001008void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001009 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +00001010 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001011 D->LocStart = ReadSourceLocation(Record, Idx);
1012 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +00001013 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001014
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001015 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001016 // FIXME: Modules will likely have trouble with pointing directly at
1017 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +00001018 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +00001019 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001020}
1021
Sebastian Redld527cc02010-08-18 23:56:48 +00001022void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001023 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001024 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +00001025 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001026 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001027 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001028}
1029
Sebastian Redld527cc02010-08-18 23:56:48 +00001030void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001031 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001032 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +00001033 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001034 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001035 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001036 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +00001037 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001038 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001039}
1040
Sebastian Redld527cc02010-08-18 23:56:48 +00001041void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001042 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +00001043 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
1044 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
1045 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001046 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +00001047 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001048}
1049
Sebastian Redld527cc02010-08-18 23:56:48 +00001050void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001051 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001052 D->UsingLoc = ReadSourceLocation(Record, Idx);
1053 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +00001054 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +00001055 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
1056 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001057}
1058
Sebastian Redld527cc02010-08-18 23:56:48 +00001059void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001060 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001061 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +00001062 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +00001063 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001064}
1065
Sebastian Redld527cc02010-08-18 23:56:48 +00001066void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001067 UnresolvedUsingTypenameDecl *D) {
1068 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001069 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +00001070 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001071}
1072
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001073void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001074 struct CXXRecordDecl::DefinitionData &Data,
1075 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001076 Data.UserDeclaredConstructor = Record[Idx++];
1077 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001078 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001079 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001080 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001081 Data.UserDeclaredDestructor = Record[Idx++];
1082 Data.Aggregate = Record[Idx++];
1083 Data.PlainOldData = Record[Idx++];
1084 Data.Empty = Record[Idx++];
1085 Data.Polymorphic = Record[Idx++];
1086 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +00001087 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +00001088 Data.HasNoNonEmptyBases = Record[Idx++];
1089 Data.HasPrivateFields = Record[Idx++];
1090 Data.HasProtectedFields = Record[Idx++];
1091 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +00001092 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +00001093 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +00001094 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001095 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +00001096 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001097 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +00001098 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001099 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +00001100 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001101 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +00001102 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001103 Data.DeclaredDefaultConstructor = Record[Idx++];
1104 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001105 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001106 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +00001107 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001108 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +00001109 Data.FailedImplicitMoveConstructor = Record[Idx++];
1110 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +00001111
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001112 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +00001113 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +00001114 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001115 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +00001116 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +00001117 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +00001118
Douglas Gregor409448c2011-07-21 22:35:25 +00001119 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
1120 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001121 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +00001122 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +00001123}
1124
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001125void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
1126 CXXRecordDecl *DefinitionDecl,
1127 const RecordData &Record,
1128 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +00001129 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +00001130
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +00001131 if (D == DefinitionDecl) {
1132 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001133 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00001134
Douglas Gregorfc529f72011-12-19 19:00:47 +00001135 // Note that we have deserialized a definition.
1136 Reader.PendingDefinitions.insert(D);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00001137 } else if (DefinitionDecl && DefinitionDecl->DefinitionData) {
1138 D->DefinitionData = DefinitionDecl->DefinitionData;
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +00001139 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001140}
1141
1142void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1143 VisitRecordDecl(D);
1144
Douglas Gregor409448c2011-07-21 22:35:25 +00001145 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001146 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1147
Douglas Gregor35942772011-09-09 21:34:22 +00001148 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +00001149
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001150 enum CXXRecKind {
1151 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1152 };
1153 switch ((CXXRecKind)Record[Idx++]) {
1154 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001155 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001156 case CXXRecNotTemplate:
1157 break;
1158 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +00001159 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001160 break;
1161 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001162 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001163 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001164 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +00001165 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1166 MSI->setPointOfInstantiation(POI);
1167 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001168 break;
1169 }
1170 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +00001171
1172 // Load the key function to avoid deserializing every method so we can
1173 // compute it.
John McCall5e1cdac2011-10-07 06:10:15 +00001174 if (D->IsCompleteDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001175 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +00001176 C.KeyFunctions[D] = Key;
1177 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001178}
1179
Sebastian Redld527cc02010-08-18 23:56:48 +00001180void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001181 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001182 unsigned NumOverridenMethods = Record[Idx++];
1183 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001184 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1185 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +00001186 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001187 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001188 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001189}
1190
Sebastian Redld527cc02010-08-18 23:56:48 +00001191void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001192 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001193
1194 D->IsExplicitSpecified = Record[Idx++];
1195 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001196 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1197 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001198}
1199
Sebastian Redld527cc02010-08-18 23:56:48 +00001200void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001201 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001202
1203 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001204 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001205}
1206
Sebastian Redld527cc02010-08-18 23:56:48 +00001207void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001208 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001209 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001210}
1211
Douglas Gregor15de72c2011-12-02 23:23:56 +00001212void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1213 VisitDecl(D);
1214 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1215 D->ImportedAndComplete.setInt(Record[Idx++]);
1216 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1217 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1218 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1219 ++Idx;
1220}
1221
Sebastian Redld527cc02010-08-18 23:56:48 +00001222void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001223 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001224 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001225}
1226
Sebastian Redld527cc02010-08-18 23:56:48 +00001227void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001228 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001229 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001230 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001231 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001232 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001233 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001234 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001235 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001236}
1237
Sebastian Redld527cc02010-08-18 23:56:48 +00001238void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001239 VisitDecl(D);
1240 unsigned NumParams = Record[Idx++];
1241 D->NumParams = NumParams;
1242 D->Params = new TemplateParameterList*[NumParams];
1243 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001244 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001245 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001246 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001247 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001248 D->Friend = GetTypeSourceInfo(Record, Idx);
1249 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001250}
1251
Sebastian Redld527cc02010-08-18 23:56:48 +00001252void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001253 VisitNamedDecl(D);
1254
Douglas Gregor409448c2011-07-21 22:35:25 +00001255 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001256 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001257 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001258 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001259}
1260
Sebastian Redld527cc02010-08-18 23:56:48 +00001261void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001262 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1263 // can be used while this is still initializing.
Douglas Gregorfc529f72011-12-19 19:00:47 +00001264 enum RedeclKind { FirstDeclaration, FirstInFile, PointsToPrevious };
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001265 RedeclKind Kind = (RedeclKind)Record[Idx++];
1266
1267 // Determine the first declaration ID.
1268 DeclID FirstDeclID;
1269 switch (Kind) {
1270 case FirstDeclaration: {
1271 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001272
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001273 // Since this is the first declaration of the template, fill in the
1274 // information for the 'common' pointer.
1275 if (D->CommonOrPrev.isNull()) {
1276 RedeclarableTemplateDecl::CommonBase *Common
1277 = D->newCommon(Reader.getContext());
1278 Common->Latest = D;
1279 D->CommonOrPrev = Common;
1280 }
Douglas Gregor0f753232011-12-22 01:48:48 +00001281
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001282 if (RedeclarableTemplateDecl *RTD
Douglas Gregor0f753232011-12-22 01:48:48 +00001283 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001284 assert(RTD->getKind() == D->getKind() &&
1285 "InstantiatedFromMemberTemplate kind mismatch");
1286 D->setInstantiatedFromMemberTemplateImpl(RTD);
1287 if (Record[Idx++])
1288 D->setMemberSpecialization();
1289 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001290 break;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001291 }
Douglas Gregorfc529f72011-12-19 19:00:47 +00001292
1293 case FirstInFile:
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001294 case PointsToPrevious: {
1295 FirstDeclID = ReadDeclID(Record, Idx);
1296 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1297
1298 RedeclarableTemplateDecl *FirstDecl
1299 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1300
1301 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1302 // We temporarily set the first (canonical) declaration as the previous one
1303 // which is the one that matters and mark the real previous DeclID to be
1304 // loaded and attached later on.
1305 D->CommonOrPrev = FirstDecl;
1306
Douglas Gregorfc529f72011-12-19 19:00:47 +00001307 if (Kind == PointsToPrevious) {
1308 // Make a note that we need to wire up this declaration to its
1309 // previous declaration, later. We don't need to do this for the first
1310 // declaration in any given module file, because those will be wired
1311 // together later.
1312 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PrevDeclID));
1313 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001314 break;
1315 }
1316 }
1317
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001318 VisitTemplateDecl(D);
1319 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001320}
1321
Sebastian Redld527cc02010-08-18 23:56:48 +00001322void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001323 VisitRedeclarableTemplateDecl(D);
1324
1325 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001326 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1327 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001328 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001329 SpecIDs.push_back(0);
1330
1331 // Specializations.
1332 unsigned Size = Record[Idx++];
1333 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001334 for (unsigned I = 0; I != Size; ++I)
1335 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001336
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001337 // Partial specializations.
1338 Size = Record[Idx++];
1339 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001340 for (unsigned I = 0; I != Size; ++I)
1341 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001342
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001343 if (SpecIDs[0]) {
1344 typedef serialization::DeclID DeclID;
1345
1346 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1347 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001348 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001349 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1350 SpecIDs.size() * sizeof(DeclID));
1351 }
1352
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001353 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001354 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001355}
1356
Sebastian Redld527cc02010-08-18 23:56:48 +00001357void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001358 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001359 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001360
Douglas Gregor35942772011-09-09 21:34:22 +00001361 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001362 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001363 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001364 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001365 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001366 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001367 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001368 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001369 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1370 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001371 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1372 = new (C) ClassTemplateSpecializationDecl::
1373 SpecializedPartialSpecialization();
1374 PS->PartialSpecialization
1375 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1376 PS->TemplateArgs = ArgList;
1377 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001378 }
1379 }
1380
1381 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001382 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001383 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1384 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1385 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001386 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1387 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001388 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001389 }
1390
Chris Lattner5f9e2722011-07-23 10:55:15 +00001391 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001392 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001393 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1394 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001395 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001396 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001397
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001398 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001399 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001400 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001401 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1402 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001403 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001404 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001405 }
1406 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001407}
1408
Sebastian Redld527cc02010-08-18 23:56:48 +00001409void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001410 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001411 VisitClassTemplateSpecializationDecl(D);
1412
Douglas Gregor35942772011-09-09 21:34:22 +00001413 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001414 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001415
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001416 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001417 if (NumArgs) {
1418 D->NumArgsAsWritten = NumArgs;
1419 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1420 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001421 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001422 }
1423
1424 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001425
1426 // These are read/set from/to the first declaration.
1427 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001428 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001429 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001430 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001431 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001432}
1433
Sebastian Redl14c36332011-08-31 13:59:56 +00001434void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1435 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001436 VisitDecl(D);
1437 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1438}
1439
Sebastian Redld527cc02010-08-18 23:56:48 +00001440void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001441 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001442
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001443 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001444 // This FunctionTemplateDecl owns a CommonPtr; read it.
1445
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001446 // Read the function specialization declarations.
1447 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001448 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001449 unsigned NumSpecs = Record[Idx++];
1450 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001451 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001452 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001453}
1454
Sebastian Redld527cc02010-08-18 23:56:48 +00001455void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001456 VisitTypeDecl(D);
1457
1458 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001459
1460 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001461 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001462 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001463}
1464
Sebastian Redld527cc02010-08-18 23:56:48 +00001465void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001466 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001467 // TemplateParmPosition.
1468 D->setDepth(Record[Idx++]);
1469 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001470 if (D->isExpandedParameterPack()) {
1471 void **Data = reinterpret_cast<void **>(D + 1);
1472 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001473 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001474 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1475 }
1476 } else {
1477 // Rest of NonTypeTemplateParmDecl.
1478 D->ParameterPack = Record[Idx++];
1479 if (Record[Idx++]) {
1480 Expr *DefArg = Reader.ReadExpr(F);
1481 bool Inherited = Record[Idx++];
1482 D->setDefaultArgument(DefArg, Inherited);
1483 }
1484 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001485}
1486
Sebastian Redld527cc02010-08-18 23:56:48 +00001487void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001488 VisitTemplateDecl(D);
1489 // TemplateParmPosition.
1490 D->setDepth(Record[Idx++]);
1491 D->setPosition(Record[Idx++]);
1492 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001493 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001494 bool IsInherited = Record[Idx++];
1495 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001496 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001497}
1498
Richard Smith3e4c6c42011-05-05 21:57:07 +00001499void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1500 VisitRedeclarableTemplateDecl(D);
1501}
1502
Sebastian Redld527cc02010-08-18 23:56:48 +00001503void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001504 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001505 D->AssertExpr = Reader.ReadExpr(F);
1506 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001507 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001508}
1509
Mike Stump1eb44332009-09-09 15:08:12 +00001510std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001511ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001512 uint64_t LexicalOffset = Record[Idx++];
1513 uint64_t VisibleOffset = Record[Idx++];
1514 return std::make_pair(LexicalOffset, VisibleOffset);
1515}
1516
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001517template <typename T>
Douglas Gregor0f753232011-12-22 01:48:48 +00001518ASTDeclReader::RedeclarableResult
1519ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Douglas Gregorfc529f72011-12-19 19:00:47 +00001520 enum RedeclKind { FirstDeclaration = 0, FirstInFile, PointsToPrevious };
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001521 RedeclKind Kind = (RedeclKind)Record[Idx++];
Douglas Gregora1be2782011-12-17 23:38:30 +00001522
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001523 DeclID FirstDeclID;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001524 switch (Kind) {
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001525 case FirstDeclaration:
1526 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001527 break;
Douglas Gregorfc529f72011-12-19 19:00:47 +00001528
1529 case FirstInFile:
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001530 case PointsToPrevious: {
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001531 FirstDeclID = ReadDeclID(Record, Idx);
1532 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1533
1534 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
Douglas Gregora1be2782011-12-17 23:38:30 +00001535
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001536 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1537 // We temporarily set the first (canonical) declaration as the previous one
1538 // which is the one that matters and mark the real previous DeclID to be
1539 // loaded & attached later on.
Douglas Gregord488b3a2011-10-26 17:53:41 +00001540 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Douglas Gregord488b3a2011-10-26 17:53:41 +00001541
Douglas Gregorfc529f72011-12-19 19:00:47 +00001542 if (Kind == PointsToPrevious) {
1543 // Make a note that we need to wire up this declaration to its
1544 // previous declaration, later. We don't need to do this for the first
1545 // declaration in any given module file, because those will be wired
1546 // together later.
1547 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1548 PrevDeclID));
1549 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001550 break;
1551 }
Douglas Gregord488b3a2011-10-26 17:53:41 +00001552 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001553
Douglas Gregor0f753232011-12-22 01:48:48 +00001554 // The result structure takes care of note that we need to load the
1555 // other declaration chains for this ID.
1556 return RedeclarableResult(Reader, FirstDeclID);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001557}
1558
Chris Lattner698f9252009-04-27 05:27:42 +00001559//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001560// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001561//===----------------------------------------------------------------------===//
1562
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001563/// \brief Reads attributes from the current stream position.
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001564void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001565 const RecordData &Record, unsigned &Idx) {
1566 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001567 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001568 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001569 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001570
Sean Huntcf807c42010-08-18 23:23:40 +00001571#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001572
1573 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001574 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001575 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001576}
1577
1578//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001579// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001580//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001581
1582/// \brief Note that we have loaded the declaration with the given
1583/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001584///
Chris Lattner698f9252009-04-27 05:27:42 +00001585/// This routine notes that this declaration has already been loaded,
1586/// so that future GetDecl calls will return this declaration rather
1587/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001588inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001589 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1590 DeclsLoaded[Index] = D;
1591}
1592
1593
1594/// \brief Determine whether the consumer will be interested in seeing
1595/// this declaration (via HandleTopLevelDecl).
1596///
1597/// This routine should return true for anything that might affect
1598/// code generation, e.g., inline function definitions, Objective-C
1599/// declarations with metadata, etc.
1600static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001601 // An ObjCMethodDecl is never considered as "interesting" because its
1602 // implementation container always is.
1603
Douglas Gregor94da1582011-09-10 00:22:34 +00001604 if (isa<FileScopeAsmDecl>(D) ||
1605 isa<ObjCProtocolDecl>(D) ||
1606 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001607 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001608 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001609 return Var->isFileVarDecl() &&
1610 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001611 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001612 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001613
1614 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001615}
1616
Douglas Gregor96e973f2011-07-20 00:27:43 +00001617/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001618ASTReader::RecordLocation
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001619ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001620 // See if there's an override.
1621 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidisef23b602011-10-31 07:20:15 +00001622 if (It != ReplacedDecls.end()) {
1623 RawLocation = It->second.RawLoc;
1624 return RecordLocation(It->second.Mod, It->second.Offset);
1625 }
Sebastian Redl0b17c612010-08-13 00:28:03 +00001626
Douglas Gregor96e973f2011-07-20 00:27:43 +00001627 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1628 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001629 ModuleFile *M = I->second;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001630 const DeclOffset &
1631 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1632 RawLocation = DOffs.Loc;
1633 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001634}
1635
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001636ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001637 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001638 = GlobalBitOffsetsMap.find(GlobalOffset);
1639
1640 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1641 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1642}
1643
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001644uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregore92b8a12011-08-04 00:01:48 +00001645 return LocalOffset + M.GlobalBitOffset;
1646}
1647
Douglas Gregor0f753232011-12-22 01:48:48 +00001648/// \brief Determine whether the two declarations refer to the same entity.
1649static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
1650 assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
1651
1652 if (X == Y)
1653 return true;
1654
1655 // Must have the same kind.
1656 if (X->getKind() != Y->getKind())
1657 return false;
1658
1659 // Must be in the same context.
1660 if (!X->getDeclContext()->getRedeclContext()->Equals(
1661 Y->getDeclContext()->getRedeclContext()))
1662 return false;
1663
1664 // Objective-C classes with the same name always match.
1665 if (isa<ObjCInterfaceDecl>(X))
1666 return true;
1667
1668 // FIXME: Many other cases to implement.
1669 return false;
1670}
1671
1672ASTDeclReader::FindExistingResult::~FindExistingResult() {
1673 if (!AddResult)
1674 return;
1675
1676 DeclContext *DC = New->getDeclContext()->getRedeclContext();
1677 if (DC->isTranslationUnit() && Reader.SemaObj) {
1678 if (!Existing) {
1679 Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName());
1680 }
1681 }
1682}
1683
1684ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
1685 DeclContext *DC = D->getDeclContext()->getRedeclContext();
1686 if (!DC->isFileContext())
1687 return FindExistingResult(Reader);
1688
1689 if (DC->isTranslationUnit() && Reader.SemaObj) {
1690 IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver;
1691 for (IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()),
1692 IEnd = IdResolver.end();
1693 I != IEnd; ++I) {
1694 if (isSameEntity(*I, D))
1695 return FindExistingResult(Reader, D, *I);
1696 }
1697 }
1698
1699 // FIXME: Search in the DeclContext.
1700
1701 return FindExistingResult(Reader, D, /*Existing=*/0);
1702}
1703
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001704void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1705 assert(D && previous);
1706 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1707 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1708 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1709 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1710 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1711 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
Douglas Gregora1be2782011-12-17 23:38:30 +00001712 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1713 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
1714 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregor0af55012011-12-16 03:12:41 +00001715 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
Douglas Gregor1d784b22012-01-01 19:51:50 +00001716 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
1717 PD->RedeclLink.setPointer(cast<ObjCProtocolDecl>(previous));
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001718 } else {
1719 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1720 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1721 }
1722}
1723
Douglas Gregora1be2782011-12-17 23:38:30 +00001724void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
1725 assert(D && Latest);
1726 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1727 TD->RedeclLink
1728 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
1729 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1730 FD->RedeclLink
1731 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
1732 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1733 VD->RedeclLink
1734 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
1735 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1736 TD->RedeclLink
1737 = Redeclarable<TypedefNameDecl>::LatestDeclLink(
1738 cast<TypedefNameDecl>(Latest));
1739 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
1740 ID->RedeclLink
1741 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
1742 cast<ObjCInterfaceDecl>(Latest));
Douglas Gregor1d784b22012-01-01 19:51:50 +00001743 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
1744 PD->RedeclLink
1745 = Redeclarable<ObjCProtocolDecl>::LatestDeclLink(
1746 cast<ObjCProtocolDecl>(Latest));
Douglas Gregora1be2782011-12-17 23:38:30 +00001747 } else {
1748 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1749 TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest);
1750 }
1751}
1752
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +00001753ASTReader::MergedDeclsMap::iterator
1754ASTReader::combineStoredMergedDecls(Decl *Canon, GlobalDeclID CanonID) {
1755 // If we don't have any stored merged declarations, just look in the
1756 // merged declarations set.
1757 StoredMergedDeclsMap::iterator StoredPos = StoredMergedDecls.find(CanonID);
1758 if (StoredPos == StoredMergedDecls.end())
1759 return MergedDecls.find(Canon);
1760
1761 // Append the stored merged declarations to the merged declarations set.
1762 MergedDeclsMap::iterator Pos = MergedDecls.find(Canon);
1763 if (Pos == MergedDecls.end())
1764 Pos = MergedDecls.insert(std::make_pair(Canon,
1765 SmallVector<DeclID, 2>())).first;
1766 Pos->second.append(StoredPos->second.begin(), StoredPos->second.end());
1767 StoredMergedDecls.erase(StoredPos);
1768
1769 // Sort and uniquify the set of merged declarations.
1770 llvm::array_pod_sort(Pos->second.begin(), Pos->second.end());
1771 Pos->second.erase(std::unique(Pos->second.begin(), Pos->second.end()),
1772 Pos->second.end());
1773 return Pos;
1774}
1775
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001776void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1777 Decl *previous = GetDecl(ID);
1778 ASTDeclReader::attachPreviousDecl(D, previous);
1779}
1780
Sebastian Redld527cc02010-08-18 23:56:48 +00001781/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001782Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001783 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001784 unsigned RawLocation = 0;
1785 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redlc3632732010-10-05 15:59:54 +00001786 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001787 // Keep track of where we are in the stream, then jump back there
1788 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001789 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001790
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001791 ReadingKindTracker ReadingKind(Read_Decl, *this);
1792
Douglas Gregord89275b2009-07-06 18:54:52 +00001793 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001794 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Sebastian Redlc3632732010-10-05 15:59:54 +00001796 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001797 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001798 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001799 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001800 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001801
Chris Lattnerda930612009-04-27 05:58:23 +00001802 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001803 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001804 case DECL_CONTEXT_LEXICAL:
1805 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001806 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001807 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001808 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001809 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001810 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001811 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001812 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001813 0, 0);
1814 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001815 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001816 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001817 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001818 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001819 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001820 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001821 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001822 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001823 0, llvm::APSInt());
1824 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001825 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001826 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001827 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001828 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001829 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001830 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001831 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001832 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001833 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001834 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001835 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001836 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001837 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001838 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001839 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001840 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001841 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001842 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001843 SourceLocation(), 0,
1844 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001845 SourceLocation(), 0);
1846 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001847 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001848 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001849 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1850 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001851 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001852 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001853 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001854 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001855 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001856 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001857 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001858 SourceLocation(), 0, 0);
1859 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001860 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001861 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001862 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001863 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001864 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001865 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001866 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001867 SourceLocation(),
1868 NestedNameSpecifierLoc(),
1869 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001870 DeclarationName());
1871 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001872 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001873 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001874 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001875 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001876 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001877 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001878 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001879 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001880 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001881 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001882 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001883 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001884 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001885 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001886 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001887 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001888 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001889 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001890 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001891 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001892 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001893 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001894 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001895 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001896 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001897 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001898 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001899 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001900 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001901 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001902 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001903 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001904 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001905 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001906 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001907 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001908 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001909 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001910 Decl::EmptyShell());
1911 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001912 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001913 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001914 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001915 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001916 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001917 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001918 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001919 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001920 SourceLocation(), 0, 0, 0, QualType(),
1921 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001922 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001923 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001924 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001925 SourceLocation(), 0, 0, 0, QualType(),
1926 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001927 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001928 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001929 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001930 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001931 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001932 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001933 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001934 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001935 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001936 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001937 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001938 break;
1939
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001940 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001941 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001942 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001943 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001944 case DECL_OBJC_INTERFACE:
Douglas Gregor0af55012011-12-16 03:12:41 +00001945 D = ObjCInterfaceDecl::CreateEmpty(Context);
Chris Lattner698f9252009-04-27 05:27:42 +00001946 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001947 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001948 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001949 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001950 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001951 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001952 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +00001953 SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001954 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001955 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001956 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001957 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001958 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001959 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001960 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001961 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001962 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001963 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001964 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001965 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001966 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +00001967 SourceLocation(), SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001968 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001969 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001970 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1971 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001972 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001973 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001974 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001975 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001976 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001977 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001978 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001979 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001980 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001981 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001982 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001983 ObjCPropertyImplDecl::Dynamic, 0,
1984 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001985 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001986 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001987 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001988 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001989 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001990 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001991 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001992 0, 0);
1993 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001994 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001995 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001996 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001997 break;
1998
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001999 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00002000 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00002001 break;
2002
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002003 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00002004 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00002005 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00002006 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002007 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00002008 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00002009 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00002010 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00002011 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00002012 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00002013 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00002014 case DECL_CXX_BASE_SPECIFIERS:
2015 Error("attempt to read a C++ base-specifier record as a declaration");
2016 return 0;
Douglas Gregor15de72c2011-12-02 23:23:56 +00002017 case DECL_IMPORT:
2018 // Note: last entry of the ImportDecl record is the number of stored source
2019 // locations.
2020 D = ImportDecl::CreateEmpty(Context, Record.back());
2021 break;
Chris Lattner698f9252009-04-27 05:27:42 +00002022 }
Chris Lattner698f9252009-04-27 05:27:42 +00002023
Sebastian Redld527cc02010-08-18 23:56:48 +00002024 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00002025 LoadedDecl(Index, D);
2026 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00002027
2028 // If this declaration is also a declaration context, get the
2029 // offsets for its tables of lexical and visible declarations.
2030 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
2031 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
2032 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00002033 if (Offsets.first != 0)
2034 DC->setHasExternalLexicalStorage(true);
2035 if (Offsets.second != 0)
2036 DC->setHasExternalVisibleStorage(true);
2037 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
2038 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00002039 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00002040 }
Sebastian Redle1dde812010-08-24 00:50:04 +00002041
Sebastian Redl024e1c42011-04-24 16:27:54 +00002042 // Now add the pending visible updates for this decl context, if it has any.
2043 DeclContextVisibleUpdatesPending::iterator I =
2044 PendingVisibleUpdates.find(ID);
2045 if (I != PendingVisibleUpdates.end()) {
2046 // There are updates. This means the context has external visible
2047 // storage, even if the original stored version didn't.
2048 DC->setHasExternalVisibleStorage(true);
2049 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00002050 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
2051 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00002052 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00002053 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00002054 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00002055 }
2056 }
2057 assert(Idx == Record.size());
2058
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002059 // Load any relevant update records.
2060 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis5a174992011-11-14 07:07:59 +00002061
2062 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002063 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis5a174992011-11-14 07:07:59 +00002064 PendingChainedObjCCategories.push_back(
2065 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002066
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002067 // If we have deserialized a declaration that has a definition the
2068 // AST consumer might need to know about, queue it.
2069 // We don't pass it to the consumer immediately because we may be in recursive
2070 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00002071 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00002072 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00002073
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002074 return D;
2075}
2076
2077void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002078 // The declaration may have been modified by files later in the chain.
2079 // If this is the case, read the record containing the updates from each file
2080 // and pass it to ASTDeclReader to make the modifications.
2081 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
2082 if (UpdI != DeclUpdateOffsets.end()) {
2083 FileOffsetsTy &UpdateOffsets = UpdI->second;
2084 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002085 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002086 ModuleFile *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002087 uint64_t Offset = I->second;
2088 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
2089 SavedStreamPosition SavedPosition(Cursor);
2090 Cursor.JumpToBit(Offset);
2091 RecordData Record;
2092 unsigned Code = Cursor.ReadCode();
2093 unsigned RecCode = Cursor.ReadRecord(Code, Record);
2094 (void)RecCode;
2095 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002096
2097 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00002098 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00002099 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002100 }
2101 }
Chris Lattner698f9252009-04-27 05:27:42 +00002102}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002103
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002104namespace {
Douglas Gregora1be2782011-12-17 23:38:30 +00002105 struct CompareLocalRedeclarationsInfoToID {
2106 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) {
2107 return X.FirstID < Y;
2108 }
2109
2110 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) {
2111 return X < Y.FirstID;
2112 }
2113
2114 bool operator()(const LocalRedeclarationsInfo &X,
2115 const LocalRedeclarationsInfo &Y) {
2116 return X.FirstID < Y.FirstID;
2117 }
2118 bool operator()(DeclID X, DeclID Y) {
2119 return X < Y;
2120 }
2121 };
2122
Douglas Gregor0f753232011-12-22 01:48:48 +00002123 /// \brief Module visitor class that finds all of the redeclarations of a
2124 ///
Douglas Gregora1be2782011-12-17 23:38:30 +00002125 class RedeclChainVisitor {
2126 ASTReader &Reader;
Douglas Gregor0f753232011-12-22 01:48:48 +00002127 SmallVectorImpl<DeclID> &SearchDecls;
2128 GlobalDeclID CanonID;
Douglas Gregora1be2782011-12-17 23:38:30 +00002129 llvm::SmallVector<std::pair<Decl *, Decl *>, 4> Chains;
2130
2131 public:
Douglas Gregor0f753232011-12-22 01:48:48 +00002132 RedeclChainVisitor(ASTReader &Reader, SmallVectorImpl<DeclID> &SearchDecls,
2133 GlobalDeclID CanonID)
2134 : Reader(Reader), SearchDecls(SearchDecls), CanonID(CanonID) { }
Douglas Gregora1be2782011-12-17 23:38:30 +00002135
2136 static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
2137 if (Preorder)
2138 return false;
2139
2140 return static_cast<RedeclChainVisitor *>(UserData)->visit(M);
2141 }
2142
Douglas Gregor0f753232011-12-22 01:48:48 +00002143 void searchForID(ModuleFile &M, GlobalDeclID GlobalID) {
Douglas Gregora1be2782011-12-17 23:38:30 +00002144 // Map global ID of the first declaration down to the local ID
2145 // used in this module file.
Douglas Gregor0f753232011-12-22 01:48:48 +00002146 DeclID ID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalID);
2147 if (!ID)
2148 return;
Douglas Gregora1be2782011-12-17 23:38:30 +00002149
2150 // Perform a binary search to find the local redeclarations for this
2151 // declaration (if any).
2152 const LocalRedeclarationsInfo *Result
2153 = std::lower_bound(M.RedeclarationsInfo,
2154 M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos,
Douglas Gregor0f753232011-12-22 01:48:48 +00002155 ID, CompareLocalRedeclarationsInfoToID());
Douglas Gregora1be2782011-12-17 23:38:30 +00002156 if (Result == M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos ||
Douglas Gregor0f753232011-12-22 01:48:48 +00002157 Result->FirstID != ID) {
2158 // If we have a previously-canonical singleton declaration that was
2159 // merged into another redeclaration chain, create a trivial chain
2160 // for this single declaration so that it will get wired into the
2161 // complete redeclaration chain.
2162 if (GlobalID != CanonID &&
2163 GlobalID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID &&
2164 GlobalID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls) {
2165 if (Decl *D = Reader.GetDecl(GlobalID))
2166 Chains.push_back(std::make_pair(D, D));
2167 }
2168
2169 return;
2170 }
2171
Douglas Gregora1be2782011-12-17 23:38:30 +00002172 // Dig out the starting/ending declarations.
2173 Decl *FirstLocalDecl = Reader.GetLocalDecl(M, Result->FirstLocalID);
2174 Decl *LastLocalDecl = Reader.GetLocalDecl(M, Result->LastLocalID);
2175 if (!FirstLocalDecl || !LastLocalDecl)
Douglas Gregor0f753232011-12-22 01:48:48 +00002176 return;
Douglas Gregora1be2782011-12-17 23:38:30 +00002177
2178 // Append this redeclaration chain to the list.
2179 Chains.push_back(std::make_pair(FirstLocalDecl, LastLocalDecl));
Douglas Gregor0f753232011-12-22 01:48:48 +00002180 }
2181
2182 bool visit(ModuleFile &M) {
2183 // Visit each of the declarations.
2184 for (unsigned I = 0, N = SearchDecls.size(); I != N; ++I)
2185 searchForID(M, SearchDecls[I]);
Douglas Gregora1be2782011-12-17 23:38:30 +00002186 return false;
2187 }
2188
2189 ArrayRef<std::pair<Decl *, Decl *> > getChains() const {
2190 return Chains;
2191 }
2192
2193 void addParsed(Decl *FirstParsedDecl, Decl *LastParsedDecl) {
2194 Chains.push_back(std::make_pair(FirstParsedDecl, LastParsedDecl));
2195 }
2196 };
2197}
2198
2199/// \brief Retrieve the previous declaration to D.
2200static Decl *getPreviousDecl(Decl *D) {
2201 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2202 return TD->getPreviousDeclaration();
2203 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2204 return FD->getPreviousDeclaration();
2205 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2206 return VD->getPreviousDeclaration();
2207 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2208 return TD->getPreviousDeclaration();
2209 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2210 return ID->getPreviousDeclaration();
Douglas Gregor1d784b22012-01-01 19:51:50 +00002211 if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
2212 return PD->getPreviousDeclaration();
Douglas Gregora1be2782011-12-17 23:38:30 +00002213
2214 return cast<RedeclarableTemplateDecl>(D)->getPreviousDeclaration();
2215}
2216
2217/// \brief Retrieve the most recent declaration of D.
2218static Decl *getMostRecentDecl(Decl *D) {
2219 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2220 return TD->getMostRecentDeclaration();
2221 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2222 return FD->getMostRecentDeclaration();
2223 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2224 return VD->getMostRecentDeclaration();
2225 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2226 return TD->getMostRecentDeclaration();
2227 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2228 return ID->getMostRecentDeclaration();
Douglas Gregor1d784b22012-01-01 19:51:50 +00002229 if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
2230 return PD->getMostRecentDeclaration();
Douglas Gregora1be2782011-12-17 23:38:30 +00002231
2232 return cast<RedeclarableTemplateDecl>(D)->getMostRecentDeclaration();
2233}
2234
2235void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
Douglas Gregor0f753232011-12-22 01:48:48 +00002236 Decl *D = GetDecl(ID);
2237 Decl *CanonDecl = D->getCanonicalDecl();
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +00002238
Douglas Gregor0f753232011-12-22 01:48:48 +00002239 // Determine the set of declaration IDs we'll be searching for.
2240 llvm::SmallVector<DeclID, 1> SearchDecls;
2241 GlobalDeclID CanonID = 0;
2242 if (D == CanonDecl) {
2243 SearchDecls.push_back(ID); // Always first.
2244 CanonID = ID;
2245 }
Douglas Gregorc3cfd2a2011-12-22 21:40:42 +00002246 MergedDeclsMap::iterator MergedPos = combineStoredMergedDecls(CanonDecl, ID);
Douglas Gregor0f753232011-12-22 01:48:48 +00002247 if (MergedPos != MergedDecls.end())
2248 SearchDecls.append(MergedPos->second.begin(), MergedPos->second.end());
2249
Douglas Gregora1be2782011-12-17 23:38:30 +00002250 // Build up the list of redeclaration chains.
Douglas Gregor0f753232011-12-22 01:48:48 +00002251 RedeclChainVisitor Visitor(*this, SearchDecls, CanonID);
Douglas Gregora1be2782011-12-17 23:38:30 +00002252 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor);
2253
2254 // Retrieve the chains.
2255 ArrayRef<std::pair<Decl *, Decl *> > Chains = Visitor.getChains();
2256 if (Chains.empty())
2257 return;
Douglas Gregor0f753232011-12-22 01:48:48 +00002258
Douglas Gregora1be2782011-12-17 23:38:30 +00002259 // Capture all of the parsed declarations and put them at the end.
2260 Decl *MostRecent = getMostRecentDecl(CanonDecl);
2261 Decl *FirstParsed = MostRecent;
2262 if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) {
2263 Decl *Current = MostRecent;
2264 while (Decl *Prev = getPreviousDecl(Current)) {
Douglas Gregor0f753232011-12-22 01:48:48 +00002265 if (Prev == CanonDecl)
2266 break;
2267
Douglas Gregora1be2782011-12-17 23:38:30 +00002268 if (Prev->isFromASTFile()) {
2269 Current = Prev;
2270 continue;
2271 }
Douglas Gregor0f753232011-12-22 01:48:48 +00002272
Douglas Gregora1be2782011-12-17 23:38:30 +00002273 // Chain all of the parsed declarations together.
2274 ASTDeclReader::attachPreviousDecl(FirstParsed, Prev);
2275 FirstParsed = Prev;
2276 Current = Prev;
2277 }
2278
2279 Visitor.addParsed(FirstParsed, MostRecent);
2280 }
Douglas Gregor0f753232011-12-22 01:48:48 +00002281
Douglas Gregora1be2782011-12-17 23:38:30 +00002282 // Hook up the separate chains.
2283 Chains = Visitor.getChains();
Douglas Gregor0f753232011-12-22 01:48:48 +00002284 if (Chains[0].first != CanonDecl)
2285 ASTDeclReader::attachPreviousDecl(Chains[0].first, CanonDecl);
Douglas Gregora1be2782011-12-17 23:38:30 +00002286 for (unsigned I = 1, N = Chains.size(); I != N; ++I)
2287 ASTDeclReader::attachPreviousDecl(Chains[I].first, Chains[I-1].second);
2288 ASTDeclReader::attachLatestDecl(CanonDecl, Chains.back().second);
2289}
2290
2291namespace {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002292 /// \brief Given an ObjC interface, goes through the modules and links to the
2293 /// interface all the categories for it.
2294 class ObjCChainedCategoriesVisitor {
2295 ASTReader &Reader;
2296 serialization::GlobalDeclID InterfaceID;
2297 ObjCInterfaceDecl *Interface;
2298 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
2299 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
2300
2301 public:
2302 ObjCChainedCategoriesVisitor(ASTReader &Reader,
2303 serialization::GlobalDeclID InterfaceID,
2304 ObjCInterfaceDecl *Interface)
2305 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
2306 GlobHeadCat(0), GlobTailCat(0) { }
2307
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002308 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002309 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
2310 }
2311
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002312 bool visit(ModuleFile &M) {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002313 if (Reader.isDeclIDFromModule(InterfaceID, M))
2314 return true; // We reached the module where the interface originated
2315 // from. Stop traversing the imported modules.
2316
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002317 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002318 I = M.ChainedObjCCategories.find(InterfaceID);
2319 if (I == M.ChainedObjCCategories.end())
2320 return false;
2321
2322 ObjCCategoryDecl *
2323 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
2324 ObjCCategoryDecl *
2325 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
2326
2327 addCategories(HeadCat, TailCat);
2328 return false;
2329 }
2330
2331 void addCategories(ObjCCategoryDecl *HeadCat,
2332 ObjCCategoryDecl *TailCat = 0) {
2333 if (!HeadCat) {
2334 assert(!TailCat);
2335 return;
2336 }
2337
2338 if (!TailCat) {
2339 TailCat = HeadCat;
2340 while (TailCat->getNextClassCategory())
2341 TailCat = TailCat->getNextClassCategory();
2342 }
2343
2344 if (!GlobHeadCat) {
2345 GlobHeadCat = HeadCat;
2346 GlobTailCat = TailCat;
2347 } else {
2348 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
2349 GlobTailCat = TailCat;
2350 }
2351
2352 llvm::DenseSet<DeclarationName> Checked;
2353 for (ObjCCategoryDecl *Cat = HeadCat,
2354 *CatEnd = TailCat->getNextClassCategory();
2355 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
2356 if (Checked.count(Cat->getDeclName()))
2357 continue;
2358 Checked.insert(Cat->getDeclName());
2359 checkForDuplicate(Cat);
2360 }
2361 }
2362
2363 /// \brief Warns for duplicate categories that come from different modules.
2364 void checkForDuplicate(ObjCCategoryDecl *Cat) {
2365 DeclarationName Name = Cat->getDeclName();
2366 // Find the top category with the same name. We do not want to warn for
2367 // duplicates along the established chain because there were already
2368 // warnings for them when the module was created. We only want to warn for
2369 // duplicates between non-dependent modules:
2370 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00002371 // MT //
2372 // / \ //
2373 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002374 //
2375 // We want to warn for duplicates between ML and MR,not between ML and MT.
2376 //
2377 // FIXME: We should not warn for duplicates in diamond:
2378 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00002379 // MT //
2380 // / \ //
2381 // ML MR //
2382 // \ / //
2383 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002384 //
2385 // If there are duplicates in ML/MR, there will be warning when creating
2386 // MB *and* when importing MB. We should not warn when importing.
2387 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
2388 Next = Next->getNextClassCategory()) {
2389 if (Next->getDeclName() == Name)
2390 Cat = Next;
2391 }
2392
2393 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2394 if (!PrevCat)
2395 PrevCat = Cat;
2396
2397 if (PrevCat != Cat) {
2398 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2399 << Interface->getDeclName() << Name;
2400 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2401 }
2402 }
2403
2404 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2405 };
2406}
2407
2408void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2409 ObjCInterfaceDecl *D) {
2410 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2411 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2412 // Also add the categories that the interface already links to.
2413 Visitor.addCategories(D->getCategoryList());
2414 D->setCategoryList(Visitor.getHeadCategory());
2415}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002416
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002417void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redlf79a7192011-04-29 08:19:30 +00002418 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002419 unsigned Idx = 0;
2420 while (Idx < Record.size()) {
2421 switch ((DeclUpdateKind)Record[Idx++]) {
2422 case UPD_CXX_SET_DEFINITIONDATA: {
2423 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00002424 CXXRecordDecl *DefinitionDecl
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002425 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002426 assert(!RD->DefinitionData && "DefinitionData is already set!");
2427 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2428 break;
2429 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00002430
2431 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002432 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00002433 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00002434
2435 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2436 // It will be added to the template's specializations set when loaded.
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002437 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00002438 break;
2439
2440 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00002441 NamespaceDecl *Anon
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002442 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00002443 // Guard against these being loaded out of original order. Don't use
2444 // getNextNamespace(), since it tries to access the context and can't in
2445 // the middle of deserialization.
2446 if (!Anon->NextNamespace) {
2447 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2448 TU->setAnonymousNamespace(Anon);
2449 else
2450 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2451 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00002452 break;
2453 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00002454
2455 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2456 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002457 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redlf79a7192011-04-29 08:19:30 +00002458 break;
Douglas Gregor53df7a12011-12-15 18:03:09 +00002459
2460 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2461 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2462 ObjCInterfaceDecl *Def
2463 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00002464 if (Def->Data)
Douglas Gregor26fec632011-12-15 18:17:27 +00002465 ID->Data = Def->Data;
Douglas Gregor53df7a12011-12-15 18:03:09 +00002466 break;
2467 }
Douglas Gregor1d784b22012-01-01 19:51:50 +00002468
2469 case UPD_OBJC_SET_PROTOCOL_DEFINITIONDATA: {
2470 ObjCProtocolDecl *ID = cast<ObjCProtocolDecl>(D);
2471 ObjCProtocolDecl *Def
2472 = Reader.ReadDeclAs<ObjCProtocolDecl>(ModuleFile, Record, Idx);
2473 if (Def->Data)
2474 ID->Data = Def->Data;
2475 break;
2476 }
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002477 }
2478 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002479}