blob: beaf5f65a98ade9e98e81175d7dec8fbe1f7ccda [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++]);
285 TD->setDefinition(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++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000485 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
486 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000487 MD->SetRelatedResultType(Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000488 MD->setResultType(Reader.readType(F, Record, Idx));
Sebastian Redlc3632732010-10-05 15:59:54 +0000489 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
490 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000491 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000492 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000493 Params.reserve(NumParams);
494 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000495 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
Argyrios Kyrtzidis491306a2011-10-03 06:37:04 +0000496
497 MD->SelLocsKind = Record[Idx++];
498 unsigned NumStoredSelLocs = Record[Idx++];
499 SmallVector<SourceLocation, 16> SelLocs;
500 SelLocs.reserve(NumStoredSelLocs);
501 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
502 SelLocs.push_back(ReadSourceLocation(Record, Idx));
503
504 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner698f9252009-04-27 05:27:42 +0000505}
506
Sebastian Redld527cc02010-08-18 23:56:48 +0000507void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000508 VisitNamedDecl(CD);
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +0000509 CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
510 CD->setAtEndRange(ReadSourceRange(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000511}
512
Sebastian Redld527cc02010-08-18 23:56:48 +0000513void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner698f9252009-04-27 05:27:42 +0000514 VisitObjCContainerDecl(ID);
Douglas Gregor393f2492011-07-22 00:38:23 +0000515 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor409448c2011-07-21 22:35:25 +0000516 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000517
518 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner698f9252009-04-27 05:27:42 +0000519 unsigned NumProtocols = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000520 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner698f9252009-04-27 05:27:42 +0000521 Protocols.reserve(NumProtocols);
522 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000523 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000524 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000525 ProtoLocs.reserve(NumProtocols);
526 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000527 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000528 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000529 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000530
531 // Read the transitive closure of protocols referenced by this class.
532 NumProtocols = Record[Idx++];
533 Protocols.clear();
534 Protocols.reserve(NumProtocols);
535 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000536 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000537 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor35942772011-09-09 21:34:22 +0000538 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000539
540 // Read the ivars.
Chris Lattner698f9252009-04-27 05:27:42 +0000541 unsigned NumIvars = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000542 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner698f9252009-04-27 05:27:42 +0000543 IVars.reserve(NumIvars);
544 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000545 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
546 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
547
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000548 // We will rebuild this list lazily.
549 ID->setIvarList(0);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000550 ID->setForwardDecl(Record[Idx++]);
551 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000552 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
553 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000554}
555
Sebastian Redld527cc02010-08-18 23:56:48 +0000556void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000557 VisitFieldDecl(IVD);
558 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000559 // This field will be built lazily.
560 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000561 bool synth = Record[Idx++];
562 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000563}
564
Sebastian Redld527cc02010-08-18 23:56:48 +0000565void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000566 VisitObjCContainerDecl(PD);
567 PD->setForwardDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000568 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000569 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000570 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000571 ProtoRefs.reserve(NumProtoRefs);
572 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000573 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000574 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000575 ProtoLocs.reserve(NumProtoRefs);
576 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000577 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000578 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000579 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000580}
581
Sebastian Redld527cc02010-08-18 23:56:48 +0000582void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000583 VisitFieldDecl(FD);
584}
585
Sebastian Redld527cc02010-08-18 23:56:48 +0000586void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000587 VisitDecl(CD);
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000588 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
589 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000590 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner698f9252009-04-27 05:27:42 +0000591}
592
Sebastian Redld527cc02010-08-18 23:56:48 +0000593void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000594 VisitDecl(FPD);
595 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000596 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000597 ProtoRefs.reserve(NumProtoRefs);
598 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000599 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000600 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000601 ProtoLocs.reserve(NumProtoRefs);
602 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000603 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000604 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000605 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000606}
607
Sebastian Redld527cc02010-08-18 23:56:48 +0000608void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000609 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000610 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000611 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000612 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000613 ProtoRefs.reserve(NumProtoRefs);
614 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000615 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000616 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000617 ProtoLocs.reserve(NumProtoRefs);
618 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000619 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000620 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000621 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000622 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000623 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000624 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000625}
626
Sebastian Redld527cc02010-08-18 23:56:48 +0000627void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000628 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000629 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000630}
631
Sebastian Redld527cc02010-08-18 23:56:48 +0000632void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000633 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000634 D->setAtLoc(ReadSourceLocation(Record, Idx));
635 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000636 // FIXME: stable encoding
637 D->setPropertyAttributes(
638 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000639 D->setPropertyAttributesAsWritten(
640 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000641 // FIXME: stable encoding
642 D->setPropertyImplementation(
643 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000644 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
645 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000646 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
647 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
648 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000649}
650
Sebastian Redld527cc02010-08-18 23:56:48 +0000651void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000652 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000653 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000654}
655
Sebastian Redld527cc02010-08-18 23:56:48 +0000656void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000657 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000658 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000659}
660
Sebastian Redld527cc02010-08-18 23:56:48 +0000661void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000662 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000663 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000664 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000665 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000666 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000667}
668
669
Sebastian Redld527cc02010-08-18 23:56:48 +0000670void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000671 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000672 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000673 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
674 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000675 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000676 D->setGetterCXXConstructor(Reader.ReadExpr(F));
677 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000678}
679
Sebastian Redld527cc02010-08-18 23:56:48 +0000680void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000681 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000682 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000683 int BitWidthOrInitializer = Record[Idx++];
684 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000685 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000686 else if (BitWidthOrInitializer == 2)
687 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000688 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000689 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000690 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000691 }
Chris Lattner698f9252009-04-27 05:27:42 +0000692}
693
Francois Pichet87c2e122010-11-21 06:08:52 +0000694void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
695 VisitValueDecl(FD);
696
697 FD->ChainingSize = Record[Idx++];
698 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000699 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000700
701 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000702 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000703}
704
Sebastian Redld527cc02010-08-18 23:56:48 +0000705void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000706 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000707 VisitRedeclarable(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000708 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
709 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
710 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
711 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
712 VD->VarDeclBits.ExceptionVar = Record[Idx++];
713 VD->VarDeclBits.NRVOVariable = Record[Idx++];
714 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000715 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000716 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000717 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000718
719 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000720 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000721 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000722 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000723 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000724 }
Chris Lattner698f9252009-04-27 05:27:42 +0000725}
726
Sebastian Redld527cc02010-08-18 23:56:48 +0000727void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000728 VisitVarDecl(PD);
729}
730
Sebastian Redld527cc02010-08-18 23:56:48 +0000731void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000732 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000733 unsigned isObjCMethodParam = Record[Idx++];
734 unsigned scopeDepth = Record[Idx++];
735 unsigned scopeIndex = Record[Idx++];
736 unsigned declQualifier = Record[Idx++];
737 if (isObjCMethodParam) {
738 assert(scopeDepth == 0);
739 PD->setObjCMethodScopeInfo(scopeIndex);
740 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
741 } else {
742 PD->setScopeInfo(scopeDepth, scopeIndex);
743 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000744 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
745 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000746 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000747 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000748}
749
Sebastian Redld527cc02010-08-18 23:56:48 +0000750void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000751 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000752 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000753 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000754}
755
Sebastian Redld527cc02010-08-18 23:56:48 +0000756void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000757 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000758 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
759 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000760 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000761 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000762 Params.reserve(NumParams);
763 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000764 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000765 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000766
767 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000768 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000769 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000770 captures.reserve(numCaptures);
771 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000772 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +0000773 unsigned flags = Record[Idx++];
774 bool byRef = (flags & 1);
775 bool nested = (flags & 2);
776 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
777
778 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
779 }
Douglas Gregor35942772011-09-09 21:34:22 +0000780 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000781 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000782}
783
Sebastian Redld527cc02010-08-18 23:56:48 +0000784void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000785 VisitDecl(D);
786 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000787 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000788 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000789}
790
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000791void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
792 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +0000793 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000794}
795
796
Sebastian Redld527cc02010-08-18 23:56:48 +0000797void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000798 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +0000799 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +0000800 D->LocStart = ReadSourceLocation(Record, Idx);
801 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +0000802 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000803
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000804 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000805 // FIXME: Modules will likely have trouble with pointing directly at
806 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000807 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +0000808 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000809}
810
Sebastian Redld527cc02010-08-18 23:56:48 +0000811void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000812 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000813 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000814 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +0000815 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000816 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000817}
818
Sebastian Redld527cc02010-08-18 23:56:48 +0000819void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000820 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000821 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000822 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000823 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000824 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000825 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +0000826 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000827 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000828}
829
Sebastian Redld527cc02010-08-18 23:56:48 +0000830void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000831 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000832 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
833 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
834 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000835 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +0000836 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000837}
838
Sebastian Redld527cc02010-08-18 23:56:48 +0000839void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000840 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000841 D->UsingLoc = ReadSourceLocation(Record, Idx);
842 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +0000843 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000844 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
845 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000846}
847
Sebastian Redld527cc02010-08-18 23:56:48 +0000848void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000849 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000850 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000851 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000852 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000853}
854
Sebastian Redld527cc02010-08-18 23:56:48 +0000855void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000856 UnresolvedUsingTypenameDecl *D) {
857 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000858 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +0000859 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000860}
861
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000862void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000863 struct CXXRecordDecl::DefinitionData &Data,
864 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000865 Data.UserDeclaredConstructor = Record[Idx++];
866 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000867 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000868 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000869 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000870 Data.UserDeclaredDestructor = Record[Idx++];
871 Data.Aggregate = Record[Idx++];
872 Data.PlainOldData = Record[Idx++];
873 Data.Empty = Record[Idx++];
874 Data.Polymorphic = Record[Idx++];
875 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +0000876 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +0000877 Data.HasNoNonEmptyBases = Record[Idx++];
878 Data.HasPrivateFields = Record[Idx++];
879 Data.HasProtectedFields = Record[Idx++];
880 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +0000881 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +0000882 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +0000883 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000884 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000885 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000886 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000887 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000888 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +0000889 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000890 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +0000891 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000892 Data.DeclaredDefaultConstructor = Record[Idx++];
893 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000894 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000895 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000896 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000897 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +0000898 Data.FailedImplicitMoveConstructor = Record[Idx++];
899 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +0000900
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000901 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000902 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000903 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000904 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000905 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000906 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +0000907
Douglas Gregor409448c2011-07-21 22:35:25 +0000908 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
909 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000910 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +0000911 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000912}
913
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000914void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
915 CXXRecordDecl *DefinitionDecl,
916 const RecordData &Record,
917 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +0000918 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000919
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000920 if (D == DefinitionDecl) {
921 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000922 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000923 // We read the definition info. Check if there are pending forward
924 // references that need to point to this DefinitionData pointer.
925 ASTReader::PendingForwardRefsMap::iterator
926 FindI = Reader.PendingForwardRefs.find(D);
927 if (FindI != Reader.PendingForwardRefs.end()) {
928 ASTReader::ForwardRefs &Refs = FindI->second;
929 for (ASTReader::ForwardRefs::iterator
930 I = Refs.begin(), E = Refs.end(); I != E; ++I)
931 (*I)->DefinitionData = D->DefinitionData;
932#ifndef NDEBUG
933 // We later check whether PendingForwardRefs is empty to make sure all
934 // pending references were linked.
935 Reader.PendingForwardRefs.erase(D);
936#endif
937 }
938 } else if (DefinitionDecl) {
939 if (DefinitionDecl->DefinitionData) {
940 D->DefinitionData = DefinitionDecl->DefinitionData;
941 } else {
942 // The definition is still initializing.
943 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
944 }
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000945 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000946}
947
948void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
949 VisitRecordDecl(D);
950
Douglas Gregor409448c2011-07-21 22:35:25 +0000951 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000952 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
953
Douglas Gregor35942772011-09-09 21:34:22 +0000954 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000955
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000956 enum CXXRecKind {
957 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
958 };
959 switch ((CXXRecKind)Record[Idx++]) {
960 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000961 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000962 case CXXRecNotTemplate:
963 break;
964 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000965 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000966 break;
967 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000968 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000969 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000970 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +0000971 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
972 MSI->setPointOfInstantiation(POI);
973 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000974 break;
975 }
976 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000977
978 // Load the key function to avoid deserializing every method so we can
979 // compute it.
980 if (D->IsDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000981 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000982 C.KeyFunctions[D] = Key;
983 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000984}
985
Sebastian Redld527cc02010-08-18 23:56:48 +0000986void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000987 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000988 unsigned NumOverridenMethods = Record[Idx++];
989 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000990 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
991 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +0000992 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000993 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000994 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000995}
996
Sebastian Redld527cc02010-08-18 23:56:48 +0000997void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000998 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000999
1000 D->IsExplicitSpecified = Record[Idx++];
1001 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +00001002 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1003 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001004}
1005
Sebastian Redld527cc02010-08-18 23:56:48 +00001006void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001007 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001008
1009 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001010 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001011}
1012
Sebastian Redld527cc02010-08-18 23:56:48 +00001013void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001014 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001015 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001016}
1017
Sebastian Redld527cc02010-08-18 23:56:48 +00001018void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001019 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001020 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001021}
1022
Sebastian Redld527cc02010-08-18 23:56:48 +00001023void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001024 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001025 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001026 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001027 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001028 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001029 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001030 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001031 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001032}
1033
Sebastian Redld527cc02010-08-18 23:56:48 +00001034void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001035 VisitDecl(D);
1036 unsigned NumParams = Record[Idx++];
1037 D->NumParams = NumParams;
1038 D->Params = new TemplateParameterList*[NumParams];
1039 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001040 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001041 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001042 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001043 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001044 D->Friend = GetTypeSourceInfo(Record, Idx);
1045 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001046}
1047
Sebastian Redld527cc02010-08-18 23:56:48 +00001048void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001049 VisitNamedDecl(D);
1050
Douglas Gregor409448c2011-07-21 22:35:25 +00001051 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001052 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001053 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001054 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001055}
1056
Sebastian Redld527cc02010-08-18 23:56:48 +00001057void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001058 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1059 // can be used while this is still initializing.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001060
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001061 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor409448c2011-07-21 22:35:25 +00001062 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1063 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001064 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1065 // We temporarily set the first (canonical) declaration as the previous one
1066 // which is the one that matters and mark the real previous DeclID to be
1067 // loaded & attached later on.
1068 RedeclarableTemplateDecl *FirstDecl =
1069 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1070 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1071 "FirstDecl kind mismatch");
1072 if (FirstDecl) {
1073 D->CommonOrPrev = FirstDecl;
1074 // Mark the real previous DeclID to be loaded & attached later on.
1075 if (PreviousDeclID != FirstDeclID)
1076 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1077 } else {
Douglas Gregor35942772011-09-09 21:34:22 +00001078 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001079 if (RedeclarableTemplateDecl *RTD
Douglas Gregor409448c2011-07-21 22:35:25 +00001080 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001081 assert(RTD->getKind() == D->getKind() &&
1082 "InstantiatedFromMemberTemplate kind mismatch");
1083 D->setInstantiatedFromMemberTemplateImpl(RTD);
1084 if (Record[Idx++])
1085 D->setMemberSpecialization();
1086 }
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001087
Douglas Gregor409448c2011-07-21 22:35:25 +00001088 RedeclarableTemplateDecl *LatestDecl
1089 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001090
1091 // This decl is a first one and the latest declaration that it points to is
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001092 // in the same AST file. However, if this actually needs to point to a
1093 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001094 // the FirstLatestDeclIDs map which tracks this kind of decls.
1095 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001096 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001097 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1098 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregor1b59e9c2011-08-25 15:28:26 +00001099 if (Decl *NewLatest = Reader.GetDecl(I->second))
1100 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001101 }
1102
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001103 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1104 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001105 }
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001106
1107 VisitTemplateDecl(D);
1108 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001109}
1110
Sebastian Redld527cc02010-08-18 23:56:48 +00001111void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001112 VisitRedeclarableTemplateDecl(D);
1113
1114 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001115 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1116 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001117 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001118 SpecIDs.push_back(0);
1119
1120 // Specializations.
1121 unsigned Size = Record[Idx++];
1122 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001123 for (unsigned I = 0; I != Size; ++I)
1124 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001125
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001126 // Partial specializations.
1127 Size = Record[Idx++];
1128 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001129 for (unsigned I = 0; I != Size; ++I)
1130 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001131
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001132 if (SpecIDs[0]) {
1133 typedef serialization::DeclID DeclID;
1134
1135 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1136 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001137 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001138 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1139 SpecIDs.size() * sizeof(DeclID));
1140 }
1141
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001142 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001143 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001144}
1145
Sebastian Redld527cc02010-08-18 23:56:48 +00001146void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001147 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001148 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001149
Douglas Gregor35942772011-09-09 21:34:22 +00001150 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001151 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001152 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001153 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001154 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001155 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001156 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001157 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001158 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1159 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001160 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1161 = new (C) ClassTemplateSpecializationDecl::
1162 SpecializedPartialSpecialization();
1163 PS->PartialSpecialization
1164 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1165 PS->TemplateArgs = ArgList;
1166 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001167 }
1168 }
1169
1170 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001171 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001172 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1173 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1174 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001175 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1176 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001177 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001178 }
1179
Chris Lattner5f9e2722011-07-23 10:55:15 +00001180 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001181 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001182 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1183 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001184 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001185 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001186
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001187 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001188 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001189 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001190 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1191 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001192 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001193 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001194 }
1195 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001196}
1197
Sebastian Redld527cc02010-08-18 23:56:48 +00001198void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001199 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001200 VisitClassTemplateSpecializationDecl(D);
1201
Douglas Gregor35942772011-09-09 21:34:22 +00001202 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001203 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001204
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001205 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001206 if (NumArgs) {
1207 D->NumArgsAsWritten = NumArgs;
1208 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1209 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001210 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001211 }
1212
1213 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001214
1215 // These are read/set from/to the first declaration.
1216 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001217 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001218 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001219 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001220 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001221}
1222
Sebastian Redl14c36332011-08-31 13:59:56 +00001223void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1224 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001225 VisitDecl(D);
1226 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1227}
1228
Sebastian Redld527cc02010-08-18 23:56:48 +00001229void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001230 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001231
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001232 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001233 // This FunctionTemplateDecl owns a CommonPtr; read it.
1234
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001235 // Read the function specialization declarations.
1236 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001237 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001238 unsigned NumSpecs = Record[Idx++];
1239 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001240 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001241 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001242}
1243
Sebastian Redld527cc02010-08-18 23:56:48 +00001244void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001245 VisitTypeDecl(D);
1246
1247 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001248
1249 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001250 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001251 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001252}
1253
Sebastian Redld527cc02010-08-18 23:56:48 +00001254void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001255 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001256 // TemplateParmPosition.
1257 D->setDepth(Record[Idx++]);
1258 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001259 if (D->isExpandedParameterPack()) {
1260 void **Data = reinterpret_cast<void **>(D + 1);
1261 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001262 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001263 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1264 }
1265 } else {
1266 // Rest of NonTypeTemplateParmDecl.
1267 D->ParameterPack = Record[Idx++];
1268 if (Record[Idx++]) {
1269 Expr *DefArg = Reader.ReadExpr(F);
1270 bool Inherited = Record[Idx++];
1271 D->setDefaultArgument(DefArg, Inherited);
1272 }
1273 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001274}
1275
Sebastian Redld527cc02010-08-18 23:56:48 +00001276void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001277 VisitTemplateDecl(D);
1278 // TemplateParmPosition.
1279 D->setDepth(Record[Idx++]);
1280 D->setPosition(Record[Idx++]);
1281 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001282 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001283 bool IsInherited = Record[Idx++];
1284 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001285 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001286}
1287
Richard Smith3e4c6c42011-05-05 21:57:07 +00001288void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1289 VisitRedeclarableTemplateDecl(D);
1290}
1291
Sebastian Redld527cc02010-08-18 23:56:48 +00001292void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001293 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001294 D->AssertExpr = Reader.ReadExpr(F);
1295 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001296 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001297}
1298
Mike Stump1eb44332009-09-09 15:08:12 +00001299std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001300ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001301 uint64_t LexicalOffset = Record[Idx++];
1302 uint64_t VisibleOffset = Record[Idx++];
1303 return std::make_pair(LexicalOffset, VisibleOffset);
1304}
1305
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001306template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001307void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001308 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1309 RedeclKind Kind = (RedeclKind)Record[Idx++];
1310 switch (Kind) {
1311 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001312 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1313 " messed up reading");
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001314 case NoRedeclaration:
1315 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001316 case PointsToPrevious: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001317 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1318 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001319 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1320 // We temporarily set the first (canonical) declaration as the previous one
1321 // which is the one that matters and mark the real previous DeclID to be
1322 // loaded & attached later on.
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001323 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001324 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1325 if (PreviousDeclID != FirstDeclID)
1326 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1327 PreviousDeclID));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001328 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001329 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001330 case PointsToLatest:
1331 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
Douglas Gregor409448c2011-07-21 22:35:25 +00001332 ReadDeclAs<T>(Record, Idx));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001333 break;
1334 }
1335
1336 assert(!(Kind == PointsToPrevious &&
1337 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1338 Reader.FirstLatestDeclIDs.end()) &&
1339 "This decl is not first, it should not be in the map");
1340 if (Kind == PointsToPrevious)
1341 return;
1342
1343 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001344 // the same AST file. However, if this actually needs to point to a
1345 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001346 // FirstLatestDeclIDs map which tracks this kind of decls.
1347 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1348 "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001349 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001350 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1351 if (I != Reader.FirstLatestDeclIDs.end()) {
1352 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001353 D->RedeclLink
1354 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1355 }
1356}
1357
Chris Lattner698f9252009-04-27 05:27:42 +00001358//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001359// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001360//===----------------------------------------------------------------------===//
1361
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001362/// \brief Reads attributes from the current stream position.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001363void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001364 const RecordData &Record, unsigned &Idx) {
1365 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001366 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001367 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001368 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001369
Sean Huntcf807c42010-08-18 23:23:40 +00001370#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001371
1372 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001373 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001374 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001375}
1376
1377//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001378// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001379//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001380
1381/// \brief Note that we have loaded the declaration with the given
1382/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001383///
Chris Lattner698f9252009-04-27 05:27:42 +00001384/// This routine notes that this declaration has already been loaded,
1385/// so that future GetDecl calls will return this declaration rather
1386/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001387inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001388 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1389 DeclsLoaded[Index] = D;
1390}
1391
1392
1393/// \brief Determine whether the consumer will be interested in seeing
1394/// this declaration (via HandleTopLevelDecl).
1395///
1396/// This routine should return true for anything that might affect
1397/// code generation, e.g., inline function definitions, Objective-C
1398/// declarations with metadata, etc.
1399static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001400 // An ObjCMethodDecl is never considered as "interesting" because its
1401 // implementation container always is.
1402
Douglas Gregor94da1582011-09-10 00:22:34 +00001403 if (isa<FileScopeAsmDecl>(D) ||
1404 isa<ObjCProtocolDecl>(D) ||
1405 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001406 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001407 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001408 return Var->isFileVarDecl() &&
1409 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001410 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001411 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001412
1413 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001414}
1415
Douglas Gregor96e973f2011-07-20 00:27:43 +00001416/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001417ASTReader::RecordLocation
Douglas Gregor496c7092011-08-03 15:48:04 +00001418ASTReader::DeclCursorForID(DeclID ID) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001419 // See if there's an override.
1420 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1421 if (It != ReplacedDecls.end())
Sebastian Redlc3632732010-10-05 15:59:54 +00001422 return RecordLocation(It->second.first, It->second.second);
Sebastian Redl0b17c612010-08-13 00:28:03 +00001423
Douglas Gregor96e973f2011-07-20 00:27:43 +00001424 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1425 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor9827a802011-07-29 00:56:45 +00001426 Module *M = I->second;
Douglas Gregorb18b1fd2011-08-03 23:28:44 +00001427 return RecordLocation(M,
1428 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001429}
1430
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001431ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001432 ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001433 = GlobalBitOffsetsMap.find(GlobalOffset);
1434
1435 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1436 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1437}
1438
Douglas Gregore92b8a12011-08-04 00:01:48 +00001439uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1440 return LocalOffset + M.GlobalBitOffset;
1441}
1442
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001443void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1444 assert(D && previous);
1445 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1446 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1447 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1448 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1449 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1450 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1451 } else {
1452 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1453 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1454 }
1455}
1456
1457void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1458 Decl *previous = GetDecl(ID);
1459 ASTDeclReader::attachPreviousDecl(D, previous);
1460}
1461
Sebastian Redld527cc02010-08-18 23:56:48 +00001462/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001463Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001464 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Douglas Gregor496c7092011-08-03 15:48:04 +00001465 RecordLocation Loc = DeclCursorForID(ID);
Sebastian Redlc3632732010-10-05 15:59:54 +00001466 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001467 // Keep track of where we are in the stream, then jump back there
1468 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001469 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001470
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001471 ReadingKindTracker ReadingKind(Read_Decl, *this);
1472
Douglas Gregord89275b2009-07-06 18:54:52 +00001473 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001474 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001475
Sebastian Redlc3632732010-10-05 15:59:54 +00001476 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001477 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001478 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001479 unsigned Idx = 0;
Sebastian Redlc3632732010-10-05 15:59:54 +00001480 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001481
Chris Lattnerda930612009-04-27 05:58:23 +00001482 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001483 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001484 case DECL_CONTEXT_LEXICAL:
1485 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001486 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001487 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001488 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001489 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001490 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001491 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001492 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001493 0, 0);
1494 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001495 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001496 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001497 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001498 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001499 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001500 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001501 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001502 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001503 0, llvm::APSInt());
1504 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001505 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001506 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001507 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001508 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001509 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001510 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001511 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001512 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001513 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001514 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001515 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001516 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001517 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001518 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001519 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001520 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001521 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001522 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001523 SourceLocation(), 0,
1524 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001525 SourceLocation(), 0);
1526 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001527 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001528 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001529 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1530 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001531 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001532 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001533 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001534 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001535 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001536 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001537 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001538 SourceLocation(), 0, 0);
1539 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001540 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001541 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001542 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001543 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001544 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001545 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001546 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001547 SourceLocation(),
1548 NestedNameSpecifierLoc(),
1549 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001550 DeclarationName());
1551 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001552 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001553 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001554 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001555 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001556 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001557 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001558 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001559 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001560 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001561 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001562 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001563 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001564 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001565 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001566 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001567 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001568 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001569 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001570 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001571 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001572 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001573 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001574 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001575 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001576 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001577 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001578 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001579 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001580 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001581 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001582 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001583 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001584 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001585 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001586 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001587 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001588 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001589 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001590 Decl::EmptyShell());
1591 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001592 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001593 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001594 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001595 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001596 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001597 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001598 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001599 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001600 SourceLocation(), 0, 0, 0, QualType(),
1601 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001602 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001603 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001604 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001605 SourceLocation(), 0, 0, 0, QualType(),
1606 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001607 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001608 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001609 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001610 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001611 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001612 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001613 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001614 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001615 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001616 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001617 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001618 break;
1619
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001620 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001621 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001622 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001623 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001624 case DECL_OBJC_INTERFACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001625 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001626 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001627 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001628 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001629 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001630 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001631 case DECL_OBJC_PROTOCOL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001632 D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
1633 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001634 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001635 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001636 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001637 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001638 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001639 case DECL_OBJC_CLASS:
Douglas Gregor35942772011-09-09 21:34:22 +00001640 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001641 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001642 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001643 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001644 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001645 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001646 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001647 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001648 case DECL_OBJC_CATEGORY_IMPL:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001649 D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1650 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001651 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001652 case DECL_OBJC_IMPLEMENTATION:
Argyrios Kyrtzidis1711fc92011-10-04 04:48:02 +00001653 D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1654 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001655 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001656 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001657 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001658 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001659 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001660 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001661 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001662 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001663 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001664 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001665 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001666 ObjCPropertyImplDecl::Dynamic, 0,
1667 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001668 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001669 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001670 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001671 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001672 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001673 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001674 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001675 0, 0);
1676 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001677 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001678 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001679 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001680 break;
1681
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001682 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00001683 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001684 break;
1685
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001686 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001687 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001688 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001689 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001690 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00001691 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00001692 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001693 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001694 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00001695 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001696 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00001697 case DECL_CXX_BASE_SPECIFIERS:
1698 Error("attempt to read a C++ base-specifier record as a declaration");
1699 return 0;
Chris Lattner698f9252009-04-27 05:27:42 +00001700 }
Chris Lattner698f9252009-04-27 05:27:42 +00001701
Sebastian Redld527cc02010-08-18 23:56:48 +00001702 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001703 LoadedDecl(Index, D);
1704 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001705
1706 // If this declaration is also a declaration context, get the
1707 // offsets for its tables of lexical and visible declarations.
1708 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1709 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1710 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001711 if (Offsets.first != 0)
1712 DC->setHasExternalLexicalStorage(true);
1713 if (Offsets.second != 0)
1714 DC->setHasExternalVisibleStorage(true);
1715 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1716 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00001717 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001718 }
Sebastian Redle1dde812010-08-24 00:50:04 +00001719
Sebastian Redl024e1c42011-04-24 16:27:54 +00001720 // Now add the pending visible updates for this decl context, if it has any.
1721 DeclContextVisibleUpdatesPending::iterator I =
1722 PendingVisibleUpdates.find(ID);
1723 if (I != PendingVisibleUpdates.end()) {
1724 // There are updates. This means the context has external visible
1725 // storage, even if the original stored version didn't.
1726 DC->setHasExternalVisibleStorage(true);
1727 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001728 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1729 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001730 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00001731 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00001732 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00001733 }
1734 }
1735 assert(Idx == Record.size());
1736
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001737 // Load any relevant update records.
1738 loadDeclUpdateRecords(ID, D);
1739
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001740 if (ObjCChainedCategoriesInterfaces.count(ID))
1741 loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1742
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001743 // If we have deserialized a declaration that has a definition the
1744 // AST consumer might need to know about, queue it.
1745 // We don't pass it to the consumer immediately because we may be in recursive
1746 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001747 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00001748 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00001749
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001750 return D;
1751}
1752
1753void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001754 // The declaration may have been modified by files later in the chain.
1755 // If this is the case, read the record containing the updates from each file
1756 // and pass it to ASTDeclReader to make the modifications.
1757 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1758 if (UpdI != DeclUpdateOffsets.end()) {
1759 FileOffsetsTy &UpdateOffsets = UpdI->second;
1760 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001761 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001762 Module *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001763 uint64_t Offset = I->second;
1764 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1765 SavedStreamPosition SavedPosition(Cursor);
1766 Cursor.JumpToBit(Offset);
1767 RecordData Record;
1768 unsigned Code = Cursor.ReadCode();
1769 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1770 (void)RecCode;
1771 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001772
1773 unsigned Idx = 0;
1774 ASTDeclReader Reader(*this, *F, Cursor, ID, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00001775 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001776 }
1777 }
Chris Lattner698f9252009-04-27 05:27:42 +00001778}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001779
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001780namespace {
1781 /// \brief Given an ObjC interface, goes through the modules and links to the
1782 /// interface all the categories for it.
1783 class ObjCChainedCategoriesVisitor {
1784 ASTReader &Reader;
1785 serialization::GlobalDeclID InterfaceID;
1786 ObjCInterfaceDecl *Interface;
1787 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1788 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1789
1790 public:
1791 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1792 serialization::GlobalDeclID InterfaceID,
1793 ObjCInterfaceDecl *Interface)
1794 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1795 GlobHeadCat(0), GlobTailCat(0) { }
1796
1797 static bool visit(Module &M, void *UserData) {
1798 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1799 }
1800
1801 bool visit(Module &M) {
1802 if (Reader.isDeclIDFromModule(InterfaceID, M))
1803 return true; // We reached the module where the interface originated
1804 // from. Stop traversing the imported modules.
1805
1806 Module::ChainedObjCCategoriesMap::iterator
1807 I = M.ChainedObjCCategories.find(InterfaceID);
1808 if (I == M.ChainedObjCCategories.end())
1809 return false;
1810
1811 ObjCCategoryDecl *
1812 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1813 ObjCCategoryDecl *
1814 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1815
1816 addCategories(HeadCat, TailCat);
1817 return false;
1818 }
1819
1820 void addCategories(ObjCCategoryDecl *HeadCat,
1821 ObjCCategoryDecl *TailCat = 0) {
1822 if (!HeadCat) {
1823 assert(!TailCat);
1824 return;
1825 }
1826
1827 if (!TailCat) {
1828 TailCat = HeadCat;
1829 while (TailCat->getNextClassCategory())
1830 TailCat = TailCat->getNextClassCategory();
1831 }
1832
1833 if (!GlobHeadCat) {
1834 GlobHeadCat = HeadCat;
1835 GlobTailCat = TailCat;
1836 } else {
1837 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1838 GlobTailCat = TailCat;
1839 }
1840
1841 llvm::DenseSet<DeclarationName> Checked;
1842 for (ObjCCategoryDecl *Cat = HeadCat,
1843 *CatEnd = TailCat->getNextClassCategory();
1844 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1845 if (Checked.count(Cat->getDeclName()))
1846 continue;
1847 Checked.insert(Cat->getDeclName());
1848 checkForDuplicate(Cat);
1849 }
1850 }
1851
1852 /// \brief Warns for duplicate categories that come from different modules.
1853 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1854 DeclarationName Name = Cat->getDeclName();
1855 // Find the top category with the same name. We do not want to warn for
1856 // duplicates along the established chain because there were already
1857 // warnings for them when the module was created. We only want to warn for
1858 // duplicates between non-dependent modules:
1859 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001860 // MT //
1861 // / \ //
1862 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001863 //
1864 // We want to warn for duplicates between ML and MR,not between ML and MT.
1865 //
1866 // FIXME: We should not warn for duplicates in diamond:
1867 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001868 // MT //
1869 // / \ //
1870 // ML MR //
1871 // \ / //
1872 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001873 //
1874 // If there are duplicates in ML/MR, there will be warning when creating
1875 // MB *and* when importing MB. We should not warn when importing.
1876 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1877 Next = Next->getNextClassCategory()) {
1878 if (Next->getDeclName() == Name)
1879 Cat = Next;
1880 }
1881
1882 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1883 if (!PrevCat)
1884 PrevCat = Cat;
1885
1886 if (PrevCat != Cat) {
1887 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1888 << Interface->getDeclName() << Name;
1889 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1890 }
1891 }
1892
1893 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1894 };
1895}
1896
1897void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1898 ObjCInterfaceDecl *D) {
1899 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1900 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1901 // Also add the categories that the interface already links to.
1902 Visitor.addCategories(D->getCategoryList());
1903 D->setCategoryList(Visitor.getHeadCategory());
1904}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001905
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001906void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +00001907 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001908 unsigned Idx = 0;
1909 while (Idx < Record.size()) {
1910 switch ((DeclUpdateKind)Record[Idx++]) {
1911 case UPD_CXX_SET_DEFINITIONDATA: {
1912 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00001913 CXXRecordDecl *DefinitionDecl
1914 = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001915 assert(!RD->DefinitionData && "DefinitionData is already set!");
1916 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1917 break;
1918 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001919
1920 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor496c7092011-08-03 15:48:04 +00001921 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001922 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00001923
1924 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1925 // It will be added to the template's specializations set when loaded.
Douglas Gregor496c7092011-08-03 15:48:04 +00001926 (void)Reader.ReadDecl(Module, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001927 break;
1928
1929 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00001930 NamespaceDecl *Anon
1931 = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00001932 // Guard against these being loaded out of original order. Don't use
1933 // getNextNamespace(), since it tries to access the context and can't in
1934 // the middle of deserialization.
1935 if (!Anon->NextNamespace) {
1936 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1937 TU->setAnonymousNamespace(Anon);
1938 else
1939 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1940 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001941 break;
1942 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00001943
1944 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1945 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1946 Reader.ReadSourceLocation(Module, Record, Idx));
1947 break;
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001948 }
1949 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001950}