blob: a15dc424e793096710c0eb97a702566746a1adfa [file] [log] [blame]
Sebastian Redl904c9c82010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner698f9252009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redlc43b54c2010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner698f9252009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redl6ab7cd82010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000017#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner698f9252009-04-27 05:27:42 +000018#include "clang/AST/ASTConsumer.h"
19#include "clang/AST/ASTContext.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/DeclGroup.h"
Chris Lattner6ad9ac02010-05-07 21:43:38 +000022#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000024#include "clang/AST/Expr.h"
25using namespace clang;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000026using namespace clang::serialization;
Chris Lattner698f9252009-04-27 05:27:42 +000027
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000032namespace clang {
Sebastian Redld527cc02010-08-18 23:56:48 +000033 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redlc43b54c2010-08-18 23:56:43 +000034 ASTReader &Reader;
Douglas Gregor72a9ae12011-07-22 16:00:58 +000035 Module &F;
Sebastian Redl577d4792010-07-22 22:43:28 +000036 llvm::BitstreamCursor &Cursor;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000037 const DeclID ThisDeclID;
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000038 typedef ASTReader::RecordData RecordData;
39 const RecordData &Record;
Chris Lattner698f9252009-04-27 05:27:42 +000040 unsigned &Idx;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000041 TypeID TypeIDForTypeDecl;
Douglas Gregor67da6f62011-03-05 01:35:54 +000042
43 DeclID DeclContextIDForTemplateParmDecl;
44 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner698f9252009-04-27 05:27:42 +000045
Sebastian Redl577d4792010-07-22 22:43:28 +000046 uint64_t GetCurrentCursorOffset();
Douglas Gregor409448c2011-07-21 22:35:25 +000047
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000048 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000049 return Reader.ReadSourceLocation(F, R, I);
50 }
Douglas Gregor409448c2011-07-21 22:35:25 +000051
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000052 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000053 return Reader.ReadSourceRange(F, R, I);
54 }
Douglas Gregor409448c2011-07-21 22:35:25 +000055
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000056 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redlc3632732010-10-05 15:59:54 +000057 return Reader.GetTypeSourceInfo(F, R, I);
58 }
Douglas Gregor409448c2011-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 Kyrtzidis40451072010-10-15 18:21:24 +000073 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000074 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000075 Reader.ReadQualifierInfo(F, Info, R, I);
76 }
Douglas Gregor409448c2011-07-21 22:35:25 +000077
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000078 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000079 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000080 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
81 }
Douglas Gregor409448c2011-07-21 22:35:25 +000082
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000083 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000084 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +000085 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
86 }
Sebastian Redl577d4792010-07-22 22:43:28 +000087
Argyrios Kyrtzidis89eaf3a2010-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 Lattner698f9252009-04-27 05:27:42 +000094 public:
Douglas Gregor72a9ae12011-07-22 16:00:58 +000095 ASTDeclReader(ASTReader &Reader, Module &F,
Sebastian Redlc3632732010-10-05 15:59:54 +000096 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +000097 const RecordData &Record, unsigned &Idx)
Sebastian Redlc3632732010-10-05 15:59:54 +000098 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
99 Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner698f9252009-04-27 05:27:42 +0000100
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +0000101 static void attachPreviousDecl(Decl *D, Decl *previous);
102
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000103 void Visit(Decl *D);
104
Douglas Gregor72a9ae12011-07-22 16:00:58 +0000105 void UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +0000106 const RecordData &Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000107
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +0000108 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
109 ObjCCategoryDecl *Next) {
110 Cat->NextClassCategory = Next;
111 }
112
Chris Lattner698f9252009-04-27 05:27:42 +0000113 void VisitDecl(Decl *D);
114 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
115 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000116 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregor0cef4832010-02-21 18:22:14 +0000117 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000118 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
119 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000120 void VisitTypeDecl(TypeDecl *TD);
121 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smith162e1c12011-04-15 14:24:37 +0000122 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000123 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000124 void VisitTagDecl(TagDecl *TD);
125 void VisitEnumDecl(EnumDecl *ED);
126 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000127 void VisitCXXRecordDecl(CXXRecordDecl *D);
128 void VisitClassTemplateSpecializationDecl(
129 ClassTemplateSpecializationDecl *D);
130 void VisitClassTemplatePartialSpecializationDecl(
131 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redl14c36332011-08-31 13:59:56 +0000132 void VisitClassScopeFunctionSpecializationDecl(
133 ClassScopeFunctionSpecializationDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000134 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000135 void VisitValueDecl(ValueDecl *VD);
136 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000137 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000138 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +0000139 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-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 Lattner698f9252009-04-27 05:27:42 +0000144 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet87c2e122010-11-21 06:08:52 +0000145 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000146 void VisitVarDecl(VarDecl *VD);
147 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
148 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000149 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
150 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000151 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000152 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000153 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000154 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000155 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000156 void VisitUsingDecl(UsingDecl *D);
157 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000158 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000159 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnara6206d532010-06-05 05:09:32 +0000160 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000161 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000162 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
163 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +0000164 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000165
Chris Lattner698f9252009-04-27 05:27:42 +0000166 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000167 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000168
Sean Hunt9a555912010-05-30 07:21:58 +0000169 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-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 Redld527cc02010-08-18 23:56:48 +0000188uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Douglas Gregor8f1231b2011-07-22 06:10:01 +0000189 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
Sebastian Redl577d4792010-07-22 22:43:28 +0000190}
191
Sebastian Redld527cc02010-08-18 23:56:48 +0000192void ASTDeclReader::Visit(Decl *D) {
193 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000194
Jonathan D. Turner953c5642011-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 Kyrtzidis91468322010-07-02 15:58:43 +0000207 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000208 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor1ab55e92010-12-10 17:03:06 +0000209 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis91468322010-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 Redl577d4792010-07-22 22:43:28 +0000213 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor67da6f62011-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 Kyrtzidis91468322010-07-02 15:58:43 +0000223 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000224}
225
Sebastian Redld527cc02010-08-18 23:56:48 +0000226void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor67da6f62011-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 Gregor409448c2011-07-21 22:35:25 +0000232 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
233 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000234 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor67da6f62011-03-05 01:35:54 +0000235 } else {
Douglas Gregor409448c2011-07-21 22:35:25 +0000236 D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
237 D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
Douglas Gregor67da6f62011-03-05 01:35:54 +0000238 }
Sebastian Redlc3632732010-10-05 15:59:54 +0000239 D->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000240 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000241 if (Record[Idx++]) { // hasAttrs
Sean Huntcf807c42010-08-18 23:23:40 +0000242 AttrVec Attrs;
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +0000243 Reader.ReadAttributes(F, Attrs, Record, Idx);
Sean Huntcf807c42010-08-18 23:23:40 +0000244 D->setAttrs(Attrs);
245 }
Chris Lattner698f9252009-04-27 05:27:42 +0000246 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000247 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis6b6b42a2011-04-19 19:51:10 +0000248 D->setReferenced(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000249 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor08e0bc12011-09-10 00:09:20 +0000250 D->FromASTFile = true;
Douglas Gregor8d267c52011-09-09 02:06:17 +0000251 D->ModulePrivate = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000252}
253
Sebastian Redld527cc02010-08-18 23:56:48 +0000254void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +0000255 llvm_unreachable("Translation units are not serialized");
Chris Lattner698f9252009-04-27 05:27:42 +0000256}
257
Sebastian Redld527cc02010-08-18 23:56:48 +0000258void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner698f9252009-04-27 05:27:42 +0000259 VisitDecl(ND);
Douglas Gregor393f2492011-07-22 00:38:23 +0000260 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000261}
262
Sebastian Redld527cc02010-08-18 23:56:48 +0000263void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000264 VisitNamedDecl(TD);
Abramo Bagnara344577e2011-03-06 15:48:19 +0000265 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000266 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor393f2492011-07-22 00:38:23 +0000267 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000268}
269
Sebastian Redld527cc02010-08-18 23:56:48 +0000270void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000271 VisitTypeDecl(TD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000272 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000273}
274
Richard Smith162e1c12011-04-15 14:24:37 +0000275void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
276 VisitTypeDecl(TD);
277 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
278}
279
Sebastian Redld527cc02010-08-18 23:56:48 +0000280void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000281 VisitTypeDecl(TD);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000282 VisitRedeclarable(TD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000283 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000284 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
John McCall5e1cdac2011-10-07 06:10:15 +0000285 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000286 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis717a20b2011-09-30 22:11:31 +0000287 TD->setFreeStanding(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000288 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000289 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor35942772011-09-09 21:34:22 +0000290 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000291 ReadQualifierInfo(*Info, Record, Idx);
Richard Smith162e1c12011-04-15 14:24:37 +0000292 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000293 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000294 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000295}
296
Sebastian Redld527cc02010-08-18 23:56:48 +0000297void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000298 VisitTagDecl(ED);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000299 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
300 ED->setIntegerTypeSourceInfo(TI);
301 else
Douglas Gregor393f2492011-07-22 00:38:23 +0000302 ED->setIntegerType(Reader.readType(F, Record, Idx));
303 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall1b5a6182010-05-06 08:49:23 +0000304 ED->setNumPositiveBits(Record[Idx++]);
305 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000306 ED->IsScoped = Record[Idx++];
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000307 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000308 ED->IsFixed = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000309 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000310}
311
Sebastian Redld527cc02010-08-18 23:56:48 +0000312void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000313 VisitTagDecl(RD);
314 RD->setHasFlexibleArrayMember(Record[Idx++]);
315 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000316 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000317}
318
Sebastian Redld527cc02010-08-18 23:56:48 +0000319void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000320 VisitNamedDecl(VD);
Douglas Gregor393f2492011-07-22 00:38:23 +0000321 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000322}
323
Sebastian Redld527cc02010-08-18 23:56:48 +0000324void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000325 VisitValueDecl(ECD);
326 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000327 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000328 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
329}
330
Sebastian Redld527cc02010-08-18 23:56:48 +0000331void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000332 VisitValueDecl(DD);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000333 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000334 if (Record[Idx++]) { // hasExtInfo
335 DeclaratorDecl::ExtInfo *Info
Douglas Gregor35942772011-09-09 21:34:22 +0000336 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000337 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000338 DD->DeclInfo = Info;
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000339 }
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000340}
341
Sebastian Redld527cc02010-08-18 23:56:48 +0000342void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000343 VisitDeclaratorDecl(FD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000344 VisitRedeclarable(FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000345
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000346 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000347 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000348 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000349 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000350 case FunctionDecl::TK_NonTemplate:
351 break;
352 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000353 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
354 Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000355 break;
356 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000357 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000358 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000359 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000360 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000361 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
362 break;
363 }
364 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000365 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
366 Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000367 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
368
369 // Template arguments.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000370 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000371 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000372
373 // Template args as written.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000374 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000375 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000376 bool HasTemplateArgumentsAsWritten = Record[Idx++];
377 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000378 unsigned NumTemplateArgLocs = Record[Idx++];
379 TemplArgLocs.reserve(NumTemplateArgLocs);
380 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000381 TemplArgLocs.push_back(
Sebastian Redlc3632732010-10-05 15:59:54 +0000382 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000383
Sebastian Redlc3632732010-10-05 15:59:54 +0000384 LAngleLoc = ReadSourceLocation(Record, Idx);
385 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000386 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000387
Sebastian Redlc3632732010-10-05 15:59:54 +0000388 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000389
Douglas Gregor35942772011-09-09 21:34:22 +0000390 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000391 TemplateArgumentList *TemplArgList
Douglas Gregor910f8002010-11-07 23:05:16 +0000392 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000393 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000394 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000395 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000396 FunctionTemplateSpecializationInfo *FTInfo
397 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
398 TemplArgList,
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000399 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
400 POI);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000401 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000402
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000403 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidis99a8ca02010-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 Gregor409448c2011-07-21 22:35:25 +0000407 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa626a3d2010-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 Kyrtzidis6b541512010-09-08 19:31:22 +0000413 llvm::FoldingSetNodeID ID;
414 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
415 TemplArgs.size(), C);
416 void *InsertPos = 0;
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000417 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000418 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000419 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000420 }
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000421 break;
Argyrios Kyrtzidisf511ba62010-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 Gregor409448c2011-07-21 22:35:25 +0000428 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000429
430 // Templates args.
431 TemplateArgumentListInfo TemplArgs;
432 unsigned NumArgs = Record[Idx++];
433 while (NumArgs--)
Sebastian Redlc3632732010-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 Kyrtzidisf511ba62010-06-22 09:55:07 +0000437
Douglas Gregor35942772011-09-09 21:34:22 +0000438 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000439 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000440 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000441 }
442 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000443
Sebastian Redld527cc02010-08-18 23:56:48 +0000444 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000445 // after everything else is read.
446
Douglas Gregor381d34e2010-12-06 18:36:25 +0000447 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000448 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregor8f150942010-12-09 16:59:22 +0000449 FD->IsInline = Record[Idx++];
450 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-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++];
Sean Hunt2be7e902011-05-12 22:46:29 +0000457 FD->IsDefaulted = Record[Idx++];
458 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000459 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smithaf1fc7a2011-08-15 21:04:07 +0000460 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000461 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000462
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000463 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000464 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000465 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000466 Params.reserve(NumParams);
467 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000468 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000469 FD->setParams(Reader.getContext(), Params);
Chris Lattner698f9252009-04-27 05:27:42 +0000470}
471
Sebastian Redld527cc02010-08-18 23:56:48 +0000472void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-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 Redlc3632732010-10-05 15:59:54 +0000477 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor409448c2011-07-21 22:35:25 +0000478 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
479 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000480 }
481 MD->setInstanceMethod(Record[Idx++]);
482 MD->setVariadic(Record[Idx++]);
483 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000484 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidis72b26252011-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 Lattner698f9252009-04-27 05:27:42 +0000492 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
493 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000494 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000495 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000496 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
497 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000498 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000499 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000500 Params.reserve(NumParams);
501 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000502 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidis491306a2011-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 Lattner698f9252009-04-27 05:27:42 +0000512}
513
Sebastian Redld527cc02010-08-18 23:56:48 +0000514void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000515 VisitNamedDecl(CD);
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000516 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
517 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000518}
519
Sebastian Redld527cc02010-08-18 23:56:48 +0000520void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner698f9252009-04-27 05:27:42 +0000521 VisitObjCContainerDecl(ID);
Douglas Gregor393f2492011-07-22 00:38:23 +0000522 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor409448c2011-07-21 22:35:25 +0000523 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000524
525 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner698f9252009-04-27 05:27:42 +0000526 unsigned NumProtocols = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000527 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner698f9252009-04-27 05:27:42 +0000528 Protocols.reserve(NumProtocols);
529 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000530 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000531 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000532 ProtoLocs.reserve(NumProtocols);
533 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000534 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000535 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000536 Reader.getContext());
Ted Kremenek53b94412010-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 Gregor409448c2011-07-21 22:35:25 +0000543 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000544 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor35942772011-09-09 21:34:22 +0000545 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000546
547 // Read the ivars.
Chris Lattner698f9252009-04-27 05:27:42 +0000548 unsigned NumIvars = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000549 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner698f9252009-04-27 05:27:42 +0000550 IVars.reserve(NumIvars);
551 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000552 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
553 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
554
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000555 // We will rebuild this list lazily.
556 ID->setIvarList(0);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000557 ID->InitiallyForwardDecl = Record[Idx++];
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000558 ID->setForwardDecl(Record[Idx++]);
559 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000560 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
561 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000562}
563
Sebastian Redld527cc02010-08-18 23:56:48 +0000564void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000565 VisitFieldDecl(IVD);
566 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000567 // This field will be built lazily.
568 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000569 bool synth = Record[Idx++];
570 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000571}
572
Sebastian Redld527cc02010-08-18 23:56:48 +0000573void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000574 VisitObjCContainerDecl(PD);
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +0000575 PD->InitiallyForwardDecl = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000576 PD->setForwardDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000577 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000578 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000579 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000580 ProtoRefs.reserve(NumProtoRefs);
581 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000582 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000583 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000584 ProtoLocs.reserve(NumProtoRefs);
585 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000586 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000587 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000588 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000589}
590
Sebastian Redld527cc02010-08-18 23:56:48 +0000591void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000592 VisitFieldDecl(FD);
593}
594
Sebastian Redld527cc02010-08-18 23:56:48 +0000595void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000596 VisitDecl(CD);
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000597 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
598 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000599 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner698f9252009-04-27 05:27:42 +0000600}
601
Sebastian Redld527cc02010-08-18 23:56:48 +0000602void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000603 VisitDecl(FPD);
604 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000605 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000606 ProtoRefs.reserve(NumProtoRefs);
607 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000608 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000609 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000610 ProtoLocs.reserve(NumProtoRefs);
611 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000612 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000613 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000614 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000615}
616
Sebastian Redld527cc02010-08-18 23:56:48 +0000617void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000618 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000619 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000620 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000621 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000622 ProtoRefs.reserve(NumProtoRefs);
623 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000624 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000625 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000626 ProtoLocs.reserve(NumProtoRefs);
627 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000628 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000629 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000630 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000631 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000632 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000633 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000634}
635
Sebastian Redld527cc02010-08-18 23:56:48 +0000636void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000637 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000638 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000639}
640
Sebastian Redld527cc02010-08-18 23:56:48 +0000641void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000642 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000643 D->setAtLoc(ReadSourceLocation(Record, Idx));
644 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000645 // FIXME: stable encoding
646 D->setPropertyAttributes(
647 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000648 D->setPropertyAttributesAsWritten(
649 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000650 // FIXME: stable encoding
651 D->setPropertyImplementation(
652 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000653 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
654 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-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 Lattner698f9252009-04-27 05:27:42 +0000658}
659
Sebastian Redld527cc02010-08-18 23:56:48 +0000660void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000661 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000662 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000663}
664
Sebastian Redld527cc02010-08-18 23:56:48 +0000665void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000666 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000667 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000668}
669
Sebastian Redld527cc02010-08-18 23:56:48 +0000670void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000671 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000672 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000673 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000674 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000675 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000676}
677
678
Sebastian Redld527cc02010-08-18 23:56:48 +0000679void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000680 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000681 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000682 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
683 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000684 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000685 D->setGetterCXXConstructor(Reader.ReadExpr(F));
686 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000687}
688
Sebastian Redld527cc02010-08-18 23:56:48 +0000689void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000690 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000691 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000692 int BitWidthOrInitializer = Record[Idx++];
693 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000694 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000695 else if (BitWidthOrInitializer == 2)
696 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000697 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000698 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000699 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000700 }
Chris Lattner698f9252009-04-27 05:27:42 +0000701}
702
Francois Pichet87c2e122010-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 Gregor35942772011-09-09 21:34:22 +0000708 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000709
710 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000711 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000712}
713
Sebastian Redld527cc02010-08-18 23:56:48 +0000714void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000715 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000716 VisitRedeclarable(VD);
John McCallf1e4fbf2011-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 McCall7acddac2011-06-17 06:42:21 +0000724 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000725 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000726 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000727
728 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000729 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000730 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000731 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000732 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000733 }
Chris Lattner698f9252009-04-27 05:27:42 +0000734}
735
Sebastian Redld527cc02010-08-18 23:56:48 +0000736void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000737 VisitVarDecl(PD);
738}
739
Sebastian Redld527cc02010-08-18 23:56:48 +0000740void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000741 VisitVarDecl(PD);
John McCall70798862011-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 McCallf1e4fbf2011-05-01 02:13:58 +0000753 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
754 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000755 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000756 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000757}
758
Sebastian Redld527cc02010-08-18 23:56:48 +0000759void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000760 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000761 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000762 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000763}
764
Sebastian Redld527cc02010-08-18 23:56:48 +0000765void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000766 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000767 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
768 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000769 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000770 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000771 Params.reserve(NumParams);
772 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000773 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000774 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000775
776 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000777 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000778 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000779 captures.reserve(numCaptures);
780 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000781 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-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 Gregor35942772011-09-09 21:34:22 +0000789 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000790 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000791}
792
Sebastian Redld527cc02010-08-18 23:56:48 +0000793void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000794 VisitDecl(D);
795 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000796 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000797 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000798}
799
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000800void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
801 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +0000802 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000803}
804
805
Sebastian Redld527cc02010-08-18 23:56:48 +0000806void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000807 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +0000808 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +0000809 D->LocStart = ReadSourceLocation(Record, Idx);
810 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +0000811 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000812
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000813 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000814 // FIXME: Modules will likely have trouble with pointing directly at
815 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000816 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +0000817 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000818}
819
Sebastian Redld527cc02010-08-18 23:56:48 +0000820void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000821 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000822 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000823 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +0000824 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000825 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000826}
827
Sebastian Redld527cc02010-08-18 23:56:48 +0000828void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000829 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000830 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000831 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000832 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000833 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000834 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +0000835 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000836 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000837}
838
Sebastian Redld527cc02010-08-18 23:56:48 +0000839void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000840 VisitNamedDecl(D);
Douglas Gregor409448c2011-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 Kyrtzidisc91e9f42010-07-04 21:44:35 +0000844 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +0000845 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000846}
847
Sebastian Redld527cc02010-08-18 23:56:48 +0000848void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000849 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000850 D->UsingLoc = ReadSourceLocation(Record, Idx);
851 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +0000852 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000853 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
854 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000855}
856
Sebastian Redld527cc02010-08-18 23:56:48 +0000857void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000858 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000859 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000860 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000861 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000862}
863
Sebastian Redld527cc02010-08-18 23:56:48 +0000864void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000865 UnresolvedUsingTypenameDecl *D) {
866 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000867 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +0000868 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000869}
870
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000871void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000872 struct CXXRecordDecl::DefinitionData &Data,
873 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000874 Data.UserDeclaredConstructor = Record[Idx++];
875 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000876 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000877 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000878 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-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 Carruthec997dc2011-04-30 10:07:30 +0000885 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-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 Gregor2bb11012011-05-13 01:05:07 +0000890 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +0000891 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +0000892 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000893 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000894 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000895 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000896 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000897 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +0000898 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000899 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +0000900 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000901 Data.DeclaredDefaultConstructor = Record[Idx++];
902 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000903 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000904 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000905 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000906 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +0000907 Data.FailedImplicitMoveConstructor = Record[Idx++];
908 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +0000909
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000910 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000911 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000912 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000913 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000914 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000915 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +0000916
Douglas Gregor409448c2011-07-21 22:35:25 +0000917 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
918 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000919 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +0000920 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000921}
922
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000923void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
924 CXXRecordDecl *DefinitionDecl,
925 const RecordData &Record,
926 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +0000927 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000928
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000929 if (D == DefinitionDecl) {
930 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000931 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidis134db1f2010-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 Kyrtzidis37ffed32010-07-02 11:55:32 +0000954 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000955}
956
957void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
958 VisitRecordDecl(D);
959
Douglas Gregor409448c2011-07-21 22:35:25 +0000960 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000961 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
962
Douglas Gregor35942772011-09-09 21:34:22 +0000963 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000964
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000965 enum CXXRecKind {
966 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
967 };
968 switch ((CXXRecKind)Record[Idx++]) {
969 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000970 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000971 case CXXRecNotTemplate:
972 break;
973 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000974 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000975 break;
976 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000977 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000978 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000979 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +0000980 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
981 MSI->setPointOfInstantiation(POI);
982 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000983 break;
984 }
985 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000986
987 // Load the key function to avoid deserializing every method so we can
988 // compute it.
John McCall5e1cdac2011-10-07 06:10:15 +0000989 if (D->IsCompleteDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000990 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000991 C.KeyFunctions[D] = Key;
992 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000993}
994
Sebastian Redld527cc02010-08-18 23:56:48 +0000995void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000996 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000997 unsigned NumOverridenMethods = Record[Idx++];
998 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000999 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1000 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +00001001 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001002 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001003 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001004}
1005
Sebastian Redld527cc02010-08-18 23:56:48 +00001006void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001007 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001008
1009 D->IsExplicitSpecified = Record[Idx++];
1010 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001011 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1012 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001013}
1014
Sebastian Redld527cc02010-08-18 23:56:48 +00001015void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001016 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001017
1018 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001019 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001020}
1021
Sebastian Redld527cc02010-08-18 23:56:48 +00001022void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001023 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001024 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001025}
1026
Sebastian Redld527cc02010-08-18 23:56:48 +00001027void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001028 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001029 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001030}
1031
Sebastian Redld527cc02010-08-18 23:56:48 +00001032void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001033 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001034 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001035 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001036 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001037 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001038 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001039 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001040 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001041}
1042
Sebastian Redld527cc02010-08-18 23:56:48 +00001043void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-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 Redlc3632732010-10-05 15:59:54 +00001049 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001050 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001051 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001052 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001053 D->Friend = GetTypeSourceInfo(Record, Idx);
1054 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001055}
1056
Sebastian Redld527cc02010-08-18 23:56:48 +00001057void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001058 VisitNamedDecl(D);
1059
Douglas Gregor409448c2011-07-21 22:35:25 +00001060 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001061 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001062 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001063 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001064}
1065
Sebastian Redld527cc02010-08-18 23:56:48 +00001066void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001067 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1068 // can be used while this is still initializing.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001069
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001070 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor409448c2011-07-21 22:35:25 +00001071 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1072 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis0895d152011-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 Gregor35942772011-09-09 21:34:22 +00001087 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001088 if (RedeclarableTemplateDecl *RTD
Douglas Gregor409448c2011-07-21 22:35:25 +00001089 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-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 Collingbourne8a798a72010-07-29 16:12:01 +00001096
Douglas Gregor409448c2011-07-21 22:35:25 +00001097 RedeclarableTemplateDecl *LatestDecl
1098 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001099
1100 // This decl is a first one and the latest declaration that it points to is
Sebastian Redl3c7f4132010-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 Kyrtzidisa8650052010-08-03 17:30:10 +00001103 // the FirstLatestDeclIDs map which tracks this kind of decls.
1104 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001105 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001106 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1107 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregor1b59e9c2011-08-25 15:28:26 +00001108 if (Decl *NewLatest = Reader.GetDecl(I->second))
1109 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001110 }
1111
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001112 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1113 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001114 }
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001115
1116 VisitTemplateDecl(D);
1117 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001118}
1119
Sebastian Redld527cc02010-08-18 23:56:48 +00001120void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001121 VisitRedeclarableTemplateDecl(D);
1122
1123 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001124 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1125 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001126 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001127 SpecIDs.push_back(0);
1128
1129 // Specializations.
1130 unsigned Size = Record[Idx++];
1131 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001132 for (unsigned I = 0; I != Size; ++I)
1133 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001134
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001135 // Partial specializations.
1136 Size = Record[Idx++];
1137 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001138 for (unsigned I = 0; I != Size; ++I)
1139 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001140
Douglas Gregorc8e5cf82010-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 Gregor35942772011-09-09 21:34:22 +00001146 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001147 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1148 SpecIDs.size() * sizeof(DeclID));
1149 }
1150
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001151 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001152 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001153}
1154
Sebastian Redld527cc02010-08-18 23:56:48 +00001155void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001156 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001157 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001158
Douglas Gregor35942772011-09-09 21:34:22 +00001159 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001160 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001161 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001162 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001163 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001164 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001165 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001166 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001167 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1168 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-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 Kyrtzidisdd41c142010-06-23 13:48:30 +00001176 }
1177 }
1178
1179 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001180 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001181 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1182 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1183 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001184 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1185 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001186 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001187 }
1188
Chris Lattner5f9e2722011-07-23 10:55:15 +00001189 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001190 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001191 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1192 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001193 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001194 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001195
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001196 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001197 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001198 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001199 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1200 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001201 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001202 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001203 }
1204 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001205}
1206
Sebastian Redld527cc02010-08-18 23:56:48 +00001207void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001208 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001209 VisitClassTemplateSpecializationDecl(D);
1210
Douglas Gregor35942772011-09-09 21:34:22 +00001211 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001212 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001213
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001214 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-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 Redlc3632732010-10-05 15:59:54 +00001219 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001220 }
1221
1222 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001223
1224 // These are read/set from/to the first declaration.
1225 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001226 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001227 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001228 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001229 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001230}
1231
Sebastian Redl14c36332011-08-31 13:59:56 +00001232void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1233 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001234 VisitDecl(D);
1235 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1236}
1237
Sebastian Redld527cc02010-08-18 23:56:48 +00001238void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001239 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001240
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001241 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001242 // This FunctionTemplateDecl owns a CommonPtr; read it.
1243
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001244 // Read the function specialization declarations.
1245 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001246 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001247 unsigned NumSpecs = Record[Idx++];
1248 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001249 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001250 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001251}
1252
Sebastian Redld527cc02010-08-18 23:56:48 +00001253void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001254 VisitTypeDecl(D);
1255
1256 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001257
1258 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001259 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001260 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001261}
1262
Sebastian Redld527cc02010-08-18 23:56:48 +00001263void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001264 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001265 // TemplateParmPosition.
1266 D->setDepth(Record[Idx++]);
1267 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-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 Gregor393f2492011-07-22 00:38:23 +00001271 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-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 Lattner6ad9ac02010-05-07 21:43:38 +00001283}
1284
Sebastian Redld527cc02010-08-18 23:56:48 +00001285void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-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 Redlc3632732010-10-05 15:59:54 +00001291 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001292 bool IsInherited = Record[Idx++];
1293 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001294 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001295}
1296
Richard Smith3e4c6c42011-05-05 21:57:07 +00001297void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1298 VisitRedeclarableTemplateDecl(D);
1299}
1300
Sebastian Redld527cc02010-08-18 23:56:48 +00001301void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001302 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001303 D->AssertExpr = Reader.ReadExpr(F);
1304 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001305 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001306}
1307
Mike Stump1eb44332009-09-09 15:08:12 +00001308std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001309ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-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 Kyrtzidisa8650052010-08-03 17:30:10 +00001315template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001316void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001317 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1318 RedeclKind Kind = (RedeclKind)Record[Idx++];
1319 switch (Kind) {
1320 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001321 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1322 " messed up reading");
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001323 case NoRedeclaration:
1324 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001325 case PointsToPrevious: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001326 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1327 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis0895d152011-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.
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001332 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001333 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1334 if (PreviousDeclID != FirstDeclID)
1335 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1336 PreviousDeclID));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001337 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001338 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001339 case PointsToLatest:
1340 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
Douglas Gregor409448c2011-07-21 22:35:25 +00001341 ReadDeclAs<T>(Record, Idx));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001342 break;
1343 }
1344
1345 assert(!(Kind == PointsToPrevious &&
1346 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1347 Reader.FirstLatestDeclIDs.end()) &&
1348 "This decl is not first, it should not be in the map");
1349 if (Kind == PointsToPrevious)
1350 return;
1351
1352 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001353 // the same AST file. However, if this actually needs to point to a
1354 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001355 // FirstLatestDeclIDs map which tracks this kind of decls.
1356 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1357 "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001358 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001359 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1360 if (I != Reader.FirstLatestDeclIDs.end()) {
1361 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001362 D->RedeclLink
1363 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1364 }
1365}
1366
Chris Lattner698f9252009-04-27 05:27:42 +00001367//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001368// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001369//===----------------------------------------------------------------------===//
1370
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001371/// \brief Reads attributes from the current stream position.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001372void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001373 const RecordData &Record, unsigned &Idx) {
1374 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001375 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001376 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001377 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001378
Sean Huntcf807c42010-08-18 23:23:40 +00001379#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001380
1381 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001382 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001383 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001384}
1385
1386//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001387// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001388//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001389
1390/// \brief Note that we have loaded the declaration with the given
1391/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001392///
Chris Lattner698f9252009-04-27 05:27:42 +00001393/// This routine notes that this declaration has already been loaded,
1394/// so that future GetDecl calls will return this declaration rather
1395/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001396inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001397 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1398 DeclsLoaded[Index] = D;
1399}
1400
1401
1402/// \brief Determine whether the consumer will be interested in seeing
1403/// this declaration (via HandleTopLevelDecl).
1404///
1405/// This routine should return true for anything that might affect
1406/// code generation, e.g., inline function definitions, Objective-C
1407/// declarations with metadata, etc.
1408static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001409 // An ObjCMethodDecl is never considered as "interesting" because its
1410 // implementation container always is.
1411
Douglas Gregor94da1582011-09-10 00:22:34 +00001412 if (isa<FileScopeAsmDecl>(D) ||
1413 isa<ObjCProtocolDecl>(D) ||
1414 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001415 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001416 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001417 return Var->isFileVarDecl() &&
1418 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001419 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001420 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001421
1422 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001423}
1424
Douglas Gregor96e973f2011-07-20 00:27:43 +00001425/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001426ASTReader::RecordLocation
Douglas Gregor496c7092011-08-03 15:48:04 +00001427ASTReader::DeclCursorForID(DeclID ID) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001428 // See if there's an override.
1429 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1430 if (It != ReplacedDecls.end())
Sebastian Redlc3632732010-10-05 15:59:54 +00001431 return RecordLocation(It->second.first, It->second.second);
Sebastian Redl0b17c612010-08-13 00:28:03 +00001432
Douglas Gregor96e973f2011-07-20 00:27:43 +00001433 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1434 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor9827a802011-07-29 00:56:45 +00001435 Module *M = I->second;
Douglas Gregorb18b1fd2011-08-03 23:28:44 +00001436 return RecordLocation(M,
1437 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001438}
1439
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001440ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001441 ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001442 = GlobalBitOffsetsMap.find(GlobalOffset);
1443
1444 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1445 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1446}
1447
Douglas Gregore92b8a12011-08-04 00:01:48 +00001448uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1449 return LocalOffset + M.GlobalBitOffset;
1450}
1451
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001452void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1453 assert(D && previous);
1454 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1455 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1456 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1457 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1458 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1459 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1460 } else {
1461 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1462 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1463 }
1464}
1465
1466void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1467 Decl *previous = GetDecl(ID);
1468 ASTDeclReader::attachPreviousDecl(D, previous);
1469}
1470
Sebastian Redld527cc02010-08-18 23:56:48 +00001471/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001472Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001473 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Douglas Gregor496c7092011-08-03 15:48:04 +00001474 RecordLocation Loc = DeclCursorForID(ID);
Sebastian Redlc3632732010-10-05 15:59:54 +00001475 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001476 // Keep track of where we are in the stream, then jump back there
1477 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001478 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001479
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001480 ReadingKindTracker ReadingKind(Read_Decl, *this);
1481
Douglas Gregord89275b2009-07-06 18:54:52 +00001482 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001483 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001484
Sebastian Redlc3632732010-10-05 15:59:54 +00001485 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001486 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001487 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001488 unsigned Idx = 0;
Sebastian Redlc3632732010-10-05 15:59:54 +00001489 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001490
Chris Lattnerda930612009-04-27 05:58:23 +00001491 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001492 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001493 case DECL_CONTEXT_LEXICAL:
1494 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001495 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001496 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001497 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001498 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001499 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001500 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001501 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001502 0, 0);
1503 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001504 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001505 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001506 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001507 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001508 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001509 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001510 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001511 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001512 0, llvm::APSInt());
1513 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001514 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001515 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001516 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001517 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001518 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001519 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001520 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001521 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001522 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001523 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001524 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001525 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001526 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001527 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001528 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001529 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001530 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001531 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001532 SourceLocation(), 0,
1533 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001534 SourceLocation(), 0);
1535 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001536 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001537 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001538 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1539 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001540 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001541 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001542 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001543 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001544 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001545 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001546 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001547 SourceLocation(), 0, 0);
1548 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001549 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001550 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001551 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001552 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001553 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001554 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001555 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001556 SourceLocation(),
1557 NestedNameSpecifierLoc(),
1558 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001559 DeclarationName());
1560 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001561 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001562 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001563 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001564 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001565 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001566 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001567 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001568 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001569 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001570 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001571 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001572 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001573 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001574 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001575 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001576 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001577 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001578 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001579 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001580 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001581 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001582 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001583 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001584 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001585 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001586 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001587 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001588 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001589 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001590 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001591 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001592 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001593 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001594 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001595 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001596 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001597 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001598 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001599 Decl::EmptyShell());
1600 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001601 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001602 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001603 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001604 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001605 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001606 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001607 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001608 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001609 SourceLocation(), 0, 0, 0, QualType(),
1610 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001611 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001612 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001613 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001614 SourceLocation(), 0, 0, 0, QualType(),
1615 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001616 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001617 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001618 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001619 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001620 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001621 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001622 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001623 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001624 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001625 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001626 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001627 break;
1628
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001629 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001630 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001631 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001632 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001633 case DECL_OBJC_INTERFACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001634 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001635 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001636 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001637 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001638 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001639 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001640 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001641 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
Argyrios Kyrtzidisb05d7b22011-10-17 19:48:06 +00001642 SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001643 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001644 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001645 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001646 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001647 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001648 case DECL_OBJC_CLASS:
Douglas Gregor35942772011-09-09 21:34:22 +00001649 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001650 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001651 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001652 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001653 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001654 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001655 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001656 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001657 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001658 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1659 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001660 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001661 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001662 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1663 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001664 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001665 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001666 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001667 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001668 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001669 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001670 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001671 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001672 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001673 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001674 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001675 ObjCPropertyImplDecl::Dynamic, 0,
1676 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001677 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001678 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001679 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001680 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001681 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001682 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001683 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001684 0, 0);
1685 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001686 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001687 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001688 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001689 break;
1690
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001691 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00001692 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001693 break;
1694
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001695 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001696 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001697 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001698 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001699 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00001700 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00001701 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001702 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001703 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00001704 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001705 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00001706 case DECL_CXX_BASE_SPECIFIERS:
1707 Error("attempt to read a C++ base-specifier record as a declaration");
1708 return 0;
Chris Lattner698f9252009-04-27 05:27:42 +00001709 }
Chris Lattner698f9252009-04-27 05:27:42 +00001710
Sebastian Redld527cc02010-08-18 23:56:48 +00001711 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001712 LoadedDecl(Index, D);
1713 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001714
1715 // If this declaration is also a declaration context, get the
1716 // offsets for its tables of lexical and visible declarations.
1717 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1718 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1719 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001720 if (Offsets.first != 0)
1721 DC->setHasExternalLexicalStorage(true);
1722 if (Offsets.second != 0)
1723 DC->setHasExternalVisibleStorage(true);
1724 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1725 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00001726 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001727 }
Sebastian Redle1dde812010-08-24 00:50:04 +00001728
Sebastian Redl024e1c42011-04-24 16:27:54 +00001729 // Now add the pending visible updates for this decl context, if it has any.
1730 DeclContextVisibleUpdatesPending::iterator I =
1731 PendingVisibleUpdates.find(ID);
1732 if (I != PendingVisibleUpdates.end()) {
1733 // There are updates. This means the context has external visible
1734 // storage, even if the original stored version didn't.
1735 DC->setHasExternalVisibleStorage(true);
1736 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001737 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1738 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001739 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00001740 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00001741 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00001742 }
1743 }
1744 assert(Idx == Record.size());
1745
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001746 // Load any relevant update records.
1747 loadDeclUpdateRecords(ID, D);
1748
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001749 if (ObjCChainedCategoriesInterfaces.count(ID))
1750 loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1751
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001752 // If we have deserialized a declaration that has a definition the
1753 // AST consumer might need to know about, queue it.
1754 // We don't pass it to the consumer immediately because we may be in recursive
1755 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001756 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00001757 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00001758
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001759 return D;
1760}
1761
1762void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001763 // The declaration may have been modified by files later in the chain.
1764 // If this is the case, read the record containing the updates from each file
1765 // and pass it to ASTDeclReader to make the modifications.
1766 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1767 if (UpdI != DeclUpdateOffsets.end()) {
1768 FileOffsetsTy &UpdateOffsets = UpdI->second;
1769 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001770 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001771 Module *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001772 uint64_t Offset = I->second;
1773 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1774 SavedStreamPosition SavedPosition(Cursor);
1775 Cursor.JumpToBit(Offset);
1776 RecordData Record;
1777 unsigned Code = Cursor.ReadCode();
1778 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1779 (void)RecCode;
1780 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001781
1782 unsigned Idx = 0;
1783 ASTDeclReader Reader(*this, *F, Cursor, ID, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00001784 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001785 }
1786 }
Chris Lattner698f9252009-04-27 05:27:42 +00001787}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001788
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001789namespace {
1790 /// \brief Given an ObjC interface, goes through the modules and links to the
1791 /// interface all the categories for it.
1792 class ObjCChainedCategoriesVisitor {
1793 ASTReader &Reader;
1794 serialization::GlobalDeclID InterfaceID;
1795 ObjCInterfaceDecl *Interface;
1796 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1797 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1798
1799 public:
1800 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1801 serialization::GlobalDeclID InterfaceID,
1802 ObjCInterfaceDecl *Interface)
1803 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1804 GlobHeadCat(0), GlobTailCat(0) { }
1805
1806 static bool visit(Module &M, void *UserData) {
1807 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1808 }
1809
1810 bool visit(Module &M) {
1811 if (Reader.isDeclIDFromModule(InterfaceID, M))
1812 return true; // We reached the module where the interface originated
1813 // from. Stop traversing the imported modules.
1814
1815 Module::ChainedObjCCategoriesMap::iterator
1816 I = M.ChainedObjCCategories.find(InterfaceID);
1817 if (I == M.ChainedObjCCategories.end())
1818 return false;
1819
1820 ObjCCategoryDecl *
1821 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1822 ObjCCategoryDecl *
1823 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1824
1825 addCategories(HeadCat, TailCat);
1826 return false;
1827 }
1828
1829 void addCategories(ObjCCategoryDecl *HeadCat,
1830 ObjCCategoryDecl *TailCat = 0) {
1831 if (!HeadCat) {
1832 assert(!TailCat);
1833 return;
1834 }
1835
1836 if (!TailCat) {
1837 TailCat = HeadCat;
1838 while (TailCat->getNextClassCategory())
1839 TailCat = TailCat->getNextClassCategory();
1840 }
1841
1842 if (!GlobHeadCat) {
1843 GlobHeadCat = HeadCat;
1844 GlobTailCat = TailCat;
1845 } else {
1846 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1847 GlobTailCat = TailCat;
1848 }
1849
1850 llvm::DenseSet<DeclarationName> Checked;
1851 for (ObjCCategoryDecl *Cat = HeadCat,
1852 *CatEnd = TailCat->getNextClassCategory();
1853 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1854 if (Checked.count(Cat->getDeclName()))
1855 continue;
1856 Checked.insert(Cat->getDeclName());
1857 checkForDuplicate(Cat);
1858 }
1859 }
1860
1861 /// \brief Warns for duplicate categories that come from different modules.
1862 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1863 DeclarationName Name = Cat->getDeclName();
1864 // Find the top category with the same name. We do not want to warn for
1865 // duplicates along the established chain because there were already
1866 // warnings for them when the module was created. We only want to warn for
1867 // duplicates between non-dependent modules:
1868 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001869 // MT //
1870 // / \ //
1871 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001872 //
1873 // We want to warn for duplicates between ML and MR,not between ML and MT.
1874 //
1875 // FIXME: We should not warn for duplicates in diamond:
1876 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001877 // MT //
1878 // / \ //
1879 // ML MR //
1880 // \ / //
1881 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001882 //
1883 // If there are duplicates in ML/MR, there will be warning when creating
1884 // MB *and* when importing MB. We should not warn when importing.
1885 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1886 Next = Next->getNextClassCategory()) {
1887 if (Next->getDeclName() == Name)
1888 Cat = Next;
1889 }
1890
1891 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1892 if (!PrevCat)
1893 PrevCat = Cat;
1894
1895 if (PrevCat != Cat) {
1896 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1897 << Interface->getDeclName() << Name;
1898 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1899 }
1900 }
1901
1902 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1903 };
1904}
1905
1906void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1907 ObjCInterfaceDecl *D) {
1908 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1909 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1910 // Also add the categories that the interface already links to.
1911 Visitor.addCategories(D->getCategoryList());
1912 D->setCategoryList(Visitor.getHeadCategory());
1913}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001914
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001915void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +00001916 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001917 unsigned Idx = 0;
1918 while (Idx < Record.size()) {
1919 switch ((DeclUpdateKind)Record[Idx++]) {
1920 case UPD_CXX_SET_DEFINITIONDATA: {
1921 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00001922 CXXRecordDecl *DefinitionDecl
1923 = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001924 assert(!RD->DefinitionData && "DefinitionData is already set!");
1925 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1926 break;
1927 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001928
1929 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor496c7092011-08-03 15:48:04 +00001930 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001931 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00001932
1933 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1934 // It will be added to the template's specializations set when loaded.
Douglas Gregor496c7092011-08-03 15:48:04 +00001935 (void)Reader.ReadDecl(Module, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001936 break;
1937
1938 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00001939 NamespaceDecl *Anon
1940 = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00001941 // Guard against these being loaded out of original order. Don't use
1942 // getNextNamespace(), since it tries to access the context and can't in
1943 // the middle of deserialization.
1944 if (!Anon->NextNamespace) {
1945 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1946 TU->setAnonymousNamespace(Anon);
1947 else
1948 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1949 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001950 break;
1951 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00001952
1953 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1954 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1955 Reader.ReadSourceLocation(Module, Record, Idx));
1956 break;
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001957 }
1958 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001959}