blob: 163cbadcd38df125413e62043b69dfa6d2976475 [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"
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner698f9252009-04-27 05:27:42 +000018#include "clang/AST/ASTConsumer.h"
19#include "clang/AST/ASTContext.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/DeclGroup.h"
Chris Lattner6ad9ac02010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner698f9252009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000032namespace clang {
Sebastian Redld527cc02010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redlc43b54c2010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregor1a4761e2011-11-30 23:21:26 +000035 ModuleFile &F;
Sebastian Redl577d4792010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +000038 const unsigned RawLocation;
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000039 typedef ASTReader::RecordData RecordData;
40 const RecordData &Record;
Chris Lattner698f9252009-04-27 05:27:42 +000041 unsigned &Idx;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000042 TypeID TypeIDForTypeDecl;
Douglas Gregor67da6f62011-03-05 01:35:54 +000043
44 DeclID DeclContextIDForTemplateParmDecl;
45 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner698f9252009-04-27 05:27:42 +000046
Sebastian Redl577d4792010-07-22 22:43:28 +000047 uint64_t GetCurrentCursorOffset();
Douglas Gregor409448c2011-07-21 22:35:25 +000048
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000049 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000050 return Reader.ReadSourceLocation(F, R, I);
51 }
Douglas Gregor409448c2011-07-21 22:35:25 +000052
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000053 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000054 return Reader.ReadSourceRange(F, R, I);
55 }
Douglas Gregor409448c2011-07-21 22:35:25 +000056
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000057 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000058 return Reader.GetTypeSourceInfo(F, R, I);
59 }
Douglas Gregor409448c2011-07-21 22:35:25 +000060
61 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
62 return Reader.ReadDeclID(F, R, I);
63 }
64
65 Decl *ReadDecl(const RecordData &R, unsigned &I) {
66 return Reader.ReadDecl(F, R, I);
67 }
68
69 template<typename T>
70 T *ReadDeclAs(const RecordData &R, unsigned &I) {
71 return Reader.ReadDeclAs<T>(F, R, I);
72 }
73
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000074 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000075 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000076 Reader.ReadQualifierInfo(F, Info, R, I);
77 }
Douglas Gregor409448c2011-07-21 22:35:25 +000078
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000079 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000080 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000081 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
82 }
Douglas Gregor409448c2011-07-21 22:35:25 +000083
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000084 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000085 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000086 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
87 }
Sebastian Redl577d4792010-07-22 22:43:28 +000088
Douglas Gregorecc2c092011-12-01 22:20:10 +000089 serialization::SubmoduleID readSubmoduleID(const RecordData &R,
90 unsigned &I) {
91 if (I >= R.size())
92 return 0;
93
94 return Reader.getGlobalSubmoduleID(F, R[I++]);
95 }
96
Douglas Gregor15de72c2011-12-02 23:23:56 +000097 Module *readModule(const RecordData &R, unsigned &I) {
98 return Reader.getSubmodule(readSubmoduleID(R, I));
99 }
100
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000101 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
102 const RecordData &R, unsigned &I);
103
104 void InitializeCXXDefinitionData(CXXRecordDecl *D,
105 CXXRecordDecl *DefinitionDecl,
106 const RecordData &Record, unsigned &Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000107 public:
Douglas Gregor1a4761e2011-11-30 23:21:26 +0000108 ASTDeclReader(ASTReader &Reader, ModuleFile &F,
Sebastian Redlc3632732010-10-05 15:59:54 +0000109 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000110 unsigned RawLocation,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000111 const RecordData &Record, unsigned &Idx)
Sebastian Redlc3632732010-10-05 15:59:54 +0000112 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000113 RawLocation(RawLocation), Record(Record), Idx(Idx),
114 TypeIDForTypeDecl(0) { }
Chris Lattner698f9252009-04-27 05:27:42 +0000115
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +0000116 static void attachPreviousDecl(Decl *D, Decl *previous);
Douglas Gregora1be2782011-12-17 23:38:30 +0000117 static void attachLatestDecl(Decl *D, Decl *latest);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +0000118
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000119 void Visit(Decl *D);
120
Douglas Gregor1a4761e2011-11-30 23:21:26 +0000121 void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redlf79a7192011-04-29 08:19:30 +0000122 const RecordData &Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000123
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +0000124 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
125 ObjCCategoryDecl *Next) {
126 Cat->NextClassCategory = Next;
127 }
128
Chris Lattner698f9252009-04-27 05:27:42 +0000129 void VisitDecl(Decl *D);
130 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
131 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000132 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregor0cef4832010-02-21 18:22:14 +0000133 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000134 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
135 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000136 void VisitTypeDecl(TypeDecl *TD);
Douglas Gregor0f456822011-12-19 14:40:25 +0000137 void VisitTypedefNameDecl(TypedefNameDecl *TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000138 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000139 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000140 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000141 void VisitTagDecl(TagDecl *TD);
142 void VisitEnumDecl(EnumDecl *ED);
143 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000144 void VisitCXXRecordDecl(CXXRecordDecl *D);
145 void VisitClassTemplateSpecializationDecl(
146 ClassTemplateSpecializationDecl *D);
147 void VisitClassTemplatePartialSpecializationDecl(
148 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redl14c36332011-08-31 13:59:56 +0000149 void VisitClassScopeFunctionSpecializationDecl(
150 ClassScopeFunctionSpecializationDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000151 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000152 void VisitValueDecl(ValueDecl *VD);
153 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000154 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000155 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +0000156 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000157 void VisitCXXMethodDecl(CXXMethodDecl *D);
158 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
159 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
160 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000161 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet87c2e122010-11-21 06:08:52 +0000162 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000163 void VisitVarDecl(VarDecl *VD);
164 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
165 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000166 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
167 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000168 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000169 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000170 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000171 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000172 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000173 void VisitUsingDecl(UsingDecl *D);
174 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000175 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000176 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregor15de72c2011-12-02 23:23:56 +0000177 void VisitImportDecl(ImportDecl *D);
Abramo Bagnara6206d532010-06-05 05:09:32 +0000178 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000179 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000180 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
181 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000182 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000183
Chris Lattner698f9252009-04-27 05:27:42 +0000184 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000185 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000186
Sean Hunt9a555912010-05-30 07:21:58 +0000187 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-04-27 05:27:42 +0000188 void VisitObjCMethodDecl(ObjCMethodDecl *D);
189 void VisitObjCContainerDecl(ObjCContainerDecl *D);
190 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
191 void VisitObjCIvarDecl(ObjCIvarDecl *D);
192 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
193 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
194 void VisitObjCClassDecl(ObjCClassDecl *D);
195 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
196 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
197 void VisitObjCImplDecl(ObjCImplDecl *D);
198 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
199 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
200 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
201 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
202 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
203 };
204}
205
Sebastian Redld527cc02010-08-18 23:56:48 +0000206uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregor8f1231b2011-07-22 06:10:01 +0000207 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redl577d4792010-07-22 22:43:28 +0000208}
209
Sebastian Redld527cc02010-08-18 23:56:48 +0000210void ASTDeclReader::Visit(Decl *D) {
211 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000212
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000213 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
214 if (DD->DeclInfo) {
215 DeclaratorDecl::ExtInfo *Info =
216 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
217 Info->TInfo =
218 GetTypeSourceInfo(Record, Idx);
219 }
220 else {
221 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
222 }
223 }
224
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000225 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000226 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor1ab55e92010-12-10 17:03:06 +0000227 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Douglas Gregor0af55012011-12-16 03:12:41 +0000228 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
229 // if we have a fully initialized TypeDecl, we can safely read its type now.
230 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000231 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
232 // FunctionDecl's body was written last after all other Stmts/Exprs.
233 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000234 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000235 } else if (D->isTemplateParameter()) {
236 // If we have a fully initialized template parameter, we can now
237 // set its DeclContext.
238 D->setDeclContext(
239 cast_or_null<DeclContext>(
240 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
241 D->setLexicalDeclContext(
242 cast_or_null<DeclContext>(
243 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000244 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000245}
246
Sebastian Redld527cc02010-08-18 23:56:48 +0000247void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor67da6f62011-03-05 01:35:54 +0000248 if (D->isTemplateParameter()) {
249 // We don't want to deserialize the DeclContext of a template
250 // parameter immediately, because the template parameter might be
251 // used in the formulation of its DeclContext. Use the translation
252 // unit DeclContext as a placeholder.
Douglas Gregor409448c2011-07-21 22:35:25 +0000253 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
254 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000255 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000256 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000257 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
258 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor67da6f62011-03-05 01:35:54 +0000259 }
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000260 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner698f9252009-04-27 05:27:42 +0000261 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000262 if (Record[Idx++]) { // hasAttrs
Sean Huntcf807c42010-08-18 23:23:40 +0000263 AttrVec Attrs;
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000264 Reader.ReadAttributes(F, Attrs, Record, Idx);
Sean Huntcf807c42010-08-18 23:23:40 +0000265 D->setAttrs(Attrs);
266 }
Chris Lattner698f9252009-04-27 05:27:42 +0000267 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000268 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis6b6b42a2011-04-19 19:51:10 +0000269 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidisc14a03d2011-11-23 20:27:36 +0000270 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000271 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor08e0bc12011-09-10 00:09:20 +0000272 D->FromASTFile = true;
Douglas Gregor8d267c52011-09-09 02:06:17 +0000273 D->ModulePrivate = Record[Idx++];
Douglas Gregorecc2c092011-12-01 22:20:10 +0000274
275 // Determine whether this declaration is part of a (sub)module. If so, it
276 // may not yet be visible.
277 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
278 // Module-private declarations are never visible, so there is no work to do.
279 if (!D->ModulePrivate) {
280 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
281 if (Owner->NameVisibility != Module::AllVisible) {
282 // The owning module is not visible. Mark this declaration as
283 // module-private,
284 D->ModulePrivate = true;
285
286 // Note that this declaration was hidden because its owning module is
287 // not yet visible.
288 Reader.HiddenNamesMap[Owner].push_back(D);
289 }
290 }
291 }
292 }
Chris Lattner698f9252009-04-27 05:27:42 +0000293}
294
Sebastian Redld527cc02010-08-18 23:56:48 +0000295void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +0000296 llvm_unreachable("Translation units are not serialized");
Chris Lattner698f9252009-04-27 05:27:42 +0000297}
298
Sebastian Redld527cc02010-08-18 23:56:48 +0000299void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner698f9252009-04-27 05:27:42 +0000300 VisitDecl(ND);
Douglas Gregor393f2492011-07-22 00:38:23 +0000301 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000302}
303
Sebastian Redld527cc02010-08-18 23:56:48 +0000304void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000305 VisitNamedDecl(TD);
Abramo Bagnara344577e2011-03-06 15:48:19 +0000306 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000307 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor393f2492011-07-22 00:38:23 +0000308 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000309}
310
Douglas Gregor0f456822011-12-19 14:40:25 +0000311void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregora1be2782011-12-17 23:38:30 +0000312 VisitRedeclarable(TD);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000313 VisitTypeDecl(TD);
Douglas Gregor0f456822011-12-19 14:40:25 +0000314 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
315}
316
317void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
318 VisitTypedefNameDecl(TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000319}
320
Richard Smith162e1c12011-04-15 14:24:37 +0000321void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Douglas Gregor0f456822011-12-19 14:40:25 +0000322 VisitTypedefNameDecl(TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000323}
324
Sebastian Redld527cc02010-08-18 23:56:48 +0000325void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000326 VisitRedeclarable(TD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000327 VisitTypeDecl(TD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000328 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000329 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCall5e1cdac2011-10-07 06:10:15 +0000330 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000331 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis717a20b2011-09-30 22:11:31 +0000332 TD->setFreeStanding(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000333 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000334 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor35942772011-09-09 21:34:22 +0000335 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000336 ReadQualifierInfo(*Info, Record, Idx);
Richard Smith162e1c12011-04-15 14:24:37 +0000337 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000338 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000339 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000340}
341
Sebastian Redld527cc02010-08-18 23:56:48 +0000342void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000343 VisitTagDecl(ED);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000344 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
345 ED->setIntegerTypeSourceInfo(TI);
346 else
Douglas Gregor393f2492011-07-22 00:38:23 +0000347 ED->setIntegerType(Reader.readType(F, Record, Idx));
348 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall1b5a6182010-05-06 08:49:23 +0000349 ED->setNumPositiveBits(Record[Idx++]);
350 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000351 ED->IsScoped = Record[Idx++];
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000352 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000353 ED->IsFixed = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000354 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000355}
356
Sebastian Redld527cc02010-08-18 23:56:48 +0000357void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000358 VisitTagDecl(RD);
359 RD->setHasFlexibleArrayMember(Record[Idx++]);
360 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000361 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000362}
363
Sebastian Redld527cc02010-08-18 23:56:48 +0000364void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000365 VisitNamedDecl(VD);
Douglas Gregor393f2492011-07-22 00:38:23 +0000366 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000367}
368
Sebastian Redld527cc02010-08-18 23:56:48 +0000369void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000370 VisitValueDecl(ECD);
371 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000372 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000373 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
374}
375
Sebastian Redld527cc02010-08-18 23:56:48 +0000376void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000377 VisitValueDecl(DD);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000378 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000379 if (Record[Idx++]) { // hasExtInfo
380 DeclaratorDecl::ExtInfo *Info
Douglas Gregor35942772011-09-09 21:34:22 +0000381 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000382 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000383 DD->DeclInfo = Info;
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000384 }
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000385}
386
Sebastian Redld527cc02010-08-18 23:56:48 +0000387void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000388 VisitRedeclarable(FD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000389 VisitDeclaratorDecl(FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000390
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000391 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000392 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000393 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000394 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000395 case FunctionDecl::TK_NonTemplate:
396 break;
397 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000398 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
399 Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000400 break;
401 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000402 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000403 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000404 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000405 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000406 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
407 break;
408 }
409 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000410 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
411 Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000412 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
413
414 // Template arguments.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000415 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000416 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000417
418 // Template args as written.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000419 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000420 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000421 bool HasTemplateArgumentsAsWritten = Record[Idx++];
422 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000423 unsigned NumTemplateArgLocs = Record[Idx++];
424 TemplArgLocs.reserve(NumTemplateArgLocs);
425 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000426 TemplArgLocs.push_back(
Sebastian Redlc3632732010-10-05 15:59:54 +0000427 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000428
Sebastian Redlc3632732010-10-05 15:59:54 +0000429 LAngleLoc = ReadSourceLocation(Record, Idx);
430 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000431 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000432
Sebastian Redlc3632732010-10-05 15:59:54 +0000433 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000434
Douglas Gregor35942772011-09-09 21:34:22 +0000435 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000436 TemplateArgumentList *TemplArgList
Douglas Gregor910f8002010-11-07 23:05:16 +0000437 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000438 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000439 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000440 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000441 FunctionTemplateSpecializationInfo *FTInfo
442 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
443 TemplArgList,
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000444 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
445 POI);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000446 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000447
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000448 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000449 // The template that contains the specializations set. It's not safe to
450 // use getCanonicalDecl on Template since it may still be initializing.
451 FunctionTemplateDecl *CanonTemplate
Douglas Gregor409448c2011-07-21 22:35:25 +0000452 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000453 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
454 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
455 // FunctionTemplateSpecializationInfo's Profile().
456 // We avoid getASTContext because a decl in the parent hierarchy may
457 // be initializing.
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000458 llvm::FoldingSetNodeID ID;
459 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
460 TemplArgs.size(), C);
461 void *InsertPos = 0;
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000462 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000463 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000464 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000465 }
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000466 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000467 }
468 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
469 // Templates.
470 UnresolvedSet<8> TemplDecls;
471 unsigned NumTemplates = Record[Idx++];
472 while (NumTemplates--)
Douglas Gregor409448c2011-07-21 22:35:25 +0000473 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000474
475 // Templates args.
476 TemplateArgumentListInfo TemplArgs;
477 unsigned NumArgs = Record[Idx++];
478 while (NumArgs--)
Sebastian Redlc3632732010-10-05 15:59:54 +0000479 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
480 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
481 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000482
Douglas Gregor35942772011-09-09 21:34:22 +0000483 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000484 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000485 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000486 }
487 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000488
Sebastian Redld527cc02010-08-18 23:56:48 +0000489 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000490 // after everything else is read.
491
Douglas Gregor381d34e2010-12-06 18:36:25 +0000492 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000493 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregor8f150942010-12-09 16:59:22 +0000494 FD->IsInline = Record[Idx++];
495 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000496 FD->IsVirtualAsWritten = Record[Idx++];
497 FD->IsPure = Record[Idx++];
498 FD->HasInheritedPrototype = Record[Idx++];
499 FD->HasWrittenPrototype = Record[Idx++];
500 FD->IsDeleted = Record[Idx++];
501 FD->IsTrivial = Record[Idx++];
Sean Hunt2be7e902011-05-12 22:46:29 +0000502 FD->IsDefaulted = Record[Idx++];
503 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000504 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smithaf1fc7a2011-08-15 21:04:07 +0000505 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000506 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000507
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000508 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000509 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000510 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000511 Params.reserve(NumParams);
512 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000513 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000514 FD->setParams(Reader.getContext(), Params);
Chris Lattner698f9252009-04-27 05:27:42 +0000515}
516
Sebastian Redld527cc02010-08-18 23:56:48 +0000517void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000518 VisitNamedDecl(MD);
519 if (Record[Idx++]) {
520 // In practice, this won't be executed (since method definitions
521 // don't occur in header files).
Sebastian Redlc3632732010-10-05 15:59:54 +0000522 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor409448c2011-07-21 22:35:25 +0000523 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
524 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000525 }
526 MD->setInstanceMethod(Record[Idx++]);
527 MD->setVariadic(Record[Idx++]);
528 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000529 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000530
531 MD->IsRedeclaration = Record[Idx++];
532 MD->HasRedeclaration = Record[Idx++];
533 if (MD->HasRedeclaration)
534 Reader.getContext().setObjCMethodRedeclaration(MD,
535 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
536
Chris Lattner698f9252009-04-27 05:27:42 +0000537 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
538 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000539 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000540 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000541 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
542 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000543 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000544 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000545 Params.reserve(NumParams);
546 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000547 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000548
549 MD->SelLocsKind = Record[Idx++];
550 unsigned NumStoredSelLocs = Record[Idx++];
551 SmallVector<SourceLocation, 16> SelLocs;
552 SelLocs.reserve(NumStoredSelLocs);
553 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
554 SelLocs.push_back(ReadSourceLocation(Record, Idx));
555
556 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner698f9252009-04-27 05:27:42 +0000557}
558
Sebastian Redld527cc02010-08-18 23:56:48 +0000559void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000560 VisitNamedDecl(CD);
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000561 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
562 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000563}
564
Sebastian Redld527cc02010-08-18 23:56:48 +0000565void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregor53df7a12011-12-15 18:03:09 +0000566 VisitRedeclarable(ID);
Chris Lattner698f9252009-04-27 05:27:42 +0000567 VisitObjCContainerDecl(ID);
Douglas Gregor0af55012011-12-16 03:12:41 +0000568 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Ted Kremenek53b94412010-09-01 01:21:15 +0000569
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000570 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
571 if (ID == Def) {
572 // Read the definition.
573 ID->allocateDefinitionData();
574
575 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
576
577 // Read the superclass.
578 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
579 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
580
Douglas Gregor05c272f2011-12-15 22:34:59 +0000581 Data.EndLoc = ReadSourceLocation(Record, Idx);
582
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000583 // Read the directly referenced protocols and their SourceLocations.
584 unsigned NumProtocols = Record[Idx++];
585 SmallVector<ObjCProtocolDecl *, 16> Protocols;
586 Protocols.reserve(NumProtocols);
587 for (unsigned I = 0; I != NumProtocols; ++I)
588 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
589 SmallVector<SourceLocation, 16> ProtoLocs;
590 ProtoLocs.reserve(NumProtocols);
591 for (unsigned I = 0; I != NumProtocols; ++I)
592 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
593 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
594 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000595
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000596 // Read the transitive closure of protocols referenced by this class.
597 NumProtocols = Record[Idx++];
598 Protocols.clear();
599 Protocols.reserve(NumProtocols);
600 for (unsigned I = 0; I != NumProtocols; ++I)
601 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
602 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
603 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000604
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000605 // Read the ivars.
606 unsigned NumIvars = Record[Idx++];
607 SmallVector<ObjCIvarDecl *, 16> IVars;
608 IVars.reserve(NumIvars);
609 for (unsigned I = 0; I != NumIvars; ++I)
610 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
611
612 // Read the categories.
613 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000614
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000615 // We will rebuild this list lazily.
616 ID->setIvarList(0);
617
Douglas Gregor21cf08b2011-12-19 20:51:16 +0000618 // Note that we have deserialized a definition.
619 Reader.PendingDefinitions.insert(ID);
620 } else if (Def && Def->Data) {
621 ID->Data = Def->Data;
Douglas Gregor2e5c15b2011-12-15 05:27:12 +0000622 }
Chris Lattner698f9252009-04-27 05:27:42 +0000623}
624
Sebastian Redld527cc02010-08-18 23:56:48 +0000625void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000626 VisitFieldDecl(IVD);
627 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000628 // This field will be built lazily.
629 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000630 bool synth = Record[Idx++];
631 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000632}
633
Sebastian Redld527cc02010-08-18 23:56:48 +0000634void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000635 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000636 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000637 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000638 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000639 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000640 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000641 ProtoRefs.reserve(NumProtoRefs);
642 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000643 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000644 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000645 ProtoLocs.reserve(NumProtoRefs);
646 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000647 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000648 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000649 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000650}
651
Sebastian Redld527cc02010-08-18 23:56:48 +0000652void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000653 VisitFieldDecl(FD);
654}
655
Sebastian Redld527cc02010-08-18 23:56:48 +0000656void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000657 VisitDecl(CD);
Douglas Gregoraf764722011-12-14 17:12:03 +0000658 CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
659 CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000660}
661
Sebastian Redld527cc02010-08-18 23:56:48 +0000662void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000663 VisitDecl(FPD);
664 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000665 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000666 ProtoRefs.reserve(NumProtoRefs);
667 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000668 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000669 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000670 ProtoLocs.reserve(NumProtoRefs);
671 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000672 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000673 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000674 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000675}
676
Sebastian Redld527cc02010-08-18 23:56:48 +0000677void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000678 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000679 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000680 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000681 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000682 ProtoRefs.reserve(NumProtoRefs);
683 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000684 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000685 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000686 ProtoLocs.reserve(NumProtoRefs);
687 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000688 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000689 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000690 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000691 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000692 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000693 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000694}
695
Sebastian Redld527cc02010-08-18 23:56:48 +0000696void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000697 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000698 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000699}
700
Sebastian Redld527cc02010-08-18 23:56:48 +0000701void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000702 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000703 D->setAtLoc(ReadSourceLocation(Record, Idx));
704 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000705 // FIXME: stable encoding
706 D->setPropertyAttributes(
707 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000708 D->setPropertyAttributesAsWritten(
709 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000710 // FIXME: stable encoding
711 D->setPropertyImplementation(
712 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000713 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
714 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000715 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
716 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
717 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000718}
719
Sebastian Redld527cc02010-08-18 23:56:48 +0000720void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000721 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000722 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000723}
724
Sebastian Redld527cc02010-08-18 23:56:48 +0000725void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000726 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000727 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +0000728 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000729}
730
Sebastian Redld527cc02010-08-18 23:56:48 +0000731void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000732 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000733 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000734 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000735 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000736 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000737}
738
739
Sebastian Redld527cc02010-08-18 23:56:48 +0000740void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000741 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000742 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000743 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
744 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000745 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000746 D->setGetterCXXConstructor(Reader.ReadExpr(F));
747 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000748}
749
Sebastian Redld527cc02010-08-18 23:56:48 +0000750void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000751 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000752 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000753 int BitWidthOrInitializer = Record[Idx++];
754 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000755 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000756 else if (BitWidthOrInitializer == 2)
757 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000758 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000759 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000760 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000761 }
Chris Lattner698f9252009-04-27 05:27:42 +0000762}
763
Francois Pichet87c2e122010-11-21 06:08:52 +0000764void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
765 VisitValueDecl(FD);
766
767 FD->ChainingSize = Record[Idx++];
768 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000769 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000770
771 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000772 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000773}
774
Sebastian Redld527cc02010-08-18 23:56:48 +0000775void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000776 VisitRedeclarable(VD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000777 VisitDeclaratorDecl(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000778 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
779 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
780 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
781 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
782 VD->VarDeclBits.ExceptionVar = Record[Idx++];
783 VD->VarDeclBits.NRVOVariable = Record[Idx++];
784 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000785 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smith099e7f62011-12-19 06:19:21 +0000786 if (uint64_t Val = Record[Idx++]) {
Sebastian Redlc3632732010-10-05 15:59:54 +0000787 VD->setInit(Reader.ReadExpr(F));
Richard Smith099e7f62011-12-19 06:19:21 +0000788 if (Val > 1) {
789 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
790 Eval->CheckedICE = true;
791 Eval->IsICE = Val == 3;
792 }
793 }
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000794
795 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000796 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000797 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000798 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000799 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000800 }
Chris Lattner698f9252009-04-27 05:27:42 +0000801}
802
Sebastian Redld527cc02010-08-18 23:56:48 +0000803void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000804 VisitVarDecl(PD);
805}
806
Sebastian Redld527cc02010-08-18 23:56:48 +0000807void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000808 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000809 unsigned isObjCMethodParam = Record[Idx++];
810 unsigned scopeDepth = Record[Idx++];
811 unsigned scopeIndex = Record[Idx++];
812 unsigned declQualifier = Record[Idx++];
813 if (isObjCMethodParam) {
814 assert(scopeDepth == 0);
815 PD->setObjCMethodScopeInfo(scopeIndex);
816 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
817 } else {
818 PD->setScopeInfo(scopeDepth, scopeIndex);
819 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000820 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
821 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000822 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000823 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000824}
825
Sebastian Redld527cc02010-08-18 23:56:48 +0000826void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000827 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000828 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000829 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000830}
831
Sebastian Redld527cc02010-08-18 23:56:48 +0000832void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000833 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000834 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
835 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000836 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000837 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000838 Params.reserve(NumParams);
839 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000840 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000841 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000842
843 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000844 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000845 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000846 captures.reserve(numCaptures);
847 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000848 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +0000849 unsigned flags = Record[Idx++];
850 bool byRef = (flags & 1);
851 bool nested = (flags & 2);
852 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
853
854 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
855 }
Douglas Gregor35942772011-09-09 21:34:22 +0000856 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000857 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000858}
859
Sebastian Redld527cc02010-08-18 23:56:48 +0000860void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000861 VisitDecl(D);
862 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000863 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000864 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000865}
866
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000867void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
868 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +0000869 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000870}
871
872
Sebastian Redld527cc02010-08-18 23:56:48 +0000873void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000874 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +0000875 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +0000876 D->LocStart = ReadSourceLocation(Record, Idx);
877 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +0000878 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000879
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000880 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000881 // FIXME: Modules will likely have trouble with pointing directly at
882 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000883 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +0000884 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000885}
886
Sebastian Redld527cc02010-08-18 23:56:48 +0000887void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000888 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000889 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000890 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +0000891 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000892 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000893}
894
Sebastian Redld527cc02010-08-18 23:56:48 +0000895void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000896 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000897 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000898 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000899 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000900 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000901 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +0000902 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000903 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000904}
905
Sebastian Redld527cc02010-08-18 23:56:48 +0000906void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000907 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000908 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
909 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
910 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000911 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +0000912 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000913}
914
Sebastian Redld527cc02010-08-18 23:56:48 +0000915void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000916 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000917 D->UsingLoc = ReadSourceLocation(Record, Idx);
918 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +0000919 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000920 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
921 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000922}
923
Sebastian Redld527cc02010-08-18 23:56:48 +0000924void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000925 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000926 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000927 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000928 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000929}
930
Sebastian Redld527cc02010-08-18 23:56:48 +0000931void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000932 UnresolvedUsingTypenameDecl *D) {
933 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000934 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +0000935 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000936}
937
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000938void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000939 struct CXXRecordDecl::DefinitionData &Data,
940 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000941 Data.UserDeclaredConstructor = Record[Idx++];
942 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000943 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000944 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000945 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000946 Data.UserDeclaredDestructor = Record[Idx++];
947 Data.Aggregate = Record[Idx++];
948 Data.PlainOldData = Record[Idx++];
949 Data.Empty = Record[Idx++];
950 Data.Polymorphic = Record[Idx++];
951 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +0000952 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +0000953 Data.HasNoNonEmptyBases = Record[Idx++];
954 Data.HasPrivateFields = Record[Idx++];
955 Data.HasProtectedFields = Record[Idx++];
956 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +0000957 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +0000958 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +0000959 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000960 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000961 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000962 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000963 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000964 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +0000965 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000966 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +0000967 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000968 Data.DeclaredDefaultConstructor = Record[Idx++];
969 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000970 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000971 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000972 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000973 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +0000974 Data.FailedImplicitMoveConstructor = Record[Idx++];
975 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +0000976
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000977 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000978 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000979 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000980 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000981 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000982 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +0000983
Douglas Gregor409448c2011-07-21 22:35:25 +0000984 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
985 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000986 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +0000987 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000988}
989
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000990void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
991 CXXRecordDecl *DefinitionDecl,
992 const RecordData &Record,
993 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +0000994 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000995
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000996 if (D == DefinitionDecl) {
997 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000998 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Douglas Gregor21cf08b2011-12-19 20:51:16 +0000999
Douglas Gregorfc529f72011-12-19 19:00:47 +00001000 // Note that we have deserialized a definition.
1001 Reader.PendingDefinitions.insert(D);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00001002 } else if (DefinitionDecl && DefinitionDecl->DefinitionData) {
1003 D->DefinitionData = DefinitionDecl->DefinitionData;
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +00001004 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001005}
1006
1007void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1008 VisitRecordDecl(D);
1009
Douglas Gregor409448c2011-07-21 22:35:25 +00001010 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +00001011 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1012
Douglas Gregor35942772011-09-09 21:34:22 +00001013 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +00001014
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001015 enum CXXRecKind {
1016 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1017 };
1018 switch ((CXXRecKind)Record[Idx++]) {
1019 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001020 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001021 case CXXRecNotTemplate:
1022 break;
1023 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +00001024 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001025 break;
1026 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001027 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001028 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001029 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +00001030 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1031 MSI->setPointOfInstantiation(POI);
1032 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001033 break;
1034 }
1035 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +00001036
1037 // Load the key function to avoid deserializing every method so we can
1038 // compute it.
John McCall5e1cdac2011-10-07 06:10:15 +00001039 if (D->IsCompleteDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +00001040 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +00001041 C.KeyFunctions[D] = Key;
1042 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001043}
1044
Sebastian Redld527cc02010-08-18 23:56:48 +00001045void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001046 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001047 unsigned NumOverridenMethods = Record[Idx++];
1048 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001049 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1050 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +00001051 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001052 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001053 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001054}
1055
Sebastian Redld527cc02010-08-18 23:56:48 +00001056void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001057 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001058
1059 D->IsExplicitSpecified = Record[Idx++];
1060 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001061 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1062 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001063}
1064
Sebastian Redld527cc02010-08-18 23:56:48 +00001065void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001066 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001067
1068 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001069 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001070}
1071
Sebastian Redld527cc02010-08-18 23:56:48 +00001072void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001073 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001074 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001075}
1076
Douglas Gregor15de72c2011-12-02 23:23:56 +00001077void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1078 VisitDecl(D);
1079 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1080 D->ImportedAndComplete.setInt(Record[Idx++]);
1081 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1082 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1083 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1084 ++Idx;
1085}
1086
Sebastian Redld527cc02010-08-18 23:56:48 +00001087void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001088 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001089 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001090}
1091
Sebastian Redld527cc02010-08-18 23:56:48 +00001092void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001093 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001094 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001095 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001096 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001097 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001098 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001099 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001100 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001101}
1102
Sebastian Redld527cc02010-08-18 23:56:48 +00001103void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001104 VisitDecl(D);
1105 unsigned NumParams = Record[Idx++];
1106 D->NumParams = NumParams;
1107 D->Params = new TemplateParameterList*[NumParams];
1108 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001109 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001110 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001111 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001112 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001113 D->Friend = GetTypeSourceInfo(Record, Idx);
1114 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001115}
1116
Sebastian Redld527cc02010-08-18 23:56:48 +00001117void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001118 VisitNamedDecl(D);
1119
Douglas Gregor409448c2011-07-21 22:35:25 +00001120 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001121 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001122 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001123 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001124}
1125
Sebastian Redld527cc02010-08-18 23:56:48 +00001126void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001127 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1128 // can be used while this is still initializing.
Douglas Gregorfc529f72011-12-19 19:00:47 +00001129 enum RedeclKind { FirstDeclaration, FirstInFile, PointsToPrevious };
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001130 RedeclKind Kind = (RedeclKind)Record[Idx++];
1131
1132 // Determine the first declaration ID.
1133 DeclID FirstDeclID;
1134 switch (Kind) {
1135 case FirstDeclaration: {
1136 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001137
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001138 // Since this is the first declaration of the template, fill in the
1139 // information for the 'common' pointer.
1140 if (D->CommonOrPrev.isNull()) {
1141 RedeclarableTemplateDecl::CommonBase *Common
1142 = D->newCommon(Reader.getContext());
1143 Common->Latest = D;
1144 D->CommonOrPrev = Common;
1145 }
1146
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001147 if (RedeclarableTemplateDecl *RTD
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001148 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001149 assert(RTD->getKind() == D->getKind() &&
1150 "InstantiatedFromMemberTemplate kind mismatch");
1151 D->setInstantiatedFromMemberTemplateImpl(RTD);
1152 if (Record[Idx++])
1153 D->setMemberSpecialization();
1154 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001155 break;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001156 }
Douglas Gregorfc529f72011-12-19 19:00:47 +00001157
1158 case FirstInFile:
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001159 case PointsToPrevious: {
1160 FirstDeclID = ReadDeclID(Record, Idx);
1161 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1162
1163 RedeclarableTemplateDecl *FirstDecl
1164 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1165
1166 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1167 // We temporarily set the first (canonical) declaration as the previous one
1168 // which is the one that matters and mark the real previous DeclID to be
1169 // loaded and attached later on.
1170 D->CommonOrPrev = FirstDecl;
1171
Douglas Gregorfc529f72011-12-19 19:00:47 +00001172 if (Kind == PointsToPrevious) {
1173 // Make a note that we need to wire up this declaration to its
1174 // previous declaration, later. We don't need to do this for the first
1175 // declaration in any given module file, because those will be wired
1176 // together later.
1177 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PrevDeclID));
1178 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001179 break;
1180 }
1181 }
1182
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001183 VisitTemplateDecl(D);
1184 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001185}
1186
Sebastian Redld527cc02010-08-18 23:56:48 +00001187void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001188 VisitRedeclarableTemplateDecl(D);
1189
1190 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001191 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1192 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001193 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001194 SpecIDs.push_back(0);
1195
1196 // Specializations.
1197 unsigned Size = Record[Idx++];
1198 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001199 for (unsigned I = 0; I != Size; ++I)
1200 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001201
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001202 // Partial specializations.
1203 Size = Record[Idx++];
1204 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001205 for (unsigned I = 0; I != Size; ++I)
1206 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001207
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001208 if (SpecIDs[0]) {
1209 typedef serialization::DeclID DeclID;
1210
1211 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1212 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001213 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001214 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1215 SpecIDs.size() * sizeof(DeclID));
1216 }
1217
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001218 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001219 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001220}
1221
Sebastian Redld527cc02010-08-18 23:56:48 +00001222void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001223 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001224 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001225
Douglas Gregor35942772011-09-09 21:34:22 +00001226 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001227 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001228 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001229 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001230 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001231 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001232 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001233 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001234 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1235 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001236 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1237 = new (C) ClassTemplateSpecializationDecl::
1238 SpecializedPartialSpecialization();
1239 PS->PartialSpecialization
1240 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1241 PS->TemplateArgs = ArgList;
1242 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001243 }
1244 }
1245
1246 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001247 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001248 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1249 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1250 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001251 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1252 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001253 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001254 }
1255
Chris Lattner5f9e2722011-07-23 10:55:15 +00001256 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001257 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001258 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1259 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001260 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001261 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001262
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001263 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001264 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001265 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001266 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1267 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001268 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001269 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001270 }
1271 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001272}
1273
Sebastian Redld527cc02010-08-18 23:56:48 +00001274void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001275 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001276 VisitClassTemplateSpecializationDecl(D);
1277
Douglas Gregor35942772011-09-09 21:34:22 +00001278 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001279 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001280
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001281 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001282 if (NumArgs) {
1283 D->NumArgsAsWritten = NumArgs;
1284 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1285 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001286 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001287 }
1288
1289 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001290
1291 // These are read/set from/to the first declaration.
1292 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001293 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001294 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001295 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001296 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001297}
1298
Sebastian Redl14c36332011-08-31 13:59:56 +00001299void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1300 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001301 VisitDecl(D);
1302 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1303}
1304
Sebastian Redld527cc02010-08-18 23:56:48 +00001305void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001306 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001307
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001308 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001309 // This FunctionTemplateDecl owns a CommonPtr; read it.
1310
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001311 // Read the function specialization declarations.
1312 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001313 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001314 unsigned NumSpecs = Record[Idx++];
1315 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001316 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001317 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001318}
1319
Sebastian Redld527cc02010-08-18 23:56:48 +00001320void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001321 VisitTypeDecl(D);
1322
1323 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001324
1325 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001326 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001327 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001328}
1329
Sebastian Redld527cc02010-08-18 23:56:48 +00001330void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001331 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001332 // TemplateParmPosition.
1333 D->setDepth(Record[Idx++]);
1334 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001335 if (D->isExpandedParameterPack()) {
1336 void **Data = reinterpret_cast<void **>(D + 1);
1337 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001338 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001339 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1340 }
1341 } else {
1342 // Rest of NonTypeTemplateParmDecl.
1343 D->ParameterPack = Record[Idx++];
1344 if (Record[Idx++]) {
1345 Expr *DefArg = Reader.ReadExpr(F);
1346 bool Inherited = Record[Idx++];
1347 D->setDefaultArgument(DefArg, Inherited);
1348 }
1349 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001350}
1351
Sebastian Redld527cc02010-08-18 23:56:48 +00001352void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001353 VisitTemplateDecl(D);
1354 // TemplateParmPosition.
1355 D->setDepth(Record[Idx++]);
1356 D->setPosition(Record[Idx++]);
1357 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001358 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001359 bool IsInherited = Record[Idx++];
1360 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001361 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001362}
1363
Richard Smith3e4c6c42011-05-05 21:57:07 +00001364void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1365 VisitRedeclarableTemplateDecl(D);
1366}
1367
Sebastian Redld527cc02010-08-18 23:56:48 +00001368void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001369 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001370 D->AssertExpr = Reader.ReadExpr(F);
1371 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001372 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001373}
1374
Mike Stump1eb44332009-09-09 15:08:12 +00001375std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001376ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001377 uint64_t LexicalOffset = Record[Idx++];
1378 uint64_t VisibleOffset = Record[Idx++];
1379 return std::make_pair(LexicalOffset, VisibleOffset);
1380}
1381
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001382template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001383void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Douglas Gregorfc529f72011-12-19 19:00:47 +00001384 enum RedeclKind { FirstDeclaration = 0, FirstInFile, PointsToPrevious };
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001385 RedeclKind Kind = (RedeclKind)Record[Idx++];
Douglas Gregora1be2782011-12-17 23:38:30 +00001386
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001387 DeclID FirstDeclID;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001388 switch (Kind) {
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001389 case FirstDeclaration:
1390 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001391 break;
Douglas Gregorfc529f72011-12-19 19:00:47 +00001392
1393 case FirstInFile:
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001394 case PointsToPrevious: {
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001395 FirstDeclID = ReadDeclID(Record, Idx);
1396 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1397
1398 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
Douglas Gregora1be2782011-12-17 23:38:30 +00001399
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001400 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1401 // We temporarily set the first (canonical) declaration as the previous one
1402 // which is the one that matters and mark the real previous DeclID to be
1403 // loaded & attached later on.
Douglas Gregord488b3a2011-10-26 17:53:41 +00001404 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Douglas Gregord488b3a2011-10-26 17:53:41 +00001405
Douglas Gregorfc529f72011-12-19 19:00:47 +00001406 if (Kind == PointsToPrevious) {
1407 // Make a note that we need to wire up this declaration to its
1408 // previous declaration, later. We don't need to do this for the first
1409 // declaration in any given module file, because those will be wired
1410 // together later.
1411 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1412 PrevDeclID));
1413 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001414 break;
1415 }
Douglas Gregord488b3a2011-10-26 17:53:41 +00001416 }
Douglas Gregorf63b0a52011-12-19 18:19:24 +00001417
1418 // Note that we need to load the other declaration chains for this ID.
Douglas Gregor87dd4f72011-12-21 15:12:03 +00001419 if (Reader.PendingDeclChainsKnown.insert(FirstDeclID))
1420 Reader.PendingDeclChains.push_back(FirstDeclID);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001421}
1422
Chris Lattner698f9252009-04-27 05:27:42 +00001423//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001424// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001425//===----------------------------------------------------------------------===//
1426
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001427/// \brief Reads attributes from the current stream position.
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001428void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001429 const RecordData &Record, unsigned &Idx) {
1430 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001431 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001432 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001433 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001434
Sean Huntcf807c42010-08-18 23:23:40 +00001435#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001436
1437 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001438 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001439 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001440}
1441
1442//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001443// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001444//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001445
1446/// \brief Note that we have loaded the declaration with the given
1447/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001448///
Chris Lattner698f9252009-04-27 05:27:42 +00001449/// This routine notes that this declaration has already been loaded,
1450/// so that future GetDecl calls will return this declaration rather
1451/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001452inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001453 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1454 DeclsLoaded[Index] = D;
1455}
1456
1457
1458/// \brief Determine whether the consumer will be interested in seeing
1459/// this declaration (via HandleTopLevelDecl).
1460///
1461/// This routine should return true for anything that might affect
1462/// code generation, e.g., inline function definitions, Objective-C
1463/// declarations with metadata, etc.
1464static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001465 // An ObjCMethodDecl is never considered as "interesting" because its
1466 // implementation container always is.
1467
Douglas Gregor94da1582011-09-10 00:22:34 +00001468 if (isa<FileScopeAsmDecl>(D) ||
1469 isa<ObjCProtocolDecl>(D) ||
1470 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001471 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001472 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001473 return Var->isFileVarDecl() &&
1474 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001475 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001476 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001477
1478 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001479}
1480
Douglas Gregor96e973f2011-07-20 00:27:43 +00001481/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001482ASTReader::RecordLocation
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001483ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001484 // See if there's an override.
1485 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidisef23b602011-10-31 07:20:15 +00001486 if (It != ReplacedDecls.end()) {
1487 RawLocation = It->second.RawLoc;
1488 return RecordLocation(It->second.Mod, It->second.Offset);
1489 }
Sebastian Redl0b17c612010-08-13 00:28:03 +00001490
Douglas Gregor96e973f2011-07-20 00:27:43 +00001491 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1492 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001493 ModuleFile *M = I->second;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001494 const DeclOffset &
1495 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1496 RawLocation = DOffs.Loc;
1497 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001498}
1499
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001500ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001501 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001502 = GlobalBitOffsetsMap.find(GlobalOffset);
1503
1504 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1505 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1506}
1507
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001508uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregore92b8a12011-08-04 00:01:48 +00001509 return LocalOffset + M.GlobalBitOffset;
1510}
1511
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001512void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1513 assert(D && previous);
1514 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1515 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1516 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1517 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1518 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1519 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
Douglas Gregora1be2782011-12-17 23:38:30 +00001520 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1521 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
1522 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregor0af55012011-12-16 03:12:41 +00001523 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001524 } else {
1525 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1526 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1527 }
1528}
1529
Douglas Gregora1be2782011-12-17 23:38:30 +00001530void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
1531 assert(D && Latest);
1532 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1533 TD->RedeclLink
1534 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
1535 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1536 FD->RedeclLink
1537 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
1538 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1539 VD->RedeclLink
1540 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
1541 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1542 TD->RedeclLink
1543 = Redeclarable<TypedefNameDecl>::LatestDeclLink(
1544 cast<TypedefNameDecl>(Latest));
1545 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
1546 ID->RedeclLink
1547 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
1548 cast<ObjCInterfaceDecl>(Latest));
1549 } else {
1550 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1551 TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest);
1552 }
1553}
1554
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001555void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1556 Decl *previous = GetDecl(ID);
1557 ASTDeclReader::attachPreviousDecl(D, previous);
1558}
1559
Sebastian Redld527cc02010-08-18 23:56:48 +00001560/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001561Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001562 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001563 unsigned RawLocation = 0;
1564 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redlc3632732010-10-05 15:59:54 +00001565 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001566 // Keep track of where we are in the stream, then jump back there
1567 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001568 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001569
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001570 ReadingKindTracker ReadingKind(Read_Decl, *this);
1571
Douglas Gregord89275b2009-07-06 18:54:52 +00001572 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001573 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001574
Sebastian Redlc3632732010-10-05 15:59:54 +00001575 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001576 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001577 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001578 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001579 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001580
Chris Lattnerda930612009-04-27 05:58:23 +00001581 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001582 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001583 case DECL_CONTEXT_LEXICAL:
1584 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001585 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001586 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001587 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001588 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001589 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001590 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001591 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001592 0, 0);
1593 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001594 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001595 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001596 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001597 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001598 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001599 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001600 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001601 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001602 0, llvm::APSInt());
1603 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001604 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001605 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001606 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001607 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001608 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001609 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001610 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001611 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001612 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001613 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001614 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001615 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001616 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001617 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001618 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001619 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001620 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001621 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001622 SourceLocation(), 0,
1623 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001624 SourceLocation(), 0);
1625 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001626 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001627 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001628 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1629 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001630 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001631 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001632 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001633 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001634 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001635 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001636 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001637 SourceLocation(), 0, 0);
1638 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001639 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001640 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001641 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001642 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001643 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001644 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001645 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001646 SourceLocation(),
1647 NestedNameSpecifierLoc(),
1648 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001649 DeclarationName());
1650 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001651 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001652 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001653 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001654 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001655 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001656 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001657 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001658 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001659 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001660 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001661 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001662 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001663 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001664 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001665 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001666 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001667 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001668 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001669 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001670 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001671 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001672 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001673 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001674 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001675 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001676 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001677 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001678 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001679 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001680 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001681 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001682 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001683 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001684 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001685 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001686 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001687 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001688 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001689 Decl::EmptyShell());
1690 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001691 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001692 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001693 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001694 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001695 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001696 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001697 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001698 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001699 SourceLocation(), 0, 0, 0, QualType(),
1700 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001701 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001702 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001703 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001704 SourceLocation(), 0, 0, 0, QualType(),
1705 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001706 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001707 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001708 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001709 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001710 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001711 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001712 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001713 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001714 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001715 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001716 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001717 break;
1718
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001719 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001720 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001721 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001722 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001723 case DECL_OBJC_INTERFACE:
Douglas Gregor0af55012011-12-16 03:12:41 +00001724 D = ObjCInterfaceDecl::CreateEmpty(Context);
Chris Lattner698f9252009-04-27 05:27:42 +00001725 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001726 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001727 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001728 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001729 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001730 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001731 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +00001732 SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001733 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001734 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001735 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001736 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001737 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001738 case DECL_OBJC_CLASS:
Douglas Gregor35942772011-09-09 21:34:22 +00001739 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001740 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001741 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001742 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001743 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001744 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001745 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001746 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001747 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001748 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidisc6994002011-12-09 00:31:40 +00001749 SourceLocation(), SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001750 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001751 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001752 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1753 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001754 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001755 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001756 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001757 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001758 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001759 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001760 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001761 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001762 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001763 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001764 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001765 ObjCPropertyImplDecl::Dynamic, 0,
1766 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001767 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001768 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001769 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001770 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001771 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001772 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001773 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001774 0, 0);
1775 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001776 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001777 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001778 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001779 break;
1780
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001781 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00001782 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001783 break;
1784
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001785 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001786 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001787 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001788 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001789 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00001790 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00001791 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001792 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001793 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00001794 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001795 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00001796 case DECL_CXX_BASE_SPECIFIERS:
1797 Error("attempt to read a C++ base-specifier record as a declaration");
1798 return 0;
Douglas Gregor15de72c2011-12-02 23:23:56 +00001799 case DECL_IMPORT:
1800 // Note: last entry of the ImportDecl record is the number of stored source
1801 // locations.
1802 D = ImportDecl::CreateEmpty(Context, Record.back());
1803 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001804 }
Chris Lattner698f9252009-04-27 05:27:42 +00001805
Sebastian Redld527cc02010-08-18 23:56:48 +00001806 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001807 LoadedDecl(Index, D);
1808 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001809
1810 // If this declaration is also a declaration context, get the
1811 // offsets for its tables of lexical and visible declarations.
1812 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1813 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1814 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001815 if (Offsets.first != 0)
1816 DC->setHasExternalLexicalStorage(true);
1817 if (Offsets.second != 0)
1818 DC->setHasExternalVisibleStorage(true);
1819 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1820 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00001821 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001822 }
Sebastian Redle1dde812010-08-24 00:50:04 +00001823
Sebastian Redl024e1c42011-04-24 16:27:54 +00001824 // Now add the pending visible updates for this decl context, if it has any.
1825 DeclContextVisibleUpdatesPending::iterator I =
1826 PendingVisibleUpdates.find(ID);
1827 if (I != PendingVisibleUpdates.end()) {
1828 // There are updates. This means the context has external visible
1829 // storage, even if the original stored version didn't.
1830 DC->setHasExternalVisibleStorage(true);
1831 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001832 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1833 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001834 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00001835 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00001836 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00001837 }
1838 }
1839 assert(Idx == Record.size());
1840
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001841 // Load any relevant update records.
1842 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis5a174992011-11-14 07:07:59 +00001843
1844 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001845 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis5a174992011-11-14 07:07:59 +00001846 PendingChainedObjCCategories.push_back(
1847 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001848
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001849 // If we have deserialized a declaration that has a definition the
1850 // AST consumer might need to know about, queue it.
1851 // We don't pass it to the consumer immediately because we may be in recursive
1852 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001853 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00001854 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00001855
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001856 return D;
1857}
1858
1859void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001860 // The declaration may have been modified by files later in the chain.
1861 // If this is the case, read the record containing the updates from each file
1862 // and pass it to ASTDeclReader to make the modifications.
1863 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1864 if (UpdI != DeclUpdateOffsets.end()) {
1865 FileOffsetsTy &UpdateOffsets = UpdI->second;
1866 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001867 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor1a4761e2011-11-30 23:21:26 +00001868 ModuleFile *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001869 uint64_t Offset = I->second;
1870 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1871 SavedStreamPosition SavedPosition(Cursor);
1872 Cursor.JumpToBit(Offset);
1873 RecordData Record;
1874 unsigned Code = Cursor.ReadCode();
1875 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1876 (void)RecCode;
1877 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001878
1879 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001880 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00001881 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001882 }
1883 }
Chris Lattner698f9252009-04-27 05:27:42 +00001884}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001885
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001886namespace {
Douglas Gregora1be2782011-12-17 23:38:30 +00001887 struct CompareLocalRedeclarationsInfoToID {
1888 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) {
1889 return X.FirstID < Y;
1890 }
1891
1892 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) {
1893 return X < Y.FirstID;
1894 }
1895
1896 bool operator()(const LocalRedeclarationsInfo &X,
1897 const LocalRedeclarationsInfo &Y) {
1898 return X.FirstID < Y.FirstID;
1899 }
1900 bool operator()(DeclID X, DeclID Y) {
1901 return X < Y;
1902 }
1903 };
1904
1905 class RedeclChainVisitor {
1906 ASTReader &Reader;
1907 DeclID GlobalFirstID;
1908 llvm::SmallVector<std::pair<Decl *, Decl *>, 4> Chains;
1909
1910 public:
1911 RedeclChainVisitor(ASTReader &Reader, DeclID GlobalFirstID)
1912 : Reader(Reader), GlobalFirstID(GlobalFirstID) { }
1913
1914 static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
1915 if (Preorder)
1916 return false;
1917
1918 return static_cast<RedeclChainVisitor *>(UserData)->visit(M);
1919 }
1920
1921 bool visit(ModuleFile &M) {
1922 // Map global ID of the first declaration down to the local ID
1923 // used in this module file.
1924 DeclID FirstID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalFirstID);
1925 if (!FirstID)
1926 return false;
1927
1928 // Perform a binary search to find the local redeclarations for this
1929 // declaration (if any).
1930 const LocalRedeclarationsInfo *Result
1931 = std::lower_bound(M.RedeclarationsInfo,
1932 M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos,
1933 FirstID, CompareLocalRedeclarationsInfoToID());
1934 if (Result == M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos ||
1935 Result->FirstID != FirstID)
1936 return false;
1937
1938 // Dig out the starting/ending declarations.
1939 Decl *FirstLocalDecl = Reader.GetLocalDecl(M, Result->FirstLocalID);
1940 Decl *LastLocalDecl = Reader.GetLocalDecl(M, Result->LastLocalID);
1941 if (!FirstLocalDecl || !LastLocalDecl)
1942 return false;
1943
1944 // Append this redeclaration chain to the list.
1945 Chains.push_back(std::make_pair(FirstLocalDecl, LastLocalDecl));
1946 return false;
1947 }
1948
1949 ArrayRef<std::pair<Decl *, Decl *> > getChains() const {
1950 return Chains;
1951 }
1952
1953 void addParsed(Decl *FirstParsedDecl, Decl *LastParsedDecl) {
1954 Chains.push_back(std::make_pair(FirstParsedDecl, LastParsedDecl));
1955 }
1956 };
1957}
1958
1959/// \brief Retrieve the previous declaration to D.
1960static Decl *getPreviousDecl(Decl *D) {
1961 if (TagDecl *TD = dyn_cast<TagDecl>(D))
1962 return TD->getPreviousDeclaration();
1963 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1964 return FD->getPreviousDeclaration();
1965 if (VarDecl *VD = dyn_cast<VarDecl>(D))
1966 return VD->getPreviousDeclaration();
1967 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
1968 return TD->getPreviousDeclaration();
1969 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
1970 return ID->getPreviousDeclaration();
1971
1972 return cast<RedeclarableTemplateDecl>(D)->getPreviousDeclaration();
1973}
1974
1975/// \brief Retrieve the most recent declaration of D.
1976static Decl *getMostRecentDecl(Decl *D) {
1977 if (TagDecl *TD = dyn_cast<TagDecl>(D))
1978 return TD->getMostRecentDeclaration();
1979 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1980 return FD->getMostRecentDeclaration();
1981 if (VarDecl *VD = dyn_cast<VarDecl>(D))
1982 return VD->getMostRecentDeclaration();
1983 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
1984 return TD->getMostRecentDeclaration();
1985 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
1986 return ID->getMostRecentDeclaration();
1987
1988 return cast<RedeclarableTemplateDecl>(D)->getMostRecentDeclaration();
1989}
1990
1991void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
1992 // Build up the list of redeclaration chains.
1993 RedeclChainVisitor Visitor(*this, ID);
1994 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor);
1995
1996 // Retrieve the chains.
1997 ArrayRef<std::pair<Decl *, Decl *> > Chains = Visitor.getChains();
1998 if (Chains.empty())
1999 return;
2000
2001 // FIXME: Splice local (not from AST file) declarations into the list,
2002 // rather than always re-ordering them.
2003 Decl *CanonDecl = GetDecl(ID);
2004
2005 // Capture all of the parsed declarations and put them at the end.
2006 Decl *MostRecent = getMostRecentDecl(CanonDecl);
2007 Decl *FirstParsed = MostRecent;
2008 if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) {
2009 Decl *Current = MostRecent;
2010 while (Decl *Prev = getPreviousDecl(Current)) {
2011 if (Prev->isFromASTFile()) {
2012 Current = Prev;
2013 continue;
2014 }
2015
2016 // Chain all of the parsed declarations together.
2017 ASTDeclReader::attachPreviousDecl(FirstParsed, Prev);
2018 FirstParsed = Prev;
2019 Current = Prev;
2020 }
2021
2022 Visitor.addParsed(FirstParsed, MostRecent);
2023 }
2024
2025 // Hook up the separate chains.
2026 Chains = Visitor.getChains();
2027 for (unsigned I = 1, N = Chains.size(); I != N; ++I)
2028 ASTDeclReader::attachPreviousDecl(Chains[I].first, Chains[I-1].second);
2029 ASTDeclReader::attachLatestDecl(CanonDecl, Chains.back().second);
2030}
2031
2032namespace {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002033 /// \brief Given an ObjC interface, goes through the modules and links to the
2034 /// interface all the categories for it.
2035 class ObjCChainedCategoriesVisitor {
2036 ASTReader &Reader;
2037 serialization::GlobalDeclID InterfaceID;
2038 ObjCInterfaceDecl *Interface;
2039 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
2040 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
2041
2042 public:
2043 ObjCChainedCategoriesVisitor(ASTReader &Reader,
2044 serialization::GlobalDeclID InterfaceID,
2045 ObjCInterfaceDecl *Interface)
2046 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
2047 GlobHeadCat(0), GlobTailCat(0) { }
2048
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002049 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002050 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
2051 }
2052
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002053 bool visit(ModuleFile &M) {
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002054 if (Reader.isDeclIDFromModule(InterfaceID, M))
2055 return true; // We reached the module where the interface originated
2056 // from. Stop traversing the imported modules.
2057
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002058 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002059 I = M.ChainedObjCCategories.find(InterfaceID);
2060 if (I == M.ChainedObjCCategories.end())
2061 return false;
2062
2063 ObjCCategoryDecl *
2064 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
2065 ObjCCategoryDecl *
2066 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
2067
2068 addCategories(HeadCat, TailCat);
2069 return false;
2070 }
2071
2072 void addCategories(ObjCCategoryDecl *HeadCat,
2073 ObjCCategoryDecl *TailCat = 0) {
2074 if (!HeadCat) {
2075 assert(!TailCat);
2076 return;
2077 }
2078
2079 if (!TailCat) {
2080 TailCat = HeadCat;
2081 while (TailCat->getNextClassCategory())
2082 TailCat = TailCat->getNextClassCategory();
2083 }
2084
2085 if (!GlobHeadCat) {
2086 GlobHeadCat = HeadCat;
2087 GlobTailCat = TailCat;
2088 } else {
2089 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
2090 GlobTailCat = TailCat;
2091 }
2092
2093 llvm::DenseSet<DeclarationName> Checked;
2094 for (ObjCCategoryDecl *Cat = HeadCat,
2095 *CatEnd = TailCat->getNextClassCategory();
2096 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
2097 if (Checked.count(Cat->getDeclName()))
2098 continue;
2099 Checked.insert(Cat->getDeclName());
2100 checkForDuplicate(Cat);
2101 }
2102 }
2103
2104 /// \brief Warns for duplicate categories that come from different modules.
2105 void checkForDuplicate(ObjCCategoryDecl *Cat) {
2106 DeclarationName Name = Cat->getDeclName();
2107 // Find the top category with the same name. We do not want to warn for
2108 // duplicates along the established chain because there were already
2109 // warnings for them when the module was created. We only want to warn for
2110 // duplicates between non-dependent modules:
2111 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00002112 // MT //
2113 // / \ //
2114 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002115 //
2116 // We want to warn for duplicates between ML and MR,not between ML and MT.
2117 //
2118 // FIXME: We should not warn for duplicates in diamond:
2119 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00002120 // MT //
2121 // / \ //
2122 // ML MR //
2123 // \ / //
2124 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00002125 //
2126 // If there are duplicates in ML/MR, there will be warning when creating
2127 // MB *and* when importing MB. We should not warn when importing.
2128 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
2129 Next = Next->getNextClassCategory()) {
2130 if (Next->getDeclName() == Name)
2131 Cat = Next;
2132 }
2133
2134 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2135 if (!PrevCat)
2136 PrevCat = Cat;
2137
2138 if (PrevCat != Cat) {
2139 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2140 << Interface->getDeclName() << Name;
2141 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2142 }
2143 }
2144
2145 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2146 };
2147}
2148
2149void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2150 ObjCInterfaceDecl *D) {
2151 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2152 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2153 // Also add the categories that the interface already links to.
2154 Visitor.addCategories(D->getCategoryList());
2155 D->setCategoryList(Visitor.getHeadCategory());
2156}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00002157
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002158void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redlf79a7192011-04-29 08:19:30 +00002159 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002160 unsigned Idx = 0;
2161 while (Idx < Record.size()) {
2162 switch ((DeclUpdateKind)Record[Idx++]) {
2163 case UPD_CXX_SET_DEFINITIONDATA: {
2164 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00002165 CXXRecordDecl *DefinitionDecl
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002166 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002167 assert(!RD->DefinitionData && "DefinitionData is already set!");
2168 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2169 break;
2170 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00002171
2172 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002173 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00002174 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00002175
2176 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2177 // It will be added to the template's specializations set when loaded.
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002178 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00002179 break;
2180
2181 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00002182 NamespaceDecl *Anon
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002183 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00002184 // Guard against these being loaded out of original order. Don't use
2185 // getNextNamespace(), since it tries to access the context and can't in
2186 // the middle of deserialization.
2187 if (!Anon->NextNamespace) {
2188 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2189 TU->setAnonymousNamespace(Anon);
2190 else
2191 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2192 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00002193 break;
2194 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00002195
2196 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2197 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregor1a4761e2011-11-30 23:21:26 +00002198 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redlf79a7192011-04-29 08:19:30 +00002199 break;
Douglas Gregor53df7a12011-12-15 18:03:09 +00002200
2201 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2202 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2203 ObjCInterfaceDecl *Def
2204 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregor21cf08b2011-12-19 20:51:16 +00002205 if (Def->Data)
Douglas Gregor26fec632011-12-15 18:17:27 +00002206 ID->Data = Def->Data;
Douglas Gregor53df7a12011-12-15 18:03:09 +00002207 break;
2208 }
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00002209 }
2210 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00002211}