blob: 12b61b0cdd87110dacd9bf4b4b5b2eccf6a88593 [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) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000557 VisitRedeclarable(ID);
Chris Lattner487412d2009-04-27 05:27:42 +0000558 VisitObjCContainerDecl(ID);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000559 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000560
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000561 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
562 if (ID == Def) {
563 // Read the definition.
564 ID->allocateDefinitionData();
565
566 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
567
568 // Read the superclass.
569 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
570 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
571
572 // Read the directly referenced protocols and their SourceLocations.
573 unsigned NumProtocols = Record[Idx++];
574 SmallVector<ObjCProtocolDecl *, 16> Protocols;
575 Protocols.reserve(NumProtocols);
576 for (unsigned I = 0; I != NumProtocols; ++I)
577 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
578 SmallVector<SourceLocation, 16> ProtoLocs;
579 ProtoLocs.reserve(NumProtocols);
580 for (unsigned I = 0; I != NumProtocols; ++I)
581 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
582 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
583 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000584
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000585 // Read the transitive closure of protocols referenced by this class.
586 NumProtocols = Record[Idx++];
587 Protocols.clear();
588 Protocols.reserve(NumProtocols);
589 for (unsigned I = 0; I != NumProtocols; ++I)
590 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
591 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
592 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000593
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000594 // Read the ivars.
595 unsigned NumIvars = Record[Idx++];
596 SmallVector<ObjCIvarDecl *, 16> IVars;
597 IVars.reserve(NumIvars);
598 for (unsigned I = 0; I != NumIvars; ++I)
599 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
600
601 // Read the categories.
602 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000603
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000604 // We will rebuild this list lazily.
605 ID->setIvarList(0);
606
607 // If there are any pending forward references, make their definition data
608 // pointers point at the newly-allocated data.
609 ASTReader::PendingForwardRefsMap::iterator
610 FindI = Reader.PendingForwardRefs.find(ID);
611 if (FindI != Reader.PendingForwardRefs.end()) {
612 ASTReader::ForwardRefs &Refs = FindI->second;
613 for (ASTReader::ForwardRefs::iterator I = Refs.begin(),
614 E = Refs.end();
615 I != E; ++I)
Douglas Gregora323c4c2011-12-15 18:17:27 +0000616 cast<ObjCInterfaceDecl>(*I)->Data = ID->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000617#ifndef NDEBUG
618 // We later check whether PendingForwardRefs is empty to make sure all
619 // pending references were linked.
620 Reader.PendingForwardRefs.erase(ID);
621#endif
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000622 } else if (Def) {
Douglas Gregora323c4c2011-12-15 18:17:27 +0000623 if (Def->Data) {
624 ID->Data = Def->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000625 } else {
626 // The definition is still initializing.
627 Reader.PendingForwardRefs[Def].push_back(ID);
628 }
629 }
630 }
631
Sebastian Redl2c373b92010-10-05 15:59:54 +0000632 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000633}
634
Sebastian Redlb3298c32010-08-18 23:56:48 +0000635void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000636 VisitFieldDecl(IVD);
637 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000638 // This field will be built lazily.
639 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000640 bool synth = Record[Idx++];
641 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000642}
643
Sebastian Redlb3298c32010-08-18 23:56:48 +0000644void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000645 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000646 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000647 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000648 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000649 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000650 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000651 ProtoRefs.reserve(NumProtoRefs);
652 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000653 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000654 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000655 ProtoLocs.reserve(NumProtoRefs);
656 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000657 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000658 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000659 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000660}
661
Sebastian Redlb3298c32010-08-18 23:56:48 +0000662void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000663 VisitFieldDecl(FD);
664}
665
Sebastian Redlb3298c32010-08-18 23:56:48 +0000666void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000667 VisitDecl(CD);
Douglas Gregor40d009f2011-12-14 17:12:03 +0000668 CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
669 CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000670}
671
Sebastian Redlb3298c32010-08-18 23:56:48 +0000672void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000673 VisitDecl(FPD);
674 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000675 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000676 ProtoRefs.reserve(NumProtoRefs);
677 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000678 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000679 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000680 ProtoLocs.reserve(NumProtoRefs);
681 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000682 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000683 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000684 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000685}
686
Sebastian Redlb3298c32010-08-18 23:56:48 +0000687void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000688 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000689 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000690 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000691 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000692 ProtoRefs.reserve(NumProtoRefs);
693 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000694 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000695 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000696 ProtoLocs.reserve(NumProtoRefs);
697 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000698 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000699 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000700 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000701 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000702 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000703 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000704}
705
Sebastian Redlb3298c32010-08-18 23:56:48 +0000706void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000707 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000708 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000709}
710
Sebastian Redlb3298c32010-08-18 23:56:48 +0000711void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000712 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000713 D->setAtLoc(ReadSourceLocation(Record, Idx));
714 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000715 // FIXME: stable encoding
716 D->setPropertyAttributes(
717 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000718 D->setPropertyAttributesAsWritten(
719 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000720 // FIXME: stable encoding
721 D->setPropertyImplementation(
722 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000723 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
724 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000725 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
726 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
727 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000728}
729
Sebastian Redlb3298c32010-08-18 23:56:48 +0000730void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000731 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000732 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000733}
734
Sebastian Redlb3298c32010-08-18 23:56:48 +0000735void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000736 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000737 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000738 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000739}
740
Sebastian Redlb3298c32010-08-18 23:56:48 +0000741void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000742 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000743 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000744 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000745 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000746 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000747}
748
749
Sebastian Redlb3298c32010-08-18 23:56:48 +0000750void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000751 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000752 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000753 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
754 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000755 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000756 D->setGetterCXXConstructor(Reader.ReadExpr(F));
757 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000758}
759
Sebastian Redlb3298c32010-08-18 23:56:48 +0000760void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000761 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000762 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000763 int BitWidthOrInitializer = Record[Idx++];
764 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000765 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000766 else if (BitWidthOrInitializer == 2)
767 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000768 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000769 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000770 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000771 }
Chris Lattner487412d2009-04-27 05:27:42 +0000772}
773
Francois Pichet783dd6e2010-11-21 06:08:52 +0000774void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
775 VisitValueDecl(FD);
776
777 FD->ChainingSize = Record[Idx++];
778 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000779 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000780
781 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000782 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000783}
784
Sebastian Redlb3298c32010-08-18 23:56:48 +0000785void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000786 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000787 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000788 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
789 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
790 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
791 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
792 VD->VarDeclBits.ExceptionVar = Record[Idx++];
793 VD->VarDeclBits.NRVOVariable = Record[Idx++];
794 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000795 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000796 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000797 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000798
799 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000800 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000801 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000802 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000803 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000804 }
Chris Lattner487412d2009-04-27 05:27:42 +0000805}
806
Sebastian Redlb3298c32010-08-18 23:56:48 +0000807void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000808 VisitVarDecl(PD);
809}
810
Sebastian Redlb3298c32010-08-18 23:56:48 +0000811void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000812 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000813 unsigned isObjCMethodParam = Record[Idx++];
814 unsigned scopeDepth = Record[Idx++];
815 unsigned scopeIndex = Record[Idx++];
816 unsigned declQualifier = Record[Idx++];
817 if (isObjCMethodParam) {
818 assert(scopeDepth == 0);
819 PD->setObjCMethodScopeInfo(scopeIndex);
820 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
821 } else {
822 PD->setScopeInfo(scopeDepth, scopeIndex);
823 }
John McCallbeaa11c2011-05-01 02:13:58 +0000824 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
825 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000826 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000827 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000828}
829
Sebastian Redlb3298c32010-08-18 23:56:48 +0000830void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000831 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000832 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000833 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000834}
835
Sebastian Redlb3298c32010-08-18 23:56:48 +0000836void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000837 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000838 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
839 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000840 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000841 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000842 Params.reserve(NumParams);
843 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000844 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000845 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000846
847 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000848 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000849 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000850 captures.reserve(numCaptures);
851 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000852 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000853 unsigned flags = Record[Idx++];
854 bool byRef = (flags & 1);
855 bool nested = (flags & 2);
856 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
857
858 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
859 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000860 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000861 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000862}
863
Sebastian Redlb3298c32010-08-18 23:56:48 +0000864void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000865 VisitDecl(D);
866 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000867 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000868 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000869}
870
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000871void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
872 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000873 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000874}
875
876
Sebastian Redlb3298c32010-08-18 23:56:48 +0000877void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000878 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000879 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000880 D->LocStart = ReadSourceLocation(Record, Idx);
881 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000882 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000883
Chris Lattnerca025db2010-05-07 21:43:38 +0000884 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000885 // FIXME: Modules will likely have trouble with pointing directly at
886 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000887 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000888 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000889}
890
Sebastian Redlb3298c32010-08-18 23:56:48 +0000891void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000892 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000893 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000894 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000895 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000896 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000897}
898
Sebastian Redlb3298c32010-08-18 23:56:48 +0000899void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000900 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000901 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000902 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000903 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000904 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000905 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000906 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000907 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000908}
909
Sebastian Redlb3298c32010-08-18 23:56:48 +0000910void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000911 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000912 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
913 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
914 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000915 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000916 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000917}
918
Sebastian Redlb3298c32010-08-18 23:56:48 +0000919void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000920 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000921 D->UsingLoc = ReadSourceLocation(Record, Idx);
922 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000923 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000924 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
925 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000926}
927
Sebastian Redlb3298c32010-08-18 23:56:48 +0000928void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000929 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000930 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000931 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000932 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000933}
934
Sebastian Redlb3298c32010-08-18 23:56:48 +0000935void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000936 UnresolvedUsingTypenameDecl *D) {
937 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000938 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000939 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000940}
941
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000942void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000943 struct CXXRecordDecl::DefinitionData &Data,
944 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000945 Data.UserDeclaredConstructor = Record[Idx++];
946 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000947 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000948 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000949 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000950 Data.UserDeclaredDestructor = Record[Idx++];
951 Data.Aggregate = Record[Idx++];
952 Data.PlainOldData = Record[Idx++];
953 Data.Empty = Record[Idx++];
954 Data.Polymorphic = Record[Idx++];
955 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000956 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000957 Data.HasNoNonEmptyBases = Record[Idx++];
958 Data.HasPrivateFields = Record[Idx++];
959 Data.HasProtectedFields = Record[Idx++];
960 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000961 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000962 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000963 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000964 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000965 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000966 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000967 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000968 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000969 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000970 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000971 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000972 Data.DeclaredDefaultConstructor = Record[Idx++];
973 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000974 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000975 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000976 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000977 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000978 Data.FailedImplicitMoveConstructor = Record[Idx++];
979 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000980
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000981 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000982 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000983 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000984 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000985 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000986 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000987
Douglas Gregor7fb09192011-07-21 22:35:25 +0000988 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
989 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000990 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +0000991 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000992}
993
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000994void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
995 CXXRecordDecl *DefinitionDecl,
996 const RecordData &Record,
997 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +0000998 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000999
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001000 if (D == DefinitionDecl) {
1001 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001002 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001003 // We read the definition info. Check if there are pending forward
1004 // references that need to point to this DefinitionData pointer.
1005 ASTReader::PendingForwardRefsMap::iterator
1006 FindI = Reader.PendingForwardRefs.find(D);
1007 if (FindI != Reader.PendingForwardRefs.end()) {
1008 ASTReader::ForwardRefs &Refs = FindI->second;
1009 for (ASTReader::ForwardRefs::iterator
1010 I = Refs.begin(), E = Refs.end(); I != E; ++I)
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001011 cast<CXXRecordDecl>(*I)->DefinitionData = D->DefinitionData;
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001012#ifndef NDEBUG
1013 // We later check whether PendingForwardRefs is empty to make sure all
1014 // pending references were linked.
1015 Reader.PendingForwardRefs.erase(D);
1016#endif
1017 }
1018 } else if (DefinitionDecl) {
1019 if (DefinitionDecl->DefinitionData) {
1020 D->DefinitionData = DefinitionDecl->DefinitionData;
1021 } else {
1022 // The definition is still initializing.
1023 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
1024 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001025 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001026}
1027
1028void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1029 VisitRecordDecl(D);
1030
Douglas Gregor7fb09192011-07-21 22:35:25 +00001031 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001032 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1033
Douglas Gregor4163aca2011-09-09 21:34:22 +00001034 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001035
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001036 enum CXXRecKind {
1037 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1038 };
1039 switch ((CXXRecKind)Record[Idx++]) {
1040 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001041 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001042 case CXXRecNotTemplate:
1043 break;
1044 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001045 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001046 break;
1047 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001048 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001049 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001050 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001051 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1052 MSI->setPointOfInstantiation(POI);
1053 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001054 break;
1055 }
1056 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001057
1058 // Load the key function to avoid deserializing every method so we can
1059 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001060 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001061 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001062 C.KeyFunctions[D] = Key;
1063 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001064}
1065
Sebastian Redlb3298c32010-08-18 23:56:48 +00001066void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001067 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001068 unsigned NumOverridenMethods = Record[Idx++];
1069 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001070 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1071 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001072 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001073 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001074 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001075}
1076
Sebastian Redlb3298c32010-08-18 23:56:48 +00001077void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001078 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001079
1080 D->IsExplicitSpecified = Record[Idx++];
1081 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001082 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1083 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001084}
1085
Sebastian Redlb3298c32010-08-18 23:56:48 +00001086void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001087 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001088
1089 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001090 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001091}
1092
Sebastian Redlb3298c32010-08-18 23:56:48 +00001093void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001094 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001095 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001096}
1097
Douglas Gregorba345522011-12-02 23:23:56 +00001098void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1099 VisitDecl(D);
1100 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1101 D->ImportedAndComplete.setInt(Record[Idx++]);
1102 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1103 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1104 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1105 ++Idx;
1106}
1107
Sebastian Redlb3298c32010-08-18 23:56:48 +00001108void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001109 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001110 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001111}
1112
Sebastian Redlb3298c32010-08-18 23:56:48 +00001113void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001114 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001115 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001116 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001117 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001118 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001119 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001120 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001121 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001122}
1123
Sebastian Redlb3298c32010-08-18 23:56:48 +00001124void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001125 VisitDecl(D);
1126 unsigned NumParams = Record[Idx++];
1127 D->NumParams = NumParams;
1128 D->Params = new TemplateParameterList*[NumParams];
1129 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001130 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001131 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001132 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001133 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001134 D->Friend = GetTypeSourceInfo(Record, Idx);
1135 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001136}
1137
Sebastian Redlb3298c32010-08-18 23:56:48 +00001138void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001139 VisitNamedDecl(D);
1140
Douglas Gregor7fb09192011-07-21 22:35:25 +00001141 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001142 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001143 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001144 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001145}
1146
Sebastian Redlb3298c32010-08-18 23:56:48 +00001147void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001148 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1149 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001150
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001151 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001152 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1153 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001154 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1155 // We temporarily set the first (canonical) declaration as the previous one
1156 // which is the one that matters and mark the real previous DeclID to be
1157 // loaded & attached later on.
1158 RedeclarableTemplateDecl *FirstDecl =
1159 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1160 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1161 "FirstDecl kind mismatch");
1162 if (FirstDecl) {
1163 D->CommonOrPrev = FirstDecl;
1164 // Mark the real previous DeclID to be loaded & attached later on.
1165 if (PreviousDeclID != FirstDeclID)
1166 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1167 } else {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001168 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001169 if (RedeclarableTemplateDecl *RTD
Douglas Gregor7fb09192011-07-21 22:35:25 +00001170 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001171 assert(RTD->getKind() == D->getKind() &&
1172 "InstantiatedFromMemberTemplate kind mismatch");
1173 D->setInstantiatedFromMemberTemplateImpl(RTD);
1174 if (Record[Idx++])
1175 D->setMemberSpecialization();
1176 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001177
Douglas Gregor7fb09192011-07-21 22:35:25 +00001178 RedeclarableTemplateDecl *LatestDecl
1179 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001180
1181 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001182 // in the same AST file. However, if this actually needs to point to a
1183 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001184 // the FirstLatestDeclIDs map which tracks this kind of decls.
1185 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001186 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001187 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1188 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregoraa7cbfd2011-08-25 15:28:26 +00001189 if (Decl *NewLatest = Reader.GetDecl(I->second))
1190 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001191 }
1192
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001193 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1194 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001195 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001196
1197 VisitTemplateDecl(D);
1198 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001199}
1200
Sebastian Redlb3298c32010-08-18 23:56:48 +00001201void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001202 VisitRedeclarableTemplateDecl(D);
1203
1204 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001205 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1206 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001207 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001208 SpecIDs.push_back(0);
1209
1210 // Specializations.
1211 unsigned Size = Record[Idx++];
1212 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001213 for (unsigned I = 0; I != Size; ++I)
1214 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001215
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001216 // Partial specializations.
1217 Size = Record[Idx++];
1218 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001219 for (unsigned I = 0; I != Size; ++I)
1220 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001221
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001222 if (SpecIDs[0]) {
1223 typedef serialization::DeclID DeclID;
1224
1225 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1226 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001227 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001228 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1229 SpecIDs.size() * sizeof(DeclID));
1230 }
1231
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001232 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001233 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001234}
1235
Sebastian Redlb3298c32010-08-18 23:56:48 +00001236void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001237 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001238 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001239
Douglas Gregor4163aca2011-09-09 21:34:22 +00001240 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001241 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001242 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001243 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001244 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001245 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001246 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001247 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001248 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1249 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001250 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1251 = new (C) ClassTemplateSpecializationDecl::
1252 SpecializedPartialSpecialization();
1253 PS->PartialSpecialization
1254 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1255 PS->TemplateArgs = ArgList;
1256 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001257 }
1258 }
1259
1260 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001261 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001262 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1263 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1264 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001265 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1266 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001267 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001268 }
1269
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001270 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001271 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001272 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1273 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001274 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001275 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001276
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001277 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001278 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001279 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001280 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1281 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001282 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001283 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001284 }
1285 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001286}
1287
Sebastian Redlb3298c32010-08-18 23:56:48 +00001288void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001289 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001290 VisitClassTemplateSpecializationDecl(D);
1291
Douglas Gregor4163aca2011-09-09 21:34:22 +00001292 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001293 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001294
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001295 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001296 if (NumArgs) {
1297 D->NumArgsAsWritten = NumArgs;
1298 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1299 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001300 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001301 }
1302
1303 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001304
1305 // These are read/set from/to the first declaration.
1306 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001307 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001308 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001309 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001310 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001311}
1312
Sebastian Redlb7448632011-08-31 13:59:56 +00001313void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1314 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001315 VisitDecl(D);
1316 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1317}
1318
Sebastian Redlb3298c32010-08-18 23:56:48 +00001319void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001320 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001321
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001322 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001323 // This FunctionTemplateDecl owns a CommonPtr; read it.
1324
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001325 // Read the function specialization declarations.
1326 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001327 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001328 unsigned NumSpecs = Record[Idx++];
1329 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001330 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001331 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001332}
1333
Sebastian Redlb3298c32010-08-18 23:56:48 +00001334void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001335 VisitTypeDecl(D);
1336
1337 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001338
1339 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001340 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001341 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001342}
1343
Sebastian Redlb3298c32010-08-18 23:56:48 +00001344void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001345 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001346 // TemplateParmPosition.
1347 D->setDepth(Record[Idx++]);
1348 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001349 if (D->isExpandedParameterPack()) {
1350 void **Data = reinterpret_cast<void **>(D + 1);
1351 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001352 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001353 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1354 }
1355 } else {
1356 // Rest of NonTypeTemplateParmDecl.
1357 D->ParameterPack = Record[Idx++];
1358 if (Record[Idx++]) {
1359 Expr *DefArg = Reader.ReadExpr(F);
1360 bool Inherited = Record[Idx++];
1361 D->setDefaultArgument(DefArg, Inherited);
1362 }
1363 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001364}
1365
Sebastian Redlb3298c32010-08-18 23:56:48 +00001366void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001367 VisitTemplateDecl(D);
1368 // TemplateParmPosition.
1369 D->setDepth(Record[Idx++]);
1370 D->setPosition(Record[Idx++]);
1371 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001372 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001373 bool IsInherited = Record[Idx++];
1374 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001375 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001376}
1377
Richard Smith3f1b5d02011-05-05 21:57:07 +00001378void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1379 VisitRedeclarableTemplateDecl(D);
1380}
1381
Sebastian Redlb3298c32010-08-18 23:56:48 +00001382void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001383 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001384 D->AssertExpr = Reader.ReadExpr(F);
1385 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001386 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001387}
1388
Mike Stump11289f42009-09-09 15:08:12 +00001389std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001390ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001391 uint64_t LexicalOffset = Record[Idx++];
1392 uint64_t VisibleOffset = Record[Idx++];
1393 return std::make_pair(LexicalOffset, VisibleOffset);
1394}
1395
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001396template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001397void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001398 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1399 RedeclKind Kind = (RedeclKind)Record[Idx++];
1400 switch (Kind) {
1401 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001402 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1403 " messed up reading");
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001404 case NoRedeclaration:
1405 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001406 case PointsToPrevious: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001407 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1408 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001409 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1410 // We temporarily set the first (canonical) declaration as the previous one
1411 // which is the one that matters and mark the real previous DeclID to be
1412 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001413 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1414 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001415 if (PreviousDeclID != FirstDeclID)
1416 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1417 PreviousDeclID));
Douglas Gregor3e300102011-10-26 17:53:41 +00001418
1419 // If the first declaration in the chain is in an inconsistent
1420 // state where it thinks that it is the only declaration, fix its
1421 // redeclaration link now to point at this declaration, so that we have a
1422 // proper redeclaration chain.
1423 if (FirstDecl->RedeclLink.getPointer() == FirstDecl) {
1424 FirstDecl->RedeclLink
1425 = typename Redeclarable<T>::LatestDeclLink(static_cast<T*>(D));
1426 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001427 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001428 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001429 case PointsToLatest: {
1430 T *LatestDecl = ReadDeclAs<T>(Record, Idx);
1431 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(LatestDecl);
1432
1433 // If the latest declaration in the chain is in an inconsistent
1434 // state where it thinks that it is the only declaration, fix its
1435 // redeclaration link now to point at this declaration, so that we have a
1436 // proper redeclaration chain.
1437 if (LatestDecl->RedeclLink.getPointer() == LatestDecl) {
1438 LatestDecl->RedeclLink
1439 = typename Redeclarable<T>::PreviousDeclLink(static_cast<T*>(D));
1440 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001441 break;
1442 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001443 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001444
1445 assert(!(Kind == PointsToPrevious &&
1446 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1447 Reader.FirstLatestDeclIDs.end()) &&
1448 "This decl is not first, it should not be in the map");
1449 if (Kind == PointsToPrevious)
1450 return;
1451
1452 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001453 // the same AST file. However, if this actually needs to point to a
1454 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001455 // FirstLatestDeclIDs map which tracks this kind of decls.
1456 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1457 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001458 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001459 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1460 if (I != Reader.FirstLatestDeclIDs.end()) {
1461 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001462 D->RedeclLink
1463 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1464 }
1465}
1466
Chris Lattner487412d2009-04-27 05:27:42 +00001467//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001468// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001469//===----------------------------------------------------------------------===//
1470
Chris Lattner8f63ab52009-04-27 06:01:06 +00001471/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001472void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001473 const RecordData &Record, unsigned &Idx) {
1474 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001475 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001476 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001477 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001478
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001479#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001480
1481 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001482 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001483 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001484}
1485
1486//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001487// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001488//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001489
1490/// \brief Note that we have loaded the declaration with the given
1491/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001492///
Chris Lattner487412d2009-04-27 05:27:42 +00001493/// This routine notes that this declaration has already been loaded,
1494/// so that future GetDecl calls will return this declaration rather
1495/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001496inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001497 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1498 DeclsLoaded[Index] = D;
1499}
1500
1501
1502/// \brief Determine whether the consumer will be interested in seeing
1503/// this declaration (via HandleTopLevelDecl).
1504///
1505/// This routine should return true for anything that might affect
1506/// code generation, e.g., inline function definitions, Objective-C
1507/// declarations with metadata, etc.
1508static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001509 // An ObjCMethodDecl is never considered as "interesting" because its
1510 // implementation container always is.
1511
Douglas Gregor87d81242011-09-10 00:22:34 +00001512 if (isa<FileScopeAsmDecl>(D) ||
1513 isa<ObjCProtocolDecl>(D) ||
1514 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001515 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001516 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001517 return Var->isFileVarDecl() &&
1518 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001519 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001520 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001521
1522 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001523}
1524
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001525/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001526ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001527ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001528 // See if there's an override.
1529 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001530 if (It != ReplacedDecls.end()) {
1531 RawLocation = It->second.RawLoc;
1532 return RecordLocation(It->second.Mod, It->second.Offset);
1533 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001534
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001535 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1536 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001537 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001538 const DeclOffset &
1539 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1540 RawLocation = DOffs.Loc;
1541 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001542}
1543
Douglas Gregord32f0352011-07-22 06:10:01 +00001544ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001545 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001546 = GlobalBitOffsetsMap.find(GlobalOffset);
1547
1548 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1549 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1550}
1551
Douglas Gregorde3ef502011-11-30 23:21:26 +00001552uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001553 return LocalOffset + M.GlobalBitOffset;
1554}
1555
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001556void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1557 assert(D && previous);
1558 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1559 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1560 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1561 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1562 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1563 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1564 } else {
1565 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1566 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1567 }
1568}
1569
1570void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1571 Decl *previous = GetDecl(ID);
1572 ASTDeclReader::attachPreviousDecl(D, previous);
1573}
1574
Sebastian Redlb3298c32010-08-18 23:56:48 +00001575/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001576Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001577 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001578 unsigned RawLocation = 0;
1579 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001580 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001581 // Keep track of where we are in the stream, then jump back there
1582 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001583 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001584
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001585 ReadingKindTracker ReadingKind(Read_Decl, *this);
1586
Douglas Gregor1342e842009-07-06 18:54:52 +00001587 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001588 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001589
Sebastian Redl2c373b92010-10-05 15:59:54 +00001590 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001591 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001592 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001593 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001594 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001595
Chris Lattner1de76db2009-04-27 05:58:23 +00001596 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001597 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001598 case DECL_CONTEXT_LEXICAL:
1599 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001600 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001601 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001602 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001603 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001604 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001605 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001606 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001607 0, 0);
1608 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001609 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001610 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001611 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001612 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001613 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001614 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001615 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001616 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001617 0, llvm::APSInt());
1618 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001619 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001620 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001621 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001622 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001623 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001624 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001625 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001626 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001627 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001628 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001629 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001630 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001631 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001632 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001633 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001634 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001635 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001636 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001637 SourceLocation(), 0,
1638 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001639 SourceLocation(), 0);
1640 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001641 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001642 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001643 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1644 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001645 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001646 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001647 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001648 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001649 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001650 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001651 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001652 SourceLocation(), 0, 0);
1653 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001654 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001655 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001656 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001657 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001658 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001659 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001660 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001661 SourceLocation(),
1662 NestedNameSpecifierLoc(),
1663 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001664 DeclarationName());
1665 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001666 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001667 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001668 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001669 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001670 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001671 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001672 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001673 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001674 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001675 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001676 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001677 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001678 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001679 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001680 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001681 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001682 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001683 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001684 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001685 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001686 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001687 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001688 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001689 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001690 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001691 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001692 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001693 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001694 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001695 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001696 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001697 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001698 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001699 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001700 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001701 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001702 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001703 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001704 Decl::EmptyShell());
1705 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001706 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001707 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001708 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001709 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001710 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001711 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001712 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001713 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001714 SourceLocation(), 0, 0, 0, QualType(),
1715 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001716 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001717 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001718 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001719 SourceLocation(), 0, 0, 0, QualType(),
1720 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001721 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001722 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001723 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001724 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001725 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001726 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001727 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001728 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001729 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001730 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001731 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001732 break;
1733
Sebastian Redl539c5062010-08-18 23:57:32 +00001734 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001735 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001736 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001737 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001738 case DECL_OBJC_INTERFACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001739 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001740 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001741 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001742 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001743 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001744 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001745 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001746 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001747 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001748 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001749 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001750 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001751 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001752 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001753 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001754 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001755 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001756 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001757 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001758 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001759 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001760 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001761 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001762 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001763 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +00001764 SourceLocation(), SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001765 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001766 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001767 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1768 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001769 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001770 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001771 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001772 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001773 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001774 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001775 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001776 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001777 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001778 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001779 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001780 ObjCPropertyImplDecl::Dynamic, 0,
1781 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001782 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001783 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001784 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001785 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001786 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001787 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001788 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001789 0, 0);
1790 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001791 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001792 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001793 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001794 break;
1795
Sebastian Redl539c5062010-08-18 23:57:32 +00001796 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001797 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001798 break;
1799
Sebastian Redl539c5062010-08-18 23:57:32 +00001800 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001801 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001802 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001803 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001804 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001805 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001806 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001807 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001808 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001809 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001810 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001811 case DECL_CXX_BASE_SPECIFIERS:
1812 Error("attempt to read a C++ base-specifier record as a declaration");
1813 return 0;
Douglas Gregorba345522011-12-02 23:23:56 +00001814 case DECL_IMPORT:
1815 // Note: last entry of the ImportDecl record is the number of stored source
1816 // locations.
1817 D = ImportDecl::CreateEmpty(Context, Record.back());
1818 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001819 }
Chris Lattner487412d2009-04-27 05:27:42 +00001820
Sebastian Redlb3298c32010-08-18 23:56:48 +00001821 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001822 LoadedDecl(Index, D);
1823 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001824
1825 // If this declaration is also a declaration context, get the
1826 // offsets for its tables of lexical and visible declarations.
1827 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1828 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1829 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001830 if (Offsets.first != 0)
1831 DC->setHasExternalLexicalStorage(true);
1832 if (Offsets.second != 0)
1833 DC->setHasExternalVisibleStorage(true);
1834 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1835 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001836 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001837 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001838
Sebastian Redlf830df42011-04-24 16:27:54 +00001839 // Now add the pending visible updates for this decl context, if it has any.
1840 DeclContextVisibleUpdatesPending::iterator I =
1841 PendingVisibleUpdates.find(ID);
1842 if (I != PendingVisibleUpdates.end()) {
1843 // There are updates. This means the context has external visible
1844 // storage, even if the original stored version didn't.
1845 DC->setHasExternalVisibleStorage(true);
1846 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001847 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1848 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001849 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001850 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001851 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001852 }
1853 }
1854 assert(Idx == Record.size());
1855
Douglas Gregordab42432011-08-12 00:15:20 +00001856 // Load any relevant update records.
1857 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001858
1859 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001860 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001861 PendingChainedObjCCategories.push_back(
1862 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001863
Douglas Gregordab42432011-08-12 00:15:20 +00001864 // If we have deserialized a declaration that has a definition the
1865 // AST consumer might need to know about, queue it.
1866 // We don't pass it to the consumer immediately because we may be in recursive
1867 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001868 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001869 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001870
Douglas Gregordab42432011-08-12 00:15:20 +00001871 return D;
1872}
1873
1874void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001875 // The declaration may have been modified by files later in the chain.
1876 // If this is the case, read the record containing the updates from each file
1877 // and pass it to ASTDeclReader to make the modifications.
1878 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1879 if (UpdI != DeclUpdateOffsets.end()) {
1880 FileOffsetsTy &UpdateOffsets = UpdI->second;
1881 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001882 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001883 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001884 uint64_t Offset = I->second;
1885 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1886 SavedStreamPosition SavedPosition(Cursor);
1887 Cursor.JumpToBit(Offset);
1888 RecordData Record;
1889 unsigned Code = Cursor.ReadCode();
1890 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1891 (void)RecCode;
1892 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001893
1894 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001895 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001896 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001897 }
1898 }
Chris Lattner487412d2009-04-27 05:27:42 +00001899}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001900
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001901namespace {
1902 /// \brief Given an ObjC interface, goes through the modules and links to the
1903 /// interface all the categories for it.
1904 class ObjCChainedCategoriesVisitor {
1905 ASTReader &Reader;
1906 serialization::GlobalDeclID InterfaceID;
1907 ObjCInterfaceDecl *Interface;
1908 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1909 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1910
1911 public:
1912 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1913 serialization::GlobalDeclID InterfaceID,
1914 ObjCInterfaceDecl *Interface)
1915 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1916 GlobHeadCat(0), GlobTailCat(0) { }
1917
Douglas Gregorde3ef502011-11-30 23:21:26 +00001918 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001919 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1920 }
1921
Douglas Gregorde3ef502011-11-30 23:21:26 +00001922 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001923 if (Reader.isDeclIDFromModule(InterfaceID, M))
1924 return true; // We reached the module where the interface originated
1925 // from. Stop traversing the imported modules.
1926
Douglas Gregorde3ef502011-11-30 23:21:26 +00001927 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001928 I = M.ChainedObjCCategories.find(InterfaceID);
1929 if (I == M.ChainedObjCCategories.end())
1930 return false;
1931
1932 ObjCCategoryDecl *
1933 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1934 ObjCCategoryDecl *
1935 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1936
1937 addCategories(HeadCat, TailCat);
1938 return false;
1939 }
1940
1941 void addCategories(ObjCCategoryDecl *HeadCat,
1942 ObjCCategoryDecl *TailCat = 0) {
1943 if (!HeadCat) {
1944 assert(!TailCat);
1945 return;
1946 }
1947
1948 if (!TailCat) {
1949 TailCat = HeadCat;
1950 while (TailCat->getNextClassCategory())
1951 TailCat = TailCat->getNextClassCategory();
1952 }
1953
1954 if (!GlobHeadCat) {
1955 GlobHeadCat = HeadCat;
1956 GlobTailCat = TailCat;
1957 } else {
1958 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1959 GlobTailCat = TailCat;
1960 }
1961
1962 llvm::DenseSet<DeclarationName> Checked;
1963 for (ObjCCategoryDecl *Cat = HeadCat,
1964 *CatEnd = TailCat->getNextClassCategory();
1965 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1966 if (Checked.count(Cat->getDeclName()))
1967 continue;
1968 Checked.insert(Cat->getDeclName());
1969 checkForDuplicate(Cat);
1970 }
1971 }
1972
1973 /// \brief Warns for duplicate categories that come from different modules.
1974 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1975 DeclarationName Name = Cat->getDeclName();
1976 // Find the top category with the same name. We do not want to warn for
1977 // duplicates along the established chain because there were already
1978 // warnings for them when the module was created. We only want to warn for
1979 // duplicates between non-dependent modules:
1980 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001981 // MT //
1982 // / \ //
1983 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001984 //
1985 // We want to warn for duplicates between ML and MR,not between ML and MT.
1986 //
1987 // FIXME: We should not warn for duplicates in diamond:
1988 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001989 // MT //
1990 // / \ //
1991 // ML MR //
1992 // \ / //
1993 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001994 //
1995 // If there are duplicates in ML/MR, there will be warning when creating
1996 // MB *and* when importing MB. We should not warn when importing.
1997 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1998 Next = Next->getNextClassCategory()) {
1999 if (Next->getDeclName() == Name)
2000 Cat = Next;
2001 }
2002
2003 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2004 if (!PrevCat)
2005 PrevCat = Cat;
2006
2007 if (PrevCat != Cat) {
2008 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2009 << Interface->getDeclName() << Name;
2010 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2011 }
2012 }
2013
2014 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2015 };
2016}
2017
2018void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2019 ObjCInterfaceDecl *D) {
2020 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2021 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2022 // Also add the categories that the interface already links to.
2023 Visitor.addCategories(D->getCategoryList());
2024 D->setCategoryList(Visitor.getHeadCategory());
2025}
Douglas Gregordab42432011-08-12 00:15:20 +00002026
Douglas Gregorde3ef502011-11-30 23:21:26 +00002027void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002028 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002029 unsigned Idx = 0;
2030 while (Idx < Record.size()) {
2031 switch ((DeclUpdateKind)Record[Idx++]) {
2032 case UPD_CXX_SET_DEFINITIONDATA: {
2033 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00002034 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00002035 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002036 assert(!RD->DefinitionData && "DefinitionData is already set!");
2037 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2038 break;
2039 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002040
2041 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00002042 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002043 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00002044
2045 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2046 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002047 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002048 break;
2049
2050 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00002051 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00002052 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00002053 // Guard against these being loaded out of original order. Don't use
2054 // getNextNamespace(), since it tries to access the context and can't in
2055 // the middle of deserialization.
2056 if (!Anon->NextNamespace) {
2057 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2058 TU->setAnonymousNamespace(Anon);
2059 else
2060 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2061 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002062 break;
2063 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002064
2065 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2066 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002067 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002068 break;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002069
2070 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2071 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2072 ObjCInterfaceDecl *Def
2073 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregora323c4c2011-12-15 18:17:27 +00002074 if (Def->Data) {
2075 ID->Data = Def->Data;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002076 } else {
2077 // The definition is still initializing.
2078 Reader.PendingForwardRefs[Def].push_back(ID);
2079 }
2080 break;
2081 }
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002082 }
2083 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002084}