blob: 729cde0abfba8d613f84df2f076526b60093622a [file] [log] [blame]
Sebastian Redl904c9c82010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner698f9252009-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 Redlc43b54c2010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner698f9252009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redl6ab7cd82010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner698f9252009-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 Lattner6ad9ac02010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner698f9252009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000032namespace clang {
Sebastian Redld527cc02010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redlc43b54c2010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregor72a9ae12011-07-22 16:00:58 +000035 Module &F;
Sebastian Redl577d4792010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +000038 const unsigned RawLocation;
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000039 typedef ASTReader::RecordData RecordData;
40 const RecordData &Record;
Chris Lattner698f9252009-04-27 05:27:42 +000041 unsigned &Idx;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000042 TypeID TypeIDForTypeDecl;
Douglas Gregor67da6f62011-03-05 01:35:54 +000043
44 DeclID DeclContextIDForTemplateParmDecl;
45 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner698f9252009-04-27 05:27:42 +000046
Sebastian Redl577d4792010-07-22 22:43:28 +000047 uint64_t GetCurrentCursorOffset();
Douglas Gregor409448c2011-07-21 22:35:25 +000048
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000049 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000050 return Reader.ReadSourceLocation(F, R, I);
51 }
Douglas Gregor409448c2011-07-21 22:35:25 +000052
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000053 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000054 return Reader.ReadSourceRange(F, R, I);
55 }
Douglas Gregor409448c2011-07-21 22:35:25 +000056
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000057 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000058 return Reader.GetTypeSourceInfo(F, R, I);
59 }
Douglas Gregor409448c2011-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 Kyrtzidis40451072010-10-15 18:21:24 +000074 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000075 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000076 Reader.ReadQualifierInfo(F, Info, R, I);
77 }
Douglas Gregor409448c2011-07-21 22:35:25 +000078
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000079 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000080 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000081 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
82 }
Douglas Gregor409448c2011-07-21 22:35:25 +000083
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000084 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000085 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000086 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
87 }
Sebastian Redl577d4792010-07-22 22:43:28 +000088
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +000089 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
90 const RecordData &R, unsigned &I);
91
92 void InitializeCXXDefinitionData(CXXRecordDecl *D,
93 CXXRecordDecl *DefinitionDecl,
94 const RecordData &Record, unsigned &Idx);
Chris Lattner698f9252009-04-27 05:27:42 +000095 public:
Douglas Gregor72a9ae12011-07-22 16:00:58 +000096 ASTDeclReader(ASTReader &Reader, Module &F,
Sebastian Redlc3632732010-10-05 15:59:54 +000097 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +000098 unsigned RawLocation,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000099 const RecordData &Record, unsigned &Idx)
Sebastian Redlc3632732010-10-05 15:59:54 +0000100 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000101 RawLocation(RawLocation), Record(Record), Idx(Idx),
102 TypeIDForTypeDecl(0) { }
Chris Lattner698f9252009-04-27 05:27:42 +0000103
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +0000104 static void attachPreviousDecl(Decl *D, Decl *previous);
105
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000106 void Visit(Decl *D);
107
Douglas Gregor72a9ae12011-07-22 16:00:58 +0000108 void UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +0000109 const RecordData &Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000110
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +0000111 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
112 ObjCCategoryDecl *Next) {
113 Cat->NextClassCategory = Next;
114 }
115
Chris Lattner698f9252009-04-27 05:27:42 +0000116 void VisitDecl(Decl *D);
117 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
118 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000119 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregor0cef4832010-02-21 18:22:14 +0000120 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000121 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
122 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000123 void VisitTypeDecl(TypeDecl *TD);
124 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000125 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000126 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000127 void VisitTagDecl(TagDecl *TD);
128 void VisitEnumDecl(EnumDecl *ED);
129 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000130 void VisitCXXRecordDecl(CXXRecordDecl *D);
131 void VisitClassTemplateSpecializationDecl(
132 ClassTemplateSpecializationDecl *D);
133 void VisitClassTemplatePartialSpecializationDecl(
134 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redl14c36332011-08-31 13:59:56 +0000135 void VisitClassScopeFunctionSpecializationDecl(
136 ClassScopeFunctionSpecializationDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000137 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000138 void VisitValueDecl(ValueDecl *VD);
139 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000140 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000141 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +0000142 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000143 void VisitCXXMethodDecl(CXXMethodDecl *D);
144 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
145 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
146 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000147 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet87c2e122010-11-21 06:08:52 +0000148 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000149 void VisitVarDecl(VarDecl *VD);
150 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
151 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000152 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
153 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000154 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000155 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000156 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000157 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000158 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000159 void VisitUsingDecl(UsingDecl *D);
160 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000161 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000162 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnara6206d532010-06-05 05:09:32 +0000163 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000164 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000165 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
166 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000167 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000168
Chris Lattner698f9252009-04-27 05:27:42 +0000169 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000170 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000171
Sean Hunt9a555912010-05-30 07:21:58 +0000172 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-04-27 05:27:42 +0000173 void VisitObjCMethodDecl(ObjCMethodDecl *D);
174 void VisitObjCContainerDecl(ObjCContainerDecl *D);
175 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
176 void VisitObjCIvarDecl(ObjCIvarDecl *D);
177 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
178 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
179 void VisitObjCClassDecl(ObjCClassDecl *D);
180 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
181 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
182 void VisitObjCImplDecl(ObjCImplDecl *D);
183 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
184 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
185 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
186 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
187 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
188 };
189}
190
Sebastian Redld527cc02010-08-18 23:56:48 +0000191uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregor8f1231b2011-07-22 06:10:01 +0000192 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redl577d4792010-07-22 22:43:28 +0000193}
194
Sebastian Redld527cc02010-08-18 23:56:48 +0000195void ASTDeclReader::Visit(Decl *D) {
196 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000197
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000198 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
199 if (DD->DeclInfo) {
200 DeclaratorDecl::ExtInfo *Info =
201 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
202 Info->TInfo =
203 GetTypeSourceInfo(Record, Idx);
204 }
205 else {
206 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
207 }
208 }
209
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000210 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000211 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor1ab55e92010-12-10 17:03:06 +0000212 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000213 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
214 // FunctionDecl's body was written last after all other Stmts/Exprs.
215 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000216 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000217 } else if (D->isTemplateParameter()) {
218 // If we have a fully initialized template parameter, we can now
219 // set its DeclContext.
220 D->setDeclContext(
221 cast_or_null<DeclContext>(
222 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
223 D->setLexicalDeclContext(
224 cast_or_null<DeclContext>(
225 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000226 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000227}
228
Sebastian Redld527cc02010-08-18 23:56:48 +0000229void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor67da6f62011-03-05 01:35:54 +0000230 if (D->isTemplateParameter()) {
231 // We don't want to deserialize the DeclContext of a template
232 // parameter immediately, because the template parameter might be
233 // used in the formulation of its DeclContext. Use the translation
234 // unit DeclContext as a placeholder.
Douglas Gregor409448c2011-07-21 22:35:25 +0000235 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
236 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000237 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000238 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000239 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
240 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor67da6f62011-03-05 01:35:54 +0000241 }
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +0000242 D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
Chris Lattner698f9252009-04-27 05:27:42 +0000243 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000244 if (Record[Idx++]) { // hasAttrs
Sean Huntcf807c42010-08-18 23:23:40 +0000245 AttrVec Attrs;
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000246 Reader.ReadAttributes(F, Attrs, Record, Idx);
Sean Huntcf807c42010-08-18 23:23:40 +0000247 D->setAttrs(Attrs);
248 }
Chris Lattner698f9252009-04-27 05:27:42 +0000249 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000250 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis6b6b42a2011-04-19 19:51:10 +0000251 D->setReferenced(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000252 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor08e0bc12011-09-10 00:09:20 +0000253 D->FromASTFile = true;
Douglas Gregor8d267c52011-09-09 02:06:17 +0000254 D->ModulePrivate = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000255}
256
Sebastian Redld527cc02010-08-18 23:56:48 +0000257void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +0000258 llvm_unreachable("Translation units are not serialized");
Chris Lattner698f9252009-04-27 05:27:42 +0000259}
260
Sebastian Redld527cc02010-08-18 23:56:48 +0000261void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner698f9252009-04-27 05:27:42 +0000262 VisitDecl(ND);
Douglas Gregor393f2492011-07-22 00:38:23 +0000263 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000264}
265
Sebastian Redld527cc02010-08-18 23:56:48 +0000266void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000267 VisitNamedDecl(TD);
Abramo Bagnara344577e2011-03-06 15:48:19 +0000268 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000269 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor393f2492011-07-22 00:38:23 +0000270 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000271}
272
Sebastian Redld527cc02010-08-18 23:56:48 +0000273void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000274 VisitTypeDecl(TD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000275 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000276}
277
Richard Smith162e1c12011-04-15 14:24:37 +0000278void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
279 VisitTypeDecl(TD);
280 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
281}
282
Sebastian Redld527cc02010-08-18 23:56:48 +0000283void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000284 VisitRedeclarable(TD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000285 VisitTypeDecl(TD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000286 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000287 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCall5e1cdac2011-10-07 06:10:15 +0000288 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000289 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis717a20b2011-09-30 22:11:31 +0000290 TD->setFreeStanding(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000291 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000292 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor35942772011-09-09 21:34:22 +0000293 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000294 ReadQualifierInfo(*Info, Record, Idx);
Richard Smith162e1c12011-04-15 14:24:37 +0000295 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000296 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000297 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000298}
299
Sebastian Redld527cc02010-08-18 23:56:48 +0000300void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000301 VisitTagDecl(ED);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000302 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
303 ED->setIntegerTypeSourceInfo(TI);
304 else
Douglas Gregor393f2492011-07-22 00:38:23 +0000305 ED->setIntegerType(Reader.readType(F, Record, Idx));
306 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall1b5a6182010-05-06 08:49:23 +0000307 ED->setNumPositiveBits(Record[Idx++]);
308 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000309 ED->IsScoped = Record[Idx++];
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000310 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000311 ED->IsFixed = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000312 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000313}
314
Sebastian Redld527cc02010-08-18 23:56:48 +0000315void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000316 VisitTagDecl(RD);
317 RD->setHasFlexibleArrayMember(Record[Idx++]);
318 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000319 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000320}
321
Sebastian Redld527cc02010-08-18 23:56:48 +0000322void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000323 VisitNamedDecl(VD);
Douglas Gregor393f2492011-07-22 00:38:23 +0000324 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000325}
326
Sebastian Redld527cc02010-08-18 23:56:48 +0000327void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000328 VisitValueDecl(ECD);
329 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000330 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000331 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
332}
333
Sebastian Redld527cc02010-08-18 23:56:48 +0000334void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000335 VisitValueDecl(DD);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000336 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000337 if (Record[Idx++]) { // hasExtInfo
338 DeclaratorDecl::ExtInfo *Info
Douglas Gregor35942772011-09-09 21:34:22 +0000339 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000340 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000341 DD->DeclInfo = Info;
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000342 }
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000343}
344
Sebastian Redld527cc02010-08-18 23:56:48 +0000345void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000346 VisitRedeclarable(FD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000347 VisitDeclaratorDecl(FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000348
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000349 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000350 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000351 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000352 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000353 case FunctionDecl::TK_NonTemplate:
354 break;
355 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000356 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
357 Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000358 break;
359 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000360 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000361 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000362 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000363 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000364 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
365 break;
366 }
367 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000368 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
369 Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000370 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
371
372 // Template arguments.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000373 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000374 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000375
376 // Template args as written.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000377 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000378 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000379 bool HasTemplateArgumentsAsWritten = Record[Idx++];
380 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000381 unsigned NumTemplateArgLocs = Record[Idx++];
382 TemplArgLocs.reserve(NumTemplateArgLocs);
383 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000384 TemplArgLocs.push_back(
Sebastian Redlc3632732010-10-05 15:59:54 +0000385 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000386
Sebastian Redlc3632732010-10-05 15:59:54 +0000387 LAngleLoc = ReadSourceLocation(Record, Idx);
388 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000389 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000390
Sebastian Redlc3632732010-10-05 15:59:54 +0000391 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000392
Douglas Gregor35942772011-09-09 21:34:22 +0000393 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000394 TemplateArgumentList *TemplArgList
Douglas Gregor910f8002010-11-07 23:05:16 +0000395 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000396 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000397 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000398 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000399 FunctionTemplateSpecializationInfo *FTInfo
400 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
401 TemplArgList,
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000402 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
403 POI);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000404 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000405
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000406 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000407 // The template that contains the specializations set. It's not safe to
408 // use getCanonicalDecl on Template since it may still be initializing.
409 FunctionTemplateDecl *CanonTemplate
Douglas Gregor409448c2011-07-21 22:35:25 +0000410 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000411 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
412 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
413 // FunctionTemplateSpecializationInfo's Profile().
414 // We avoid getASTContext because a decl in the parent hierarchy may
415 // be initializing.
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000416 llvm::FoldingSetNodeID ID;
417 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
418 TemplArgs.size(), C);
419 void *InsertPos = 0;
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000420 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000421 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000422 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000423 }
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000424 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000425 }
426 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
427 // Templates.
428 UnresolvedSet<8> TemplDecls;
429 unsigned NumTemplates = Record[Idx++];
430 while (NumTemplates--)
Douglas Gregor409448c2011-07-21 22:35:25 +0000431 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000432
433 // Templates args.
434 TemplateArgumentListInfo TemplArgs;
435 unsigned NumArgs = Record[Idx++];
436 while (NumArgs--)
Sebastian Redlc3632732010-10-05 15:59:54 +0000437 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
438 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
439 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000440
Douglas Gregor35942772011-09-09 21:34:22 +0000441 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000442 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000443 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000444 }
445 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000446
Sebastian Redld527cc02010-08-18 23:56:48 +0000447 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000448 // after everything else is read.
449
Douglas Gregor381d34e2010-12-06 18:36:25 +0000450 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000451 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregor8f150942010-12-09 16:59:22 +0000452 FD->IsInline = Record[Idx++];
453 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000454 FD->IsVirtualAsWritten = Record[Idx++];
455 FD->IsPure = Record[Idx++];
456 FD->HasInheritedPrototype = Record[Idx++];
457 FD->HasWrittenPrototype = Record[Idx++];
458 FD->IsDeleted = Record[Idx++];
459 FD->IsTrivial = Record[Idx++];
Sean Hunt2be7e902011-05-12 22:46:29 +0000460 FD->IsDefaulted = Record[Idx++];
461 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000462 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smithaf1fc7a2011-08-15 21:04:07 +0000463 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000464 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000465
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000466 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000467 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000468 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000469 Params.reserve(NumParams);
470 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000471 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000472 FD->setParams(Reader.getContext(), Params);
Chris Lattner698f9252009-04-27 05:27:42 +0000473}
474
Sebastian Redld527cc02010-08-18 23:56:48 +0000475void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000476 VisitNamedDecl(MD);
477 if (Record[Idx++]) {
478 // In practice, this won't be executed (since method definitions
479 // don't occur in header files).
Sebastian Redlc3632732010-10-05 15:59:54 +0000480 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor409448c2011-07-21 22:35:25 +0000481 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
482 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000483 }
484 MD->setInstanceMethod(Record[Idx++]);
485 MD->setVariadic(Record[Idx++]);
486 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000487 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidis72b26252011-10-14 17:41:52 +0000488
489 MD->IsRedeclaration = Record[Idx++];
490 MD->HasRedeclaration = Record[Idx++];
491 if (MD->HasRedeclaration)
492 Reader.getContext().setObjCMethodRedeclaration(MD,
493 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
494
Chris Lattner698f9252009-04-27 05:27:42 +0000495 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
496 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000497 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000498 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000499 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
500 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000501 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000502 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000503 Params.reserve(NumParams);
504 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000505 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000506
507 MD->SelLocsKind = Record[Idx++];
508 unsigned NumStoredSelLocs = Record[Idx++];
509 SmallVector<SourceLocation, 16> SelLocs;
510 SelLocs.reserve(NumStoredSelLocs);
511 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
512 SelLocs.push_back(ReadSourceLocation(Record, Idx));
513
514 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner698f9252009-04-27 05:27:42 +0000515}
516
Sebastian Redld527cc02010-08-18 23:56:48 +0000517void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000518 VisitNamedDecl(CD);
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000519 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
520 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000521}
522
Sebastian Redld527cc02010-08-18 23:56:48 +0000523void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner698f9252009-04-27 05:27:42 +0000524 VisitObjCContainerDecl(ID);
Douglas Gregor393f2492011-07-22 00:38:23 +0000525 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor409448c2011-07-21 22:35:25 +0000526 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000527
528 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner698f9252009-04-27 05:27:42 +0000529 unsigned NumProtocols = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000530 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner698f9252009-04-27 05:27:42 +0000531 Protocols.reserve(NumProtocols);
532 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000533 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000534 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000535 ProtoLocs.reserve(NumProtocols);
536 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000537 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000538 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000539 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000540
541 // Read the transitive closure of protocols referenced by this class.
542 NumProtocols = Record[Idx++];
543 Protocols.clear();
544 Protocols.reserve(NumProtocols);
545 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000546 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000547 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor35942772011-09-09 21:34:22 +0000548 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000549
550 // Read the ivars.
Chris Lattner698f9252009-04-27 05:27:42 +0000551 unsigned NumIvars = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000552 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner698f9252009-04-27 05:27:42 +0000553 IVars.reserve(NumIvars);
554 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000555 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
556 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
557
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000558 // We will rebuild this list lazily.
559 ID->setIvarList(0);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000560 ID->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000561 ID->ForwardDecl = Record[Idx++];
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000562 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000563 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
564 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000565}
566
Sebastian Redld527cc02010-08-18 23:56:48 +0000567void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000568 VisitFieldDecl(IVD);
569 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000570 // This field will be built lazily.
571 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000572 bool synth = Record[Idx++];
573 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000574}
575
Sebastian Redld527cc02010-08-18 23:56:48 +0000576void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000577 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000578 PD->InitiallyForwardDecl = Record[Idx++];
Argyrios Kyrtzidisad834d52011-11-12 21:07:46 +0000579 PD->isForwardProtoDecl = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000580 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000581 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000582 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000583 ProtoRefs.reserve(NumProtoRefs);
584 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000585 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000586 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000587 ProtoLocs.reserve(NumProtoRefs);
588 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000589 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000590 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000591 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000592}
593
Sebastian Redld527cc02010-08-18 23:56:48 +0000594void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000595 VisitFieldDecl(FD);
596}
597
Sebastian Redld527cc02010-08-18 23:56:48 +0000598void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000599 VisitDecl(CD);
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000600 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
601 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000602 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner698f9252009-04-27 05:27:42 +0000603}
604
Sebastian Redld527cc02010-08-18 23:56:48 +0000605void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000606 VisitDecl(FPD);
607 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000608 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000609 ProtoRefs.reserve(NumProtoRefs);
610 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000611 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000612 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000613 ProtoLocs.reserve(NumProtoRefs);
614 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000615 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000616 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000617 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000618}
619
Sebastian Redld527cc02010-08-18 23:56:48 +0000620void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000621 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000622 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000623 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000624 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000625 ProtoRefs.reserve(NumProtoRefs);
626 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000627 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000628 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000629 ProtoLocs.reserve(NumProtoRefs);
630 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000631 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000632 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000633 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000634 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000635 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000636 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000637}
638
Sebastian Redld527cc02010-08-18 23:56:48 +0000639void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000640 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000641 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000642}
643
Sebastian Redld527cc02010-08-18 23:56:48 +0000644void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000645 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000646 D->setAtLoc(ReadSourceLocation(Record, Idx));
647 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000648 // FIXME: stable encoding
649 D->setPropertyAttributes(
650 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000651 D->setPropertyAttributesAsWritten(
652 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000653 // FIXME: stable encoding
654 D->setPropertyImplementation(
655 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000656 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
657 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000658 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
659 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
660 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000661}
662
Sebastian Redld527cc02010-08-18 23:56:48 +0000663void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000664 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000665 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000666}
667
Sebastian Redld527cc02010-08-18 23:56:48 +0000668void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000669 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000670 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000671}
672
Sebastian Redld527cc02010-08-18 23:56:48 +0000673void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000674 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000675 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000676 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000677 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000678 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000679}
680
681
Sebastian Redld527cc02010-08-18 23:56:48 +0000682void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000683 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000684 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000685 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
686 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000687 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000688 D->setGetterCXXConstructor(Reader.ReadExpr(F));
689 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000690}
691
Sebastian Redld527cc02010-08-18 23:56:48 +0000692void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000693 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000694 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000695 int BitWidthOrInitializer = Record[Idx++];
696 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000697 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000698 else if (BitWidthOrInitializer == 2)
699 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000700 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000701 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000702 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000703 }
Chris Lattner698f9252009-04-27 05:27:42 +0000704}
705
Francois Pichet87c2e122010-11-21 06:08:52 +0000706void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
707 VisitValueDecl(FD);
708
709 FD->ChainingSize = Record[Idx++];
710 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000711 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000712
713 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000714 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000715}
716
Sebastian Redld527cc02010-08-18 23:56:48 +0000717void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000718 VisitRedeclarable(VD);
Douglas Gregord488b3a2011-10-26 17:53:41 +0000719 VisitDeclaratorDecl(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000720 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
721 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
722 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
723 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
724 VD->VarDeclBits.ExceptionVar = Record[Idx++];
725 VD->VarDeclBits.NRVOVariable = Record[Idx++];
726 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000727 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000728 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000729 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000730
731 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000732 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000733 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000734 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000735 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000736 }
Chris Lattner698f9252009-04-27 05:27:42 +0000737}
738
Sebastian Redld527cc02010-08-18 23:56:48 +0000739void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000740 VisitVarDecl(PD);
741}
742
Sebastian Redld527cc02010-08-18 23:56:48 +0000743void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000744 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000745 unsigned isObjCMethodParam = Record[Idx++];
746 unsigned scopeDepth = Record[Idx++];
747 unsigned scopeIndex = Record[Idx++];
748 unsigned declQualifier = Record[Idx++];
749 if (isObjCMethodParam) {
750 assert(scopeDepth == 0);
751 PD->setObjCMethodScopeInfo(scopeIndex);
752 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
753 } else {
754 PD->setScopeInfo(scopeDepth, scopeIndex);
755 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000756 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
757 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000758 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000759 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000760}
761
Sebastian Redld527cc02010-08-18 23:56:48 +0000762void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000763 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000764 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000765 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000766}
767
Sebastian Redld527cc02010-08-18 23:56:48 +0000768void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000769 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000770 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
771 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000772 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000773 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000774 Params.reserve(NumParams);
775 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000776 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000777 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000778
779 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000780 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000781 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000782 captures.reserve(numCaptures);
783 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000784 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +0000785 unsigned flags = Record[Idx++];
786 bool byRef = (flags & 1);
787 bool nested = (flags & 2);
788 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
789
790 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
791 }
Douglas Gregor35942772011-09-09 21:34:22 +0000792 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000793 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000794}
795
Sebastian Redld527cc02010-08-18 23:56:48 +0000796void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000797 VisitDecl(D);
798 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000799 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000800 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000801}
802
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000803void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
804 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +0000805 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000806}
807
808
Sebastian Redld527cc02010-08-18 23:56:48 +0000809void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000810 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +0000811 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +0000812 D->LocStart = ReadSourceLocation(Record, Idx);
813 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +0000814 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000815
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000816 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000817 // FIXME: Modules will likely have trouble with pointing directly at
818 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000819 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +0000820 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000821}
822
Sebastian Redld527cc02010-08-18 23:56:48 +0000823void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000824 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000825 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000826 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +0000827 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000828 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000829}
830
Sebastian Redld527cc02010-08-18 23:56:48 +0000831void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000832 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000833 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000834 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000835 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000836 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000837 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +0000838 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000839 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000840}
841
Sebastian Redld527cc02010-08-18 23:56:48 +0000842void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000843 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000844 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
845 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
846 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000847 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +0000848 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000849}
850
Sebastian Redld527cc02010-08-18 23:56:48 +0000851void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000852 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000853 D->UsingLoc = ReadSourceLocation(Record, Idx);
854 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +0000855 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000856 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
857 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000858}
859
Sebastian Redld527cc02010-08-18 23:56:48 +0000860void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000861 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000862 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000863 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000864 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000865}
866
Sebastian Redld527cc02010-08-18 23:56:48 +0000867void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000868 UnresolvedUsingTypenameDecl *D) {
869 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000870 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +0000871 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000872}
873
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000874void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000875 struct CXXRecordDecl::DefinitionData &Data,
876 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000877 Data.UserDeclaredConstructor = Record[Idx++];
878 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000879 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000880 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000881 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000882 Data.UserDeclaredDestructor = Record[Idx++];
883 Data.Aggregate = Record[Idx++];
884 Data.PlainOldData = Record[Idx++];
885 Data.Empty = Record[Idx++];
886 Data.Polymorphic = Record[Idx++];
887 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +0000888 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +0000889 Data.HasNoNonEmptyBases = Record[Idx++];
890 Data.HasPrivateFields = Record[Idx++];
891 Data.HasProtectedFields = Record[Idx++];
892 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +0000893 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +0000894 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +0000895 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000896 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000897 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000898 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000899 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000900 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +0000901 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000902 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +0000903 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000904 Data.DeclaredDefaultConstructor = Record[Idx++];
905 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000906 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000907 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000908 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000909 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +0000910 Data.FailedImplicitMoveConstructor = Record[Idx++];
911 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +0000912
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000913 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000914 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000915 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000916 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000917 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000918 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +0000919
Douglas Gregor409448c2011-07-21 22:35:25 +0000920 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
921 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000922 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +0000923 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000924}
925
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000926void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
927 CXXRecordDecl *DefinitionDecl,
928 const RecordData &Record,
929 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +0000930 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000931
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000932 if (D == DefinitionDecl) {
933 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000934 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000935 // We read the definition info. Check if there are pending forward
936 // references that need to point to this DefinitionData pointer.
937 ASTReader::PendingForwardRefsMap::iterator
938 FindI = Reader.PendingForwardRefs.find(D);
939 if (FindI != Reader.PendingForwardRefs.end()) {
940 ASTReader::ForwardRefs &Refs = FindI->second;
941 for (ASTReader::ForwardRefs::iterator
942 I = Refs.begin(), E = Refs.end(); I != E; ++I)
943 (*I)->DefinitionData = D->DefinitionData;
944#ifndef NDEBUG
945 // We later check whether PendingForwardRefs is empty to make sure all
946 // pending references were linked.
947 Reader.PendingForwardRefs.erase(D);
948#endif
949 }
950 } else if (DefinitionDecl) {
951 if (DefinitionDecl->DefinitionData) {
952 D->DefinitionData = DefinitionDecl->DefinitionData;
953 } else {
954 // The definition is still initializing.
955 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
956 }
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000957 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000958}
959
960void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
961 VisitRecordDecl(D);
962
Douglas Gregor409448c2011-07-21 22:35:25 +0000963 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000964 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
965
Douglas Gregor35942772011-09-09 21:34:22 +0000966 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000967
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000968 enum CXXRecKind {
969 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
970 };
971 switch ((CXXRecKind)Record[Idx++]) {
972 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000973 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000974 case CXXRecNotTemplate:
975 break;
976 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000977 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000978 break;
979 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000980 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000981 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000982 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +0000983 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
984 MSI->setPointOfInstantiation(POI);
985 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000986 break;
987 }
988 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000989
990 // Load the key function to avoid deserializing every method so we can
991 // compute it.
John McCall5e1cdac2011-10-07 06:10:15 +0000992 if (D->IsCompleteDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000993 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000994 C.KeyFunctions[D] = Key;
995 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000996}
997
Sebastian Redld527cc02010-08-18 23:56:48 +0000998void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000999 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001000 unsigned NumOverridenMethods = Record[Idx++];
1001 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001002 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1003 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +00001004 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001005 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001006 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001007}
1008
Sebastian Redld527cc02010-08-18 23:56:48 +00001009void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001010 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001011
1012 D->IsExplicitSpecified = Record[Idx++];
1013 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001014 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1015 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001016}
1017
Sebastian Redld527cc02010-08-18 23:56:48 +00001018void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001019 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001020
1021 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001022 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001023}
1024
Sebastian Redld527cc02010-08-18 23:56:48 +00001025void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001026 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001027 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001028}
1029
Sebastian Redld527cc02010-08-18 23:56:48 +00001030void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001031 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001032 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001033}
1034
Sebastian Redld527cc02010-08-18 23:56:48 +00001035void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001036 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001037 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001038 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001039 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001040 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001041 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001042 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001043 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001044}
1045
Sebastian Redld527cc02010-08-18 23:56:48 +00001046void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001047 VisitDecl(D);
1048 unsigned NumParams = Record[Idx++];
1049 D->NumParams = NumParams;
1050 D->Params = new TemplateParameterList*[NumParams];
1051 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001052 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001053 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001054 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001055 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001056 D->Friend = GetTypeSourceInfo(Record, Idx);
1057 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001058}
1059
Sebastian Redld527cc02010-08-18 23:56:48 +00001060void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001061 VisitNamedDecl(D);
1062
Douglas Gregor409448c2011-07-21 22:35:25 +00001063 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001064 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001065 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001066 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001067}
1068
Sebastian Redld527cc02010-08-18 23:56:48 +00001069void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001070 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1071 // can be used while this is still initializing.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001072
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001073 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor409448c2011-07-21 22:35:25 +00001074 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1075 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001076 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1077 // We temporarily set the first (canonical) declaration as the previous one
1078 // which is the one that matters and mark the real previous DeclID to be
1079 // loaded & attached later on.
1080 RedeclarableTemplateDecl *FirstDecl =
1081 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1082 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1083 "FirstDecl kind mismatch");
1084 if (FirstDecl) {
1085 D->CommonOrPrev = FirstDecl;
1086 // Mark the real previous DeclID to be loaded & attached later on.
1087 if (PreviousDeclID != FirstDeclID)
1088 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1089 } else {
Douglas Gregor35942772011-09-09 21:34:22 +00001090 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001091 if (RedeclarableTemplateDecl *RTD
Douglas Gregor409448c2011-07-21 22:35:25 +00001092 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001093 assert(RTD->getKind() == D->getKind() &&
1094 "InstantiatedFromMemberTemplate kind mismatch");
1095 D->setInstantiatedFromMemberTemplateImpl(RTD);
1096 if (Record[Idx++])
1097 D->setMemberSpecialization();
1098 }
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001099
Douglas Gregor409448c2011-07-21 22:35:25 +00001100 RedeclarableTemplateDecl *LatestDecl
1101 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001102
1103 // This decl is a first one and the latest declaration that it points to is
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001104 // in the same AST file. However, if this actually needs to point to a
1105 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001106 // the FirstLatestDeclIDs map which tracks this kind of decls.
1107 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001108 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001109 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1110 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregor1b59e9c2011-08-25 15:28:26 +00001111 if (Decl *NewLatest = Reader.GetDecl(I->second))
1112 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001113 }
1114
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001115 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1116 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001117 }
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001118
1119 VisitTemplateDecl(D);
1120 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001121}
1122
Sebastian Redld527cc02010-08-18 23:56:48 +00001123void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001124 VisitRedeclarableTemplateDecl(D);
1125
1126 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001127 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1128 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001129 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001130 SpecIDs.push_back(0);
1131
1132 // Specializations.
1133 unsigned Size = Record[Idx++];
1134 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001135 for (unsigned I = 0; I != Size; ++I)
1136 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001137
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001138 // Partial specializations.
1139 Size = Record[Idx++];
1140 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001141 for (unsigned I = 0; I != Size; ++I)
1142 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001143
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001144 if (SpecIDs[0]) {
1145 typedef serialization::DeclID DeclID;
1146
1147 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1148 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001149 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001150 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1151 SpecIDs.size() * sizeof(DeclID));
1152 }
1153
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001154 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001155 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001156}
1157
Sebastian Redld527cc02010-08-18 23:56:48 +00001158void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001159 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001160 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001161
Douglas Gregor35942772011-09-09 21:34:22 +00001162 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001163 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001164 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001165 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001166 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001167 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001168 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001169 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001170 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1171 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001172 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1173 = new (C) ClassTemplateSpecializationDecl::
1174 SpecializedPartialSpecialization();
1175 PS->PartialSpecialization
1176 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1177 PS->TemplateArgs = ArgList;
1178 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001179 }
1180 }
1181
1182 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001183 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001184 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1185 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1186 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001187 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1188 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001189 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001190 }
1191
Chris Lattner5f9e2722011-07-23 10:55:15 +00001192 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001193 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001194 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1195 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001196 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001197 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001198
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001199 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001200 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001201 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001202 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1203 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001204 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001205 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001206 }
1207 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001208}
1209
Sebastian Redld527cc02010-08-18 23:56:48 +00001210void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001211 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001212 VisitClassTemplateSpecializationDecl(D);
1213
Douglas Gregor35942772011-09-09 21:34:22 +00001214 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001215 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001216
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001217 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001218 if (NumArgs) {
1219 D->NumArgsAsWritten = NumArgs;
1220 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1221 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001222 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001223 }
1224
1225 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001226
1227 // These are read/set from/to the first declaration.
1228 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001229 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001230 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001231 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001232 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001233}
1234
Sebastian Redl14c36332011-08-31 13:59:56 +00001235void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1236 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001237 VisitDecl(D);
1238 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1239}
1240
Sebastian Redld527cc02010-08-18 23:56:48 +00001241void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001242 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001243
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001244 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001245 // This FunctionTemplateDecl owns a CommonPtr; read it.
1246
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001247 // Read the function specialization declarations.
1248 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001249 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001250 unsigned NumSpecs = Record[Idx++];
1251 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001252 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001253 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001254}
1255
Sebastian Redld527cc02010-08-18 23:56:48 +00001256void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001257 VisitTypeDecl(D);
1258
1259 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001260
1261 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001262 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001263 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001264}
1265
Sebastian Redld527cc02010-08-18 23:56:48 +00001266void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001267 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001268 // TemplateParmPosition.
1269 D->setDepth(Record[Idx++]);
1270 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001271 if (D->isExpandedParameterPack()) {
1272 void **Data = reinterpret_cast<void **>(D + 1);
1273 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001274 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001275 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1276 }
1277 } else {
1278 // Rest of NonTypeTemplateParmDecl.
1279 D->ParameterPack = Record[Idx++];
1280 if (Record[Idx++]) {
1281 Expr *DefArg = Reader.ReadExpr(F);
1282 bool Inherited = Record[Idx++];
1283 D->setDefaultArgument(DefArg, Inherited);
1284 }
1285 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001286}
1287
Sebastian Redld527cc02010-08-18 23:56:48 +00001288void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001289 VisitTemplateDecl(D);
1290 // TemplateParmPosition.
1291 D->setDepth(Record[Idx++]);
1292 D->setPosition(Record[Idx++]);
1293 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001294 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001295 bool IsInherited = Record[Idx++];
1296 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001297 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001298}
1299
Richard Smith3e4c6c42011-05-05 21:57:07 +00001300void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1301 VisitRedeclarableTemplateDecl(D);
1302}
1303
Sebastian Redld527cc02010-08-18 23:56:48 +00001304void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001305 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001306 D->AssertExpr = Reader.ReadExpr(F);
1307 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001308 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001309}
1310
Mike Stump1eb44332009-09-09 15:08:12 +00001311std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001312ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001313 uint64_t LexicalOffset = Record[Idx++];
1314 uint64_t VisibleOffset = Record[Idx++];
1315 return std::make_pair(LexicalOffset, VisibleOffset);
1316}
1317
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001318template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001319void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001320 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1321 RedeclKind Kind = (RedeclKind)Record[Idx++];
1322 switch (Kind) {
1323 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001324 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1325 " messed up reading");
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001326 case NoRedeclaration:
1327 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001328 case PointsToPrevious: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001329 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1330 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001331 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1332 // We temporarily set the first (canonical) declaration as the previous one
1333 // which is the one that matters and mark the real previous DeclID to be
1334 // loaded & attached later on.
Douglas Gregord488b3a2011-10-26 17:53:41 +00001335 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1336 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001337 if (PreviousDeclID != FirstDeclID)
1338 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1339 PreviousDeclID));
Douglas Gregord488b3a2011-10-26 17:53:41 +00001340
1341 // If the first declaration in the chain is in an inconsistent
1342 // state where it thinks that it is the only declaration, fix its
1343 // redeclaration link now to point at this declaration, so that we have a
1344 // proper redeclaration chain.
1345 if (FirstDecl->RedeclLink.getPointer() == FirstDecl) {
1346 FirstDecl->RedeclLink
1347 = typename Redeclarable<T>::LatestDeclLink(static_cast<T*>(D));
1348 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001349 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001350 }
Douglas Gregord488b3a2011-10-26 17:53:41 +00001351 case PointsToLatest: {
1352 T *LatestDecl = ReadDeclAs<T>(Record, Idx);
1353 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(LatestDecl);
1354
1355 // If the latest declaration in the chain is in an inconsistent
1356 // state where it thinks that it is the only declaration, fix its
1357 // redeclaration link now to point at this declaration, so that we have a
1358 // proper redeclaration chain.
1359 if (LatestDecl->RedeclLink.getPointer() == LatestDecl) {
1360 LatestDecl->RedeclLink
1361 = typename Redeclarable<T>::PreviousDeclLink(static_cast<T*>(D));
1362 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001363 break;
1364 }
Douglas Gregord488b3a2011-10-26 17:53:41 +00001365 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001366
1367 assert(!(Kind == PointsToPrevious &&
1368 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1369 Reader.FirstLatestDeclIDs.end()) &&
1370 "This decl is not first, it should not be in the map");
1371 if (Kind == PointsToPrevious)
1372 return;
1373
1374 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001375 // the same AST file. However, if this actually needs to point to a
1376 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001377 // FirstLatestDeclIDs map which tracks this kind of decls.
1378 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1379 "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001380 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001381 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1382 if (I != Reader.FirstLatestDeclIDs.end()) {
1383 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001384 D->RedeclLink
1385 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1386 }
1387}
1388
Chris Lattner698f9252009-04-27 05:27:42 +00001389//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001390// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001391//===----------------------------------------------------------------------===//
1392
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001393/// \brief Reads attributes from the current stream position.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001394void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001395 const RecordData &Record, unsigned &Idx) {
1396 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001397 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001398 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001399 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001400
Sean Huntcf807c42010-08-18 23:23:40 +00001401#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001402
1403 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001404 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001405 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001406}
1407
1408//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001409// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001410//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001411
1412/// \brief Note that we have loaded the declaration with the given
1413/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001414///
Chris Lattner698f9252009-04-27 05:27:42 +00001415/// This routine notes that this declaration has already been loaded,
1416/// so that future GetDecl calls will return this declaration rather
1417/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001418inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001419 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1420 DeclsLoaded[Index] = D;
1421}
1422
1423
1424/// \brief Determine whether the consumer will be interested in seeing
1425/// this declaration (via HandleTopLevelDecl).
1426///
1427/// This routine should return true for anything that might affect
1428/// code generation, e.g., inline function definitions, Objective-C
1429/// declarations with metadata, etc.
1430static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001431 // An ObjCMethodDecl is never considered as "interesting" because its
1432 // implementation container always is.
1433
Douglas Gregor94da1582011-09-10 00:22:34 +00001434 if (isa<FileScopeAsmDecl>(D) ||
1435 isa<ObjCProtocolDecl>(D) ||
1436 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001437 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001438 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001439 return Var->isFileVarDecl() &&
1440 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001441 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001442 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001443
1444 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001445}
1446
Douglas Gregor96e973f2011-07-20 00:27:43 +00001447/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001448ASTReader::RecordLocation
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001449ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001450 // See if there's an override.
1451 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
Argyrios Kyrtzidisef23b602011-10-31 07:20:15 +00001452 if (It != ReplacedDecls.end()) {
1453 RawLocation = It->second.RawLoc;
1454 return RecordLocation(It->second.Mod, It->second.Offset);
1455 }
Sebastian Redl0b17c612010-08-13 00:28:03 +00001456
Douglas Gregor96e973f2011-07-20 00:27:43 +00001457 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1458 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor9827a802011-07-29 00:56:45 +00001459 Module *M = I->second;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001460 const DeclOffset &
1461 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
1462 RawLocation = DOffs.Loc;
1463 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001464}
1465
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001466ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001467 ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001468 = GlobalBitOffsetsMap.find(GlobalOffset);
1469
1470 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1471 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1472}
1473
Douglas Gregore92b8a12011-08-04 00:01:48 +00001474uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1475 return LocalOffset + M.GlobalBitOffset;
1476}
1477
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001478void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1479 assert(D && previous);
1480 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1481 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1482 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1483 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1484 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1485 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1486 } else {
1487 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1488 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1489 }
1490}
1491
1492void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1493 Decl *previous = GetDecl(ID);
1494 ASTDeclReader::attachPreviousDecl(D, previous);
1495}
1496
Sebastian Redld527cc02010-08-18 23:56:48 +00001497/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001498Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001499 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001500 unsigned RawLocation = 0;
1501 RecordLocation Loc = DeclCursorForID(ID, RawLocation);
Sebastian Redlc3632732010-10-05 15:59:54 +00001502 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001503 // Keep track of where we are in the stream, then jump back there
1504 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001505 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001506
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001507 ReadingKindTracker ReadingKind(Read_Decl, *this);
1508
Douglas Gregord89275b2009-07-06 18:54:52 +00001509 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001510 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001511
Sebastian Redlc3632732010-10-05 15:59:54 +00001512 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001513 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001514 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001515 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001516 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001517
Chris Lattnerda930612009-04-27 05:58:23 +00001518 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001519 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001520 case DECL_CONTEXT_LEXICAL:
1521 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001522 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001523 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001524 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001525 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001526 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001527 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001528 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001529 0, 0);
1530 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001531 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001532 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001533 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001534 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001535 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001536 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001537 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001538 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001539 0, llvm::APSInt());
1540 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001541 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001542 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001543 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001544 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001545 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001546 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001547 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001548 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001549 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001550 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001551 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001552 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001553 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001554 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001555 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001556 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001557 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001558 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001559 SourceLocation(), 0,
1560 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001561 SourceLocation(), 0);
1562 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001563 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001564 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001565 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1566 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001567 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001568 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001569 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001570 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001571 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001572 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001573 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001574 SourceLocation(), 0, 0);
1575 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001576 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001577 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001578 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001579 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001580 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001581 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001582 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001583 SourceLocation(),
1584 NestedNameSpecifierLoc(),
1585 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001586 DeclarationName());
1587 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001588 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001589 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001590 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001591 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001592 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001593 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001594 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001595 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001596 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001597 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001598 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001599 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001600 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001601 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001602 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001603 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001604 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001605 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001606 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001607 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001608 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001609 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001610 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001611 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001612 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001613 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001614 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001615 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001616 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001617 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001618 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001619 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001620 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001621 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001622 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001623 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001624 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001625 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001626 Decl::EmptyShell());
1627 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001628 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001629 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001630 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001631 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001632 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001633 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001634 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001635 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001636 SourceLocation(), 0, 0, 0, QualType(),
1637 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001638 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001639 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001640 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001641 SourceLocation(), 0, 0, 0, QualType(),
1642 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001643 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001644 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001645 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001646 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001647 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001648 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001649 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001650 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001651 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001652 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001653 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001654 break;
1655
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001656 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001657 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001658 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001659 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001660 case DECL_OBJC_INTERFACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001661 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001662 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001663 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001664 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001665 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001666 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001667 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001668 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +00001669 SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001670 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001671 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001672 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001673 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001674 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001675 case DECL_OBJC_CLASS:
Douglas Gregor35942772011-09-09 21:34:22 +00001676 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001677 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001678 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001679 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001680 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001681 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001682 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001683 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001684 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001685 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1686 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001687 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001688 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001689 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1690 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001691 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001692 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001693 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001694 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001695 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001696 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001697 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001698 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001699 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001700 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001701 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001702 ObjCPropertyImplDecl::Dynamic, 0,
1703 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001704 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001705 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001706 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001707 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001708 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001709 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001710 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001711 0, 0);
1712 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001713 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001714 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001715 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001716 break;
1717
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001718 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00001719 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001720 break;
1721
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001722 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001723 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001724 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001725 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001726 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00001727 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00001728 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001729 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001730 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00001731 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001732 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00001733 case DECL_CXX_BASE_SPECIFIERS:
1734 Error("attempt to read a C++ base-specifier record as a declaration");
1735 return 0;
Chris Lattner698f9252009-04-27 05:27:42 +00001736 }
Chris Lattner698f9252009-04-27 05:27:42 +00001737
Sebastian Redld527cc02010-08-18 23:56:48 +00001738 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001739 LoadedDecl(Index, D);
1740 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001741
1742 // If this declaration is also a declaration context, get the
1743 // offsets for its tables of lexical and visible declarations.
1744 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1745 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1746 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001747 if (Offsets.first != 0)
1748 DC->setHasExternalLexicalStorage(true);
1749 if (Offsets.second != 0)
1750 DC->setHasExternalVisibleStorage(true);
1751 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1752 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00001753 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001754 }
Sebastian Redle1dde812010-08-24 00:50:04 +00001755
Sebastian Redl024e1c42011-04-24 16:27:54 +00001756 // Now add the pending visible updates for this decl context, if it has any.
1757 DeclContextVisibleUpdatesPending::iterator I =
1758 PendingVisibleUpdates.find(ID);
1759 if (I != PendingVisibleUpdates.end()) {
1760 // There are updates. This means the context has external visible
1761 // storage, even if the original stored version didn't.
1762 DC->setHasExternalVisibleStorage(true);
1763 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001764 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1765 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001766 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00001767 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00001768 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00001769 }
1770 }
1771 assert(Idx == Record.size());
1772
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001773 // Load any relevant update records.
1774 loadDeclUpdateRecords(ID, D);
1775
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001776 if (ObjCChainedCategoriesInterfaces.count(ID))
1777 loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1778
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001779 // If we have deserialized a declaration that has a definition the
1780 // AST consumer might need to know about, queue it.
1781 // We don't pass it to the consumer immediately because we may be in recursive
1782 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001783 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00001784 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00001785
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001786 return D;
1787}
1788
1789void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001790 // The declaration may have been modified by files later in the chain.
1791 // If this is the case, read the record containing the updates from each file
1792 // and pass it to ASTDeclReader to make the modifications.
1793 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1794 if (UpdI != DeclUpdateOffsets.end()) {
1795 FileOffsetsTy &UpdateOffsets = UpdI->second;
1796 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001797 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001798 Module *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001799 uint64_t Offset = I->second;
1800 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1801 SavedStreamPosition SavedPosition(Cursor);
1802 Cursor.JumpToBit(Offset);
1803 RecordData Record;
1804 unsigned Code = Cursor.ReadCode();
1805 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1806 (void)RecCode;
1807 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001808
1809 unsigned Idx = 0;
Argyrios Kyrtzidis9d31fa72011-10-27 18:47:35 +00001810 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00001811 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001812 }
1813 }
Chris Lattner698f9252009-04-27 05:27:42 +00001814}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001815
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001816namespace {
1817 /// \brief Given an ObjC interface, goes through the modules and links to the
1818 /// interface all the categories for it.
1819 class ObjCChainedCategoriesVisitor {
1820 ASTReader &Reader;
1821 serialization::GlobalDeclID InterfaceID;
1822 ObjCInterfaceDecl *Interface;
1823 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1824 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1825
1826 public:
1827 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1828 serialization::GlobalDeclID InterfaceID,
1829 ObjCInterfaceDecl *Interface)
1830 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1831 GlobHeadCat(0), GlobTailCat(0) { }
1832
1833 static bool visit(Module &M, void *UserData) {
1834 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1835 }
1836
1837 bool visit(Module &M) {
1838 if (Reader.isDeclIDFromModule(InterfaceID, M))
1839 return true; // We reached the module where the interface originated
1840 // from. Stop traversing the imported modules.
1841
1842 Module::ChainedObjCCategoriesMap::iterator
1843 I = M.ChainedObjCCategories.find(InterfaceID);
1844 if (I == M.ChainedObjCCategories.end())
1845 return false;
1846
1847 ObjCCategoryDecl *
1848 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1849 ObjCCategoryDecl *
1850 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1851
1852 addCategories(HeadCat, TailCat);
1853 return false;
1854 }
1855
1856 void addCategories(ObjCCategoryDecl *HeadCat,
1857 ObjCCategoryDecl *TailCat = 0) {
1858 if (!HeadCat) {
1859 assert(!TailCat);
1860 return;
1861 }
1862
1863 if (!TailCat) {
1864 TailCat = HeadCat;
1865 while (TailCat->getNextClassCategory())
1866 TailCat = TailCat->getNextClassCategory();
1867 }
1868
1869 if (!GlobHeadCat) {
1870 GlobHeadCat = HeadCat;
1871 GlobTailCat = TailCat;
1872 } else {
1873 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1874 GlobTailCat = TailCat;
1875 }
1876
1877 llvm::DenseSet<DeclarationName> Checked;
1878 for (ObjCCategoryDecl *Cat = HeadCat,
1879 *CatEnd = TailCat->getNextClassCategory();
1880 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1881 if (Checked.count(Cat->getDeclName()))
1882 continue;
1883 Checked.insert(Cat->getDeclName());
1884 checkForDuplicate(Cat);
1885 }
1886 }
1887
1888 /// \brief Warns for duplicate categories that come from different modules.
1889 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1890 DeclarationName Name = Cat->getDeclName();
1891 // Find the top category with the same name. We do not want to warn for
1892 // duplicates along the established chain because there were already
1893 // warnings for them when the module was created. We only want to warn for
1894 // duplicates between non-dependent modules:
1895 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001896 // MT //
1897 // / \ //
1898 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001899 //
1900 // We want to warn for duplicates between ML and MR,not between ML and MT.
1901 //
1902 // FIXME: We should not warn for duplicates in diamond:
1903 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001904 // MT //
1905 // / \ //
1906 // ML MR //
1907 // \ / //
1908 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001909 //
1910 // If there are duplicates in ML/MR, there will be warning when creating
1911 // MB *and* when importing MB. We should not warn when importing.
1912 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1913 Next = Next->getNextClassCategory()) {
1914 if (Next->getDeclName() == Name)
1915 Cat = Next;
1916 }
1917
1918 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1919 if (!PrevCat)
1920 PrevCat = Cat;
1921
1922 if (PrevCat != Cat) {
1923 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1924 << Interface->getDeclName() << Name;
1925 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1926 }
1927 }
1928
1929 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1930 };
1931}
1932
1933void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1934 ObjCInterfaceDecl *D) {
1935 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1936 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1937 // Also add the categories that the interface already links to.
1938 Visitor.addCategories(D->getCategoryList());
1939 D->setCategoryList(Visitor.getHeadCategory());
1940}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001941
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001942void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +00001943 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001944 unsigned Idx = 0;
1945 while (Idx < Record.size()) {
1946 switch ((DeclUpdateKind)Record[Idx++]) {
1947 case UPD_CXX_SET_DEFINITIONDATA: {
1948 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00001949 CXXRecordDecl *DefinitionDecl
1950 = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001951 assert(!RD->DefinitionData && "DefinitionData is already set!");
1952 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1953 break;
1954 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001955
1956 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor496c7092011-08-03 15:48:04 +00001957 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001958 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00001959
1960 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1961 // It will be added to the template's specializations set when loaded.
Douglas Gregor496c7092011-08-03 15:48:04 +00001962 (void)Reader.ReadDecl(Module, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001963 break;
1964
1965 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00001966 NamespaceDecl *Anon
1967 = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00001968 // Guard against these being loaded out of original order. Don't use
1969 // getNextNamespace(), since it tries to access the context and can't in
1970 // the middle of deserialization.
1971 if (!Anon->NextNamespace) {
1972 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1973 TU->setAnonymousNamespace(Anon);
1974 else
1975 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1976 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001977 break;
1978 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00001979
1980 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1981 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1982 Reader.ReadSourceLocation(Module, Record, Idx));
1983 break;
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001984 }
1985 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001986}