blob: 35cd8478d5be2725249a66e954675cd6b4f34667 [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-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 Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redlf5b13462010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner487412d2009-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 Lattnerca025db2010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000032namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregorde3ef502011-11-30 23:21:26 +000035 ModuleFile &F;
Sebastian Redlc67764e2010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl539c5062010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +000038 const unsigned RawLocation;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000039 typedef ASTReader::RecordData RecordData;
40 const RecordData &Record;
Chris Lattner487412d2009-04-27 05:27:42 +000041 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000042 TypeID TypeIDForTypeDecl;
Douglas Gregor250ffb12011-03-05 01:35:54 +000043
44 DeclID DeclContextIDForTemplateParmDecl;
45 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000046
Sebastian Redlc67764e2010-07-22 22:43:28 +000047 uint64_t GetCurrentCursorOffset();
Douglas Gregor7fb09192011-07-21 22:35:25 +000048
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000049 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000050 return Reader.ReadSourceLocation(F, R, I);
51 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000052
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000053 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000054 return Reader.ReadSourceRange(F, R, I);
55 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000056
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000057 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000058 return Reader.GetTypeSourceInfo(F, R, I);
59 }
Douglas Gregor7fb09192011-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 Kyrtzidis434383d2010-10-15 18:21:24 +000074 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000075 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000076 Reader.ReadQualifierInfo(F, Info, R, I);
77 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000078
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000079 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000080 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000081 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
82 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000083
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000084 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000085 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000086 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
87 }
Sebastian Redlc67764e2010-07-22 22:43:28 +000088
Douglas Gregorcf68c582011-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 Gregorba345522011-12-02 23:23:56 +000097 Module *readModule(const RecordData &R, unsigned &I) {
98 return Reader.getSubmodule(readSubmoduleID(R, I));
99 }
100
Argyrios Kyrtzidiseb39d9a2010-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 Lattner487412d2009-04-27 05:27:42 +0000107 public:
Douglas Gregorde3ef502011-11-30 23:21:26 +0000108 ASTDeclReader(ASTReader &Reader, ModuleFile &F,
Sebastian Redl2c373b92010-10-05 15:59:54 +0000109 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000110 unsigned RawLocation,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000111 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000112 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000113 RawLocation(RawLocation), Record(Record), Idx(Idx),
114 TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +0000115
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000116 static void attachPreviousDecl(Decl *D, Decl *previous);
Douglas Gregor05f10352011-12-17 23:38:30 +0000117 static void attachLatestDecl(Decl *D, Decl *latest);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000118
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000119 void Visit(Decl *D);
120
Douglas Gregorde3ef502011-11-30 23:21:26 +0000121 void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000122 const RecordData &Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000123
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000124 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
125 ObjCCategoryDecl *Next) {
126 Cat->NextClassCategory = Next;
127 }
128
Chris Lattner487412d2009-04-27 05:27:42 +0000129 void VisitDecl(Decl *D);
130 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
131 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000132 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000133 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000134 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
135 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000136 void VisitTypeDecl(TypeDecl *TD);
Douglas Gregor1f179062011-12-19 14:40:25 +0000137 void VisitTypedefNameDecl(TypedefNameDecl *TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000138 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000139 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000140 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000141 void VisitTagDecl(TagDecl *TD);
142 void VisitEnumDecl(EnumDecl *ED);
143 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000144 void VisitCXXRecordDecl(CXXRecordDecl *D);
145 void VisitClassTemplateSpecializationDecl(
146 ClassTemplateSpecializationDecl *D);
147 void VisitClassTemplatePartialSpecializationDecl(
148 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000149 void VisitClassScopeFunctionSpecializationDecl(
150 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000151 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000152 void VisitValueDecl(ValueDecl *VD);
153 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000154 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000155 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000156 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-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 Lattner487412d2009-04-27 05:27:42 +0000161 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000162 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000163 void VisitVarDecl(VarDecl *VD);
164 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
165 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000166 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
167 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000168 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000169 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000170 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000171 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000172 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000173 void VisitUsingDecl(UsingDecl *D);
174 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000175 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000176 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregorba345522011-12-02 23:23:56 +0000177 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000178 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000179 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000180 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
181 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000182 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000183
Chris Lattner487412d2009-04-27 05:27:42 +0000184 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000185 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000186
Alexis Hunted053252010-05-30 07:21:58 +0000187 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-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 Redlb3298c32010-08-18 23:56:48 +0000206uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregord32f0352011-07-22 06:10:01 +0000207 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000208}
209
Sebastian Redlb3298c32010-08-18 23:56:48 +0000210void ASTDeclReader::Visit(Decl *D) {
211 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000212
Jonathan D. Turner205c7d52011-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 Kyrtzidis33575162010-07-02 15:58:43 +0000225 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000226 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000227 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Douglas Gregorab1ec82e2011-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 Kyrtzidis33575162010-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 Redlc67764e2010-07-22 22:43:28 +0000234 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-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 Kyrtzidis33575162010-07-02 15:58:43 +0000244 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000245}
246
Sebastian Redlb3298c32010-08-18 23:56:48 +0000247void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-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 Gregor7fb09192011-07-21 22:35:25 +0000253 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
254 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000255 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000256 } else {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000257 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
258 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000259 }
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000260 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner487412d2009-04-27 05:27:42 +0000261 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000262 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000263 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000264 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000265 D->setAttrs(Attrs);
266 }
Chris Lattner487412d2009-04-27 05:27:42 +0000267 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000268 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000269 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +0000270 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000271 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000272 D->FromASTFile = true;
Douglas Gregor26701a42011-09-09 02:06:17 +0000273 D->ModulePrivate = Record[Idx++];
Douglas Gregorcf68c582011-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 Lattner487412d2009-04-27 05:27:42 +0000293}
294
Sebastian Redlb3298c32010-08-18 23:56:48 +0000295void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000296 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000297}
298
Sebastian Redlb3298c32010-08-18 23:56:48 +0000299void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000300 VisitDecl(ND);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000301 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000302}
303
Sebastian Redlb3298c32010-08-18 23:56:48 +0000304void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000305 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000306 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000307 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor903b7e92011-07-22 00:38:23 +0000308 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000309}
310
Douglas Gregor1f179062011-12-19 14:40:25 +0000311void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000312 VisitRedeclarable(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000313 VisitTypeDecl(TD);
Douglas Gregor1f179062011-12-19 14:40:25 +0000314 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
315}
316
317void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
318 VisitTypedefNameDecl(TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000319}
320
Richard Smithdda56e42011-04-15 14:24:37 +0000321void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000322 VisitTypedefNameDecl(TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000323}
324
Sebastian Redlb3298c32010-08-18 23:56:48 +0000325void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000326 VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000327 VisitTypeDecl(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000328 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000329 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCallf937c022011-10-07 06:10:15 +0000330 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000331 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000332 TD->setFreeStanding(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000333 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000334 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000335 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000336 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000337 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000338 } else
Douglas Gregor7fb09192011-07-21 22:35:25 +0000339 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000340}
341
Sebastian Redlb3298c32010-08-18 23:56:48 +0000342void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000343 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000344 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
345 ED->setIntegerTypeSourceInfo(TI);
346 else
Douglas Gregor903b7e92011-07-22 00:38:23 +0000347 ED->setIntegerType(Reader.readType(F, Record, Idx));
348 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000349 ED->setNumPositiveBits(Record[Idx++]);
350 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000351 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000352 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000353 ED->IsFixed = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000354 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000355}
356
Sebastian Redlb3298c32010-08-18 23:56:48 +0000357void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000358 VisitTagDecl(RD);
359 RD->setHasFlexibleArrayMember(Record[Idx++]);
360 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000361 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000362}
363
Sebastian Redlb3298c32010-08-18 23:56:48 +0000364void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000365 VisitNamedDecl(VD);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000366 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000367}
368
Sebastian Redlb3298c32010-08-18 23:56:48 +0000369void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000370 VisitValueDecl(ECD);
371 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000372 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000373 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
374}
375
Sebastian Redlb3298c32010-08-18 23:56:48 +0000376void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000377 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000378 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000379 if (Record[Idx++]) { // hasExtInfo
380 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000381 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000382 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000383 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000384 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000385}
386
Sebastian Redlb3298c32010-08-18 23:56:48 +0000387void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000388 VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000389 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000390
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000391 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000392 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000393 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikie83d382b2011-09-23 05:06:16 +0000394 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000395 case FunctionDecl::TK_NonTemplate:
396 break;
397 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000398 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
399 Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000400 break;
401 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000402 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000403 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000404 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000405 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000406 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
407 break;
408 }
409 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000410 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
411 Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000412 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
413
414 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000415 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000416 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000417
418 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000419 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000420 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000421 bool HasTemplateArgumentsAsWritten = Record[Idx++];
422 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000423 unsigned NumTemplateArgLocs = Record[Idx++];
424 TemplArgLocs.reserve(NumTemplateArgLocs);
425 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000426 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000427 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000428
Sebastian Redl2c373b92010-10-05 15:59:54 +0000429 LAngleLoc = ReadSourceLocation(Record, Idx);
430 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000431 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000432
Sebastian Redl2c373b92010-10-05 15:59:54 +0000433 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000434
Douglas Gregor4163aca2011-09-09 21:34:22 +0000435 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000436 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000437 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000438 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000439 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000440 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000441 FunctionTemplateSpecializationInfo *FTInfo
442 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
443 TemplArgList,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000444 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
445 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000446 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000447
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000448 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-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 Gregor7fb09192011-07-21 22:35:25 +0000452 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidise262a952010-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 Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000458 llvm::FoldingSetNodeID ID;
459 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
460 TemplArgs.size(), C);
461 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000462 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000463 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000464 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000465 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000466 break;
Argyrios Kyrtzidis69da4a82010-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 Gregor7fb09192011-07-21 22:35:25 +0000473 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000474
475 // Templates args.
476 TemplateArgumentListInfo TemplArgs;
477 unsigned NumArgs = Record[Idx++];
478 while (NumArgs--)
Sebastian Redl2c373b92010-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 Kyrtzidis69da4a82010-06-22 09:55:07 +0000482
Douglas Gregor4163aca2011-09-09 21:34:22 +0000483 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000484 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000485 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000486 }
487 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000488
Sebastian Redlb3298c32010-08-18 23:56:48 +0000489 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000490 // after everything else is read.
491
Douglas Gregorbf62d642010-12-06 18:36:25 +0000492 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000493 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000494 FD->IsInline = Record[Idx++];
495 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-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++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000502 FD->IsDefaulted = Record[Idx++];
503 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000504 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smitha77a0a62011-08-15 21:04:07 +0000505 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000506 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000507
Chris Lattnerca025db2010-05-07 21:43:38 +0000508 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000509 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000510 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000511 Params.reserve(NumParams);
512 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000513 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000514 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000515}
516
Sebastian Redlb3298c32010-08-18 23:56:48 +0000517void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-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 Redl2c373b92010-10-05 15:59:54 +0000522 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000523 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
524 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000525 }
526 MD->setInstanceMethod(Record[Idx++]);
527 MD->setVariadic(Record[Idx++]);
528 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000529 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidisdb215962011-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 Lattner487412d2009-04-27 05:27:42 +0000537 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
538 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000539 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000540 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000541 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
542 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000543 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000544 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000545 Params.reserve(NumParams);
546 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000547 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidisb8c3aaf2011-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 Lattner487412d2009-04-27 05:27:42 +0000557}
558
Sebastian Redlb3298c32010-08-18 23:56:48 +0000559void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000560 VisitNamedDecl(CD);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000561 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
562 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000563}
564
Sebastian Redlb3298c32010-08-18 23:56:48 +0000565void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000566 VisitRedeclarable(ID);
Chris Lattner487412d2009-04-27 05:27:42 +0000567 VisitObjCContainerDecl(ID);
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000568 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000569
Douglas Gregorc0ac7d62011-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 Gregor16408322011-12-15 22:34:59 +0000581 Data.EndLoc = ReadSourceLocation(Record, Idx);
582
Douglas Gregorc0ac7d62011-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 Kremenek0ef508d2010-09-01 01:21:15 +0000595
Douglas Gregorc0ac7d62011-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 Kremenek0ef508d2010-09-01 01:21:15 +0000604
Douglas Gregorc0ac7d62011-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 Gregor7fb09192011-07-21 22:35:25 +0000614
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000615 // We will rebuild this list lazily.
616 ID->setIvarList(0);
617
618 // If there are any pending forward references, make their definition data
619 // pointers point at the newly-allocated data.
620 ASTReader::PendingForwardRefsMap::iterator
621 FindI = Reader.PendingForwardRefs.find(ID);
622 if (FindI != Reader.PendingForwardRefs.end()) {
623 ASTReader::ForwardRefs &Refs = FindI->second;
624 for (ASTReader::ForwardRefs::iterator I = Refs.begin(),
625 E = Refs.end();
626 I != E; ++I)
Douglas Gregora323c4c2011-12-15 18:17:27 +0000627 cast<ObjCInterfaceDecl>(*I)->Data = ID->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000628#ifndef NDEBUG
629 // We later check whether PendingForwardRefs is empty to make sure all
630 // pending references were linked.
631 Reader.PendingForwardRefs.erase(ID);
632#endif
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000633 }
634 } else if (Def) {
635 if (Def->Data) {
636 ID->Data = Def->Data;
637 } else {
638 // The definition is still initializing.
639 Reader.PendingForwardRefs[Def].push_back(ID);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000640 }
641 }
Chris Lattner487412d2009-04-27 05:27:42 +0000642}
643
Sebastian Redlb3298c32010-08-18 23:56:48 +0000644void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000645 VisitFieldDecl(IVD);
646 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000647 // This field will be built lazily.
648 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000649 bool synth = Record[Idx++];
650 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000651}
652
Sebastian Redlb3298c32010-08-18 23:56:48 +0000653void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000654 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000655 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000656 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000657 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000658 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000659 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000660 ProtoRefs.reserve(NumProtoRefs);
661 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000662 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000663 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000664 ProtoLocs.reserve(NumProtoRefs);
665 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000666 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000667 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000668 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000669}
670
Sebastian Redlb3298c32010-08-18 23:56:48 +0000671void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000672 VisitFieldDecl(FD);
673}
674
Sebastian Redlb3298c32010-08-18 23:56:48 +0000675void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000676 VisitDecl(CD);
Douglas Gregor40d009f2011-12-14 17:12:03 +0000677 CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
678 CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000679}
680
Sebastian Redlb3298c32010-08-18 23:56:48 +0000681void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000682 VisitDecl(FPD);
683 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000684 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000685 ProtoRefs.reserve(NumProtoRefs);
686 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000687 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000688 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000689 ProtoLocs.reserve(NumProtoRefs);
690 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000691 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000692 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000693 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000694}
695
Sebastian Redlb3298c32010-08-18 23:56:48 +0000696void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000697 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000698 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000699 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000700 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000701 ProtoRefs.reserve(NumProtoRefs);
702 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000703 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000704 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000705 ProtoLocs.reserve(NumProtoRefs);
706 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000707 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000708 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000709 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000710 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000711 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000712 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000713}
714
Sebastian Redlb3298c32010-08-18 23:56:48 +0000715void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000716 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000717 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000718}
719
Sebastian Redlb3298c32010-08-18 23:56:48 +0000720void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000721 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000722 D->setAtLoc(ReadSourceLocation(Record, Idx));
723 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000724 // FIXME: stable encoding
725 D->setPropertyAttributes(
726 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000727 D->setPropertyAttributesAsWritten(
728 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000729 // FIXME: stable encoding
730 D->setPropertyImplementation(
731 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000732 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
733 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000734 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
735 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
736 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000737}
738
Sebastian Redlb3298c32010-08-18 23:56:48 +0000739void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000740 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000741 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000742}
743
Sebastian Redlb3298c32010-08-18 23:56:48 +0000744void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000745 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000746 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000747 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000748}
749
Sebastian Redlb3298c32010-08-18 23:56:48 +0000750void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000751 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000752 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000753 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000754 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000755 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000756}
757
758
Sebastian Redlb3298c32010-08-18 23:56:48 +0000759void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000760 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000761 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000762 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
763 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000764 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000765 D->setGetterCXXConstructor(Reader.ReadExpr(F));
766 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000767}
768
Sebastian Redlb3298c32010-08-18 23:56:48 +0000769void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000770 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000771 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000772 int BitWidthOrInitializer = Record[Idx++];
773 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000774 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000775 else if (BitWidthOrInitializer == 2)
776 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000777 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000778 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000779 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000780 }
Chris Lattner487412d2009-04-27 05:27:42 +0000781}
782
Francois Pichet783dd6e2010-11-21 06:08:52 +0000783void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
784 VisitValueDecl(FD);
785
786 FD->ChainingSize = Record[Idx++];
787 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000788 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000789
790 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000791 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000792}
793
Sebastian Redlb3298c32010-08-18 23:56:48 +0000794void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000795 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000796 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000797 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
798 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
799 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
800 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
801 VD->VarDeclBits.ExceptionVar = Record[Idx++];
802 VD->VarDeclBits.NRVOVariable = Record[Idx++];
803 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000804 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smithd0b4dd62011-12-19 06:19:21 +0000805 if (uint64_t Val = Record[Idx++]) {
Sebastian Redl2c373b92010-10-05 15:59:54 +0000806 VD->setInit(Reader.ReadExpr(F));
Richard Smithd0b4dd62011-12-19 06:19:21 +0000807 if (Val > 1) {
808 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
809 Eval->CheckedICE = true;
810 Eval->IsICE = Val == 3;
811 }
812 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000813
814 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000815 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000816 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000817 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000818 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000819 }
Chris Lattner487412d2009-04-27 05:27:42 +0000820}
821
Sebastian Redlb3298c32010-08-18 23:56:48 +0000822void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000823 VisitVarDecl(PD);
824}
825
Sebastian Redlb3298c32010-08-18 23:56:48 +0000826void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000827 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000828 unsigned isObjCMethodParam = Record[Idx++];
829 unsigned scopeDepth = Record[Idx++];
830 unsigned scopeIndex = Record[Idx++];
831 unsigned declQualifier = Record[Idx++];
832 if (isObjCMethodParam) {
833 assert(scopeDepth == 0);
834 PD->setObjCMethodScopeInfo(scopeIndex);
835 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
836 } else {
837 PD->setScopeInfo(scopeDepth, scopeIndex);
838 }
John McCallbeaa11c2011-05-01 02:13:58 +0000839 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
840 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000841 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000842 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000843}
844
Sebastian Redlb3298c32010-08-18 23:56:48 +0000845void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000846 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000847 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000848 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000849}
850
Sebastian Redlb3298c32010-08-18 23:56:48 +0000851void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000852 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000853 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
854 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000855 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000856 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000857 Params.reserve(NumParams);
858 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000859 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000860 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000861
862 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000863 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000864 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000865 captures.reserve(numCaptures);
866 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000867 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000868 unsigned flags = Record[Idx++];
869 bool byRef = (flags & 1);
870 bool nested = (flags & 2);
871 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
872
873 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
874 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000875 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000876 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000877}
878
Sebastian Redlb3298c32010-08-18 23:56:48 +0000879void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000880 VisitDecl(D);
881 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000882 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000883 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000884}
885
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000886void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
887 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000888 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000889}
890
891
Sebastian Redlb3298c32010-08-18 23:56:48 +0000892void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000893 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000894 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000895 D->LocStart = ReadSourceLocation(Record, Idx);
896 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000897 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000898
Chris Lattnerca025db2010-05-07 21:43:38 +0000899 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000900 // FIXME: Modules will likely have trouble with pointing directly at
901 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000902 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000903 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000904}
905
Sebastian Redlb3298c32010-08-18 23:56:48 +0000906void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000907 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000908 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000909 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000910 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000911 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000912}
913
Sebastian Redlb3298c32010-08-18 23:56:48 +0000914void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000915 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000916 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000917 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000918 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000919 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000920 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000921 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000922 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000923}
924
Sebastian Redlb3298c32010-08-18 23:56:48 +0000925void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000926 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000927 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
928 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
929 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000930 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000931 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000932}
933
Sebastian Redlb3298c32010-08-18 23:56:48 +0000934void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000935 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000936 D->UsingLoc = ReadSourceLocation(Record, Idx);
937 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000938 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000939 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
940 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000941}
942
Sebastian Redlb3298c32010-08-18 23:56:48 +0000943void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000944 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000945 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000946 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000947 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000948}
949
Sebastian Redlb3298c32010-08-18 23:56:48 +0000950void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000951 UnresolvedUsingTypenameDecl *D) {
952 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000953 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000954 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000955}
956
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000957void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000958 struct CXXRecordDecl::DefinitionData &Data,
959 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000960 Data.UserDeclaredConstructor = Record[Idx++];
961 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000962 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000963 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000964 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000965 Data.UserDeclaredDestructor = Record[Idx++];
966 Data.Aggregate = Record[Idx++];
967 Data.PlainOldData = Record[Idx++];
968 Data.Empty = Record[Idx++];
969 Data.Polymorphic = Record[Idx++];
970 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000971 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000972 Data.HasNoNonEmptyBases = Record[Idx++];
973 Data.HasPrivateFields = Record[Idx++];
974 Data.HasProtectedFields = Record[Idx++];
975 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000976 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000977 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000978 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000979 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000980 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000981 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000982 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000983 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000984 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000985 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000986 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000987 Data.DeclaredDefaultConstructor = Record[Idx++];
988 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000989 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000990 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000991 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000992 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000993 Data.FailedImplicitMoveConstructor = Record[Idx++];
994 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000995
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000996 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000997 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000998 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000999 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001000 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +00001001 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001002
Douglas Gregor7fb09192011-07-21 22:35:25 +00001003 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
1004 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001005 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001006 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001007}
1008
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001009void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
1010 CXXRecordDecl *DefinitionDecl,
1011 const RecordData &Record,
1012 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001013 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +00001014
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001015 if (D == DefinitionDecl) {
1016 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001017 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001018 // We read the definition info. Check if there are pending forward
1019 // references that need to point to this DefinitionData pointer.
1020 ASTReader::PendingForwardRefsMap::iterator
1021 FindI = Reader.PendingForwardRefs.find(D);
1022 if (FindI != Reader.PendingForwardRefs.end()) {
1023 ASTReader::ForwardRefs &Refs = FindI->second;
1024 for (ASTReader::ForwardRefs::iterator
1025 I = Refs.begin(), E = Refs.end(); I != E; ++I)
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001026 cast<CXXRecordDecl>(*I)->DefinitionData = D->DefinitionData;
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001027#ifndef NDEBUG
1028 // We later check whether PendingForwardRefs is empty to make sure all
1029 // pending references were linked.
1030 Reader.PendingForwardRefs.erase(D);
1031#endif
1032 }
1033 } else if (DefinitionDecl) {
1034 if (DefinitionDecl->DefinitionData) {
1035 D->DefinitionData = DefinitionDecl->DefinitionData;
1036 } else {
1037 // The definition is still initializing.
1038 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
1039 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001040 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001041}
1042
1043void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1044 VisitRecordDecl(D);
1045
Douglas Gregor7fb09192011-07-21 22:35:25 +00001046 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001047 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1048
Douglas Gregor4163aca2011-09-09 21:34:22 +00001049 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001050
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001051 enum CXXRecKind {
1052 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1053 };
1054 switch ((CXXRecKind)Record[Idx++]) {
1055 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001056 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001057 case CXXRecNotTemplate:
1058 break;
1059 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001060 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001061 break;
1062 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001063 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001064 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001065 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001066 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1067 MSI->setPointOfInstantiation(POI);
1068 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001069 break;
1070 }
1071 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001072
1073 // Load the key function to avoid deserializing every method so we can
1074 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001075 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001076 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001077 C.KeyFunctions[D] = Key;
1078 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001079}
1080
Sebastian Redlb3298c32010-08-18 23:56:48 +00001081void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001082 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001083 unsigned NumOverridenMethods = Record[Idx++];
1084 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001085 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1086 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001087 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001088 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001089 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001090}
1091
Sebastian Redlb3298c32010-08-18 23:56:48 +00001092void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001093 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001094
1095 D->IsExplicitSpecified = Record[Idx++];
1096 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001097 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1098 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001099}
1100
Sebastian Redlb3298c32010-08-18 23:56:48 +00001101void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001102 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001103
1104 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001105 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001106}
1107
Sebastian Redlb3298c32010-08-18 23:56:48 +00001108void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001109 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001110 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001111}
1112
Douglas Gregorba345522011-12-02 23:23:56 +00001113void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1114 VisitDecl(D);
1115 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1116 D->ImportedAndComplete.setInt(Record[Idx++]);
1117 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1118 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1119 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1120 ++Idx;
1121}
1122
Sebastian Redlb3298c32010-08-18 23:56:48 +00001123void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001124 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001125 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001126}
1127
Sebastian Redlb3298c32010-08-18 23:56:48 +00001128void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001129 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001130 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001131 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001132 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001133 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001134 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001135 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001136 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001137}
1138
Sebastian Redlb3298c32010-08-18 23:56:48 +00001139void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001140 VisitDecl(D);
1141 unsigned NumParams = Record[Idx++];
1142 D->NumParams = NumParams;
1143 D->Params = new TemplateParameterList*[NumParams];
1144 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001145 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001146 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001147 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001148 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001149 D->Friend = GetTypeSourceInfo(Record, Idx);
1150 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001151}
1152
Sebastian Redlb3298c32010-08-18 23:56:48 +00001153void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001154 VisitNamedDecl(D);
1155
Douglas Gregor7fb09192011-07-21 22:35:25 +00001156 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001157 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001158 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001159 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001160}
1161
Sebastian Redlb3298c32010-08-18 23:56:48 +00001162void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001163 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1164 // can be used while this is still initializing.
Douglas Gregor074a4092011-12-19 18:19:24 +00001165 enum RedeclKind { FirstDeclaration, PointsToPrevious };
1166 RedeclKind Kind = (RedeclKind)Record[Idx++];
1167
1168 // Determine the first declaration ID.
1169 DeclID FirstDeclID;
1170 switch (Kind) {
1171 case FirstDeclaration: {
1172 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001173
Douglas Gregor074a4092011-12-19 18:19:24 +00001174 // Since this is the first declaration of the template, fill in the
1175 // information for the 'common' pointer.
1176 if (D->CommonOrPrev.isNull()) {
1177 RedeclarableTemplateDecl::CommonBase *Common
1178 = D->newCommon(Reader.getContext());
1179 Common->Latest = D;
1180 D->CommonOrPrev = Common;
1181 }
1182
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001183 if (RedeclarableTemplateDecl *RTD
Douglas Gregor074a4092011-12-19 18:19:24 +00001184 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001185 assert(RTD->getKind() == D->getKind() &&
1186 "InstantiatedFromMemberTemplate kind mismatch");
1187 D->setInstantiatedFromMemberTemplateImpl(RTD);
1188 if (Record[Idx++])
1189 D->setMemberSpecialization();
1190 }
Douglas Gregor074a4092011-12-19 18:19:24 +00001191 break;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001192 }
Douglas Gregor074a4092011-12-19 18:19:24 +00001193
1194 case PointsToPrevious: {
1195 FirstDeclID = ReadDeclID(Record, Idx);
1196 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1197
1198 RedeclarableTemplateDecl *FirstDecl
1199 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1200
1201 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1202 // We temporarily set the first (canonical) declaration as the previous one
1203 // which is the one that matters and mark the real previous DeclID to be
1204 // loaded and attached later on.
1205 D->CommonOrPrev = FirstDecl;
1206
1207 // Make a note that we need to wire up this declaration to its
1208 // previous declaration, later.
1209 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PrevDeclID));
1210 break;
1211 }
1212 }
1213
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001214 VisitTemplateDecl(D);
1215 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001216}
1217
Sebastian Redlb3298c32010-08-18 23:56:48 +00001218void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001219 VisitRedeclarableTemplateDecl(D);
1220
1221 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001222 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1223 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001224 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001225 SpecIDs.push_back(0);
1226
1227 // Specializations.
1228 unsigned Size = Record[Idx++];
1229 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001230 for (unsigned I = 0; I != Size; ++I)
1231 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001232
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001233 // Partial specializations.
1234 Size = Record[Idx++];
1235 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001236 for (unsigned I = 0; I != Size; ++I)
1237 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001238
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001239 if (SpecIDs[0]) {
1240 typedef serialization::DeclID DeclID;
1241
1242 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1243 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001244 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001245 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1246 SpecIDs.size() * sizeof(DeclID));
1247 }
1248
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001249 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001250 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001251}
1252
Sebastian Redlb3298c32010-08-18 23:56:48 +00001253void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001254 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001255 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001256
Douglas Gregor4163aca2011-09-09 21:34:22 +00001257 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001258 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001259 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001260 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001261 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001262 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001263 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001264 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001265 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1266 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001267 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1268 = new (C) ClassTemplateSpecializationDecl::
1269 SpecializedPartialSpecialization();
1270 PS->PartialSpecialization
1271 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1272 PS->TemplateArgs = ArgList;
1273 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001274 }
1275 }
1276
1277 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001278 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001279 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1280 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1281 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001282 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1283 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001284 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001285 }
1286
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001287 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001288 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001289 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1290 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001291 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001292 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001293
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001294 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001295 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001296 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001297 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1298 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001299 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001300 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001301 }
1302 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001303}
1304
Sebastian Redlb3298c32010-08-18 23:56:48 +00001305void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001306 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001307 VisitClassTemplateSpecializationDecl(D);
1308
Douglas Gregor4163aca2011-09-09 21:34:22 +00001309 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001310 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001311
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001312 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001313 if (NumArgs) {
1314 D->NumArgsAsWritten = NumArgs;
1315 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1316 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001317 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001318 }
1319
1320 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001321
1322 // These are read/set from/to the first declaration.
1323 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001324 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001325 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001326 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001327 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001328}
1329
Sebastian Redlb7448632011-08-31 13:59:56 +00001330void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1331 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001332 VisitDecl(D);
1333 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1334}
1335
Sebastian Redlb3298c32010-08-18 23:56:48 +00001336void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001337 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001338
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001339 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001340 // This FunctionTemplateDecl owns a CommonPtr; read it.
1341
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001342 // Read the function specialization declarations.
1343 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001344 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001345 unsigned NumSpecs = Record[Idx++];
1346 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001347 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001348 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001349}
1350
Sebastian Redlb3298c32010-08-18 23:56:48 +00001351void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001352 VisitTypeDecl(D);
1353
1354 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001355
1356 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001357 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001358 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001359}
1360
Sebastian Redlb3298c32010-08-18 23:56:48 +00001361void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001362 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001363 // TemplateParmPosition.
1364 D->setDepth(Record[Idx++]);
1365 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001366 if (D->isExpandedParameterPack()) {
1367 void **Data = reinterpret_cast<void **>(D + 1);
1368 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001369 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001370 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1371 }
1372 } else {
1373 // Rest of NonTypeTemplateParmDecl.
1374 D->ParameterPack = Record[Idx++];
1375 if (Record[Idx++]) {
1376 Expr *DefArg = Reader.ReadExpr(F);
1377 bool Inherited = Record[Idx++];
1378 D->setDefaultArgument(DefArg, Inherited);
1379 }
1380 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001381}
1382
Sebastian Redlb3298c32010-08-18 23:56:48 +00001383void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001384 VisitTemplateDecl(D);
1385 // TemplateParmPosition.
1386 D->setDepth(Record[Idx++]);
1387 D->setPosition(Record[Idx++]);
1388 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001389 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001390 bool IsInherited = Record[Idx++];
1391 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001392 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001393}
1394
Richard Smith3f1b5d02011-05-05 21:57:07 +00001395void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1396 VisitRedeclarableTemplateDecl(D);
1397}
1398
Sebastian Redlb3298c32010-08-18 23:56:48 +00001399void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001400 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001401 D->AssertExpr = Reader.ReadExpr(F);
1402 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001403 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001404}
1405
Mike Stump11289f42009-09-09 15:08:12 +00001406std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001407ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001408 uint64_t LexicalOffset = Record[Idx++];
1409 uint64_t VisibleOffset = Record[Idx++];
1410 return std::make_pair(LexicalOffset, VisibleOffset);
1411}
1412
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001413template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001414void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001415 enum RedeclKind { FirstDeclaration = 0, PointsToPrevious };
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001416 RedeclKind Kind = (RedeclKind)Record[Idx++];
Douglas Gregor05f10352011-12-17 23:38:30 +00001417
Douglas Gregor074a4092011-12-19 18:19:24 +00001418 DeclID FirstDeclID;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001419 switch (Kind) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001420 case FirstDeclaration:
1421 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001422 break;
Douglas Gregor05f10352011-12-17 23:38:30 +00001423
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001424 case PointsToPrevious: {
Douglas Gregor074a4092011-12-19 18:19:24 +00001425 FirstDeclID = ReadDeclID(Record, Idx);
1426 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1427
1428 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
Douglas Gregor05f10352011-12-17 23:38:30 +00001429
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001430 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1431 // We temporarily set the first (canonical) declaration as the previous one
1432 // which is the one that matters and mark the real previous DeclID to be
1433 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001434 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Douglas Gregor3e300102011-10-26 17:53:41 +00001435
Douglas Gregor05f10352011-12-17 23:38:30 +00001436 // Make a note that we need to wire up this declaration to its
1437 // previous declaration, later.
1438 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
Douglas Gregor074a4092011-12-19 18:19:24 +00001439 PrevDeclID));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001440 break;
1441 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001442 }
Douglas Gregor074a4092011-12-19 18:19:24 +00001443
1444 // Note that we need to load the other declaration chains for this ID.
1445 if (Reader.PendingDeclChainsKnown.insert(ThisDeclID))
1446 Reader.PendingDeclChains.push_back(ThisDeclID);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001447}
1448
Chris Lattner487412d2009-04-27 05:27:42 +00001449//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001450// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001451//===----------------------------------------------------------------------===//
1452
Chris Lattner8f63ab52009-04-27 06:01:06 +00001453/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001454void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001455 const RecordData &Record, unsigned &Idx) {
1456 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001457 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001458 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001459 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001460
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001461#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001462
1463 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001464 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001465 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001466}
1467
1468//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001469// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001470//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001471
1472/// \brief Note that we have loaded the declaration with the given
1473/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001474///
Chris Lattner487412d2009-04-27 05:27:42 +00001475/// This routine notes that this declaration has already been loaded,
1476/// so that future GetDecl calls will return this declaration rather
1477/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001478inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001479 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1480 DeclsLoaded[Index] = D;
1481}
1482
1483
1484/// \brief Determine whether the consumer will be interested in seeing
1485/// this declaration (via HandleTopLevelDecl).
1486///
1487/// This routine should return true for anything that might affect
1488/// code generation, e.g., inline function definitions, Objective-C
1489/// declarations with metadata, etc.
1490static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001491 // An ObjCMethodDecl is never considered as "interesting" because its
1492 // implementation container always is.
1493
Douglas Gregor87d81242011-09-10 00:22:34 +00001494 if (isa<FileScopeAsmDecl>(D) ||
1495 isa<ObjCProtocolDecl>(D) ||
1496 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001497 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001498 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001499 return Var->isFileVarDecl() &&
1500 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001501 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001502 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001503
1504 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001505}
1506
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001507/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001508ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001509ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001510 // See if there's an override.
1511 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001512 if (It != ReplacedDecls.end()) {
1513 RawLocation = It->second.RawLoc;
1514 return RecordLocation(It->second.Mod, It->second.Offset);
1515 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001516
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001517 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1518 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001519 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001520 const DeclOffset &
1521 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1522 RawLocation = DOffs.Loc;
1523 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001524}
1525
Douglas Gregord32f0352011-07-22 06:10:01 +00001526ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001527 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001528 = GlobalBitOffsetsMap.find(GlobalOffset);
1529
1530 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1531 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1532}
1533
Douglas Gregorde3ef502011-11-30 23:21:26 +00001534uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001535 return LocalOffset + M.GlobalBitOffset;
1536}
1537
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001538void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1539 assert(D && previous);
1540 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1541 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1542 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1543 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1544 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1545 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
Douglas Gregor05f10352011-12-17 23:38:30 +00001546 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1547 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
1548 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregorab1ec82e2011-12-16 03:12:41 +00001549 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001550 } else {
1551 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1552 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1553 }
1554}
1555
Douglas Gregor05f10352011-12-17 23:38:30 +00001556void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
1557 assert(D && Latest);
1558 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1559 TD->RedeclLink
1560 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
1561 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1562 FD->RedeclLink
1563 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
1564 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1565 VD->RedeclLink
1566 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
1567 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1568 TD->RedeclLink
1569 = Redeclarable<TypedefNameDecl>::LatestDeclLink(
1570 cast<TypedefNameDecl>(Latest));
1571 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
1572 ID->RedeclLink
1573 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
1574 cast<ObjCInterfaceDecl>(Latest));
1575 } else {
1576 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1577 TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest);
1578 }
1579}
1580
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001581void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1582 Decl *previous = GetDecl(ID);
1583 ASTDeclReader::attachPreviousDecl(D, previous);
1584}
1585
Sebastian Redlb3298c32010-08-18 23:56:48 +00001586/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001587Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001588 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001589 unsigned RawLocation = 0;
1590 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001591 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001592 // Keep track of where we are in the stream, then jump back there
1593 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001594 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001595
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001596 ReadingKindTracker ReadingKind(Read_Decl, *this);
1597
Douglas Gregor1342e842009-07-06 18:54:52 +00001598 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001599 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001600
Sebastian Redl2c373b92010-10-05 15:59:54 +00001601 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001602 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001603 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001604 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001605 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001606
Chris Lattner1de76db2009-04-27 05:58:23 +00001607 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001608 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001609 case DECL_CONTEXT_LEXICAL:
1610 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001611 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001612 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001613 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001614 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001615 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001616 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001617 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001618 0, 0);
1619 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001620 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001621 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001622 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001623 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001624 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001625 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001626 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001627 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001628 0, llvm::APSInt());
1629 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001630 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001631 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001632 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001633 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001634 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001635 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001636 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001637 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001638 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001639 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001640 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001641 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001642 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001643 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001644 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001645 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001646 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001647 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001648 SourceLocation(), 0,
1649 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001650 SourceLocation(), 0);
1651 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001652 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001653 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001654 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1655 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001656 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001657 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001658 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001659 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001660 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001661 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001662 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001663 SourceLocation(), 0, 0);
1664 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001665 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001666 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001667 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001668 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001669 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001670 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001671 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001672 SourceLocation(),
1673 NestedNameSpecifierLoc(),
1674 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001675 DeclarationName());
1676 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001677 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001678 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001679 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001680 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001681 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001682 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001683 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001684 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001685 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001686 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001687 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001688 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001689 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001690 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001691 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001692 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001693 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001694 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001695 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001696 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001697 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001698 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001699 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001700 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001701 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001702 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001703 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001704 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001705 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001706 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001707 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001708 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001709 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001710 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001711 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001712 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001713 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001714 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001715 Decl::EmptyShell());
1716 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001717 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001718 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001719 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001720 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001721 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001722 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001723 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001724 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001725 SourceLocation(), 0, 0, 0, QualType(),
1726 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001727 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001728 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001729 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001730 SourceLocation(), 0, 0, 0, QualType(),
1731 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001732 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001733 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001734 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001735 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001736 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001737 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001738 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001739 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001740 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001741 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001742 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001743 break;
1744
Sebastian Redl539c5062010-08-18 23:57:32 +00001745 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001746 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001747 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001748 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001749 case DECL_OBJC_INTERFACE:
Douglas Gregorab1ec82e2011-12-16 03:12:41 +00001750 D = ObjCInterfaceDecl::CreateEmpty(Context);
Chris Lattner487412d2009-04-27 05:27:42 +00001751 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001752 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001753 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001754 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001755 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001756 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001757 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001758 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001759 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001760 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001761 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001762 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001763 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001764 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001765 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001766 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001767 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001768 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001769 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001770 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001771 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001772 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001773 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001774 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +00001775 SourceLocation(), SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001776 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001777 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001778 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1779 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001780 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001781 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001782 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001783 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001784 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001785 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001786 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001787 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001788 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001789 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001790 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001791 ObjCPropertyImplDecl::Dynamic, 0,
1792 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001793 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001794 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001795 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001796 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001797 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001798 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001799 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001800 0, 0);
1801 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001802 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001803 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001804 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001805 break;
1806
Sebastian Redl539c5062010-08-18 23:57:32 +00001807 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001808 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001809 break;
1810
Sebastian Redl539c5062010-08-18 23:57:32 +00001811 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001812 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001813 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001814 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001815 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001816 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001817 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001818 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001819 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001820 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001821 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001822 case DECL_CXX_BASE_SPECIFIERS:
1823 Error("attempt to read a C++ base-specifier record as a declaration");
1824 return 0;
Douglas Gregorba345522011-12-02 23:23:56 +00001825 case DECL_IMPORT:
1826 // Note: last entry of the ImportDecl record is the number of stored source
1827 // locations.
1828 D = ImportDecl::CreateEmpty(Context, Record.back());
1829 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001830 }
Chris Lattner487412d2009-04-27 05:27:42 +00001831
Sebastian Redlb3298c32010-08-18 23:56:48 +00001832 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001833 LoadedDecl(Index, D);
1834 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001835
1836 // If this declaration is also a declaration context, get the
1837 // offsets for its tables of lexical and visible declarations.
1838 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1839 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1840 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001841 if (Offsets.first != 0)
1842 DC->setHasExternalLexicalStorage(true);
1843 if (Offsets.second != 0)
1844 DC->setHasExternalVisibleStorage(true);
1845 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1846 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001847 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001848 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001849
Sebastian Redlf830df42011-04-24 16:27:54 +00001850 // Now add the pending visible updates for this decl context, if it has any.
1851 DeclContextVisibleUpdatesPending::iterator I =
1852 PendingVisibleUpdates.find(ID);
1853 if (I != PendingVisibleUpdates.end()) {
1854 // There are updates. This means the context has external visible
1855 // storage, even if the original stored version didn't.
1856 DC->setHasExternalVisibleStorage(true);
1857 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001858 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1859 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001860 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001861 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001862 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001863 }
1864 }
1865 assert(Idx == Record.size());
1866
Douglas Gregordab42432011-08-12 00:15:20 +00001867 // Load any relevant update records.
1868 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001869
1870 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001871 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001872 PendingChainedObjCCategories.push_back(
1873 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001874
Douglas Gregordab42432011-08-12 00:15:20 +00001875 // If we have deserialized a declaration that has a definition the
1876 // AST consumer might need to know about, queue it.
1877 // We don't pass it to the consumer immediately because we may be in recursive
1878 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001879 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001880 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001881
Douglas Gregordab42432011-08-12 00:15:20 +00001882 return D;
1883}
1884
1885void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001886 // The declaration may have been modified by files later in the chain.
1887 // If this is the case, read the record containing the updates from each file
1888 // and pass it to ASTDeclReader to make the modifications.
1889 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1890 if (UpdI != DeclUpdateOffsets.end()) {
1891 FileOffsetsTy &UpdateOffsets = UpdI->second;
1892 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001893 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001894 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001895 uint64_t Offset = I->second;
1896 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1897 SavedStreamPosition SavedPosition(Cursor);
1898 Cursor.JumpToBit(Offset);
1899 RecordData Record;
1900 unsigned Code = Cursor.ReadCode();
1901 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1902 (void)RecCode;
1903 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001904
1905 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001906 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001907 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001908 }
1909 }
Chris Lattner487412d2009-04-27 05:27:42 +00001910}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001911
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001912namespace {
Douglas Gregor05f10352011-12-17 23:38:30 +00001913 struct CompareLocalRedeclarationsInfoToID {
1914 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) {
1915 return X.FirstID < Y;
1916 }
1917
1918 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) {
1919 return X < Y.FirstID;
1920 }
1921
1922 bool operator()(const LocalRedeclarationsInfo &X,
1923 const LocalRedeclarationsInfo &Y) {
1924 return X.FirstID < Y.FirstID;
1925 }
1926 bool operator()(DeclID X, DeclID Y) {
1927 return X < Y;
1928 }
1929 };
1930
1931 class RedeclChainVisitor {
1932 ASTReader &Reader;
1933 DeclID GlobalFirstID;
1934 llvm::SmallVector<std::pair<Decl *, Decl *>, 4> Chains;
1935
1936 public:
1937 RedeclChainVisitor(ASTReader &Reader, DeclID GlobalFirstID)
1938 : Reader(Reader), GlobalFirstID(GlobalFirstID) { }
1939
1940 static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
1941 if (Preorder)
1942 return false;
1943
1944 return static_cast<RedeclChainVisitor *>(UserData)->visit(M);
1945 }
1946
1947 bool visit(ModuleFile &M) {
1948 // Map global ID of the first declaration down to the local ID
1949 // used in this module file.
1950 DeclID FirstID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalFirstID);
1951 if (!FirstID)
1952 return false;
1953
1954 // Perform a binary search to find the local redeclarations for this
1955 // declaration (if any).
1956 const LocalRedeclarationsInfo *Result
1957 = std::lower_bound(M.RedeclarationsInfo,
1958 M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos,
1959 FirstID, CompareLocalRedeclarationsInfoToID());
1960 if (Result == M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos ||
1961 Result->FirstID != FirstID)
1962 return false;
1963
1964 // Dig out the starting/ending declarations.
1965 Decl *FirstLocalDecl = Reader.GetLocalDecl(M, Result->FirstLocalID);
1966 Decl *LastLocalDecl = Reader.GetLocalDecl(M, Result->LastLocalID);
1967 if (!FirstLocalDecl || !LastLocalDecl)
1968 return false;
1969
1970 // Append this redeclaration chain to the list.
1971 Chains.push_back(std::make_pair(FirstLocalDecl, LastLocalDecl));
1972 return false;
1973 }
1974
1975 ArrayRef<std::pair<Decl *, Decl *> > getChains() const {
1976 return Chains;
1977 }
1978
1979 void addParsed(Decl *FirstParsedDecl, Decl *LastParsedDecl) {
1980 Chains.push_back(std::make_pair(FirstParsedDecl, LastParsedDecl));
1981 }
1982 };
1983}
1984
1985/// \brief Retrieve the previous declaration to D.
1986static Decl *getPreviousDecl(Decl *D) {
1987 if (TagDecl *TD = dyn_cast<TagDecl>(D))
1988 return TD->getPreviousDeclaration();
1989 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1990 return FD->getPreviousDeclaration();
1991 if (VarDecl *VD = dyn_cast<VarDecl>(D))
1992 return VD->getPreviousDeclaration();
1993 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
1994 return TD->getPreviousDeclaration();
1995 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
1996 return ID->getPreviousDeclaration();
1997
1998 return cast<RedeclarableTemplateDecl>(D)->getPreviousDeclaration();
1999}
2000
2001/// \brief Retrieve the most recent declaration of D.
2002static Decl *getMostRecentDecl(Decl *D) {
2003 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2004 return TD->getMostRecentDeclaration();
2005 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2006 return FD->getMostRecentDeclaration();
2007 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2008 return VD->getMostRecentDeclaration();
2009 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2010 return TD->getMostRecentDeclaration();
2011 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2012 return ID->getMostRecentDeclaration();
2013
2014 return cast<RedeclarableTemplateDecl>(D)->getMostRecentDeclaration();
2015}
2016
2017void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
2018 // Build up the list of redeclaration chains.
2019 RedeclChainVisitor Visitor(*this, ID);
2020 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor);
2021
2022 // Retrieve the chains.
2023 ArrayRef<std::pair<Decl *, Decl *> > Chains = Visitor.getChains();
2024 if (Chains.empty())
2025 return;
2026
2027 // FIXME: Splice local (not from AST file) declarations into the list,
2028 // rather than always re-ordering them.
2029 Decl *CanonDecl = GetDecl(ID);
2030
2031 // Capture all of the parsed declarations and put them at the end.
2032 Decl *MostRecent = getMostRecentDecl(CanonDecl);
2033 Decl *FirstParsed = MostRecent;
2034 if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) {
2035 Decl *Current = MostRecent;
2036 while (Decl *Prev = getPreviousDecl(Current)) {
2037 if (Prev->isFromASTFile()) {
2038 Current = Prev;
2039 continue;
2040 }
2041
2042 // Chain all of the parsed declarations together.
2043 ASTDeclReader::attachPreviousDecl(FirstParsed, Prev);
2044 FirstParsed = Prev;
2045 Current = Prev;
2046 }
2047
2048 Visitor.addParsed(FirstParsed, MostRecent);
2049 }
2050
2051 // Hook up the separate chains.
2052 Chains = Visitor.getChains();
2053 for (unsigned I = 1, N = Chains.size(); I != N; ++I)
2054 ASTDeclReader::attachPreviousDecl(Chains[I].first, Chains[I-1].second);
2055 ASTDeclReader::attachLatestDecl(CanonDecl, Chains.back().second);
2056}
2057
2058namespace {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002059 /// \brief Given an ObjC interface, goes through the modules and links to the
2060 /// interface all the categories for it.
2061 class ObjCChainedCategoriesVisitor {
2062 ASTReader &Reader;
2063 serialization::GlobalDeclID InterfaceID;
2064 ObjCInterfaceDecl *Interface;
2065 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
2066 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
2067
2068 public:
2069 ObjCChainedCategoriesVisitor(ASTReader &Reader,
2070 serialization::GlobalDeclID InterfaceID,
2071 ObjCInterfaceDecl *Interface)
2072 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
2073 GlobHeadCat(0), GlobTailCat(0) { }
2074
Douglas Gregorde3ef502011-11-30 23:21:26 +00002075 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002076 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
2077 }
2078
Douglas Gregorde3ef502011-11-30 23:21:26 +00002079 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002080 if (Reader.isDeclIDFromModule(InterfaceID, M))
2081 return true; // We reached the module where the interface originated
2082 // from. Stop traversing the imported modules.
2083
Douglas Gregorde3ef502011-11-30 23:21:26 +00002084 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002085 I = M.ChainedObjCCategories.find(InterfaceID);
2086 if (I == M.ChainedObjCCategories.end())
2087 return false;
2088
2089 ObjCCategoryDecl *
2090 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
2091 ObjCCategoryDecl *
2092 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
2093
2094 addCategories(HeadCat, TailCat);
2095 return false;
2096 }
2097
2098 void addCategories(ObjCCategoryDecl *HeadCat,
2099 ObjCCategoryDecl *TailCat = 0) {
2100 if (!HeadCat) {
2101 assert(!TailCat);
2102 return;
2103 }
2104
2105 if (!TailCat) {
2106 TailCat = HeadCat;
2107 while (TailCat->getNextClassCategory())
2108 TailCat = TailCat->getNextClassCategory();
2109 }
2110
2111 if (!GlobHeadCat) {
2112 GlobHeadCat = HeadCat;
2113 GlobTailCat = TailCat;
2114 } else {
2115 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
2116 GlobTailCat = TailCat;
2117 }
2118
2119 llvm::DenseSet<DeclarationName> Checked;
2120 for (ObjCCategoryDecl *Cat = HeadCat,
2121 *CatEnd = TailCat->getNextClassCategory();
2122 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
2123 if (Checked.count(Cat->getDeclName()))
2124 continue;
2125 Checked.insert(Cat->getDeclName());
2126 checkForDuplicate(Cat);
2127 }
2128 }
2129
2130 /// \brief Warns for duplicate categories that come from different modules.
2131 void checkForDuplicate(ObjCCategoryDecl *Cat) {
2132 DeclarationName Name = Cat->getDeclName();
2133 // Find the top category with the same name. We do not want to warn for
2134 // duplicates along the established chain because there were already
2135 // warnings for them when the module was created. We only want to warn for
2136 // duplicates between non-dependent modules:
2137 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00002138 // MT //
2139 // / \ //
2140 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002141 //
2142 // We want to warn for duplicates between ML and MR,not between ML and MT.
2143 //
2144 // FIXME: We should not warn for duplicates in diamond:
2145 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00002146 // MT //
2147 // / \ //
2148 // ML MR //
2149 // \ / //
2150 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002151 //
2152 // If there are duplicates in ML/MR, there will be warning when creating
2153 // MB *and* when importing MB. We should not warn when importing.
2154 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
2155 Next = Next->getNextClassCategory()) {
2156 if (Next->getDeclName() == Name)
2157 Cat = Next;
2158 }
2159
2160 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2161 if (!PrevCat)
2162 PrevCat = Cat;
2163
2164 if (PrevCat != Cat) {
2165 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2166 << Interface->getDeclName() << Name;
2167 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2168 }
2169 }
2170
2171 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2172 };
2173}
2174
2175void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2176 ObjCInterfaceDecl *D) {
2177 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2178 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2179 // Also add the categories that the interface already links to.
2180 Visitor.addCategories(D->getCategoryList());
2181 D->setCategoryList(Visitor.getHeadCategory());
2182}
Douglas Gregordab42432011-08-12 00:15:20 +00002183
Douglas Gregorde3ef502011-11-30 23:21:26 +00002184void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002185 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002186 unsigned Idx = 0;
2187 while (Idx < Record.size()) {
2188 switch ((DeclUpdateKind)Record[Idx++]) {
2189 case UPD_CXX_SET_DEFINITIONDATA: {
2190 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00002191 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00002192 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002193 assert(!RD->DefinitionData && "DefinitionData is already set!");
2194 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2195 break;
2196 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002197
2198 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00002199 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002200 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00002201
2202 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2203 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002204 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002205 break;
2206
2207 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00002208 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00002209 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00002210 // Guard against these being loaded out of original order. Don't use
2211 // getNextNamespace(), since it tries to access the context and can't in
2212 // the middle of deserialization.
2213 if (!Anon->NextNamespace) {
2214 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2215 TU->setAnonymousNamespace(Anon);
2216 else
2217 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2218 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002219 break;
2220 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002221
2222 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2223 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002224 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002225 break;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002226
2227 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2228 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2229 ObjCInterfaceDecl *Def
2230 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregora323c4c2011-12-15 18:17:27 +00002231 if (Def->Data) {
2232 ID->Data = Def->Data;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002233 } else {
2234 // The definition is still initializing.
2235 Reader.PendingForwardRefs[Def].push_back(ID);
2236 }
2237 break;
2238 }
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002239 }
2240 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002241}