blob: 6e9d4d48204264e9b93e0b685b513cebe9a69ec2 [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000015#include "ASTCommon.h"
Sebastian Redlf5b13462010-08-18 23:57:17 +000016#include "clang/Serialization/ASTReader.h"
Chris Lattner487412d2009-04-27 05:27:42 +000017#include "clang/AST/ASTConsumer.h"
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/DeclVisitor.h"
20#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000021#include "clang/AST/DeclCXX.h"
22#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000023#include "clang/AST/Expr.h"
24using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000025using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000026
27//===----------------------------------------------------------------------===//
28// Declaration deserialization
29//===----------------------------------------------------------------------===//
30
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000031namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000032 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000033 ASTReader &Reader;
Sebastian Redl2c373b92010-10-05 15:59:54 +000034 ASTReader::PerFileData &F;
Sebastian Redlc67764e2010-07-22 22:43:28 +000035 llvm::BitstreamCursor &Cursor;
Sebastian Redl539c5062010-08-18 23:57:32 +000036 const DeclID ThisDeclID;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000037 typedef ASTReader::RecordData RecordData;
38 const RecordData &Record;
Chris Lattner487412d2009-04-27 05:27:42 +000039 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000040 TypeID TypeIDForTypeDecl;
Douglas Gregor250ffb12011-03-05 01:35:54 +000041
42 DeclID DeclContextIDForTemplateParmDecl;
43 DeclID LexicalDeclContextIDForTemplateParmDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000044
Sebastian Redlc67764e2010-07-22 22:43:28 +000045 uint64_t GetCurrentCursorOffset();
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000046 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000047 return Reader.ReadSourceLocation(F, R, I);
48 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000049 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000050 return Reader.ReadSourceRange(F, R, I);
51 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000052 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000053 return Reader.GetTypeSourceInfo(F, R, I);
54 }
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000055 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000056 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000057 Reader.ReadQualifierInfo(F, Info, R, I);
58 }
59 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000060 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000061 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
62 }
63 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000064 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000065 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
66 }
Sebastian Redlc67764e2010-07-22 22:43:28 +000067
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +000068 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
69 const RecordData &R, unsigned &I);
70
71 void InitializeCXXDefinitionData(CXXRecordDecl *D,
72 CXXRecordDecl *DefinitionDecl,
73 const RecordData &Record, unsigned &Idx);
Chris Lattner487412d2009-04-27 05:27:42 +000074 public:
Sebastian Redl2c373b92010-10-05 15:59:54 +000075 ASTDeclReader(ASTReader &Reader, ASTReader::PerFileData &F,
76 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000077 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +000078 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
79 Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000080
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +000081 static void attachPreviousDecl(Decl *D, Decl *previous);
82
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000083 void Visit(Decl *D);
84
Sebastian Redl2ac2c722011-04-29 08:19:30 +000085 void UpdateDecl(Decl *D, ASTReader::PerFileData &Module,
86 const RecordData &Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000087
Chris Lattner487412d2009-04-27 05:27:42 +000088 void VisitDecl(Decl *D);
89 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
90 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000091 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000092 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000093 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
94 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000095 void VisitTypeDecl(TypeDecl *TD);
96 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +000097 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000098 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000099 void VisitTagDecl(TagDecl *TD);
100 void VisitEnumDecl(EnumDecl *ED);
101 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000102 void VisitCXXRecordDecl(CXXRecordDecl *D);
103 void VisitClassTemplateSpecializationDecl(
104 ClassTemplateSpecializationDecl *D);
105 void VisitClassTemplatePartialSpecializationDecl(
106 ClassTemplatePartialSpecializationDecl *D);
107 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000108 void VisitValueDecl(ValueDecl *VD);
109 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000110 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000111 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000112 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000113 void VisitCXXMethodDecl(CXXMethodDecl *D);
114 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
115 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
116 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000117 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000118 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000119 void VisitVarDecl(VarDecl *VD);
120 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
121 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000122 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
123 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000124 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000125 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000126 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000127 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000128 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000129 void VisitUsingDecl(UsingDecl *D);
130 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000131 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000132 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000133 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000134 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000135 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
136 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000137 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000138
Chris Lattner487412d2009-04-27 05:27:42 +0000139 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000140 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000141
Alexis Hunted053252010-05-30 07:21:58 +0000142 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000143 void VisitObjCMethodDecl(ObjCMethodDecl *D);
144 void VisitObjCContainerDecl(ObjCContainerDecl *D);
145 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
146 void VisitObjCIvarDecl(ObjCIvarDecl *D);
147 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
148 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
149 void VisitObjCClassDecl(ObjCClassDecl *D);
150 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
151 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
152 void VisitObjCImplDecl(ObjCImplDecl *D);
153 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
154 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
155 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
156 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
157 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
158 };
159}
160
Sebastian Redlb3298c32010-08-18 23:56:48 +0000161uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Sebastian Redlc67764e2010-07-22 22:43:28 +0000162 uint64_t Off = 0;
163 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
Sebastian Redl2c499f62010-08-18 23:56:43 +0000164 ASTReader::PerFileData &F = *Reader.Chain[N - I - 1];
Sebastian Redlc67764e2010-07-22 22:43:28 +0000165 if (&Cursor == &F.DeclsCursor) {
166 Off += F.DeclsCursor.GetCurrentBitNo();
167 break;
168 }
169 Off += F.SizeInBits;
170 }
171 return Off;
172}
173
Sebastian Redlb3298c32010-08-18 23:56:48 +0000174void ASTDeclReader::Visit(Decl *D) {
175 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000176
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000177 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
178 if (DD->DeclInfo) {
179 DeclaratorDecl::ExtInfo *Info =
180 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
181 Info->TInfo =
182 GetTypeSourceInfo(Record, Idx);
183 }
184 else {
185 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
186 }
187 }
188
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000189 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000190 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000191 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000192 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
193 // FunctionDecl's body was written last after all other Stmts/Exprs.
194 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000195 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000196 } else if (D->isTemplateParameter()) {
197 // If we have a fully initialized template parameter, we can now
198 // set its DeclContext.
199 D->setDeclContext(
200 cast_or_null<DeclContext>(
201 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
202 D->setLexicalDeclContext(
203 cast_or_null<DeclContext>(
204 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000205 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000206}
207
Sebastian Redlb3298c32010-08-18 23:56:48 +0000208void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000209 if (D->isTemplateParameter()) {
210 // We don't want to deserialize the DeclContext of a template
211 // parameter immediately, because the template parameter might be
212 // used in the formulation of its DeclContext. Use the translation
213 // unit DeclContext as a placeholder.
214 DeclContextIDForTemplateParmDecl = Record[Idx++];
215 LexicalDeclContextIDForTemplateParmDecl = Record[Idx++];
216 D->setDeclContext(Reader.getContext()->getTranslationUnitDecl());
217 } else {
218 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
219 D->setLexicalDeclContext(
Chris Lattner487412d2009-04-27 05:27:42 +0000220 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000221 }
Sebastian Redl2c373b92010-10-05 15:59:54 +0000222 D->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000223 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000224 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000225 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000226 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000227 D->setAttrs(Attrs);
228 }
Chris Lattner487412d2009-04-27 05:27:42 +0000229 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000230 D->setUsed(Record[Idx++]);
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000231 D->setReferenced(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000232 D->setAccess((AccessSpecifier)Record[Idx++]);
Sebastian Redl009e7f22010-10-05 16:15:19 +0000233 D->setPCHLevel(Record[Idx++] + (F.Type <= ASTReader::PCH));
Chris Lattner487412d2009-04-27 05:27:42 +0000234}
235
Sebastian Redlb3298c32010-08-18 23:56:48 +0000236void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Chris Lattner487412d2009-04-27 05:27:42 +0000237 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000238 TU->setAnonymousNamespace(
239 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000240}
241
Sebastian Redlb3298c32010-08-18 23:56:48 +0000242void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000243 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000244 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000245}
246
Sebastian Redlb3298c32010-08-18 23:56:48 +0000247void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000248 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000249 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000250 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor1c283312010-08-11 12:19:30 +0000251 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000252}
253
Sebastian Redlb3298c32010-08-18 23:56:48 +0000254void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000255 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000256 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000257}
258
Richard Smithdda56e42011-04-15 14:24:37 +0000259void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
260 VisitTypeDecl(TD);
261 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
262}
263
Sebastian Redlb3298c32010-08-18 23:56:48 +0000264void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000265 VisitTypeDecl(TD);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000266 VisitRedeclarable(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000267 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000268 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
269 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000270 TD->setEmbeddedInDeclarator(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000271 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000272 if (Record[Idx++]) { // hasExtInfo
273 TagDecl::ExtInfo *Info = new (*Reader.getContext()) TagDecl::ExtInfo();
274 ReadQualifierInfo(*Info, Record, Idx);
Richard Smithdda56e42011-04-15 14:24:37 +0000275 TD->TypedefNameDeclOrQualifier = Info;
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000276 } else
Richard Smithdda56e42011-04-15 14:24:37 +0000277 TD->setTypedefNameForAnonDecl(
278 cast_or_null<TypedefNameDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000279}
280
Sebastian Redlb3298c32010-08-18 23:56:48 +0000281void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000282 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000283 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
284 ED->setIntegerTypeSourceInfo(TI);
285 else
286 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000287 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000288 ED->setNumPositiveBits(Record[Idx++]);
289 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000290 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000291 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000292 ED->IsFixed = Record[Idx++];
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000293 ED->setInstantiationOfMemberEnum(
294 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000295}
296
Sebastian Redlb3298c32010-08-18 23:56:48 +0000297void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000298 VisitTagDecl(RD);
299 RD->setHasFlexibleArrayMember(Record[Idx++]);
300 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000301 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000302}
303
Sebastian Redlb3298c32010-08-18 23:56:48 +0000304void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000305 VisitNamedDecl(VD);
306 VD->setType(Reader.GetType(Record[Idx++]));
307}
308
Sebastian Redlb3298c32010-08-18 23:56:48 +0000309void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000310 VisitValueDecl(ECD);
311 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000312 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000313 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
314}
315
Sebastian Redlb3298c32010-08-18 23:56:48 +0000316void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000317 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000318 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000319 if (Record[Idx++]) { // hasExtInfo
320 DeclaratorDecl::ExtInfo *Info
321 = new (*Reader.getContext()) DeclaratorDecl::ExtInfo();
322 ReadQualifierInfo(*Info, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000323 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000324 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000325}
326
Sebastian Redlb3298c32010-08-18 23:56:48 +0000327void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000328 VisitDeclaratorDecl(FD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000329 VisitRedeclarable(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000330
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000331 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000332 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000333 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000334 default: assert(false && "Unhandled TemplatedKind!");
335 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000336 case FunctionDecl::TK_NonTemplate:
337 break;
338 case FunctionDecl::TK_FunctionTemplate:
339 FD->setDescribedFunctionTemplate(
340 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
341 break;
342 case FunctionDecl::TK_MemberSpecialization: {
343 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
344 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000345 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000346 FD->setInstantiationOfMemberFunction(*Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000347 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
348 break;
349 }
350 case FunctionDecl::TK_FunctionTemplateSpecialization: {
351 FunctionTemplateDecl *Template
352 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
353 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
354
355 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000356 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000357 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000358
359 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000360 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000361 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000362 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
363 unsigned NumTemplateArgLocs = Record[Idx++];
364 TemplArgLocs.reserve(NumTemplateArgLocs);
365 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000366 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000367 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000368
Sebastian Redl2c373b92010-10-05 15:59:54 +0000369 LAngleLoc = ReadSourceLocation(Record, Idx);
370 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000371 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000372
Sebastian Redl2c373b92010-10-05 15:59:54 +0000373 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000374
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000375 ASTContext &C = *Reader.getContext();
376 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000377 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000378 TemplateArgumentListInfo *TemplArgsInfo
379 = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
380 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
381 TemplArgsInfo->addArgument(TemplArgLocs[i]);
382 FunctionTemplateSpecializationInfo *FTInfo
383 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
384 TemplArgList,
385 TemplArgsInfo, POI);
386 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000387
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000388 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000389 // The template that contains the specializations set. It's not safe to
390 // use getCanonicalDecl on Template since it may still be initializing.
391 FunctionTemplateDecl *CanonTemplate
392 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000393 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
394 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
395 // FunctionTemplateSpecializationInfo's Profile().
396 // We avoid getASTContext because a decl in the parent hierarchy may
397 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000398 llvm::FoldingSetNodeID ID;
399 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
400 TemplArgs.size(), C);
401 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000402 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000403 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000404 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000405 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000406 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000407 }
408 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
409 // Templates.
410 UnresolvedSet<8> TemplDecls;
411 unsigned NumTemplates = Record[Idx++];
412 while (NumTemplates--)
413 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
414
415 // Templates args.
416 TemplateArgumentListInfo TemplArgs;
417 unsigned NumArgs = Record[Idx++];
418 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000419 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
420 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
421 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000422
423 FD->setDependentTemplateSpecialization(*Reader.getContext(),
424 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000425 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000426 }
427 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000428
Sebastian Redlb3298c32010-08-18 23:56:48 +0000429 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000430 // after everything else is read.
431
Douglas Gregorbf62d642010-12-06 18:36:25 +0000432 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000433 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000434 FD->IsInline = Record[Idx++];
435 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000436 FD->IsVirtualAsWritten = Record[Idx++];
437 FD->IsPure = Record[Idx++];
438 FD->HasInheritedPrototype = Record[Idx++];
439 FD->HasWrittenPrototype = Record[Idx++];
440 FD->IsDeleted = Record[Idx++];
441 FD->IsTrivial = Record[Idx++];
Alexis Hunt1f69a022011-05-12 22:46:29 +0000442 FD->IsDefaulted = Record[Idx++];
443 FD->IsExplicitlyDefaulted = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000444 FD->HasImplicitReturnZero = Record[Idx++];
445 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000446
Chris Lattnerca025db2010-05-07 21:43:38 +0000447 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000448 unsigned NumParams = Record[Idx++];
449 llvm::SmallVector<ParmVarDecl *, 16> Params;
450 Params.reserve(NumParams);
451 for (unsigned I = 0; I != NumParams; ++I)
452 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000453 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000454}
455
Sebastian Redlb3298c32010-08-18 23:56:48 +0000456void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000457 VisitNamedDecl(MD);
458 if (Record[Idx++]) {
459 // In practice, this won't be executed (since method definitions
460 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000461 MD->setBody(Reader.ReadStmt(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000462 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
463 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
464 }
465 MD->setInstanceMethod(Record[Idx++]);
466 MD->setVariadic(Record[Idx++]);
467 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000468 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000469 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
470 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000471 MD->SetRelatedResultType(Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000472 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000473 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000474 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
475 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000476 unsigned NumParams = Record[Idx++];
477 llvm::SmallVector<ParmVarDecl *, 16> Params;
478 Params.reserve(NumParams);
479 for (unsigned I = 0; I != NumParams; ++I)
480 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000481 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
482 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000483}
484
Sebastian Redlb3298c32010-08-18 23:56:48 +0000485void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000486 VisitNamedDecl(CD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000487 SourceLocation A = ReadSourceLocation(Record, Idx);
488 SourceLocation B = ReadSourceLocation(Record, Idx);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000489 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000490}
491
Sebastian Redlb3298c32010-08-18 23:56:48 +0000492void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000493 VisitObjCContainerDecl(ID);
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000494 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtrOrNull());
Chris Lattner487412d2009-04-27 05:27:42 +0000495 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
496 (Reader.GetDecl(Record[Idx++])));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000497
498 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000499 unsigned NumProtocols = Record[Idx++];
500 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
501 Protocols.reserve(NumProtocols);
502 for (unsigned I = 0; I != NumProtocols; ++I)
503 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000504 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
505 ProtoLocs.reserve(NumProtocols);
506 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000507 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000508 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
509 *Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000510
511 // Read the transitive closure of protocols referenced by this class.
512 NumProtocols = Record[Idx++];
513 Protocols.clear();
514 Protocols.reserve(NumProtocols);
515 for (unsigned I = 0; I != NumProtocols; ++I)
516 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
517 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
518 *Reader.getContext());
519
520 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000521 unsigned NumIvars = Record[Idx++];
522 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
523 IVars.reserve(NumIvars);
524 for (unsigned I = 0; I != NumIvars; ++I)
525 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000526 ID->setCategoryList(
527 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000528 // We will rebuild this list lazily.
529 ID->setIvarList(0);
Douglas Gregor1c283312010-08-11 12:19:30 +0000530 ID->setForwardDecl(Record[Idx++]);
531 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000532 ID->setClassLoc(ReadSourceLocation(Record, Idx));
533 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
534 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000535}
536
Sebastian Redlb3298c32010-08-18 23:56:48 +0000537void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000538 VisitFieldDecl(IVD);
539 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000540 // This field will be built lazily.
541 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000542 bool synth = Record[Idx++];
543 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000544}
545
Sebastian Redlb3298c32010-08-18 23:56:48 +0000546void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000547 VisitObjCContainerDecl(PD);
548 PD->setForwardDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000549 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000550 unsigned NumProtoRefs = Record[Idx++];
551 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
552 ProtoRefs.reserve(NumProtoRefs);
553 for (unsigned I = 0; I != NumProtoRefs; ++I)
554 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000555 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
556 ProtoLocs.reserve(NumProtoRefs);
557 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000558 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000559 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
560 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000561}
562
Sebastian Redlb3298c32010-08-18 23:56:48 +0000563void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000564 VisitFieldDecl(FD);
565}
566
Sebastian Redlb3298c32010-08-18 23:56:48 +0000567void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000568 VisitDecl(CD);
569 unsigned NumClassRefs = Record[Idx++];
570 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
571 ClassRefs.reserve(NumClassRefs);
572 for (unsigned I = 0; I != NumClassRefs; ++I)
573 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000574 llvm::SmallVector<SourceLocation, 16> SLocs;
575 SLocs.reserve(NumClassRefs);
576 for (unsigned I = 0; I != NumClassRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000577 SLocs.push_back(ReadSourceLocation(Record, Idx));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000578 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
579 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000580}
581
Sebastian Redlb3298c32010-08-18 23:56:48 +0000582void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000583 VisitDecl(FPD);
584 unsigned NumProtoRefs = Record[Idx++];
585 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
586 ProtoRefs.reserve(NumProtoRefs);
587 for (unsigned I = 0; I != NumProtoRefs; ++I)
588 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000589 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
590 ProtoLocs.reserve(NumProtoRefs);
591 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000592 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000593 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
594 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000595}
596
Sebastian Redlb3298c32010-08-18 23:56:48 +0000597void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000598 VisitObjCContainerDecl(CD);
599 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
600 unsigned NumProtoRefs = Record[Idx++];
601 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
602 ProtoRefs.reserve(NumProtoRefs);
603 for (unsigned I = 0; I != NumProtoRefs; ++I)
604 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000605 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
606 ProtoLocs.reserve(NumProtoRefs);
607 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000608 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000609 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
610 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000611 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000612 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000613 CD->setAtLoc(ReadSourceLocation(Record, Idx));
614 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000615}
616
Sebastian Redlb3298c32010-08-18 23:56:48 +0000617void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000618 VisitNamedDecl(CAD);
619 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
620}
621
Sebastian Redlb3298c32010-08-18 23:56:48 +0000622void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000623 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000624 D->setAtLoc(ReadSourceLocation(Record, Idx));
625 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000626 // FIXME: stable encoding
627 D->setPropertyAttributes(
628 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000629 D->setPropertyAttributesAsWritten(
630 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000631 // FIXME: stable encoding
632 D->setPropertyImplementation(
633 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
634 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
635 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
636 D->setGetterMethodDecl(
637 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
638 D->setSetterMethodDecl(
639 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
640 D->setPropertyIvarDecl(
641 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
642}
643
Sebastian Redlb3298c32010-08-18 23:56:48 +0000644void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000645 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000646 D->setClassInterface(
647 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000648}
649
Sebastian Redlb3298c32010-08-18 23:56:48 +0000650void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000651 VisitObjCImplDecl(D);
652 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
653}
654
Sebastian Redlb3298c32010-08-18 23:56:48 +0000655void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000656 VisitObjCImplDecl(D);
657 D->setSuperClass(
658 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000659 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000660 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000661 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000662}
663
664
Sebastian Redlb3298c32010-08-18 23:56:48 +0000665void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000666 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000667 D->setAtLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000668 D->setPropertyDecl(
669 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000670 D->PropertyIvarDecl =
671 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]));
672 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000673 D->setGetterCXXConstructor(Reader.ReadExpr(F));
674 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000675}
676
Sebastian Redlb3298c32010-08-18 23:56:48 +0000677void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000678 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000679 FD->setMutable(Record[Idx++]);
680 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000681 FD->setBitWidth(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000682 if (!FD->getDeclName()) {
683 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
684 if (Tmpl)
685 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
686 }
Chris Lattner487412d2009-04-27 05:27:42 +0000687}
688
Francois Pichet783dd6e2010-11-21 06:08:52 +0000689void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
690 VisitValueDecl(FD);
691
692 FD->ChainingSize = Record[Idx++];
693 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
694 FD->Chaining = new (*Reader.getContext())NamedDecl*[FD->ChainingSize];
695
696 for (unsigned I = 0; I != FD->ChainingSize; ++I)
697 FD->Chaining[I] = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
698}
699
Sebastian Redlb3298c32010-08-18 23:56:48 +0000700void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000701 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000702 VisitRedeclarable(VD);
John McCallbeaa11c2011-05-01 02:13:58 +0000703 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
704 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
705 VD->VarDeclBits.ThreadSpecified = Record[Idx++];
706 VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
707 VD->VarDeclBits.ExceptionVar = Record[Idx++];
708 VD->VarDeclBits.NRVOVariable = Record[Idx++];
709 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000710 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000711 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000712
713 if (Record[Idx++]) { // HasMemberSpecializationInfo.
714 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
715 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000716 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000717 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
718 }
Chris Lattner487412d2009-04-27 05:27:42 +0000719}
720
Sebastian Redlb3298c32010-08-18 23:56:48 +0000721void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000722 VisitVarDecl(PD);
723}
724
Sebastian Redlb3298c32010-08-18 23:56:48 +0000725void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000726 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +0000727 unsigned isObjCMethodParam = Record[Idx++];
728 unsigned scopeDepth = Record[Idx++];
729 unsigned scopeIndex = Record[Idx++];
730 unsigned declQualifier = Record[Idx++];
731 if (isObjCMethodParam) {
732 assert(scopeDepth == 0);
733 PD->setObjCMethodScopeInfo(scopeIndex);
734 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
735 } else {
736 PD->setScopeInfo(scopeDepth, scopeIndex);
737 }
John McCallbeaa11c2011-05-01 02:13:58 +0000738 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
739 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000740 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000741 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000742}
743
Sebastian Redlb3298c32010-08-18 23:56:48 +0000744void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000745 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000746 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000747 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000748}
749
Sebastian Redlb3298c32010-08-18 23:56:48 +0000750void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000751 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000752 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
753 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000754 unsigned NumParams = Record[Idx++];
755 llvm::SmallVector<ParmVarDecl *, 16> Params;
756 Params.reserve(NumParams);
757 for (unsigned I = 0; I != NumParams; ++I)
758 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000759 BD->setParams(Params.data(), NumParams);
John McCallc63de662011-02-02 13:00:07 +0000760
761 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000762 unsigned numCaptures = Record[Idx++];
763 llvm::SmallVector<BlockDecl::Capture, 16> captures;
764 captures.reserve(numCaptures);
765 for (unsigned i = 0; i != numCaptures; ++i) {
766 VarDecl *decl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
767 unsigned flags = Record[Idx++];
768 bool byRef = (flags & 1);
769 bool nested = (flags & 2);
770 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
771
772 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
773 }
774 BD->setCaptures(*Reader.getContext(), captures.begin(),
775 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000776}
777
Sebastian Redlb3298c32010-08-18 23:56:48 +0000778void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000779 VisitDecl(D);
780 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnaraea947882011-03-08 16:41:52 +0000781 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000782 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000783}
784
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000785void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
786 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000787 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000788}
789
790
Sebastian Redlb3298c32010-08-18 23:56:48 +0000791void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000792 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000793 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000794 D->LocStart = ReadSourceLocation(Record, Idx);
795 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000796 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000797
Chris Lattnerca025db2010-05-07 21:43:38 +0000798 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000799 D->OrigOrAnonNamespace.setInt(IsOriginal);
800 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000801 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
802}
803
Sebastian Redlb3298c32010-08-18 23:56:48 +0000804void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000805 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000806 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000807 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000808 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000809 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000810}
811
Sebastian Redlb3298c32010-08-18 23:56:48 +0000812void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000813 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000814 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000815 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000816 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000817 D->FirstUsingShadow = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000818 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000819 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
820 if (Pattern)
821 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000822}
823
Sebastian Redlb3298c32010-08-18 23:56:48 +0000824void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000825 VisitNamedDecl(D);
826 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000827 D->UsingOrNextShadow = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000828 UsingShadowDecl *Pattern
829 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
830 if (Pattern)
831 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000832}
833
Sebastian Redlb3298c32010-08-18 23:56:48 +0000834void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000835 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000836 D->UsingLoc = ReadSourceLocation(Record, Idx);
837 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000838 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor01a430132010-09-01 03:07:18 +0000839 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
840 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000841}
842
Sebastian Redlb3298c32010-08-18 23:56:48 +0000843void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000844 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000845 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000846 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000847 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000848}
849
Sebastian Redlb3298c32010-08-18 23:56:48 +0000850void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000851 UnresolvedUsingTypenameDecl *D) {
852 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000853 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000854 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000855}
856
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000857void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000858 struct CXXRecordDecl::DefinitionData &Data,
859 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000860 Data.UserDeclaredConstructor = Record[Idx++];
861 Data.UserDeclaredCopyConstructor = Record[Idx++];
862 Data.UserDeclaredCopyAssignment = Record[Idx++];
863 Data.UserDeclaredDestructor = Record[Idx++];
864 Data.Aggregate = Record[Idx++];
865 Data.PlainOldData = Record[Idx++];
866 Data.Empty = Record[Idx++];
867 Data.Polymorphic = Record[Idx++];
868 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +0000869 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +0000870 Data.HasNoNonEmptyBases = Record[Idx++];
871 Data.HasPrivateFields = Record[Idx++];
872 Data.HasProtectedFields = Record[Idx++];
873 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +0000874 Data.HasMutableFields = Record[Idx++];
Alexis Huntf479f1b2011-05-09 18:22:59 +0000875 Data.HasTrivialDefaultConstructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000876 Data.HasConstExprNonCopyMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000877 Data.HasTrivialCopyConstructor = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000878 Data.HasTrivialMoveConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000879 Data.HasTrivialCopyAssignment = Record[Idx++];
Chandler Carruthad7d4042011-04-23 23:10:33 +0000880 Data.HasTrivialMoveAssignment = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000881 Data.HasTrivialDestructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +0000882 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000883 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +0000884 Data.UserProvidedDefaultConstructor = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000885 Data.DeclaredDefaultConstructor = Record[Idx++];
886 Data.DeclaredCopyConstructor = Record[Idx++];
887 Data.DeclaredCopyAssignment = Record[Idx++];
888 Data.DeclaredDestructor = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000889
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000890 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000891 if (Data.NumBases)
892 Data.Bases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000893 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000894 if (Data.NumVBases)
895 Data.VBases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
896
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000897 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
898 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
899 assert(Data.Definition && "Data.Definition should be already set!");
900 Data.FirstFriend
901 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
902}
903
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000904void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
905 CXXRecordDecl *DefinitionDecl,
906 const RecordData &Record,
907 unsigned &Idx) {
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000908 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000909
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000910 if (D == DefinitionDecl) {
911 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000912 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000913 // We read the definition info. Check if there are pending forward
914 // references that need to point to this DefinitionData pointer.
915 ASTReader::PendingForwardRefsMap::iterator
916 FindI = Reader.PendingForwardRefs.find(D);
917 if (FindI != Reader.PendingForwardRefs.end()) {
918 ASTReader::ForwardRefs &Refs = FindI->second;
919 for (ASTReader::ForwardRefs::iterator
920 I = Refs.begin(), E = Refs.end(); I != E; ++I)
921 (*I)->DefinitionData = D->DefinitionData;
922#ifndef NDEBUG
923 // We later check whether PendingForwardRefs is empty to make sure all
924 // pending references were linked.
925 Reader.PendingForwardRefs.erase(D);
926#endif
927 }
928 } else if (DefinitionDecl) {
929 if (DefinitionDecl->DefinitionData) {
930 D->DefinitionData = DefinitionDecl->DefinitionData;
931 } else {
932 // The definition is still initializing.
933 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
934 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000935 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000936}
937
938void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
939 VisitRecordDecl(D);
940
941 CXXRecordDecl *DefinitionDecl
942 = cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
943 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
944
945 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000946
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000947 enum CXXRecKind {
948 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
949 };
950 switch ((CXXRecKind)Record[Idx++]) {
951 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000952 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000953 case CXXRecNotTemplate:
954 break;
955 case CXXRecTemplate:
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000956 D->TemplateOrInstantiation
957 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000958 break;
959 case CXXRecMemberSpecialization: {
960 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
961 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000962 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000963 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
964 MSI->setPointOfInstantiation(POI);
965 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000966 break;
967 }
968 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +0000969
970 // Load the key function to avoid deserializing every method so we can
971 // compute it.
972 if (D->IsDefinition) {
973 CXXMethodDecl *Key
974 = cast_or_null<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
975 if (Key)
976 C.KeyFunctions[D] = Key;
977 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000978}
979
Sebastian Redlb3298c32010-08-18 23:56:48 +0000980void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000981 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000982 unsigned NumOverridenMethods = Record[Idx++];
983 while (NumOverridenMethods--) {
984 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
985 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
986 // MD may be initializing.
987 Reader.getContext()->addOverriddenMethod(D, MD);
988 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000989}
990
Sebastian Redlb3298c32010-08-18 23:56:48 +0000991void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000992 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000993
994 D->IsExplicitSpecified = Record[Idx++];
995 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +0000996 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
997 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000998}
999
Sebastian Redlb3298c32010-08-18 23:56:48 +00001000void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001001 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001002
1003 D->ImplicitlyDefined = Record[Idx++];
1004 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +00001005}
1006
Sebastian Redlb3298c32010-08-18 23:56:48 +00001007void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001008 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001009 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001010}
1011
Sebastian Redlb3298c32010-08-18 23:56:48 +00001012void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001013 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001014 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +00001015}
1016
Sebastian Redlb3298c32010-08-18 23:56:48 +00001017void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001018 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001019 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +00001020 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001021 else
1022 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001023 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +00001024 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001025 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001026}
1027
Sebastian Redlb3298c32010-08-18 23:56:48 +00001028void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001029 VisitDecl(D);
1030 unsigned NumParams = Record[Idx++];
1031 D->NumParams = NumParams;
1032 D->Params = new TemplateParameterList*[NumParams];
1033 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001034 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001035 if (Record[Idx++]) // HasFriendDecl
1036 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
1037 else
Sebastian Redl2c373b92010-10-05 15:59:54 +00001038 D->Friend = GetTypeSourceInfo(Record, Idx);
1039 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001040}
1041
Sebastian Redlb3298c32010-08-18 23:56:48 +00001042void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001043 VisitNamedDecl(D);
1044
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001045 NamedDecl *TemplatedDecl
1046 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001047 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001048 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001049 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001050}
1051
Sebastian Redlb3298c32010-08-18 23:56:48 +00001052void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001053 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1054 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001055
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001056 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001057 DeclID PreviousDeclID = Record[Idx++];
1058 DeclID FirstDeclID = PreviousDeclID ? Record[Idx++] : 0;
1059 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1060 // We temporarily set the first (canonical) declaration as the previous one
1061 // which is the one that matters and mark the real previous DeclID to be
1062 // loaded & attached later on.
1063 RedeclarableTemplateDecl *FirstDecl =
1064 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1065 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1066 "FirstDecl kind mismatch");
1067 if (FirstDecl) {
1068 D->CommonOrPrev = FirstDecl;
1069 // Mark the real previous DeclID to be loaded & attached later on.
1070 if (PreviousDeclID != FirstDeclID)
1071 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1072 } else {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001073 D->CommonOrPrev = D->newCommon(*Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001074 if (RedeclarableTemplateDecl *RTD
1075 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
1076 assert(RTD->getKind() == D->getKind() &&
1077 "InstantiatedFromMemberTemplate kind mismatch");
1078 D->setInstantiatedFromMemberTemplateImpl(RTD);
1079 if (Record[Idx++])
1080 D->setMemberSpecialization();
1081 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001082
1083 RedeclarableTemplateDecl *LatestDecl =
1084 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001085
1086 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001087 // in the same AST file. However, if this actually needs to point to a
1088 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001089 // the FirstLatestDeclIDs map which tracks this kind of decls.
1090 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001091 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001092 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1093 if (I != Reader.FirstLatestDeclIDs.end()) {
1094 Decl *NewLatest = Reader.GetDecl(I->second);
1095 assert((LatestDecl->getLocation().isInvalid() ||
1096 NewLatest->getLocation().isInvalid() ||
Argyrios Kyrtzidis54b88e72010-10-20 23:48:40 +00001097 !Reader.SourceMgr.isBeforeInTranslationUnit(
1098 NewLatest->getLocation(),
1099 LatestDecl->getLocation())) &&
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001100 "The new latest is supposed to come after the previous latest");
1101 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
1102 }
1103
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001104 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1105 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001106 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001107
1108 VisitTemplateDecl(D);
1109 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001110}
1111
Sebastian Redlb3298c32010-08-18 23:56:48 +00001112void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001113 VisitRedeclarableTemplateDecl(D);
1114
1115 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001116 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1117 // the specializations.
1118 llvm::SmallVector<serialization::DeclID, 2> SpecIDs;
1119 SpecIDs.push_back(0);
1120
1121 // Specializations.
1122 unsigned Size = Record[Idx++];
1123 SpecIDs[0] += Size;
1124 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1125 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001126
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001127 // Partial specializations.
1128 Size = Record[Idx++];
1129 SpecIDs[0] += Size;
1130 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1131 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001132
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001133 if (SpecIDs[0]) {
1134 typedef serialization::DeclID DeclID;
1135
1136 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1137 CommonPtr->LazySpecializations
1138 = new (*Reader.getContext()) DeclID [SpecIDs.size()];
1139 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1140 SpecIDs.size() * sizeof(DeclID));
1141 }
1142
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001143 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001144 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001145}
1146
Sebastian Redlb3298c32010-08-18 23:56:48 +00001147void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001148 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001149 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001150
1151 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001152 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
1153 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001154 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001155 } else {
1156 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001157 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001158 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001159 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1160 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001161 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1162 = new (C) ClassTemplateSpecializationDecl::
1163 SpecializedPartialSpecialization();
1164 PS->PartialSpecialization
1165 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1166 PS->TemplateArgs = ArgList;
1167 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001168 }
1169 }
1170
1171 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001172 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001173 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1174 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1175 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001176 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1177 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001178 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001179 }
1180
1181 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001182 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001183 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1184 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001185 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001186 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001187
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001188 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001189 ClassTemplateDecl *CanonPattern
1190 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
1191 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001192 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1193 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001194 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001195 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001196 }
1197 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001198}
1199
Sebastian Redlb3298c32010-08-18 23:56:48 +00001200void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001201 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001202 VisitClassTemplateSpecializationDecl(D);
1203
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001204 ASTContext &C = *Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001205 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001206
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001207 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001208 if (NumArgs) {
1209 D->NumArgsAsWritten = NumArgs;
1210 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1211 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001212 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001213 }
1214
1215 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001216
1217 // These are read/set from/to the first declaration.
1218 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001219 D->InstantiatedFromMember.setPointer(
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001220 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1221 Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001222 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001223 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001224}
1225
Sebastian Redlb3298c32010-08-18 23:56:48 +00001226void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001227 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001228
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001229 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001230 // This FunctionTemplateDecl owns a CommonPtr; read it.
1231
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001232 // Read the function specialization declarations.
1233 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001234 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001235 unsigned NumSpecs = Record[Idx++];
1236 while (NumSpecs--)
1237 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001238 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001239}
1240
Sebastian Redlb3298c32010-08-18 23:56:48 +00001241void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001242 VisitTypeDecl(D);
1243
1244 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001245
1246 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001247 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001248 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001249}
1250
Sebastian Redlb3298c32010-08-18 23:56:48 +00001251void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001252 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001253 // TemplateParmPosition.
1254 D->setDepth(Record[Idx++]);
1255 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001256 if (D->isExpandedParameterPack()) {
1257 void **Data = reinterpret_cast<void **>(D + 1);
1258 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1259 Data[2*I] = Reader.GetType(Record[Idx++]).getAsOpaquePtr();
1260 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1261 }
1262 } else {
1263 // Rest of NonTypeTemplateParmDecl.
1264 D->ParameterPack = Record[Idx++];
1265 if (Record[Idx++]) {
1266 Expr *DefArg = Reader.ReadExpr(F);
1267 bool Inherited = Record[Idx++];
1268 D->setDefaultArgument(DefArg, Inherited);
1269 }
1270 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001271}
1272
Sebastian Redlb3298c32010-08-18 23:56:48 +00001273void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001274 VisitTemplateDecl(D);
1275 // TemplateParmPosition.
1276 D->setDepth(Record[Idx++]);
1277 D->setPosition(Record[Idx++]);
1278 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001279 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001280 bool IsInherited = Record[Idx++];
1281 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001282 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001283}
1284
Richard Smith3f1b5d02011-05-05 21:57:07 +00001285void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1286 VisitRedeclarableTemplateDecl(D);
1287}
1288
Sebastian Redlb3298c32010-08-18 23:56:48 +00001289void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001290 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001291 D->AssertExpr = Reader.ReadExpr(F);
1292 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001293 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001294}
1295
Mike Stump11289f42009-09-09 15:08:12 +00001296std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001297ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001298 uint64_t LexicalOffset = Record[Idx++];
1299 uint64_t VisibleOffset = Record[Idx++];
1300 return std::make_pair(LexicalOffset, VisibleOffset);
1301}
1302
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001303template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001304void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001305 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1306 RedeclKind Kind = (RedeclKind)Record[Idx++];
1307 switch (Kind) {
1308 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +00001309 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001310 " reading");
1311 case NoRedeclaration:
1312 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001313 case PointsToPrevious: {
1314 DeclID PreviousDeclID = Record[Idx++];
1315 DeclID FirstDeclID = Record[Idx++];
1316 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1317 // We temporarily set the first (canonical) declaration as the previous one
1318 // which is the one that matters and mark the real previous DeclID to be
1319 // loaded & attached later on.
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001320 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001321 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1322 if (PreviousDeclID != FirstDeclID)
1323 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1324 PreviousDeclID));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001325 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001326 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001327 case PointsToLatest:
1328 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1329 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1330 break;
1331 }
1332
1333 assert(!(Kind == PointsToPrevious &&
1334 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1335 Reader.FirstLatestDeclIDs.end()) &&
1336 "This decl is not first, it should not be in the map");
1337 if (Kind == PointsToPrevious)
1338 return;
1339
1340 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001341 // the same AST file. However, if this actually needs to point to a
1342 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001343 // FirstLatestDeclIDs map which tracks this kind of decls.
1344 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1345 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001346 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001347 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1348 if (I != Reader.FirstLatestDeclIDs.end()) {
1349 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001350 D->RedeclLink
1351 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1352 }
1353}
1354
Chris Lattner487412d2009-04-27 05:27:42 +00001355//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001356// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001357//===----------------------------------------------------------------------===//
1358
Chris Lattner8f63ab52009-04-27 06:01:06 +00001359/// \brief Reads attributes from the current stream position.
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001360void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs,
1361 const RecordData &Record, unsigned &Idx) {
1362 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001363 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001364 attr::Kind Kind = (attr::Kind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001365 SourceLocation Loc = ReadSourceLocation(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001366
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001367#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001368
1369 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001370 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001371 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001372}
1373
1374//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001375// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001376//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001377
1378/// \brief Note that we have loaded the declaration with the given
1379/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001380///
Chris Lattner487412d2009-04-27 05:27:42 +00001381/// This routine notes that this declaration has already been loaded,
1382/// so that future GetDecl calls will return this declaration rather
1383/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001384inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001385 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1386 DeclsLoaded[Index] = D;
1387}
1388
1389
1390/// \brief Determine whether the consumer will be interested in seeing
1391/// this declaration (via HandleTopLevelDecl).
1392///
1393/// This routine should return true for anything that might affect
1394/// code generation, e.g., inline function definitions, Objective-C
1395/// declarations with metadata, etc.
1396static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001397 if (isa<FileScopeAsmDecl>(D))
1398 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001399 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001400 return Var->isFileVarDecl() &&
1401 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001402 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Alexis Hunt4a8ea102011-05-06 20:44:56 +00001403 return Func->doesThisDeclarationHaveABody();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001404 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001405}
1406
Sebastian Redl34627792010-07-20 22:46:15 +00001407/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001408ASTReader::RecordLocation
Sebastian Redl539c5062010-08-18 23:57:32 +00001409ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001410 // See if there's an override.
1411 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1412 if (It != ReplacedDecls.end())
Sebastian Redl2c373b92010-10-05 15:59:54 +00001413 return RecordLocation(It->second.first, It->second.second);
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001414
Sebastian Redl34627792010-07-20 22:46:15 +00001415 PerFileData *F = 0;
1416 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1417 F = Chain[N - I - 1];
1418 if (Index < F->LocalNumDecls)
1419 break;
1420 Index -= F->LocalNumDecls;
1421 }
1422 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redl2c373b92010-10-05 15:59:54 +00001423 return RecordLocation(F, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001424}
1425
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001426void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1427 assert(D && previous);
1428 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1429 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1430 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1431 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1432 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1433 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1434 } else {
1435 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1436 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1437 }
1438}
1439
1440void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1441 Decl *previous = GetDecl(ID);
1442 ASTDeclReader::attachPreviousDecl(D, previous);
1443}
1444
Sebastian Redlb3298c32010-08-18 23:56:48 +00001445/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl539c5062010-08-18 23:57:32 +00001446Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001447 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001448 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001449 // Keep track of where we are in the stream, then jump back there
1450 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001451 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001452
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001453 ReadingKindTracker ReadingKind(Read_Decl, *this);
1454
Douglas Gregor1342e842009-07-06 18:54:52 +00001455 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001456 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001457
Sebastian Redl2c373b92010-10-05 15:59:54 +00001458 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001459 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001460 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001461 unsigned Idx = 0;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001462 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001463
Chris Lattner1de76db2009-04-27 05:58:23 +00001464 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001465 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001466 case DECL_CONTEXT_LEXICAL:
1467 case DECL_CONTEXT_VISIBLE:
Chris Lattner487412d2009-04-27 05:27:42 +00001468 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1469 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001470 case DECL_TRANSLATION_UNIT:
Chris Lattner487412d2009-04-27 05:27:42 +00001471 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001472 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001473 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001474 case DECL_TYPEDEF:
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001475 D = TypedefDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1476 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001477 break;
Richard Smithdda56e42011-04-15 14:24:37 +00001478 case DECL_TYPEALIAS:
1479 D = TypeAliasDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1480 0, 0);
1481 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001482 case DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001483 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001484 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001485 case DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001486 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001487 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001488 case DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001489 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001490 0, llvm::APSInt());
1491 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001492 case DECL_FUNCTION:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001493 D = FunctionDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1494 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001495 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001496 case DECL_LINKAGE_SPEC:
Abramo Bagnaraea947882011-03-08 16:41:52 +00001497 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001498 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001499 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001500 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001501 case DECL_LABEL:
1502 D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
1503 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001504 case DECL_NAMESPACE:
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001505 D = NamespaceDecl::Create(*Context, 0, SourceLocation(),
1506 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001507 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001508 case DECL_NAMESPACE_ALIAS:
Chris Lattnerca025db2010-05-07 21:43:38 +00001509 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001510 SourceLocation(), 0,
1511 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001512 SourceLocation(), 0);
1513 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001514 case DECL_USING:
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001515 D = UsingDecl::Create(*Context, 0, SourceLocation(),
1516 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1517 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001518 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001519 case DECL_USING_SHADOW:
Chris Lattnerca025db2010-05-07 21:43:38 +00001520 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1521 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001522 case DECL_USING_DIRECTIVE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001523 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001524 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001525 SourceLocation(), 0, 0);
1526 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001527 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001528 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001529 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001530 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001531 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001532 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattnerca025db2010-05-07 21:43:38 +00001533 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001534 SourceLocation(),
1535 NestedNameSpecifierLoc(),
1536 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001537 DeclarationName());
1538 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001539 case DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001540 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001541 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001542 case DECL_CXX_METHOD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001543 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregorf2f08062011-03-08 17:10:18 +00001544 DeclarationNameInfo(), QualType(), 0,
1545 false, SC_None, false, SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001546 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001547 case DECL_CXX_CONSTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001548 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1549 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001550 case DECL_CXX_DESTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001551 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1552 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001553 case DECL_CXX_CONVERSION:
Chris Lattnerca025db2010-05-07 21:43:38 +00001554 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1555 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001556 case DECL_ACCESS_SPEC:
Argyrios Kyrtzidis260b4a82010-09-08 21:32:35 +00001557 D = AccessSpecDecl::Create(*Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001558 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001559 case DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001560 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001561 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001562 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001563 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001564 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001565 case DECL_CLASS_TEMPLATE:
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001566 D = ClassTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001567 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001568 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001569 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001570 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001571 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001572 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001573 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001574 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001575 case DECL_FUNCTION_TEMPLATE:
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001576 D = FunctionTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001577 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001578 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001579 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001580 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001581 case DECL_NON_TYPE_TEMPLATE_PARM:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001582 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(),
1583 SourceLocation(), 0, 0, 0, QualType(),
1584 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001585 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001586 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001587 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(),
1588 SourceLocation(), 0, 0, 0, QualType(),
1589 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001590 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001591 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregorf5500772011-01-05 15:48:55 +00001592 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1593 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001594 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001595 case DECL_TYPE_ALIAS_TEMPLATE:
1596 D = TypeAliasTemplateDecl::Create(*Context, Decl::EmptyShell());
1597 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001598 case DECL_STATIC_ASSERT:
Abramo Bagnaraea947882011-03-08 16:41:52 +00001599 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1600 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001601 break;
1602
Sebastian Redl539c5062010-08-18 23:57:32 +00001603 case DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001604 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001605 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001606 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001607 case DECL_OBJC_INTERFACE:
Douglas Gregor1c283312010-08-11 12:19:30 +00001608 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001609 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001610 case DECL_OBJC_IVAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001611 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1612 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001613 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001614 case DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001615 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001616 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001617 case DECL_OBJC_AT_DEFS_FIELD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001618 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(),
1619 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001620 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001621 case DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001622 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001623 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001624 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001625 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001626 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001627 case DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001628 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1629 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001630 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001631 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001632 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001633 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001634 case DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001635 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001636 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001637 case DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001638 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001639 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001640 case DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001641 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001642 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001643 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001644 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001645 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001646 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001647 ObjCPropertyImplDecl::Dynamic, 0,
1648 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001649 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001650 case DECL_FIELD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001651 D = FieldDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1652 QualType(), 0, 0, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001653 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001654 case DECL_INDIRECTFIELD:
1655 D = IndirectFieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
1656 0, 0);
1657 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001658 case DECL_VAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001659 D = VarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1660 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001661 break;
1662
Sebastian Redl539c5062010-08-18 23:57:32 +00001663 case DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001664 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001665 break;
1666
Sebastian Redl539c5062010-08-18 23:57:32 +00001667 case DECL_PARM_VAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001668 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1669 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001670 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001671 case DECL_FILE_SCOPE_ASM:
Abramo Bagnara348823a2011-03-03 14:20:18 +00001672 D = FileScopeAsmDecl::Create(*Context, 0, 0, SourceLocation(),
1673 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001674 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001675 case DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001676 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001677 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001678 case DECL_CXX_BASE_SPECIFIERS:
1679 Error("attempt to read a C++ base-specifier record as a declaration");
1680 return 0;
Chris Lattner487412d2009-04-27 05:27:42 +00001681 }
Chris Lattner487412d2009-04-27 05:27:42 +00001682
Sebastian Redlb3298c32010-08-18 23:56:48 +00001683 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001684 LoadedDecl(Index, D);
1685 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001686
1687 // If this declaration is also a declaration context, get the
1688 // offsets for its tables of lexical and visible declarations.
1689 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1690 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1691 if (Offsets.first || Offsets.second) {
1692 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1693 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001694 DeclContextInfo Info;
1695 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1696 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001697 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001698 // Reading the TU will happen after reading its lexical update blocks,
1699 // so we need to make sure we insert in front. For all other contexts,
1700 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001701 Infos.insert(Infos.begin(), Info);
Sebastian Redlf830df42011-04-24 16:27:54 +00001702 }
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001703
Sebastian Redlf830df42011-04-24 16:27:54 +00001704 // Now add the pending visible updates for this decl context, if it has any.
1705 DeclContextVisibleUpdatesPending::iterator I =
1706 PendingVisibleUpdates.find(ID);
1707 if (I != PendingVisibleUpdates.end()) {
1708 // There are updates. This means the context has external visible
1709 // storage, even if the original stored version didn't.
1710 DC->setHasExternalVisibleStorage(true);
1711 DeclContextVisibleUpdates &U = I->second;
1712 DeclContextInfos &Infos = DeclContextOffsets[DC];
1713 DeclContextInfo Info;
1714 Info.LexicalDecls = 0;
1715 Info.NumLexicalDecls = 0;
1716 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1717 UI != UE; ++UI) {
1718 Info.NameLookupTableData = *UI;
1719 Infos.push_back(Info);
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001720 }
Sebastian Redlf830df42011-04-24 16:27:54 +00001721 PendingVisibleUpdates.erase(I);
Chris Lattner487412d2009-04-27 05:27:42 +00001722 }
1723 }
1724 assert(Idx == Record.size());
1725
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001726 // The declaration may have been modified by files later in the chain.
1727 // If this is the case, read the record containing the updates from each file
1728 // and pass it to ASTDeclReader to make the modifications.
1729 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1730 if (UpdI != DeclUpdateOffsets.end()) {
1731 FileOffsetsTy &UpdateOffsets = UpdI->second;
1732 for (FileOffsetsTy::iterator
1733 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
1734 PerFileData *F = I->first;
1735 uint64_t Offset = I->second;
1736 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1737 SavedStreamPosition SavedPosition(Cursor);
1738 Cursor.JumpToBit(Offset);
1739 RecordData Record;
1740 unsigned Code = Cursor.ReadCode();
1741 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1742 (void)RecCode;
1743 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001744 Reader.UpdateDecl(D, *F, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001745 }
1746 }
1747
Chris Lattner487412d2009-04-27 05:27:42 +00001748 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001749 // AST consumer might need to know about, queue it.
1750 // We don't pass it to the consumer immediately because we may be in recursive
1751 // loading, and some declarations may still be initializing.
1752 if (isConsumerInterestedIn(D))
1753 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001754
1755 return D;
1756}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001757
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001758void ASTDeclReader::UpdateDecl(Decl *D, ASTReader::PerFileData &Module,
1759 const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001760 unsigned Idx = 0;
1761 while (Idx < Record.size()) {
1762 switch ((DeclUpdateKind)Record[Idx++]) {
1763 case UPD_CXX_SET_DEFINITIONDATA: {
1764 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
1765 CXXRecordDecl *
1766 DefinitionDecl = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
1767 assert(!RD->DefinitionData && "DefinitionData is already set!");
1768 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1769 break;
1770 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001771
1772 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
1773 cast<CXXRecordDecl>(D)->addedMember(Reader.GetDecl(Record[Idx++]));
1774 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00001775
1776 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1777 // It will be added to the template's specializations set when loaded.
1778 Reader.GetDecl(Record[Idx++]);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001779 break;
1780
1781 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
1782 NamespaceDecl *Anon = cast<NamespaceDecl>(Reader.GetDecl(Record[Idx++]));
Sebastian Redl010288f2011-04-24 16:28:21 +00001783 // Guard against these being loaded out of original order. Don't use
1784 // getNextNamespace(), since it tries to access the context and can't in
1785 // the middle of deserialization.
1786 if (!Anon->NextNamespace) {
1787 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1788 TU->setAnonymousNamespace(Anon);
1789 else
1790 cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1791 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001792 break;
1793 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00001794
1795 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1796 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1797 Reader.ReadSourceLocation(Module, Record, Idx));
1798 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001799 }
1800 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001801}