blob: 32d88407195a932ba0e2b1a34a967abfd82f49ef [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++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000287 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000288 if (Record[Idx++]) { // hasExtInfo
Douglas Gregor35942772011-09-09 21:34:22 +0000289 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000290 ReadQualifierInfo(*Info, Record, Idx);
Richard Smith162e1c12011-04-15 14:24:37 +0000291 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000292 } else
Douglas Gregor409448c2011-07-21 22:35:25 +0000293 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000294}
295
Sebastian Redld527cc02010-08-18 23:56:48 +0000296void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000297 VisitTagDecl(ED);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000298 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
299 ED->setIntegerTypeSourceInfo(TI);
300 else
Douglas Gregor393f2492011-07-22 00:38:23 +0000301 ED->setIntegerType(Reader.readType(F, Record, Idx));
302 ED->setPromotionType(Reader.readType(F, Record, Idx));
John McCall1b5a6182010-05-06 08:49:23 +0000303 ED->setNumPositiveBits(Record[Idx++]);
304 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000305 ED->IsScoped = Record[Idx++];
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000306 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor1274ccd2010-10-08 23:50:27 +0000307 ED->IsFixed = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000308 ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000309}
310
Sebastian Redld527cc02010-08-18 23:56:48 +0000311void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000312 VisitTagDecl(RD);
313 RD->setHasFlexibleArrayMember(Record[Idx++]);
314 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000315 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000316}
317
Sebastian Redld527cc02010-08-18 23:56:48 +0000318void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000319 VisitNamedDecl(VD);
Douglas Gregor393f2492011-07-22 00:38:23 +0000320 VD->setType(Reader.readType(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000321}
322
Sebastian Redld527cc02010-08-18 23:56:48 +0000323void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000324 VisitValueDecl(ECD);
325 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000326 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000327 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
328}
329
Sebastian Redld527cc02010-08-18 23:56:48 +0000330void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000331 VisitValueDecl(DD);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000332 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000333 if (Record[Idx++]) { // hasExtInfo
334 DeclaratorDecl::ExtInfo *Info
Douglas Gregor35942772011-09-09 21:34:22 +0000335 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000336 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000337 DD->DeclInfo = Info;
Jonathan D. Turner953c5642011-06-03 23:11:16 +0000338 }
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000339}
340
Sebastian Redld527cc02010-08-18 23:56:48 +0000341void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000342 VisitDeclaratorDecl(FD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000343 VisitRedeclarable(FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000344
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000345 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000346 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000347 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000348 default: llvm_unreachable("Unhandled TemplatedKind!");
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000349 case FunctionDecl::TK_NonTemplate:
350 break;
351 case FunctionDecl::TK_FunctionTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000352 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
353 Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000354 break;
355 case FunctionDecl::TK_MemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000356 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000357 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000358 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000359 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000360 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
361 break;
362 }
363 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000364 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
365 Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000366 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
367
368 // Template arguments.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000369 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +0000370 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000371
372 // Template args as written.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000373 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000374 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000375 bool HasTemplateArgumentsAsWritten = Record[Idx++];
376 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000377 unsigned NumTemplateArgLocs = Record[Idx++];
378 TemplArgLocs.reserve(NumTemplateArgLocs);
379 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000380 TemplArgLocs.push_back(
Sebastian Redlc3632732010-10-05 15:59:54 +0000381 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000382
Sebastian Redlc3632732010-10-05 15:59:54 +0000383 LAngleLoc = ReadSourceLocation(Record, Idx);
384 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000385 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000386
Sebastian Redlc3632732010-10-05 15:59:54 +0000387 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000388
Douglas Gregor35942772011-09-09 21:34:22 +0000389 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000390 TemplateArgumentList *TemplArgList
Douglas Gregor910f8002010-11-07 23:05:16 +0000391 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000392 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000393 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000394 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000395 FunctionTemplateSpecializationInfo *FTInfo
396 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
397 TemplArgList,
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000398 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
399 POI);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000400 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000401
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000402 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000403 // The template that contains the specializations set. It's not safe to
404 // use getCanonicalDecl on Template since it may still be initializing.
405 FunctionTemplateDecl *CanonTemplate
Douglas Gregor409448c2011-07-21 22:35:25 +0000406 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000407 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
408 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
409 // FunctionTemplateSpecializationInfo's Profile().
410 // We avoid getASTContext because a decl in the parent hierarchy may
411 // be initializing.
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000412 llvm::FoldingSetNodeID ID;
413 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
414 TemplArgs.size(), C);
415 void *InsertPos = 0;
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000416 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidisa626a3d2010-09-09 11:28:23 +0000417 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +0000418 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000419 }
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000420 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000421 }
422 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
423 // Templates.
424 UnresolvedSet<8> TemplDecls;
425 unsigned NumTemplates = Record[Idx++];
426 while (NumTemplates--)
Douglas Gregor409448c2011-07-21 22:35:25 +0000427 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000428
429 // Templates args.
430 TemplateArgumentListInfo TemplArgs;
431 unsigned NumArgs = Record[Idx++];
432 while (NumArgs--)
Sebastian Redlc3632732010-10-05 15:59:54 +0000433 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
434 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
435 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000436
Douglas Gregor35942772011-09-09 21:34:22 +0000437 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000438 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000439 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000440 }
441 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000442
Sebastian Redld527cc02010-08-18 23:56:48 +0000443 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000444 // after everything else is read.
445
Douglas Gregor381d34e2010-12-06 18:36:25 +0000446 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000447 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregor8f150942010-12-09 16:59:22 +0000448 FD->IsInline = Record[Idx++];
449 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000450 FD->IsVirtualAsWritten = Record[Idx++];
451 FD->IsPure = Record[Idx++];
452 FD->HasInheritedPrototype = Record[Idx++];
453 FD->HasWrittenPrototype = Record[Idx++];
454 FD->IsDeleted = Record[Idx++];
455 FD->IsTrivial = Record[Idx++];
Sean Hunt2be7e902011-05-12 22:46:29 +0000456 FD->IsDefaulted = Record[Idx++];
457 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000458 FD->HasImplicitReturnZero = Record[Idx++];
Richard Smithaf1fc7a2011-08-15 21:04:07 +0000459 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis20df8e72011-01-03 17:57:40 +0000460 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000461
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000462 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000463 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000464 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000465 Params.reserve(NumParams);
466 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000467 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000468 FD->setParams(Reader.getContext(), Params);
Chris Lattner698f9252009-04-27 05:27:42 +0000469}
470
Sebastian Redld527cc02010-08-18 23:56:48 +0000471void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000472 VisitNamedDecl(MD);
473 if (Record[Idx++]) {
474 // In practice, this won't be executed (since method definitions
475 // don't occur in header files).
Sebastian Redlc3632732010-10-05 15:59:54 +0000476 MD->setBody(Reader.ReadStmt(F));
Douglas Gregor409448c2011-07-21 22:35:25 +0000477 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
478 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000479 }
480 MD->setInstanceMethod(Record[Idx++]);
481 MD->setVariadic(Record[Idx++]);
482 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000483 MD->setDefined(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000484 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
485 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor926df6c2011-06-11 01:09:30 +0000486 MD->SetRelatedResultType(Record[Idx++]);
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000487 MD->setNumSelectorArgs(unsigned(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));
Douglas Gregor35942772011-09-09 21:34:22 +0000496 MD->setMethodParams(Reader.getContext(), Params.data(), NumParams,
Fariborz Jahanian4ecb25f2010-04-09 15:40:42 +0000497 NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000498}
499
Sebastian Redld527cc02010-08-18 23:56:48 +0000500void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000501 VisitNamedDecl(CD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000502 SourceLocation A = ReadSourceLocation(Record, Idx);
503 SourceLocation B = ReadSourceLocation(Record, Idx);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000504 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000505}
506
Sebastian Redld527cc02010-08-18 23:56:48 +0000507void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner698f9252009-04-27 05:27:42 +0000508 VisitObjCContainerDecl(ID);
Douglas Gregor393f2492011-07-22 00:38:23 +0000509 ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
Douglas Gregor409448c2011-07-21 22:35:25 +0000510 ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000511
512 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner698f9252009-04-27 05:27:42 +0000513 unsigned NumProtocols = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000514 SmallVector<ObjCProtocolDecl *, 16> Protocols;
Chris Lattner698f9252009-04-27 05:27:42 +0000515 Protocols.reserve(NumProtocols);
516 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000517 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000518 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000519 ProtoLocs.reserve(NumProtocols);
520 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000521 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000522 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000523 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000524
525 // Read the transitive closure of protocols referenced by this class.
526 NumProtocols = Record[Idx++];
527 Protocols.clear();
528 Protocols.reserve(NumProtocols);
529 for (unsigned I = 0; I != NumProtocols; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000530 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Ted Kremenek53b94412010-09-01 01:21:15 +0000531 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
Douglas Gregor35942772011-09-09 21:34:22 +0000532 Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000533
534 // Read the ivars.
Chris Lattner698f9252009-04-27 05:27:42 +0000535 unsigned NumIvars = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000536 SmallVector<ObjCIvarDecl *, 16> IVars;
Chris Lattner698f9252009-04-27 05:27:42 +0000537 IVars.reserve(NumIvars);
538 for (unsigned I = 0; I != NumIvars; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000539 IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
540 ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
541
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000542 // We will rebuild this list lazily.
543 ID->setIvarList(0);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000544 ID->setForwardDecl(Record[Idx++]);
545 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000546 ID->setClassLoc(ReadSourceLocation(Record, Idx));
547 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
548 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000549}
550
Sebastian Redld527cc02010-08-18 23:56:48 +0000551void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000552 VisitFieldDecl(IVD);
553 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000554 // This field will be built lazily.
555 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000556 bool synth = Record[Idx++];
557 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000558}
559
Sebastian Redld527cc02010-08-18 23:56:48 +0000560void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000561 VisitObjCContainerDecl(PD);
562 PD->setForwardDecl(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000563 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000564 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000565 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000566 ProtoRefs.reserve(NumProtoRefs);
567 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000568 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000569 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000570 ProtoLocs.reserve(NumProtoRefs);
571 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000572 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000573 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000574 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000575}
576
Sebastian Redld527cc02010-08-18 23:56:48 +0000577void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000578 VisitFieldDecl(FD);
579}
580
Sebastian Redld527cc02010-08-18 23:56:48 +0000581void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000582 VisitDecl(CD);
Fariborz Jahanian95ed7782011-08-27 20:50:59 +0000583 ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
584 SourceLocation SLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000585 CD->setClass(Reader.getContext(), ClassRef, SLoc);
Chris Lattner698f9252009-04-27 05:27:42 +0000586}
587
Sebastian Redld527cc02010-08-18 23:56:48 +0000588void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000589 VisitDecl(FPD);
590 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000591 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000592 ProtoRefs.reserve(NumProtoRefs);
593 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000594 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000595 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000596 ProtoLocs.reserve(NumProtoRefs);
597 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000598 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000599 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000600 Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000601}
602
Sebastian Redld527cc02010-08-18 23:56:48 +0000603void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000604 VisitObjCContainerDecl(CD);
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000605 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000606 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000607 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner698f9252009-04-27 05:27:42 +0000608 ProtoRefs.reserve(NumProtoRefs);
609 for (unsigned I = 0; I != NumProtoRefs; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000610 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
Chris Lattner5f9e2722011-07-23 10:55:15 +0000611 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000612 ProtoLocs.reserve(NumProtoRefs);
613 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redlc3632732010-10-05 15:59:54 +0000614 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000615 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor35942772011-09-09 21:34:22 +0000616 Reader.getContext());
Argyrios Kyrtzidis955fadb2011-08-30 19:43:26 +0000617 CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000618 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redlc3632732010-10-05 15:59:54 +0000619 CD->setAtLoc(ReadSourceLocation(Record, Idx));
620 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000621}
622
Sebastian Redld527cc02010-08-18 23:56:48 +0000623void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000624 VisitNamedDecl(CAD);
Douglas Gregor409448c2011-07-21 22:35:25 +0000625 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000626}
627
Sebastian Redld527cc02010-08-18 23:56:48 +0000628void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000629 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000630 D->setAtLoc(ReadSourceLocation(Record, Idx));
631 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000632 // FIXME: stable encoding
633 D->setPropertyAttributes(
634 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000635 D->setPropertyAttributesAsWritten(
636 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000637 // FIXME: stable encoding
638 D->setPropertyImplementation(
639 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
Douglas Gregor393f2492011-07-22 00:38:23 +0000640 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
641 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
Douglas Gregor409448c2011-07-21 22:35:25 +0000642 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
643 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
644 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000645}
646
Sebastian Redld527cc02010-08-18 23:56:48 +0000647void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000648 VisitObjCContainerDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000649 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000650}
651
Sebastian Redld527cc02010-08-18 23:56:48 +0000652void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000653 VisitObjCImplDecl(D);
Douglas Gregor95eab172011-07-28 20:55:49 +0000654 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000655}
656
Sebastian Redld527cc02010-08-18 23:56:48 +0000657void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000658 VisitObjCImplDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000659 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000660 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Sean Huntcbb67482011-01-08 20:30:50 +0000661 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000662 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000663}
664
665
Sebastian Redld527cc02010-08-18 23:56:48 +0000666void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000667 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000668 D->setAtLoc(ReadSourceLocation(Record, Idx));
Douglas Gregor409448c2011-07-21 22:35:25 +0000669 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
670 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
Douglas Gregora4ffd852010-11-17 01:03:52 +0000671 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000672 D->setGetterCXXConstructor(Reader.ReadExpr(F));
673 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000674}
675
Sebastian Redld527cc02010-08-18 23:56:48 +0000676void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000677 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000678 FD->setMutable(Record[Idx++]);
Richard Smith7a614d82011-06-11 17:19:42 +0000679 int BitWidthOrInitializer = Record[Idx++];
680 if (BitWidthOrInitializer == 1)
Sebastian Redlc3632732010-10-05 15:59:54 +0000681 FD->setBitWidth(Reader.ReadExpr(F));
Richard Smith7a614d82011-06-11 17:19:42 +0000682 else if (BitWidthOrInitializer == 2)
683 FD->setInClassInitializer(Reader.ReadExpr(F));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000684 if (!FD->getDeclName()) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000685 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000686 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000687 }
Chris Lattner698f9252009-04-27 05:27:42 +0000688}
689
Francois Pichet87c2e122010-11-21 06:08:52 +0000690void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
691 VisitValueDecl(FD);
692
693 FD->ChainingSize = Record[Idx++];
694 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor35942772011-09-09 21:34:22 +0000695 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet87c2e122010-11-21 06:08:52 +0000696
697 for (unsigned I = 0; I != FD->ChainingSize; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000698 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
Francois Pichet87c2e122010-11-21 06:08:52 +0000699}
700
Sebastian Redld527cc02010-08-18 23:56:48 +0000701void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000702 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000703 VisitRedeclarable(VD);
John McCallf1e4fbf2011-05-01 02:13:58 +0000704 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
705 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
706 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
707 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
708 VD->VarDeclBits.ExceptionVar = Record[Idx++];
709 VD->VarDeclBits.NRVOVariable = Record[Idx++];
710 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
John McCall7acddac2011-06-17 06:42:21 +0000711 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000712 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +0000713 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000714
715 if (Record[Idx++]) { // HasMemberSpecializationInfo.
Douglas Gregor409448c2011-07-21 22:35:25 +0000716 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000717 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000718 SourceLocation POI = ReadSourceLocation(Record, Idx);
Douglas Gregor35942772011-09-09 21:34:22 +0000719 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000720 }
Chris Lattner698f9252009-04-27 05:27:42 +0000721}
722
Sebastian Redld527cc02010-08-18 23:56:48 +0000723void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000724 VisitVarDecl(PD);
725}
726
Sebastian Redld527cc02010-08-18 23:56:48 +0000727void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000728 VisitVarDecl(PD);
John McCall70798862011-05-02 00:30:12 +0000729 unsigned isObjCMethodParam = Record[Idx++];
730 unsigned scopeDepth = Record[Idx++];
731 unsigned scopeIndex = Record[Idx++];
732 unsigned declQualifier = Record[Idx++];
733 if (isObjCMethodParam) {
734 assert(scopeDepth == 0);
735 PD->setObjCMethodScopeInfo(scopeIndex);
736 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
737 } else {
738 PD->setScopeInfo(scopeDepth, scopeIndex);
739 }
John McCallf1e4fbf2011-05-01 02:13:58 +0000740 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
741 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000742 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc3632732010-10-05 15:59:54 +0000743 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner698f9252009-04-27 05:27:42 +0000744}
745
Sebastian Redld527cc02010-08-18 23:56:48 +0000746void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000747 VisitDecl(AD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000748 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara21e006e2011-03-03 14:20:18 +0000749 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000750}
751
Sebastian Redld527cc02010-08-18 23:56:48 +0000752void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000753 VisitDecl(BD);
Sebastian Redlc3632732010-10-05 15:59:54 +0000754 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
755 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000756 unsigned NumParams = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000757 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner698f9252009-04-27 05:27:42 +0000758 Params.reserve(NumParams);
759 for (unsigned I = 0; I != NumParams; ++I)
Douglas Gregor409448c2011-07-21 22:35:25 +0000760 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
David Blaikie4278c652011-09-21 18:16:56 +0000761 BD->setParams(Params);
John McCall469a1eb2011-02-02 13:00:07 +0000762
763 bool capturesCXXThis = Record[Idx++];
John McCall6b5a61b2011-02-07 10:33:21 +0000764 unsigned numCaptures = Record[Idx++];
Chris Lattner5f9e2722011-07-23 10:55:15 +0000765 SmallVector<BlockDecl::Capture, 16> captures;
John McCall6b5a61b2011-02-07 10:33:21 +0000766 captures.reserve(numCaptures);
767 for (unsigned i = 0; i != numCaptures; ++i) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000768 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
John McCall6b5a61b2011-02-07 10:33:21 +0000769 unsigned flags = Record[Idx++];
770 bool byRef = (flags & 1);
771 bool nested = (flags & 2);
772 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
773
774 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
775 }
Douglas Gregor35942772011-09-09 21:34:22 +0000776 BD->setCaptures(Reader.getContext(), captures.begin(),
John McCall6b5a61b2011-02-07 10:33:21 +0000777 captures.end(), capturesCXXThis);
Chris Lattner698f9252009-04-27 05:27:42 +0000778}
779
Sebastian Redld527cc02010-08-18 23:56:48 +0000780void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000781 VisitDecl(D);
782 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000783 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara5f6bcbe2011-03-03 14:52:38 +0000784 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000785}
786
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000787void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
788 VisitNamedDecl(D);
Abramo Bagnara67843042011-03-05 18:21:20 +0000789 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000790}
791
792
Sebastian Redld527cc02010-08-18 23:56:48 +0000793void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000794 VisitNamedDecl(D);
Douglas Gregor0a0c3e72010-10-05 20:41:58 +0000795 D->IsInline = Record[Idx++];
Abramo Bagnaraacba90f2011-03-08 12:38:20 +0000796 D->LocStart = ReadSourceLocation(Record, Idx);
797 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor06c91932010-10-27 19:49:05 +0000798 D->NextNamespace = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000799
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000800 bool IsOriginal = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +0000801 // FIXME: Modules will likely have trouble with pointing directly at
802 // the original namespace.
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000803 D->OrigOrAnonNamespace.setInt(IsOriginal);
Douglas Gregor409448c2011-07-21 22:35:25 +0000804 D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000805}
806
Sebastian Redld527cc02010-08-18 23:56:48 +0000807void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000808 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000809 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redlc3632732010-10-05 15:59:54 +0000810 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +0000811 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000812 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000813}
814
Sebastian Redld527cc02010-08-18 23:56:48 +0000815void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000816 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000817 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000818 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000819 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000820 D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000821 D->setTypeName(Record[Idx++]);
Douglas Gregor409448c2011-07-21 22:35:25 +0000822 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000823 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000824}
825
Sebastian Redld527cc02010-08-18 23:56:48 +0000826void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000827 VisitNamedDecl(D);
Douglas Gregor409448c2011-07-21 22:35:25 +0000828 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
829 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
830 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000831 if (Pattern)
Douglas Gregor35942772011-09-09 21:34:22 +0000832 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000833}
834
Sebastian Redld527cc02010-08-18 23:56:48 +0000835void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000836 VisitNamedDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000837 D->UsingLoc = ReadSourceLocation(Record, Idx);
838 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregordb992412011-02-25 16:33:46 +0000839 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor409448c2011-07-21 22:35:25 +0000840 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
841 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000842}
843
Sebastian Redld527cc02010-08-18 23:56:48 +0000844void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000845 VisitValueDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000846 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregordc355712011-02-25 00:36:19 +0000847 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis40451072010-10-15 18:21:24 +0000848 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000849}
850
Sebastian Redld527cc02010-08-18 23:56:48 +0000851void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000852 UnresolvedUsingTypenameDecl *D) {
853 VisitTypeDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +0000854 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregordc355712011-02-25 00:36:19 +0000855 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000856}
857
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000858void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000859 struct CXXRecordDecl::DefinitionData &Data,
860 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000861 Data.UserDeclaredConstructor = Record[Idx++];
862 Data.UserDeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000863 Data.UserDeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000864 Data.UserDeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000865 Data.UserDeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000866 Data.UserDeclaredDestructor = Record[Idx++];
867 Data.Aggregate = Record[Idx++];
868 Data.PlainOldData = Record[Idx++];
869 Data.Empty = Record[Idx++];
870 Data.Polymorphic = Record[Idx++];
871 Data.Abstract = Record[Idx++];
Chandler Carruthec997dc2011-04-30 10:07:30 +0000872 Data.IsStandardLayout = Record[Idx++];
Chandler Carrutha8225442011-04-30 09:17:45 +0000873 Data.HasNoNonEmptyBases = Record[Idx++];
874 Data.HasPrivateFields = Record[Idx++];
875 Data.HasProtectedFields = Record[Idx++];
876 Data.HasPublicFields = Record[Idx++];
Douglas Gregor2bb11012011-05-13 01:05:07 +0000877 Data.HasMutableFields = Record[Idx++];
Sean Hunt023df372011-05-09 18:22:59 +0000878 Data.HasTrivialDefaultConstructor = Record[Idx++];
Richard Smith6b8bc072011-08-10 18:11:37 +0000879 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000880 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000881 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000882 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruth4d6e5a22011-04-23 23:10:33 +0000883 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000884 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruth9b6347c2011-04-24 02:49:34 +0000885 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000886 Data.ComputedVisibleConversions = Record[Idx++];
Sean Huntcdee3fe2011-05-11 22:34:38 +0000887 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000888 Data.DeclaredDefaultConstructor = Record[Idx++];
889 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000890 Data.DeclaredMoveConstructor = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000891 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor58e97972011-09-06 16:38:46 +0000892 Data.DeclaredMoveAssignment = Record[Idx++];
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000893 Data.DeclaredDestructor = Record[Idx++];
Sebastian Redl14c36332011-08-31 13:59:56 +0000894 Data.FailedImplicitMoveConstructor = Record[Idx++];
895 Data.FailedImplicitMoveAssignment = Record[Idx++];
Anders Carlssonfaa6afd2011-01-22 18:11:02 +0000896
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000897 Data.NumBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000898 if (Data.NumBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000899 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000900 Data.NumVBases = Record[Idx++];
Douglas Gregor7c789c12010-10-29 22:39:52 +0000901 if (Data.NumVBases)
Douglas Gregore92b8a12011-08-04 00:01:48 +0000902 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
Douglas Gregor7c789c12010-10-29 22:39:52 +0000903
Douglas Gregor409448c2011-07-21 22:35:25 +0000904 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
905 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000906 assert(Data.Definition && "Data.Definition should be already set!");
Douglas Gregor409448c2011-07-21 22:35:25 +0000907 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
Argyrios Kyrtzidisc01dc6f2010-10-24 17:26:27 +0000908}
909
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000910void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
911 CXXRecordDecl *DefinitionDecl,
912 const RecordData &Record,
913 unsigned &Idx) {
Douglas Gregor35942772011-09-09 21:34:22 +0000914 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000915
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000916 if (D == DefinitionDecl) {
917 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000918 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidis134db1f2010-10-24 17:26:31 +0000919 // We read the definition info. Check if there are pending forward
920 // references that need to point to this DefinitionData pointer.
921 ASTReader::PendingForwardRefsMap::iterator
922 FindI = Reader.PendingForwardRefs.find(D);
923 if (FindI != Reader.PendingForwardRefs.end()) {
924 ASTReader::ForwardRefs &Refs = FindI->second;
925 for (ASTReader::ForwardRefs::iterator
926 I = Refs.begin(), E = Refs.end(); I != E; ++I)
927 (*I)->DefinitionData = D->DefinitionData;
928#ifndef NDEBUG
929 // We later check whether PendingForwardRefs is empty to make sure all
930 // pending references were linked.
931 Reader.PendingForwardRefs.erase(D);
932#endif
933 }
934 } else if (DefinitionDecl) {
935 if (DefinitionDecl->DefinitionData) {
936 D->DefinitionData = DefinitionDecl->DefinitionData;
937 } else {
938 // The definition is still initializing.
939 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
940 }
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000941 }
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000942}
943
944void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
945 VisitRecordDecl(D);
946
Douglas Gregor409448c2011-07-21 22:35:25 +0000947 CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis89eaf3a2010-10-24 17:26:40 +0000948 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
949
Douglas Gregor35942772011-09-09 21:34:22 +0000950 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000951
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000952 enum CXXRecKind {
953 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
954 };
955 switch ((CXXRecKind)Record[Idx++]) {
956 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000957 llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000958 case CXXRecNotTemplate:
959 break;
960 case CXXRecTemplate:
Douglas Gregor409448c2011-07-21 22:35:25 +0000961 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000962 break;
963 case CXXRecMemberSpecialization: {
Douglas Gregor409448c2011-07-21 22:35:25 +0000964 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000965 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +0000966 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis8b996b82010-09-13 11:45:25 +0000967 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
968 MSI->setPointOfInstantiation(POI);
969 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000970 break;
971 }
972 }
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000973
974 // Load the key function to avoid deserializing every method so we can
975 // compute it.
976 if (D->IsDefinition) {
Douglas Gregor409448c2011-07-21 22:35:25 +0000977 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Argyrios Kyrtzidis36d2fd42010-10-14 20:14:38 +0000978 C.KeyFunctions[D] = Key;
979 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000980}
981
Sebastian Redld527cc02010-08-18 23:56:48 +0000982void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000983 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000984 unsigned NumOverridenMethods = Record[Idx++];
985 while (NumOverridenMethods--) {
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000986 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
987 // MD may be initializing.
Douglas Gregor409448c2011-07-21 22:35:25 +0000988 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
Douglas Gregor35942772011-09-09 21:34:22 +0000989 Reader.getContext().addOverriddenMethod(D, MD);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000990 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000991}
992
Sebastian Redld527cc02010-08-18 23:56:48 +0000993void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000994 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000995
996 D->IsExplicitSpecified = Record[Idx++];
997 D->ImplicitlyDefined = Record[Idx++];
Sean Huntcbb67482011-01-08 20:30:50 +0000998 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
999 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001000}
1001
Sebastian Redld527cc02010-08-18 23:56:48 +00001002void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001003 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001004
1005 D->ImplicitlyDefined = Record[Idx++];
Douglas Gregor409448c2011-07-21 22:35:25 +00001006 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001007}
1008
Sebastian Redld527cc02010-08-18 23:56:48 +00001009void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001010 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +00001011 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001012}
1013
Sebastian Redld527cc02010-08-18 23:56:48 +00001014void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +00001015 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001016 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara6206d532010-06-05 05:09:32 +00001017}
1018
Sebastian Redld527cc02010-08-18 23:56:48 +00001019void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +00001020 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001021 if (Record[Idx++])
Sebastian Redlc3632732010-10-05 15:59:54 +00001022 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001023 else
Douglas Gregor409448c2011-07-21 22:35:25 +00001024 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Douglas Gregor69aecc62010-10-27 20:23:41 +00001025 D->NextFriend = Record[Idx++];
John McCall6102ca12010-10-16 06:59:13 +00001026 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redlc3632732010-10-05 15:59:54 +00001027 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001028}
1029
Sebastian Redld527cc02010-08-18 23:56:48 +00001030void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001031 VisitDecl(D);
1032 unsigned NumParams = Record[Idx++];
1033 D->NumParams = NumParams;
1034 D->Params = new TemplateParameterList*[NumParams];
1035 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001036 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001037 if (Record[Idx++]) // HasFriendDecl
Douglas Gregor409448c2011-07-21 22:35:25 +00001038 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001039 else
Sebastian Redlc3632732010-10-05 15:59:54 +00001040 D->Friend = GetTypeSourceInfo(Record, Idx);
1041 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001042}
1043
Sebastian Redld527cc02010-08-18 23:56:48 +00001044void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001045 VisitNamedDecl(D);
1046
Douglas Gregor409448c2011-07-21 22:35:25 +00001047 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001048 TemplateParameterList* TemplateParams
Sebastian Redlc3632732010-10-05 15:59:54 +00001049 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001050 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001051}
1052
Sebastian Redld527cc02010-08-18 23:56:48 +00001053void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001054 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1055 // can be used while this is still initializing.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001056
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001057 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Douglas Gregor409448c2011-07-21 22:35:25 +00001058 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1059 DeclID FirstDeclID = PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001060 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1061 // We temporarily set the first (canonical) declaration as the previous one
1062 // which is the one that matters and mark the real previous DeclID to be
1063 // loaded & attached later on.
1064 RedeclarableTemplateDecl *FirstDecl =
1065 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1066 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1067 "FirstDecl kind mismatch");
1068 if (FirstDecl) {
1069 D->CommonOrPrev = FirstDecl;
1070 // Mark the real previous DeclID to be loaded & attached later on.
1071 if (PreviousDeclID != FirstDeclID)
1072 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1073 } else {
Douglas Gregor35942772011-09-09 21:34:22 +00001074 D->CommonOrPrev = D->newCommon(Reader.getContext());
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001075 if (RedeclarableTemplateDecl *RTD
Douglas Gregor409448c2011-07-21 22:35:25 +00001076 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001077 assert(RTD->getKind() == D->getKind() &&
1078 "InstantiatedFromMemberTemplate kind mismatch");
1079 D->setInstantiatedFromMemberTemplateImpl(RTD);
1080 if (Record[Idx++])
1081 D->setMemberSpecialization();
1082 }
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001083
Douglas Gregor409448c2011-07-21 22:35:25 +00001084 RedeclarableTemplateDecl *LatestDecl
1085 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001086
1087 // This decl is a first one and the latest declaration that it points to is
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001088 // in the same AST file. However, if this actually needs to point to a
1089 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001090 // the FirstLatestDeclIDs map which tracks this kind of decls.
1091 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001092 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001093 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1094 if (I != Reader.FirstLatestDeclIDs.end()) {
Douglas Gregor1b59e9c2011-08-25 15:28:26 +00001095 if (Decl *NewLatest = Reader.GetDecl(I->second))
1096 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001097 }
1098
Peter Collingbourne8a798a72010-07-29 16:12:01 +00001099 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1100 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001101 }
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +00001102
1103 VisitTemplateDecl(D);
1104 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001105}
1106
Sebastian Redld527cc02010-08-18 23:56:48 +00001107void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001108 VisitRedeclarableTemplateDecl(D);
1109
1110 if (D->getPreviousDeclaration() == 0) {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001111 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1112 // the specializations.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001113 SmallVector<serialization::DeclID, 2> SpecIDs;
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001114 SpecIDs.push_back(0);
1115
1116 // Specializations.
1117 unsigned Size = Record[Idx++];
1118 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001119 for (unsigned I = 0; I != Size; ++I)
1120 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001121
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001122 // Partial specializations.
1123 Size = Record[Idx++];
1124 SpecIDs[0] += Size;
Douglas Gregor409448c2011-07-21 22:35:25 +00001125 for (unsigned I = 0; I != Size; ++I)
1126 SpecIDs.push_back(ReadDeclID(Record, Idx));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001127
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001128 if (SpecIDs[0]) {
1129 typedef serialization::DeclID DeclID;
1130
1131 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1132 CommonPtr->LazySpecializations
Douglas Gregor35942772011-09-09 21:34:22 +00001133 = new (Reader.getContext()) DeclID [SpecIDs.size()];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001134 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1135 SpecIDs.size() * sizeof(DeclID));
1136 }
1137
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001138 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001139 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001140}
1141
Sebastian Redld527cc02010-08-18 23:56:48 +00001142void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001143 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001144 VisitCXXRecordDecl(D);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001145
Douglas Gregor35942772011-09-09 21:34:22 +00001146 ASTContext &C = Reader.getContext();
Douglas Gregor409448c2011-07-21 22:35:25 +00001147 if (Decl *InstD = ReadDecl(Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001148 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001149 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001150 } else {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001151 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001152 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001153 TemplateArgumentList *ArgList
Douglas Gregor910f8002010-11-07 23:05:16 +00001154 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1155 TemplArgs.size());
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001156 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1157 = new (C) ClassTemplateSpecializationDecl::
1158 SpecializedPartialSpecialization();
1159 PS->PartialSpecialization
1160 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1161 PS->TemplateArgs = ArgList;
1162 D->SpecializedTemplate = PS;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001163 }
1164 }
1165
1166 // Explicit info.
Sebastian Redlc3632732010-10-05 15:59:54 +00001167 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001168 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1169 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1170 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redlc3632732010-10-05 15:59:54 +00001171 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1172 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001173 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001174 }
1175
Chris Lattner5f9e2722011-07-23 10:55:15 +00001176 SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc3632732010-10-05 15:59:54 +00001177 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor910f8002010-11-07 23:05:16 +00001178 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1179 TemplArgs.size());
Sebastian Redlc3632732010-10-05 15:59:54 +00001180 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis586c7152010-09-13 11:45:32 +00001181 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001182
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +00001183 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Douglas Gregor409448c2011-07-21 22:35:25 +00001184 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001185 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001186 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1187 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001188 } else {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +00001189 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +00001190 }
1191 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001192}
1193
Sebastian Redld527cc02010-08-18 23:56:48 +00001194void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001195 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001196 VisitClassTemplateSpecializationDecl(D);
1197
Douglas Gregor35942772011-09-09 21:34:22 +00001198 ASTContext &C = Reader.getContext();
Sebastian Redlc3632732010-10-05 15:59:54 +00001199 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001200
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001201 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001202 if (NumArgs) {
1203 D->NumArgsAsWritten = NumArgs;
1204 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1205 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redlc3632732010-10-05 15:59:54 +00001206 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001207 }
1208
1209 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001210
1211 // These are read/set from/to the first declaration.
1212 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001213 D->InstantiatedFromMember.setPointer(
Douglas Gregor409448c2011-07-21 22:35:25 +00001214 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
Argyrios Kyrtzidis8fed4b42010-09-13 11:45:41 +00001215 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001216 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001217}
1218
Sebastian Redl14c36332011-08-31 13:59:56 +00001219void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1220 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichetbc845322011-08-17 01:06:54 +00001221 VisitDecl(D);
1222 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1223}
1224
Sebastian Redld527cc02010-08-18 23:56:48 +00001225void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001226 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001227
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001228 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001229 // This FunctionTemplateDecl owns a CommonPtr; read it.
1230
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001231 // Read the function specialization declarations.
1232 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidis99a8ca02010-09-13 11:45:48 +00001233 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001234 unsigned NumSpecs = Record[Idx++];
1235 while (NumSpecs--)
Douglas Gregor409448c2011-07-21 22:35:25 +00001236 (void)ReadDecl(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001237 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001238}
1239
Sebastian Redld527cc02010-08-18 23:56:48 +00001240void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001241 VisitTypeDecl(D);
1242
1243 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001244
1245 bool Inherited = Record[Idx++];
Sebastian Redlc3632732010-10-05 15:59:54 +00001246 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001247 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001248}
1249
Sebastian Redld527cc02010-08-18 23:56:48 +00001250void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCall76a40212011-02-09 01:13:10 +00001251 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001252 // TemplateParmPosition.
1253 D->setDepth(Record[Idx++]);
1254 D->setPosition(Record[Idx++]);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001255 if (D->isExpandedParameterPack()) {
1256 void **Data = reinterpret_cast<void **>(D + 1);
1257 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Douglas Gregor393f2492011-07-22 00:38:23 +00001258 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001259 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1260 }
1261 } else {
1262 // Rest of NonTypeTemplateParmDecl.
1263 D->ParameterPack = Record[Idx++];
1264 if (Record[Idx++]) {
1265 Expr *DefArg = Reader.ReadExpr(F);
1266 bool Inherited = Record[Idx++];
1267 D->setDefaultArgument(DefArg, Inherited);
1268 }
1269 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001270}
1271
Sebastian Redld527cc02010-08-18 23:56:48 +00001272void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001273 VisitTemplateDecl(D);
1274 // TemplateParmPosition.
1275 D->setDepth(Record[Idx++]);
1276 D->setPosition(Record[Idx++]);
1277 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc3632732010-10-05 15:59:54 +00001278 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001279 bool IsInherited = Record[Idx++];
1280 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregor61c4d282011-01-05 15:48:55 +00001281 D->ParameterPack = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001282}
1283
Richard Smith3e4c6c42011-05-05 21:57:07 +00001284void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1285 VisitRedeclarableTemplateDecl(D);
1286}
1287
Sebastian Redld527cc02010-08-18 23:56:48 +00001288void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001289 VisitDecl(D);
Sebastian Redlc3632732010-10-05 15:59:54 +00001290 D->AssertExpr = Reader.ReadExpr(F);
1291 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001292 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001293}
1294
Mike Stump1eb44332009-09-09 15:08:12 +00001295std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001296ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001297 uint64_t LexicalOffset = Record[Idx++];
1298 uint64_t VisibleOffset = Record[Idx++];
1299 return std::make_pair(LexicalOffset, VisibleOffset);
1300}
1301
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001302template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001303void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001304 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1305 RedeclKind Kind = (RedeclKind)Record[Idx++];
1306 switch (Kind) {
1307 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001308 llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1309 " messed up reading");
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001310 case NoRedeclaration:
1311 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001312 case PointsToPrevious: {
Douglas Gregor409448c2011-07-21 22:35:25 +00001313 DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1314 DeclID FirstDeclID = ReadDeclID(Record, Idx);
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001315 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1316 // We temporarily set the first (canonical) declaration as the previous one
1317 // which is the one that matters and mark the real previous DeclID to be
1318 // loaded & attached later on.
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001319 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001320 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1321 if (PreviousDeclID != FirstDeclID)
1322 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1323 PreviousDeclID));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001324 break;
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001325 }
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001326 case PointsToLatest:
1327 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
Douglas Gregor409448c2011-07-21 22:35:25 +00001328 ReadDeclAs<T>(Record, Idx));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001329 break;
1330 }
1331
1332 assert(!(Kind == PointsToPrevious &&
1333 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1334 Reader.FirstLatestDeclIDs.end()) &&
1335 "This decl is not first, it should not be in the map");
1336 if (Kind == PointsToPrevious)
1337 return;
1338
1339 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001340 // the same AST file. However, if this actually needs to point to a
1341 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001342 // FirstLatestDeclIDs map which tracks this kind of decls.
1343 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1344 "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001345 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001346 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1347 if (I != Reader.FirstLatestDeclIDs.end()) {
1348 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001349 D->RedeclLink
1350 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1351 }
1352}
1353
Chris Lattner698f9252009-04-27 05:27:42 +00001354//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001355// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001356//===----------------------------------------------------------------------===//
1357
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001358/// \brief Reads attributes from the current stream position.
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001359void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
Argyrios Kyrtzidis4eb9fc02010-10-18 19:20:11 +00001360 const RecordData &Record, unsigned &Idx) {
1361 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001362 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001363 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis768d6ca2011-09-13 16:05:58 +00001364 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001365
Sean Huntcf807c42010-08-18 23:23:40 +00001366#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001367
1368 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001369 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001370 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001371}
1372
1373//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001374// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001375//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001376
1377/// \brief Note that we have loaded the declaration with the given
1378/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001379///
Chris Lattner698f9252009-04-27 05:27:42 +00001380/// This routine notes that this declaration has already been loaded,
1381/// so that future GetDecl calls will return this declaration rather
1382/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001383inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001384 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1385 DeclsLoaded[Index] = D;
1386}
1387
1388
1389/// \brief Determine whether the consumer will be interested in seeing
1390/// this declaration (via HandleTopLevelDecl).
1391///
1392/// This routine should return true for anything that might affect
1393/// code generation, e.g., inline function definitions, Objective-C
1394/// declarations with metadata, etc.
1395static bool isConsumerInterestedIn(Decl *D) {
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001396 // An ObjCMethodDecl is never considered as "interesting" because its
1397 // implementation container always is.
1398
Douglas Gregor94da1582011-09-10 00:22:34 +00001399 if (isa<FileScopeAsmDecl>(D) ||
1400 isa<ObjCProtocolDecl>(D) ||
1401 isa<ObjCImplDecl>(D))
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001402 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001403 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001404 return Var->isFileVarDecl() &&
1405 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001406 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Sean Hunt10620eb2011-05-06 20:44:56 +00001407 return Func->doesThisDeclarationHaveABody();
Douglas Gregor94da1582011-09-10 00:22:34 +00001408
1409 return false;
Chris Lattner698f9252009-04-27 05:27:42 +00001410}
1411
Douglas Gregor96e973f2011-07-20 00:27:43 +00001412/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001413ASTReader::RecordLocation
Douglas Gregor496c7092011-08-03 15:48:04 +00001414ASTReader::DeclCursorForID(DeclID ID) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001415 // See if there's an override.
1416 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1417 if (It != ReplacedDecls.end())
Sebastian Redlc3632732010-10-05 15:59:54 +00001418 return RecordLocation(It->second.first, It->second.second);
Sebastian Redl0b17c612010-08-13 00:28:03 +00001419
Douglas Gregor96e973f2011-07-20 00:27:43 +00001420 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1421 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregor9827a802011-07-29 00:56:45 +00001422 Module *M = I->second;
Douglas Gregorb18b1fd2011-08-03 23:28:44 +00001423 return RecordLocation(M,
1424 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001425}
1426
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001427ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001428 ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
Douglas Gregor8f1231b2011-07-22 06:10:01 +00001429 = GlobalBitOffsetsMap.find(GlobalOffset);
1430
1431 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1432 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1433}
1434
Douglas Gregore92b8a12011-08-04 00:01:48 +00001435uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1436 return LocalOffset + M.GlobalBitOffset;
1437}
1438
Argyrios Kyrtzidis0895d152011-02-12 07:50:47 +00001439void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1440 assert(D && previous);
1441 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1442 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1443 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1444 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1445 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1446 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1447 } else {
1448 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1449 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1450 }
1451}
1452
1453void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1454 Decl *previous = GetDecl(ID);
1455 ASTDeclReader::attachPreviousDecl(D, previous);
1456}
1457
Sebastian Redld527cc02010-08-18 23:56:48 +00001458/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregor496c7092011-08-03 15:48:04 +00001459Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001460 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Douglas Gregor496c7092011-08-03 15:48:04 +00001461 RecordLocation Loc = DeclCursorForID(ID);
Sebastian Redlc3632732010-10-05 15:59:54 +00001462 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner698f9252009-04-27 05:27:42 +00001463 // Keep track of where we are in the stream, then jump back there
1464 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001465 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001466
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001467 ReadingKindTracker ReadingKind(Read_Decl, *this);
1468
Douglas Gregord89275b2009-07-06 18:54:52 +00001469 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001470 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Sebastian Redlc3632732010-10-05 15:59:54 +00001472 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001473 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001474 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001475 unsigned Idx = 0;
Sebastian Redlc3632732010-10-05 15:59:54 +00001476 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001477
Chris Lattnerda930612009-04-27 05:58:23 +00001478 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001479 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001480 case DECL_CONTEXT_LEXICAL:
1481 case DECL_CONTEXT_VISIBLE:
David Blaikieb219cfc2011-09-23 05:06:16 +00001482 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001483 case DECL_TYPEDEF:
Douglas Gregor35942772011-09-09 21:34:22 +00001484 D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnara344577e2011-03-06 15:48:19 +00001485 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001486 break;
Richard Smith162e1c12011-04-15 14:24:37 +00001487 case DECL_TYPEALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001488 D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Richard Smith162e1c12011-04-15 14:24:37 +00001489 0, 0);
1490 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001491 case DECL_ENUM:
Douglas Gregor35942772011-09-09 21:34:22 +00001492 D = EnumDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001493 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001494 case DECL_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001495 D = RecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001496 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001497 case DECL_ENUM_CONSTANT:
Douglas Gregor35942772011-09-09 21:34:22 +00001498 D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001499 0, llvm::APSInt());
1500 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001501 case DECL_FUNCTION:
Douglas Gregor35942772011-09-09 21:34:22 +00001502 D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001503 DeclarationName(), QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001504 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001505 case DECL_LINKAGE_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001506 D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001507 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara55a96372011-03-03 16:52:29 +00001508 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001509 break;
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001510 case DECL_LABEL:
Douglas Gregor35942772011-09-09 21:34:22 +00001511 D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001512 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001513 case DECL_NAMESPACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001514 D = NamespaceDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraacba90f2011-03-08 12:38:20 +00001515 SourceLocation(), 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001516 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001517 case DECL_NAMESPACE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001518 D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
Douglas Gregor0cfaf6a2011-02-25 17:08:07 +00001519 SourceLocation(), 0,
1520 NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001521 SourceLocation(), 0);
1522 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001523 case DECL_USING:
Douglas Gregor35942772011-09-09 21:34:22 +00001524 D = UsingDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001525 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1526 false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001527 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001528 case DECL_USING_SHADOW:
Douglas Gregor35942772011-09-09 21:34:22 +00001529 D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001530 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001531 case DECL_USING_DIRECTIVE:
Douglas Gregor35942772011-09-09 21:34:22 +00001532 D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordb992412011-02-25 16:33:46 +00001533 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001534 SourceLocation(), 0, 0);
1535 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001536 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor35942772011-09-09 21:34:22 +00001537 D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001538 NestedNameSpecifierLoc(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001539 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001540 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001541 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor35942772011-09-09 21:34:22 +00001542 D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
Douglas Gregordc355712011-02-25 00:36:19 +00001543 SourceLocation(),
1544 NestedNameSpecifierLoc(),
1545 SourceLocation(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001546 DeclarationName());
1547 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001548 case DECL_CXX_RECORD:
Douglas Gregor35942772011-09-09 21:34:22 +00001549 D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001550 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001551 case DECL_CXX_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001552 D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
Douglas Gregorf5251602011-03-08 17:10:18 +00001553 DeclarationNameInfo(), QualType(), 0,
Richard Smithaf1fc7a2011-08-15 21:04:07 +00001554 false, SC_None, false, false, SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001555 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001556 case DECL_CXX_CONSTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001557 D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001558 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001559 case DECL_CXX_DESTRUCTOR:
Douglas Gregor35942772011-09-09 21:34:22 +00001560 D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001561 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001562 case DECL_CXX_CONVERSION:
Douglas Gregor35942772011-09-09 21:34:22 +00001563 D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001564 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001565 case DECL_ACCESS_SPEC:
Douglas Gregor35942772011-09-09 21:34:22 +00001566 D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
Abramo Bagnara6206d532010-06-05 05:09:32 +00001567 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001568 case DECL_FRIEND:
Douglas Gregor35942772011-09-09 21:34:22 +00001569 D = FriendDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001570 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001571 case DECL_FRIEND_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001572 D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001573 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001574 case DECL_CLASS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001575 D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001576 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001577 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001578 D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001579 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001580 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001581 D = ClassTemplatePartialSpecializationDecl::Create(Context,
Douglas Gregor9a299e02011-03-04 17:52:15 +00001582 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001583 break;
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001584 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001585 D = ClassScopeFunctionSpecializationDecl::Create(Context,
Francois Pichetaf0f4d02011-08-14 03:52:19 +00001586 Decl::EmptyShell());
1587 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001588 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001589 D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001590 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001591 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001592 D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001593 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001594 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001595 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001596 SourceLocation(), 0, 0, 0, QualType(),
1597 false, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001598 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001599 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor35942772011-09-09 21:34:22 +00001600 D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001601 SourceLocation(), 0, 0, 0, QualType(),
1602 0, 0, Record[Idx++], 0);
Douglas Gregor6952f1e2011-01-19 20:10:05 +00001603 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001604 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor35942772011-09-09 21:34:22 +00001605 D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
Douglas Gregor61c4d282011-01-05 15:48:55 +00001606 false, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001607 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +00001608 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor35942772011-09-09 21:34:22 +00001609 D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
Richard Smith3e4c6c42011-05-05 21:57:07 +00001610 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001611 case DECL_STATIC_ASSERT:
Douglas Gregor35942772011-09-09 21:34:22 +00001612 D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
Abramo Bagnaraa2026c92011-03-08 16:41:52 +00001613 SourceLocation());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001614 break;
1615
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001616 case DECL_OBJC_METHOD:
Douglas Gregor35942772011-09-09 21:34:22 +00001617 D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001618 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001619 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001620 case DECL_OBJC_INTERFACE:
Douglas Gregor35942772011-09-09 21:34:22 +00001621 D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001622 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001623 case DECL_OBJC_IVAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001624 D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001625 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001626 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001627 case DECL_OBJC_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001628 D = ObjCProtocolDecl::Create(Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001629 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001630 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001631 D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001632 SourceLocation(), 0, QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001633 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001634 case DECL_OBJC_CLASS:
Douglas Gregor35942772011-09-09 21:34:22 +00001635 D = ObjCClassDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001636 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001637 case DECL_OBJC_FORWARD_PROTOCOL:
Douglas Gregor35942772011-09-09 21:34:22 +00001638 D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001639 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001640 case DECL_OBJC_CATEGORY:
Douglas Gregor35942772011-09-09 21:34:22 +00001641 D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001642 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001643 case DECL_OBJC_CATEGORY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001644 D = ObjCCategoryImplDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001645 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001646 case DECL_OBJC_IMPLEMENTATION:
Douglas Gregor35942772011-09-09 21:34:22 +00001647 D = ObjCImplementationDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001648 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001649 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor35942772011-09-09 21:34:22 +00001650 D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001651 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001652 case DECL_OBJC_PROPERTY:
Douglas Gregor35942772011-09-09 21:34:22 +00001653 D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001654 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001655 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001656 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor35942772011-09-09 21:34:22 +00001657 D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001658 SourceLocation(), 0,
Douglas Gregora4ffd852010-11-17 01:03:52 +00001659 ObjCPropertyImplDecl::Dynamic, 0,
1660 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001661 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001662 case DECL_FIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001663 D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Richard Smith7a614d82011-06-11 17:19:42 +00001664 QualType(), 0, 0, false, false);
Chris Lattner698f9252009-04-27 05:27:42 +00001665 break;
Francois Pichet87c2e122010-11-21 06:08:52 +00001666 case DECL_INDIRECTFIELD:
Douglas Gregor35942772011-09-09 21:34:22 +00001667 D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
Francois Pichet87c2e122010-11-21 06:08:52 +00001668 0, 0);
1669 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001670 case DECL_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001671 D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001672 QualType(), 0, SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001673 break;
1674
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001675 case DECL_IMPLICIT_PARAM:
Douglas Gregor35942772011-09-09 21:34:22 +00001676 D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001677 break;
1678
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001679 case DECL_PARM_VAR:
Douglas Gregor35942772011-09-09 21:34:22 +00001680 D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001681 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001682 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001683 case DECL_FILE_SCOPE_ASM:
Douglas Gregor35942772011-09-09 21:34:22 +00001684 D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
Abramo Bagnara21e006e2011-03-03 14:20:18 +00001685 SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001686 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001687 case DECL_BLOCK:
Douglas Gregor35942772011-09-09 21:34:22 +00001688 D = BlockDecl::Create(Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001689 break;
Douglas Gregor7c789c12010-10-29 22:39:52 +00001690 case DECL_CXX_BASE_SPECIFIERS:
1691 Error("attempt to read a C++ base-specifier record as a declaration");
1692 return 0;
Chris Lattner698f9252009-04-27 05:27:42 +00001693 }
Chris Lattner698f9252009-04-27 05:27:42 +00001694
Sebastian Redld527cc02010-08-18 23:56:48 +00001695 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001696 LoadedDecl(Index, D);
1697 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001698
1699 // If this declaration is also a declaration context, get the
1700 // offsets for its tables of lexical and visible declarations.
1701 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1702 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1703 if (Offsets.first || Offsets.second) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001704 if (Offsets.first != 0)
1705 DC->setHasExternalLexicalStorage(true);
1706 if (Offsets.second != 0)
1707 DC->setHasExternalVisibleStorage(true);
1708 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1709 Loc.F->DeclContextInfos[DC]))
Sebastian Redl681d7232010-07-27 00:17:23 +00001710 return 0;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001711 }
Sebastian Redle1dde812010-08-24 00:50:04 +00001712
Sebastian Redl024e1c42011-04-24 16:27:54 +00001713 // Now add the pending visible updates for this decl context, if it has any.
1714 DeclContextVisibleUpdatesPending::iterator I =
1715 PendingVisibleUpdates.find(ID);
1716 if (I != PendingVisibleUpdates.end()) {
1717 // There are updates. This means the context has external visible
1718 // storage, even if the original stored version didn't.
1719 DC->setHasExternalVisibleStorage(true);
1720 DeclContextVisibleUpdates &U = I->second;
Sebastian Redl024e1c42011-04-24 16:27:54 +00001721 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1722 UI != UE; ++UI) {
Douglas Gregor0d95f772011-08-24 19:03:07 +00001723 UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
Sebastian Redle1dde812010-08-24 00:50:04 +00001724 }
Sebastian Redl024e1c42011-04-24 16:27:54 +00001725 PendingVisibleUpdates.erase(I);
Chris Lattner698f9252009-04-27 05:27:42 +00001726 }
1727 }
1728 assert(Idx == Record.size());
1729
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001730 // Load any relevant update records.
1731 loadDeclUpdateRecords(ID, D);
1732
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001733 if (ObjCChainedCategoriesInterfaces.count(ID))
1734 loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1735
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001736 // If we have deserialized a declaration that has a definition the
1737 // AST consumer might need to know about, queue it.
1738 // We don't pass it to the consumer immediately because we may be in recursive
1739 // loading, and some declarations may still be initializing.
Argyrios Kyrtzidis144b38a2011-09-13 21:35:00 +00001740 if (isConsumerInterestedIn(D))
Douglas Gregor94da1582011-09-10 00:22:34 +00001741 InterestingDecls.push_back(D);
Douglas Gregor94da1582011-09-10 00:22:34 +00001742
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001743 return D;
1744}
1745
1746void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001747 // The declaration may have been modified by files later in the chain.
1748 // If this is the case, read the record containing the updates from each file
1749 // and pass it to ASTDeclReader to make the modifications.
1750 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1751 if (UpdI != DeclUpdateOffsets.end()) {
1752 FileOffsetsTy &UpdateOffsets = UpdI->second;
1753 for (FileOffsetsTy::iterator
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001754 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001755 Module *F = I->first;
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001756 uint64_t Offset = I->second;
1757 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1758 SavedStreamPosition SavedPosition(Cursor);
1759 Cursor.JumpToBit(Offset);
1760 RecordData Record;
1761 unsigned Code = Cursor.ReadCode();
1762 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1763 (void)RecCode;
1764 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001765
1766 unsigned Idx = 0;
1767 ASTDeclReader Reader(*this, *F, Cursor, ID, Record, Idx);
Sebastian Redlf79a7192011-04-29 08:19:30 +00001768 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001769 }
1770 }
Chris Lattner698f9252009-04-27 05:27:42 +00001771}
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001772
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001773namespace {
1774 /// \brief Given an ObjC interface, goes through the modules and links to the
1775 /// interface all the categories for it.
1776 class ObjCChainedCategoriesVisitor {
1777 ASTReader &Reader;
1778 serialization::GlobalDeclID InterfaceID;
1779 ObjCInterfaceDecl *Interface;
1780 ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1781 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1782
1783 public:
1784 ObjCChainedCategoriesVisitor(ASTReader &Reader,
1785 serialization::GlobalDeclID InterfaceID,
1786 ObjCInterfaceDecl *Interface)
1787 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1788 GlobHeadCat(0), GlobTailCat(0) { }
1789
1790 static bool visit(Module &M, void *UserData) {
1791 return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1792 }
1793
1794 bool visit(Module &M) {
1795 if (Reader.isDeclIDFromModule(InterfaceID, M))
1796 return true; // We reached the module where the interface originated
1797 // from. Stop traversing the imported modules.
1798
1799 Module::ChainedObjCCategoriesMap::iterator
1800 I = M.ChainedObjCCategories.find(InterfaceID);
1801 if (I == M.ChainedObjCCategories.end())
1802 return false;
1803
1804 ObjCCategoryDecl *
1805 HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1806 ObjCCategoryDecl *
1807 TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1808
1809 addCategories(HeadCat, TailCat);
1810 return false;
1811 }
1812
1813 void addCategories(ObjCCategoryDecl *HeadCat,
1814 ObjCCategoryDecl *TailCat = 0) {
1815 if (!HeadCat) {
1816 assert(!TailCat);
1817 return;
1818 }
1819
1820 if (!TailCat) {
1821 TailCat = HeadCat;
1822 while (TailCat->getNextClassCategory())
1823 TailCat = TailCat->getNextClassCategory();
1824 }
1825
1826 if (!GlobHeadCat) {
1827 GlobHeadCat = HeadCat;
1828 GlobTailCat = TailCat;
1829 } else {
1830 ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1831 GlobTailCat = TailCat;
1832 }
1833
1834 llvm::DenseSet<DeclarationName> Checked;
1835 for (ObjCCategoryDecl *Cat = HeadCat,
1836 *CatEnd = TailCat->getNextClassCategory();
1837 Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1838 if (Checked.count(Cat->getDeclName()))
1839 continue;
1840 Checked.insert(Cat->getDeclName());
1841 checkForDuplicate(Cat);
1842 }
1843 }
1844
1845 /// \brief Warns for duplicate categories that come from different modules.
1846 void checkForDuplicate(ObjCCategoryDecl *Cat) {
1847 DeclarationName Name = Cat->getDeclName();
1848 // Find the top category with the same name. We do not want to warn for
1849 // duplicates along the established chain because there were already
1850 // warnings for them when the module was created. We only want to warn for
1851 // duplicates between non-dependent modules:
1852 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001853 // MT //
1854 // / \ //
1855 // ML MR //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001856 //
1857 // We want to warn for duplicates between ML and MR,not between ML and MT.
1858 //
1859 // FIXME: We should not warn for duplicates in diamond:
1860 //
Argyrios Kyrtzidisfa77cba2011-09-01 03:07:11 +00001861 // MT //
1862 // / \ //
1863 // ML MR //
1864 // \ / //
1865 // MB //
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00001866 //
1867 // If there are duplicates in ML/MR, there will be warning when creating
1868 // MB *and* when importing MB. We should not warn when importing.
1869 for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1870 Next = Next->getNextClassCategory()) {
1871 if (Next->getDeclName() == Name)
1872 Cat = Next;
1873 }
1874
1875 ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1876 if (!PrevCat)
1877 PrevCat = Cat;
1878
1879 if (PrevCat != Cat) {
1880 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1881 << Interface->getDeclName() << Name;
1882 Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1883 }
1884 }
1885
1886 ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1887 };
1888}
1889
1890void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1891 ObjCInterfaceDecl *D) {
1892 ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1893 ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1894 // Also add the categories that the interface already links to.
1895 Visitor.addCategories(D->getCategoryList());
1896 D->setCategoryList(Visitor.getHeadCategory());
1897}
Douglas Gregor6bf2b9f2011-08-12 00:15:20 +00001898
Douglas Gregor72a9ae12011-07-22 16:00:58 +00001899void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
Sebastian Redlf79a7192011-04-29 08:19:30 +00001900 const RecordData &Record) {
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001901 unsigned Idx = 0;
1902 while (Idx < Record.size()) {
1903 switch ((DeclUpdateKind)Record[Idx++]) {
1904 case UPD_CXX_SET_DEFINITIONDATA: {
1905 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
Douglas Gregor496c7092011-08-03 15:48:04 +00001906 CXXRecordDecl *DefinitionDecl
1907 = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001908 assert(!RD->DefinitionData && "DefinitionData is already set!");
1909 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1910 break;
1911 }
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001912
1913 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
Douglas Gregor496c7092011-08-03 15:48:04 +00001914 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
Argyrios Kyrtzidisb6cc0e12010-10-24 17:26:54 +00001915 break;
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +00001916
1917 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1918 // It will be added to the template's specializations set when loaded.
Douglas Gregor496c7092011-08-03 15:48:04 +00001919 (void)Reader.ReadDecl(Module, Record, Idx);
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001920 break;
1921
1922 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Douglas Gregor496c7092011-08-03 15:48:04 +00001923 NamespaceDecl *Anon
1924 = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
Sebastian Redl74b485a2011-04-24 16:28:21 +00001925 // Guard against these being loaded out of original order. Don't use
1926 // getNextNamespace(), since it tries to access the context and can't in
1927 // the middle of deserialization.
1928 if (!Anon->NextNamespace) {
1929 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1930 TU->setAnonymousNamespace(Anon);
1931 else
1932 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1933 }
Sebastian Redl7c0837f2011-04-24 16:28:13 +00001934 break;
1935 }
Sebastian Redlf79a7192011-04-29 08:19:30 +00001936
1937 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1938 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1939 Reader.ReadSourceLocation(Module, Record, Idx));
1940 break;
Argyrios Kyrtzidis565bf302010-10-24 17:26:50 +00001941 }
1942 }
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +00001943}