blob: bd6a5a5e06d3965c38f83d0b9dfe874ec6f4c7a9 [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);
Douglas Gregor1f179062011-12-19 14:40:25 +0000137 void VisitTypedefNameDecl(TypedefNameDecl *TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000138 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000139 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000140 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000141 void VisitTagDecl(TagDecl *TD);
142 void VisitEnumDecl(EnumDecl *ED);
143 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000144 void VisitCXXRecordDecl(CXXRecordDecl *D);
145 void VisitClassTemplateSpecializationDecl(
146 ClassTemplateSpecializationDecl *D);
147 void VisitClassTemplatePartialSpecializationDecl(
148 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000149 void VisitClassScopeFunctionSpecializationDecl(
150 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000151 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000152 void VisitValueDecl(ValueDecl *VD);
153 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000154 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000155 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000156 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000157 void VisitCXXMethodDecl(CXXMethodDecl *D);
158 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
159 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
160 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000161 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000162 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000163 void VisitVarDecl(VarDecl *VD);
164 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
165 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000166 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
167 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000168 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000169 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000170 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000171 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000172 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000173 void VisitUsingDecl(UsingDecl *D);
174 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000175 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000176 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregorba345522011-12-02 23:23:56 +0000177 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000178 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000179 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000180 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
181 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000182 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000183
Chris Lattner487412d2009-04-27 05:27:42 +0000184 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000185 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000186
Alexis Hunted053252010-05-30 07:21:58 +0000187 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000188 void VisitObjCMethodDecl(ObjCMethodDecl *D);
189 void VisitObjCContainerDecl(ObjCContainerDecl *D);
190 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
191 void VisitObjCIvarDecl(ObjCIvarDecl *D);
192 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
193 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
194 void VisitObjCClassDecl(ObjCClassDecl *D);
195 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
196 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
197 void VisitObjCImplDecl(ObjCImplDecl *D);
198 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
199 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
200 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
201 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
202 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
203 };
204}
205
Sebastian Redlb3298c32010-08-18 23:56:48 +0000206uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregord32f0352011-07-22 06:10:01 +0000207 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000208}
209
Sebastian Redlb3298c32010-08-18 23:56:48 +0000210void ASTDeclReader::Visit(Decl *D) {
211 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000212
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000213 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
214 if (DD->DeclInfo) {
215 DeclaratorDecl::ExtInfo *Info =
216 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
217 Info->TInfo =
218 GetTypeSourceInfo(Record, Idx);
219 }
220 else {
221 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
222 }
223 }
224
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000225 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000226 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000227 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000228 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
229 // if we have a fully initialized TypeDecl, we can safely read its type now.
230 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000231 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
232 // FunctionDecl's body was written last after all other Stmts/Exprs.
233 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000234 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000235 } else if (D->isTemplateParameter()) {
236 // If we have a fully initialized template parameter, we can now
237 // set its DeclContext.
238 D->setDeclContext(
239 cast_or_null<DeclContext>(
240 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
241 D->setLexicalDeclContext(
242 cast_or_null<DeclContext>(
243 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000244 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000245}
246
Sebastian Redlb3298c32010-08-18 23:56:48 +0000247void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000248 if (D->isTemplateParameter()) {
249 // We don't want to deserialize the DeclContext of a template
250 // parameter immediately, because the template parameter might be
251 // used in the formulation of its DeclContext. Use the translation
252 // unit DeclContext as a placeholder.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000253 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
254 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000255 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000256 } else {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000257 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
258 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000259 }
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +0000260 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner487412d2009-04-27 05:27:42 +0000261 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000262 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000263 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000264 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000265 D->setAttrs(Attrs);
266 }
Chris Lattner487412d2009-04-27 05:27:42 +0000267 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000268 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000269 D->setReferenced(Record[Idx++]);
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +0000270 D->TopLevelDeclInObjCContainer = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000271 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000272 D->FromASTFile = true;
Douglas Gregor26701a42011-09-09 02:06:17 +0000273 D->ModulePrivate = Record[Idx++];
Douglas Gregorcf68c582011-12-01 22:20:10 +0000274
275 // Determine whether this declaration is part of a (sub)module. If so, it
276 // may not yet be visible.
277 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
278 // Module-private declarations are never visible, so there is no work to do.
279 if (!D->ModulePrivate) {
280 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
281 if (Owner->NameVisibility != Module::AllVisible) {
282 // The owning module is not visible. Mark this declaration as
283 // module-private,
284 D->ModulePrivate = true;
285
286 // Note that this declaration was hidden because its owning module is
287 // not yet visible.
288 Reader.HiddenNamesMap[Owner].push_back(D);
289 }
290 }
291 }
292 }
Chris Lattner487412d2009-04-27 05:27:42 +0000293}
294
Sebastian Redlb3298c32010-08-18 23:56:48 +0000295void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000296 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000297}
298
Sebastian Redlb3298c32010-08-18 23:56:48 +0000299void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000300 VisitDecl(ND);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000301 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000302}
303
Sebastian Redlb3298c32010-08-18 23:56:48 +0000304void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000305 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000306 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000307 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor903b7e92011-07-22 00:38:23 +0000308 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000309}
310
Douglas Gregor1f179062011-12-19 14:40:25 +0000311void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000312 VisitRedeclarable(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000313 VisitTypeDecl(TD);
Douglas Gregor1f179062011-12-19 14:40:25 +0000314 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
315}
316
317void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
318 VisitTypedefNameDecl(TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000319}
320
Richard Smithdda56e42011-04-15 14:24:37 +0000321void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000322 VisitTypedefNameDecl(TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000323}
324
Sebastian Redlb3298c32010-08-18 23:56:48 +0000325void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000326 VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000327 VisitTypeDecl(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000328 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000329 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCallf937c022011-10-07 06:10:15 +0000330 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000331 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000332 TD->setFreeStanding(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000333 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000334 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000335 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000336 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000337 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000338 } else
Douglas Gregor7fb09192011-07-21 22:35:25 +0000339 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000340}
341
Sebastian Redlb3298c32010-08-18 23:56:48 +0000342void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000343 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000344 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
345 ED->setIntegerTypeSourceInfo(TI);
346 else
Douglas Gregor903b7e92011-07-22 00:38:23 +0000347 ED->setIntegerType(Reader.readType(F, Record, Idx));
348 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000349 ED->setNumPositiveBits(Record[Idx++]);
350 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000351 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000352 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000353 ED->IsFixed = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000354 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000355}
356
Sebastian Redlb3298c32010-08-18 23:56:48 +0000357void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000358 VisitTagDecl(RD);
359 RD->setHasFlexibleArrayMember(Record[Idx++]);
360 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000361 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000362}
363
Sebastian Redlb3298c32010-08-18 23:56:48 +0000364void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000365 VisitNamedDecl(VD);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000366 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000367}
368
Sebastian Redlb3298c32010-08-18 23:56:48 +0000369void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000370 VisitValueDecl(ECD);
371 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000372 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000373 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
374}
375
Sebastian Redlb3298c32010-08-18 23:56:48 +0000376void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000377 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000378 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000379 if (Record[Idx++]) { // hasExtInfo
380 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000381 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000382 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000383 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000384 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000385}
386
Sebastian Redlb3298c32010-08-18 23:56:48 +0000387void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000388 VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000389 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000390
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000391 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000392 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000393 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikie83d382b2011-09-23 05:06:16 +0000394 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000395 case FunctionDecl::TK_NonTemplate:
396 break;
397 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000398 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
399 Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000400 break;
401 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000402 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000403 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000404 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000405 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000406 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
407 break;
408 }
409 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000410 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
411 Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000412 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
413
414 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000415 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000416 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000417
418 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000419 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000420 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000421 bool HasTemplateArgumentsAsWritten = Record[Idx++];
422 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000423 unsigned NumTemplateArgLocs = Record[Idx++];
424 TemplArgLocs.reserve(NumTemplateArgLocs);
425 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000426 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000427 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000428
Sebastian Redl2c373b92010-10-05 15:59:54 +0000429 LAngleLoc = ReadSourceLocation(Record, Idx);
430 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000431 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000432
Sebastian Redl2c373b92010-10-05 15:59:54 +0000433 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000434
Douglas Gregor4163aca2011-09-09 21:34:22 +0000435 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000436 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000437 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000438 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000439 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000440 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000441 FunctionTemplateSpecializationInfo *FTInfo
442 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
443 TemplArgList,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000444 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
445 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000446 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000447
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000448 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000449 // The template that contains the specializations set. It's not safe to
450 // use getCanonicalDecl on Template since it may still be initializing.
451 FunctionTemplateDecl *CanonTemplate
Douglas Gregor7fb09192011-07-21 22:35:25 +0000452 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000453 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
454 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
455 // FunctionTemplateSpecializationInfo's Profile().
456 // We avoid getASTContext because a decl in the parent hierarchy may
457 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000458 llvm::FoldingSetNodeID ID;
459 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
460 TemplArgs.size(), C);
461 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000462 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000463 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000464 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000465 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000466 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000467 }
468 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
469 // Templates.
470 UnresolvedSet<8> TemplDecls;
471 unsigned NumTemplates = Record[Idx++];
472 while (NumTemplates--)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000473 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000474
475 // Templates args.
476 TemplateArgumentListInfo TemplArgs;
477 unsigned NumArgs = Record[Idx++];
478 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000479 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
480 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
481 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000482
Douglas Gregor4163aca2011-09-09 21:34:22 +0000483 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000484 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000485 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000486 }
487 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000488
Sebastian Redlb3298c32010-08-18 23:56:48 +0000489 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000490 // after everything else is read.
491
Douglas Gregorbf62d642010-12-06 18:36:25 +0000492 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000493 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000494 FD->IsInline = Record[Idx++];
495 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000496 FD->IsVirtualAsWritten = Record[Idx++];
497 FD->IsPure = Record[Idx++];
498 FD->HasInheritedPrototype = Record[Idx++];
499 FD->HasWrittenPrototype = Record[Idx++];
500 FD->IsDeleted = Record[Idx++];
501 FD->IsTrivial = Record[Idx++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000502 FD->IsDefaulted = Record[Idx++];
503 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000504 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smitha77a0a62011-08-15 21:04:07 +0000505 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000506 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000507
Chris Lattnerca025db2010-05-07 21:43:38 +0000508 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000509 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000510 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000511 Params.reserve(NumParams);
512 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000513 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000514 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000515}
516
Sebastian Redlb3298c32010-08-18 23:56:48 +0000517void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000518 VisitNamedDecl(MD);
519 if (Record[Idx++]) {
520 // In practice, this won't be executed (since method definitions
521 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000522 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000523 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
524 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000525 }
526 MD->setInstanceMethod(Record[Idx++]);
527 MD->setVariadic(Record[Idx++]);
528 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000529 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000530
531 MD->IsRedeclaration = Record[Idx++];
532 MD->HasRedeclaration = Record[Idx++];
533 if (MD->HasRedeclaration)
534 Reader.getContext().setObjCMethodRedeclaration(MD,
535 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
536
Chris Lattner487412d2009-04-27 05:27:42 +0000537 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
538 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000539 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000540 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000541 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
542 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000543 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000544 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000545 Params.reserve(NumParams);
546 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000547 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000548
549 MD->SelLocsKind = Record[Idx++];
550 unsigned NumStoredSelLocs = Record[Idx++];
551 SmallVector<SourceLocation, 16> SelLocs;
552 SelLocs.reserve(NumStoredSelLocs);
553 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
554 SelLocs.push_back(ReadSourceLocation(Record, Idx));
555
556 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +0000557}
558
Sebastian Redlb3298c32010-08-18 23:56:48 +0000559void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000560 VisitNamedDecl(CD);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000561 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
562 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000563}
564
Sebastian Redlb3298c32010-08-18 23:56:48 +0000565void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000566 VisitRedeclarable(ID);
Chris Lattner487412d2009-04-27 05:27:42 +0000567 VisitObjCContainerDecl(ID);
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000568 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000569
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000570 ObjCInterfaceDecl *Def = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
571 if (ID == Def) {
572 // Read the definition.
573 ID->allocateDefinitionData();
574
575 ObjCInterfaceDecl::DefinitionData &Data = ID->data();
576
577 // Read the superclass.
578 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
579 Data.SuperClassLoc = ReadSourceLocation(Record, Idx);
580
Douglas Gregor16408322011-12-15 22:34:59 +0000581 Data.EndLoc = ReadSourceLocation(Record, Idx);
582
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000583 // Read the directly referenced protocols and their SourceLocations.
584 unsigned NumProtocols = Record[Idx++];
585 SmallVector<ObjCProtocolDecl *, 16> Protocols;
586 Protocols.reserve(NumProtocols);
587 for (unsigned I = 0; I != NumProtocols; ++I)
588 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
589 SmallVector<SourceLocation, 16> ProtoLocs;
590 ProtoLocs.reserve(NumProtocols);
591 for (unsigned I = 0; I != NumProtocols; ++I)
592 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
593 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
594 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000595
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000596 // Read the transitive closure of protocols referenced by this class.
597 NumProtocols = Record[Idx++];
598 Protocols.clear();
599 Protocols.reserve(NumProtocols);
600 for (unsigned I = 0; I != NumProtocols; ++I)
601 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
602 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols,
603 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000604
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000605 // Read the ivars.
606 unsigned NumIvars = Record[Idx++];
607 SmallVector<ObjCIvarDecl *, 16> IVars;
608 IVars.reserve(NumIvars);
609 for (unsigned I = 0; I != NumIvars; ++I)
610 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
611
612 // Read the categories.
613 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000614
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000615 // We will rebuild this list lazily.
616 ID->setIvarList(0);
617
618 // If there are any pending forward references, make their definition data
619 // pointers point at the newly-allocated data.
620 ASTReader::PendingForwardRefsMap::iterator
621 FindI = Reader.PendingForwardRefs.find(ID);
622 if (FindI != Reader.PendingForwardRefs.end()) {
623 ASTReader::ForwardRefs &Refs = FindI->second;
624 for (ASTReader::ForwardRefs::iterator I = Refs.begin(),
625 E = Refs.end();
626 I != E; ++I)
Douglas Gregora323c4c2011-12-15 18:17:27 +0000627 cast<ObjCInterfaceDecl>(*I)->Data = ID->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000628#ifndef NDEBUG
629 // We later check whether PendingForwardRefs is empty to make sure all
630 // pending references were linked.
631 Reader.PendingForwardRefs.erase(ID);
632#endif
Douglas Gregore80b31f2011-12-19 19:00:47 +0000633
634 // Note that we have deserialized a definition.
635 Reader.PendingDefinitions.insert(ID);
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000636 }
637 } else if (Def) {
638 if (Def->Data) {
639 ID->Data = Def->Data;
640 } else {
641 // The definition is still initializing.
642 Reader.PendingForwardRefs[Def].push_back(ID);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000643 }
644 }
Chris Lattner487412d2009-04-27 05:27:42 +0000645}
646
Sebastian Redlb3298c32010-08-18 23:56:48 +0000647void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000648 VisitFieldDecl(IVD);
649 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000650 // This field will be built lazily.
651 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000652 bool synth = Record[Idx++];
653 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000654}
655
Sebastian Redlb3298c32010-08-18 23:56:48 +0000656void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000657 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000658 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisb97a4022011-11-12 21:07:46 +0000659 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000660 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000661 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000662 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000663 ProtoRefs.reserve(NumProtoRefs);
664 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000665 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000666 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000667 ProtoLocs.reserve(NumProtoRefs);
668 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000669 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000670 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000671 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000672}
673
Sebastian Redlb3298c32010-08-18 23:56:48 +0000674void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000675 VisitFieldDecl(FD);
676}
677
Sebastian Redlb3298c32010-08-18 23:56:48 +0000678void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000679 VisitDecl(CD);
Douglas Gregor40d009f2011-12-14 17:12:03 +0000680 CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
681 CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000682}
683
Sebastian Redlb3298c32010-08-18 23:56:48 +0000684void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000685 VisitDecl(FPD);
686 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000687 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000688 ProtoRefs.reserve(NumProtoRefs);
689 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000690 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000691 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000692 ProtoLocs.reserve(NumProtoRefs);
693 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000694 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000695 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000696 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000697}
698
Sebastian Redlb3298c32010-08-18 23:56:48 +0000699void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000700 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000701 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000702 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000703 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000704 ProtoRefs.reserve(NumProtoRefs);
705 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000706 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000707 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000708 ProtoLocs.reserve(NumProtoRefs);
709 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000710 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000711 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000712 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000713 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000714 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000715 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000716}
717
Sebastian Redlb3298c32010-08-18 23:56:48 +0000718void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000719 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000720 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000721}
722
Sebastian Redlb3298c32010-08-18 23:56:48 +0000723void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000724 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000725 D->setAtLoc(ReadSourceLocation(Record, Idx));
726 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000727 // FIXME: stable encoding
728 D->setPropertyAttributes(
729 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000730 D->setPropertyAttributesAsWritten(
731 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000732 // FIXME: stable encoding
733 D->setPropertyImplementation(
734 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000735 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
736 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000737 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
738 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
739 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000740}
741
Sebastian Redlb3298c32010-08-18 23:56:48 +0000742void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000743 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000744 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000745}
746
Sebastian Redlb3298c32010-08-18 23:56:48 +0000747void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000748 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000749 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000750 D->CategoryNameLoc = ReadSourceLocation(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000751}
752
Sebastian Redlb3298c32010-08-18 23:56:48 +0000753void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000754 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000755 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000756 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000757 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000758 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000759}
760
761
Sebastian Redlb3298c32010-08-18 23:56:48 +0000762void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000763 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000764 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000765 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
766 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000767 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000768 D->setGetterCXXConstructor(Reader.ReadExpr(F));
769 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000770}
771
Sebastian Redlb3298c32010-08-18 23:56:48 +0000772void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000773 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000774 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000775 int BitWidthOrInitializer = Record[Idx++];
776 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000777 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000778 else if (BitWidthOrInitializer == 2)
779 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000780 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000781 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000782 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000783 }
Chris Lattner487412d2009-04-27 05:27:42 +0000784}
785
Francois Pichet783dd6e2010-11-21 06:08:52 +0000786void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
787 VisitValueDecl(FD);
788
789 FD->ChainingSize = Record[Idx++];
790 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000791 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000792
793 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000794 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000795}
796
Sebastian Redlb3298c32010-08-18 23:56:48 +0000797void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000798 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000799 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000800 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
801 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
802 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
803 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
804 VD->VarDeclBits.ExceptionVar = Record[Idx++];
805 VD->VarDeclBits.NRVOVariable = Record[Idx++];
806 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000807 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smithd0b4dd62011-12-19 06:19:21 +0000808 if (uint64_t Val = Record[Idx++]) {
Sebastian Redl2c373b92010-10-05 15:59:54 +0000809 VD->setInit(Reader.ReadExpr(F));
Richard Smithd0b4dd62011-12-19 06:19:21 +0000810 if (Val > 1) {
811 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
812 Eval->CheckedICE = true;
813 Eval->IsICE = Val == 3;
814 }
815 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000816
817 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000818 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000819 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000820 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000821 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000822 }
Chris Lattner487412d2009-04-27 05:27:42 +0000823}
824
Sebastian Redlb3298c32010-08-18 23:56:48 +0000825void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000826 VisitVarDecl(PD);
827}
828
Sebastian Redlb3298c32010-08-18 23:56:48 +0000829void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000830 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000831 unsigned isObjCMethodParam = Record[Idx++];
832 unsigned scopeDepth = Record[Idx++];
833 unsigned scopeIndex = Record[Idx++];
834 unsigned declQualifier = Record[Idx++];
835 if (isObjCMethodParam) {
836 assert(scopeDepth == 0);
837 PD->setObjCMethodScopeInfo(scopeIndex);
838 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
839 } else {
840 PD->setScopeInfo(scopeDepth, scopeIndex);
841 }
John McCallbeaa11c2011-05-01 02:13:58 +0000842 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
843 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000844 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000845 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000846}
847
Sebastian Redlb3298c32010-08-18 23:56:48 +0000848void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000849 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000850 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000851 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000852}
853
Sebastian Redlb3298c32010-08-18 23:56:48 +0000854void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000855 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000856 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
857 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000858 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000859 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000860 Params.reserve(NumParams);
861 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000862 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000863 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000864
865 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000866 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000867 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000868 captures.reserve(numCaptures);
869 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000870 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000871 unsigned flags = Record[Idx++];
872 bool byRef = (flags & 1);
873 bool nested = (flags & 2);
874 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
875
876 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
877 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000878 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000879 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000880}
881
Sebastian Redlb3298c32010-08-18 23:56:48 +0000882void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000883 VisitDecl(D);
884 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000885 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000886 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000887}
888
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000889void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
890 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000891 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000892}
893
894
Sebastian Redlb3298c32010-08-18 23:56:48 +0000895void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000896 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000897 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000898 D->LocStart = ReadSourceLocation(Record, Idx);
899 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000900 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000901
Chris Lattnerca025db2010-05-07 21:43:38 +0000902 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000903 // FIXME: Modules will likely have trouble with pointing directly at
904 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000905 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000906 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000907}
908
Sebastian Redlb3298c32010-08-18 23:56:48 +0000909void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000910 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000911 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000912 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000913 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000914 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000915}
916
Sebastian Redlb3298c32010-08-18 23:56:48 +0000917void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000918 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000919 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000920 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000921 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000922 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000923 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000924 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000925 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000926}
927
Sebastian Redlb3298c32010-08-18 23:56:48 +0000928void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000929 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000930 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
931 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
932 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000933 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000934 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000935}
936
Sebastian Redlb3298c32010-08-18 23:56:48 +0000937void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000938 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000939 D->UsingLoc = ReadSourceLocation(Record, Idx);
940 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000941 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000942 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
943 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000944}
945
Sebastian Redlb3298c32010-08-18 23:56:48 +0000946void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000947 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000948 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000949 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000950 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000951}
952
Sebastian Redlb3298c32010-08-18 23:56:48 +0000953void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000954 UnresolvedUsingTypenameDecl *D) {
955 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000956 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000957 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000958}
959
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000960void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000961 struct CXXRecordDecl::DefinitionData &Data,
962 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000963 Data.UserDeclaredConstructor = Record[Idx++];
964 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000965 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000966 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000967 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000968 Data.UserDeclaredDestructor = Record[Idx++];
969 Data.Aggregate = Record[Idx++];
970 Data.PlainOldData = Record[Idx++];
971 Data.Empty = Record[Idx++];
972 Data.Polymorphic = Record[Idx++];
973 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000974 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000975 Data.HasNoNonEmptyBases = Record[Idx++];
976 Data.HasPrivateFields = Record[Idx++];
977 Data.HasProtectedFields = Record[Idx++];
978 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000979 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000980 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000981 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000982 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000983 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000984 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000985 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000986 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000987 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000988 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000989 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000990 Data.DeclaredDefaultConstructor = Record[Idx++];
991 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000992 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000993 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000994 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000995 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000996 Data.FailedImplicitMoveConstructor = Record[Idx++];
997 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000998
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000999 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001000 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +00001001 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001002 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001003 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +00001004 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001005
Douglas Gregor7fb09192011-07-21 22:35:25 +00001006 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
1007 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001008 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001009 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001010}
1011
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001012void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
1013 CXXRecordDecl *DefinitionDecl,
1014 const RecordData &Record,
1015 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001016 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +00001017
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001018 if (D == DefinitionDecl) {
1019 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001020 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001021 // We read the definition info. Check if there are pending forward
1022 // references that need to point to this DefinitionData pointer.
1023 ASTReader::PendingForwardRefsMap::iterator
1024 FindI = Reader.PendingForwardRefs.find(D);
1025 if (FindI != Reader.PendingForwardRefs.end()) {
1026 ASTReader::ForwardRefs &Refs = FindI->second;
1027 for (ASTReader::ForwardRefs::iterator
1028 I = Refs.begin(), E = Refs.end(); I != E; ++I)
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001029 cast<CXXRecordDecl>(*I)->DefinitionData = D->DefinitionData;
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001030#ifndef NDEBUG
1031 // We later check whether PendingForwardRefs is empty to make sure all
1032 // pending references were linked.
1033 Reader.PendingForwardRefs.erase(D);
1034#endif
1035 }
Douglas Gregore80b31f2011-12-19 19:00:47 +00001036
1037 // Note that we have deserialized a definition.
1038 Reader.PendingDefinitions.insert(D);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +00001039 } else if (DefinitionDecl) {
1040 if (DefinitionDecl->DefinitionData) {
1041 D->DefinitionData = DefinitionDecl->DefinitionData;
1042 } else {
1043 // The definition is still initializing.
1044 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
1045 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001046 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001047}
1048
1049void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
1050 VisitRecordDecl(D);
1051
Douglas Gregor7fb09192011-07-21 22:35:25 +00001052 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001053 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
1054
Douglas Gregor4163aca2011-09-09 21:34:22 +00001055 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001056
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001057 enum CXXRecKind {
1058 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1059 };
1060 switch ((CXXRecKind)Record[Idx++]) {
1061 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001062 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001063 case CXXRecNotTemplate:
1064 break;
1065 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +00001066 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001067 break;
1068 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001069 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001070 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001071 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001072 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1073 MSI->setPointOfInstantiation(POI);
1074 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001075 break;
1076 }
1077 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001078
1079 // Load the key function to avoid deserializing every method so we can
1080 // compute it.
John McCallf937c022011-10-07 06:10:15 +00001081 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001082 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001083 C.KeyFunctions[D] = Key;
1084 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001085}
1086
Sebastian Redlb3298c32010-08-18 23:56:48 +00001087void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001088 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001089 unsigned NumOverridenMethods = Record[Idx++];
1090 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001091 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1092 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001093 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001094 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001095 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001096}
1097
Sebastian Redlb3298c32010-08-18 23:56:48 +00001098void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001099 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001100
1101 D->IsExplicitSpecified = Record[Idx++];
1102 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001103 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1104 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001105}
1106
Sebastian Redlb3298c32010-08-18 23:56:48 +00001107void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001108 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001109
1110 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001111 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001112}
1113
Sebastian Redlb3298c32010-08-18 23:56:48 +00001114void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001115 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001116 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001117}
1118
Douglas Gregorba345522011-12-02 23:23:56 +00001119void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1120 VisitDecl(D);
1121 D->ImportedAndComplete.setPointer(readModule(Record, Idx));
1122 D->ImportedAndComplete.setInt(Record[Idx++]);
1123 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1);
1124 for (unsigned I = 0, N = Record.back(); I != N; ++I)
1125 StoredLocs[I] = ReadSourceLocation(Record, Idx);
1126 ++Idx;
1127}
1128
Sebastian Redlb3298c32010-08-18 23:56:48 +00001129void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001130 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001131 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001132}
1133
Sebastian Redlb3298c32010-08-18 23:56:48 +00001134void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001135 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001136 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001137 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001138 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001139 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001140 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001141 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001142 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001143}
1144
Sebastian Redlb3298c32010-08-18 23:56:48 +00001145void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001146 VisitDecl(D);
1147 unsigned NumParams = Record[Idx++];
1148 D->NumParams = NumParams;
1149 D->Params = new TemplateParameterList*[NumParams];
1150 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001151 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001152 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001153 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001154 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001155 D->Friend = GetTypeSourceInfo(Record, Idx);
1156 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001157}
1158
Sebastian Redlb3298c32010-08-18 23:56:48 +00001159void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001160 VisitNamedDecl(D);
1161
Douglas Gregor7fb09192011-07-21 22:35:25 +00001162 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001163 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001164 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001165 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001166}
1167
Sebastian Redlb3298c32010-08-18 23:56:48 +00001168void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001169 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1170 // can be used while this is still initializing.
Douglas Gregore80b31f2011-12-19 19:00:47 +00001171 enum RedeclKind { FirstDeclaration, FirstInFile, PointsToPrevious };
Douglas Gregor074a4092011-12-19 18:19:24 +00001172 RedeclKind Kind = (RedeclKind)Record[Idx++];
1173
1174 // Determine the first declaration ID.
1175 DeclID FirstDeclID;
1176 switch (Kind) {
1177 case FirstDeclaration: {
1178 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001179
Douglas Gregor074a4092011-12-19 18:19:24 +00001180 // Since this is the first declaration of the template, fill in the
1181 // information for the 'common' pointer.
1182 if (D->CommonOrPrev.isNull()) {
1183 RedeclarableTemplateDecl::CommonBase *Common
1184 = D->newCommon(Reader.getContext());
1185 Common->Latest = D;
1186 D->CommonOrPrev = Common;
1187 }
1188
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001189 if (RedeclarableTemplateDecl *RTD
Douglas Gregor074a4092011-12-19 18:19:24 +00001190 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001191 assert(RTD->getKind() == D->getKind() &&
1192 "InstantiatedFromMemberTemplate kind mismatch");
1193 D->setInstantiatedFromMemberTemplateImpl(RTD);
1194 if (Record[Idx++])
1195 D->setMemberSpecialization();
1196 }
Douglas Gregor074a4092011-12-19 18:19:24 +00001197 break;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001198 }
Douglas Gregore80b31f2011-12-19 19:00:47 +00001199
1200 case FirstInFile:
Douglas Gregor074a4092011-12-19 18:19:24 +00001201 case PointsToPrevious: {
1202 FirstDeclID = ReadDeclID(Record, Idx);
1203 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1204
1205 RedeclarableTemplateDecl *FirstDecl
1206 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1207
1208 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1209 // We temporarily set the first (canonical) declaration as the previous one
1210 // which is the one that matters and mark the real previous DeclID to be
1211 // loaded and attached later on.
1212 D->CommonOrPrev = FirstDecl;
1213
Douglas Gregore80b31f2011-12-19 19:00:47 +00001214 if (Kind == PointsToPrevious) {
1215 // Make a note that we need to wire up this declaration to its
1216 // previous declaration, later. We don't need to do this for the first
1217 // declaration in any given module file, because those will be wired
1218 // together later.
1219 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PrevDeclID));
1220 }
Douglas Gregor074a4092011-12-19 18:19:24 +00001221 break;
1222 }
1223 }
1224
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001225 VisitTemplateDecl(D);
1226 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001227}
1228
Sebastian Redlb3298c32010-08-18 23:56:48 +00001229void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001230 VisitRedeclarableTemplateDecl(D);
1231
1232 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001233 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1234 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001235 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001236 SpecIDs.push_back(0);
1237
1238 // Specializations.
1239 unsigned Size = Record[Idx++];
1240 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001241 for (unsigned I = 0; I != Size; ++I)
1242 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001243
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001244 // Partial specializations.
1245 Size = Record[Idx++];
1246 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001247 for (unsigned I = 0; I != Size; ++I)
1248 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001249
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001250 if (SpecIDs[0]) {
1251 typedef serialization::DeclID DeclID;
1252
1253 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1254 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001255 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001256 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1257 SpecIDs.size() * sizeof(DeclID));
1258 }
1259
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001260 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001261 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001262}
1263
Sebastian Redlb3298c32010-08-18 23:56:48 +00001264void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001265 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001266 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001267
Douglas Gregor4163aca2011-09-09 21:34:22 +00001268 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001269 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001270 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001271 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001272 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001273 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001274 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001275 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001276 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1277 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001278 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1279 = new (C) ClassTemplateSpecializationDecl::
1280 SpecializedPartialSpecialization();
1281 PS->PartialSpecialization
1282 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1283 PS->TemplateArgs = ArgList;
1284 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001285 }
1286 }
1287
1288 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001289 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001290 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1291 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1292 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001293 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1294 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001295 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001296 }
1297
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001298 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001299 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001300 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1301 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001302 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001303 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001304
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001305 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001306 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001307 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001308 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1309 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001310 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001311 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001312 }
1313 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001314}
1315
Sebastian Redlb3298c32010-08-18 23:56:48 +00001316void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001317 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001318 VisitClassTemplateSpecializationDecl(D);
1319
Douglas Gregor4163aca2011-09-09 21:34:22 +00001320 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001321 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001322
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001323 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001324 if (NumArgs) {
1325 D->NumArgsAsWritten = NumArgs;
1326 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1327 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001328 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001329 }
1330
1331 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001332
1333 // These are read/set from/to the first declaration.
1334 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001335 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001336 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001337 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001338 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001339}
1340
Sebastian Redlb7448632011-08-31 13:59:56 +00001341void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1342 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001343 VisitDecl(D);
1344 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1345}
1346
Sebastian Redlb3298c32010-08-18 23:56:48 +00001347void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001348 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001349
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001350 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001351 // This FunctionTemplateDecl owns a CommonPtr; read it.
1352
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001353 // Read the function specialization declarations.
1354 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001355 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001356 unsigned NumSpecs = Record[Idx++];
1357 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001358 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001359 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001360}
1361
Sebastian Redlb3298c32010-08-18 23:56:48 +00001362void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001363 VisitTypeDecl(D);
1364
1365 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001366
1367 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001368 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001369 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001370}
1371
Sebastian Redlb3298c32010-08-18 23:56:48 +00001372void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001373 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001374 // TemplateParmPosition.
1375 D->setDepth(Record[Idx++]);
1376 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001377 if (D->isExpandedParameterPack()) {
1378 void **Data = reinterpret_cast<void **>(D + 1);
1379 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001380 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001381 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1382 }
1383 } else {
1384 // Rest of NonTypeTemplateParmDecl.
1385 D->ParameterPack = Record[Idx++];
1386 if (Record[Idx++]) {
1387 Expr *DefArg = Reader.ReadExpr(F);
1388 bool Inherited = Record[Idx++];
1389 D->setDefaultArgument(DefArg, Inherited);
1390 }
1391 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001392}
1393
Sebastian Redlb3298c32010-08-18 23:56:48 +00001394void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001395 VisitTemplateDecl(D);
1396 // TemplateParmPosition.
1397 D->setDepth(Record[Idx++]);
1398 D->setPosition(Record[Idx++]);
1399 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001400 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001401 bool IsInherited = Record[Idx++];
1402 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001403 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001404}
1405
Richard Smith3f1b5d02011-05-05 21:57:07 +00001406void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1407 VisitRedeclarableTemplateDecl(D);
1408}
1409
Sebastian Redlb3298c32010-08-18 23:56:48 +00001410void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001411 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001412 D->AssertExpr = Reader.ReadExpr(F);
1413 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001414 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001415}
1416
Mike Stump11289f42009-09-09 15:08:12 +00001417std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001418ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001419 uint64_t LexicalOffset = Record[Idx++];
1420 uint64_t VisibleOffset = Record[Idx++];
1421 return std::make_pair(LexicalOffset, VisibleOffset);
1422}
1423
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001424template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001425void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Douglas Gregore80b31f2011-12-19 19:00:47 +00001426 enum RedeclKind { FirstDeclaration = 0, FirstInFile, PointsToPrevious };
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001427 RedeclKind Kind = (RedeclKind)Record[Idx++];
Douglas Gregor05f10352011-12-17 23:38:30 +00001428
Douglas Gregor074a4092011-12-19 18:19:24 +00001429 DeclID FirstDeclID;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001430 switch (Kind) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001431 case FirstDeclaration:
1432 FirstDeclID = ThisDeclID;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001433 break;
Douglas Gregore80b31f2011-12-19 19:00:47 +00001434
1435 case FirstInFile:
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001436 case PointsToPrevious: {
Douglas Gregor074a4092011-12-19 18:19:24 +00001437 FirstDeclID = ReadDeclID(Record, Idx);
1438 DeclID PrevDeclID = ReadDeclID(Record, Idx);
1439
1440 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
Douglas Gregor05f10352011-12-17 23:38:30 +00001441
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001442 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1443 // We temporarily set the first (canonical) declaration as the previous one
1444 // which is the one that matters and mark the real previous DeclID to be
1445 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001446 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Douglas Gregor3e300102011-10-26 17:53:41 +00001447
Douglas Gregore80b31f2011-12-19 19:00:47 +00001448 if (Kind == PointsToPrevious) {
1449 // Make a note that we need to wire up this declaration to its
1450 // previous declaration, later. We don't need to do this for the first
1451 // declaration in any given module file, because those will be wired
1452 // together later.
1453 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1454 PrevDeclID));
1455 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001456 break;
1457 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001458 }
Douglas Gregor074a4092011-12-19 18:19:24 +00001459
1460 // Note that we need to load the other declaration chains for this ID.
1461 if (Reader.PendingDeclChainsKnown.insert(ThisDeclID))
1462 Reader.PendingDeclChains.push_back(ThisDeclID);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001463}
1464
Chris Lattner487412d2009-04-27 05:27:42 +00001465//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001466// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001467//===----------------------------------------------------------------------===//
1468
Chris Lattner8f63ab52009-04-27 06:01:06 +00001469/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00001470void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001471 const RecordData &Record, unsigned &Idx) {
1472 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001473 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001474 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001475 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001476
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001477#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001478
1479 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001480 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001481 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001482}
1483
1484//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001485// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001486//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001487
1488/// \brief Note that we have loaded the declaration with the given
1489/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001490///
Chris Lattner487412d2009-04-27 05:27:42 +00001491/// This routine notes that this declaration has already been loaded,
1492/// so that future GetDecl calls will return this declaration rather
1493/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001494inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001495 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1496 DeclsLoaded[Index] = D;
1497}
1498
1499
1500/// \brief Determine whether the consumer will be interested in seeing
1501/// this declaration (via HandleTopLevelDecl).
1502///
1503/// This routine should return true for anything that might affect
1504/// code generation, e.g., inline function definitions, Objective-C
1505/// declarations with metadata, etc.
1506static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001507 // An ObjCMethodDecl is never considered as "interesting" because its
1508 // implementation container always is.
1509
Douglas Gregor87d81242011-09-10 00:22:34 +00001510 if (isa<FileScopeAsmDecl>(D) ||
1511 isa<ObjCProtocolDecl>(D) ||
1512 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001513 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001514 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001515 return Var->isFileVarDecl() &&
1516 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001517 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001518 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001519
1520 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001521}
1522
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001523/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001524ASTReader::RecordLocation
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001525ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001526 // See if there's an override.
1527 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00001528 if (It != ReplacedDecls.end()) {
1529 RawLocation = It->second.RawLoc;
1530 return RecordLocation(It->second.Mod, It->second.Offset);
1531 }
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001532
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001533 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1534 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00001535 ModuleFile *M = I->second;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001536 const DeclOffset &
1537 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1538 RawLocation = DOffs.Loc;
1539 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00001540}
1541
Douglas Gregord32f0352011-07-22 06:10:01 +00001542ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001543 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001544 = GlobalBitOffsetsMap.find(GlobalOffset);
1545
1546 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1547 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1548}
1549
Douglas Gregorde3ef502011-11-30 23:21:26 +00001550uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00001551 return LocalOffset + M.GlobalBitOffset;
1552}
1553
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001554void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1555 assert(D && previous);
1556 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1557 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1558 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1559 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1560 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1561 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
Douglas Gregor05f10352011-12-17 23:38:30 +00001562 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1563 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
1564 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregorab1ec82e2011-12-16 03:12:41 +00001565 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001566 } else {
1567 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1568 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1569 }
1570}
1571
Douglas Gregor05f10352011-12-17 23:38:30 +00001572void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
1573 assert(D && Latest);
1574 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1575 TD->RedeclLink
1576 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
1577 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1578 FD->RedeclLink
1579 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
1580 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1581 VD->RedeclLink
1582 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
1583 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
1584 TD->RedeclLink
1585 = Redeclarable<TypedefNameDecl>::LatestDeclLink(
1586 cast<TypedefNameDecl>(Latest));
1587 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
1588 ID->RedeclLink
1589 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
1590 cast<ObjCInterfaceDecl>(Latest));
1591 } else {
1592 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1593 TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest);
1594 }
1595}
1596
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001597void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1598 Decl *previous = GetDecl(ID);
1599 ASTDeclReader::attachPreviousDecl(D, previous);
1600}
1601
Sebastian Redlb3298c32010-08-18 23:56:48 +00001602/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001603Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001604 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001605 unsigned RawLocation = 0;
1606 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001607 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001608 // Keep track of where we are in the stream, then jump back there
1609 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001610 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001611
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001612 ReadingKindTracker ReadingKind(Read_Decl, *this);
1613
Douglas Gregor1342e842009-07-06 18:54:52 +00001614 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001615 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001616
Sebastian Redl2c373b92010-10-05 15:59:54 +00001617 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001618 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001619 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001620 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001621 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001622
Chris Lattner1de76db2009-04-27 05:58:23 +00001623 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001624 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001625 case DECL_CONTEXT_LEXICAL:
1626 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001627 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001628 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001629 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001630 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001631 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001632 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001633 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001634 0, 0);
1635 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001636 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001637 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001638 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001639 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001640 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001641 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001642 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001643 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001644 0, llvm::APSInt());
1645 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001646 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001647 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001648 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001649 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001650 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001651 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001652 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001653 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001654 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001655 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001656 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001657 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001658 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001659 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001660 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001661 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001662 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001663 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001664 SourceLocation(), 0,
1665 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001666 SourceLocation(), 0);
1667 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001668 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001669 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001670 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1671 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001672 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001673 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001674 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001675 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001676 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001677 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001678 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001679 SourceLocation(), 0, 0);
1680 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001681 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001682 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001683 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001684 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001685 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001686 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001687 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001688 SourceLocation(),
1689 NestedNameSpecifierLoc(),
1690 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001691 DeclarationName());
1692 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001693 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001694 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001695 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001696 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001697 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001698 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001699 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001700 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001701 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001702 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001703 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001704 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001705 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001706 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001707 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001708 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001709 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001710 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001711 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001712 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001713 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001714 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001715 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001716 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001717 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001718 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001719 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001720 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001721 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001722 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001723 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001724 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001725 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001726 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001727 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001728 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001729 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001730 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001731 Decl::EmptyShell());
1732 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001733 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001734 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001735 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001736 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001737 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001738 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001739 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001740 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001741 SourceLocation(), 0, 0, 0, QualType(),
1742 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001743 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001744 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001745 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001746 SourceLocation(), 0, 0, 0, QualType(),
1747 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001748 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001749 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001750 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001751 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001752 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001753 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001754 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001755 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001756 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001757 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001758 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001759 break;
1760
Sebastian Redl539c5062010-08-18 23:57:32 +00001761 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001762 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001763 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001764 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001765 case DECL_OBJC_INTERFACE:
Douglas Gregorab1ec82e2011-12-16 03:12:41 +00001766 D = ObjCInterfaceDecl::CreateEmpty(Context);
Chris Lattner487412d2009-04-27 05:27:42 +00001767 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001768 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001769 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001770 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001771 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001772 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001773 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001774 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001775 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001776 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001777 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001778 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001779 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001780 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001781 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001782 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001783 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001784 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001785 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001786 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001787 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001788 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001789 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001790 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +00001791 SourceLocation(), SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001792 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001793 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001794 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1795 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001796 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001797 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001798 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001799 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001800 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001801 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001802 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001803 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001804 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001805 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001806 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001807 ObjCPropertyImplDecl::Dynamic, 0,
1808 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001809 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001810 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001811 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001812 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001813 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001814 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001815 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001816 0, 0);
1817 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001818 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001819 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001820 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001821 break;
1822
Sebastian Redl539c5062010-08-18 23:57:32 +00001823 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001824 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001825 break;
1826
Sebastian Redl539c5062010-08-18 23:57:32 +00001827 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001828 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001829 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001830 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001831 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001832 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001833 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001834 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001835 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001836 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001837 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001838 case DECL_CXX_BASE_SPECIFIERS:
1839 Error("attempt to read a C++ base-specifier record as a declaration");
1840 return 0;
Douglas Gregorba345522011-12-02 23:23:56 +00001841 case DECL_IMPORT:
1842 // Note: last entry of the ImportDecl record is the number of stored source
1843 // locations.
1844 D = ImportDecl::CreateEmpty(Context, Record.back());
1845 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001846 }
Chris Lattner487412d2009-04-27 05:27:42 +00001847
Sebastian Redlb3298c32010-08-18 23:56:48 +00001848 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001849 LoadedDecl(Index, D);
1850 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001851
1852 // If this declaration is also a declaration context, get the
1853 // offsets for its tables of lexical and visible declarations.
1854 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1855 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1856 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001857 if (Offsets.first != 0)
1858 DC->setHasExternalLexicalStorage(true);
1859 if (Offsets.second != 0)
1860 DC->setHasExternalVisibleStorage(true);
1861 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1862 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001863 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001864 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001865
Sebastian Redlf830df42011-04-24 16:27:54 +00001866 // Now add the pending visible updates for this decl context, if it has any.
1867 DeclContextVisibleUpdatesPending::iterator I =
1868 PendingVisibleUpdates.find(ID);
1869 if (I != PendingVisibleUpdates.end()) {
1870 // There are updates. This means the context has external visible
1871 // storage, even if the original stored version didn't.
1872 DC->setHasExternalVisibleStorage(true);
1873 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001874 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1875 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001876 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001877 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001878 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001879 }
1880 }
1881 assert(Idx == Record.size());
1882
Douglas Gregordab42432011-08-12 00:15:20 +00001883 // Load any relevant update records.
1884 loadDeclUpdateRecords(ID, D);
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001885
1886 // Load the category chain after recursive loading is finished.
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001887 if (ObjCChainedCategoriesInterfaces.count(ID))
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00001888 PendingChainedObjCCategories.push_back(
1889 std::make_pair(cast<ObjCInterfaceDecl>(D), ID));
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001890
Douglas Gregordab42432011-08-12 00:15:20 +00001891 // If we have deserialized a declaration that has a definition the
1892 // AST consumer might need to know about, queue it.
1893 // We don't pass it to the consumer immediately because we may be in recursive
1894 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001895 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001896 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001897
Douglas Gregordab42432011-08-12 00:15:20 +00001898 return D;
1899}
1900
1901void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001902 // The declaration may have been modified by files later in the chain.
1903 // If this is the case, read the record containing the updates from each file
1904 // and pass it to ASTDeclReader to make the modifications.
1905 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1906 if (UpdI != DeclUpdateOffsets.end()) {
1907 FileOffsetsTy &UpdateOffsets = UpdI->second;
1908 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001909 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00001910 ModuleFile *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001911 uint64_t Offset = I->second;
1912 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1913 SavedStreamPosition SavedPosition(Cursor);
1914 Cursor.JumpToBit(Offset);
1915 RecordData Record;
1916 unsigned Code = Cursor.ReadCode();
1917 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1918 (void)RecCode;
1919 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001920
1921 unsigned Idx = 0;
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00001922 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001923 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001924 }
1925 }
Chris Lattner487412d2009-04-27 05:27:42 +00001926}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001927
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001928namespace {
Douglas Gregor05f10352011-12-17 23:38:30 +00001929 struct CompareLocalRedeclarationsInfoToID {
1930 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) {
1931 return X.FirstID < Y;
1932 }
1933
1934 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) {
1935 return X < Y.FirstID;
1936 }
1937
1938 bool operator()(const LocalRedeclarationsInfo &X,
1939 const LocalRedeclarationsInfo &Y) {
1940 return X.FirstID < Y.FirstID;
1941 }
1942 bool operator()(DeclID X, DeclID Y) {
1943 return X < Y;
1944 }
1945 };
1946
1947 class RedeclChainVisitor {
1948 ASTReader &Reader;
1949 DeclID GlobalFirstID;
1950 llvm::SmallVector<std::pair<Decl *, Decl *>, 4> Chains;
1951
1952 public:
1953 RedeclChainVisitor(ASTReader &Reader, DeclID GlobalFirstID)
1954 : Reader(Reader), GlobalFirstID(GlobalFirstID) { }
1955
1956 static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
1957 if (Preorder)
1958 return false;
1959
1960 return static_cast<RedeclChainVisitor *>(UserData)->visit(M);
1961 }
1962
1963 bool visit(ModuleFile &M) {
1964 // Map global ID of the first declaration down to the local ID
1965 // used in this module file.
1966 DeclID FirstID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalFirstID);
1967 if (!FirstID)
1968 return false;
1969
1970 // Perform a binary search to find the local redeclarations for this
1971 // declaration (if any).
1972 const LocalRedeclarationsInfo *Result
1973 = std::lower_bound(M.RedeclarationsInfo,
1974 M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos,
1975 FirstID, CompareLocalRedeclarationsInfoToID());
1976 if (Result == M.RedeclarationsInfo + M.LocalNumRedeclarationsInfos ||
1977 Result->FirstID != FirstID)
1978 return false;
1979
1980 // Dig out the starting/ending declarations.
1981 Decl *FirstLocalDecl = Reader.GetLocalDecl(M, Result->FirstLocalID);
1982 Decl *LastLocalDecl = Reader.GetLocalDecl(M, Result->LastLocalID);
1983 if (!FirstLocalDecl || !LastLocalDecl)
1984 return false;
1985
1986 // Append this redeclaration chain to the list.
1987 Chains.push_back(std::make_pair(FirstLocalDecl, LastLocalDecl));
1988 return false;
1989 }
1990
1991 ArrayRef<std::pair<Decl *, Decl *> > getChains() const {
1992 return Chains;
1993 }
1994
1995 void addParsed(Decl *FirstParsedDecl, Decl *LastParsedDecl) {
1996 Chains.push_back(std::make_pair(FirstParsedDecl, LastParsedDecl));
1997 }
1998 };
1999}
2000
2001/// \brief Retrieve the previous declaration to D.
2002static Decl *getPreviousDecl(Decl *D) {
2003 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2004 return TD->getPreviousDeclaration();
2005 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2006 return FD->getPreviousDeclaration();
2007 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2008 return VD->getPreviousDeclaration();
2009 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2010 return TD->getPreviousDeclaration();
2011 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2012 return ID->getPreviousDeclaration();
2013
2014 return cast<RedeclarableTemplateDecl>(D)->getPreviousDeclaration();
2015}
2016
2017/// \brief Retrieve the most recent declaration of D.
2018static Decl *getMostRecentDecl(Decl *D) {
2019 if (TagDecl *TD = dyn_cast<TagDecl>(D))
2020 return TD->getMostRecentDeclaration();
2021 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2022 return FD->getMostRecentDeclaration();
2023 if (VarDecl *VD = dyn_cast<VarDecl>(D))
2024 return VD->getMostRecentDeclaration();
2025 if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D))
2026 return TD->getMostRecentDeclaration();
2027 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
2028 return ID->getMostRecentDeclaration();
2029
2030 return cast<RedeclarableTemplateDecl>(D)->getMostRecentDeclaration();
2031}
2032
2033void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
2034 // Build up the list of redeclaration chains.
2035 RedeclChainVisitor Visitor(*this, ID);
2036 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor);
2037
2038 // Retrieve the chains.
2039 ArrayRef<std::pair<Decl *, Decl *> > Chains = Visitor.getChains();
2040 if (Chains.empty())
2041 return;
2042
2043 // FIXME: Splice local (not from AST file) declarations into the list,
2044 // rather than always re-ordering them.
2045 Decl *CanonDecl = GetDecl(ID);
2046
2047 // Capture all of the parsed declarations and put them at the end.
2048 Decl *MostRecent = getMostRecentDecl(CanonDecl);
2049 Decl *FirstParsed = MostRecent;
2050 if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) {
2051 Decl *Current = MostRecent;
2052 while (Decl *Prev = getPreviousDecl(Current)) {
2053 if (Prev->isFromASTFile()) {
2054 Current = Prev;
2055 continue;
2056 }
2057
2058 // Chain all of the parsed declarations together.
2059 ASTDeclReader::attachPreviousDecl(FirstParsed, Prev);
2060 FirstParsed = Prev;
2061 Current = Prev;
2062 }
2063
2064 Visitor.addParsed(FirstParsed, MostRecent);
2065 }
2066
2067 // Hook up the separate chains.
2068 Chains = Visitor.getChains();
2069 for (unsigned I = 1, N = Chains.size(); I != N; ++I)
2070 ASTDeclReader::attachPreviousDecl(Chains[I].first, Chains[I-1].second);
2071 ASTDeclReader::attachLatestDecl(CanonDecl, Chains.back().second);
2072}
2073
2074namespace {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002075 /// \brief Given an ObjC interface, goes through the modules and links to the
2076 /// interface all the categories for it.
2077 class ObjCChainedCategoriesVisitor {
2078 ASTReader &Reader;
2079 serialization::GlobalDeclID InterfaceID;
2080 ObjCInterfaceDecl *Interface;
2081 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
2082 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
2083
2084 public:
2085 ObjCChainedCategoriesVisitor(ASTReader &Reader,
2086 serialization::GlobalDeclID InterfaceID,
2087 ObjCInterfaceDecl *Interface)
2088 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
2089 GlobHeadCat(0), GlobTailCat(0) { }
2090
Douglas Gregorde3ef502011-11-30 23:21:26 +00002091 static bool visit(ModuleFile &M, void *UserData) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002092 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
2093 }
2094
Douglas Gregorde3ef502011-11-30 23:21:26 +00002095 bool visit(ModuleFile &M) {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002096 if (Reader.isDeclIDFromModule(InterfaceID, M))
2097 return true; // We reached the module where the interface originated
2098 // from. Stop traversing the imported modules.
2099
Douglas Gregorde3ef502011-11-30 23:21:26 +00002100 ModuleFile::ChainedObjCCategoriesMap::iterator
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002101 I = M.ChainedObjCCategories.find(InterfaceID);
2102 if (I == M.ChainedObjCCategories.end())
2103 return false;
2104
2105 ObjCCategoryDecl *
2106 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
2107 ObjCCategoryDecl *
2108 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
2109
2110 addCategories(HeadCat, TailCat);
2111 return false;
2112 }
2113
2114 void addCategories(ObjCCategoryDecl *HeadCat,
2115 ObjCCategoryDecl *TailCat = 0) {
2116 if (!HeadCat) {
2117 assert(!TailCat);
2118 return;
2119 }
2120
2121 if (!TailCat) {
2122 TailCat = HeadCat;
2123 while (TailCat->getNextClassCategory())
2124 TailCat = TailCat->getNextClassCategory();
2125 }
2126
2127 if (!GlobHeadCat) {
2128 GlobHeadCat = HeadCat;
2129 GlobTailCat = TailCat;
2130 } else {
2131 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
2132 GlobTailCat = TailCat;
2133 }
2134
2135 llvm::DenseSet<DeclarationName> Checked;
2136 for (ObjCCategoryDecl *Cat = HeadCat,
2137 *CatEnd = TailCat->getNextClassCategory();
2138 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
2139 if (Checked.count(Cat->getDeclName()))
2140 continue;
2141 Checked.insert(Cat->getDeclName());
2142 checkForDuplicate(Cat);
2143 }
2144 }
2145
2146 /// \brief Warns for duplicate categories that come from different modules.
2147 void checkForDuplicate(ObjCCategoryDecl *Cat) {
2148 DeclarationName Name = Cat->getDeclName();
2149 // Find the top category with the same name. We do not want to warn for
2150 // duplicates along the established chain because there were already
2151 // warnings for them when the module was created. We only want to warn for
2152 // duplicates between non-dependent modules:
2153 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00002154 // MT //
2155 // / \ //
2156 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002157 //
2158 // We want to warn for duplicates between ML and MR,not between ML and MT.
2159 //
2160 // FIXME: We should not warn for duplicates in diamond:
2161 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00002162 // MT //
2163 // / \ //
2164 // ML MR //
2165 // \ / //
2166 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00002167 //
2168 // If there are duplicates in ML/MR, there will be warning when creating
2169 // MB *and* when importing MB. We should not warn when importing.
2170 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
2171 Next = Next->getNextClassCategory()) {
2172 if (Next->getDeclName() == Name)
2173 Cat = Next;
2174 }
2175
2176 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
2177 if (!PrevCat)
2178 PrevCat = Cat;
2179
2180 if (PrevCat != Cat) {
2181 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
2182 << Interface->getDeclName() << Name;
2183 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
2184 }
2185 }
2186
2187 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
2188 };
2189}
2190
2191void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
2192 ObjCInterfaceDecl *D) {
2193 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
2194 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
2195 // Also add the categories that the interface already links to.
2196 Visitor.addCategories(D->getCategoryList());
2197 D->setCategoryList(Visitor.getHeadCategory());
2198}
Douglas Gregordab42432011-08-12 00:15:20 +00002199
Douglas Gregorde3ef502011-11-30 23:21:26 +00002200void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002201 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002202 unsigned Idx = 0;
2203 while (Idx < Record.size()) {
2204 switch ((DeclUpdateKind)Record[Idx++]) {
2205 case UPD_CXX_SET_DEFINITIONDATA: {
2206 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00002207 CXXRecordDecl *DefinitionDecl
Douglas Gregorde3ef502011-11-30 23:21:26 +00002208 = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002209 assert(!RD->DefinitionData && "DefinitionData is already set!");
2210 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
2211 break;
2212 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002213
2214 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorde3ef502011-11-30 23:21:26 +00002215 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00002216 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00002217
2218 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
2219 // It will be added to the template's specializations set when loaded.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002220 (void)Reader.ReadDecl(ModuleFile, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002221 break;
2222
2223 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00002224 NamespaceDecl *Anon
Douglas Gregorde3ef502011-11-30 23:21:26 +00002225 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00002226 // Guard against these being loaded out of original order. Don't use
2227 // getNextNamespace(), since it tries to access the context and can't in
2228 // the middle of deserialization.
2229 if (!Anon->NextNamespace) {
2230 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
2231 TU->setAnonymousNamespace(Anon);
2232 else
2233 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
2234 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00002235 break;
2236 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002237
2238 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
2239 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
Douglas Gregorde3ef502011-11-30 23:21:26 +00002240 Reader.ReadSourceLocation(ModuleFile, Record, Idx));
Sebastian Redl2ac2c722011-04-29 08:19:30 +00002241 break;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002242
2243 case UPD_OBJC_SET_CLASS_DEFINITIONDATA: {
2244 ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
2245 ObjCInterfaceDecl *Def
2246 = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
Douglas Gregora323c4c2011-12-15 18:17:27 +00002247 if (Def->Data) {
2248 ID->Data = Def->Data;
Douglas Gregor66b310c2011-12-15 18:03:09 +00002249 } else {
2250 // The definition is still initializing.
2251 Reader.PendingForwardRefs[Def].push_back(ID);
2252 }
2253 break;
2254 }
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00002255 }
2256 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00002257}