blob: f64aa20a22f52bad83bee7cbbd5038ef20dd957a [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redlf5b13462010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner487412d2009-04-27 05:27:42 +000018#include "clang/AST/ASTConsumer.h"
19#include "clang/AST/ASTContext.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000032namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregora6895d82011-07-22 16:00:58 +000035 Module &F;
Sebastian Redlc67764e2010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl539c5062010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000038 typedef ASTReader::RecordData RecordData;
39 const RecordData &Record;
Chris Lattner487412d2009-04-27 05:27:42 +000040 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000041 TypeID TypeIDForTypeDecl;
Douglas Gregor250ffb12011-03-05 01:35:54 +000042
43 DeclID DeclContextIDForTemplateParmDecl;
44 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000045
Sebastian Redlc67764e2010-07-22 22:43:28 +000046 uint64_t GetCurrentCursorOffset();
Douglas Gregor7fb09192011-07-21 22:35:25 +000047
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000048 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000049 return Reader.ReadSourceLocation(F, R, I);
50 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000051
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000052 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000053 return Reader.ReadSourceRange(F, R, I);
54 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000055
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000056 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000057 return Reader.GetTypeSourceInfo(F, R, I);
58 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000059
60 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
61 return Reader.ReadDeclID(F, R, I);
62 }
63
64 Decl *ReadDecl(const RecordData &R, unsigned &I) {
65 return Reader.ReadDecl(F, R, I);
66 }
67
68 template<typename T>
69 T *ReadDeclAs(const RecordData &R, unsigned &I) {
70 return Reader.ReadDeclAs<T>(F, R, I);
71 }
72
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000073 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000074 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000075 Reader.ReadQualifierInfo(F, Info, R, I);
76 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000077
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000078 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000079 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000080 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
81 }
Douglas Gregor7fb09192011-07-21 22:35:25 +000082
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000083 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000084 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000085 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
86 }
Sebastian Redlc67764e2010-07-22 22:43:28 +000087
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +000088 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
89 const RecordData &R, unsigned &I);
90
91 void InitializeCXXDefinitionData(CXXRecordDecl *D,
92 CXXRecordDecl *DefinitionDecl,
93 const RecordData &Record, unsigned &Idx);
Chris Lattner487412d2009-04-27 05:27:42 +000094 public:
Douglas Gregora6895d82011-07-22 16:00:58 +000095 ASTDeclReader(ASTReader &Reader, Module &F,
Sebastian Redl2c373b92010-10-05 15:59:54 +000096 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000097 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +000098 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
99 Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +0000100
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000101 static void attachPreviousDecl(Decl *D, Decl *previous);
102
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000103 void Visit(Decl *D);
104
Douglas Gregora6895d82011-07-22 16:00:58 +0000105 void UpdateDecl(Decl *D, Module &Module,
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000106 const RecordData &Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000107
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000108 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
109 ObjCCategoryDecl *Next) {
110 Cat->NextClassCategory = Next;
111 }
112
Chris Lattner487412d2009-04-27 05:27:42 +0000113 void VisitDecl(Decl *D);
114 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
115 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000116 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000117 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000118 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
119 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000120 void VisitTypeDecl(TypeDecl *TD);
121 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000122 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000123 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000124 void VisitTagDecl(TagDecl *TD);
125 void VisitEnumDecl(EnumDecl *ED);
126 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000127 void VisitCXXRecordDecl(CXXRecordDecl *D);
128 void VisitClassTemplateSpecializationDecl(
129 ClassTemplateSpecializationDecl *D);
130 void VisitClassTemplatePartialSpecializationDecl(
131 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000132 void VisitClassScopeFunctionSpecializationDecl(
133 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000134 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000135 void VisitValueDecl(ValueDecl *VD);
136 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000137 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000138 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000139 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000140 void VisitCXXMethodDecl(CXXMethodDecl *D);
141 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
142 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
143 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000144 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000145 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000146 void VisitVarDecl(VarDecl *VD);
147 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
148 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000149 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
150 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000151 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000152 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000153 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000154 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000155 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000156 void VisitUsingDecl(UsingDecl *D);
157 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000158 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000159 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000160 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000161 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000162 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
163 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000164 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000165
Chris Lattner487412d2009-04-27 05:27:42 +0000166 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000167 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000168
Alexis Hunted053252010-05-30 07:21:58 +0000169 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000170 void VisitObjCMethodDecl(ObjCMethodDecl *D);
171 void VisitObjCContainerDecl(ObjCContainerDecl *D);
172 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
173 void VisitObjCIvarDecl(ObjCIvarDecl *D);
174 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
175 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
176 void VisitObjCClassDecl(ObjCClassDecl *D);
177 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
178 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
179 void VisitObjCImplDecl(ObjCImplDecl *D);
180 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
181 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
182 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
183 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
184 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
185 };
186}
187
Sebastian Redlb3298c32010-08-18 23:56:48 +0000188uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregord32f0352011-07-22 06:10:01 +0000189 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000190}
191
Sebastian Redlb3298c32010-08-18 23:56:48 +0000192void ASTDeclReader::Visit(Decl *D) {
193 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000194
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000195 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
196 if (DD->DeclInfo) {
197 DeclaratorDecl::ExtInfo *Info =
198 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
199 Info->TInfo =
200 GetTypeSourceInfo(Record, Idx);
201 }
202 else {
203 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
204 }
205 }
206
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000207 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000208 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000209 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000210 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
211 // FunctionDecl's body was written last after all other Stmts/Exprs.
212 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000213 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000214 } else if (D->isTemplateParameter()) {
215 // If we have a fully initialized template parameter, we can now
216 // set its DeclContext.
217 D->setDeclContext(
218 cast_or_null<DeclContext>(
219 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
220 D->setLexicalDeclContext(
221 cast_or_null<DeclContext>(
222 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000223 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000224}
225
Sebastian Redlb3298c32010-08-18 23:56:48 +0000226void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000227 if (D->isTemplateParameter()) {
228 // We don't want to deserialize the DeclContext of a template
229 // parameter immediately, because the template parameter might be
230 // used in the formulation of its DeclContext. Use the translation
231 // unit DeclContext as a placeholder.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000232 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
233 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000234 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000235 } else {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000236 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
237 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000238 }
Sebastian Redl2c373b92010-10-05 15:59:54 +0000239 D->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000240 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000241 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000242 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000243 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000244 D->setAttrs(Attrs);
245 }
Chris Lattner487412d2009-04-27 05:27:42 +0000246 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000247 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000248 D->setReferenced(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000249 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000250 D->FromASTFile = true;
Douglas Gregor26701a42011-09-09 02:06:17 +0000251 D->ModulePrivate = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000252}
253
Sebastian Redlb3298c32010-08-18 23:56:48 +0000254void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000255 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000256}
257
Sebastian Redlb3298c32010-08-18 23:56:48 +0000258void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000259 VisitDecl(ND);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000260 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000261}
262
Sebastian Redlb3298c32010-08-18 23:56:48 +0000263void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000264 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000265 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000266 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor903b7e92011-07-22 00:38:23 +0000267 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000268}
269
Sebastian Redlb3298c32010-08-18 23:56:48 +0000270void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000271 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000272 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000273}
274
Richard Smithdda56e42011-04-15 14:24:37 +0000275void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
276 VisitTypeDecl(TD);
277 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
278}
279
Sebastian Redlb3298c32010-08-18 23:56:48 +0000280void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000281 VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000282 VisitTypeDecl(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000283 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000284 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCallf937c022011-10-07 06:10:15 +0000285 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000286 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000287 TD->setFreeStanding(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000288 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000289 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000290 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000291 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000292 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000293 } else
Douglas Gregor7fb09192011-07-21 22:35:25 +0000294 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000295}
296
Sebastian Redlb3298c32010-08-18 23:56:48 +0000297void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000298 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000299 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
300 ED->setIntegerTypeSourceInfo(TI);
301 else
Douglas Gregor903b7e92011-07-22 00:38:23 +0000302 ED->setIntegerType(Reader.readType(F, Record, Idx));
303 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000304 ED->setNumPositiveBits(Record[Idx++]);
305 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000306 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000307 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000308 ED->IsFixed = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000309 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000310}
311
Sebastian Redlb3298c32010-08-18 23:56:48 +0000312void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000313 VisitTagDecl(RD);
314 RD->setHasFlexibleArrayMember(Record[Idx++]);
315 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000316 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000317}
318
Sebastian Redlb3298c32010-08-18 23:56:48 +0000319void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000320 VisitNamedDecl(VD);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000321 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000322}
323
Sebastian Redlb3298c32010-08-18 23:56:48 +0000324void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000325 VisitValueDecl(ECD);
326 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000327 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000328 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
329}
330
Sebastian Redlb3298c32010-08-18 23:56:48 +0000331void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000332 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000333 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000334 if (Record[Idx++]) { // hasExtInfo
335 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000336 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000337 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000338 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000339 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000340}
341
Sebastian Redlb3298c32010-08-18 23:56:48 +0000342void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000343 VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000344 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000345
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000346 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000347 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000348 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikie83d382b2011-09-23 05:06:16 +0000349 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000350 case FunctionDecl::TK_NonTemplate:
351 break;
352 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000353 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
354 Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000355 break;
356 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000357 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000358 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000359 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000360 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000361 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
362 break;
363 }
364 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000365 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
366 Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000367 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
368
369 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000370 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000371 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000372
373 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000374 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000375 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000376 bool HasTemplateArgumentsAsWritten = Record[Idx++];
377 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000378 unsigned NumTemplateArgLocs = Record[Idx++];
379 TemplArgLocs.reserve(NumTemplateArgLocs);
380 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000381 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000382 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000383
Sebastian Redl2c373b92010-10-05 15:59:54 +0000384 LAngleLoc = ReadSourceLocation(Record, Idx);
385 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000386 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000387
Sebastian Redl2c373b92010-10-05 15:59:54 +0000388 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000389
Douglas Gregor4163aca2011-09-09 21:34:22 +0000390 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000391 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000392 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000393 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000394 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000395 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000396 FunctionTemplateSpecializationInfo *FTInfo
397 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
398 TemplArgList,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000399 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
400 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000401 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000402
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000403 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000404 // The template that contains the specializations set. It's not safe to
405 // use getCanonicalDecl on Template since it may still be initializing.
406 FunctionTemplateDecl *CanonTemplate
Douglas Gregor7fb09192011-07-21 22:35:25 +0000407 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000408 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
409 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
410 // FunctionTemplateSpecializationInfo's Profile().
411 // We avoid getASTContext because a decl in the parent hierarchy may
412 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000413 llvm::FoldingSetNodeID ID;
414 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
415 TemplArgs.size(), C);
416 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000417 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000418 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000419 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000420 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000421 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000422 }
423 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
424 // Templates.
425 UnresolvedSet<8> TemplDecls;
426 unsigned NumTemplates = Record[Idx++];
427 while (NumTemplates--)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000428 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000429
430 // Templates args.
431 TemplateArgumentListInfo TemplArgs;
432 unsigned NumArgs = Record[Idx++];
433 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000434 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
435 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
436 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000437
Douglas Gregor4163aca2011-09-09 21:34:22 +0000438 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000439 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000440 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000441 }
442 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000443
Sebastian Redlb3298c32010-08-18 23:56:48 +0000444 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000445 // after everything else is read.
446
Douglas Gregorbf62d642010-12-06 18:36:25 +0000447 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000448 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000449 FD->IsInline = Record[Idx++];
450 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000451 FD->IsVirtualAsWritten = Record[Idx++];
452 FD->IsPure = Record[Idx++];
453 FD->HasInheritedPrototype = Record[Idx++];
454 FD->HasWrittenPrototype = Record[Idx++];
455 FD->IsDeleted = Record[Idx++];
456 FD->IsTrivial = Record[Idx++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000457 FD->IsDefaulted = Record[Idx++];
458 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000459 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smitha77a0a62011-08-15 21:04:07 +0000460 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000461 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000462
Chris Lattnerca025db2010-05-07 21:43:38 +0000463 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000464 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000465 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000466 Params.reserve(NumParams);
467 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000468 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000469 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000470}
471
Sebastian Redlb3298c32010-08-18 23:56:48 +0000472void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000473 VisitNamedDecl(MD);
474 if (Record[Idx++]) {
475 // In practice, this won't be executed (since method definitions
476 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000477 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000478 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
479 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000480 }
481 MD->setInstanceMethod(Record[Idx++]);
482 MD->setVariadic(Record[Idx++]);
483 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000484 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000485
486 MD->IsRedeclaration = Record[Idx++];
487 MD->HasRedeclaration = Record[Idx++];
488 if (MD->HasRedeclaration)
489 Reader.getContext().setObjCMethodRedeclaration(MD,
490 ReadDeclAs<ObjCMethodDecl>(Record, Idx));
491
Chris Lattner487412d2009-04-27 05:27:42 +0000492 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
493 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000494 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000495 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000496 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
497 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000498 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000499 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000500 Params.reserve(NumParams);
501 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000502 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000503
504 MD->SelLocsKind = Record[Idx++];
505 unsigned NumStoredSelLocs = Record[Idx++];
506 SmallVector<SourceLocation, 16> SelLocs;
507 SelLocs.reserve(NumStoredSelLocs);
508 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
509 SelLocs.push_back(ReadSourceLocation(Record, Idx));
510
511 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +0000512}
513
Sebastian Redlb3298c32010-08-18 23:56:48 +0000514void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000515 VisitNamedDecl(CD);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000516 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
517 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000518}
519
Sebastian Redlb3298c32010-08-18 23:56:48 +0000520void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000521 VisitObjCContainerDecl(ID);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000522 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000523 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000524
525 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000526 unsigned NumProtocols = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000527 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner487412d2009-04-27 05:27:42 +0000528 Protocols.reserve(NumProtocols);
529 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000530 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000531 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000532 ProtoLocs.reserve(NumProtocols);
533 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000534 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000535 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000536 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000537
538 // Read the transitive closure of protocols referenced by this class.
539 NumProtocols = Record[Idx++];
540 Protocols.clear();
541 Protocols.reserve(NumProtocols);
542 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000543 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000544 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor4163aca2011-09-09 21:34:22 +0000545 Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000546
547 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000548 unsigned NumIvars = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000549 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner487412d2009-04-27 05:27:42 +0000550 IVars.reserve(NumIvars);
551 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000552 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
553 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
554
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000555 // We will rebuild this list lazily.
556 ID->setIvarList(0);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000557 ID->InitiallyForwardDecl = Record[Idx++];
Douglas Gregor1c283312010-08-11 12:19:30 +0000558 ID->setForwardDecl(Record[Idx++]);
559 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000560 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
561 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000562}
563
Sebastian Redlb3298c32010-08-18 23:56:48 +0000564void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000565 VisitFieldDecl(IVD);
566 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000567 // This field will be built lazily.
568 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000569 bool synth = Record[Idx++];
570 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000571}
572
Sebastian Redlb3298c32010-08-18 23:56:48 +0000573void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000574 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +0000575 PD->InitiallyForwardDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000576 PD->setForwardDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000577 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000578 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000579 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000580 ProtoRefs.reserve(NumProtoRefs);
581 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000582 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000583 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000584 ProtoLocs.reserve(NumProtoRefs);
585 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000586 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000587 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000588 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000589}
590
Sebastian Redlb3298c32010-08-18 23:56:48 +0000591void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000592 VisitFieldDecl(FD);
593}
594
Sebastian Redlb3298c32010-08-18 23:56:48 +0000595void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000596 VisitDecl(CD);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +0000597 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
598 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000599 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner487412d2009-04-27 05:27:42 +0000600}
601
Sebastian Redlb3298c32010-08-18 23:56:48 +0000602void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000603 VisitDecl(FPD);
604 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000605 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000606 ProtoRefs.reserve(NumProtoRefs);
607 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000608 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000609 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000610 ProtoLocs.reserve(NumProtoRefs);
611 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000612 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000613 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000614 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000615}
616
Sebastian Redlb3298c32010-08-18 23:56:48 +0000617void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000618 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000619 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000620 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000621 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +0000622 ProtoRefs.reserve(NumProtoRefs);
623 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000624 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000625 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +0000626 ProtoLocs.reserve(NumProtoRefs);
627 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000628 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000629 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +0000630 Reader.getContext());
Argyrios Kyrtzidis3a5094b2011-08-30 19:43:26 +0000631 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000632 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000633 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000634}
635
Sebastian Redlb3298c32010-08-18 23:56:48 +0000636void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000637 VisitNamedDecl(CAD);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000638 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000639}
640
Sebastian Redlb3298c32010-08-18 23:56:48 +0000641void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000642 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000643 D->setAtLoc(ReadSourceLocation(Record, Idx));
644 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000645 // FIXME: stable encoding
646 D->setPropertyAttributes(
647 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000648 D->setPropertyAttributesAsWritten(
649 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000650 // FIXME: stable encoding
651 D->setPropertyImplementation(
652 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor903b7e92011-07-22 00:38:23 +0000653 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
654 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor7fb09192011-07-21 22:35:25 +0000655 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
656 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
657 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000658}
659
Sebastian Redlb3298c32010-08-18 23:56:48 +0000660void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000661 VisitObjCContainerDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000662 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000663}
664
Sebastian Redlb3298c32010-08-18 23:56:48 +0000665void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000666 VisitObjCImplDecl(D);
Douglas Gregora3e41532011-07-28 20:55:49 +0000667 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000668}
669
Sebastian Redlb3298c32010-08-18 23:56:48 +0000670void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000671 VisitObjCImplDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000672 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000673 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000674 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000675 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000676}
677
678
Sebastian Redlb3298c32010-08-18 23:56:48 +0000679void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000680 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000681 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor7fb09192011-07-21 22:35:25 +0000682 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
683 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000684 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000685 D->setGetterCXXConstructor(Reader.ReadExpr(F));
686 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000687}
688
Sebastian Redlb3298c32010-08-18 23:56:48 +0000689void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000690 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000691 FD->setMutable(Record[Idx++]);
Richard Smith938f40b2011-06-11 17:19:42 +0000692 int BitWidthOrInitializer = Record[Idx++];
693 if (BitWidthOrInitializer == 1)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000694 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith938f40b2011-06-11 17:19:42 +0000695 else if (BitWidthOrInitializer == 2)
696 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000697 if (!FD->getDeclName()) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000698 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000699 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000700 }
Chris Lattner487412d2009-04-27 05:27:42 +0000701}
702
Francois Pichet783dd6e2010-11-21 06:08:52 +0000703void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
704 VisitValueDecl(FD);
705
706 FD->ChainingSize = Record[Idx++];
707 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +0000708 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +0000709
710 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000711 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000712}
713
Sebastian Redlb3298c32010-08-18 23:56:48 +0000714void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000715 VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000716 VisitDeclaratorDecl(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000717 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
718 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
719 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
720 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
721 VD->VarDeclBits.ExceptionVar = Record[Idx++];
722 VD->VarDeclBits.NRVOVariable = Record[Idx++];
723 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCalld4631322011-06-17 06:42:21 +0000724 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000725 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000726 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000727
728 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor7fb09192011-07-21 22:35:25 +0000729 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000730 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000731 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000732 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000733 }
Chris Lattner487412d2009-04-27 05:27:42 +0000734}
735
Sebastian Redlb3298c32010-08-18 23:56:48 +0000736void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000737 VisitVarDecl(PD);
738}
739
Sebastian Redlb3298c32010-08-18 23:56:48 +0000740void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000741 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000742 unsigned isObjCMethodParam = Record[Idx++];
743 unsigned scopeDepth = Record[Idx++];
744 unsigned scopeIndex = Record[Idx++];
745 unsigned declQualifier = Record[Idx++];
746 if (isObjCMethodParam) {
747 assert(scopeDepth == 0);
748 PD->setObjCMethodScopeInfo(scopeIndex);
749 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
750 } else {
751 PD->setScopeInfo(scopeDepth, scopeIndex);
752 }
John McCallbeaa11c2011-05-01 02:13:58 +0000753 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
754 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000755 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000756 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000757}
758
Sebastian Redlb3298c32010-08-18 23:56:48 +0000759void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000760 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000761 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000762 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000763}
764
Sebastian Redlb3298c32010-08-18 23:56:48 +0000765void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000766 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000767 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
768 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000769 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000770 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000771 Params.reserve(NumParams);
772 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor7fb09192011-07-21 22:35:25 +0000773 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie9c70e042011-09-21 18:16:56 +0000774 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +0000775
776 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000777 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000778 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +0000779 captures.reserve(numCaptures);
780 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000781 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall351762c2011-02-07 10:33:21 +0000782 unsigned flags = Record[Idx++];
783 bool byRef = (flags & 1);
784 bool nested = (flags & 2);
785 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
786
787 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
788 }
Douglas Gregor4163aca2011-09-09 21:34:22 +0000789 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall351762c2011-02-07 10:33:21 +0000790 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000791}
792
Sebastian Redlb3298c32010-08-18 23:56:48 +0000793void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000794 VisitDecl(D);
795 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000796 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000797 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000798}
799
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000800void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
801 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000802 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000803}
804
805
Sebastian Redlb3298c32010-08-18 23:56:48 +0000806void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000807 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000808 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000809 D->LocStart = ReadSourceLocation(Record, Idx);
810 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000811 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000812
Chris Lattnerca025db2010-05-07 21:43:38 +0000813 bool IsOriginal = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +0000814 // FIXME: Modules will likely have trouble with pointing directly at
815 // the original namespace.
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000816 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000817 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000818}
819
Sebastian Redlb3298c32010-08-18 23:56:48 +0000820void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000821 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000822 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000823 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000824 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000825 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000826}
827
Sebastian Redlb3298c32010-08-18 23:56:48 +0000828void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000829 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000830 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000831 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000832 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000833 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000834 D->setTypeName(Record[Idx++]);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000835 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +0000836 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000837}
838
Sebastian Redlb3298c32010-08-18 23:56:48 +0000839void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000840 VisitNamedDecl(D);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000841 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
842 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
843 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000844 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +0000845 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000846}
847
Sebastian Redlb3298c32010-08-18 23:56:48 +0000848void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000849 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000850 D->UsingLoc = ReadSourceLocation(Record, Idx);
851 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000852 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000853 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
854 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000855}
856
Sebastian Redlb3298c32010-08-18 23:56:48 +0000857void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000858 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000859 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000860 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000861 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000862}
863
Sebastian Redlb3298c32010-08-18 23:56:48 +0000864void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000865 UnresolvedUsingTypenameDecl *D) {
866 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000867 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000868 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000869}
870
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000871void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000872 struct CXXRecordDecl::DefinitionData &Data,
873 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000874 Data.UserDeclaredConstructor = Record[Idx++];
875 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000876 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000877 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000878 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000879 Data.UserDeclaredDestructor = Record[Idx++];
880 Data.Aggregate = Record[Idx++];
881 Data.PlainOldData = Record[Idx++];
882 Data.Empty = Record[Idx++];
883 Data.Polymorphic = Record[Idx++];
884 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000885 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000886 Data.HasNoNonEmptyBases = Record[Idx++];
887 Data.HasPrivateFields = Record[Idx++];
888 Data.HasProtectedFields = Record[Idx++];
889 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000890 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000891 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +0000892 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000893 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000894 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000895 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000896 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000897 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000898 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000899 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000900 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000901 Data.DeclaredDefaultConstructor = Record[Idx++];
902 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000903 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000904 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregorcd0d8262011-09-06 16:38:46 +0000905 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000906 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redlb7448632011-08-31 13:59:56 +0000907 Data.FailedImplicitMoveConstructor = Record[Idx++];
908 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000909
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000910 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000911 if (Data.NumBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000912 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000913 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000914 if (Data.NumVBases)
Douglas Gregorc27b2872011-08-04 00:01:48 +0000915 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000916
Douglas Gregor7fb09192011-07-21 22:35:25 +0000917 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
918 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000919 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor7fb09192011-07-21 22:35:25 +0000920 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000921}
922
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000923void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
924 CXXRecordDecl *DefinitionDecl,
925 const RecordData &Record,
926 unsigned &Idx) {
Douglas Gregor4163aca2011-09-09 21:34:22 +0000927 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000928
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000929 if (D == DefinitionDecl) {
930 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000931 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000932 // We read the definition info. Check if there are pending forward
933 // references that need to point to this DefinitionData pointer.
934 ASTReader::PendingForwardRefsMap::iterator
935 FindI = Reader.PendingForwardRefs.find(D);
936 if (FindI != Reader.PendingForwardRefs.end()) {
937 ASTReader::ForwardRefs &Refs = FindI->second;
938 for (ASTReader::ForwardRefs::iterator
939 I = Refs.begin(), E = Refs.end(); I != E; ++I)
940 (*I)->DefinitionData = D->DefinitionData;
941#ifndef NDEBUG
942 // We later check whether PendingForwardRefs is empty to make sure all
943 // pending references were linked.
944 Reader.PendingForwardRefs.erase(D);
945#endif
946 }
947 } else if (DefinitionDecl) {
948 if (DefinitionDecl->DefinitionData) {
949 D->DefinitionData = DefinitionDecl->DefinitionData;
950 } else {
951 // The definition is still initializing.
952 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
953 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000954 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000955}
956
957void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
958 VisitRecordDecl(D);
959
Douglas Gregor7fb09192011-07-21 22:35:25 +0000960 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000961 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
962
Douglas Gregor4163aca2011-09-09 21:34:22 +0000963 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000964
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000965 enum CXXRecKind {
966 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
967 };
968 switch ((CXXRecKind)Record[Idx++]) {
969 default:
David Blaikie83d382b2011-09-23 05:06:16 +0000970 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000971 case CXXRecNotTemplate:
972 break;
973 case CXXRecTemplate:
Douglas Gregor7fb09192011-07-21 22:35:25 +0000974 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000975 break;
976 case CXXRecMemberSpecialization: {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000977 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000978 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000979 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000980 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
981 MSI->setPointOfInstantiation(POI);
982 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000983 break;
984 }
985 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +0000986
987 // Load the key function to avoid deserializing every method so we can
988 // compute it.
John McCallf937c022011-10-07 06:10:15 +0000989 if (D->IsCompleteDefinition) {
Douglas Gregor7fb09192011-07-21 22:35:25 +0000990 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +0000991 C.KeyFunctions[D] = Key;
992 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000993}
994
Sebastian Redlb3298c32010-08-18 23:56:48 +0000995void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000996 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000997 unsigned NumOverridenMethods = Record[Idx++];
998 while (NumOverridenMethods--) {
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000999 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1000 // MD may be initializing.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001001 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor4163aca2011-09-09 21:34:22 +00001002 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001003 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001004}
1005
Sebastian Redlb3298c32010-08-18 23:56:48 +00001006void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001007 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001008
1009 D->IsExplicitSpecified = Record[Idx++];
1010 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +00001011 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1012 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001013}
1014
Sebastian Redlb3298c32010-08-18 23:56:48 +00001015void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001016 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001017
1018 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor7fb09192011-07-21 22:35:25 +00001019 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001020}
1021
Sebastian Redlb3298c32010-08-18 23:56:48 +00001022void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001023 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001024 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001025}
1026
Sebastian Redlb3298c32010-08-18 23:56:48 +00001027void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001028 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001029 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001030}
1031
Sebastian Redlb3298c32010-08-18 23:56:48 +00001032void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001033 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001034 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001035 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001036 else
Douglas Gregor7fb09192011-07-21 22:35:25 +00001037 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001038 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001039 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001040 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001041}
1042
Sebastian Redlb3298c32010-08-18 23:56:48 +00001043void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001044 VisitDecl(D);
1045 unsigned NumParams = Record[Idx++];
1046 D->NumParams = NumParams;
1047 D->Params = new TemplateParameterList*[NumParams];
1048 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001049 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001050 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor7fb09192011-07-21 22:35:25 +00001051 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001052 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001053 D->Friend = GetTypeSourceInfo(Record, Idx);
1054 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001055}
1056
Sebastian Redlb3298c32010-08-18 23:56:48 +00001057void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001058 VisitNamedDecl(D);
1059
Douglas Gregor7fb09192011-07-21 22:35:25 +00001060 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001061 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001062 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001063 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001064}
1065
Sebastian Redlb3298c32010-08-18 23:56:48 +00001066void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001067 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1068 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001069
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001070 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor7fb09192011-07-21 22:35:25 +00001071 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1072 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001073 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1074 // We temporarily set the first (canonical) declaration as the previous one
1075 // which is the one that matters and mark the real previous DeclID to be
1076 // loaded & attached later on.
1077 RedeclarableTemplateDecl *FirstDecl =
1078 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1079 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1080 "FirstDecl kind mismatch");
1081 if (FirstDecl) {
1082 D->CommonOrPrev = FirstDecl;
1083 // Mark the real previous DeclID to be loaded & attached later on.
1084 if (PreviousDeclID != FirstDeclID)
1085 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1086 } else {
Douglas Gregor4163aca2011-09-09 21:34:22 +00001087 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001088 if (RedeclarableTemplateDecl *RTD
Douglas Gregor7fb09192011-07-21 22:35:25 +00001089 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001090 assert(RTD->getKind() == D->getKind() &&
1091 "InstantiatedFromMemberTemplate kind mismatch");
1092 D->setInstantiatedFromMemberTemplateImpl(RTD);
1093 if (Record[Idx++])
1094 D->setMemberSpecialization();
1095 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001096
Douglas Gregor7fb09192011-07-21 22:35:25 +00001097 RedeclarableTemplateDecl *LatestDecl
1098 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001099
1100 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001101 // in the same AST file. However, if this actually needs to point to a
1102 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001103 // the FirstLatestDeclIDs map which tracks this kind of decls.
1104 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001105 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001106 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1107 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregoraa7cbfd2011-08-25 15:28:26 +00001108 if (Decl *NewLatest = Reader.GetDecl(I->second))
1109 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001110 }
1111
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001112 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1113 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001114 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001115
1116 VisitTemplateDecl(D);
1117 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001118}
1119
Sebastian Redlb3298c32010-08-18 23:56:48 +00001120void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001121 VisitRedeclarableTemplateDecl(D);
1122
1123 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001124 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1125 // the specializations.
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001126 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001127 SpecIDs.push_back(0);
1128
1129 // Specializations.
1130 unsigned Size = Record[Idx++];
1131 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001132 for (unsigned I = 0; I != Size; ++I)
1133 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001134
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001135 // Partial specializations.
1136 Size = Record[Idx++];
1137 SpecIDs[0] += Size;
Douglas Gregor7fb09192011-07-21 22:35:25 +00001138 for (unsigned I = 0; I != Size; ++I)
1139 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001140
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001141 if (SpecIDs[0]) {
1142 typedef serialization::DeclID DeclID;
1143
1144 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1145 CommonPtr->LazySpecializations
Douglas Gregor4163aca2011-09-09 21:34:22 +00001146 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001147 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1148 SpecIDs.size() * sizeof(DeclID));
1149 }
1150
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001151 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001152 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001153}
1154
Sebastian Redlb3298c32010-08-18 23:56:48 +00001155void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001156 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001157 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001158
Douglas Gregor4163aca2011-09-09 21:34:22 +00001159 ASTContext &C = Reader.getContext();
Douglas Gregor7fb09192011-07-21 22:35:25 +00001160 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001161 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001162 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001163 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001164 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001165 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001166 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001167 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1168 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001169 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1170 = new (C) ClassTemplateSpecializationDecl::
1171 SpecializedPartialSpecialization();
1172 PS->PartialSpecialization
1173 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1174 PS->TemplateArgs = ArgList;
1175 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001176 }
1177 }
1178
1179 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001180 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001181 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1182 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1183 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001184 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1185 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001186 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001187 }
1188
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001189 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001190 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001191 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1192 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001193 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001194 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001195
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001196 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor7fb09192011-07-21 22:35:25 +00001197 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001198 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001199 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1200 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001201 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001202 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001203 }
1204 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001205}
1206
Sebastian Redlb3298c32010-08-18 23:56:48 +00001207void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001208 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001209 VisitClassTemplateSpecializationDecl(D);
1210
Douglas Gregor4163aca2011-09-09 21:34:22 +00001211 ASTContext &C = Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001212 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001213
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001214 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001215 if (NumArgs) {
1216 D->NumArgsAsWritten = NumArgs;
1217 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1218 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001219 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001220 }
1221
1222 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001223
1224 // These are read/set from/to the first declaration.
1225 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001226 D->InstantiatedFromMember.setPointer(
Douglas Gregor7fb09192011-07-21 22:35:25 +00001227 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001228 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001229 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001230}
1231
Sebastian Redlb7448632011-08-31 13:59:56 +00001232void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1233 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001234 VisitDecl(D);
1235 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1236}
1237
Sebastian Redlb3298c32010-08-18 23:56:48 +00001238void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001239 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001240
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001241 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001242 // This FunctionTemplateDecl owns a CommonPtr; read it.
1243
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001244 // Read the function specialization declarations.
1245 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001246 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001247 unsigned NumSpecs = Record[Idx++];
1248 while (NumSpecs--)
Douglas Gregor7fb09192011-07-21 22:35:25 +00001249 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001250 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001251}
1252
Sebastian Redlb3298c32010-08-18 23:56:48 +00001253void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001254 VisitTypeDecl(D);
1255
1256 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001257
1258 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001259 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001260 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001261}
1262
Sebastian Redlb3298c32010-08-18 23:56:48 +00001263void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001264 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001265 // TemplateParmPosition.
1266 D->setDepth(Record[Idx++]);
1267 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001268 if (D->isExpandedParameterPack()) {
1269 void **Data = reinterpret_cast<void **>(D + 1);
1270 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor903b7e92011-07-22 00:38:23 +00001271 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001272 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1273 }
1274 } else {
1275 // Rest of NonTypeTemplateParmDecl.
1276 D->ParameterPack = Record[Idx++];
1277 if (Record[Idx++]) {
1278 Expr *DefArg = Reader.ReadExpr(F);
1279 bool Inherited = Record[Idx++];
1280 D->setDefaultArgument(DefArg, Inherited);
1281 }
1282 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001283}
1284
Sebastian Redlb3298c32010-08-18 23:56:48 +00001285void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001286 VisitTemplateDecl(D);
1287 // TemplateParmPosition.
1288 D->setDepth(Record[Idx++]);
1289 D->setPosition(Record[Idx++]);
1290 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001291 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001292 bool IsInherited = Record[Idx++];
1293 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001294 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001295}
1296
Richard Smith3f1b5d02011-05-05 21:57:07 +00001297void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1298 VisitRedeclarableTemplateDecl(D);
1299}
1300
Sebastian Redlb3298c32010-08-18 23:56:48 +00001301void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001302 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001303 D->AssertExpr = Reader.ReadExpr(F);
1304 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001305 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001306}
1307
Mike Stump11289f42009-09-09 15:08:12 +00001308std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001309ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001310 uint64_t LexicalOffset = Record[Idx++];
1311 uint64_t VisibleOffset = Record[Idx++];
1312 return std::make_pair(LexicalOffset, VisibleOffset);
1313}
1314
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001315template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001316void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001317 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1318 RedeclKind Kind = (RedeclKind)Record[Idx++];
1319 switch (Kind) {
1320 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001321 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1322 " messed up reading");
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001323 case NoRedeclaration:
1324 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001325 case PointsToPrevious: {
Douglas Gregor7fb09192011-07-21 22:35:25 +00001326 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1327 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001328 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1329 // We temporarily set the first (canonical) declaration as the previous one
1330 // which is the one that matters and mark the real previous DeclID to be
1331 // loaded & attached later on.
Douglas Gregor3e300102011-10-26 17:53:41 +00001332 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
1333 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001334 if (PreviousDeclID != FirstDeclID)
1335 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1336 PreviousDeclID));
Douglas Gregor3e300102011-10-26 17:53:41 +00001337
1338 // If the first declaration in the chain is in an inconsistent
1339 // state where it thinks that it is the only declaration, fix its
1340 // redeclaration link now to point at this declaration, so that we have a
1341 // proper redeclaration chain.
1342 if (FirstDecl->RedeclLink.getPointer() == FirstDecl) {
1343 FirstDecl->RedeclLink
1344 = typename Redeclarable<T>::LatestDeclLink(static_cast<T*>(D));
1345 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001346 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001347 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001348 case PointsToLatest: {
1349 T *LatestDecl = ReadDeclAs<T>(Record, Idx);
1350 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(LatestDecl);
1351
1352 // If the latest declaration in the chain is in an inconsistent
1353 // state where it thinks that it is the only declaration, fix its
1354 // redeclaration link now to point at this declaration, so that we have a
1355 // proper redeclaration chain.
1356 if (LatestDecl->RedeclLink.getPointer() == LatestDecl) {
1357 LatestDecl->RedeclLink
1358 = typename Redeclarable<T>::PreviousDeclLink(static_cast<T*>(D));
1359 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001360 break;
1361 }
Douglas Gregor3e300102011-10-26 17:53:41 +00001362 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001363
1364 assert(!(Kind == PointsToPrevious &&
1365 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1366 Reader.FirstLatestDeclIDs.end()) &&
1367 "This decl is not first, it should not be in the map");
1368 if (Kind == PointsToPrevious)
1369 return;
1370
1371 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001372 // the same AST file. However, if this actually needs to point to a
1373 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001374 // FirstLatestDeclIDs map which tracks this kind of decls.
1375 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1376 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001377 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001378 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1379 if (I != Reader.FirstLatestDeclIDs.end()) {
1380 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001381 D->RedeclLink
1382 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1383 }
1384}
1385
Chris Lattner487412d2009-04-27 05:27:42 +00001386//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001387// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001388//===----------------------------------------------------------------------===//
1389
Chris Lattner8f63ab52009-04-27 06:01:06 +00001390/// \brief Reads attributes from the current stream position.
Douglas Gregora6895d82011-07-22 16:00:58 +00001391void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001392 const RecordData &Record, unsigned &Idx) {
1393 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001394 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001395 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00001396 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001397
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001398#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001399
1400 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001401 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001402 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001403}
1404
1405//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001406// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001407//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001408
1409/// \brief Note that we have loaded the declaration with the given
1410/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001411///
Chris Lattner487412d2009-04-27 05:27:42 +00001412/// This routine notes that this declaration has already been loaded,
1413/// so that future GetDecl calls will return this declaration rather
1414/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001415inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001416 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1417 DeclsLoaded[Index] = D;
1418}
1419
1420
1421/// \brief Determine whether the consumer will be interested in seeing
1422/// this declaration (via HandleTopLevelDecl).
1423///
1424/// This routine should return true for anything that might affect
1425/// code generation, e.g., inline function definitions, Objective-C
1426/// declarations with metadata, etc.
1427static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001428 // An ObjCMethodDecl is never considered as "interesting" because its
1429 // implementation container always is.
1430
Douglas Gregor87d81242011-09-10 00:22:34 +00001431 if (isa<FileScopeAsmDecl>(D) ||
1432 isa<ObjCProtocolDecl>(D) ||
1433 isa<ObjCImplDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001434 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001435 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001436 return Var->isFileVarDecl() &&
1437 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001438 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001439 return Func->doesThisDeclarationHaveABody();
Douglas Gregor87d81242011-09-10 00:22:34 +00001440
1441 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00001442}
1443
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001444/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001445ASTReader::RecordLocation
Douglas Gregorf7180622011-08-03 15:48:04 +00001446ASTReader::DeclCursorForID(DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001447 // See if there's an override.
1448 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1449 if (It != ReplacedDecls.end())
Sebastian Redl2c373b92010-10-05 15:59:54 +00001450 return RecordLocation(It->second.first, It->second.second);
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001451
Douglas Gregor047d2ef2011-07-20 00:27:43 +00001452 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1453 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorbab6d2c2011-07-29 00:56:45 +00001454 Module *M = I->second;
Douglas Gregor8f364fb2011-08-03 23:28:44 +00001455 return RecordLocation(M,
1456 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
Sebastian Redl34627792010-07-20 22:46:15 +00001457}
1458
Douglas Gregord32f0352011-07-22 06:10:01 +00001459ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregora6895d82011-07-22 16:00:58 +00001460 ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00001461 = GlobalBitOffsetsMap.find(GlobalOffset);
1462
1463 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1464 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1465}
1466
Douglas Gregorc27b2872011-08-04 00:01:48 +00001467uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1468 return LocalOffset + M.GlobalBitOffset;
1469}
1470
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001471void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1472 assert(D && previous);
1473 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1474 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1475 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1476 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1477 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1478 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1479 } else {
1480 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1481 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1482 }
1483}
1484
1485void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1486 Decl *previous = GetDecl(ID);
1487 ASTDeclReader::attachPreviousDecl(D, previous);
1488}
1489
Sebastian Redlb3298c32010-08-18 23:56:48 +00001490/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00001491Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00001492 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Douglas Gregorf7180622011-08-03 15:48:04 +00001493 RecordLocation Loc = DeclCursorForID(ID);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001494 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001495 // Keep track of where we are in the stream, then jump back there
1496 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001497 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001498
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001499 ReadingKindTracker ReadingKind(Read_Decl, *this);
1500
Douglas Gregor1342e842009-07-06 18:54:52 +00001501 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001502 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001503
Sebastian Redl2c373b92010-10-05 15:59:54 +00001504 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001505 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001506 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001507 unsigned Idx = 0;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001508 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001509
Chris Lattner1de76db2009-04-27 05:58:23 +00001510 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001511 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001512 case DECL_CONTEXT_LEXICAL:
1513 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00001514 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00001515 case DECL_TYPEDEF:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001516 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001517 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001518 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001519 case DECL_TYPEALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001520 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smithdda56e42011-04-15 14:24:37 +00001521 0, 0);
1522 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001523 case DECL_ENUM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001524 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001525 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001526 case DECL_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001527 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001528 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001529 case DECL_ENUM_CONSTANT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001530 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001531 0, llvm::APSInt());
1532 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001533 case DECL_FUNCTION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001534 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001535 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001536 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001537 case DECL_LINKAGE_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001538 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001539 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001540 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001541 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001542 case DECL_LABEL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001543 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001544 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001545 case DECL_NAMESPACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001546 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001547 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001548 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001549 case DECL_NAMESPACE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001550 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001551 SourceLocation(), 0,
1552 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001553 SourceLocation(), 0);
1554 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001555 case DECL_USING:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001556 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001557 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1558 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001559 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001560 case DECL_USING_SHADOW:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001561 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001562 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001563 case DECL_USING_DIRECTIVE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001564 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001565 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001566 SourceLocation(), 0, 0);
1567 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001568 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001569 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001570 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001571 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001572 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001573 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001574 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001575 SourceLocation(),
1576 NestedNameSpecifierLoc(),
1577 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001578 DeclarationName());
1579 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001580 case DECL_CXX_RECORD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001581 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001582 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001583 case DECL_CXX_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001584 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001585 DeclarationNameInfo(), QualType(), 0,
Richard Smitha77a0a62011-08-15 21:04:07 +00001586 false, SC_None, false, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001587 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001588 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001589 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001590 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001591 case DECL_CXX_DESTRUCTOR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001592 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001593 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001594 case DECL_CXX_CONVERSION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001595 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001596 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001597 case DECL_ACCESS_SPEC:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001598 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001599 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001600 case DECL_FRIEND:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001601 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001602 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001603 case DECL_FRIEND_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001604 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001605 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001606 case DECL_CLASS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001607 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001608 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001609 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001610 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001611 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001612 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001613 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001614 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001615 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001616 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001617 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001618 Decl::EmptyShell());
1619 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001620 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001621 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001622 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001623 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001624 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001625 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001626 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001627 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001628 SourceLocation(), 0, 0, 0, QualType(),
1629 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001630 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001631 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001632 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001633 SourceLocation(), 0, 0, 0, QualType(),
1634 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001635 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001636 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001637 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregorf5500772011-01-05 15:48:55 +00001638 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001639 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001640 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001641 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3f1b5d02011-05-05 21:57:07 +00001642 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001643 case DECL_STATIC_ASSERT:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001644 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraea947882011-03-08 16:41:52 +00001645 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001646 break;
1647
Sebastian Redl539c5062010-08-18 23:57:32 +00001648 case DECL_OBJC_METHOD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001649 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001650 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001651 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001652 case DECL_OBJC_INTERFACE:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001653 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001654 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001655 case DECL_OBJC_IVAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001656 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001657 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001658 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001659 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001660 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidis1f4bee52011-10-17 19:48:06 +00001661 SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001662 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001663 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001664 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00001665 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001666 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001667 case DECL_OBJC_CLASS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001668 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001669 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001670 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001671 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001672 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001673 case DECL_OBJC_CATEGORY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001674 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001675 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001676 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001677 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1678 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001679 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001680 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +00001681 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1682 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001683 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001684 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001685 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001686 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001687 case DECL_OBJC_PROPERTY:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001688 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001689 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001690 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001691 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001692 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001693 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001694 ObjCPropertyImplDecl::Dynamic, 0,
1695 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001696 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001697 case DECL_FIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001698 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith938f40b2011-06-11 17:19:42 +00001699 QualType(), 0, 0, false, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001700 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001701 case DECL_INDIRECTFIELD:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001702 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet783dd6e2010-11-21 06:08:52 +00001703 0, 0);
1704 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001705 case DECL_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001706 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001707 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001708 break;
1709
Sebastian Redl539c5062010-08-18 23:57:32 +00001710 case DECL_IMPLICIT_PARAM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001711 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001712 break;
1713
Sebastian Redl539c5062010-08-18 23:57:32 +00001714 case DECL_PARM_VAR:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001715 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001716 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001717 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001718 case DECL_FILE_SCOPE_ASM:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001719 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara348823a2011-03-03 14:20:18 +00001720 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001721 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001722 case DECL_BLOCK:
Douglas Gregor4163aca2011-09-09 21:34:22 +00001723 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001724 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001725 case DECL_CXX_BASE_SPECIFIERS:
1726 Error("attempt to read a C++ base-specifier record as a declaration");
1727 return 0;
Chris Lattner487412d2009-04-27 05:27:42 +00001728 }
Chris Lattner487412d2009-04-27 05:27:42 +00001729
Sebastian Redlb3298c32010-08-18 23:56:48 +00001730 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001731 LoadedDecl(Index, D);
1732 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001733
1734 // If this declaration is also a declaration context, get the
1735 // offsets for its tables of lexical and visible declarations.
1736 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1737 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1738 if (Offsets.first || Offsets.second) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001739 if (Offsets.first != 0)
1740 DC->setHasExternalLexicalStorage(true);
1741 if (Offsets.second != 0)
1742 DC->setHasExternalVisibleStorage(true);
1743 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1744 Loc.F->DeclContextInfos[DC]))
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001745 return 0;
Sebastian Redlf830df42011-04-24 16:27:54 +00001746 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001747
Sebastian Redlf830df42011-04-24 16:27:54 +00001748 // Now add the pending visible updates for this decl context, if it has any.
1749 DeclContextVisibleUpdatesPending::iterator I =
1750 PendingVisibleUpdates.find(ID);
1751 if (I != PendingVisibleUpdates.end()) {
1752 // There are updates. This means the context has external visible
1753 // storage, even if the original stored version didn't.
1754 DC->setHasExternalVisibleStorage(true);
1755 DeclContextVisibleUpdates &U = I->second;
Sebastian Redlf830df42011-04-24 16:27:54 +00001756 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1757 UI != UE; ++UI) {
Douglas Gregor94619c82011-08-24 19:03:07 +00001758 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001759 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001760 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001761 }
1762 }
1763 assert(Idx == Record.size());
1764
Douglas Gregordab42432011-08-12 00:15:20 +00001765 // Load any relevant update records.
1766 loadDeclUpdateRecords(ID, D);
1767
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001768 if (ObjCChainedCategoriesInterfaces.count(ID))
1769 loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1770
Douglas Gregordab42432011-08-12 00:15:20 +00001771 // If we have deserialized a declaration that has a definition the
1772 // AST consumer might need to know about, queue it.
1773 // We don't pass it to the consumer immediately because we may be in recursive
1774 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001775 if (isConsumerInterestedIn(D))
Douglas Gregor87d81242011-09-10 00:22:34 +00001776 InterestingDecls.push_back(D);
Douglas Gregor87d81242011-09-10 00:22:34 +00001777
Douglas Gregordab42432011-08-12 00:15:20 +00001778 return D;
1779}
1780
1781void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001782 // The declaration may have been modified by files later in the chain.
1783 // If this is the case, read the record containing the updates from each file
1784 // and pass it to ASTDeclReader to make the modifications.
1785 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1786 if (UpdI != DeclUpdateOffsets.end()) {
1787 FileOffsetsTy &UpdateOffsets = UpdI->second;
1788 for (FileOffsetsTy::iterator
Douglas Gregordab42432011-08-12 00:15:20 +00001789 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregora6895d82011-07-22 16:00:58 +00001790 Module *F = I->first;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001791 uint64_t Offset = I->second;
1792 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1793 SavedStreamPosition SavedPosition(Cursor);
1794 Cursor.JumpToBit(Offset);
1795 RecordData Record;
1796 unsigned Code = Cursor.ReadCode();
1797 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1798 (void)RecCode;
1799 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregordab42432011-08-12 00:15:20 +00001800
1801 unsigned Idx = 0;
1802 ASTDeclReader Reader(*this, *F, Cursor, ID, Record, Idx);
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001803 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001804 }
1805 }
Chris Lattner487412d2009-04-27 05:27:42 +00001806}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001807
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001808namespace {
1809 /// \brief Given an ObjC interface, goes through the modules and links to the
1810 /// interface all the categories for it.
1811 class ObjCChainedCategoriesVisitor {
1812 ASTReader &Reader;
1813 serialization::GlobalDeclID InterfaceID;
1814 ObjCInterfaceDecl *Interface;
1815 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1816 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1817
1818 public:
1819 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1820 serialization::GlobalDeclID InterfaceID,
1821 ObjCInterfaceDecl *Interface)
1822 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1823 GlobHeadCat(0), GlobTailCat(0) { }
1824
1825 static bool visit(Module &M, void *UserData) {
1826 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1827 }
1828
1829 bool visit(Module &M) {
1830 if (Reader.isDeclIDFromModule(InterfaceID, M))
1831 return true; // We reached the module where the interface originated
1832 // from. Stop traversing the imported modules.
1833
1834 Module::ChainedObjCCategoriesMap::iterator
1835 I = M.ChainedObjCCategories.find(InterfaceID);
1836 if (I == M.ChainedObjCCategories.end())
1837 return false;
1838
1839 ObjCCategoryDecl *
1840 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1841 ObjCCategoryDecl *
1842 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1843
1844 addCategories(HeadCat, TailCat);
1845 return false;
1846 }
1847
1848 void addCategories(ObjCCategoryDecl *HeadCat,
1849 ObjCCategoryDecl *TailCat = 0) {
1850 if (!HeadCat) {
1851 assert(!TailCat);
1852 return;
1853 }
1854
1855 if (!TailCat) {
1856 TailCat = HeadCat;
1857 while (TailCat->getNextClassCategory())
1858 TailCat = TailCat->getNextClassCategory();
1859 }
1860
1861 if (!GlobHeadCat) {
1862 GlobHeadCat = HeadCat;
1863 GlobTailCat = TailCat;
1864 } else {
1865 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1866 GlobTailCat = TailCat;
1867 }
1868
1869 llvm::DenseSet<DeclarationName> Checked;
1870 for (ObjCCategoryDecl *Cat = HeadCat,
1871 *CatEnd = TailCat->getNextClassCategory();
1872 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1873 if (Checked.count(Cat->getDeclName()))
1874 continue;
1875 Checked.insert(Cat->getDeclName());
1876 checkForDuplicate(Cat);
1877 }
1878 }
1879
1880 /// \brief Warns for duplicate categories that come from different modules.
1881 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1882 DeclarationName Name = Cat->getDeclName();
1883 // Find the top category with the same name. We do not want to warn for
1884 // duplicates along the established chain because there were already
1885 // warnings for them when the module was created. We only want to warn for
1886 // duplicates between non-dependent modules:
1887 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001888 // MT //
1889 // / \ //
1890 // ML MR //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001891 //
1892 // We want to warn for duplicates between ML and MR,not between ML and MT.
1893 //
1894 // FIXME: We should not warn for duplicates in diamond:
1895 //
Argyrios Kyrtzidis019f3c22011-09-01 03:07:11 +00001896 // MT //
1897 // / \ //
1898 // ML MR //
1899 // \ / //
1900 // MB //
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00001901 //
1902 // If there are duplicates in ML/MR, there will be warning when creating
1903 // MB *and* when importing MB. We should not warn when importing.
1904 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1905 Next = Next->getNextClassCategory()) {
1906 if (Next->getDeclName() == Name)
1907 Cat = Next;
1908 }
1909
1910 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1911 if (!PrevCat)
1912 PrevCat = Cat;
1913
1914 if (PrevCat != Cat) {
1915 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1916 << Interface->getDeclName() << Name;
1917 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1918 }
1919 }
1920
1921 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1922 };
1923}
1924
1925void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1926 ObjCInterfaceDecl *D) {
1927 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1928 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1929 // Also add the categories that the interface already links to.
1930 Visitor.addCategories(D->getCategoryList());
1931 D->setCategoryList(Visitor.getHeadCategory());
1932}
Douglas Gregordab42432011-08-12 00:15:20 +00001933
Douglas Gregora6895d82011-07-22 16:00:58 +00001934void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001935 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001936 unsigned Idx = 0;
1937 while (Idx < Record.size()) {
1938 switch ((DeclUpdateKind)Record[Idx++]) {
1939 case UPD_CXX_SET_DEFINITIONDATA: {
1940 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregorf7180622011-08-03 15:48:04 +00001941 CXXRecordDecl *DefinitionDecl
1942 = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001943 assert(!RD->DefinitionData && "DefinitionData is already set!");
1944 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1945 break;
1946 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001947
1948 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregorf7180622011-08-03 15:48:04 +00001949 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001950 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00001951
1952 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1953 // It will be added to the template's specializations set when loaded.
Douglas Gregorf7180622011-08-03 15:48:04 +00001954 (void)Reader.ReadDecl(Module, Record, Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001955 break;
1956
1957 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregorf7180622011-08-03 15:48:04 +00001958 NamespaceDecl *Anon
1959 = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
Sebastian Redl010288f2011-04-24 16:28:21 +00001960 // Guard against these being loaded out of original order. Don't use
1961 // getNextNamespace(), since it tries to access the context and can't in
1962 // the middle of deserialization.
1963 if (!Anon->NextNamespace) {
1964 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1965 TU->setAnonymousNamespace(Anon);
1966 else
1967 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1968 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001969 break;
1970 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001971
1972 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1973 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1974 Reader.ReadSourceLocation(Module, Record, Idx));
1975 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001976 }
1977 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001978}