blob: e9833c394c90f4d2c7a20f2a8303d504f088809b [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redlf5b13462010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner487412d2009-04-27 05:27:42 +000018#include "clang/AST/ASTConsumer.h"
19#include "clang/AST/ASTContext.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000032namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregorde3ef502011-11-30 23:21:26 +000035 ModuleFile &F;
Sebastian Redlc67764e2010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl539c5062010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +000038 const unsigned RawLocation;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000039 typedef ASTReader::RecordData RecordData;
40 const RecordData &Record;
Chris Lattner487412d2009-04-27 05:27:42 +000041 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000042 TypeID TypeIDForTypeDecl;
Douglas Gregor250ffb12011-03-05 01:35:54 +000043
44 DeclID DeclContextIDForTemplateParmDecl;
45 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000046
Sebastian Redlc67764e2010-07-22 22:43:28 +000047 uint64_t GetCurrentCursorOffset();
Douglas Gregor7fb09192011-07-21 22:35:25 +000048
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000049 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000050 return Reader.ReadSourceLocation(F, R, I);
51 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000052
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000053 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000054 return Reader.ReadSourceRange(F, R, I);
55 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000056
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000057 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000058 return Reader.GetTypeSourceInfo(F, R, I);
59 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000060
61 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
62 return Reader.ReadDeclID(F, R, I);
63 }
64
65 Decl *ReadDecl(const RecordData &R, unsigned &I) {
66 return Reader.ReadDecl(F, R, I);
67 }
68
69 template<typename T>
70 T *ReadDeclAs(const RecordData &R, unsigned &I) {
71 return Reader.ReadDeclAs<T>(F, R, I);
72 }
73
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000074 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000075 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000076 Reader.ReadQualifierInfo(F, Info, R, I);
77 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000078
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000079 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000080 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000081 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
82 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000083
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000084 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000085 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000086 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
87 }
Sebastian Redlc67764e2010-07-22 22:43:28 +000088
Douglas Gregorcf68c582011-12-01 22:20:10 +000089 serialization::SubmoduleID readSubmoduleID(const RecordData &R,
90 unsigned &I) {
91 if (I >= R.size())
92 return 0;
93
94 return Reader.getGlobalSubmoduleID(F, R[I++]);
95 }
96
Douglas Gregorba345522011-12-02 23:23:56 +000097 Module *readModule(const RecordData &R, unsigned &I) {
98 return Reader.getSubmodule(readSubmoduleID(R, I));
99 }
100
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000101 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
102 const RecordData &R, unsigned &I);
103
104 void InitializeCXXDefinitionData(CXXRecordDecl *D,
105 CXXRecordDecl *DefinitionDecl,
106 const RecordData &Record, unsigned &Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000107 public:
Douglas Gregorde3ef502011-11-30 23:21:26 +0000108 ASTDeclReader(ASTReader &Reader, ModuleFile &F,
Sebastian Redl2c373b92010-10-05 15:59:54 +0000109 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000110 unsigned RawLocation,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000111 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000112 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000113 RawLocation(RawLocation), Record(Record), Idx(Idx),
114 TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +0000115
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000116 static void attachPreviousDecl(Decl *D, Decl *previous);
117
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000118 void Visit(Decl *D);
119
Douglas Gregorde3ef502011-11-30 23:21:26 +0000120 void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000121 const RecordData &Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000122
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000123 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
124 ObjCCategoryDecl *Next) {
125 Cat->NextClassCategory = Next;
126 }
127
Chris Lattner487412d2009-04-27 05:27:42 +0000128 void VisitDecl(Decl *D);
129 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
130 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000131 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000132 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000133 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
134 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000135 void VisitTypeDecl(TypeDecl *TD);
136 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000137 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000138 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000139 void VisitTagDecl(TagDecl *TD);
140 void VisitEnumDecl(EnumDecl *ED);
141 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000142 void VisitCXXRecordDecl(CXXRecordDecl *D);
143 void VisitClassTemplateSpecializationDecl(
144 ClassTemplateSpecializationDecl *D);
145 void VisitClassTemplatePartialSpecializationDecl(
146 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000147 void VisitClassScopeFunctionSpecializationDecl(
148 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000149 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000150 void VisitValueDecl(ValueDecl *VD);
151 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000152 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000153 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000154 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000155 void VisitCXXMethodDecl(CXXMethodDecl *D);
156 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
157 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
158 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000159 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000160 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000161 void VisitVarDecl(VarDecl *VD);
162 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
163 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000164 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
165 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000166 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000167 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000168 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000169 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000170 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000171 void VisitUsingDecl(UsingDecl *D);
172 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000173 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000174 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregorba345522011-12-02 23:23:56 +0000175 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000176 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000177 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000178 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
179 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000180 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000181
Chris Lattner487412d2009-04-27 05:27:42 +0000182 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000183 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000184
Alexis Hunted053252010-05-30 07:21:58 +0000185 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000186 void VisitObjCMethodDecl(ObjCMethodDecl *D);
187 void VisitObjCContainerDecl(ObjCContainerDecl *D);
188 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
189 void VisitObjCIvarDecl(ObjCIvarDecl *D);
190 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
191 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
192 void VisitObjCClassDecl(ObjCClassDecl *D);
193 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
194 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
195 void VisitObjCImplDecl(ObjCImplDecl *D);
196 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
197 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
198 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
199 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
200 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
201 };
202}
203
Sebastian Redlb3298c32010-08-18 23:56:48 +0000204uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregord32f0352011-07-22 06:10:01 +0000205 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000206}
207
Sebastian Redlb3298c32010-08-18 23:56:48 +0000208void ASTDeclReader::Visit(Decl *D) {
209 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000210
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000211 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
212 if (DD->DeclInfo) {
213 DeclaratorDecl::ExtInfo *Info =
214 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
215 Info->TInfo =
216 GetTypeSourceInfo(Record, Idx);
217 }
218 else {
219 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
220 }
221 }
222
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000223 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000224 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000225 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000226 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
227 // FunctionDecl's body was written last after all other Stmts/Exprs.
228 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000229 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000230 } else if (D->isTemplateParameter()) {
231 // If we have a fully initialized template parameter, we can now
232 // set its DeclContext.
233 D->setDeclContext(
234 cast_or_null<DeclContext>(
235 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
236 D->setLexicalDeclContext(
237 cast_or_null<DeclContext>(
238 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000239 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000240}
241
Sebastian Redlb3298c32010-08-18 23:56:48 +0000242void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000243 if (D->isTemplateParameter()) {
244 // We don't want to deserialize the DeclContext of a template
245 // parameter immediately, because the template parameter might be
246 // used in the formulation of its DeclContext. Use the translation
247 // unit DeclContext as a placeholder.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000248 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
249 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000250 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000251 } else {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000252 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
253 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000254 }
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000255 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner487412d2009-04-27 05:27:42 +0000256 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000257 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000258 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000259 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000260 D->setAttrs(Attrs);
261 }
Chris Lattner487412d2009-04-27 05:27:42 +0000262 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000263 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000264 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +0000265 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000266 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000267 D->FromASTFile = true;
Douglas Gregor26701a42011-09-09 02:06:17 +0000268 D->ModulePrivate = Record[Idx++];
Douglas Gregorcf68c582011-12-01 22:20:10 +0000269
270 // Determine whether this declaration is part of a (sub)module. If so, it
271 // may not yet be visible.
272 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
273 // Module-private declarations are never visible, so there is no work to do.
274 if (!D->ModulePrivate) {
275 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
276 if (Owner->NameVisibility != Module::AllVisible) {
277 // The owning module is not visible. Mark this declaration as
278 // module-private,
279 D->ModulePrivate = true;
280
281 // Note that this declaration was hidden because its owning module is
282 // not yet visible.
283 Reader.HiddenNamesMap[Owner].push_back(D);
284 }
285 }
286 }
287 }
Chris Lattner487412d2009-04-27 05:27:42 +0000288}
289
Sebastian Redlb3298c32010-08-18 23:56:48 +0000290void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000291 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000292}
293
Sebastian Redlb3298c32010-08-18 23:56:48 +0000294void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000295 VisitDecl(ND);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000296 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000297}
298
Sebastian Redlb3298c32010-08-18 23:56:48 +0000299void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000300 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000301 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000302 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor903b7e92011-07-22 00:38:23 +0000303 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000304}
305
Sebastian Redlb3298c32010-08-18 23:56:48 +0000306void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000307 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000308 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000309}
310
Richard Smithdda56e42011-04-15 14:24:37 +0000311void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
312 VisitTypeDecl(TD);
313 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
314}
315
Sebastian Redlb3298c32010-08-18 23:56:48 +0000316void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000317 VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000318 VisitTypeDecl(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000319 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000320 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCallf937c022011-10-07 06:10:15 +0000321 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000322 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000323 TD->setFreeStanding(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000324 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000325 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000326 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000327 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000328 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000329 } else
Douglas Gregor7fb09192011-07-21 22:35:25 +0000330 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000331}
332
Sebastian Redlb3298c32010-08-18 23:56:48 +0000333void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000334 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000335 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
336 ED->setIntegerTypeSourceInfo(TI);
337 else
Douglas Gregor903b7e92011-07-22 00:38:23 +0000338 ED->setIntegerType(Reader.readType(F, Record, Idx));
339 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000340 ED->setNumPositiveBits(Record[Idx++]);
341 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000342 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000343 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000344 ED->IsFixed = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000345 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000346}
347
Sebastian Redlb3298c32010-08-18 23:56:48 +0000348void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000349 VisitTagDecl(RD);
350 RD->setHasFlexibleArrayMember(Record[Idx++]);
351 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000352 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000353}
354
Sebastian Redlb3298c32010-08-18 23:56:48 +0000355void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000356 VisitNamedDecl(VD);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000357 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000358}
359
Sebastian Redlb3298c32010-08-18 23:56:48 +0000360void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000361 VisitValueDecl(ECD);
362 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000363 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000364 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
365}
366
Sebastian Redlb3298c32010-08-18 23:56:48 +0000367void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000368 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000369 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000370 if (Record[Idx++]) { // hasExtInfo
371 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000372 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000373 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000374 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000375 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000376}
377
Sebastian Redlb3298c32010-08-18 23:56:48 +0000378void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000379 VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000380 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000381
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000382 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000383 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000384 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikie83d382b2011-09-23 05:06:16 +0000385 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000386 case FunctionDecl::TK_NonTemplate:
387 break;
388 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000389 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
390 Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000391 break;
392 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000393 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000394 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000395 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000396 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000397 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
398 break;
399 }
400 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000401 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
402 Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000403 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
404
405 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000406 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000407 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000408
409 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000410 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000411 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000412 bool HasTemplateArgumentsAsWritten = Record[Idx++];
413 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000414 unsigned NumTemplateArgLocs = Record[Idx++];
415 TemplArgLocs.reserve(NumTemplateArgLocs);
416 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000417 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000418 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000419
Sebastian Redl2c373b92010-10-05 15:59:54 +0000420 LAngleLoc = ReadSourceLocation(Record, Idx);
421 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000422 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000423
Sebastian Redl2c373b92010-10-05 15:59:54 +0000424 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000425
Douglas Gregor4163aca2011-09-09 21:34:22 +0000426 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000427 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000428 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000429 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000430 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000431 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000432 FunctionTemplateSpecializationInfo *FTInfo
433 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
434 TemplArgList,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000435 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
436 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000437 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000438
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000439 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000440 // The template that contains the specializations set. It's not safe to
441 // use getCanonicalDecl on Template since it may still be initializing.
442 FunctionTemplateDecl *CanonTemplate
Douglas Gregor7fb09192011-07-21 22:35:25 +0000443 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000444 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
445 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
446 // FunctionTemplateSpecializationInfo's Profile().
447 // We avoid getASTContext because a decl in the parent hierarchy may
448 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000449 llvm::FoldingSetNodeID ID;
450 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
451 TemplArgs.size(), C);
452 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000453 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000454 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000455 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000456 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000457 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000458 }
459 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
460 // Templates.
461 UnresolvedSet<8> TemplDecls;
462 unsigned NumTemplates = Record[Idx++];
463 while (NumTemplates--)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000464 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000465
466 // Templates args.
467 TemplateArgumentListInfo TemplArgs;
468 unsigned NumArgs = Record[Idx++];
469 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000470 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
471 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
472 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000473
Douglas Gregor4163aca2011-09-09 21:34:22 +0000474 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000475 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000476 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000477 }
478 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000479
Sebastian Redlb3298c32010-08-18 23:56:48 +0000480 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000481 // after everything else is read.
482
Douglas Gregorbf62d642010-12-06 18:36:25 +0000483 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000484 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000485 FD->IsInline = Record[Idx++];
486 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000487 FD->IsVirtualAsWritten = Record[Idx++];
488 FD->IsPure = Record[Idx++];
489 FD->HasInheritedPrototype = Record[Idx++];
490 FD->HasWrittenPrototype = Record[Idx++];
491 FD->IsDeleted = Record[Idx++];
492 FD->IsTrivial = Record[Idx++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000493 FD->IsDefaulted = Record[Idx++];
494 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000495 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smitha77a0a62011-08-15 21:04:07 +0000496 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000497 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000498
Chris Lattnerca025db2010-05-07 21:43:38 +0000499 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000500 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000501 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000502 Params.reserve(NumParams);
503 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000504 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000505 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000506}
507
Sebastian Redlb3298c32010-08-18 23:56:48 +0000508void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000509 VisitNamedDecl(MD);
510 if (Record[Idx++]) {
511 // In practice, this won't be executed (since method definitions
512 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000513 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000514 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
515 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000516 }
517 MD->setInstanceMethod(Record[Idx++]);
518 MD->setVariadic(Record[Idx++]);
519 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000520 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000521
522 MD->IsRedeclaration = Record[Idx++];
523 MD->HasRedeclaration = Record[Idx++];
524 if (MD->HasRedeclaration)
525 Reader.getContext().setObjCMethodRedeclaration(MD,
526 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
527
Chris Lattner487412d2009-04-27 05:27:42 +0000528 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
529 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000530 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000531 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000532 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
533 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000534 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000535 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000536 Params.reserve(NumParams);
537 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000538 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000539
540 MD->SelLocsKind = Record[Idx++];
541 unsigned NumStoredSelLocs = Record[Idx++];
542 SmallVector<SourceLocation, 16> SelLocs;
543 SelLocs.reserve(NumStoredSelLocs);
544 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
545 SelLocs.push_back(ReadSourceLocation(Record, Idx));
546
547 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +0000548}
549
Sebastian Redlb3298c32010-08-18 23:56:48 +0000550void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000551 VisitNamedDecl(CD);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000552 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
553 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000554}
555
Sebastian Redlb3298c32010-08-18 23:56:48 +0000556void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000557 VisitObjCContainerDecl(ID);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000558 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000559 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000560
561 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000562 unsigned NumProtocols = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000563 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner487412d2009-04-27 05:27:42 +0000564 Protocols.reserve(NumProtocols);
565 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000566 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000567 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000568 ProtoLocs.reserve(NumProtocols);
569 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000570 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000571 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000572 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000573
574 // Read the transitive closure of protocols referenced by this class.
575 NumProtocols = Record[Idx++];
576 Protocols.clear();
577 Protocols.reserve(NumProtocols);
578 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000579 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000580 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor4163aca2011-09-09 21:34:22 +0000581 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000582
583 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000584 unsigned NumIvars = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000585 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner487412d2009-04-27 05:27:42 +0000586 IVars.reserve(NumIvars);
587 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000588 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
589 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
590
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000591 // We will rebuild this list lazily.
592 ID->setIvarList(0);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000593 ID->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000594 ID->ForwardDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000595 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
596 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000597}
598
Sebastian Redlb3298c32010-08-18 23:56:48 +0000599void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000600 VisitFieldDecl(IVD);
601 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000602 // This field will be built lazily.
603 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000604 bool synth = Record[Idx++];
605 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000606}
607
Sebastian Redlb3298c32010-08-18 23:56:48 +0000608void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000609 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000610 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000611 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000612 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000613 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000614 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000615 ProtoRefs.reserve(NumProtoRefs);
616 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000617 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000618 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000619 ProtoLocs.reserve(NumProtoRefs);
620 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000621 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000622 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000623 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000624}
625
Sebastian Redlb3298c32010-08-18 23:56:48 +0000626void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000627 VisitFieldDecl(FD);
628}
629
Sebastian Redlb3298c32010-08-18 23:56:48 +0000630void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000631 VisitDecl(CD);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000632 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
633 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000634 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner487412d2009-04-27 05:27:42 +0000635}
636
Sebastian Redlb3298c32010-08-18 23:56:48 +0000637void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000638 VisitDecl(FPD);
639 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000640 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000641 ProtoRefs.reserve(NumProtoRefs);
642 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000643 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000644 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000645 ProtoLocs.reserve(NumProtoRefs);
646 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000647 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000648 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000649 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000650}
651
Sebastian Redlb3298c32010-08-18 23:56:48 +0000652void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000653 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000654 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000655 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000656 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000657 ProtoRefs.reserve(NumProtoRefs);
658 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000659 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000660 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000661 ProtoLocs.reserve(NumProtoRefs);
662 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000663 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000664 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000665 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000666 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000667 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000668 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000669}
670
Sebastian Redlb3298c32010-08-18 23:56:48 +0000671void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000672 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000673 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000674}
675
Sebastian Redlb3298c32010-08-18 23:56:48 +0000676void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000677 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000678 D->setAtLoc(ReadSourceLocation(Record, Idx));
679 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000680 // FIXME: stable encoding
681 D->setPropertyAttributes(
682 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000683 D->setPropertyAttributesAsWritten(
684 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000685 // FIXME: stable encoding
686 D->setPropertyImplementation(
687 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000688 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
689 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000690 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
691 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
692 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000693}
694
Sebastian Redlb3298c32010-08-18 23:56:48 +0000695void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000696 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000697 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000698}
699
Sebastian Redlb3298c32010-08-18 23:56:48 +0000700void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000701 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000702 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000703}
704
Sebastian Redlb3298c32010-08-18 23:56:48 +0000705void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000706 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000707 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000708 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000709 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000710 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000711}
712
713
Sebastian Redlb3298c32010-08-18 23:56:48 +0000714void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000715 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000716 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000717 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
718 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000719 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000720 D->setGetterCXXConstructor(Reader.ReadExpr(F));
721 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000722}
723
Sebastian Redlb3298c32010-08-18 23:56:48 +0000724void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000725 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000726 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000727 int BitWidthOrInitializer = Record[Idx++];
728 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000729 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000730 else if (BitWidthOrInitializer == 2)
731 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000732 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000733 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000734 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000735 }
Chris Lattner487412d2009-04-27 05:27:42 +0000736}
737
Francois Pichet783dd6e2010-11-21 06:08:52 +0000738void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
739 VisitValueDecl(FD);
740
741 FD->ChainingSize = Record[Idx++];
742 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000743 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000744
745 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000746 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000747}
748
Sebastian Redlb3298c32010-08-18 23:56:48 +0000749void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000750 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000751 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000752 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
753 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
754 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
755 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
756 VD->VarDeclBits.ExceptionVar = Record[Idx++];
757 VD->VarDeclBits.NRVOVariable = Record[Idx++];
758 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000759 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000760 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000761 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000762
763 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000764 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000765 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000766 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000767 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000768 }
Chris Lattner487412d2009-04-27 05:27:42 +0000769}
770
Sebastian Redlb3298c32010-08-18 23:56:48 +0000771void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000772 VisitVarDecl(PD);
773}
774
Sebastian Redlb3298c32010-08-18 23:56:48 +0000775void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000776 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000777 unsigned isObjCMethodParam = Record[Idx++];
778 unsigned scopeDepth = Record[Idx++];
779 unsigned scopeIndex = Record[Idx++];
780 unsigned declQualifier = Record[Idx++];
781 if (isObjCMethodParam) {
782 assert(scopeDepth == 0);
783 PD->setObjCMethodScopeInfo(scopeIndex);
784 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
785 } else {
786 PD->setScopeInfo(scopeDepth, scopeIndex);
787 }
John McCallbeaa11c2011-05-01 02:13:58 +0000788 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
789 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000790 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000791 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000792}
793
Sebastian Redlb3298c32010-08-18 23:56:48 +0000794void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000795 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000796 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000797 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000798}
799
Sebastian Redlb3298c32010-08-18 23:56:48 +0000800void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000801 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000802 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
803 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000804 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000805 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000806 Params.reserve(NumParams);
807 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000808 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000809 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000810
811 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000812 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000813 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000814 captures.reserve(numCaptures);
815 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000816 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000817 unsigned flags = Record[Idx++];
818 bool byRef = (flags & 1);
819 bool nested = (flags & 2);
820 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
821
822 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
823 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000824 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000825 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000826}
827
Sebastian Redlb3298c32010-08-18 23:56:48 +0000828void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000829 VisitDecl(D);
830 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000831 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000832 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000833}
834
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000835void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
836 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000837 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000838}
839
840
Sebastian Redlb3298c32010-08-18 23:56:48 +0000841void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000842 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000843 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000844 D->LocStart = ReadSourceLocation(Record, Idx);
845 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000846 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000847
Chris Lattnerca025db2010-05-07 21:43:38 +0000848 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000849 // FIXME: Modules will likely have trouble with pointing directly at
850 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000851 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000852 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000853}
854
Sebastian Redlb3298c32010-08-18 23:56:48 +0000855void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000856 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000857 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000858 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000859 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000860 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000861}
862
Sebastian Redlb3298c32010-08-18 23:56:48 +0000863void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000864 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000865 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000866 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000867 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000868 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000869 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000870 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000871 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000872}
873
Sebastian Redlb3298c32010-08-18 23:56:48 +0000874void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000875 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000876 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
877 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
878 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000879 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000880 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000881}
882
Sebastian Redlb3298c32010-08-18 23:56:48 +0000883void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000884 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000885 D->UsingLoc = ReadSourceLocation(Record, Idx);
886 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000887 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000888 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
889 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000890}
891
Sebastian Redlb3298c32010-08-18 23:56:48 +0000892void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000893 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000894 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000895 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000896 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000897}
898
Sebastian Redlb3298c32010-08-18 23:56:48 +0000899void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000900 UnresolvedUsingTypenameDecl *D) {
901 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000902 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000903 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000904}
905
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000906void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000907 struct CXXRecordDecl::DefinitionData &Data,
908 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000909 Data.UserDeclaredConstructor = Record[Idx++];
910 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000911 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000912 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000913 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000914 Data.UserDeclaredDestructor = Record[Idx++];
915 Data.Aggregate = Record[Idx++];
916 Data.PlainOldData = Record[Idx++];
917 Data.Empty = Record[Idx++];
918 Data.Polymorphic = Record[Idx++];
919 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000920 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000921 Data.HasNoNonEmptyBases = Record[Idx++];
922 Data.HasPrivateFields = Record[Idx++];
923 Data.HasProtectedFields = Record[Idx++];
924 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000925 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000926 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000927 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000928 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000929 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000930 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000931 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000932 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000933 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000934 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000935 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000936 Data.DeclaredDefaultConstructor = Record[Idx++];
937 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000938 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000939 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000940 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000941 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000942 Data.FailedImplicitMoveConstructor = Record[Idx++];
943 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000944
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000945 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000946 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000947 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000948 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000949 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000950 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000951
Douglas Gregor7fb09192011-07-21 22:35:25 +0000952 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
953 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000954 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +0000955 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000956}
957
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000958void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
959 CXXRecordDecl *DefinitionDecl,
960 const RecordData &Record,
961 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +0000962 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000963
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000964 if (D == DefinitionDecl) {
965 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000966 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000967 // We read the definition info. Check if there are pending forward
968 // references that need to point to this DefinitionData pointer.
969 ASTReader::PendingForwardRefsMap::iterator
970 FindI = Reader.PendingForwardRefs.find(D);
971 if (FindI != Reader.PendingForwardRefs.end()) {
972 ASTReader::ForwardRefs &Refs = FindI->second;
973 for (ASTReader::ForwardRefs::iterator
974 I = Refs.begin(), E = Refs.end(); I != E; ++I)
975 (*I)->DefinitionData = D->DefinitionData;
976#ifndef NDEBUG
977 // We later check whether PendingForwardRefs is empty to make sure all
978 // pending references were linked.
979 Reader.PendingForwardRefs.erase(D);
980#endif
981 }
982 } else if (DefinitionDecl) {
983 if (DefinitionDecl->DefinitionData) {
984 D->DefinitionData = DefinitionDecl->DefinitionData;
985 } else {
986 // The definition is still initializing.
987 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
988 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000989 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000990}
991
992void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
993 VisitRecordDecl(D);
994
Douglas Gregor7fb09192011-07-21 22:35:25 +0000995 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000996 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
997
Douglas Gregor4163aca2011-09-09 21:34:22 +0000998 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000999
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001000 enum CXXRecKind {
1001 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1002 };
1003 switch ((CXXRecKind)Record[Idx++]) {
1004 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001005 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001006 case CXXRecNotTemplate:
1007 break;
1008 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001009 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001010 break;
1011 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001012 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001013 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001014 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001015 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1016 MSI->setPointOfInstantiation(POI);
1017 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001018 break;
1019 }
1020 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001021
1022 // Load the key function to avoid deserializing every method so we can
1023 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001024 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001025 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001026 C.KeyFunctions[D] = Key;
1027 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001028}
1029
Sebastian Redlb3298c32010-08-18 23:56:48 +00001030void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001031 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001032 unsigned NumOverridenMethods = Record[Idx++];
1033 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001034 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1035 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001036 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001037 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001038 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001039}
1040
Sebastian Redlb3298c32010-08-18 23:56:48 +00001041void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001042 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001043
1044 D->IsExplicitSpecified = Record[Idx++];
1045 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001046 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1047 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001048}
1049
Sebastian Redlb3298c32010-08-18 23:56:48 +00001050void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001051 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001052
1053 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001054 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001055}
1056
Sebastian Redlb3298c32010-08-18 23:56:48 +00001057void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001058 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001059 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001060}
1061
Douglas Gregorba345522011-12-02 23:23:56 +00001062void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1063 VisitDecl(D);
1064 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1065 D->ImportedAndComplete.setInt(Record[Idx++]);
1066 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1067 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1068 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1069 ++Idx;
1070}
1071
Sebastian Redlb3298c32010-08-18 23:56:48 +00001072void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001073 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001074 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001075}
1076
Sebastian Redlb3298c32010-08-18 23:56:48 +00001077void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001078 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001079 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001080 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001081 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001082 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001083 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001084 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001085 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001086}
1087
Sebastian Redlb3298c32010-08-18 23:56:48 +00001088void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001089 VisitDecl(D);
1090 unsigned NumParams = Record[Idx++];
1091 D->NumParams = NumParams;
1092 D->Params = new TemplateParameterList*[NumParams];
1093 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001094 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001095 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001096 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001097 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001098 D->Friend = GetTypeSourceInfo(Record, Idx);
1099 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001100}
1101
Sebastian Redlb3298c32010-08-18 23:56:48 +00001102void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001103 VisitNamedDecl(D);
1104
Douglas Gregor7fb09192011-07-21 22:35:25 +00001105 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001106 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001107 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001108 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001109}
1110
Sebastian Redlb3298c32010-08-18 23:56:48 +00001111void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001112 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1113 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001114
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001115 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001116 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1117 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001118 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1119 // We temporarily set the first (canonical) declaration as the previous one
1120 // which is the one that matters and mark the real previous DeclID to be
1121 // loaded & attached later on.
1122 RedeclarableTemplateDecl *FirstDecl =
1123 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1124 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1125 "FirstDecl kind mismatch");
1126 if (FirstDecl) {
1127 D->CommonOrPrev = FirstDecl;
1128 // Mark the real previous DeclID to be loaded & attached later on.
1129 if (PreviousDeclID != FirstDeclID)
1130 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1131 } else {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001132 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001133 if (RedeclarableTemplateDecl *RTD
Douglas Gregor7fb09192011-07-21 22:35:25 +00001134 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001135 assert(RTD->getKind() == D->getKind() &&
1136 "InstantiatedFromMemberTemplate kind mismatch");
1137 D->setInstantiatedFromMemberTemplateImpl(RTD);
1138 if (Record[Idx++])
1139 D->setMemberSpecialization();
1140 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001141
Douglas Gregor7fb09192011-07-21 22:35:25 +00001142 RedeclarableTemplateDecl *LatestDecl
1143 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001144
1145 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001146 // in the same AST file. However, if this actually needs to point to a
1147 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001148 // the FirstLatestDeclIDs map which tracks this kind of decls.
1149 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001150 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001151 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1152 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregoraa7cbfd2011-08-25 15:28:26 +00001153 if (Decl *NewLatest = Reader.GetDecl(I->second))
1154 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001155 }
1156
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001157 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1158 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001159 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001160
1161 VisitTemplateDecl(D);
1162 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001163}
1164
Sebastian Redlb3298c32010-08-18 23:56:48 +00001165void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001166 VisitRedeclarableTemplateDecl(D);
1167
1168 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001169 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1170 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001171 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001172 SpecIDs.push_back(0);
1173
1174 // Specializations.
1175 unsigned Size = Record[Idx++];
1176 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001177 for (unsigned I = 0; I != Size; ++I)
1178 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001179
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001180 // Partial specializations.
1181 Size = Record[Idx++];
1182 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001183 for (unsigned I = 0; I != Size; ++I)
1184 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001185
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001186 if (SpecIDs[0]) {
1187 typedef serialization::DeclID DeclID;
1188
1189 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1190 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001191 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001192 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1193 SpecIDs.size() * sizeof(DeclID));
1194 }
1195
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001196 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001197 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001198}
1199
Sebastian Redlb3298c32010-08-18 23:56:48 +00001200void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001201 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001202 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001203
Douglas Gregor4163aca2011-09-09 21:34:22 +00001204 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001205 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001206 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001207 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001208 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001209 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001210 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001211 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001212 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1213 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001214 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1215 = new (C) ClassTemplateSpecializationDecl::
1216 SpecializedPartialSpecialization();
1217 PS->PartialSpecialization
1218 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1219 PS->TemplateArgs = ArgList;
1220 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001221 }
1222 }
1223
1224 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001225 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001226 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1227 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1228 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001229 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1230 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001231 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001232 }
1233
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001234 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001235 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001236 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1237 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001238 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001239 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001240
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001241 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001242 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001243 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001244 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1245 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001246 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001247 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001248 }
1249 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001250}
1251
Sebastian Redlb3298c32010-08-18 23:56:48 +00001252void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001253 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001254 VisitClassTemplateSpecializationDecl(D);
1255
Douglas Gregor4163aca2011-09-09 21:34:22 +00001256 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001257 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001258
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001259 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001260 if (NumArgs) {
1261 D->NumArgsAsWritten = NumArgs;
1262 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1263 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001264 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001265 }
1266
1267 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001268
1269 // These are read/set from/to the first declaration.
1270 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001271 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001272 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001273 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001274 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001275}
1276
Sebastian Redlb7448632011-08-31 13:59:56 +00001277void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1278 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001279 VisitDecl(D);
1280 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1281}
1282
Sebastian Redlb3298c32010-08-18 23:56:48 +00001283void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001284 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001285
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001286 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001287 // This FunctionTemplateDecl owns a CommonPtr; read it.
1288
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001289 // Read the function specialization declarations.
1290 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001291 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001292 unsigned NumSpecs = Record[Idx++];
1293 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001294 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001295 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001296}
1297
Sebastian Redlb3298c32010-08-18 23:56:48 +00001298void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001299 VisitTypeDecl(D);
1300
1301 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001302
1303 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001304 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001305 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001306}
1307
Sebastian Redlb3298c32010-08-18 23:56:48 +00001308void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001309 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001310 // TemplateParmPosition.
1311 D->setDepth(Record[Idx++]);
1312 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001313 if (D->isExpandedParameterPack()) {
1314 void **Data = reinterpret_cast<void **>(D + 1);
1315 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001316 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001317 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1318 }
1319 } else {
1320 // Rest of NonTypeTemplateParmDecl.
1321 D->ParameterPack = Record[Idx++];
1322 if (Record[Idx++]) {
1323 Expr *DefArg = Reader.ReadExpr(F);
1324 bool Inherited = Record[Idx++];
1325 D->setDefaultArgument(DefArg, Inherited);
1326 }
1327 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001328}
1329
Sebastian Redlb3298c32010-08-18 23:56:48 +00001330void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001331 VisitTemplateDecl(D);
1332 // TemplateParmPosition.
1333 D->setDepth(Record[Idx++]);
1334 D->setPosition(Record[Idx++]);
1335 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001336 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001337 bool IsInherited = Record[Idx++];
1338 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001339 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001340}
1341
Richard Smith3f1b5d02011-05-05 21:57:07 +00001342void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1343 VisitRedeclarableTemplateDecl(D);
1344}
1345
Sebastian Redlb3298c32010-08-18 23:56:48 +00001346void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001347 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001348 D->AssertExpr = Reader.ReadExpr(F);
1349 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001350 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001351}
1352
Mike Stump11289f42009-09-09 15:08:12 +00001353std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001354ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001355 uint64_t LexicalOffset = Record[Idx++];
1356 uint64_t VisibleOffset = Record[Idx++];
1357 return std::make_pair(LexicalOffset, VisibleOffset);
1358}
1359
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001360template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001361void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001362 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1363 RedeclKind Kind = (RedeclKind)Record[Idx++];
1364 switch (Kind) {
1365 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001366 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1367 " messed up reading");
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001368 case NoRedeclaration:
1369 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001370 case PointsToPrevious: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001371 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1372 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001373 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1374 // We temporarily set the first (canonical) declaration as the previous one
1375 // which is the one that matters and mark the real previous DeclID to be
1376 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001377 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1378 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001379 if (PreviousDeclID != FirstDeclID)
1380 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1381 PreviousDeclID));
Douglas Gregor3e300102011-10-26 17:53:41 +00001382
1383 // If the first declaration in the chain is in an inconsistent
1384 // state where it thinks that it is the only declaration, fix its
1385 // redeclaration link now to point at this declaration, so that we have a
1386 // proper redeclaration chain.
1387 if (FirstDecl->RedeclLink.getPointer() == FirstDecl) {
1388 FirstDecl->RedeclLink
1389 = typename Redeclarable<T>::LatestDeclLink(static_cast<T*>(D));
1390 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001391 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001392 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001393 case PointsToLatest: {
1394 T *LatestDecl = ReadDeclAs<T>(Record, Idx);
1395 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(LatestDecl);
1396
1397 // If the latest declaration in the chain is in an inconsistent
1398 // state where it thinks that it is the only declaration, fix its
1399 // redeclaration link now to point at this declaration, so that we have a
1400 // proper redeclaration chain.
1401 if (LatestDecl->RedeclLink.getPointer() == LatestDecl) {
1402 LatestDecl->RedeclLink
1403 = typename Redeclarable<T>::PreviousDeclLink(static_cast<T*>(D));
1404 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001405 break;
1406 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001407 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001408
1409 assert(!(Kind == PointsToPrevious &&
1410 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1411 Reader.FirstLatestDeclIDs.end()) &&
1412 "This decl is not first, it should not be in the map");
1413 if (Kind == PointsToPrevious)
1414 return;
1415
1416 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001417 // the same AST file. However, if this actually needs to point to a
1418 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001419 // FirstLatestDeclIDs map which tracks this kind of decls.
1420 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1421 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001422 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001423 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1424 if (I != Reader.FirstLatestDeclIDs.end()) {
1425 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001426 D->RedeclLink
1427 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1428 }
1429}
1430
Chris Lattner487412d2009-04-27 05:27:42 +00001431//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001432// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001433//===----------------------------------------------------------------------===//
1434
Chris Lattner8f63ab52009-04-27 06:01:06 +00001435/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001436void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001437 const RecordData &Record, unsigned &Idx) {
1438 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001439 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001440 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001441 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001442
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001443#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001444
1445 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001446 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001447 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001448}
1449
1450//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001451// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001452//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001453
1454/// \brief Note that we have loaded the declaration with the given
1455/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001456///
Chris Lattner487412d2009-04-27 05:27:42 +00001457/// This routine notes that this declaration has already been loaded,
1458/// so that future GetDecl calls will return this declaration rather
1459/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001460inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001461 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1462 DeclsLoaded[Index] = D;
1463}
1464
1465
1466/// \brief Determine whether the consumer will be interested in seeing
1467/// this declaration (via HandleTopLevelDecl).
1468///
1469/// This routine should return true for anything that might affect
1470/// code generation, e.g., inline function definitions, Objective-C
1471/// declarations with metadata, etc.
1472static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001473 // An ObjCMethodDecl is never considered as "interesting" because its
1474 // implementation container always is.
1475
Douglas Gregor87d81242011-09-10 00:22:34 +00001476 if (isa<FileScopeAsmDecl>(D) ||
1477 isa<ObjCProtocolDecl>(D) ||
1478 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001479 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001480 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001481 return Var->isFileVarDecl() &&
1482 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001483 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001484 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001485
1486 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001487}
1488
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001489/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001490ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001491ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001492 // See if there's an override.
1493 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001494 if (It != ReplacedDecls.end()) {
1495 RawLocation = It->second.RawLoc;
1496 return RecordLocation(It->second.Mod, It->second.Offset);
1497 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001498
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001499 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1500 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001501 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001502 const DeclOffset &
1503 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1504 RawLocation = DOffs.Loc;
1505 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001506}
1507
Douglas Gregord32f0352011-07-22 06:10:01 +00001508ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001509 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001510 = GlobalBitOffsetsMap.find(GlobalOffset);
1511
1512 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1513 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1514}
1515
Douglas Gregorde3ef502011-11-30 23:21:26 +00001516uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001517 return LocalOffset + M.GlobalBitOffset;
1518}
1519
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001520void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1521 assert(D && previous);
1522 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1523 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1524 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1525 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1526 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1527 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1528 } else {
1529 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1530 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1531 }
1532}
1533
1534void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1535 Decl *previous = GetDecl(ID);
1536 ASTDeclReader::attachPreviousDecl(D, previous);
1537}
1538
Sebastian Redlb3298c32010-08-18 23:56:48 +00001539/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001540Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001541 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001542 unsigned RawLocation = 0;
1543 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001544 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001545 // Keep track of where we are in the stream, then jump back there
1546 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001547 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001548
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001549 ReadingKindTracker ReadingKind(Read_Decl, *this);
1550
Douglas Gregor1342e842009-07-06 18:54:52 +00001551 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001552 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001553
Sebastian Redl2c373b92010-10-05 15:59:54 +00001554 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001555 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001556 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001557 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001558 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001559
Chris Lattner1de76db2009-04-27 05:58:23 +00001560 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001561 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001562 case DECL_CONTEXT_LEXICAL:
1563 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001564 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001565 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001566 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001567 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001568 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001569 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001570 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001571 0, 0);
1572 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001573 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001574 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001575 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001576 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001577 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001578 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001579 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001580 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001581 0, llvm::APSInt());
1582 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001583 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001584 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001585 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001586 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001587 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001588 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001589 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001590 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001591 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001592 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001593 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001594 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001595 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001596 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001597 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001598 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001599 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001600 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001601 SourceLocation(), 0,
1602 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001603 SourceLocation(), 0);
1604 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001605 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001606 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001607 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1608 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001609 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001610 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001611 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001612 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001613 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001614 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001615 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001616 SourceLocation(), 0, 0);
1617 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001618 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001619 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001620 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001621 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001622 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001623 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001624 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001625 SourceLocation(),
1626 NestedNameSpecifierLoc(),
1627 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001628 DeclarationName());
1629 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001630 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001631 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001632 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001633 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001634 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001635 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001636 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001637 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001638 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001639 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001640 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001641 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001642 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001643 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001644 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001645 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001646 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001647 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001648 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001649 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001650 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001651 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001652 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001653 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001654 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001655 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001656 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001657 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001658 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001659 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001660 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001661 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001662 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001663 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001664 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001665 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001666 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001667 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001668 Decl::EmptyShell());
1669 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001670 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001671 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001672 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001673 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001674 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001675 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001676 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001677 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001678 SourceLocation(), 0, 0, 0, QualType(),
1679 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001680 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001681 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001682 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001683 SourceLocation(), 0, 0, 0, QualType(),
1684 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001685 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001686 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001687 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001688 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001689 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001690 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001691 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001692 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001693 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001694 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001695 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001696 break;
1697
Sebastian Redl539c5062010-08-18 23:57:32 +00001698 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001699 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001700 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001701 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001702 case DECL_OBJC_INTERFACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001703 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001704 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001705 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001706 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001707 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001708 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001709 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001710 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001711 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001712 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001713 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001714 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001715 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001716 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001717 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001718 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001719 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001720 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001721 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001722 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001723 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001724 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001725 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001726 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001727 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1728 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001729 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001730 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001731 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1732 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001733 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001734 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001735 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001736 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001737 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001738 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001739 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001740 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001741 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001742 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001743 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001744 ObjCPropertyImplDecl::Dynamic, 0,
1745 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001746 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001747 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001748 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001749 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001750 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001751 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001752 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001753 0, 0);
1754 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001755 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001756 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001757 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001758 break;
1759
Sebastian Redl539c5062010-08-18 23:57:32 +00001760 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001761 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001762 break;
1763
Sebastian Redl539c5062010-08-18 23:57:32 +00001764 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001765 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001766 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001767 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001768 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001769 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001770 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001771 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001772 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001773 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001774 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001775 case DECL_CXX_BASE_SPECIFIERS:
1776 Error("attempt to read a C++ base-specifier record as a declaration");
1777 return 0;
Douglas Gregorba345522011-12-02 23:23:56 +00001778 case DECL_IMPORT:
1779 // Note: last entry of the ImportDecl record is the number of stored source
1780 // locations.
1781 D = ImportDecl::CreateEmpty(Context, Record.back());
1782 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001783 }
Chris Lattner487412d2009-04-27 05:27:42 +00001784
Sebastian Redlb3298c32010-08-18 23:56:48 +00001785 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001786 LoadedDecl(Index, D);
1787 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001788
1789 // If this declaration is also a declaration context, get the
1790 // offsets for its tables of lexical and visible declarations.
1791 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1792 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1793 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001794 if (Offsets.first != 0)
1795 DC->setHasExternalLexicalStorage(true);
1796 if (Offsets.second != 0)
1797 DC->setHasExternalVisibleStorage(true);
1798 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1799 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001800 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001801 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001802
Sebastian Redlf830df42011-04-24 16:27:54 +00001803 // Now add the pending visible updates for this decl context, if it has any.
1804 DeclContextVisibleUpdatesPending::iterator I =
1805 PendingVisibleUpdates.find(ID);
1806 if (I != PendingVisibleUpdates.end()) {
1807 // There are updates. This means the context has external visible
1808 // storage, even if the original stored version didn't.
1809 DC->setHasExternalVisibleStorage(true);
1810 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001811 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1812 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001813 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001814 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001815 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001816 }
1817 }
1818 assert(Idx == Record.size());
1819
Douglas Gregordab42432011-08-12 00:15:20 +00001820 // Load any relevant update records.
1821 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001822
1823 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001824 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001825 PendingChainedObjCCategories.push_back(
1826 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001827
Douglas Gregordab42432011-08-12 00:15:20 +00001828 // If we have deserialized a declaration that has a definition the
1829 // AST consumer might need to know about, queue it.
1830 // We don't pass it to the consumer immediately because we may be in recursive
1831 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001832 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001833 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001834
Douglas Gregordab42432011-08-12 00:15:20 +00001835 return D;
1836}
1837
1838void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001839 // The declaration may have been modified by files later in the chain.
1840 // If this is the case, read the record containing the updates from each file
1841 // and pass it to ASTDeclReader to make the modifications.
1842 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1843 if (UpdI != DeclUpdateOffsets.end()) {
1844 FileOffsetsTy &UpdateOffsets = UpdI->second;
1845 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001846 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001847 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001848 uint64_t Offset = I->second;
1849 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1850 SavedStreamPosition SavedPosition(Cursor);
1851 Cursor.JumpToBit(Offset);
1852 RecordData Record;
1853 unsigned Code = Cursor.ReadCode();
1854 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1855 (void)RecCode;
1856 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001857
1858 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001859 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001860 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001861 }
1862 }
Chris Lattner487412d2009-04-27 05:27:42 +00001863}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001864
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001865namespace {
1866 /// \brief Given an ObjC interface, goes through the modules and links to the
1867 /// interface all the categories for it.
1868 class ObjCChainedCategoriesVisitor {
1869 ASTReader &Reader;
1870 serialization::GlobalDeclID InterfaceID;
1871 ObjCInterfaceDecl *Interface;
1872 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1873 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1874
1875 public:
1876 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1877 serialization::GlobalDeclID InterfaceID,
1878 ObjCInterfaceDecl *Interface)
1879 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1880 GlobHeadCat(0), GlobTailCat(0) { }
1881
Douglas Gregorde3ef502011-11-30 23:21:26 +00001882 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001883 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1884 }
1885
Douglas Gregorde3ef502011-11-30 23:21:26 +00001886 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001887 if (Reader.isDeclIDFromModule(InterfaceID, M))
1888 return true; // We reached the module where the interface originated
1889 // from. Stop traversing the imported modules.
1890
Douglas Gregorde3ef502011-11-30 23:21:26 +00001891 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001892 I = M.ChainedObjCCategories.find(InterfaceID);
1893 if (I == M.ChainedObjCCategories.end())
1894 return false;
1895
1896 ObjCCategoryDecl *
1897 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1898 ObjCCategoryDecl *
1899 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1900
1901 addCategories(HeadCat, TailCat);
1902 return false;
1903 }
1904
1905 void addCategories(ObjCCategoryDecl *HeadCat,
1906 ObjCCategoryDecl *TailCat = 0) {
1907 if (!HeadCat) {
1908 assert(!TailCat);
1909 return;
1910 }
1911
1912 if (!TailCat) {
1913 TailCat = HeadCat;
1914 while (TailCat->getNextClassCategory())
1915 TailCat = TailCat->getNextClassCategory();
1916 }
1917
1918 if (!GlobHeadCat) {
1919 GlobHeadCat = HeadCat;
1920 GlobTailCat = TailCat;
1921 } else {
1922 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1923 GlobTailCat = TailCat;
1924 }
1925
1926 llvm::DenseSet<DeclarationName> Checked;
1927 for (ObjCCategoryDecl *Cat = HeadCat,
1928 *CatEnd = TailCat->getNextClassCategory();
1929 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1930 if (Checked.count(Cat->getDeclName()))
1931 continue;
1932 Checked.insert(Cat->getDeclName());
1933 checkForDuplicate(Cat);
1934 }
1935 }
1936
1937 /// \brief Warns for duplicate categories that come from different modules.
1938 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1939 DeclarationName Name = Cat->getDeclName();
1940 // Find the top category with the same name. We do not want to warn for
1941 // duplicates along the established chain because there were already
1942 // warnings for them when the module was created. We only want to warn for
1943 // duplicates between non-dependent modules:
1944 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001945 // MT //
1946 // / \ //
1947 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001948 //
1949 // We want to warn for duplicates between ML and MR,not between ML and MT.
1950 //
1951 // FIXME: We should not warn for duplicates in diamond:
1952 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001953 // MT //
1954 // / \ //
1955 // ML MR //
1956 // \ / //
1957 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001958 //
1959 // If there are duplicates in ML/MR, there will be warning when creating
1960 // MB *and* when importing MB. We should not warn when importing.
1961 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1962 Next = Next->getNextClassCategory()) {
1963 if (Next->getDeclName() == Name)
1964 Cat = Next;
1965 }
1966
1967 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1968 if (!PrevCat)
1969 PrevCat = Cat;
1970
1971 if (PrevCat != Cat) {
1972 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1973 << Interface->getDeclName() << Name;
1974 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1975 }
1976 }
1977
1978 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1979 };
1980}
1981
1982void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1983 ObjCInterfaceDecl *D) {
1984 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1985 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1986 // Also add the categories that the interface already links to.
1987 Visitor.addCategories(D->getCategoryList());
1988 D->setCategoryList(Visitor.getHeadCategory());
1989}
Douglas Gregordab42432011-08-12 00:15:20 +00001990
Douglas Gregorde3ef502011-11-30 23:21:26 +00001991void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001992 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001993 unsigned Idx = 0;
1994 while (Idx < Record.size()) {
1995 switch ((DeclUpdateKind)Record[Idx++]) {
1996 case UPD_CXX_SET_DEFINITIONDATA: {
1997 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00001998 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00001999 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002000 assert(!RD->DefinitionData && "DefinitionData is already set!");
2001 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2002 break;
2003 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002004
2005 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00002006 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002007 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00002008
2009 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2010 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002011 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002012 break;
2013
2014 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00002015 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00002016 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00002017 // Guard against these being loaded out of original order. Don't use
2018 // getNextNamespace(), since it tries to access the context and can't in
2019 // the middle of deserialization.
2020 if (!Anon->NextNamespace) {
2021 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2022 TU->setAnonymousNamespace(Anon);
2023 else
2024 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2025 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002026 break;
2027 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002028
2029 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2030 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002031 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002032 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002033 }
2034 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002035}