blob: f7f93af9ce533e4031a144a5dff53073c1343b27 [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());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000559
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000560 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
561 if (ID == Def) {
562 // Read the definition.
563 ID->allocateDefinitionData();
564
565 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
566
567 // Read the superclass.
568 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
569 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
570
571 // Read the directly referenced protocols and their SourceLocations.
572 unsigned NumProtocols = Record[Idx++];
573 SmallVector<ObjCProtocolDecl *, 16> Protocols;
574 Protocols.reserve(NumProtocols);
575 for (unsigned I = 0; I != NumProtocols; ++I)
576 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
577 SmallVector<SourceLocation, 16> ProtoLocs;
578 ProtoLocs.reserve(NumProtocols);
579 for (unsigned I = 0; I != NumProtocols; ++I)
580 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
581 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
582 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000583
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000584 // Read the transitive closure of protocols referenced by this class.
585 NumProtocols = Record[Idx++];
586 Protocols.clear();
587 Protocols.reserve(NumProtocols);
588 for (unsigned I = 0; I != NumProtocols; ++I)
589 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
590 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
591 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000592
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000593 // Read the ivars.
594 unsigned NumIvars = Record[Idx++];
595 SmallVector<ObjCIvarDecl *, 16> IVars;
596 IVars.reserve(NumIvars);
597 for (unsigned I = 0; I != NumIvars; ++I)
598 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
599
600 // Read the categories.
601 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000602
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000603 // We will rebuild this list lazily.
604 ID->setIvarList(0);
605
606 // If there are any pending forward references, make their definition data
607 // pointers point at the newly-allocated data.
608 ASTReader::PendingForwardRefsMap::iterator
609 FindI = Reader.PendingForwardRefs.find(ID);
610 if (FindI != Reader.PendingForwardRefs.end()) {
611 ASTReader::ForwardRefs &Refs = FindI->second;
612 for (ASTReader::ForwardRefs::iterator I = Refs.begin(),
613 E = Refs.end();
614 I != E; ++I)
615 cast<ObjCInterfaceDecl>(*I)->Definition = ID->Definition;
616#ifndef NDEBUG
617 // We later check whether PendingForwardRefs is empty to make sure all
618 // pending references were linked.
619 Reader.PendingForwardRefs.erase(ID);
620#endif
621
622 } else if (Def) {
623 if (Def->Definition) {
624 ID->Definition = Def->Definition;
625 } else {
626 // The definition is still initializing.
627 Reader.PendingForwardRefs[Def].push_back(ID);
628 }
629 }
630 }
631
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000632 ID->InitiallyForwardDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000633 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000634}
635
Sebastian Redlb3298c32010-08-18 23:56:48 +0000636void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000637 VisitFieldDecl(IVD);
638 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000639 // This field will be built lazily.
640 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000641 bool synth = Record[Idx++];
642 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000643}
644
Sebastian Redlb3298c32010-08-18 23:56:48 +0000645void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000646 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000647 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000648 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000649 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000650 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000651 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000652 ProtoRefs.reserve(NumProtoRefs);
653 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000654 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000655 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000656 ProtoLocs.reserve(NumProtoRefs);
657 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000658 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000659 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000660 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000661}
662
Sebastian Redlb3298c32010-08-18 23:56:48 +0000663void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000664 VisitFieldDecl(FD);
665}
666
Sebastian Redlb3298c32010-08-18 23:56:48 +0000667void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000668 VisitDecl(CD);
Douglas Gregor40d009f2011-12-14 17:12:03 +0000669 CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
670 CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000671}
672
Sebastian Redlb3298c32010-08-18 23:56:48 +0000673void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000674 VisitDecl(FPD);
675 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000676 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000677 ProtoRefs.reserve(NumProtoRefs);
678 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000679 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000680 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000681 ProtoLocs.reserve(NumProtoRefs);
682 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000683 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000684 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000685 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000686}
687
Sebastian Redlb3298c32010-08-18 23:56:48 +0000688void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000689 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000690 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000691 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000692 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000693 ProtoRefs.reserve(NumProtoRefs);
694 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000695 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000696 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000697 ProtoLocs.reserve(NumProtoRefs);
698 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000699 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000700 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000701 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000702 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000703 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000704 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000705}
706
Sebastian Redlb3298c32010-08-18 23:56:48 +0000707void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000708 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000709 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000710}
711
Sebastian Redlb3298c32010-08-18 23:56:48 +0000712void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000713 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000714 D->setAtLoc(ReadSourceLocation(Record, Idx));
715 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000716 // FIXME: stable encoding
717 D->setPropertyAttributes(
718 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000719 D->setPropertyAttributesAsWritten(
720 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000721 // FIXME: stable encoding
722 D->setPropertyImplementation(
723 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000724 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
725 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000726 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
727 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
728 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000729}
730
Sebastian Redlb3298c32010-08-18 23:56:48 +0000731void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000732 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000733 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000734}
735
Sebastian Redlb3298c32010-08-18 23:56:48 +0000736void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000737 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000738 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000739 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000740}
741
Sebastian Redlb3298c32010-08-18 23:56:48 +0000742void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000743 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000744 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000745 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000746 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000747 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000748}
749
750
Sebastian Redlb3298c32010-08-18 23:56:48 +0000751void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000752 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000753 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000754 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
755 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000756 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000757 D->setGetterCXXConstructor(Reader.ReadExpr(F));
758 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000759}
760
Sebastian Redlb3298c32010-08-18 23:56:48 +0000761void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000762 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000763 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000764 int BitWidthOrInitializer = Record[Idx++];
765 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000766 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000767 else if (BitWidthOrInitializer == 2)
768 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000769 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000770 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000771 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000772 }
Chris Lattner487412d2009-04-27 05:27:42 +0000773}
774
Francois Pichet783dd6e2010-11-21 06:08:52 +0000775void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
776 VisitValueDecl(FD);
777
778 FD->ChainingSize = Record[Idx++];
779 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000780 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000781
782 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000783 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000784}
785
Sebastian Redlb3298c32010-08-18 23:56:48 +0000786void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000787 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000788 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000789 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
790 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
791 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
792 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
793 VD->VarDeclBits.ExceptionVar = Record[Idx++];
794 VD->VarDeclBits.NRVOVariable = Record[Idx++];
795 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000796 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000797 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000798 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000799
800 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000801 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000802 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000803 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000804 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000805 }
Chris Lattner487412d2009-04-27 05:27:42 +0000806}
807
Sebastian Redlb3298c32010-08-18 23:56:48 +0000808void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000809 VisitVarDecl(PD);
810}
811
Sebastian Redlb3298c32010-08-18 23:56:48 +0000812void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000813 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000814 unsigned isObjCMethodParam = Record[Idx++];
815 unsigned scopeDepth = Record[Idx++];
816 unsigned scopeIndex = Record[Idx++];
817 unsigned declQualifier = Record[Idx++];
818 if (isObjCMethodParam) {
819 assert(scopeDepth == 0);
820 PD->setObjCMethodScopeInfo(scopeIndex);
821 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
822 } else {
823 PD->setScopeInfo(scopeDepth, scopeIndex);
824 }
John McCallbeaa11c2011-05-01 02:13:58 +0000825 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
826 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000827 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000828 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000829}
830
Sebastian Redlb3298c32010-08-18 23:56:48 +0000831void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000832 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000833 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000834 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000835}
836
Sebastian Redlb3298c32010-08-18 23:56:48 +0000837void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000838 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000839 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
840 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000841 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000842 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000843 Params.reserve(NumParams);
844 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000845 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000846 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000847
848 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000849 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000850 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000851 captures.reserve(numCaptures);
852 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000853 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000854 unsigned flags = Record[Idx++];
855 bool byRef = (flags & 1);
856 bool nested = (flags & 2);
857 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
858
859 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
860 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000861 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000862 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000863}
864
Sebastian Redlb3298c32010-08-18 23:56:48 +0000865void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000866 VisitDecl(D);
867 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000868 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000869 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000870}
871
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000872void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
873 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000874 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000875}
876
877
Sebastian Redlb3298c32010-08-18 23:56:48 +0000878void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000879 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000880 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000881 D->LocStart = ReadSourceLocation(Record, Idx);
882 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000883 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000884
Chris Lattnerca025db2010-05-07 21:43:38 +0000885 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000886 // FIXME: Modules will likely have trouble with pointing directly at
887 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000888 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000889 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000890}
891
Sebastian Redlb3298c32010-08-18 23:56:48 +0000892void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000893 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000894 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000895 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000896 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000897 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000898}
899
Sebastian Redlb3298c32010-08-18 23:56:48 +0000900void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000901 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000902 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000903 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000904 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000905 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000906 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000907 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000908 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000909}
910
Sebastian Redlb3298c32010-08-18 23:56:48 +0000911void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000912 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000913 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
914 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
915 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000916 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000917 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000918}
919
Sebastian Redlb3298c32010-08-18 23:56:48 +0000920void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000921 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000922 D->UsingLoc = ReadSourceLocation(Record, Idx);
923 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000924 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000925 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
926 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000927}
928
Sebastian Redlb3298c32010-08-18 23:56:48 +0000929void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000930 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000931 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000932 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000933 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000934}
935
Sebastian Redlb3298c32010-08-18 23:56:48 +0000936void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000937 UnresolvedUsingTypenameDecl *D) {
938 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000939 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000940 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000941}
942
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000943void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000944 struct CXXRecordDecl::DefinitionData &Data,
945 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000946 Data.UserDeclaredConstructor = Record[Idx++];
947 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000948 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000949 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000950 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000951 Data.UserDeclaredDestructor = Record[Idx++];
952 Data.Aggregate = Record[Idx++];
953 Data.PlainOldData = Record[Idx++];
954 Data.Empty = Record[Idx++];
955 Data.Polymorphic = Record[Idx++];
956 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000957 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000958 Data.HasNoNonEmptyBases = Record[Idx++];
959 Data.HasPrivateFields = Record[Idx++];
960 Data.HasProtectedFields = Record[Idx++];
961 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000962 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000963 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000964 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000965 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000966 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000967 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000968 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000969 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000970 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000971 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000972 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000973 Data.DeclaredDefaultConstructor = Record[Idx++];
974 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000975 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000976 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000977 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000978 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000979 Data.FailedImplicitMoveConstructor = Record[Idx++];
980 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000981
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000982 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000983 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000984 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000985 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000986 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000987 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000988
Douglas Gregor7fb09192011-07-21 22:35:25 +0000989 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
990 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000991 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +0000992 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000993}
994
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000995void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
996 CXXRecordDecl *DefinitionDecl,
997 const RecordData &Record,
998 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +0000999 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +00001000
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001001 if (D == DefinitionDecl) {
1002 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001003 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001004 // We read the definition info. Check if there are pending forward
1005 // references that need to point to this DefinitionData pointer.
1006 ASTReader::PendingForwardRefsMap::iterator
1007 FindI = Reader.PendingForwardRefs.find(D);
1008 if (FindI != Reader.PendingForwardRefs.end()) {
1009 ASTReader::ForwardRefs &Refs = FindI->second;
1010 for (ASTReader::ForwardRefs::iterator
1011 I = Refs.begin(), E = Refs.end(); I != E; ++I)
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001012 cast<CXXRecordDecl>(*I)->DefinitionData = D->DefinitionData;
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001013#ifndef NDEBUG
1014 // We later check whether PendingForwardRefs is empty to make sure all
1015 // pending references were linked.
1016 Reader.PendingForwardRefs.erase(D);
1017#endif
1018 }
1019 } else if (DefinitionDecl) {
1020 if (DefinitionDecl->DefinitionData) {
1021 D->DefinitionData = DefinitionDecl->DefinitionData;
1022 } else {
1023 // The definition is still initializing.
1024 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
1025 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001026 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001027}
1028
1029void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1030 VisitRecordDecl(D);
1031
Douglas Gregor7fb09192011-07-21 22:35:25 +00001032 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001033 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1034
Douglas Gregor4163aca2011-09-09 21:34:22 +00001035 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001036
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001037 enum CXXRecKind {
1038 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1039 };
1040 switch ((CXXRecKind)Record[Idx++]) {
1041 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001042 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001043 case CXXRecNotTemplate:
1044 break;
1045 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001046 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001047 break;
1048 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001049 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001050 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001051 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001052 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1053 MSI->setPointOfInstantiation(POI);
1054 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001055 break;
1056 }
1057 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001058
1059 // Load the key function to avoid deserializing every method so we can
1060 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001061 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001062 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001063 C.KeyFunctions[D] = Key;
1064 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001065}
1066
Sebastian Redlb3298c32010-08-18 23:56:48 +00001067void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001068 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001069 unsigned NumOverridenMethods = Record[Idx++];
1070 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001071 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1072 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001073 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001074 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001075 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001076}
1077
Sebastian Redlb3298c32010-08-18 23:56:48 +00001078void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001079 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001080
1081 D->IsExplicitSpecified = Record[Idx++];
1082 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001083 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1084 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001085}
1086
Sebastian Redlb3298c32010-08-18 23:56:48 +00001087void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001088 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001089
1090 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001091 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001092}
1093
Sebastian Redlb3298c32010-08-18 23:56:48 +00001094void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001095 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001096 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001097}
1098
Douglas Gregorba345522011-12-02 23:23:56 +00001099void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1100 VisitDecl(D);
1101 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1102 D->ImportedAndComplete.setInt(Record[Idx++]);
1103 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1104 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1105 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1106 ++Idx;
1107}
1108
Sebastian Redlb3298c32010-08-18 23:56:48 +00001109void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001110 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001111 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001112}
1113
Sebastian Redlb3298c32010-08-18 23:56:48 +00001114void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001115 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001116 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001117 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001118 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001119 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001120 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001121 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001122 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001123}
1124
Sebastian Redlb3298c32010-08-18 23:56:48 +00001125void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001126 VisitDecl(D);
1127 unsigned NumParams = Record[Idx++];
1128 D->NumParams = NumParams;
1129 D->Params = new TemplateParameterList*[NumParams];
1130 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001131 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001132 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001133 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001134 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001135 D->Friend = GetTypeSourceInfo(Record, Idx);
1136 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001137}
1138
Sebastian Redlb3298c32010-08-18 23:56:48 +00001139void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001140 VisitNamedDecl(D);
1141
Douglas Gregor7fb09192011-07-21 22:35:25 +00001142 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001143 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001144 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001145 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001146}
1147
Sebastian Redlb3298c32010-08-18 23:56:48 +00001148void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001149 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1150 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001151
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001152 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001153 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1154 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001155 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1156 // We temporarily set the first (canonical) declaration as the previous one
1157 // which is the one that matters and mark the real previous DeclID to be
1158 // loaded & attached later on.
1159 RedeclarableTemplateDecl *FirstDecl =
1160 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1161 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1162 "FirstDecl kind mismatch");
1163 if (FirstDecl) {
1164 D->CommonOrPrev = FirstDecl;
1165 // Mark the real previous DeclID to be loaded & attached later on.
1166 if (PreviousDeclID != FirstDeclID)
1167 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1168 } else {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001169 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001170 if (RedeclarableTemplateDecl *RTD
Douglas Gregor7fb09192011-07-21 22:35:25 +00001171 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001172 assert(RTD->getKind() == D->getKind() &&
1173 "InstantiatedFromMemberTemplate kind mismatch");
1174 D->setInstantiatedFromMemberTemplateImpl(RTD);
1175 if (Record[Idx++])
1176 D->setMemberSpecialization();
1177 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001178
Douglas Gregor7fb09192011-07-21 22:35:25 +00001179 RedeclarableTemplateDecl *LatestDecl
1180 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001181
1182 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001183 // in the same AST file. However, if this actually needs to point to a
1184 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001185 // the FirstLatestDeclIDs map which tracks this kind of decls.
1186 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001187 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001188 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1189 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregoraa7cbfd2011-08-25 15:28:26 +00001190 if (Decl *NewLatest = Reader.GetDecl(I->second))
1191 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001192 }
1193
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001194 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1195 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001196 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001197
1198 VisitTemplateDecl(D);
1199 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001200}
1201
Sebastian Redlb3298c32010-08-18 23:56:48 +00001202void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001203 VisitRedeclarableTemplateDecl(D);
1204
1205 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001206 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1207 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001208 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001209 SpecIDs.push_back(0);
1210
1211 // Specializations.
1212 unsigned Size = Record[Idx++];
1213 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001214 for (unsigned I = 0; I != Size; ++I)
1215 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001216
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001217 // Partial specializations.
1218 Size = Record[Idx++];
1219 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001220 for (unsigned I = 0; I != Size; ++I)
1221 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001222
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001223 if (SpecIDs[0]) {
1224 typedef serialization::DeclID DeclID;
1225
1226 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1227 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001228 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001229 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1230 SpecIDs.size() * sizeof(DeclID));
1231 }
1232
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001233 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001234 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001235}
1236
Sebastian Redlb3298c32010-08-18 23:56:48 +00001237void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001238 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001239 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001240
Douglas Gregor4163aca2011-09-09 21:34:22 +00001241 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001242 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001243 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001244 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001245 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001246 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001247 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001248 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001249 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1250 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001251 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1252 = new (C) ClassTemplateSpecializationDecl::
1253 SpecializedPartialSpecialization();
1254 PS->PartialSpecialization
1255 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1256 PS->TemplateArgs = ArgList;
1257 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001258 }
1259 }
1260
1261 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001262 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001263 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1264 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1265 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001266 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1267 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001268 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001269 }
1270
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001271 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001272 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001273 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1274 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001275 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001276 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001277
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001278 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001279 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001280 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001281 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1282 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001283 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001284 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001285 }
1286 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001287}
1288
Sebastian Redlb3298c32010-08-18 23:56:48 +00001289void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001290 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001291 VisitClassTemplateSpecializationDecl(D);
1292
Douglas Gregor4163aca2011-09-09 21:34:22 +00001293 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001294 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001295
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001296 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001297 if (NumArgs) {
1298 D->NumArgsAsWritten = NumArgs;
1299 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1300 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001301 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001302 }
1303
1304 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001305
1306 // These are read/set from/to the first declaration.
1307 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001308 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001309 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001310 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001311 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001312}
1313
Sebastian Redlb7448632011-08-31 13:59:56 +00001314void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1315 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001316 VisitDecl(D);
1317 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1318}
1319
Sebastian Redlb3298c32010-08-18 23:56:48 +00001320void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001321 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001322
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001323 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001324 // This FunctionTemplateDecl owns a CommonPtr; read it.
1325
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001326 // Read the function specialization declarations.
1327 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001328 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001329 unsigned NumSpecs = Record[Idx++];
1330 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001331 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001332 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001333}
1334
Sebastian Redlb3298c32010-08-18 23:56:48 +00001335void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001336 VisitTypeDecl(D);
1337
1338 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001339
1340 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001341 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001342 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001343}
1344
Sebastian Redlb3298c32010-08-18 23:56:48 +00001345void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001346 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001347 // TemplateParmPosition.
1348 D->setDepth(Record[Idx++]);
1349 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001350 if (D->isExpandedParameterPack()) {
1351 void **Data = reinterpret_cast<void **>(D + 1);
1352 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001353 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001354 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1355 }
1356 } else {
1357 // Rest of NonTypeTemplateParmDecl.
1358 D->ParameterPack = Record[Idx++];
1359 if (Record[Idx++]) {
1360 Expr *DefArg = Reader.ReadExpr(F);
1361 bool Inherited = Record[Idx++];
1362 D->setDefaultArgument(DefArg, Inherited);
1363 }
1364 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001365}
1366
Sebastian Redlb3298c32010-08-18 23:56:48 +00001367void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001368 VisitTemplateDecl(D);
1369 // TemplateParmPosition.
1370 D->setDepth(Record[Idx++]);
1371 D->setPosition(Record[Idx++]);
1372 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001373 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001374 bool IsInherited = Record[Idx++];
1375 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001376 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001377}
1378
Richard Smith3f1b5d02011-05-05 21:57:07 +00001379void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1380 VisitRedeclarableTemplateDecl(D);
1381}
1382
Sebastian Redlb3298c32010-08-18 23:56:48 +00001383void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001384 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001385 D->AssertExpr = Reader.ReadExpr(F);
1386 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001387 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001388}
1389
Mike Stump11289f42009-09-09 15:08:12 +00001390std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001391ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001392 uint64_t LexicalOffset = Record[Idx++];
1393 uint64_t VisibleOffset = Record[Idx++];
1394 return std::make_pair(LexicalOffset, VisibleOffset);
1395}
1396
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001397template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001398void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001399 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1400 RedeclKind Kind = (RedeclKind)Record[Idx++];
1401 switch (Kind) {
1402 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001403 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1404 " messed up reading");
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001405 case NoRedeclaration:
1406 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001407 case PointsToPrevious: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001408 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1409 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001410 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1411 // We temporarily set the first (canonical) declaration as the previous one
1412 // which is the one that matters and mark the real previous DeclID to be
1413 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001414 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1415 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001416 if (PreviousDeclID != FirstDeclID)
1417 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1418 PreviousDeclID));
Douglas Gregor3e300102011-10-26 17:53:41 +00001419
1420 // If the first declaration in the chain is in an inconsistent
1421 // state where it thinks that it is the only declaration, fix its
1422 // redeclaration link now to point at this declaration, so that we have a
1423 // proper redeclaration chain.
1424 if (FirstDecl->RedeclLink.getPointer() == FirstDecl) {
1425 FirstDecl->RedeclLink
1426 = typename Redeclarable<T>::LatestDeclLink(static_cast<T*>(D));
1427 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001428 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001429 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001430 case PointsToLatest: {
1431 T *LatestDecl = ReadDeclAs<T>(Record, Idx);
1432 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(LatestDecl);
1433
1434 // If the latest declaration in the chain is in an inconsistent
1435 // state where it thinks that it is the only declaration, fix its
1436 // redeclaration link now to point at this declaration, so that we have a
1437 // proper redeclaration chain.
1438 if (LatestDecl->RedeclLink.getPointer() == LatestDecl) {
1439 LatestDecl->RedeclLink
1440 = typename Redeclarable<T>::PreviousDeclLink(static_cast<T*>(D));
1441 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001442 break;
1443 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001444 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001445
1446 assert(!(Kind == PointsToPrevious &&
1447 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1448 Reader.FirstLatestDeclIDs.end()) &&
1449 "This decl is not first, it should not be in the map");
1450 if (Kind == PointsToPrevious)
1451 return;
1452
1453 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001454 // the same AST file. However, if this actually needs to point to a
1455 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001456 // FirstLatestDeclIDs map which tracks this kind of decls.
1457 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1458 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001459 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001460 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1461 if (I != Reader.FirstLatestDeclIDs.end()) {
1462 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001463 D->RedeclLink
1464 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1465 }
1466}
1467
Chris Lattner487412d2009-04-27 05:27:42 +00001468//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001469// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001470//===----------------------------------------------------------------------===//
1471
Chris Lattner8f63ab52009-04-27 06:01:06 +00001472/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001473void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001474 const RecordData &Record, unsigned &Idx) {
1475 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001476 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001477 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001478 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001479
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001480#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001481
1482 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001483 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001484 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001485}
1486
1487//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001488// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001489//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001490
1491/// \brief Note that we have loaded the declaration with the given
1492/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001493///
Chris Lattner487412d2009-04-27 05:27:42 +00001494/// This routine notes that this declaration has already been loaded,
1495/// so that future GetDecl calls will return this declaration rather
1496/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001497inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001498 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1499 DeclsLoaded[Index] = D;
1500}
1501
1502
1503/// \brief Determine whether the consumer will be interested in seeing
1504/// this declaration (via HandleTopLevelDecl).
1505///
1506/// This routine should return true for anything that might affect
1507/// code generation, e.g., inline function definitions, Objective-C
1508/// declarations with metadata, etc.
1509static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001510 // An ObjCMethodDecl is never considered as "interesting" because its
1511 // implementation container always is.
1512
Douglas Gregor87d81242011-09-10 00:22:34 +00001513 if (isa<FileScopeAsmDecl>(D) ||
1514 isa<ObjCProtocolDecl>(D) ||
1515 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001516 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001517 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001518 return Var->isFileVarDecl() &&
1519 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001520 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001521 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001522
1523 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001524}
1525
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001526/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001527ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001528ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001529 // See if there's an override.
1530 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001531 if (It != ReplacedDecls.end()) {
1532 RawLocation = It->second.RawLoc;
1533 return RecordLocation(It->second.Mod, It->second.Offset);
1534 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001535
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001536 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1537 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001538 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001539 const DeclOffset &
1540 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1541 RawLocation = DOffs.Loc;
1542 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001543}
1544
Douglas Gregord32f0352011-07-22 06:10:01 +00001545ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001546 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001547 = GlobalBitOffsetsMap.find(GlobalOffset);
1548
1549 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1550 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1551}
1552
Douglas Gregorde3ef502011-11-30 23:21:26 +00001553uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001554 return LocalOffset + M.GlobalBitOffset;
1555}
1556
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001557void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1558 assert(D && previous);
1559 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1560 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1561 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1562 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1563 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1564 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1565 } else {
1566 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1567 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1568 }
1569}
1570
1571void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1572 Decl *previous = GetDecl(ID);
1573 ASTDeclReader::attachPreviousDecl(D, previous);
1574}
1575
Sebastian Redlb3298c32010-08-18 23:56:48 +00001576/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001577Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001578 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001579 unsigned RawLocation = 0;
1580 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001581 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001582 // Keep track of where we are in the stream, then jump back there
1583 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001584 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001585
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001586 ReadingKindTracker ReadingKind(Read_Decl, *this);
1587
Douglas Gregor1342e842009-07-06 18:54:52 +00001588 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001589 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001590
Sebastian Redl2c373b92010-10-05 15:59:54 +00001591 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001592 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001593 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001594 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001595 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001596
Chris Lattner1de76db2009-04-27 05:58:23 +00001597 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001598 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001599 case DECL_CONTEXT_LEXICAL:
1600 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001601 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001602 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001603 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001604 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001605 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001606 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001607 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001608 0, 0);
1609 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001610 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001611 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001612 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001613 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001614 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001615 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001616 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001617 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001618 0, llvm::APSInt());
1619 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001620 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001621 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001622 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001623 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001624 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001625 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001626 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001627 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001628 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001629 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001630 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001631 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001632 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001633 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001634 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001635 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001636 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001637 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001638 SourceLocation(), 0,
1639 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001640 SourceLocation(), 0);
1641 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001642 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001643 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001644 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1645 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001646 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001647 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001648 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001649 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001650 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001651 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001652 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001653 SourceLocation(), 0, 0);
1654 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001655 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001656 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001657 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001658 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001659 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001660 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001661 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001662 SourceLocation(),
1663 NestedNameSpecifierLoc(),
1664 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001665 DeclarationName());
1666 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001667 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001668 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001669 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001670 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001671 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001672 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001673 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001674 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001675 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001676 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001677 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001678 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001679 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001680 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001681 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001682 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001683 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001684 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001685 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001686 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001687 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001688 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001689 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001690 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001691 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001692 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001693 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001694 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001695 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001696 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001697 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001698 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001699 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001700 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001701 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001702 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001703 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001704 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001705 Decl::EmptyShell());
1706 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001707 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001708 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001709 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001710 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001711 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001712 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001713 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001714 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001715 SourceLocation(), 0, 0, 0, QualType(),
1716 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001717 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001718 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001719 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001720 SourceLocation(), 0, 0, 0, QualType(),
1721 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001722 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001723 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001724 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001725 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001726 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001727 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001728 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001729 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001730 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001731 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001732 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001733 break;
1734
Sebastian Redl539c5062010-08-18 23:57:32 +00001735 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001736 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001737 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001738 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001739 case DECL_OBJC_INTERFACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001740 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001741 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001742 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001743 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001744 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001745 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001746 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001747 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001748 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001749 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001750 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001751 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001752 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001753 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001754 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001755 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001756 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001757 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001758 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001759 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001760 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001761 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001762 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001763 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001764 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +00001765 SourceLocation(), SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001766 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001767 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001768 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1769 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001770 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001771 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001772 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001773 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001774 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001775 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001776 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001777 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001778 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001779 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001780 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001781 ObjCPropertyImplDecl::Dynamic, 0,
1782 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001783 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001784 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001785 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001786 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001787 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001788 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001789 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001790 0, 0);
1791 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001792 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001793 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001794 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001795 break;
1796
Sebastian Redl539c5062010-08-18 23:57:32 +00001797 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001798 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001799 break;
1800
Sebastian Redl539c5062010-08-18 23:57:32 +00001801 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001802 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001803 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001804 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001805 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001806 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001807 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001808 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001809 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001810 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001811 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001812 case DECL_CXX_BASE_SPECIFIERS:
1813 Error("attempt to read a C++ base-specifier record as a declaration");
1814 return 0;
Douglas Gregorba345522011-12-02 23:23:56 +00001815 case DECL_IMPORT:
1816 // Note: last entry of the ImportDecl record is the number of stored source
1817 // locations.
1818 D = ImportDecl::CreateEmpty(Context, Record.back());
1819 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001820 }
Chris Lattner487412d2009-04-27 05:27:42 +00001821
Sebastian Redlb3298c32010-08-18 23:56:48 +00001822 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001823 LoadedDecl(Index, D);
1824 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001825
1826 // If this declaration is also a declaration context, get the
1827 // offsets for its tables of lexical and visible declarations.
1828 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1829 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1830 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001831 if (Offsets.first != 0)
1832 DC->setHasExternalLexicalStorage(true);
1833 if (Offsets.second != 0)
1834 DC->setHasExternalVisibleStorage(true);
1835 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1836 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001837 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001838 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001839
Sebastian Redlf830df42011-04-24 16:27:54 +00001840 // Now add the pending visible updates for this decl context, if it has any.
1841 DeclContextVisibleUpdatesPending::iterator I =
1842 PendingVisibleUpdates.find(ID);
1843 if (I != PendingVisibleUpdates.end()) {
1844 // There are updates. This means the context has external visible
1845 // storage, even if the original stored version didn't.
1846 DC->setHasExternalVisibleStorage(true);
1847 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001848 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1849 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001850 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001851 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001852 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001853 }
1854 }
1855 assert(Idx == Record.size());
1856
Douglas Gregordab42432011-08-12 00:15:20 +00001857 // Load any relevant update records.
1858 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001859
1860 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001861 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001862 PendingChainedObjCCategories.push_back(
1863 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001864
Douglas Gregordab42432011-08-12 00:15:20 +00001865 // If we have deserialized a declaration that has a definition the
1866 // AST consumer might need to know about, queue it.
1867 // We don't pass it to the consumer immediately because we may be in recursive
1868 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001869 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001870 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001871
Douglas Gregordab42432011-08-12 00:15:20 +00001872 return D;
1873}
1874
1875void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001876 // The declaration may have been modified by files later in the chain.
1877 // If this is the case, read the record containing the updates from each file
1878 // and pass it to ASTDeclReader to make the modifications.
1879 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1880 if (UpdI != DeclUpdateOffsets.end()) {
1881 FileOffsetsTy &UpdateOffsets = UpdI->second;
1882 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001883 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001884 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001885 uint64_t Offset = I->second;
1886 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1887 SavedStreamPosition SavedPosition(Cursor);
1888 Cursor.JumpToBit(Offset);
1889 RecordData Record;
1890 unsigned Code = Cursor.ReadCode();
1891 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1892 (void)RecCode;
1893 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001894
1895 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001896 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001897 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001898 }
1899 }
Chris Lattner487412d2009-04-27 05:27:42 +00001900}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001901
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001902namespace {
1903 /// \brief Given an ObjC interface, goes through the modules and links to the
1904 /// interface all the categories for it.
1905 class ObjCChainedCategoriesVisitor {
1906 ASTReader &Reader;
1907 serialization::GlobalDeclID InterfaceID;
1908 ObjCInterfaceDecl *Interface;
1909 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1910 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1911
1912 public:
1913 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1914 serialization::GlobalDeclID InterfaceID,
1915 ObjCInterfaceDecl *Interface)
1916 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1917 GlobHeadCat(0), GlobTailCat(0) { }
1918
Douglas Gregorde3ef502011-11-30 23:21:26 +00001919 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001920 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1921 }
1922
Douglas Gregorde3ef502011-11-30 23:21:26 +00001923 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001924 if (Reader.isDeclIDFromModule(InterfaceID, M))
1925 return true; // We reached the module where the interface originated
1926 // from. Stop traversing the imported modules.
1927
Douglas Gregorde3ef502011-11-30 23:21:26 +00001928 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001929 I = M.ChainedObjCCategories.find(InterfaceID);
1930 if (I == M.ChainedObjCCategories.end())
1931 return false;
1932
1933 ObjCCategoryDecl *
1934 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1935 ObjCCategoryDecl *
1936 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1937
1938 addCategories(HeadCat, TailCat);
1939 return false;
1940 }
1941
1942 void addCategories(ObjCCategoryDecl *HeadCat,
1943 ObjCCategoryDecl *TailCat = 0) {
1944 if (!HeadCat) {
1945 assert(!TailCat);
1946 return;
1947 }
1948
1949 if (!TailCat) {
1950 TailCat = HeadCat;
1951 while (TailCat->getNextClassCategory())
1952 TailCat = TailCat->getNextClassCategory();
1953 }
1954
1955 if (!GlobHeadCat) {
1956 GlobHeadCat = HeadCat;
1957 GlobTailCat = TailCat;
1958 } else {
1959 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1960 GlobTailCat = TailCat;
1961 }
1962
1963 llvm::DenseSet<DeclarationName> Checked;
1964 for (ObjCCategoryDecl *Cat = HeadCat,
1965 *CatEnd = TailCat->getNextClassCategory();
1966 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1967 if (Checked.count(Cat->getDeclName()))
1968 continue;
1969 Checked.insert(Cat->getDeclName());
1970 checkForDuplicate(Cat);
1971 }
1972 }
1973
1974 /// \brief Warns for duplicate categories that come from different modules.
1975 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1976 DeclarationName Name = Cat->getDeclName();
1977 // Find the top category with the same name. We do not want to warn for
1978 // duplicates along the established chain because there were already
1979 // warnings for them when the module was created. We only want to warn for
1980 // duplicates between non-dependent modules:
1981 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001982 // MT //
1983 // / \ //
1984 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001985 //
1986 // We want to warn for duplicates between ML and MR,not between ML and MT.
1987 //
1988 // FIXME: We should not warn for duplicates in diamond:
1989 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001990 // MT //
1991 // / \ //
1992 // ML MR //
1993 // \ / //
1994 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001995 //
1996 // If there are duplicates in ML/MR, there will be warning when creating
1997 // MB *and* when importing MB. We should not warn when importing.
1998 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1999 Next = Next->getNextClassCategory()) {
2000 if (Next->getDeclName() == Name)
2001 Cat = Next;
2002 }
2003
2004 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2005 if (!PrevCat)
2006 PrevCat = Cat;
2007
2008 if (PrevCat != Cat) {
2009 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2010 << Interface->getDeclName() << Name;
2011 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2012 }
2013 }
2014
2015 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2016 };
2017}
2018
2019void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2020 ObjCInterfaceDecl *D) {
2021 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2022 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2023 // Also add the categories that the interface already links to.
2024 Visitor.addCategories(D->getCategoryList());
2025 D->setCategoryList(Visitor.getHeadCategory());
2026}
Douglas Gregordab42432011-08-12 00:15:20 +00002027
Douglas Gregorde3ef502011-11-30 23:21:26 +00002028void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002029 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002030 unsigned Idx = 0;
2031 while (Idx < Record.size()) {
2032 switch ((DeclUpdateKind)Record[Idx++]) {
2033 case UPD_CXX_SET_DEFINITIONDATA: {
2034 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00002035 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00002036 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002037 assert(!RD->DefinitionData && "DefinitionData is already set!");
2038 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2039 break;
2040 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002041
2042 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00002043 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002044 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00002045
2046 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2047 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002048 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002049 break;
2050
2051 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00002052 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00002053 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00002054 // Guard against these being loaded out of original order. Don't use
2055 // getNextNamespace(), since it tries to access the context and can't in
2056 // the middle of deserialization.
2057 if (!Anon->NextNamespace) {
2058 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2059 TU->setAnonymousNamespace(Anon);
2060 else
2061 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2062 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002063 break;
2064 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002065
2066 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2067 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002068 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002069 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002070 }
2071 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002072}