blob: 3bcafe9d598a2e6318708e24d888ac2e4c37b6da [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redlf5b13462010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner487412d2009-04-27 05:27:42 +000018#include "clang/AST/ASTConsumer.h"
19#include "clang/AST/ASTContext.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000032namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregorde3ef502011-11-30 23:21:26 +000035 ModuleFile &F;
Sebastian Redlc67764e2010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl539c5062010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +000038 const unsigned RawLocation;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000039 typedef ASTReader::RecordData RecordData;
40 const RecordData &Record;
Chris Lattner487412d2009-04-27 05:27:42 +000041 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000042 TypeID TypeIDForTypeDecl;
Douglas Gregor250ffb12011-03-05 01:35:54 +000043
44 DeclID DeclContextIDForTemplateParmDecl;
45 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000046
Sebastian Redlc67764e2010-07-22 22:43:28 +000047 uint64_t GetCurrentCursorOffset();
Douglas Gregor7fb09192011-07-21 22:35:25 +000048
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000049 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000050 return Reader.ReadSourceLocation(F, R, I);
51 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000052
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000053 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000054 return Reader.ReadSourceRange(F, R, I);
55 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000056
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000057 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000058 return Reader.GetTypeSourceInfo(F, R, I);
59 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000060
61 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
62 return Reader.ReadDeclID(F, R, I);
63 }
64
65 Decl *ReadDecl(const RecordData &R, unsigned &I) {
66 return Reader.ReadDecl(F, R, I);
67 }
68
69 template<typename T>
70 T *ReadDeclAs(const RecordData &R, unsigned &I) {
71 return Reader.ReadDeclAs<T>(F, R, I);
72 }
73
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000074 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000075 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000076 Reader.ReadQualifierInfo(F, Info, R, I);
77 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000078
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000079 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000080 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000081 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
82 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000083
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000084 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000085 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000086 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
87 }
Sebastian Redlc67764e2010-07-22 22:43:28 +000088
Douglas Gregorcf68c582011-12-01 22:20:10 +000089 serialization::SubmoduleID readSubmoduleID(const RecordData &R,
90 unsigned &I) {
91 if (I >= R.size())
92 return 0;
93
94 return Reader.getGlobalSubmoduleID(F, R[I++]);
95 }
96
Douglas Gregorba345522011-12-02 23:23:56 +000097 Module *readModule(const RecordData &R, unsigned &I) {
98 return Reader.getSubmodule(readSubmoduleID(R, I));
99 }
100
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000101 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
102 const RecordData &R, unsigned &I);
103
104 void InitializeCXXDefinitionData(CXXRecordDecl *D,
105 CXXRecordDecl *DefinitionDecl,
106 const RecordData &Record, unsigned &Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000107 public:
Douglas Gregorde3ef502011-11-30 23:21:26 +0000108 ASTDeclReader(ASTReader &Reader, ModuleFile &F,
Sebastian Redl2c373b92010-10-05 15:59:54 +0000109 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000110 unsigned RawLocation,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000111 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000112 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000113 RawLocation(RawLocation), Record(Record), Idx(Idx),
114 TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +0000115
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000116 static void attachPreviousDecl(Decl *D, Decl *previous);
Douglas Gregor05f10352011-12-17 23:38:30 +0000117 static void attachLatestDecl(Decl *D, Decl *latest);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000118
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000119 void Visit(Decl *D);
120
Douglas Gregorde3ef502011-11-30 23:21:26 +0000121 void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000122 const RecordData &Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000123
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000124 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
125 ObjCCategoryDecl *Next) {
126 Cat->NextClassCategory = Next;
127 }
128
Chris Lattner487412d2009-04-27 05:27:42 +0000129 void VisitDecl(Decl *D);
130 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
131 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000132 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000133 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000134 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
135 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000136 void VisitTypeDecl(TypeDecl *TD);
137 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000138 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000139 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000140 void VisitTagDecl(TagDecl *TD);
141 void VisitEnumDecl(EnumDecl *ED);
142 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000143 void VisitCXXRecordDecl(CXXRecordDecl *D);
144 void VisitClassTemplateSpecializationDecl(
145 ClassTemplateSpecializationDecl *D);
146 void VisitClassTemplatePartialSpecializationDecl(
147 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000148 void VisitClassScopeFunctionSpecializationDecl(
149 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000150 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000151 void VisitValueDecl(ValueDecl *VD);
152 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000153 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000154 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000155 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000156 void VisitCXXMethodDecl(CXXMethodDecl *D);
157 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
158 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
159 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000160 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000161 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000162 void VisitVarDecl(VarDecl *VD);
163 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
164 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000165 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
166 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000167 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000168 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000169 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000170 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000171 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000172 void VisitUsingDecl(UsingDecl *D);
173 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000174 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000175 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregorba345522011-12-02 23:23:56 +0000176 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000177 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000178 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000179 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
180 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000181 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000182
Chris Lattner487412d2009-04-27 05:27:42 +0000183 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000184 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000185
Alexis Hunted053252010-05-30 07:21:58 +0000186 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000187 void VisitObjCMethodDecl(ObjCMethodDecl *D);
188 void VisitObjCContainerDecl(ObjCContainerDecl *D);
189 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
190 void VisitObjCIvarDecl(ObjCIvarDecl *D);
191 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
192 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
193 void VisitObjCClassDecl(ObjCClassDecl *D);
194 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
195 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
196 void VisitObjCImplDecl(ObjCImplDecl *D);
197 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
198 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
199 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
200 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
201 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
202 };
203}
204
Sebastian Redlb3298c32010-08-18 23:56:48 +0000205uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregord32f0352011-07-22 06:10:01 +0000206 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000207}
208
Sebastian Redlb3298c32010-08-18 23:56:48 +0000209void ASTDeclReader::Visit(Decl *D) {
210 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000211
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000212 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
213 if (DD->DeclInfo) {
214 DeclaratorDecl::ExtInfo *Info =
215 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
216 Info->TInfo =
217 GetTypeSourceInfo(Record, Idx);
218 }
219 else {
220 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
221 }
222 }
223
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000224 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000225 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000226 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000227 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
228 // if we have a fully initialized TypeDecl, we can safely read its type now.
229 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000230 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
231 // FunctionDecl's body was written last after all other Stmts/Exprs.
232 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000233 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000234 } else if (D->isTemplateParameter()) {
235 // If we have a fully initialized template parameter, we can now
236 // set its DeclContext.
237 D->setDeclContext(
238 cast_or_null<DeclContext>(
239 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
240 D->setLexicalDeclContext(
241 cast_or_null<DeclContext>(
242 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000243 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000244}
245
Sebastian Redlb3298c32010-08-18 23:56:48 +0000246void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000247 if (D->isTemplateParameter()) {
248 // We don't want to deserialize the DeclContext of a template
249 // parameter immediately, because the template parameter might be
250 // used in the formulation of its DeclContext. Use the translation
251 // unit DeclContext as a placeholder.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000252 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
253 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000254 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000255 } else {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000256 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
257 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000258 }
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000259 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner487412d2009-04-27 05:27:42 +0000260 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000261 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000262 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000263 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000264 D->setAttrs(Attrs);
265 }
Chris Lattner487412d2009-04-27 05:27:42 +0000266 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000267 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000268 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +0000269 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000270 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000271 D->FromASTFile = true;
Douglas Gregor26701a42011-09-09 02:06:17 +0000272 D->ModulePrivate = Record[Idx++];
Douglas Gregorcf68c582011-12-01 22:20:10 +0000273
274 // Determine whether this declaration is part of a (sub)module. If so, it
275 // may not yet be visible.
276 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
277 // Module-private declarations are never visible, so there is no work to do.
278 if (!D->ModulePrivate) {
279 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
280 if (Owner->NameVisibility != Module::AllVisible) {
281 // The owning module is not visible. Mark this declaration as
282 // module-private,
283 D->ModulePrivate = true;
284
285 // Note that this declaration was hidden because its owning module is
286 // not yet visible.
287 Reader.HiddenNamesMap[Owner].push_back(D);
288 }
289 }
290 }
291 }
Chris Lattner487412d2009-04-27 05:27:42 +0000292}
293
Sebastian Redlb3298c32010-08-18 23:56:48 +0000294void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000295 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000296}
297
Sebastian Redlb3298c32010-08-18 23:56:48 +0000298void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000299 VisitDecl(ND);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000300 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000301}
302
Sebastian Redlb3298c32010-08-18 23:56:48 +0000303void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000304 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000305 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000306 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor903b7e92011-07-22 00:38:23 +0000307 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000308}
309
Sebastian Redlb3298c32010-08-18 23:56:48 +0000310void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000311 VisitRedeclarable(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000312 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000313 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000314}
315
Richard Smithdda56e42011-04-15 14:24:37 +0000316void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000317 VisitRedeclarable(TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000318 VisitTypeDecl(TD);
319 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
320}
321
Sebastian Redlb3298c32010-08-18 23:56:48 +0000322void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000323 VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000324 VisitTypeDecl(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000325 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000326 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCallf937c022011-10-07 06:10:15 +0000327 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000328 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000329 TD->setFreeStanding(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000330 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000331 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000332 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000333 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000334 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000335 } else
Douglas Gregor7fb09192011-07-21 22:35:25 +0000336 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000337}
338
Sebastian Redlb3298c32010-08-18 23:56:48 +0000339void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000340 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000341 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
342 ED->setIntegerTypeSourceInfo(TI);
343 else
Douglas Gregor903b7e92011-07-22 00:38:23 +0000344 ED->setIntegerType(Reader.readType(F, Record, Idx));
345 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000346 ED->setNumPositiveBits(Record[Idx++]);
347 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000348 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000349 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000350 ED->IsFixed = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000351 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000352}
353
Sebastian Redlb3298c32010-08-18 23:56:48 +0000354void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000355 VisitTagDecl(RD);
356 RD->setHasFlexibleArrayMember(Record[Idx++]);
357 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000358 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000359}
360
Sebastian Redlb3298c32010-08-18 23:56:48 +0000361void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000362 VisitNamedDecl(VD);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000363 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000364}
365
Sebastian Redlb3298c32010-08-18 23:56:48 +0000366void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000367 VisitValueDecl(ECD);
368 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000369 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000370 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
371}
372
Sebastian Redlb3298c32010-08-18 23:56:48 +0000373void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000374 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000375 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000376 if (Record[Idx++]) { // hasExtInfo
377 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000378 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000379 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000380 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000381 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000382}
383
Sebastian Redlb3298c32010-08-18 23:56:48 +0000384void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000385 VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000386 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000387
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000388 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000389 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000390 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikie83d382b2011-09-23 05:06:16 +0000391 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000392 case FunctionDecl::TK_NonTemplate:
393 break;
394 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000395 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
396 Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000397 break;
398 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000399 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000400 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000401 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000402 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000403 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
404 break;
405 }
406 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000407 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
408 Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000409 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
410
411 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000412 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000413 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000414
415 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000416 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000417 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000418 bool HasTemplateArgumentsAsWritten = Record[Idx++];
419 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000420 unsigned NumTemplateArgLocs = Record[Idx++];
421 TemplArgLocs.reserve(NumTemplateArgLocs);
422 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000423 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000424 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000425
Sebastian Redl2c373b92010-10-05 15:59:54 +0000426 LAngleLoc = ReadSourceLocation(Record, Idx);
427 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000428 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000429
Sebastian Redl2c373b92010-10-05 15:59:54 +0000430 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000431
Douglas Gregor4163aca2011-09-09 21:34:22 +0000432 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000433 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000434 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000435 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000436 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000437 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000438 FunctionTemplateSpecializationInfo *FTInfo
439 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
440 TemplArgList,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000441 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
442 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000443 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000444
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000445 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000446 // The template that contains the specializations set. It's not safe to
447 // use getCanonicalDecl on Template since it may still be initializing.
448 FunctionTemplateDecl *CanonTemplate
Douglas Gregor7fb09192011-07-21 22:35:25 +0000449 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000450 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
451 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
452 // FunctionTemplateSpecializationInfo's Profile().
453 // We avoid getASTContext because a decl in the parent hierarchy may
454 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000455 llvm::FoldingSetNodeID ID;
456 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
457 TemplArgs.size(), C);
458 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000459 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000460 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000461 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000462 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000463 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000464 }
465 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
466 // Templates.
467 UnresolvedSet<8> TemplDecls;
468 unsigned NumTemplates = Record[Idx++];
469 while (NumTemplates--)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000470 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000471
472 // Templates args.
473 TemplateArgumentListInfo TemplArgs;
474 unsigned NumArgs = Record[Idx++];
475 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000476 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
477 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
478 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000479
Douglas Gregor4163aca2011-09-09 21:34:22 +0000480 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000481 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000482 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000483 }
484 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000485
Sebastian Redlb3298c32010-08-18 23:56:48 +0000486 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000487 // after everything else is read.
488
Douglas Gregorbf62d642010-12-06 18:36:25 +0000489 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000490 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000491 FD->IsInline = Record[Idx++];
492 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000493 FD->IsVirtualAsWritten = Record[Idx++];
494 FD->IsPure = Record[Idx++];
495 FD->HasInheritedPrototype = Record[Idx++];
496 FD->HasWrittenPrototype = Record[Idx++];
497 FD->IsDeleted = Record[Idx++];
498 FD->IsTrivial = Record[Idx++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000499 FD->IsDefaulted = Record[Idx++];
500 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000501 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smitha77a0a62011-08-15 21:04:07 +0000502 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000503 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000504
Chris Lattnerca025db2010-05-07 21:43:38 +0000505 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000506 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000507 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000508 Params.reserve(NumParams);
509 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000510 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000511 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000512}
513
Sebastian Redlb3298c32010-08-18 23:56:48 +0000514void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000515 VisitNamedDecl(MD);
516 if (Record[Idx++]) {
517 // In practice, this won't be executed (since method definitions
518 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000519 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000520 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
521 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000522 }
523 MD->setInstanceMethod(Record[Idx++]);
524 MD->setVariadic(Record[Idx++]);
525 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000526 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000527
528 MD->IsRedeclaration = Record[Idx++];
529 MD->HasRedeclaration = Record[Idx++];
530 if (MD->HasRedeclaration)
531 Reader.getContext().setObjCMethodRedeclaration(MD,
532 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
533
Chris Lattner487412d2009-04-27 05:27:42 +0000534 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
535 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000536 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000537 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000538 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
539 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000540 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000541 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000542 Params.reserve(NumParams);
543 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000544 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000545
546 MD->SelLocsKind = Record[Idx++];
547 unsigned NumStoredSelLocs = Record[Idx++];
548 SmallVector<SourceLocation, 16> SelLocs;
549 SelLocs.reserve(NumStoredSelLocs);
550 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
551 SelLocs.push_back(ReadSourceLocation(Record, Idx));
552
553 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +0000554}
555
Sebastian Redlb3298c32010-08-18 23:56:48 +0000556void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000557 VisitNamedDecl(CD);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000558 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
559 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000560}
561
Sebastian Redlb3298c32010-08-18 23:56:48 +0000562void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000563 VisitRedeclarable(ID);
Chris Lattner487412d2009-04-27 05:27:42 +0000564 VisitObjCContainerDecl(ID);
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000565 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000566
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000567 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
568 if (ID == Def) {
569 // Read the definition.
570 ID->allocateDefinitionData();
571
572 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
573
574 // Read the superclass.
575 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
576 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
577
Douglas Gregor16408322011-12-15 22:34:59 +0000578 Data.EndLoc = ReadSourceLocation(Record, Idx);
579
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000580 // Read the directly referenced protocols and their SourceLocations.
581 unsigned NumProtocols = Record[Idx++];
582 SmallVector<ObjCProtocolDecl *, 16> Protocols;
583 Protocols.reserve(NumProtocols);
584 for (unsigned I = 0; I != NumProtocols; ++I)
585 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
586 SmallVector<SourceLocation, 16> ProtoLocs;
587 ProtoLocs.reserve(NumProtocols);
588 for (unsigned I = 0; I != NumProtocols; ++I)
589 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
590 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
591 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000592
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000593 // Read the transitive closure of protocols referenced by this class.
594 NumProtocols = Record[Idx++];
595 Protocols.clear();
596 Protocols.reserve(NumProtocols);
597 for (unsigned I = 0; I != NumProtocols; ++I)
598 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
599 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
600 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000601
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000602 // Read the ivars.
603 unsigned NumIvars = Record[Idx++];
604 SmallVector<ObjCIvarDecl *, 16> IVars;
605 IVars.reserve(NumIvars);
606 for (unsigned I = 0; I != NumIvars; ++I)
607 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
608
609 // Read the categories.
610 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000611
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000612 // We will rebuild this list lazily.
613 ID->setIvarList(0);
614
615 // If there are any pending forward references, make their definition data
616 // pointers point at the newly-allocated data.
617 ASTReader::PendingForwardRefsMap::iterator
618 FindI = Reader.PendingForwardRefs.find(ID);
619 if (FindI != Reader.PendingForwardRefs.end()) {
620 ASTReader::ForwardRefs &Refs = FindI->second;
621 for (ASTReader::ForwardRefs::iterator I = Refs.begin(),
622 E = Refs.end();
623 I != E; ++I)
Douglas Gregora323c4c2011-12-15 18:17:27 +0000624 cast<ObjCInterfaceDecl>(*I)->Data = ID->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000625#ifndef NDEBUG
626 // We later check whether PendingForwardRefs is empty to make sure all
627 // pending references were linked.
628 Reader.PendingForwardRefs.erase(ID);
629#endif
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000630 }
631 } else if (Def) {
632 if (Def->Data) {
633 ID->Data = Def->Data;
634 } else {
635 // The definition is still initializing.
636 Reader.PendingForwardRefs[Def].push_back(ID);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000637 }
638 }
Chris Lattner487412d2009-04-27 05:27:42 +0000639}
640
Sebastian Redlb3298c32010-08-18 23:56:48 +0000641void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000642 VisitFieldDecl(IVD);
643 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000644 // This field will be built lazily.
645 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000646 bool synth = Record[Idx++];
647 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000648}
649
Sebastian Redlb3298c32010-08-18 23:56:48 +0000650void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000651 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000652 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000653 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000654 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000655 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000656 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000657 ProtoRefs.reserve(NumProtoRefs);
658 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000659 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000660 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000661 ProtoLocs.reserve(NumProtoRefs);
662 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000663 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000664 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000665 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000666}
667
Sebastian Redlb3298c32010-08-18 23:56:48 +0000668void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000669 VisitFieldDecl(FD);
670}
671
Sebastian Redlb3298c32010-08-18 23:56:48 +0000672void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000673 VisitDecl(CD);
Douglas Gregor40d009f2011-12-14 17:12:03 +0000674 CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
675 CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000676}
677
Sebastian Redlb3298c32010-08-18 23:56:48 +0000678void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000679 VisitDecl(FPD);
680 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000681 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000682 ProtoRefs.reserve(NumProtoRefs);
683 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000684 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000685 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000686 ProtoLocs.reserve(NumProtoRefs);
687 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000688 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000689 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000690 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000691}
692
Sebastian Redlb3298c32010-08-18 23:56:48 +0000693void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000694 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000695 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000696 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000697 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000698 ProtoRefs.reserve(NumProtoRefs);
699 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000700 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000701 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000702 ProtoLocs.reserve(NumProtoRefs);
703 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000704 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000705 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000706 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000707 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000708 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000709 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000710}
711
Sebastian Redlb3298c32010-08-18 23:56:48 +0000712void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000713 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000714 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000715}
716
Sebastian Redlb3298c32010-08-18 23:56:48 +0000717void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000718 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000719 D->setAtLoc(ReadSourceLocation(Record, Idx));
720 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000721 // FIXME: stable encoding
722 D->setPropertyAttributes(
723 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000724 D->setPropertyAttributesAsWritten(
725 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000726 // FIXME: stable encoding
727 D->setPropertyImplementation(
728 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000729 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
730 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000731 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
732 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
733 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000734}
735
Sebastian Redlb3298c32010-08-18 23:56:48 +0000736void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000737 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000738 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000739}
740
Sebastian Redlb3298c32010-08-18 23:56:48 +0000741void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000742 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000743 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000744 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000745}
746
Sebastian Redlb3298c32010-08-18 23:56:48 +0000747void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000748 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000749 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000750 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000751 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000752 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000753}
754
755
Sebastian Redlb3298c32010-08-18 23:56:48 +0000756void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000757 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000758 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000759 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
760 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000761 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000762 D->setGetterCXXConstructor(Reader.ReadExpr(F));
763 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000764}
765
Sebastian Redlb3298c32010-08-18 23:56:48 +0000766void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000767 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000768 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000769 int BitWidthOrInitializer = Record[Idx++];
770 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000771 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000772 else if (BitWidthOrInitializer == 2)
773 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000774 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000775 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000776 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000777 }
Chris Lattner487412d2009-04-27 05:27:42 +0000778}
779
Francois Pichet783dd6e2010-11-21 06:08:52 +0000780void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
781 VisitValueDecl(FD);
782
783 FD->ChainingSize = Record[Idx++];
784 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000785 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000786
787 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000788 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000789}
790
Sebastian Redlb3298c32010-08-18 23:56:48 +0000791void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000792 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000793 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000794 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
795 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
796 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
797 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
798 VD->VarDeclBits.ExceptionVar = Record[Idx++];
799 VD->VarDeclBits.NRVOVariable = Record[Idx++];
800 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000801 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smithd0b4dd62011-12-19 06:19:21 +0000802 if (uint64_t Val = Record[Idx++]) {
Sebastian Redl2c373b92010-10-05 15:59:54 +0000803 VD->setInit(Reader.ReadExpr(F));
Richard Smithd0b4dd62011-12-19 06:19:21 +0000804 if (Val > 1) {
805 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
806 Eval->CheckedICE = true;
807 Eval->IsICE = Val == 3;
808 }
809 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000810
811 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000812 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000813 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000814 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000815 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000816 }
Chris Lattner487412d2009-04-27 05:27:42 +0000817}
818
Sebastian Redlb3298c32010-08-18 23:56:48 +0000819void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000820 VisitVarDecl(PD);
821}
822
Sebastian Redlb3298c32010-08-18 23:56:48 +0000823void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000824 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000825 unsigned isObjCMethodParam = Record[Idx++];
826 unsigned scopeDepth = Record[Idx++];
827 unsigned scopeIndex = Record[Idx++];
828 unsigned declQualifier = Record[Idx++];
829 if (isObjCMethodParam) {
830 assert(scopeDepth == 0);
831 PD->setObjCMethodScopeInfo(scopeIndex);
832 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
833 } else {
834 PD->setScopeInfo(scopeDepth, scopeIndex);
835 }
John McCallbeaa11c2011-05-01 02:13:58 +0000836 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
837 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000838 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000839 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000840}
841
Sebastian Redlb3298c32010-08-18 23:56:48 +0000842void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000843 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000844 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000845 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000846}
847
Sebastian Redlb3298c32010-08-18 23:56:48 +0000848void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000849 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000850 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
851 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000852 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000853 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000854 Params.reserve(NumParams);
855 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000856 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000857 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000858
859 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000860 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000861 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000862 captures.reserve(numCaptures);
863 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000864 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000865 unsigned flags = Record[Idx++];
866 bool byRef = (flags & 1);
867 bool nested = (flags & 2);
868 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
869
870 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
871 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000872 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000873 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000874}
875
Sebastian Redlb3298c32010-08-18 23:56:48 +0000876void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000877 VisitDecl(D);
878 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000879 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000880 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000881}
882
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000883void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
884 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000885 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000886}
887
888
Sebastian Redlb3298c32010-08-18 23:56:48 +0000889void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000890 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000891 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000892 D->LocStart = ReadSourceLocation(Record, Idx);
893 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000894 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000895
Chris Lattnerca025db2010-05-07 21:43:38 +0000896 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000897 // FIXME: Modules will likely have trouble with pointing directly at
898 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000899 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000900 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000901}
902
Sebastian Redlb3298c32010-08-18 23:56:48 +0000903void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000904 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000905 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000906 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000907 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000908 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000909}
910
Sebastian Redlb3298c32010-08-18 23:56:48 +0000911void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000912 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000913 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000914 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000915 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000916 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000917 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000918 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000919 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000920}
921
Sebastian Redlb3298c32010-08-18 23:56:48 +0000922void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000923 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000924 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
925 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
926 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000927 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000928 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000929}
930
Sebastian Redlb3298c32010-08-18 23:56:48 +0000931void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000932 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000933 D->UsingLoc = ReadSourceLocation(Record, Idx);
934 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000935 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000936 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
937 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000938}
939
Sebastian Redlb3298c32010-08-18 23:56:48 +0000940void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000941 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000942 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000943 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000944 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000945}
946
Sebastian Redlb3298c32010-08-18 23:56:48 +0000947void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000948 UnresolvedUsingTypenameDecl *D) {
949 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000950 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000951 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000952}
953
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000954void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000955 struct CXXRecordDecl::DefinitionData &Data,
956 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000957 Data.UserDeclaredConstructor = Record[Idx++];
958 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000959 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000960 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000961 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000962 Data.UserDeclaredDestructor = Record[Idx++];
963 Data.Aggregate = Record[Idx++];
964 Data.PlainOldData = Record[Idx++];
965 Data.Empty = Record[Idx++];
966 Data.Polymorphic = Record[Idx++];
967 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000968 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000969 Data.HasNoNonEmptyBases = Record[Idx++];
970 Data.HasPrivateFields = Record[Idx++];
971 Data.HasProtectedFields = Record[Idx++];
972 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000973 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000974 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000975 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000976 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000977 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000978 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000979 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000980 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000981 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000982 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000983 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000984 Data.DeclaredDefaultConstructor = Record[Idx++];
985 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000986 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000987 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000988 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000989 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000990 Data.FailedImplicitMoveConstructor = Record[Idx++];
991 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000992
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000993 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000994 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000995 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000996 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000997 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000998 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000999
Douglas Gregor7fb09192011-07-21 22:35:25 +00001000 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
1001 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001002 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001003 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001004}
1005
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001006void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
1007 CXXRecordDecl *DefinitionDecl,
1008 const RecordData &Record,
1009 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001010 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +00001011
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001012 if (D == DefinitionDecl) {
1013 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001014 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001015 // We read the definition info. Check if there are pending forward
1016 // references that need to point to this DefinitionData pointer.
1017 ASTReader::PendingForwardRefsMap::iterator
1018 FindI = Reader.PendingForwardRefs.find(D);
1019 if (FindI != Reader.PendingForwardRefs.end()) {
1020 ASTReader::ForwardRefs &Refs = FindI->second;
1021 for (ASTReader::ForwardRefs::iterator
1022 I = Refs.begin(), E = Refs.end(); I != E; ++I)
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001023 cast<CXXRecordDecl>(*I)->DefinitionData = D->DefinitionData;
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001024#ifndef NDEBUG
1025 // We later check whether PendingForwardRefs is empty to make sure all
1026 // pending references were linked.
1027 Reader.PendingForwardRefs.erase(D);
1028#endif
1029 }
1030 } else if (DefinitionDecl) {
1031 if (DefinitionDecl->DefinitionData) {
1032 D->DefinitionData = DefinitionDecl->DefinitionData;
1033 } else {
1034 // The definition is still initializing.
1035 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
1036 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001037 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001038}
1039
1040void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1041 VisitRecordDecl(D);
1042
Douglas Gregor7fb09192011-07-21 22:35:25 +00001043 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001044 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1045
Douglas Gregor4163aca2011-09-09 21:34:22 +00001046 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001047
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001048 enum CXXRecKind {
1049 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1050 };
1051 switch ((CXXRecKind)Record[Idx++]) {
1052 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001053 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001054 case CXXRecNotTemplate:
1055 break;
1056 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001057 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001058 break;
1059 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001060 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001061 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001062 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001063 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1064 MSI->setPointOfInstantiation(POI);
1065 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001066 break;
1067 }
1068 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001069
1070 // Load the key function to avoid deserializing every method so we can
1071 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001072 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001073 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001074 C.KeyFunctions[D] = Key;
1075 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001076}
1077
Sebastian Redlb3298c32010-08-18 23:56:48 +00001078void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001079 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001080 unsigned NumOverridenMethods = Record[Idx++];
1081 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001082 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1083 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001084 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001085 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001086 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001087}
1088
Sebastian Redlb3298c32010-08-18 23:56:48 +00001089void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001090 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001091
1092 D->IsExplicitSpecified = Record[Idx++];
1093 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001094 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1095 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001096}
1097
Sebastian Redlb3298c32010-08-18 23:56:48 +00001098void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001099 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001100
1101 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001102 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001103}
1104
Sebastian Redlb3298c32010-08-18 23:56:48 +00001105void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001106 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001107 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001108}
1109
Douglas Gregorba345522011-12-02 23:23:56 +00001110void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1111 VisitDecl(D);
1112 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1113 D->ImportedAndComplete.setInt(Record[Idx++]);
1114 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1115 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1116 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1117 ++Idx;
1118}
1119
Sebastian Redlb3298c32010-08-18 23:56:48 +00001120void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001121 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001122 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001123}
1124
Sebastian Redlb3298c32010-08-18 23:56:48 +00001125void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001126 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001127 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001128 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001129 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001130 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001131 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001132 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001133 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001134}
1135
Sebastian Redlb3298c32010-08-18 23:56:48 +00001136void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001137 VisitDecl(D);
1138 unsigned NumParams = Record[Idx++];
1139 D->NumParams = NumParams;
1140 D->Params = new TemplateParameterList*[NumParams];
1141 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001142 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001143 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001144 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001145 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001146 D->Friend = GetTypeSourceInfo(Record, Idx);
1147 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001148}
1149
Sebastian Redlb3298c32010-08-18 23:56:48 +00001150void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001151 VisitNamedDecl(D);
1152
Douglas Gregor7fb09192011-07-21 22:35:25 +00001153 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001154 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001155 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001156 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001157}
1158
Sebastian Redlb3298c32010-08-18 23:56:48 +00001159void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001160 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1161 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001162
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001163 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001164 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1165 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001166 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1167 // We temporarily set the first (canonical) declaration as the previous one
1168 // which is the one that matters and mark the real previous DeclID to be
1169 // loaded & attached later on.
1170 RedeclarableTemplateDecl *FirstDecl =
1171 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1172 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1173 "FirstDecl kind mismatch");
1174 if (FirstDecl) {
1175 D->CommonOrPrev = FirstDecl;
1176 // Mark the real previous DeclID to be loaded & attached later on.
1177 if (PreviousDeclID != FirstDeclID)
1178 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1179 } else {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001180 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001181 if (RedeclarableTemplateDecl *RTD
Douglas Gregor7fb09192011-07-21 22:35:25 +00001182 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001183 assert(RTD->getKind() == D->getKind() &&
1184 "InstantiatedFromMemberTemplate kind mismatch");
1185 D->setInstantiatedFromMemberTemplateImpl(RTD);
1186 if (Record[Idx++])
1187 D->setMemberSpecialization();
1188 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001189
Douglas Gregor7fb09192011-07-21 22:35:25 +00001190 RedeclarableTemplateDecl *LatestDecl
1191 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001192
1193 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001194 // in the same AST file. However, if this actually needs to point to a
1195 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001196 // the FirstLatestDeclIDs map which tracks this kind of decls.
1197 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001198 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001199 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1200 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregoraa7cbfd2011-08-25 15:28:26 +00001201 if (Decl *NewLatest = Reader.GetDecl(I->second))
1202 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001203 }
1204
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001205 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1206 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001207 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001208
1209 VisitTemplateDecl(D);
1210 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001211}
1212
Sebastian Redlb3298c32010-08-18 23:56:48 +00001213void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001214 VisitRedeclarableTemplateDecl(D);
1215
1216 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001217 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1218 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001219 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001220 SpecIDs.push_back(0);
1221
1222 // Specializations.
1223 unsigned Size = Record[Idx++];
1224 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001225 for (unsigned I = 0; I != Size; ++I)
1226 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001227
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001228 // Partial specializations.
1229 Size = Record[Idx++];
1230 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001231 for (unsigned I = 0; I != Size; ++I)
1232 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001233
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001234 if (SpecIDs[0]) {
1235 typedef serialization::DeclID DeclID;
1236
1237 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1238 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001239 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001240 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1241 SpecIDs.size() * sizeof(DeclID));
1242 }
1243
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001244 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001245 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001246}
1247
Sebastian Redlb3298c32010-08-18 23:56:48 +00001248void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001249 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001250 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001251
Douglas Gregor4163aca2011-09-09 21:34:22 +00001252 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001253 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001254 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001255 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001256 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001257 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001258 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001259 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001260 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1261 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001262 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1263 = new (C) ClassTemplateSpecializationDecl::
1264 SpecializedPartialSpecialization();
1265 PS->PartialSpecialization
1266 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1267 PS->TemplateArgs = ArgList;
1268 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001269 }
1270 }
1271
1272 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001273 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001274 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1275 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1276 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001277 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1278 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001279 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001280 }
1281
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001282 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001283 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001284 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1285 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001286 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001287 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001288
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001289 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001290 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001291 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001292 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1293 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001294 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001295 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001296 }
1297 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001298}
1299
Sebastian Redlb3298c32010-08-18 23:56:48 +00001300void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001301 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001302 VisitClassTemplateSpecializationDecl(D);
1303
Douglas Gregor4163aca2011-09-09 21:34:22 +00001304 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001305 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001306
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001307 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001308 if (NumArgs) {
1309 D->NumArgsAsWritten = NumArgs;
1310 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1311 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001312 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001313 }
1314
1315 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001316
1317 // These are read/set from/to the first declaration.
1318 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001319 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001320 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001321 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001322 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001323}
1324
Sebastian Redlb7448632011-08-31 13:59:56 +00001325void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1326 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001327 VisitDecl(D);
1328 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1329}
1330
Sebastian Redlb3298c32010-08-18 23:56:48 +00001331void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001332 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001333
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001334 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001335 // This FunctionTemplateDecl owns a CommonPtr; read it.
1336
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001337 // Read the function specialization declarations.
1338 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001339 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001340 unsigned NumSpecs = Record[Idx++];
1341 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001342 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001343 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001344}
1345
Sebastian Redlb3298c32010-08-18 23:56:48 +00001346void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001347 VisitTypeDecl(D);
1348
1349 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001350
1351 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001352 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001353 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001354}
1355
Sebastian Redlb3298c32010-08-18 23:56:48 +00001356void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001357 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001358 // TemplateParmPosition.
1359 D->setDepth(Record[Idx++]);
1360 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001361 if (D->isExpandedParameterPack()) {
1362 void **Data = reinterpret_cast<void **>(D + 1);
1363 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001364 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001365 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1366 }
1367 } else {
1368 // Rest of NonTypeTemplateParmDecl.
1369 D->ParameterPack = Record[Idx++];
1370 if (Record[Idx++]) {
1371 Expr *DefArg = Reader.ReadExpr(F);
1372 bool Inherited = Record[Idx++];
1373 D->setDefaultArgument(DefArg, Inherited);
1374 }
1375 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001376}
1377
Sebastian Redlb3298c32010-08-18 23:56:48 +00001378void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001379 VisitTemplateDecl(D);
1380 // TemplateParmPosition.
1381 D->setDepth(Record[Idx++]);
1382 D->setPosition(Record[Idx++]);
1383 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001384 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001385 bool IsInherited = Record[Idx++];
1386 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001387 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001388}
1389
Richard Smith3f1b5d02011-05-05 21:57:07 +00001390void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1391 VisitRedeclarableTemplateDecl(D);
1392}
1393
Sebastian Redlb3298c32010-08-18 23:56:48 +00001394void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001395 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001396 D->AssertExpr = Reader.ReadExpr(F);
1397 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001398 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001399}
1400
Mike Stump11289f42009-09-09 15:08:12 +00001401std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001402ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001403 uint64_t LexicalOffset = Record[Idx++];
1404 uint64_t VisibleOffset = Record[Idx++];
1405 return std::make_pair(LexicalOffset, VisibleOffset);
1406}
1407
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001408template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001409void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +00001410 enum RedeclKind { FirstInFile, PointsToPrevious };
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001411 RedeclKind Kind = (RedeclKind)Record[Idx++];
Douglas Gregor05f10352011-12-17 23:38:30 +00001412
1413 // Read the first declaration ID, and note that we need to reconstruct
1414 // the redeclaration chain once we hit the top level.
1415 DeclID FirstDeclID = ReadDeclID(Record, Idx);
1416 if (Reader.PendingDeclChainsKnown.insert(FirstDeclID))
1417 Reader.PendingDeclChains.push_back(FirstDeclID);
1418
1419 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1420
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001421 switch (Kind) {
Douglas Gregor05f10352011-12-17 23:38:30 +00001422 case FirstInFile:
1423 if (FirstDecl != D)
1424 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001425 break;
Douglas Gregor05f10352011-12-17 23:38:30 +00001426
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001427 case PointsToPrevious: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001428 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
Douglas Gregor05f10352011-12-17 23:38:30 +00001429
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001430 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1431 // We temporarily set the first (canonical) declaration as the previous one
1432 // which is the one that matters and mark the real previous DeclID to be
1433 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001434 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Douglas Gregor3e300102011-10-26 17:53:41 +00001435
Douglas Gregor05f10352011-12-17 23:38:30 +00001436 // Make a note that we need to wire up this declaration to its
1437 // previous declaration, later.
1438 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1439 PreviousDeclID));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001440 break;
1441 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001442 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001443}
1444
Chris Lattner487412d2009-04-27 05:27:42 +00001445//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001446// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001447//===----------------------------------------------------------------------===//
1448
Chris Lattner8f63ab52009-04-27 06:01:06 +00001449/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001450void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001451 const RecordData &Record, unsigned &Idx) {
1452 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001453 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001454 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001455 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001456
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001457#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001458
1459 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001460 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001461 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001462}
1463
1464//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001465// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001466//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001467
1468/// \brief Note that we have loaded the declaration with the given
1469/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001470///
Chris Lattner487412d2009-04-27 05:27:42 +00001471/// This routine notes that this declaration has already been loaded,
1472/// so that future GetDecl calls will return this declaration rather
1473/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001474inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001475 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1476 DeclsLoaded[Index] = D;
1477}
1478
1479
1480/// \brief Determine whether the consumer will be interested in seeing
1481/// this declaration (via HandleTopLevelDecl).
1482///
1483/// This routine should return true for anything that might affect
1484/// code generation, e.g., inline function definitions, Objective-C
1485/// declarations with metadata, etc.
1486static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001487 // An ObjCMethodDecl is never considered as "interesting" because its
1488 // implementation container always is.
1489
Douglas Gregor87d81242011-09-10 00:22:34 +00001490 if (isa<FileScopeAsmDecl>(D) ||
1491 isa<ObjCProtocolDecl>(D) ||
1492 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001493 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001494 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001495 return Var->isFileVarDecl() &&
1496 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001497 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001498 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001499
1500 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001501}
1502
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001503/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001504ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001505ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001506 // See if there's an override.
1507 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001508 if (It != ReplacedDecls.end()) {
1509 RawLocation = It->second.RawLoc;
1510 return RecordLocation(It->second.Mod, It->second.Offset);
1511 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001512
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001513 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1514 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001515 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001516 const DeclOffset &
1517 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1518 RawLocation = DOffs.Loc;
1519 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001520}
1521
Douglas Gregord32f0352011-07-22 06:10:01 +00001522ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001523 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001524 = GlobalBitOffsetsMap.find(GlobalOffset);
1525
1526 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1527 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1528}
1529
Douglas Gregorde3ef502011-11-30 23:21:26 +00001530uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001531 return LocalOffset + M.GlobalBitOffset;
1532}
1533
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001534void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1535 assert(D && previous);
1536 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1537 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1538 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1539 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1540 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1541 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
Douglas Gregor05f10352011-12-17 23:38:30 +00001542 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1543 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
1544 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregorab1ec82e2011-12-16 03:12:41 +00001545 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001546 } else {
1547 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1548 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1549 }
1550}
1551
Douglas Gregor05f10352011-12-17 23:38:30 +00001552void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
1553 assert(D && Latest);
1554 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1555 TD->RedeclLink
1556 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
1557 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1558 FD->RedeclLink
1559 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
1560 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1561 VD->RedeclLink
1562 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
1563 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1564 TD->RedeclLink
1565 = Redeclarable<TypedefNameDecl>::LatestDeclLink(
1566 cast<TypedefNameDecl>(Latest));
1567 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
1568 ID->RedeclLink
1569 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
1570 cast<ObjCInterfaceDecl>(Latest));
1571 } else {
1572 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1573 TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest);
1574 }
1575}
1576
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001577void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1578 Decl *previous = GetDecl(ID);
1579 ASTDeclReader::attachPreviousDecl(D, previous);
1580}
1581
Sebastian Redlb3298c32010-08-18 23:56:48 +00001582/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001583Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001584 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001585 unsigned RawLocation = 0;
1586 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001587 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001588 // Keep track of where we are in the stream, then jump back there
1589 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001590 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001591
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001592 ReadingKindTracker ReadingKind(Read_Decl, *this);
1593
Douglas Gregor1342e842009-07-06 18:54:52 +00001594 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001595 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001596
Sebastian Redl2c373b92010-10-05 15:59:54 +00001597 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001598 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001599 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001600 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001601 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001602
Chris Lattner1de76db2009-04-27 05:58:23 +00001603 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001604 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001605 case DECL_CONTEXT_LEXICAL:
1606 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001607 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001608 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001609 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001610 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001611 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001612 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001613 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001614 0, 0);
1615 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001616 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001617 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001618 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001619 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001620 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001621 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001622 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001623 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001624 0, llvm::APSInt());
1625 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001626 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001627 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001628 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001629 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001630 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001631 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001632 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001633 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001634 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001635 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001636 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001637 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001638 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001639 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001640 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001641 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001642 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001643 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001644 SourceLocation(), 0,
1645 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001646 SourceLocation(), 0);
1647 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001648 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001649 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001650 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1651 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001652 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001653 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001654 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001655 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001656 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001657 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001658 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001659 SourceLocation(), 0, 0);
1660 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001661 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001662 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001663 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001664 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001665 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001666 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001667 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001668 SourceLocation(),
1669 NestedNameSpecifierLoc(),
1670 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001671 DeclarationName());
1672 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001673 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001674 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001675 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001676 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001677 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001678 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001679 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001680 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001681 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001682 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001683 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001684 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001685 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001686 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001687 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001688 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001689 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001690 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001691 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001692 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001693 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001694 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001695 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001696 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001697 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001698 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001699 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001700 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001701 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001702 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001703 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001704 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001705 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001706 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001707 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001708 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001709 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001710 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001711 Decl::EmptyShell());
1712 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001713 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001714 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001715 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001716 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001717 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001718 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001719 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001720 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001721 SourceLocation(), 0, 0, 0, QualType(),
1722 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001723 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001724 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001725 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001726 SourceLocation(), 0, 0, 0, QualType(),
1727 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001728 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001729 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001730 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001731 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001732 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001733 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001734 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001735 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001736 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001737 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001738 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001739 break;
1740
Sebastian Redl539c5062010-08-18 23:57:32 +00001741 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001742 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001743 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001744 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001745 case DECL_OBJC_INTERFACE:
Douglas Gregorab1ec82e2011-12-16 03:12:41 +00001746 D = ObjCInterfaceDecl::CreateEmpty(Context);
Chris Lattner487412d2009-04-27 05:27:42 +00001747 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001748 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001749 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001750 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001751 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001752 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001753 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001754 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001755 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001756 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001757 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001758 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001759 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001760 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001761 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001762 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001763 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001764 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001765 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001766 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001767 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001768 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001769 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001770 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +00001771 SourceLocation(), SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001772 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001773 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001774 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1775 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001776 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001777 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001778 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001779 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001780 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001781 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001782 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001783 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001784 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001785 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001786 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001787 ObjCPropertyImplDecl::Dynamic, 0,
1788 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001789 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001790 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001791 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001792 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001793 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001794 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001795 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001796 0, 0);
1797 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001798 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001799 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001800 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001801 break;
1802
Sebastian Redl539c5062010-08-18 23:57:32 +00001803 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001804 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001805 break;
1806
Sebastian Redl539c5062010-08-18 23:57:32 +00001807 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001808 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001809 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001810 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001811 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001812 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001813 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001814 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001815 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001816 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001817 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001818 case DECL_CXX_BASE_SPECIFIERS:
1819 Error("attempt to read a C++ base-specifier record as a declaration");
1820 return 0;
Douglas Gregorba345522011-12-02 23:23:56 +00001821 case DECL_IMPORT:
1822 // Note: last entry of the ImportDecl record is the number of stored source
1823 // locations.
1824 D = ImportDecl::CreateEmpty(Context, Record.back());
1825 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001826 }
Chris Lattner487412d2009-04-27 05:27:42 +00001827
Sebastian Redlb3298c32010-08-18 23:56:48 +00001828 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001829 LoadedDecl(Index, D);
1830 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001831
1832 // If this declaration is also a declaration context, get the
1833 // offsets for its tables of lexical and visible declarations.
1834 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1835 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1836 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001837 if (Offsets.first != 0)
1838 DC->setHasExternalLexicalStorage(true);
1839 if (Offsets.second != 0)
1840 DC->setHasExternalVisibleStorage(true);
1841 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1842 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001843 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001844 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001845
Sebastian Redlf830df42011-04-24 16:27:54 +00001846 // Now add the pending visible updates for this decl context, if it has any.
1847 DeclContextVisibleUpdatesPending::iterator I =
1848 PendingVisibleUpdates.find(ID);
1849 if (I != PendingVisibleUpdates.end()) {
1850 // There are updates. This means the context has external visible
1851 // storage, even if the original stored version didn't.
1852 DC->setHasExternalVisibleStorage(true);
1853 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001854 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1855 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001856 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001857 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001858 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001859 }
1860 }
1861 assert(Idx == Record.size());
1862
Douglas Gregordab42432011-08-12 00:15:20 +00001863 // Load any relevant update records.
1864 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001865
1866 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001867 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001868 PendingChainedObjCCategories.push_back(
1869 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001870
Douglas Gregordab42432011-08-12 00:15:20 +00001871 // If we have deserialized a declaration that has a definition the
1872 // AST consumer might need to know about, queue it.
1873 // We don't pass it to the consumer immediately because we may be in recursive
1874 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001875 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001876 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001877
Douglas Gregordab42432011-08-12 00:15:20 +00001878 return D;
1879}
1880
1881void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001882 // The declaration may have been modified by files later in the chain.
1883 // If this is the case, read the record containing the updates from each file
1884 // and pass it to ASTDeclReader to make the modifications.
1885 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1886 if (UpdI != DeclUpdateOffsets.end()) {
1887 FileOffsetsTy &UpdateOffsets = UpdI->second;
1888 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001889 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001890 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001891 uint64_t Offset = I->second;
1892 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1893 SavedStreamPosition SavedPosition(Cursor);
1894 Cursor.JumpToBit(Offset);
1895 RecordData Record;
1896 unsigned Code = Cursor.ReadCode();
1897 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1898 (void)RecCode;
1899 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001900
1901 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001902 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001903 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001904 }
1905 }
Chris Lattner487412d2009-04-27 05:27:42 +00001906}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001907
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001908namespace {
Douglas Gregor05f10352011-12-17 23:38:30 +00001909 struct CompareLocalRedeclarationsInfoToID {
1910 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) {
1911 return X.FirstID < Y;
1912 }
1913
1914 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) {
1915 return X < Y.FirstID;
1916 }
1917
1918 bool operator()(const LocalRedeclarationsInfo &X,
1919 const LocalRedeclarationsInfo &Y) {
1920 return X.FirstID < Y.FirstID;
1921 }
1922 bool operator()(DeclID X, DeclID Y) {
1923 return X < Y;
1924 }
1925 };
1926
1927 class RedeclChainVisitor {
1928 ASTReader &Reader;
1929 DeclID GlobalFirstID;
1930 llvm::SmallVector<std::pair<Decl *, Decl *>, 4> Chains;
1931
1932 public:
1933 RedeclChainVisitor(ASTReader &Reader, DeclID GlobalFirstID)
1934 : Reader(Reader), GlobalFirstID(GlobalFirstID) { }
1935
1936 static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
1937 if (Preorder)
1938 return false;
1939
1940 return static_cast<RedeclChainVisitor *>(UserData)->visit(M);
1941 }
1942
1943 bool visit(ModuleFile &M) {
1944 // Map global ID of the first declaration down to the local ID
1945 // used in this module file.
1946 DeclID FirstID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalFirstID);
1947 if (!FirstID)
1948 return false;
1949
1950 // Perform a binary search to find the local redeclarations for this
1951 // declaration (if any).
1952 const LocalRedeclarationsInfo *Result
1953 = std::lower_bound(M.RedeclarationsInfo,
1954 M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos,
1955 FirstID, CompareLocalRedeclarationsInfoToID());
1956 if (Result == M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos ||
1957 Result->FirstID != FirstID)
1958 return false;
1959
1960 // Dig out the starting/ending declarations.
1961 Decl *FirstLocalDecl = Reader.GetLocalDecl(M, Result->FirstLocalID);
1962 Decl *LastLocalDecl = Reader.GetLocalDecl(M, Result->LastLocalID);
1963 if (!FirstLocalDecl || !LastLocalDecl)
1964 return false;
1965
1966 // Append this redeclaration chain to the list.
1967 Chains.push_back(std::make_pair(FirstLocalDecl, LastLocalDecl));
1968 return false;
1969 }
1970
1971 ArrayRef<std::pair<Decl *, Decl *> > getChains() const {
1972 return Chains;
1973 }
1974
1975 void addParsed(Decl *FirstParsedDecl, Decl *LastParsedDecl) {
1976 Chains.push_back(std::make_pair(FirstParsedDecl, LastParsedDecl));
1977 }
1978 };
1979}
1980
1981/// \brief Retrieve the previous declaration to D.
1982static Decl *getPreviousDecl(Decl *D) {
1983 if (TagDecl *TD = dyn_cast<TagDecl>(D))
1984 return TD->getPreviousDeclaration();
1985 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1986 return FD->getPreviousDeclaration();
1987 if (VarDecl *VD = dyn_cast<VarDecl>(D))
1988 return VD->getPreviousDeclaration();
1989 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
1990 return TD->getPreviousDeclaration();
1991 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
1992 return ID->getPreviousDeclaration();
1993
1994 return cast<RedeclarableTemplateDecl>(D)->getPreviousDeclaration();
1995}
1996
1997/// \brief Retrieve the most recent declaration of D.
1998static Decl *getMostRecentDecl(Decl *D) {
1999 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2000 return TD->getMostRecentDeclaration();
2001 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2002 return FD->getMostRecentDeclaration();
2003 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2004 return VD->getMostRecentDeclaration();
2005 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2006 return TD->getMostRecentDeclaration();
2007 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2008 return ID->getMostRecentDeclaration();
2009
2010 return cast<RedeclarableTemplateDecl>(D)->getMostRecentDeclaration();
2011}
2012
2013void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
2014 // Build up the list of redeclaration chains.
2015 RedeclChainVisitor Visitor(*this, ID);
2016 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor);
2017
2018 // Retrieve the chains.
2019 ArrayRef<std::pair<Decl *, Decl *> > Chains = Visitor.getChains();
2020 if (Chains.empty())
2021 return;
2022
2023 // FIXME: Splice local (not from AST file) declarations into the list,
2024 // rather than always re-ordering them.
2025 Decl *CanonDecl = GetDecl(ID);
2026
2027 // Capture all of the parsed declarations and put them at the end.
2028 Decl *MostRecent = getMostRecentDecl(CanonDecl);
2029 Decl *FirstParsed = MostRecent;
2030 if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) {
2031 Decl *Current = MostRecent;
2032 while (Decl *Prev = getPreviousDecl(Current)) {
2033 if (Prev->isFromASTFile()) {
2034 Current = Prev;
2035 continue;
2036 }
2037
2038 // Chain all of the parsed declarations together.
2039 ASTDeclReader::attachPreviousDecl(FirstParsed, Prev);
2040 FirstParsed = Prev;
2041 Current = Prev;
2042 }
2043
2044 Visitor.addParsed(FirstParsed, MostRecent);
2045 }
2046
2047 // Hook up the separate chains.
2048 Chains = Visitor.getChains();
2049 for (unsigned I = 1, N = Chains.size(); I != N; ++I)
2050 ASTDeclReader::attachPreviousDecl(Chains[I].first, Chains[I-1].second);
2051 ASTDeclReader::attachLatestDecl(CanonDecl, Chains.back().second);
2052}
2053
2054namespace {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002055 /// \brief Given an ObjC interface, goes through the modules and links to the
2056 /// interface all the categories for it.
2057 class ObjCChainedCategoriesVisitor {
2058 ASTReader &Reader;
2059 serialization::GlobalDeclID InterfaceID;
2060 ObjCInterfaceDecl *Interface;
2061 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
2062 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
2063
2064 public:
2065 ObjCChainedCategoriesVisitor(ASTReader &Reader,
2066 serialization::GlobalDeclID InterfaceID,
2067 ObjCInterfaceDecl *Interface)
2068 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
2069 GlobHeadCat(0), GlobTailCat(0) { }
2070
Douglas Gregorde3ef502011-11-30 23:21:26 +00002071 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002072 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
2073 }
2074
Douglas Gregorde3ef502011-11-30 23:21:26 +00002075 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002076 if (Reader.isDeclIDFromModule(InterfaceID, M))
2077 return true; // We reached the module where the interface originated
2078 // from. Stop traversing the imported modules.
2079
Douglas Gregorde3ef502011-11-30 23:21:26 +00002080 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002081 I = M.ChainedObjCCategories.find(InterfaceID);
2082 if (I == M.ChainedObjCCategories.end())
2083 return false;
2084
2085 ObjCCategoryDecl *
2086 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
2087 ObjCCategoryDecl *
2088 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
2089
2090 addCategories(HeadCat, TailCat);
2091 return false;
2092 }
2093
2094 void addCategories(ObjCCategoryDecl *HeadCat,
2095 ObjCCategoryDecl *TailCat = 0) {
2096 if (!HeadCat) {
2097 assert(!TailCat);
2098 return;
2099 }
2100
2101 if (!TailCat) {
2102 TailCat = HeadCat;
2103 while (TailCat->getNextClassCategory())
2104 TailCat = TailCat->getNextClassCategory();
2105 }
2106
2107 if (!GlobHeadCat) {
2108 GlobHeadCat = HeadCat;
2109 GlobTailCat = TailCat;
2110 } else {
2111 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
2112 GlobTailCat = TailCat;
2113 }
2114
2115 llvm::DenseSet<DeclarationName> Checked;
2116 for (ObjCCategoryDecl *Cat = HeadCat,
2117 *CatEnd = TailCat->getNextClassCategory();
2118 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
2119 if (Checked.count(Cat->getDeclName()))
2120 continue;
2121 Checked.insert(Cat->getDeclName());
2122 checkForDuplicate(Cat);
2123 }
2124 }
2125
2126 /// \brief Warns for duplicate categories that come from different modules.
2127 void checkForDuplicate(ObjCCategoryDecl *Cat) {
2128 DeclarationName Name = Cat->getDeclName();
2129 // Find the top category with the same name. We do not want to warn for
2130 // duplicates along the established chain because there were already
2131 // warnings for them when the module was created. We only want to warn for
2132 // duplicates between non-dependent modules:
2133 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00002134 // MT //
2135 // / \ //
2136 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002137 //
2138 // We want to warn for duplicates between ML and MR,not between ML and MT.
2139 //
2140 // FIXME: We should not warn for duplicates in diamond:
2141 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00002142 // MT //
2143 // / \ //
2144 // ML MR //
2145 // \ / //
2146 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002147 //
2148 // If there are duplicates in ML/MR, there will be warning when creating
2149 // MB *and* when importing MB. We should not warn when importing.
2150 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
2151 Next = Next->getNextClassCategory()) {
2152 if (Next->getDeclName() == Name)
2153 Cat = Next;
2154 }
2155
2156 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2157 if (!PrevCat)
2158 PrevCat = Cat;
2159
2160 if (PrevCat != Cat) {
2161 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2162 << Interface->getDeclName() << Name;
2163 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2164 }
2165 }
2166
2167 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2168 };
2169}
2170
2171void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2172 ObjCInterfaceDecl *D) {
2173 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2174 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2175 // Also add the categories that the interface already links to.
2176 Visitor.addCategories(D->getCategoryList());
2177 D->setCategoryList(Visitor.getHeadCategory());
2178}
Douglas Gregordab42432011-08-12 00:15:20 +00002179
Douglas Gregorde3ef502011-11-30 23:21:26 +00002180void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002181 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002182 unsigned Idx = 0;
2183 while (Idx < Record.size()) {
2184 switch ((DeclUpdateKind)Record[Idx++]) {
2185 case UPD_CXX_SET_DEFINITIONDATA: {
2186 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00002187 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00002188 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002189 assert(!RD->DefinitionData && "DefinitionData is already set!");
2190 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2191 break;
2192 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002193
2194 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00002195 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002196 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00002197
2198 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2199 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002200 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002201 break;
2202
2203 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00002204 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00002205 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00002206 // Guard against these being loaded out of original order. Don't use
2207 // getNextNamespace(), since it tries to access the context and can't in
2208 // the middle of deserialization.
2209 if (!Anon->NextNamespace) {
2210 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2211 TU->setAnonymousNamespace(Anon);
2212 else
2213 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2214 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002215 break;
2216 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002217
2218 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2219 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002220 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002221 break;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002222
2223 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2224 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2225 ObjCInterfaceDecl *Def
2226 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregora323c4c2011-12-15 18:17:27 +00002227 if (Def->Data) {
2228 ID->Data = Def->Data;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002229 } else {
2230 // The definition is still initializing.
2231 Reader.PendingForwardRefs[Def].push_back(ID);
2232 }
2233 break;
2234 }
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002235 }
2236 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002237}