blob: 85cd72840af1e0ed6bda11b6325dc9fb0a24e836 [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
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +000097 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
98 const RecordData &R, unsigned &I);
99
100 void InitializeCXXDefinitionData(CXXRecordDecl *D,
101 CXXRecordDecl *DefinitionDecl,
102 const RecordData &Record, unsigned &Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000103 public:
Douglas Gregorde3ef502011-11-30 23:21:26 +0000104 ASTDeclReader(ASTReader &Reader, ModuleFile &F,
Sebastian Redl2c373b92010-10-05 15:59:54 +0000105 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000106 unsigned RawLocation,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000107 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000108 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000109 RawLocation(RawLocation), Record(Record), Idx(Idx),
110 TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +0000111
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000112 static void attachPreviousDecl(Decl *D, Decl *previous);
113
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000114 void Visit(Decl *D);
115
Douglas Gregorde3ef502011-11-30 23:21:26 +0000116 void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000117 const RecordData &Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000118
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000119 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
120 ObjCCategoryDecl *Next) {
121 Cat->NextClassCategory = Next;
122 }
123
Chris Lattner487412d2009-04-27 05:27:42 +0000124 void VisitDecl(Decl *D);
125 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
126 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000127 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000128 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000129 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
130 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000131 void VisitTypeDecl(TypeDecl *TD);
132 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000133 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000134 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000135 void VisitTagDecl(TagDecl *TD);
136 void VisitEnumDecl(EnumDecl *ED);
137 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000138 void VisitCXXRecordDecl(CXXRecordDecl *D);
139 void VisitClassTemplateSpecializationDecl(
140 ClassTemplateSpecializationDecl *D);
141 void VisitClassTemplatePartialSpecializationDecl(
142 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000143 void VisitClassScopeFunctionSpecializationDecl(
144 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000145 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000146 void VisitValueDecl(ValueDecl *VD);
147 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000148 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000149 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000150 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000151 void VisitCXXMethodDecl(CXXMethodDecl *D);
152 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
153 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
154 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000155 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000156 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000157 void VisitVarDecl(VarDecl *VD);
158 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
159 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000160 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
161 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000162 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000163 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000164 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000165 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000166 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000167 void VisitUsingDecl(UsingDecl *D);
168 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000169 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000170 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000171 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000172 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000173 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
174 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000175 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000176
Chris Lattner487412d2009-04-27 05:27:42 +0000177 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000178 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000179
Alexis Hunted053252010-05-30 07:21:58 +0000180 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000181 void VisitObjCMethodDecl(ObjCMethodDecl *D);
182 void VisitObjCContainerDecl(ObjCContainerDecl *D);
183 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
184 void VisitObjCIvarDecl(ObjCIvarDecl *D);
185 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
186 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
187 void VisitObjCClassDecl(ObjCClassDecl *D);
188 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
189 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
190 void VisitObjCImplDecl(ObjCImplDecl *D);
191 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
192 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
193 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
194 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
195 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
196 };
197}
198
Sebastian Redlb3298c32010-08-18 23:56:48 +0000199uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregord32f0352011-07-22 06:10:01 +0000200 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000201}
202
Sebastian Redlb3298c32010-08-18 23:56:48 +0000203void ASTDeclReader::Visit(Decl *D) {
204 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000205
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000206 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
207 if (DD->DeclInfo) {
208 DeclaratorDecl::ExtInfo *Info =
209 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
210 Info->TInfo =
211 GetTypeSourceInfo(Record, Idx);
212 }
213 else {
214 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
215 }
216 }
217
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000218 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000219 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000220 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000221 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
222 // FunctionDecl's body was written last after all other Stmts/Exprs.
223 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000224 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000225 } else if (D->isTemplateParameter()) {
226 // If we have a fully initialized template parameter, we can now
227 // set its DeclContext.
228 D->setDeclContext(
229 cast_or_null<DeclContext>(
230 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
231 D->setLexicalDeclContext(
232 cast_or_null<DeclContext>(
233 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000234 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000235}
236
Sebastian Redlb3298c32010-08-18 23:56:48 +0000237void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000238 if (D->isTemplateParameter()) {
239 // We don't want to deserialize the DeclContext of a template
240 // parameter immediately, because the template parameter might be
241 // used in the formulation of its DeclContext. Use the translation
242 // unit DeclContext as a placeholder.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000243 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
244 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000245 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000246 } else {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000247 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
248 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000249 }
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000250 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner487412d2009-04-27 05:27:42 +0000251 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000252 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000253 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000254 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000255 D->setAttrs(Attrs);
256 }
Chris Lattner487412d2009-04-27 05:27:42 +0000257 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000258 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000259 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +0000260 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000261 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000262 D->FromASTFile = true;
Douglas Gregor26701a42011-09-09 02:06:17 +0000263 D->ModulePrivate = Record[Idx++];
Douglas Gregorcf68c582011-12-01 22:20:10 +0000264
265 // Determine whether this declaration is part of a (sub)module. If so, it
266 // may not yet be visible.
267 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
268 // Module-private declarations are never visible, so there is no work to do.
269 if (!D->ModulePrivate) {
270 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
271 if (Owner->NameVisibility != Module::AllVisible) {
272 // The owning module is not visible. Mark this declaration as
273 // module-private,
274 D->ModulePrivate = true;
275
276 // Note that this declaration was hidden because its owning module is
277 // not yet visible.
278 Reader.HiddenNamesMap[Owner].push_back(D);
279 }
280 }
281 }
282 }
Chris Lattner487412d2009-04-27 05:27:42 +0000283}
284
Sebastian Redlb3298c32010-08-18 23:56:48 +0000285void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000286 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000287}
288
Sebastian Redlb3298c32010-08-18 23:56:48 +0000289void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000290 VisitDecl(ND);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000291 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000292}
293
Sebastian Redlb3298c32010-08-18 23:56:48 +0000294void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000295 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000296 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000297 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor903b7e92011-07-22 00:38:23 +0000298 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000299}
300
Sebastian Redlb3298c32010-08-18 23:56:48 +0000301void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000302 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000303 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000304}
305
Richard Smithdda56e42011-04-15 14:24:37 +0000306void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
307 VisitTypeDecl(TD);
308 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
309}
310
Sebastian Redlb3298c32010-08-18 23:56:48 +0000311void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000312 VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000313 VisitTypeDecl(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000314 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000315 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCallf937c022011-10-07 06:10:15 +0000316 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000317 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000318 TD->setFreeStanding(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000319 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000320 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000321 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000322 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000323 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000324 } else
Douglas Gregor7fb09192011-07-21 22:35:25 +0000325 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000326}
327
Sebastian Redlb3298c32010-08-18 23:56:48 +0000328void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000329 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000330 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
331 ED->setIntegerTypeSourceInfo(TI);
332 else
Douglas Gregor903b7e92011-07-22 00:38:23 +0000333 ED->setIntegerType(Reader.readType(F, Record, Idx));
334 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000335 ED->setNumPositiveBits(Record[Idx++]);
336 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000337 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000338 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000339 ED->IsFixed = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000340 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000341}
342
Sebastian Redlb3298c32010-08-18 23:56:48 +0000343void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000344 VisitTagDecl(RD);
345 RD->setHasFlexibleArrayMember(Record[Idx++]);
346 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000347 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000348}
349
Sebastian Redlb3298c32010-08-18 23:56:48 +0000350void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000351 VisitNamedDecl(VD);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000352 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000353}
354
Sebastian Redlb3298c32010-08-18 23:56:48 +0000355void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000356 VisitValueDecl(ECD);
357 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000358 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000359 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
360}
361
Sebastian Redlb3298c32010-08-18 23:56:48 +0000362void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000363 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000364 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000365 if (Record[Idx++]) { // hasExtInfo
366 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000367 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000368 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000369 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000370 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000371}
372
Sebastian Redlb3298c32010-08-18 23:56:48 +0000373void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000374 VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000375 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000376
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000377 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000378 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000379 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikie83d382b2011-09-23 05:06:16 +0000380 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000381 case FunctionDecl::TK_NonTemplate:
382 break;
383 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000384 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
385 Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000386 break;
387 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000388 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000389 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000390 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000391 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000392 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
393 break;
394 }
395 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000396 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
397 Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000398 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
399
400 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000401 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000402 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000403
404 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000405 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000406 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000407 bool HasTemplateArgumentsAsWritten = Record[Idx++];
408 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000409 unsigned NumTemplateArgLocs = Record[Idx++];
410 TemplArgLocs.reserve(NumTemplateArgLocs);
411 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000412 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000413 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000414
Sebastian Redl2c373b92010-10-05 15:59:54 +0000415 LAngleLoc = ReadSourceLocation(Record, Idx);
416 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000417 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000418
Sebastian Redl2c373b92010-10-05 15:59:54 +0000419 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000420
Douglas Gregor4163aca2011-09-09 21:34:22 +0000421 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000422 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000423 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000424 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000425 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000426 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000427 FunctionTemplateSpecializationInfo *FTInfo
428 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
429 TemplArgList,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000430 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
431 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000432 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000433
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000434 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000435 // The template that contains the specializations set. It's not safe to
436 // use getCanonicalDecl on Template since it may still be initializing.
437 FunctionTemplateDecl *CanonTemplate
Douglas Gregor7fb09192011-07-21 22:35:25 +0000438 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000439 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
440 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
441 // FunctionTemplateSpecializationInfo's Profile().
442 // We avoid getASTContext because a decl in the parent hierarchy may
443 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000444 llvm::FoldingSetNodeID ID;
445 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
446 TemplArgs.size(), C);
447 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000448 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000449 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000450 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000451 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000452 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000453 }
454 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
455 // Templates.
456 UnresolvedSet<8> TemplDecls;
457 unsigned NumTemplates = Record[Idx++];
458 while (NumTemplates--)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000459 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000460
461 // Templates args.
462 TemplateArgumentListInfo TemplArgs;
463 unsigned NumArgs = Record[Idx++];
464 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000465 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
466 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
467 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000468
Douglas Gregor4163aca2011-09-09 21:34:22 +0000469 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000470 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000471 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000472 }
473 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000474
Sebastian Redlb3298c32010-08-18 23:56:48 +0000475 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000476 // after everything else is read.
477
Douglas Gregorbf62d642010-12-06 18:36:25 +0000478 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000479 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000480 FD->IsInline = Record[Idx++];
481 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000482 FD->IsVirtualAsWritten = Record[Idx++];
483 FD->IsPure = Record[Idx++];
484 FD->HasInheritedPrototype = Record[Idx++];
485 FD->HasWrittenPrototype = Record[Idx++];
486 FD->IsDeleted = Record[Idx++];
487 FD->IsTrivial = Record[Idx++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000488 FD->IsDefaulted = Record[Idx++];
489 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000490 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smitha77a0a62011-08-15 21:04:07 +0000491 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000492 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000493
Chris Lattnerca025db2010-05-07 21:43:38 +0000494 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000495 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000496 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000497 Params.reserve(NumParams);
498 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000499 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000500 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000501}
502
Sebastian Redlb3298c32010-08-18 23:56:48 +0000503void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000504 VisitNamedDecl(MD);
505 if (Record[Idx++]) {
506 // In practice, this won't be executed (since method definitions
507 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000508 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000509 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
510 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000511 }
512 MD->setInstanceMethod(Record[Idx++]);
513 MD->setVariadic(Record[Idx++]);
514 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000515 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000516
517 MD->IsRedeclaration = Record[Idx++];
518 MD->HasRedeclaration = Record[Idx++];
519 if (MD->HasRedeclaration)
520 Reader.getContext().setObjCMethodRedeclaration(MD,
521 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
522
Chris Lattner487412d2009-04-27 05:27:42 +0000523 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
524 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000525 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000526 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000527 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
528 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000529 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000530 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000531 Params.reserve(NumParams);
532 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000533 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000534
535 MD->SelLocsKind = Record[Idx++];
536 unsigned NumStoredSelLocs = Record[Idx++];
537 SmallVector<SourceLocation, 16> SelLocs;
538 SelLocs.reserve(NumStoredSelLocs);
539 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
540 SelLocs.push_back(ReadSourceLocation(Record, Idx));
541
542 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +0000543}
544
Sebastian Redlb3298c32010-08-18 23:56:48 +0000545void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000546 VisitNamedDecl(CD);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000547 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
548 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000549}
550
Sebastian Redlb3298c32010-08-18 23:56:48 +0000551void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000552 VisitObjCContainerDecl(ID);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000553 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000554 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000555
556 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000557 unsigned NumProtocols = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000558 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner487412d2009-04-27 05:27:42 +0000559 Protocols.reserve(NumProtocols);
560 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000561 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000562 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000563 ProtoLocs.reserve(NumProtocols);
564 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000565 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000566 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000567 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000568
569 // Read the transitive closure of protocols referenced by this class.
570 NumProtocols = Record[Idx++];
571 Protocols.clear();
572 Protocols.reserve(NumProtocols);
573 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000574 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000575 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor4163aca2011-09-09 21:34:22 +0000576 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000577
578 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000579 unsigned NumIvars = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000580 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner487412d2009-04-27 05:27:42 +0000581 IVars.reserve(NumIvars);
582 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000583 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
584 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
585
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000586 // We will rebuild this list lazily.
587 ID->setIvarList(0);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000588 ID->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000589 ID->ForwardDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000590 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
591 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000592}
593
Sebastian Redlb3298c32010-08-18 23:56:48 +0000594void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000595 VisitFieldDecl(IVD);
596 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000597 // This field will be built lazily.
598 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000599 bool synth = Record[Idx++];
600 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000601}
602
Sebastian Redlb3298c32010-08-18 23:56:48 +0000603void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000604 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000605 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000606 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000607 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000608 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000609 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000610 ProtoRefs.reserve(NumProtoRefs);
611 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000612 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000613 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000614 ProtoLocs.reserve(NumProtoRefs);
615 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000616 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000617 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000618 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000619}
620
Sebastian Redlb3298c32010-08-18 23:56:48 +0000621void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000622 VisitFieldDecl(FD);
623}
624
Sebastian Redlb3298c32010-08-18 23:56:48 +0000625void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000626 VisitDecl(CD);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000627 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
628 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000629 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner487412d2009-04-27 05:27:42 +0000630}
631
Sebastian Redlb3298c32010-08-18 23:56:48 +0000632void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000633 VisitDecl(FPD);
634 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000635 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000636 ProtoRefs.reserve(NumProtoRefs);
637 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000638 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000639 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000640 ProtoLocs.reserve(NumProtoRefs);
641 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000642 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000643 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000644 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000645}
646
Sebastian Redlb3298c32010-08-18 23:56:48 +0000647void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000648 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000649 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000650 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000651 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000652 ProtoRefs.reserve(NumProtoRefs);
653 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000654 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000655 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000656 ProtoLocs.reserve(NumProtoRefs);
657 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000658 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000659 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000660 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000661 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000662 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000663 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000664}
665
Sebastian Redlb3298c32010-08-18 23:56:48 +0000666void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000667 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000668 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000669}
670
Sebastian Redlb3298c32010-08-18 23:56:48 +0000671void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000672 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000673 D->setAtLoc(ReadSourceLocation(Record, Idx));
674 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000675 // FIXME: stable encoding
676 D->setPropertyAttributes(
677 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000678 D->setPropertyAttributesAsWritten(
679 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000680 // FIXME: stable encoding
681 D->setPropertyImplementation(
682 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000683 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
684 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000685 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
686 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
687 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000688}
689
Sebastian Redlb3298c32010-08-18 23:56:48 +0000690void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000691 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000692 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000693}
694
Sebastian Redlb3298c32010-08-18 23:56:48 +0000695void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000696 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000697 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000698}
699
Sebastian Redlb3298c32010-08-18 23:56:48 +0000700void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000701 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000702 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000703 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000704 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000705 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000706}
707
708
Sebastian Redlb3298c32010-08-18 23:56:48 +0000709void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000710 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000711 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000712 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
713 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000714 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000715 D->setGetterCXXConstructor(Reader.ReadExpr(F));
716 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000717}
718
Sebastian Redlb3298c32010-08-18 23:56:48 +0000719void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000720 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000721 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000722 int BitWidthOrInitializer = Record[Idx++];
723 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000724 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000725 else if (BitWidthOrInitializer == 2)
726 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000727 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000728 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000729 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000730 }
Chris Lattner487412d2009-04-27 05:27:42 +0000731}
732
Francois Pichet783dd6e2010-11-21 06:08:52 +0000733void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
734 VisitValueDecl(FD);
735
736 FD->ChainingSize = Record[Idx++];
737 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000738 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000739
740 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000741 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000742}
743
Sebastian Redlb3298c32010-08-18 23:56:48 +0000744void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000745 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000746 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000747 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
748 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
749 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
750 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
751 VD->VarDeclBits.ExceptionVar = Record[Idx++];
752 VD->VarDeclBits.NRVOVariable = Record[Idx++];
753 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000754 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000755 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000756 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000757
758 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000759 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000760 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000761 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000762 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000763 }
Chris Lattner487412d2009-04-27 05:27:42 +0000764}
765
Sebastian Redlb3298c32010-08-18 23:56:48 +0000766void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000767 VisitVarDecl(PD);
768}
769
Sebastian Redlb3298c32010-08-18 23:56:48 +0000770void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000771 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000772 unsigned isObjCMethodParam = Record[Idx++];
773 unsigned scopeDepth = Record[Idx++];
774 unsigned scopeIndex = Record[Idx++];
775 unsigned declQualifier = Record[Idx++];
776 if (isObjCMethodParam) {
777 assert(scopeDepth == 0);
778 PD->setObjCMethodScopeInfo(scopeIndex);
779 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
780 } else {
781 PD->setScopeInfo(scopeDepth, scopeIndex);
782 }
John McCallbeaa11c2011-05-01 02:13:58 +0000783 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
784 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000785 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000786 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000787}
788
Sebastian Redlb3298c32010-08-18 23:56:48 +0000789void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000790 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000791 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000792 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000793}
794
Sebastian Redlb3298c32010-08-18 23:56:48 +0000795void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000796 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000797 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
798 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000799 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000800 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000801 Params.reserve(NumParams);
802 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000803 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000804 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000805
806 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000807 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000808 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000809 captures.reserve(numCaptures);
810 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000811 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000812 unsigned flags = Record[Idx++];
813 bool byRef = (flags & 1);
814 bool nested = (flags & 2);
815 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
816
817 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
818 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000819 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000820 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000821}
822
Sebastian Redlb3298c32010-08-18 23:56:48 +0000823void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000824 VisitDecl(D);
825 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000826 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000827 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000828}
829
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000830void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
831 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000832 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000833}
834
835
Sebastian Redlb3298c32010-08-18 23:56:48 +0000836void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000837 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000838 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000839 D->LocStart = ReadSourceLocation(Record, Idx);
840 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000841 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000842
Chris Lattnerca025db2010-05-07 21:43:38 +0000843 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000844 // FIXME: Modules will likely have trouble with pointing directly at
845 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000846 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000847 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000848}
849
Sebastian Redlb3298c32010-08-18 23:56:48 +0000850void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000851 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000852 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000853 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000854 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000855 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000856}
857
Sebastian Redlb3298c32010-08-18 23:56:48 +0000858void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000859 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000860 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000861 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000862 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000863 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000864 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000865 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000866 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000867}
868
Sebastian Redlb3298c32010-08-18 23:56:48 +0000869void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000870 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000871 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
872 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
873 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000874 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000875 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000876}
877
Sebastian Redlb3298c32010-08-18 23:56:48 +0000878void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000879 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000880 D->UsingLoc = ReadSourceLocation(Record, Idx);
881 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000882 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000883 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
884 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000885}
886
Sebastian Redlb3298c32010-08-18 23:56:48 +0000887void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000888 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000889 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000890 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000891 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000892}
893
Sebastian Redlb3298c32010-08-18 23:56:48 +0000894void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000895 UnresolvedUsingTypenameDecl *D) {
896 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000897 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000898 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000899}
900
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000901void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000902 struct CXXRecordDecl::DefinitionData &Data,
903 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000904 Data.UserDeclaredConstructor = Record[Idx++];
905 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000906 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000907 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000908 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000909 Data.UserDeclaredDestructor = Record[Idx++];
910 Data.Aggregate = Record[Idx++];
911 Data.PlainOldData = Record[Idx++];
912 Data.Empty = Record[Idx++];
913 Data.Polymorphic = Record[Idx++];
914 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000915 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000916 Data.HasNoNonEmptyBases = Record[Idx++];
917 Data.HasPrivateFields = Record[Idx++];
918 Data.HasProtectedFields = Record[Idx++];
919 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000920 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000921 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000922 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000923 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000924 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000925 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000926 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000927 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000928 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000929 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000930 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000931 Data.DeclaredDefaultConstructor = Record[Idx++];
932 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000933 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000934 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000935 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000936 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000937 Data.FailedImplicitMoveConstructor = Record[Idx++];
938 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000939
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000940 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000941 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000942 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000943 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000944 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000945 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000946
Douglas Gregor7fb09192011-07-21 22:35:25 +0000947 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
948 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000949 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +0000950 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000951}
952
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000953void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
954 CXXRecordDecl *DefinitionDecl,
955 const RecordData &Record,
956 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +0000957 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000958
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000959 if (D == DefinitionDecl) {
960 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000961 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000962 // We read the definition info. Check if there are pending forward
963 // references that need to point to this DefinitionData pointer.
964 ASTReader::PendingForwardRefsMap::iterator
965 FindI = Reader.PendingForwardRefs.find(D);
966 if (FindI != Reader.PendingForwardRefs.end()) {
967 ASTReader::ForwardRefs &Refs = FindI->second;
968 for (ASTReader::ForwardRefs::iterator
969 I = Refs.begin(), E = Refs.end(); I != E; ++I)
970 (*I)->DefinitionData = D->DefinitionData;
971#ifndef NDEBUG
972 // We later check whether PendingForwardRefs is empty to make sure all
973 // pending references were linked.
974 Reader.PendingForwardRefs.erase(D);
975#endif
976 }
977 } else if (DefinitionDecl) {
978 if (DefinitionDecl->DefinitionData) {
979 D->DefinitionData = DefinitionDecl->DefinitionData;
980 } else {
981 // The definition is still initializing.
982 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
983 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000984 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000985}
986
987void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
988 VisitRecordDecl(D);
989
Douglas Gregor7fb09192011-07-21 22:35:25 +0000990 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000991 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
992
Douglas Gregor4163aca2011-09-09 21:34:22 +0000993 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000994
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000995 enum CXXRecKind {
996 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
997 };
998 switch ((CXXRecKind)Record[Idx++]) {
999 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001000 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001001 case CXXRecNotTemplate:
1002 break;
1003 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001004 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001005 break;
1006 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001007 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001008 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001009 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001010 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1011 MSI->setPointOfInstantiation(POI);
1012 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001013 break;
1014 }
1015 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001016
1017 // Load the key function to avoid deserializing every method so we can
1018 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001019 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001020 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001021 C.KeyFunctions[D] = Key;
1022 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001023}
1024
Sebastian Redlb3298c32010-08-18 23:56:48 +00001025void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001026 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001027 unsigned NumOverridenMethods = Record[Idx++];
1028 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001029 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1030 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001031 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001032 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001033 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001034}
1035
Sebastian Redlb3298c32010-08-18 23:56:48 +00001036void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001037 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001038
1039 D->IsExplicitSpecified = Record[Idx++];
1040 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001041 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1042 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001043}
1044
Sebastian Redlb3298c32010-08-18 23:56:48 +00001045void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001046 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001047
1048 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001049 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001050}
1051
Sebastian Redlb3298c32010-08-18 23:56:48 +00001052void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001053 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001054 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001055}
1056
Sebastian Redlb3298c32010-08-18 23:56:48 +00001057void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001058 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001059 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001060}
1061
Sebastian Redlb3298c32010-08-18 23:56:48 +00001062void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001063 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001064 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001065 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001066 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001067 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001068 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001069 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001070 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001071}
1072
Sebastian Redlb3298c32010-08-18 23:56:48 +00001073void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001074 VisitDecl(D);
1075 unsigned NumParams = Record[Idx++];
1076 D->NumParams = NumParams;
1077 D->Params = new TemplateParameterList*[NumParams];
1078 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001079 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001080 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001081 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001082 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001083 D->Friend = GetTypeSourceInfo(Record, Idx);
1084 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001085}
1086
Sebastian Redlb3298c32010-08-18 23:56:48 +00001087void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001088 VisitNamedDecl(D);
1089
Douglas Gregor7fb09192011-07-21 22:35:25 +00001090 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001091 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001092 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001093 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001094}
1095
Sebastian Redlb3298c32010-08-18 23:56:48 +00001096void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001097 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1098 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001099
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001100 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001101 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1102 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001103 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1104 // We temporarily set the first (canonical) declaration as the previous one
1105 // which is the one that matters and mark the real previous DeclID to be
1106 // loaded & attached later on.
1107 RedeclarableTemplateDecl *FirstDecl =
1108 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1109 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1110 "FirstDecl kind mismatch");
1111 if (FirstDecl) {
1112 D->CommonOrPrev = FirstDecl;
1113 // Mark the real previous DeclID to be loaded & attached later on.
1114 if (PreviousDeclID != FirstDeclID)
1115 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1116 } else {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001117 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001118 if (RedeclarableTemplateDecl *RTD
Douglas Gregor7fb09192011-07-21 22:35:25 +00001119 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001120 assert(RTD->getKind() == D->getKind() &&
1121 "InstantiatedFromMemberTemplate kind mismatch");
1122 D->setInstantiatedFromMemberTemplateImpl(RTD);
1123 if (Record[Idx++])
1124 D->setMemberSpecialization();
1125 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001126
Douglas Gregor7fb09192011-07-21 22:35:25 +00001127 RedeclarableTemplateDecl *LatestDecl
1128 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001129
1130 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001131 // in the same AST file. However, if this actually needs to point to a
1132 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001133 // the FirstLatestDeclIDs map which tracks this kind of decls.
1134 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001135 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001136 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1137 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregoraa7cbfd2011-08-25 15:28:26 +00001138 if (Decl *NewLatest = Reader.GetDecl(I->second))
1139 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001140 }
1141
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001142 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1143 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001144 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001145
1146 VisitTemplateDecl(D);
1147 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001148}
1149
Sebastian Redlb3298c32010-08-18 23:56:48 +00001150void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001151 VisitRedeclarableTemplateDecl(D);
1152
1153 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001154 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1155 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001156 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001157 SpecIDs.push_back(0);
1158
1159 // Specializations.
1160 unsigned Size = Record[Idx++];
1161 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001162 for (unsigned I = 0; I != Size; ++I)
1163 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001164
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001165 // Partial specializations.
1166 Size = Record[Idx++];
1167 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001168 for (unsigned I = 0; I != Size; ++I)
1169 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001170
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001171 if (SpecIDs[0]) {
1172 typedef serialization::DeclID DeclID;
1173
1174 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1175 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001176 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001177 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1178 SpecIDs.size() * sizeof(DeclID));
1179 }
1180
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001181 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001182 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001183}
1184
Sebastian Redlb3298c32010-08-18 23:56:48 +00001185void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001186 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001187 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001188
Douglas Gregor4163aca2011-09-09 21:34:22 +00001189 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001190 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001191 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001192 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001193 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001194 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001195 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001196 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001197 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1198 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001199 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1200 = new (C) ClassTemplateSpecializationDecl::
1201 SpecializedPartialSpecialization();
1202 PS->PartialSpecialization
1203 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1204 PS->TemplateArgs = ArgList;
1205 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001206 }
1207 }
1208
1209 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001210 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001211 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1212 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1213 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001214 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1215 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001216 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001217 }
1218
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001219 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001220 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001221 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1222 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001223 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001224 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001225
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001226 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001227 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001228 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001229 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1230 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001231 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001232 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001233 }
1234 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001235}
1236
Sebastian Redlb3298c32010-08-18 23:56:48 +00001237void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001238 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001239 VisitClassTemplateSpecializationDecl(D);
1240
Douglas Gregor4163aca2011-09-09 21:34:22 +00001241 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001242 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001243
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001244 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001245 if (NumArgs) {
1246 D->NumArgsAsWritten = NumArgs;
1247 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1248 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001249 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001250 }
1251
1252 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001253
1254 // These are read/set from/to the first declaration.
1255 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001256 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001257 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001258 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001259 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001260}
1261
Sebastian Redlb7448632011-08-31 13:59:56 +00001262void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1263 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001264 VisitDecl(D);
1265 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1266}
1267
Sebastian Redlb3298c32010-08-18 23:56:48 +00001268void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001269 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001270
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001271 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001272 // This FunctionTemplateDecl owns a CommonPtr; read it.
1273
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001274 // Read the function specialization declarations.
1275 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001276 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001277 unsigned NumSpecs = Record[Idx++];
1278 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001279 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001280 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001281}
1282
Sebastian Redlb3298c32010-08-18 23:56:48 +00001283void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001284 VisitTypeDecl(D);
1285
1286 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001287
1288 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001289 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001290 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001291}
1292
Sebastian Redlb3298c32010-08-18 23:56:48 +00001293void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001294 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001295 // TemplateParmPosition.
1296 D->setDepth(Record[Idx++]);
1297 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001298 if (D->isExpandedParameterPack()) {
1299 void **Data = reinterpret_cast<void **>(D + 1);
1300 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001301 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001302 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1303 }
1304 } else {
1305 // Rest of NonTypeTemplateParmDecl.
1306 D->ParameterPack = Record[Idx++];
1307 if (Record[Idx++]) {
1308 Expr *DefArg = Reader.ReadExpr(F);
1309 bool Inherited = Record[Idx++];
1310 D->setDefaultArgument(DefArg, Inherited);
1311 }
1312 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001313}
1314
Sebastian Redlb3298c32010-08-18 23:56:48 +00001315void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001316 VisitTemplateDecl(D);
1317 // TemplateParmPosition.
1318 D->setDepth(Record[Idx++]);
1319 D->setPosition(Record[Idx++]);
1320 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001321 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001322 bool IsInherited = Record[Idx++];
1323 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001324 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001325}
1326
Richard Smith3f1b5d02011-05-05 21:57:07 +00001327void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1328 VisitRedeclarableTemplateDecl(D);
1329}
1330
Sebastian Redlb3298c32010-08-18 23:56:48 +00001331void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001332 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001333 D->AssertExpr = Reader.ReadExpr(F);
1334 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001335 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001336}
1337
Mike Stump11289f42009-09-09 15:08:12 +00001338std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001339ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001340 uint64_t LexicalOffset = Record[Idx++];
1341 uint64_t VisibleOffset = Record[Idx++];
1342 return std::make_pair(LexicalOffset, VisibleOffset);
1343}
1344
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001345template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001346void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001347 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1348 RedeclKind Kind = (RedeclKind)Record[Idx++];
1349 switch (Kind) {
1350 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001351 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1352 " messed up reading");
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001353 case NoRedeclaration:
1354 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001355 case PointsToPrevious: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001356 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1357 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001358 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1359 // We temporarily set the first (canonical) declaration as the previous one
1360 // which is the one that matters and mark the real previous DeclID to be
1361 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001362 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1363 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001364 if (PreviousDeclID != FirstDeclID)
1365 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1366 PreviousDeclID));
Douglas Gregor3e300102011-10-26 17:53:41 +00001367
1368 // If the first declaration in the chain is in an inconsistent
1369 // state where it thinks that it is the only declaration, fix its
1370 // redeclaration link now to point at this declaration, so that we have a
1371 // proper redeclaration chain.
1372 if (FirstDecl->RedeclLink.getPointer() == FirstDecl) {
1373 FirstDecl->RedeclLink
1374 = typename Redeclarable<T>::LatestDeclLink(static_cast<T*>(D));
1375 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001376 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001377 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001378 case PointsToLatest: {
1379 T *LatestDecl = ReadDeclAs<T>(Record, Idx);
1380 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(LatestDecl);
1381
1382 // If the latest declaration in the chain is in an inconsistent
1383 // state where it thinks that it is the only declaration, fix its
1384 // redeclaration link now to point at this declaration, so that we have a
1385 // proper redeclaration chain.
1386 if (LatestDecl->RedeclLink.getPointer() == LatestDecl) {
1387 LatestDecl->RedeclLink
1388 = typename Redeclarable<T>::PreviousDeclLink(static_cast<T*>(D));
1389 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001390 break;
1391 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001392 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001393
1394 assert(!(Kind == PointsToPrevious &&
1395 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1396 Reader.FirstLatestDeclIDs.end()) &&
1397 "This decl is not first, it should not be in the map");
1398 if (Kind == PointsToPrevious)
1399 return;
1400
1401 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001402 // the same AST file. However, if this actually needs to point to a
1403 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001404 // FirstLatestDeclIDs map which tracks this kind of decls.
1405 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1406 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001407 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001408 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1409 if (I != Reader.FirstLatestDeclIDs.end()) {
1410 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001411 D->RedeclLink
1412 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1413 }
1414}
1415
Chris Lattner487412d2009-04-27 05:27:42 +00001416//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001417// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001418//===----------------------------------------------------------------------===//
1419
Chris Lattner8f63ab52009-04-27 06:01:06 +00001420/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001421void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001422 const RecordData &Record, unsigned &Idx) {
1423 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001424 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001425 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001426 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001427
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001428#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001429
1430 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001431 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001432 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001433}
1434
1435//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001436// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001437//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001438
1439/// \brief Note that we have loaded the declaration with the given
1440/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001441///
Chris Lattner487412d2009-04-27 05:27:42 +00001442/// This routine notes that this declaration has already been loaded,
1443/// so that future GetDecl calls will return this declaration rather
1444/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001445inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001446 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1447 DeclsLoaded[Index] = D;
1448}
1449
1450
1451/// \brief Determine whether the consumer will be interested in seeing
1452/// this declaration (via HandleTopLevelDecl).
1453///
1454/// This routine should return true for anything that might affect
1455/// code generation, e.g., inline function definitions, Objective-C
1456/// declarations with metadata, etc.
1457static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001458 // An ObjCMethodDecl is never considered as "interesting" because its
1459 // implementation container always is.
1460
Douglas Gregor87d81242011-09-10 00:22:34 +00001461 if (isa<FileScopeAsmDecl>(D) ||
1462 isa<ObjCProtocolDecl>(D) ||
1463 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001464 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001465 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001466 return Var->isFileVarDecl() &&
1467 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001468 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001469 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001470
1471 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001472}
1473
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001474/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001475ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001476ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001477 // See if there's an override.
1478 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001479 if (It != ReplacedDecls.end()) {
1480 RawLocation = It->second.RawLoc;
1481 return RecordLocation(It->second.Mod, It->second.Offset);
1482 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001483
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001484 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1485 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001486 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001487 const DeclOffset &
1488 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1489 RawLocation = DOffs.Loc;
1490 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001491}
1492
Douglas Gregord32f0352011-07-22 06:10:01 +00001493ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001494 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001495 = GlobalBitOffsetsMap.find(GlobalOffset);
1496
1497 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1498 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1499}
1500
Douglas Gregorde3ef502011-11-30 23:21:26 +00001501uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001502 return LocalOffset + M.GlobalBitOffset;
1503}
1504
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001505void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1506 assert(D && previous);
1507 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1508 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1509 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1510 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1511 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1512 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1513 } else {
1514 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1515 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1516 }
1517}
1518
1519void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1520 Decl *previous = GetDecl(ID);
1521 ASTDeclReader::attachPreviousDecl(D, previous);
1522}
1523
Sebastian Redlb3298c32010-08-18 23:56:48 +00001524/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001525Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001526 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001527 unsigned RawLocation = 0;
1528 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001529 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001530 // Keep track of where we are in the stream, then jump back there
1531 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001532 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001533
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001534 ReadingKindTracker ReadingKind(Read_Decl, *this);
1535
Douglas Gregor1342e842009-07-06 18:54:52 +00001536 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001537 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001538
Sebastian Redl2c373b92010-10-05 15:59:54 +00001539 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001540 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001541 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001542 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001543 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001544
Chris Lattner1de76db2009-04-27 05:58:23 +00001545 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001546 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001547 case DECL_CONTEXT_LEXICAL:
1548 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001549 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001550 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001551 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001552 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001553 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001554 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001555 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001556 0, 0);
1557 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001558 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001559 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001560 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001561 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001562 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001563 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001564 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001565 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001566 0, llvm::APSInt());
1567 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001568 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001569 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001570 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001571 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001572 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001573 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001574 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001575 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001576 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001577 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001578 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001579 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001580 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001581 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001582 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001583 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001584 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001585 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001586 SourceLocation(), 0,
1587 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001588 SourceLocation(), 0);
1589 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001590 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001591 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001592 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1593 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001594 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001595 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001596 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001597 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001598 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001599 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001600 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001601 SourceLocation(), 0, 0);
1602 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001603 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001604 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001605 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001606 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001607 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001608 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001609 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001610 SourceLocation(),
1611 NestedNameSpecifierLoc(),
1612 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001613 DeclarationName());
1614 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001615 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001616 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001617 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001618 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001619 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001620 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001621 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001622 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001623 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001624 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001625 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001626 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001627 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001628 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001629 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001630 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001631 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001632 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001633 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001634 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001635 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001636 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001637 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001638 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001639 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001640 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001641 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001642 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001643 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001644 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001645 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001646 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001647 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001648 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001649 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001650 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001651 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001652 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001653 Decl::EmptyShell());
1654 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001655 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001656 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001657 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001658 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001659 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001660 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001661 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001662 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001663 SourceLocation(), 0, 0, 0, QualType(),
1664 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001665 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001666 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001667 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001668 SourceLocation(), 0, 0, 0, QualType(),
1669 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001670 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001671 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001672 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001673 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001674 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001675 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001676 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001677 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001678 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001679 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001680 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001681 break;
1682
Sebastian Redl539c5062010-08-18 23:57:32 +00001683 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001684 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001685 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001686 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001687 case DECL_OBJC_INTERFACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001688 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001689 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001690 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001691 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001692 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001693 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001694 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001695 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001696 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001697 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001698 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001699 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001700 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001701 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001702 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001703 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001704 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001705 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001706 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001707 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001708 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001709 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001710 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001711 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001712 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1713 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001714 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001715 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001716 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1717 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001718 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001719 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001720 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001721 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001722 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001723 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001724 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001725 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001726 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001727 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001728 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001729 ObjCPropertyImplDecl::Dynamic, 0,
1730 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001731 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001732 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001733 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001734 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001735 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001736 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001737 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001738 0, 0);
1739 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001740 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001741 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001742 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001743 break;
1744
Sebastian Redl539c5062010-08-18 23:57:32 +00001745 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001746 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001747 break;
1748
Sebastian Redl539c5062010-08-18 23:57:32 +00001749 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001750 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001751 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001752 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001753 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001754 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001755 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001756 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001757 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001758 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001759 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001760 case DECL_CXX_BASE_SPECIFIERS:
1761 Error("attempt to read a C++ base-specifier record as a declaration");
1762 return 0;
Chris Lattner487412d2009-04-27 05:27:42 +00001763 }
Chris Lattner487412d2009-04-27 05:27:42 +00001764
Sebastian Redlb3298c32010-08-18 23:56:48 +00001765 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001766 LoadedDecl(Index, D);
1767 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001768
1769 // If this declaration is also a declaration context, get the
1770 // offsets for its tables of lexical and visible declarations.
1771 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1772 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1773 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001774 if (Offsets.first != 0)
1775 DC->setHasExternalLexicalStorage(true);
1776 if (Offsets.second != 0)
1777 DC->setHasExternalVisibleStorage(true);
1778 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1779 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001780 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001781 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001782
Sebastian Redlf830df42011-04-24 16:27:54 +00001783 // Now add the pending visible updates for this decl context, if it has any.
1784 DeclContextVisibleUpdatesPending::iterator I =
1785 PendingVisibleUpdates.find(ID);
1786 if (I != PendingVisibleUpdates.end()) {
1787 // There are updates. This means the context has external visible
1788 // storage, even if the original stored version didn't.
1789 DC->setHasExternalVisibleStorage(true);
1790 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001791 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1792 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001793 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001794 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001795 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001796 }
1797 }
1798 assert(Idx == Record.size());
1799
Douglas Gregordab42432011-08-12 00:15:20 +00001800 // Load any relevant update records.
1801 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001802
1803 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001804 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001805 PendingChainedObjCCategories.push_back(
1806 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001807
Douglas Gregordab42432011-08-12 00:15:20 +00001808 // If we have deserialized a declaration that has a definition the
1809 // AST consumer might need to know about, queue it.
1810 // We don't pass it to the consumer immediately because we may be in recursive
1811 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001812 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001813 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001814
Douglas Gregordab42432011-08-12 00:15:20 +00001815 return D;
1816}
1817
1818void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001819 // The declaration may have been modified by files later in the chain.
1820 // If this is the case, read the record containing the updates from each file
1821 // and pass it to ASTDeclReader to make the modifications.
1822 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1823 if (UpdI != DeclUpdateOffsets.end()) {
1824 FileOffsetsTy &UpdateOffsets = UpdI->second;
1825 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001826 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001827 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001828 uint64_t Offset = I->second;
1829 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1830 SavedStreamPosition SavedPosition(Cursor);
1831 Cursor.JumpToBit(Offset);
1832 RecordData Record;
1833 unsigned Code = Cursor.ReadCode();
1834 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1835 (void)RecCode;
1836 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001837
1838 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001839 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001840 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001841 }
1842 }
Chris Lattner487412d2009-04-27 05:27:42 +00001843}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001844
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001845namespace {
1846 /// \brief Given an ObjC interface, goes through the modules and links to the
1847 /// interface all the categories for it.
1848 class ObjCChainedCategoriesVisitor {
1849 ASTReader &Reader;
1850 serialization::GlobalDeclID InterfaceID;
1851 ObjCInterfaceDecl *Interface;
1852 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1853 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1854
1855 public:
1856 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1857 serialization::GlobalDeclID InterfaceID,
1858 ObjCInterfaceDecl *Interface)
1859 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1860 GlobHeadCat(0), GlobTailCat(0) { }
1861
Douglas Gregorde3ef502011-11-30 23:21:26 +00001862 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001863 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1864 }
1865
Douglas Gregorde3ef502011-11-30 23:21:26 +00001866 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001867 if (Reader.isDeclIDFromModule(InterfaceID, M))
1868 return true; // We reached the module where the interface originated
1869 // from. Stop traversing the imported modules.
1870
Douglas Gregorde3ef502011-11-30 23:21:26 +00001871 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001872 I = M.ChainedObjCCategories.find(InterfaceID);
1873 if (I == M.ChainedObjCCategories.end())
1874 return false;
1875
1876 ObjCCategoryDecl *
1877 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1878 ObjCCategoryDecl *
1879 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1880
1881 addCategories(HeadCat, TailCat);
1882 return false;
1883 }
1884
1885 void addCategories(ObjCCategoryDecl *HeadCat,
1886 ObjCCategoryDecl *TailCat = 0) {
1887 if (!HeadCat) {
1888 assert(!TailCat);
1889 return;
1890 }
1891
1892 if (!TailCat) {
1893 TailCat = HeadCat;
1894 while (TailCat->getNextClassCategory())
1895 TailCat = TailCat->getNextClassCategory();
1896 }
1897
1898 if (!GlobHeadCat) {
1899 GlobHeadCat = HeadCat;
1900 GlobTailCat = TailCat;
1901 } else {
1902 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1903 GlobTailCat = TailCat;
1904 }
1905
1906 llvm::DenseSet<DeclarationName> Checked;
1907 for (ObjCCategoryDecl *Cat = HeadCat,
1908 *CatEnd = TailCat->getNextClassCategory();
1909 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1910 if (Checked.count(Cat->getDeclName()))
1911 continue;
1912 Checked.insert(Cat->getDeclName());
1913 checkForDuplicate(Cat);
1914 }
1915 }
1916
1917 /// \brief Warns for duplicate categories that come from different modules.
1918 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1919 DeclarationName Name = Cat->getDeclName();
1920 // Find the top category with the same name. We do not want to warn for
1921 // duplicates along the established chain because there were already
1922 // warnings for them when the module was created. We only want to warn for
1923 // duplicates between non-dependent modules:
1924 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001925 // MT //
1926 // / \ //
1927 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001928 //
1929 // We want to warn for duplicates between ML and MR,not between ML and MT.
1930 //
1931 // FIXME: We should not warn for duplicates in diamond:
1932 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001933 // MT //
1934 // / \ //
1935 // ML MR //
1936 // \ / //
1937 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001938 //
1939 // If there are duplicates in ML/MR, there will be warning when creating
1940 // MB *and* when importing MB. We should not warn when importing.
1941 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1942 Next = Next->getNextClassCategory()) {
1943 if (Next->getDeclName() == Name)
1944 Cat = Next;
1945 }
1946
1947 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1948 if (!PrevCat)
1949 PrevCat = Cat;
1950
1951 if (PrevCat != Cat) {
1952 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1953 << Interface->getDeclName() << Name;
1954 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1955 }
1956 }
1957
1958 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1959 };
1960}
1961
1962void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1963 ObjCInterfaceDecl *D) {
1964 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1965 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1966 // Also add the categories that the interface already links to.
1967 Visitor.addCategories(D->getCategoryList());
1968 D->setCategoryList(Visitor.getHeadCategory());
1969}
Douglas Gregordab42432011-08-12 00:15:20 +00001970
Douglas Gregorde3ef502011-11-30 23:21:26 +00001971void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001972 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001973 unsigned Idx = 0;
1974 while (Idx < Record.size()) {
1975 switch ((DeclUpdateKind)Record[Idx++]) {
1976 case UPD_CXX_SET_DEFINITIONDATA: {
1977 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00001978 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00001979 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001980 assert(!RD->DefinitionData && "DefinitionData is already set!");
1981 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1982 break;
1983 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001984
1985 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00001986 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001987 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00001988
1989 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1990 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001991 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001992 break;
1993
1994 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00001995 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00001996 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00001997 // Guard against these being loaded out of original order. Don't use
1998 // getNextNamespace(), since it tries to access the context and can't in
1999 // the middle of deserialization.
2000 if (!Anon->NextNamespace) {
2001 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2002 TU->setAnonymousNamespace(Anon);
2003 else
2004 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2005 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002006 break;
2007 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002008
2009 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2010 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002011 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002012 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002013 }
2014 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002015}