blob: 6cc3f0a70bc198e0789f134c3fef0f25e3088188 [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);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000557 ID->setForwardDecl(Record[Idx++]);
558 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000559 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
560 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000561}
562
Sebastian Redld527cc02010-08-18 23:56:48 +0000563void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000564 VisitFieldDecl(IVD);
565 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000566 // This field will be built lazily.
567 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000568 bool synth = Record[Idx++];
569 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000570}
571
Sebastian Redld527cc02010-08-18 23:56:48 +0000572void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000573 VisitObjCContainerDecl(PD);
574 PD->setForwardDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000575 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000576 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000577 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000578 ProtoRefs.reserve(NumProtoRefs);
579 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000580 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000581 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000582 ProtoLocs.reserve(NumProtoRefs);
583 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000584 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000585 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000586 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000587}
588
Sebastian Redld527cc02010-08-18 23:56:48 +0000589void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000590 VisitFieldDecl(FD);
591}
592
Sebastian Redld527cc02010-08-18 23:56:48 +0000593void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000594 VisitDecl(CD);
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000595 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
596 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000597 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner698f9252009-04-27 05:27:42 +0000598}
599
Sebastian Redld527cc02010-08-18 23:56:48 +0000600void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000601 VisitDecl(FPD);
602 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000603 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000604 ProtoRefs.reserve(NumProtoRefs);
605 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000606 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000607 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000608 ProtoLocs.reserve(NumProtoRefs);
609 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000610 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000611 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000612 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000613}
614
Sebastian Redld527cc02010-08-18 23:56:48 +0000615void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000616 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000617 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000618 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000619 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000620 ProtoRefs.reserve(NumProtoRefs);
621 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000622 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000623 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000624 ProtoLocs.reserve(NumProtoRefs);
625 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000626 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000627 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000628 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000629 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000630 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000631 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000632}
633
Sebastian Redld527cc02010-08-18 23:56:48 +0000634void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000635 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000636 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000637}
638
Sebastian Redld527cc02010-08-18 23:56:48 +0000639void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000640 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000641 D->setAtLoc(ReadSourceLocation(Record, Idx));
642 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000643 // FIXME: stable encoding
644 D->setPropertyAttributes(
645 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000646 D->setPropertyAttributesAsWritten(
647 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000648 // FIXME: stable encoding
649 D->setPropertyImplementation(
650 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000651 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
652 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000653 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
654 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
655 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000656}
657
Sebastian Redld527cc02010-08-18 23:56:48 +0000658void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000659 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000660 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000661}
662
Sebastian Redld527cc02010-08-18 23:56:48 +0000663void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000664 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000665 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000666}
667
Sebastian Redld527cc02010-08-18 23:56:48 +0000668void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000669 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000670 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000671 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000672 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000673 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000674}
675
676
Sebastian Redld527cc02010-08-18 23:56:48 +0000677void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000678 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000679 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000680 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
681 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000682 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000683 D->setGetterCXXConstructor(Reader.ReadExpr(F));
684 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000685}
686
Sebastian Redld527cc02010-08-18 23:56:48 +0000687void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000688 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000689 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000690 int BitWidthOrInitializer = Record[Idx++];
691 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000692 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000693 else if (BitWidthOrInitializer == 2)
694 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000695 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000696 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000697 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000698 }
Chris Lattner698f9252009-04-27 05:27:42 +0000699}
700
Francois Pichet87c2e122010-11-21 06:08:52 +0000701void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
702 VisitValueDecl(FD);
703
704 FD->ChainingSize = Record[Idx++];
705 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000706 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000707
708 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000709 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000710}
711
Sebastian Redld527cc02010-08-18 23:56:48 +0000712void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000713 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000714 VisitRedeclarable(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000715 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
716 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
717 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
718 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
719 VD->VarDeclBits.ExceptionVar = Record[Idx++];
720 VD->VarDeclBits.NRVOVariable = Record[Idx++];
721 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000722 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000723 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000724 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000725
726 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000727 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000728 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000729 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000730 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000731 }
Chris Lattner698f9252009-04-27 05:27:42 +0000732}
733
Sebastian Redld527cc02010-08-18 23:56:48 +0000734void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000735 VisitVarDecl(PD);
736}
737
Sebastian Redld527cc02010-08-18 23:56:48 +0000738void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000739 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000740 unsigned isObjCMethodParam = Record[Idx++];
741 unsigned scopeDepth = Record[Idx++];
742 unsigned scopeIndex = Record[Idx++];
743 unsigned declQualifier = Record[Idx++];
744 if (isObjCMethodParam) {
745 assert(scopeDepth == 0);
746 PD->setObjCMethodScopeInfo(scopeIndex);
747 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
748 } else {
749 PD->setScopeInfo(scopeDepth, scopeIndex);
750 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000751 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
752 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000753 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000754 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000755}
756
Sebastian Redld527cc02010-08-18 23:56:48 +0000757void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000758 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000759 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000760 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000761}
762
Sebastian Redld527cc02010-08-18 23:56:48 +0000763void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000764 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000765 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
766 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000767 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000768 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000769 Params.reserve(NumParams);
770 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000771 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000772 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000773
774 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000775 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000776 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000777 captures.reserve(numCaptures);
778 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000779 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +0000780 unsigned flags = Record[Idx++];
781 bool byRef = (flags & 1);
782 bool nested = (flags & 2);
783 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
784
785 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
786 }
Douglas Gregor35942772011-09-09 21:34:22 +0000787 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000788 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000789}
790
Sebastian Redld527cc02010-08-18 23:56:48 +0000791void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000792 VisitDecl(D);
793 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000794 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000795 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000796}
797
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000798void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
799 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +0000800 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000801}
802
803
Sebastian Redld527cc02010-08-18 23:56:48 +0000804void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000805 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +0000806 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +0000807 D->LocStart = ReadSourceLocation(Record, Idx);
808 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +0000809 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000810
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000811 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000812 // FIXME: Modules will likely have trouble with pointing directly at
813 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000814 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +0000815 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000816}
817
Sebastian Redld527cc02010-08-18 23:56:48 +0000818void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000819 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000820 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000821 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +0000822 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000823 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000824}
825
Sebastian Redld527cc02010-08-18 23:56:48 +0000826void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000827 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000828 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000829 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000830 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000831 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000832 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +0000833 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000834 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000835}
836
Sebastian Redld527cc02010-08-18 23:56:48 +0000837void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000838 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000839 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
840 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
841 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000842 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +0000843 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000844}
845
Sebastian Redld527cc02010-08-18 23:56:48 +0000846void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000847 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000848 D->UsingLoc = ReadSourceLocation(Record, Idx);
849 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +0000850 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000851 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
852 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000853}
854
Sebastian Redld527cc02010-08-18 23:56:48 +0000855void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000856 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000857 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000858 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000859 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000860}
861
Sebastian Redld527cc02010-08-18 23:56:48 +0000862void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000863 UnresolvedUsingTypenameDecl *D) {
864 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000865 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +0000866 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000867}
868
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000869void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000870 struct CXXRecordDecl::DefinitionData &Data,
871 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000872 Data.UserDeclaredConstructor = Record[Idx++];
873 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000874 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000875 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000876 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000877 Data.UserDeclaredDestructor = Record[Idx++];
878 Data.Aggregate = Record[Idx++];
879 Data.PlainOldData = Record[Idx++];
880 Data.Empty = Record[Idx++];
881 Data.Polymorphic = Record[Idx++];
882 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +0000883 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +0000884 Data.HasNoNonEmptyBases = Record[Idx++];
885 Data.HasPrivateFields = Record[Idx++];
886 Data.HasProtectedFields = Record[Idx++];
887 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +0000888 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +0000889 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +0000890 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000891 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000892 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000893 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000894 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000895 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +0000896 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000897 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +0000898 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000899 Data.DeclaredDefaultConstructor = Record[Idx++];
900 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000901 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000902 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000903 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000904 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +0000905 Data.FailedImplicitMoveConstructor = Record[Idx++];
906 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +0000907
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000908 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000909 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000910 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000911 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000912 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000913 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +0000914
Douglas Gregor409448c2011-07-21 22:35:25 +0000915 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
916 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000917 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +0000918 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000919}
920
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000921void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
922 CXXRecordDecl *DefinitionDecl,
923 const RecordData &Record,
924 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +0000925 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000926
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000927 if (D == DefinitionDecl) {
928 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000929 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000930 // We read the definition info. Check if there are pending forward
931 // references that need to point to this DefinitionData pointer.
932 ASTReader::PendingForwardRefsMap::iterator
933 FindI = Reader.PendingForwardRefs.find(D);
934 if (FindI != Reader.PendingForwardRefs.end()) {
935 ASTReader::ForwardRefs &Refs = FindI->second;
936 for (ASTReader::ForwardRefs::iterator
937 I = Refs.begin(), E = Refs.end(); I != E; ++I)
938 (*I)->DefinitionData = D->DefinitionData;
939#ifndef NDEBUG
940 // We later check whether PendingForwardRefs is empty to make sure all
941 // pending references were linked.
942 Reader.PendingForwardRefs.erase(D);
943#endif
944 }
945 } else if (DefinitionDecl) {
946 if (DefinitionDecl->DefinitionData) {
947 D->DefinitionData = DefinitionDecl->DefinitionData;
948 } else {
949 // The definition is still initializing.
950 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
951 }
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000952 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000953}
954
955void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
956 VisitRecordDecl(D);
957
Douglas Gregor409448c2011-07-21 22:35:25 +0000958 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000959 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
960
Douglas Gregor35942772011-09-09 21:34:22 +0000961 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000962
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000963 enum CXXRecKind {
964 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
965 };
966 switch ((CXXRecKind)Record[Idx++]) {
967 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000968 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000969 case CXXRecNotTemplate:
970 break;
971 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000972 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000973 break;
974 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000975 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000976 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000977 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +0000978 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
979 MSI->setPointOfInstantiation(POI);
980 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000981 break;
982 }
983 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000984
985 // Load the key function to avoid deserializing every method so we can
986 // compute it.
John McCall5e1cdac2011-10-07 06:10:15 +0000987 if (D->IsCompleteDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000988 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000989 C.KeyFunctions[D] = Key;
990 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000991}
992
Sebastian Redld527cc02010-08-18 23:56:48 +0000993void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000994 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000995 unsigned NumOverridenMethods = Record[Idx++];
996 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000997 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
998 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +0000999 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +00001000 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +00001001 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001002}
1003
Sebastian Redld527cc02010-08-18 23:56:48 +00001004void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001005 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001006
1007 D->IsExplicitSpecified = Record[Idx++];
1008 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001009 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1010 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001011}
1012
Sebastian Redld527cc02010-08-18 23:56:48 +00001013void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001014 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001015
1016 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001017 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001018}
1019
Sebastian Redld527cc02010-08-18 23:56:48 +00001020void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001021 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001022 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001023}
1024
Sebastian Redld527cc02010-08-18 23:56:48 +00001025void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001026 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001027 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001028}
1029
Sebastian Redld527cc02010-08-18 23:56:48 +00001030void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001031 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001032 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001033 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001034 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001035 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001036 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001037 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001038 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001039}
1040
Sebastian Redld527cc02010-08-18 23:56:48 +00001041void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001042 VisitDecl(D);
1043 unsigned NumParams = Record[Idx++];
1044 D->NumParams = NumParams;
1045 D->Params = new TemplateParameterList*[NumParams];
1046 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001047 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001048 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001049 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001050 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001051 D->Friend = GetTypeSourceInfo(Record, Idx);
1052 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001053}
1054
Sebastian Redld527cc02010-08-18 23:56:48 +00001055void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001056 VisitNamedDecl(D);
1057
Douglas Gregor409448c2011-07-21 22:35:25 +00001058 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001059 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001060 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001061 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001062}
1063
Sebastian Redld527cc02010-08-18 23:56:48 +00001064void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001065 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1066 // can be used while this is still initializing.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001067
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001068 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor409448c2011-07-21 22:35:25 +00001069 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1070 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001071 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1072 // We temporarily set the first (canonical) declaration as the previous one
1073 // which is the one that matters and mark the real previous DeclID to be
1074 // loaded & attached later on.
1075 RedeclarableTemplateDecl *FirstDecl =
1076 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1077 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1078 "FirstDecl kind mismatch");
1079 if (FirstDecl) {
1080 D->CommonOrPrev = FirstDecl;
1081 // Mark the real previous DeclID to be loaded & attached later on.
1082 if (PreviousDeclID != FirstDeclID)
1083 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1084 } else {
Douglas Gregor35942772011-09-09 21:34:22 +00001085 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001086 if (RedeclarableTemplateDecl *RTD
Douglas Gregor409448c2011-07-21 22:35:25 +00001087 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001088 assert(RTD->getKind() == D->getKind() &&
1089 "InstantiatedFromMemberTemplate kind mismatch");
1090 D->setInstantiatedFromMemberTemplateImpl(RTD);
1091 if (Record[Idx++])
1092 D->setMemberSpecialization();
1093 }
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001094
Douglas Gregor409448c2011-07-21 22:35:25 +00001095 RedeclarableTemplateDecl *LatestDecl
1096 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001097
1098 // This decl is a first one and the latest declaration that it points to is
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001099 // in the same AST file. However, if this actually needs to point to a
1100 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001101 // the FirstLatestDeclIDs map which tracks this kind of decls.
1102 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001103 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001104 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1105 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregor1b59e9c2011-08-25 15:28:26 +00001106 if (Decl *NewLatest = Reader.GetDecl(I->second))
1107 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001108 }
1109
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001110 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1111 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001112 }
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001113
1114 VisitTemplateDecl(D);
1115 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001116}
1117
Sebastian Redld527cc02010-08-18 23:56:48 +00001118void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001119 VisitRedeclarableTemplateDecl(D);
1120
1121 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001122 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1123 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001124 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001125 SpecIDs.push_back(0);
1126
1127 // Specializations.
1128 unsigned Size = Record[Idx++];
1129 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001130 for (unsigned I = 0; I != Size; ++I)
1131 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001132
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001133 // Partial specializations.
1134 Size = Record[Idx++];
1135 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001136 for (unsigned I = 0; I != Size; ++I)
1137 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001138
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001139 if (SpecIDs[0]) {
1140 typedef serialization::DeclID DeclID;
1141
1142 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1143 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001144 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001145 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1146 SpecIDs.size() * sizeof(DeclID));
1147 }
1148
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001149 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001150 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001151}
1152
Sebastian Redld527cc02010-08-18 23:56:48 +00001153void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001154 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001155 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001156
Douglas Gregor35942772011-09-09 21:34:22 +00001157 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001158 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001159 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001160 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001161 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001162 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001163 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001164 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001165 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1166 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001167 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1168 = new (C) ClassTemplateSpecializationDecl::
1169 SpecializedPartialSpecialization();
1170 PS->PartialSpecialization
1171 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1172 PS->TemplateArgs = ArgList;
1173 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001174 }
1175 }
1176
1177 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001178 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001179 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1180 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1181 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001182 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1183 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001184 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001185 }
1186
Chris Lattner5f9e2722011-07-23 10:55:15 +00001187 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001188 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001189 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1190 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001191 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001192 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001193
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001194 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001195 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001196 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001197 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1198 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001199 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001200 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001201 }
1202 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001203}
1204
Sebastian Redld527cc02010-08-18 23:56:48 +00001205void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001206 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001207 VisitClassTemplateSpecializationDecl(D);
1208
Douglas Gregor35942772011-09-09 21:34:22 +00001209 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001210 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001211
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001212 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001213 if (NumArgs) {
1214 D->NumArgsAsWritten = NumArgs;
1215 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1216 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001217 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001218 }
1219
1220 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001221
1222 // These are read/set from/to the first declaration.
1223 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001224 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001225 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001226 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001227 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001228}
1229
Sebastian Redl14c36332011-08-31 13:59:56 +00001230void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1231 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001232 VisitDecl(D);
1233 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1234}
1235
Sebastian Redld527cc02010-08-18 23:56:48 +00001236void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001237 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001238
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001239 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001240 // This FunctionTemplateDecl owns a CommonPtr; read it.
1241
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001242 // Read the function specialization declarations.
1243 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001244 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001245 unsigned NumSpecs = Record[Idx++];
1246 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001247 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001248 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001249}
1250
Sebastian Redld527cc02010-08-18 23:56:48 +00001251void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001252 VisitTypeDecl(D);
1253
1254 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001255
1256 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001257 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001258 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001259}
1260
Sebastian Redld527cc02010-08-18 23:56:48 +00001261void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001262 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001263 // TemplateParmPosition.
1264 D->setDepth(Record[Idx++]);
1265 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001266 if (D->isExpandedParameterPack()) {
1267 void **Data = reinterpret_cast<void **>(D + 1);
1268 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001269 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001270 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1271 }
1272 } else {
1273 // Rest of NonTypeTemplateParmDecl.
1274 D->ParameterPack = Record[Idx++];
1275 if (Record[Idx++]) {
1276 Expr *DefArg = Reader.ReadExpr(F);
1277 bool Inherited = Record[Idx++];
1278 D->setDefaultArgument(DefArg, Inherited);
1279 }
1280 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001281}
1282
Sebastian Redld527cc02010-08-18 23:56:48 +00001283void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001284 VisitTemplateDecl(D);
1285 // TemplateParmPosition.
1286 D->setDepth(Record[Idx++]);
1287 D->setPosition(Record[Idx++]);
1288 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001289 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001290 bool IsInherited = Record[Idx++];
1291 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001292 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001293}
1294
Richard Smith3e4c6c42011-05-05 21:57:07 +00001295void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1296 VisitRedeclarableTemplateDecl(D);
1297}
1298
Sebastian Redld527cc02010-08-18 23:56:48 +00001299void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001300 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001301 D->AssertExpr = Reader.ReadExpr(F);
1302 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001303 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001304}
1305
Mike Stump1eb44332009-09-09 15:08:12 +00001306std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001307ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001308 uint64_t LexicalOffset = Record[Idx++];
1309 uint64_t VisibleOffset = Record[Idx++];
1310 return std::make_pair(LexicalOffset, VisibleOffset);
1311}
1312
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001313template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001314void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001315 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1316 RedeclKind Kind = (RedeclKind)Record[Idx++];
1317 switch (Kind) {
1318 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001319 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1320 " messed up reading");
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001321 case NoRedeclaration:
1322 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001323 case PointsToPrevious: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001324 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1325 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001326 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1327 // We temporarily set the first (canonical) declaration as the previous one
1328 // which is the one that matters and mark the real previous DeclID to be
1329 // loaded & attached later on.
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001330 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001331 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1332 if (PreviousDeclID != FirstDeclID)
1333 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1334 PreviousDeclID));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001335 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001336 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001337 case PointsToLatest:
1338 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
Douglas Gregor409448c2011-07-21 22:35:25 +00001339 ReadDeclAs<T>(Record, Idx));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001340 break;
1341 }
1342
1343 assert(!(Kind == PointsToPrevious &&
1344 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1345 Reader.FirstLatestDeclIDs.end()) &&
1346 "This decl is not first, it should not be in the map");
1347 if (Kind == PointsToPrevious)
1348 return;
1349
1350 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001351 // the same AST file. However, if this actually needs to point to a
1352 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001353 // FirstLatestDeclIDs map which tracks this kind of decls.
1354 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1355 "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001356 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001357 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1358 if (I != Reader.FirstLatestDeclIDs.end()) {
1359 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001360 D->RedeclLink
1361 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1362 }
1363}
1364
Chris Lattner698f9252009-04-27 05:27:42 +00001365//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001366// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001367//===----------------------------------------------------------------------===//
1368
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001369/// \brief Reads attributes from the current stream position.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001370void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001371 const RecordData &Record, unsigned &Idx) {
1372 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001373 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001374 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001375 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001376
Sean Huntcf807c42010-08-18 23:23:40 +00001377#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001378
1379 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001380 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001381 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001382}
1383
1384//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001385// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001386//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001387
1388/// \brief Note that we have loaded the declaration with the given
1389/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001390///
Chris Lattner698f9252009-04-27 05:27:42 +00001391/// This routine notes that this declaration has already been loaded,
1392/// so that future GetDecl calls will return this declaration rather
1393/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001394inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001395 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1396 DeclsLoaded[Index] = D;
1397}
1398
1399
1400/// \brief Determine whether the consumer will be interested in seeing
1401/// this declaration (via HandleTopLevelDecl).
1402///
1403/// This routine should return true for anything that might affect
1404/// code generation, e.g., inline function definitions, Objective-C
1405/// declarations with metadata, etc.
1406static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001407 // An ObjCMethodDecl is never considered as "interesting" because its
1408 // implementation container always is.
1409
Douglas Gregor94da1582011-09-10 00:22:34 +00001410 if (isa<FileScopeAsmDecl>(D) ||
1411 isa<ObjCProtocolDecl>(D) ||
1412 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001413 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001414 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001415 return Var->isFileVarDecl() &&
1416 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001417 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001418 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001419
1420 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001421}
1422
Douglas Gregor96e973f2011-07-20 00:27:43 +00001423/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001424ASTReader::RecordLocation
Douglas Gregor496c7092011-08-03 15:48:04 +00001425ASTReader::DeclCursorForID(DeclID ID) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001426 // See if there's an override.
1427 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1428 if (It != ReplacedDecls.end())
Sebastian Redlc3632732010-10-05 15:59:54 +00001429 return RecordLocation(It->second.first, It->second.second);
Sebastian Redl0b17c612010-08-13 00:28:03 +00001430
Douglas Gregor96e973f2011-07-20 00:27:43 +00001431 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1432 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor9827a802011-07-29 00:56:45 +00001433 Module *M = I->second;
Douglas Gregorb18b1fd2011-08-03 23:28:44 +00001434 return RecordLocation(M,
1435 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001436}
1437
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001438ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001439 ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001440 = GlobalBitOffsetsMap.find(GlobalOffset);
1441
1442 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1443 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1444}
1445
Douglas Gregore92b8a12011-08-04 00:01:48 +00001446uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1447 return LocalOffset + M.GlobalBitOffset;
1448}
1449
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001450void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1451 assert(D && previous);
1452 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1453 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1454 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1455 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1456 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1457 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1458 } else {
1459 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1460 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1461 }
1462}
1463
1464void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1465 Decl *previous = GetDecl(ID);
1466 ASTDeclReader::attachPreviousDecl(D, previous);
1467}
1468
Sebastian Redld527cc02010-08-18 23:56:48 +00001469/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001470Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001471 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Douglas Gregor496c7092011-08-03 15:48:04 +00001472 RecordLocation Loc = DeclCursorForID(ID);
Sebastian Redlc3632732010-10-05 15:59:54 +00001473 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001474 // Keep track of where we are in the stream, then jump back there
1475 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001476 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001477
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001478 ReadingKindTracker ReadingKind(Read_Decl, *this);
1479
Douglas Gregord89275b2009-07-06 18:54:52 +00001480 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001481 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Sebastian Redlc3632732010-10-05 15:59:54 +00001483 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001484 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001485 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001486 unsigned Idx = 0;
Sebastian Redlc3632732010-10-05 15:59:54 +00001487 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001488
Chris Lattnerda930612009-04-27 05:58:23 +00001489 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001490 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001491 case DECL_CONTEXT_LEXICAL:
1492 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001493 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001494 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001495 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001496 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001497 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001498 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001499 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001500 0, 0);
1501 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001502 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001503 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001504 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001505 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001506 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001507 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001508 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001509 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001510 0, llvm::APSInt());
1511 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001512 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001513 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001514 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001515 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001516 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001517 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001518 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001519 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001520 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001521 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001522 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001523 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001524 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001525 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001526 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001527 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001528 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001529 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001530 SourceLocation(), 0,
1531 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001532 SourceLocation(), 0);
1533 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001534 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001535 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001536 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1537 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001538 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001539 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001540 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001541 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001542 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001543 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001544 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001545 SourceLocation(), 0, 0);
1546 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001547 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001548 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001549 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001550 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001551 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001552 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001553 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001554 SourceLocation(),
1555 NestedNameSpecifierLoc(),
1556 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001557 DeclarationName());
1558 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001559 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001560 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001561 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001562 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001563 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001564 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001565 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001566 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001567 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001568 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001569 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001570 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001571 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001572 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001573 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001574 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001575 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001576 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001577 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001578 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001579 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001580 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001581 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001582 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001583 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001584 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001585 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001586 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001587 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001588 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001589 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001590 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001591 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001592 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001593 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001594 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001595 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001596 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001597 Decl::EmptyShell());
1598 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001599 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001600 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001601 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001602 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001603 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001604 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001605 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001606 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001607 SourceLocation(), 0, 0, 0, QualType(),
1608 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001609 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001610 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001611 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001612 SourceLocation(), 0, 0, 0, QualType(),
1613 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001614 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001615 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001616 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001617 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001618 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001619 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001620 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001621 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001622 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001623 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001624 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001625 break;
1626
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001627 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001628 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001629 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001630 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001631 case DECL_OBJC_INTERFACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001632 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001633 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001634 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001635 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001636 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001637 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001638 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001639 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
1640 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001641 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001642 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001643 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001644 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001645 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001646 case DECL_OBJC_CLASS:
Douglas Gregor35942772011-09-09 21:34:22 +00001647 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001648 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001649 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001650 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001651 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001652 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001653 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001654 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001655 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001656 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1657 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001658 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001659 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001660 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1661 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001662 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001663 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001664 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001665 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001666 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001667 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001668 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001669 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001670 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001671 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001672 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001673 ObjCPropertyImplDecl::Dynamic, 0,
1674 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001675 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001676 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001677 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001678 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001679 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001680 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001681 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001682 0, 0);
1683 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001684 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001685 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001686 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001687 break;
1688
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001689 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00001690 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001691 break;
1692
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001693 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001694 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001695 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001696 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001697 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00001698 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00001699 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001700 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001701 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00001702 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001703 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00001704 case DECL_CXX_BASE_SPECIFIERS:
1705 Error("attempt to read a C++ base-specifier record as a declaration");
1706 return 0;
Chris Lattner698f9252009-04-27 05:27:42 +00001707 }
Chris Lattner698f9252009-04-27 05:27:42 +00001708
Sebastian Redld527cc02010-08-18 23:56:48 +00001709 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001710 LoadedDecl(Index, D);
1711 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001712
1713 // If this declaration is also a declaration context, get the
1714 // offsets for its tables of lexical and visible declarations.
1715 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1716 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1717 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001718 if (Offsets.first != 0)
1719 DC->setHasExternalLexicalStorage(true);
1720 if (Offsets.second != 0)
1721 DC->setHasExternalVisibleStorage(true);
1722 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1723 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00001724 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001725 }
Sebastian Redle1dde812010-08-24 00:50:04 +00001726
Sebastian Redl024e1c42011-04-24 16:27:54 +00001727 // Now add the pending visible updates for this decl context, if it has any.
1728 DeclContextVisibleUpdatesPending::iterator I =
1729 PendingVisibleUpdates.find(ID);
1730 if (I != PendingVisibleUpdates.end()) {
1731 // There are updates. This means the context has external visible
1732 // storage, even if the original stored version didn't.
1733 DC->setHasExternalVisibleStorage(true);
1734 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001735 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1736 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001737 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00001738 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00001739 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00001740 }
1741 }
1742 assert(Idx == Record.size());
1743
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001744 // Load any relevant update records.
1745 loadDeclUpdateRecords(ID, D);
1746
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001747 if (ObjCChainedCategoriesInterfaces.count(ID))
1748 loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1749
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001750 // If we have deserialized a declaration that has a definition the
1751 // AST consumer might need to know about, queue it.
1752 // We don't pass it to the consumer immediately because we may be in recursive
1753 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001754 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00001755 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00001756
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001757 return D;
1758}
1759
1760void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001761 // The declaration may have been modified by files later in the chain.
1762 // If this is the case, read the record containing the updates from each file
1763 // and pass it to ASTDeclReader to make the modifications.
1764 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1765 if (UpdI != DeclUpdateOffsets.end()) {
1766 FileOffsetsTy &UpdateOffsets = UpdI->second;
1767 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001768 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001769 Module *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001770 uint64_t Offset = I->second;
1771 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1772 SavedStreamPosition SavedPosition(Cursor);
1773 Cursor.JumpToBit(Offset);
1774 RecordData Record;
1775 unsigned Code = Cursor.ReadCode();
1776 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1777 (void)RecCode;
1778 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001779
1780 unsigned Idx = 0;
1781 ASTDeclReader Reader(*this, *F, Cursor, ID, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00001782 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001783 }
1784 }
Chris Lattner698f9252009-04-27 05:27:42 +00001785}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001786
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001787namespace {
1788 /// \brief Given an ObjC interface, goes through the modules and links to the
1789 /// interface all the categories for it.
1790 class ObjCChainedCategoriesVisitor {
1791 ASTReader &Reader;
1792 serialization::GlobalDeclID InterfaceID;
1793 ObjCInterfaceDecl *Interface;
1794 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1795 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1796
1797 public:
1798 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1799 serialization::GlobalDeclID InterfaceID,
1800 ObjCInterfaceDecl *Interface)
1801 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1802 GlobHeadCat(0), GlobTailCat(0) { }
1803
1804 static bool visit(Module &M, void *UserData) {
1805 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1806 }
1807
1808 bool visit(Module &M) {
1809 if (Reader.isDeclIDFromModule(InterfaceID, M))
1810 return true; // We reached the module where the interface originated
1811 // from. Stop traversing the imported modules.
1812
1813 Module::ChainedObjCCategoriesMap::iterator
1814 I = M.ChainedObjCCategories.find(InterfaceID);
1815 if (I == M.ChainedObjCCategories.end())
1816 return false;
1817
1818 ObjCCategoryDecl *
1819 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1820 ObjCCategoryDecl *
1821 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1822
1823 addCategories(HeadCat, TailCat);
1824 return false;
1825 }
1826
1827 void addCategories(ObjCCategoryDecl *HeadCat,
1828 ObjCCategoryDecl *TailCat = 0) {
1829 if (!HeadCat) {
1830 assert(!TailCat);
1831 return;
1832 }
1833
1834 if (!TailCat) {
1835 TailCat = HeadCat;
1836 while (TailCat->getNextClassCategory())
1837 TailCat = TailCat->getNextClassCategory();
1838 }
1839
1840 if (!GlobHeadCat) {
1841 GlobHeadCat = HeadCat;
1842 GlobTailCat = TailCat;
1843 } else {
1844 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1845 GlobTailCat = TailCat;
1846 }
1847
1848 llvm::DenseSet<DeclarationName> Checked;
1849 for (ObjCCategoryDecl *Cat = HeadCat,
1850 *CatEnd = TailCat->getNextClassCategory();
1851 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1852 if (Checked.count(Cat->getDeclName()))
1853 continue;
1854 Checked.insert(Cat->getDeclName());
1855 checkForDuplicate(Cat);
1856 }
1857 }
1858
1859 /// \brief Warns for duplicate categories that come from different modules.
1860 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1861 DeclarationName Name = Cat->getDeclName();
1862 // Find the top category with the same name. We do not want to warn for
1863 // duplicates along the established chain because there were already
1864 // warnings for them when the module was created. We only want to warn for
1865 // duplicates between non-dependent modules:
1866 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001867 // MT //
1868 // / \ //
1869 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001870 //
1871 // We want to warn for duplicates between ML and MR,not between ML and MT.
1872 //
1873 // FIXME: We should not warn for duplicates in diamond:
1874 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001875 // MT //
1876 // / \ //
1877 // ML MR //
1878 // \ / //
1879 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001880 //
1881 // If there are duplicates in ML/MR, there will be warning when creating
1882 // MB *and* when importing MB. We should not warn when importing.
1883 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1884 Next = Next->getNextClassCategory()) {
1885 if (Next->getDeclName() == Name)
1886 Cat = Next;
1887 }
1888
1889 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1890 if (!PrevCat)
1891 PrevCat = Cat;
1892
1893 if (PrevCat != Cat) {
1894 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1895 << Interface->getDeclName() << Name;
1896 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1897 }
1898 }
1899
1900 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1901 };
1902}
1903
1904void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1905 ObjCInterfaceDecl *D) {
1906 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1907 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1908 // Also add the categories that the interface already links to.
1909 Visitor.addCategories(D->getCategoryList());
1910 D->setCategoryList(Visitor.getHeadCategory());
1911}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001912
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001913void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +00001914 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001915 unsigned Idx = 0;
1916 while (Idx < Record.size()) {
1917 switch ((DeclUpdateKind)Record[Idx++]) {
1918 case UPD_CXX_SET_DEFINITIONDATA: {
1919 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00001920 CXXRecordDecl *DefinitionDecl
1921 = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001922 assert(!RD->DefinitionData && "DefinitionData is already set!");
1923 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1924 break;
1925 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001926
1927 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor496c7092011-08-03 15:48:04 +00001928 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001929 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00001930
1931 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1932 // It will be added to the template's specializations set when loaded.
Douglas Gregor496c7092011-08-03 15:48:04 +00001933 (void)Reader.ReadDecl(Module, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001934 break;
1935
1936 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00001937 NamespaceDecl *Anon
1938 = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00001939 // Guard against these being loaded out of original order. Don't use
1940 // getNextNamespace(), since it tries to access the context and can't in
1941 // the middle of deserialization.
1942 if (!Anon->NextNamespace) {
1943 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1944 TU->setAnonymousNamespace(Anon);
1945 else
1946 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1947 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001948 break;
1949 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00001950
1951 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1952 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1953 Reader.ReadSourceLocation(Module, Record, Idx));
1954 break;
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001955 }
1956 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001957}