blob: e07bba4f6b67e1322f7b3f1ab31f9727ace5fa84 [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
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000085 void UpdateDecl(Decl *D, const RecordData &Record);
86
Chris Lattner487412d2009-04-27 05:27:42 +000087 void VisitDecl(Decl *D);
88 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
89 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000090 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000091 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000092 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
93 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000094 void VisitTypeDecl(TypeDecl *TD);
95 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000096 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000097 void VisitTagDecl(TagDecl *TD);
98 void VisitEnumDecl(EnumDecl *ED);
99 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000100 void VisitCXXRecordDecl(CXXRecordDecl *D);
101 void VisitClassTemplateSpecializationDecl(
102 ClassTemplateSpecializationDecl *D);
103 void VisitClassTemplatePartialSpecializationDecl(
104 ClassTemplatePartialSpecializationDecl *D);
105 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000106 void VisitValueDecl(ValueDecl *VD);
107 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000108 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000109 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000110 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000111 void VisitCXXMethodDecl(CXXMethodDecl *D);
112 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
113 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
114 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000115 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000116 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000117 void VisitVarDecl(VarDecl *VD);
118 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
119 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000120 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
121 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000122 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000123 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000124 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000125 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000126 void VisitUsingDecl(UsingDecl *D);
127 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000128 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000129 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000130 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000131 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000132 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
133 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000134 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000135
Chris Lattner487412d2009-04-27 05:27:42 +0000136 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000137 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000138
Alexis Hunted053252010-05-30 07:21:58 +0000139 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000140 void VisitObjCMethodDecl(ObjCMethodDecl *D);
141 void VisitObjCContainerDecl(ObjCContainerDecl *D);
142 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
143 void VisitObjCIvarDecl(ObjCIvarDecl *D);
144 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
145 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
146 void VisitObjCClassDecl(ObjCClassDecl *D);
147 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
148 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
149 void VisitObjCImplDecl(ObjCImplDecl *D);
150 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
151 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
152 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
153 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
154 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
155 };
156}
157
Sebastian Redlb3298c32010-08-18 23:56:48 +0000158uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Sebastian Redlc67764e2010-07-22 22:43:28 +0000159 uint64_t Off = 0;
160 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
Sebastian Redl2c499f62010-08-18 23:56:43 +0000161 ASTReader::PerFileData &F = *Reader.Chain[N - I - 1];
Sebastian Redlc67764e2010-07-22 22:43:28 +0000162 if (&Cursor == &F.DeclsCursor) {
163 Off += F.DeclsCursor.GetCurrentBitNo();
164 break;
165 }
166 Off += F.SizeInBits;
167 }
168 return Off;
169}
170
Sebastian Redlb3298c32010-08-18 23:56:48 +0000171void ASTDeclReader::Visit(Decl *D) {
172 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000173
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000174 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000175 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000176 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000177 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
178 // FunctionDecl's body was written last after all other Stmts/Exprs.
179 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000180 FD->setLazyBody(GetCurrentCursorOffset());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000181 } else if (D->isTemplateParameter()) {
182 // If we have a fully initialized template parameter, we can now
183 // set its DeclContext.
184 D->setDeclContext(
185 cast_or_null<DeclContext>(
186 Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
187 D->setLexicalDeclContext(
188 cast_or_null<DeclContext>(
189 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000190 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000191}
192
Sebastian Redlb3298c32010-08-18 23:56:48 +0000193void ASTDeclReader::VisitDecl(Decl *D) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000194 if (D->isTemplateParameter()) {
195 // We don't want to deserialize the DeclContext of a template
196 // parameter immediately, because the template parameter might be
197 // used in the formulation of its DeclContext. Use the translation
198 // unit DeclContext as a placeholder.
199 DeclContextIDForTemplateParmDecl = Record[Idx++];
200 LexicalDeclContextIDForTemplateParmDecl = Record[Idx++];
201 D->setDeclContext(Reader.getContext()->getTranslationUnitDecl());
202 } else {
203 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
204 D->setLexicalDeclContext(
Chris Lattner487412d2009-04-27 05:27:42 +0000205 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor250ffb12011-03-05 01:35:54 +0000206 }
Sebastian Redl2c373b92010-10-05 15:59:54 +0000207 D->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000208 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000209 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000210 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000211 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000212 D->setAttrs(Attrs);
213 }
Chris Lattner487412d2009-04-27 05:27:42 +0000214 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000215 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000216 D->setAccess((AccessSpecifier)Record[Idx++]);
Sebastian Redl009e7f22010-10-05 16:15:19 +0000217 D->setPCHLevel(Record[Idx++] + (F.Type <= ASTReader::PCH));
Chris Lattner487412d2009-04-27 05:27:42 +0000218}
219
Sebastian Redlb3298c32010-08-18 23:56:48 +0000220void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Chris Lattner487412d2009-04-27 05:27:42 +0000221 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000222 TU->setAnonymousNamespace(
223 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000224}
225
Sebastian Redlb3298c32010-08-18 23:56:48 +0000226void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000227 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000228 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000229}
230
Sebastian Redlb3298c32010-08-18 23:56:48 +0000231void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000232 VisitNamedDecl(TD);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000233 TD->setLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000234 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor1c283312010-08-11 12:19:30 +0000235 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000236}
237
Sebastian Redlb3298c32010-08-18 23:56:48 +0000238void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000239 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000240 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000241}
242
Sebastian Redlb3298c32010-08-18 23:56:48 +0000243void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000244 VisitTypeDecl(TD);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000245 VisitRedeclarable(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000246 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000247 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
248 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000249 TD->setEmbeddedInDeclarator(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000250 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000251 if (Record[Idx++]) { // hasExtInfo
252 TagDecl::ExtInfo *Info = new (*Reader.getContext()) TagDecl::ExtInfo();
253 ReadQualifierInfo(*Info, Record, Idx);
254 TD->TypedefDeclOrQualifier = Info;
255 } else
256 TD->setTypedefForAnonDecl(
257 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000258}
259
Sebastian Redlb3298c32010-08-18 23:56:48 +0000260void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000261 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000262 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
263 ED->setIntegerTypeSourceInfo(TI);
264 else
265 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000266 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000267 ED->setNumPositiveBits(Record[Idx++]);
268 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000269 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000270 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000271 ED->IsFixed = Record[Idx++];
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000272 ED->setInstantiationOfMemberEnum(
273 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000274}
275
Sebastian Redlb3298c32010-08-18 23:56:48 +0000276void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000277 VisitTagDecl(RD);
278 RD->setHasFlexibleArrayMember(Record[Idx++]);
279 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000280 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000281}
282
Sebastian Redlb3298c32010-08-18 23:56:48 +0000283void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000284 VisitNamedDecl(VD);
285 VD->setType(Reader.GetType(Record[Idx++]));
286}
287
Sebastian Redlb3298c32010-08-18 23:56:48 +0000288void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000289 VisitValueDecl(ECD);
290 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000291 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000292 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
293}
294
Sebastian Redlb3298c32010-08-18 23:56:48 +0000295void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000296 VisitValueDecl(DD);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000297 DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000298 if (Record[Idx++]) { // hasExtInfo
299 DeclaratorDecl::ExtInfo *Info
300 = new (*Reader.getContext()) DeclaratorDecl::ExtInfo();
301 ReadQualifierInfo(*Info, Record, Idx);
302 Info->TInfo = GetTypeSourceInfo(Record, Idx);
303 DD->DeclInfo = Info;
304 } else
305 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000306}
307
Sebastian Redlb3298c32010-08-18 23:56:48 +0000308void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000309 VisitDeclaratorDecl(FD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000310 VisitRedeclarable(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000311
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000312 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000313 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000314 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000315 default: assert(false && "Unhandled TemplatedKind!");
316 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000317 case FunctionDecl::TK_NonTemplate:
318 break;
319 case FunctionDecl::TK_FunctionTemplate:
320 FD->setDescribedFunctionTemplate(
321 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
322 break;
323 case FunctionDecl::TK_MemberSpecialization: {
324 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
325 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000326 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000327 FD->setInstantiationOfMemberFunction(*Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000328 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
329 break;
330 }
331 case FunctionDecl::TK_FunctionTemplateSpecialization: {
332 FunctionTemplateDecl *Template
333 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
334 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
335
336 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000337 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000338 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000339
340 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000341 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000342 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000343 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
344 unsigned NumTemplateArgLocs = Record[Idx++];
345 TemplArgLocs.reserve(NumTemplateArgLocs);
346 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000347 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000348 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000349
Sebastian Redl2c373b92010-10-05 15:59:54 +0000350 LAngleLoc = ReadSourceLocation(Record, Idx);
351 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000352 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000353
Sebastian Redl2c373b92010-10-05 15:59:54 +0000354 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000355
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000356 ASTContext &C = *Reader.getContext();
357 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000358 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000359 TemplateArgumentListInfo *TemplArgsInfo
360 = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
361 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
362 TemplArgsInfo->addArgument(TemplArgLocs[i]);
363 FunctionTemplateSpecializationInfo *FTInfo
364 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
365 TemplArgList,
366 TemplArgsInfo, POI);
367 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000368
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000369 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000370 // The template that contains the specializations set. It's not safe to
371 // use getCanonicalDecl on Template since it may still be initializing.
372 FunctionTemplateDecl *CanonTemplate
373 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000374 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
375 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
376 // FunctionTemplateSpecializationInfo's Profile().
377 // We avoid getASTContext because a decl in the parent hierarchy may
378 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000379 llvm::FoldingSetNodeID ID;
380 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
381 TemplArgs.size(), C);
382 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000383 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000384 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000385 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000386 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000387 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000388 }
389 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
390 // Templates.
391 UnresolvedSet<8> TemplDecls;
392 unsigned NumTemplates = Record[Idx++];
393 while (NumTemplates--)
394 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
395
396 // Templates args.
397 TemplateArgumentListInfo TemplArgs;
398 unsigned NumArgs = Record[Idx++];
399 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000400 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
401 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
402 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000403
404 FD->setDependentTemplateSpecialization(*Reader.getContext(),
405 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000406 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000407 }
408 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000409
Sebastian Redlb3298c32010-08-18 23:56:48 +0000410 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000411 // after everything else is read.
412
Douglas Gregorbf62d642010-12-06 18:36:25 +0000413 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000414 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000415 FD->IsInline = Record[Idx++];
416 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000417 FD->IsVirtualAsWritten = Record[Idx++];
418 FD->IsPure = Record[Idx++];
419 FD->HasInheritedPrototype = Record[Idx++];
420 FD->HasWrittenPrototype = Record[Idx++];
421 FD->IsDeleted = Record[Idx++];
422 FD->IsTrivial = Record[Idx++];
423 FD->HasImplicitReturnZero = Record[Idx++];
424 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000425
Chris Lattnerca025db2010-05-07 21:43:38 +0000426 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000427 unsigned NumParams = Record[Idx++];
428 llvm::SmallVector<ParmVarDecl *, 16> Params;
429 Params.reserve(NumParams);
430 for (unsigned I = 0; I != NumParams; ++I)
431 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000432 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000433}
434
Sebastian Redlb3298c32010-08-18 23:56:48 +0000435void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000436 VisitNamedDecl(MD);
437 if (Record[Idx++]) {
438 // In practice, this won't be executed (since method definitions
439 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000440 MD->setBody(Reader.ReadStmt(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000441 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
442 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
443 }
444 MD->setInstanceMethod(Record[Idx++]);
445 MD->setVariadic(Record[Idx++]);
446 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000447 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000448 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
449 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000450 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000451 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000452 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
453 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000454 unsigned NumParams = Record[Idx++];
455 llvm::SmallVector<ParmVarDecl *, 16> Params;
456 Params.reserve(NumParams);
457 for (unsigned I = 0; I != NumParams; ++I)
458 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000459 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
460 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000461}
462
Sebastian Redlb3298c32010-08-18 23:56:48 +0000463void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000464 VisitNamedDecl(CD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000465 SourceLocation A = ReadSourceLocation(Record, Idx);
466 SourceLocation B = ReadSourceLocation(Record, Idx);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000467 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000468}
469
Sebastian Redlb3298c32010-08-18 23:56:48 +0000470void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000471 VisitObjCContainerDecl(ID);
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000472 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtrOrNull());
Chris Lattner487412d2009-04-27 05:27:42 +0000473 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
474 (Reader.GetDecl(Record[Idx++])));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000475
476 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000477 unsigned NumProtocols = Record[Idx++];
478 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
479 Protocols.reserve(NumProtocols);
480 for (unsigned I = 0; I != NumProtocols; ++I)
481 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000482 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
483 ProtoLocs.reserve(NumProtocols);
484 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000485 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000486 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
487 *Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000488
489 // Read the transitive closure of protocols referenced by this class.
490 NumProtocols = Record[Idx++];
491 Protocols.clear();
492 Protocols.reserve(NumProtocols);
493 for (unsigned I = 0; I != NumProtocols; ++I)
494 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
495 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
496 *Reader.getContext());
497
498 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000499 unsigned NumIvars = Record[Idx++];
500 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
501 IVars.reserve(NumIvars);
502 for (unsigned I = 0; I != NumIvars; ++I)
503 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000504 ID->setCategoryList(
505 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000506 // We will rebuild this list lazily.
507 ID->setIvarList(0);
Douglas Gregor1c283312010-08-11 12:19:30 +0000508 ID->setForwardDecl(Record[Idx++]);
509 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000510 ID->setClassLoc(ReadSourceLocation(Record, Idx));
511 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
512 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000513}
514
Sebastian Redlb3298c32010-08-18 23:56:48 +0000515void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000516 VisitFieldDecl(IVD);
517 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000518 // This field will be built lazily.
519 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000520 bool synth = Record[Idx++];
521 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000522}
523
Sebastian Redlb3298c32010-08-18 23:56:48 +0000524void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000525 VisitObjCContainerDecl(PD);
526 PD->setForwardDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000527 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000528 unsigned NumProtoRefs = Record[Idx++];
529 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
530 ProtoRefs.reserve(NumProtoRefs);
531 for (unsigned I = 0; I != NumProtoRefs; ++I)
532 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000533 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
534 ProtoLocs.reserve(NumProtoRefs);
535 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000536 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000537 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
538 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000539}
540
Sebastian Redlb3298c32010-08-18 23:56:48 +0000541void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000542 VisitFieldDecl(FD);
543}
544
Sebastian Redlb3298c32010-08-18 23:56:48 +0000545void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000546 VisitDecl(CD);
547 unsigned NumClassRefs = Record[Idx++];
548 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
549 ClassRefs.reserve(NumClassRefs);
550 for (unsigned I = 0; I != NumClassRefs; ++I)
551 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000552 llvm::SmallVector<SourceLocation, 16> SLocs;
553 SLocs.reserve(NumClassRefs);
554 for (unsigned I = 0; I != NumClassRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000555 SLocs.push_back(ReadSourceLocation(Record, Idx));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000556 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
557 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000558}
559
Sebastian Redlb3298c32010-08-18 23:56:48 +0000560void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000561 VisitDecl(FPD);
562 unsigned NumProtoRefs = Record[Idx++];
563 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
564 ProtoRefs.reserve(NumProtoRefs);
565 for (unsigned I = 0; I != NumProtoRefs; ++I)
566 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000567 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
568 ProtoLocs.reserve(NumProtoRefs);
569 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000570 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000571 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
572 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000573}
574
Sebastian Redlb3298c32010-08-18 23:56:48 +0000575void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000576 VisitObjCContainerDecl(CD);
577 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
578 unsigned NumProtoRefs = Record[Idx++];
579 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
580 ProtoRefs.reserve(NumProtoRefs);
581 for (unsigned I = 0; I != NumProtoRefs; ++I)
582 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000583 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
584 ProtoLocs.reserve(NumProtoRefs);
585 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000586 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000587 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
588 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000589 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000590 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000591 CD->setAtLoc(ReadSourceLocation(Record, Idx));
592 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000593}
594
Sebastian Redlb3298c32010-08-18 23:56:48 +0000595void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000596 VisitNamedDecl(CAD);
597 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
598}
599
Sebastian Redlb3298c32010-08-18 23:56:48 +0000600void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000601 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000602 D->setAtLoc(ReadSourceLocation(Record, Idx));
603 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000604 // FIXME: stable encoding
605 D->setPropertyAttributes(
606 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000607 D->setPropertyAttributesAsWritten(
608 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000609 // FIXME: stable encoding
610 D->setPropertyImplementation(
611 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
612 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
613 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
614 D->setGetterMethodDecl(
615 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
616 D->setSetterMethodDecl(
617 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
618 D->setPropertyIvarDecl(
619 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
620}
621
Sebastian Redlb3298c32010-08-18 23:56:48 +0000622void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000623 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000624 D->setClassInterface(
625 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000626}
627
Sebastian Redlb3298c32010-08-18 23:56:48 +0000628void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000629 VisitObjCImplDecl(D);
630 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
631}
632
Sebastian Redlb3298c32010-08-18 23:56:48 +0000633void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000634 VisitObjCImplDecl(D);
635 D->setSuperClass(
636 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000637 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000638 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000639 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000640}
641
642
Sebastian Redlb3298c32010-08-18 23:56:48 +0000643void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000644 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000645 D->setAtLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000646 D->setPropertyDecl(
647 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000648 D->PropertyIvarDecl =
649 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]));
650 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000651 D->setGetterCXXConstructor(Reader.ReadExpr(F));
652 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000653}
654
Sebastian Redlb3298c32010-08-18 23:56:48 +0000655void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000656 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000657 FD->setMutable(Record[Idx++]);
658 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000659 FD->setBitWidth(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000660 if (!FD->getDeclName()) {
661 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
662 if (Tmpl)
663 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
664 }
Chris Lattner487412d2009-04-27 05:27:42 +0000665}
666
Francois Pichet783dd6e2010-11-21 06:08:52 +0000667void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
668 VisitValueDecl(FD);
669
670 FD->ChainingSize = Record[Idx++];
671 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
672 FD->Chaining = new (*Reader.getContext())NamedDecl*[FD->ChainingSize];
673
674 for (unsigned I = 0; I != FD->ChainingSize; ++I)
675 FD->Chaining[I] = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
676}
677
Sebastian Redlb3298c32010-08-18 23:56:48 +0000678void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000679 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000680 VisitRedeclarable(VD);
Douglas Gregorbf62d642010-12-06 18:36:25 +0000681 VD->SClass = (StorageClass)Record[Idx++];
John McCall8e7d6562010-08-26 03:08:43 +0000682 VD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000683 VD->setThreadSpecified(Record[Idx++]);
684 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000685 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000686 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000687 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000688 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000689
690 if (Record[Idx++]) { // HasMemberSpecializationInfo.
691 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
692 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000693 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000694 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
695 }
Chris Lattner487412d2009-04-27 05:27:42 +0000696}
697
Sebastian Redlb3298c32010-08-18 23:56:48 +0000698void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000699 VisitVarDecl(PD);
700}
701
Sebastian Redlb3298c32010-08-18 23:56:48 +0000702void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000703 VisitVarDecl(PD);
704 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000705 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000706 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000707 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000708}
709
Sebastian Redlb3298c32010-08-18 23:56:48 +0000710void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000711 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000712 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Abramo Bagnara348823a2011-03-03 14:20:18 +0000713 AD->setRParenLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000714}
715
Sebastian Redlb3298c32010-08-18 23:56:48 +0000716void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000717 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000718 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
719 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000720 unsigned NumParams = Record[Idx++];
721 llvm::SmallVector<ParmVarDecl *, 16> Params;
722 Params.reserve(NumParams);
723 for (unsigned I = 0; I != NumParams; ++I)
724 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000725 BD->setParams(Params.data(), NumParams);
John McCallc63de662011-02-02 13:00:07 +0000726
727 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000728 unsigned numCaptures = Record[Idx++];
729 llvm::SmallVector<BlockDecl::Capture, 16> captures;
730 captures.reserve(numCaptures);
731 for (unsigned i = 0; i != numCaptures; ++i) {
732 VarDecl *decl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
733 unsigned flags = Record[Idx++];
734 bool byRef = (flags & 1);
735 bool nested = (flags & 2);
736 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
737
738 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
739 }
740 BD->setCaptures(*Reader.getContext(), captures.begin(),
741 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000742}
743
Sebastian Redlb3298c32010-08-18 23:56:48 +0000744void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000745 VisitDecl(D);
746 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000747 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000748}
749
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000750void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
751 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000752 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000753}
754
755
Sebastian Redlb3298c32010-08-18 23:56:48 +0000756void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000757 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000758 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000759 D->LocStart = ReadSourceLocation(Record, Idx);
760 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000761 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000762
Chris Lattnerca025db2010-05-07 21:43:38 +0000763 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000764 D->OrigOrAnonNamespace.setInt(IsOriginal);
765 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000766 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
767}
768
Sebastian Redlb3298c32010-08-18 23:56:48 +0000769void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000770 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000771 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000772 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000773 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000774 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000775}
776
Sebastian Redlb3298c32010-08-18 23:56:48 +0000777void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000778 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000779 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000780 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000781 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000782 D->FirstUsingShadow = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000783 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000784 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
785 if (Pattern)
786 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000787}
788
Sebastian Redlb3298c32010-08-18 23:56:48 +0000789void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000790 VisitNamedDecl(D);
791 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000792 D->UsingOrNextShadow = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000793 UsingShadowDecl *Pattern
794 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
795 if (Pattern)
796 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000797}
798
Sebastian Redlb3298c32010-08-18 23:56:48 +0000799void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000800 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000801 D->UsingLoc = ReadSourceLocation(Record, Idx);
802 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000803 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor01a430132010-09-01 03:07:18 +0000804 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
805 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000806}
807
Sebastian Redlb3298c32010-08-18 23:56:48 +0000808void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000809 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000810 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000811 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000812 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000813}
814
Sebastian Redlb3298c32010-08-18 23:56:48 +0000815void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000816 UnresolvedUsingTypenameDecl *D) {
817 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000818 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000819 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000820}
821
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000822void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000823 struct CXXRecordDecl::DefinitionData &Data,
824 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000825 Data.UserDeclaredConstructor = Record[Idx++];
826 Data.UserDeclaredCopyConstructor = Record[Idx++];
827 Data.UserDeclaredCopyAssignment = Record[Idx++];
828 Data.UserDeclaredDestructor = Record[Idx++];
829 Data.Aggregate = Record[Idx++];
830 Data.PlainOldData = Record[Idx++];
831 Data.Empty = Record[Idx++];
832 Data.Polymorphic = Record[Idx++];
833 Data.Abstract = Record[Idx++];
834 Data.HasTrivialConstructor = Record[Idx++];
835 Data.HasTrivialCopyConstructor = Record[Idx++];
836 Data.HasTrivialCopyAssignment = Record[Idx++];
837 Data.HasTrivialDestructor = Record[Idx++];
838 Data.ComputedVisibleConversions = Record[Idx++];
839 Data.DeclaredDefaultConstructor = Record[Idx++];
840 Data.DeclaredCopyConstructor = Record[Idx++];
841 Data.DeclaredCopyAssignment = Record[Idx++];
842 Data.DeclaredDestructor = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000843
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000844 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000845 if (Data.NumBases)
846 Data.Bases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000847 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000848 if (Data.NumVBases)
849 Data.VBases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
850
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000851 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
852 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
853 assert(Data.Definition && "Data.Definition should be already set!");
854 Data.FirstFriend
855 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
856}
857
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000858void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
859 CXXRecordDecl *DefinitionDecl,
860 const RecordData &Record,
861 unsigned &Idx) {
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000862 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000863
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000864 if (D == DefinitionDecl) {
865 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000866 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000867 // We read the definition info. Check if there are pending forward
868 // references that need to point to this DefinitionData pointer.
869 ASTReader::PendingForwardRefsMap::iterator
870 FindI = Reader.PendingForwardRefs.find(D);
871 if (FindI != Reader.PendingForwardRefs.end()) {
872 ASTReader::ForwardRefs &Refs = FindI->second;
873 for (ASTReader::ForwardRefs::iterator
874 I = Refs.begin(), E = Refs.end(); I != E; ++I)
875 (*I)->DefinitionData = D->DefinitionData;
876#ifndef NDEBUG
877 // We later check whether PendingForwardRefs is empty to make sure all
878 // pending references were linked.
879 Reader.PendingForwardRefs.erase(D);
880#endif
881 }
882 } else if (DefinitionDecl) {
883 if (DefinitionDecl->DefinitionData) {
884 D->DefinitionData = DefinitionDecl->DefinitionData;
885 } else {
886 // The definition is still initializing.
887 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
888 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000889 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000890}
891
892void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
893 VisitRecordDecl(D);
894
895 CXXRecordDecl *DefinitionDecl
896 = cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
897 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
898
899 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000900
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000901 enum CXXRecKind {
902 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
903 };
904 switch ((CXXRecKind)Record[Idx++]) {
905 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000906 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000907 case CXXRecNotTemplate:
908 break;
909 case CXXRecTemplate:
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000910 D->TemplateOrInstantiation
911 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000912 break;
913 case CXXRecMemberSpecialization: {
914 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
915 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000916 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000917 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
918 MSI->setPointOfInstantiation(POI);
919 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000920 break;
921 }
922 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +0000923
924 // Load the key function to avoid deserializing every method so we can
925 // compute it.
926 if (D->IsDefinition) {
927 CXXMethodDecl *Key
928 = cast_or_null<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
929 if (Key)
930 C.KeyFunctions[D] = Key;
931 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000932}
933
Sebastian Redlb3298c32010-08-18 23:56:48 +0000934void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000935 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000936 unsigned NumOverridenMethods = Record[Idx++];
937 while (NumOverridenMethods--) {
938 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
939 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
940 // MD may be initializing.
941 Reader.getContext()->addOverriddenMethod(D, MD);
942 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000943}
944
Sebastian Redlb3298c32010-08-18 23:56:48 +0000945void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000946 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000947
948 D->IsExplicitSpecified = Record[Idx++];
949 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +0000950 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
951 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000952}
953
Sebastian Redlb3298c32010-08-18 23:56:48 +0000954void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000955 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000956
957 D->ImplicitlyDefined = Record[Idx++];
958 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000959}
960
Sebastian Redlb3298c32010-08-18 23:56:48 +0000961void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000962 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000963 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000964}
965
Sebastian Redlb3298c32010-08-18 23:56:48 +0000966void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +0000967 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000968 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +0000969}
970
Sebastian Redlb3298c32010-08-18 23:56:48 +0000971void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000972 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000973 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000974 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000975 else
976 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Douglas Gregore0fb32c2010-10-27 20:23:41 +0000977 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +0000978 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000979 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000980}
981
Sebastian Redlb3298c32010-08-18 23:56:48 +0000982void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000983 VisitDecl(D);
984 unsigned NumParams = Record[Idx++];
985 D->NumParams = NumParams;
986 D->Params = new TemplateParameterList*[NumParams];
987 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000988 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000989 if (Record[Idx++]) // HasFriendDecl
990 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
991 else
Sebastian Redl2c373b92010-10-05 15:59:54 +0000992 D->Friend = GetTypeSourceInfo(Record, Idx);
993 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000994}
995
Sebastian Redlb3298c32010-08-18 23:56:48 +0000996void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000997 VisitNamedDecl(D);
998
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000999 NamedDecl *TemplatedDecl
1000 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001001 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001002 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001003 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001004}
1005
Sebastian Redlb3298c32010-08-18 23:56:48 +00001006void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001007 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1008 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001009
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001010 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001011 DeclID PreviousDeclID = Record[Idx++];
1012 DeclID FirstDeclID = PreviousDeclID ? Record[Idx++] : 0;
1013 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1014 // We temporarily set the first (canonical) declaration as the previous one
1015 // which is the one that matters and mark the real previous DeclID to be
1016 // loaded & attached later on.
1017 RedeclarableTemplateDecl *FirstDecl =
1018 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1019 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1020 "FirstDecl kind mismatch");
1021 if (FirstDecl) {
1022 D->CommonOrPrev = FirstDecl;
1023 // Mark the real previous DeclID to be loaded & attached later on.
1024 if (PreviousDeclID != FirstDeclID)
1025 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1026 } else {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001027 D->CommonOrPrev = D->newCommon(*Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001028 if (RedeclarableTemplateDecl *RTD
1029 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
1030 assert(RTD->getKind() == D->getKind() &&
1031 "InstantiatedFromMemberTemplate kind mismatch");
1032 D->setInstantiatedFromMemberTemplateImpl(RTD);
1033 if (Record[Idx++])
1034 D->setMemberSpecialization();
1035 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001036
1037 RedeclarableTemplateDecl *LatestDecl =
1038 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001039
1040 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001041 // in the same AST file. However, if this actually needs to point to a
1042 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001043 // the FirstLatestDeclIDs map which tracks this kind of decls.
1044 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001045 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001046 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1047 if (I != Reader.FirstLatestDeclIDs.end()) {
1048 Decl *NewLatest = Reader.GetDecl(I->second);
1049 assert((LatestDecl->getLocation().isInvalid() ||
1050 NewLatest->getLocation().isInvalid() ||
Argyrios Kyrtzidis54b88e72010-10-20 23:48:40 +00001051 !Reader.SourceMgr.isBeforeInTranslationUnit(
1052 NewLatest->getLocation(),
1053 LatestDecl->getLocation())) &&
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001054 "The new latest is supposed to come after the previous latest");
1055 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
1056 }
1057
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001058 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1059 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001060 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001061
1062 VisitTemplateDecl(D);
1063 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001064}
1065
Sebastian Redlb3298c32010-08-18 23:56:48 +00001066void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001067 VisitRedeclarableTemplateDecl(D);
1068
1069 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001070 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1071 // the specializations.
1072 llvm::SmallVector<serialization::DeclID, 2> SpecIDs;
1073 SpecIDs.push_back(0);
1074
1075 // Specializations.
1076 unsigned Size = Record[Idx++];
1077 SpecIDs[0] += Size;
1078 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1079 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001080
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001081 // Partial specializations.
1082 Size = Record[Idx++];
1083 SpecIDs[0] += Size;
1084 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1085 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001086
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001087 if (SpecIDs[0]) {
1088 typedef serialization::DeclID DeclID;
1089
1090 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1091 CommonPtr->LazySpecializations
1092 = new (*Reader.getContext()) DeclID [SpecIDs.size()];
1093 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1094 SpecIDs.size() * sizeof(DeclID));
1095 }
1096
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001097 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001098 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001099}
1100
Sebastian Redlb3298c32010-08-18 23:56:48 +00001101void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001102 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001103 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001104
1105 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001106 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
1107 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001108 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001109 } else {
1110 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001111 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001112 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001113 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1114 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001115 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1116 = new (C) ClassTemplateSpecializationDecl::
1117 SpecializedPartialSpecialization();
1118 PS->PartialSpecialization
1119 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1120 PS->TemplateArgs = ArgList;
1121 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001122 }
1123 }
1124
1125 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001126 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001127 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1128 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1129 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001130 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1131 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001132 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001133 }
1134
1135 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001136 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001137 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1138 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001139 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001140 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001141
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001142 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001143 ClassTemplateDecl *CanonPattern
1144 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
1145 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001146 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1147 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001148 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001149 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001150 }
1151 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001152}
1153
Sebastian Redlb3298c32010-08-18 23:56:48 +00001154void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001155 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001156 VisitClassTemplateSpecializationDecl(D);
1157
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001158 ASTContext &C = *Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001159 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001160
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001161 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001162 if (NumArgs) {
1163 D->NumArgsAsWritten = NumArgs;
1164 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1165 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001166 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001167 }
1168
1169 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001170
1171 // These are read/set from/to the first declaration.
1172 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001173 D->InstantiatedFromMember.setPointer(
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001174 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1175 Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001176 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001177 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001178}
1179
Sebastian Redlb3298c32010-08-18 23:56:48 +00001180void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001181 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001182
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001183 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001184 // This FunctionTemplateDecl owns a CommonPtr; read it.
1185
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001186 // Read the function specialization declarations.
1187 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001188 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001189 unsigned NumSpecs = Record[Idx++];
1190 while (NumSpecs--)
1191 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001192 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001193}
1194
Sebastian Redlb3298c32010-08-18 23:56:48 +00001195void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001196 VisitTypeDecl(D);
1197
1198 D->setDeclaredWithTypename(Record[Idx++]);
1199 D->setParameterPack(Record[Idx++]);
1200
1201 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001202 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001203 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001204}
1205
Sebastian Redlb3298c32010-08-18 23:56:48 +00001206void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001207 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001208 // TemplateParmPosition.
1209 D->setDepth(Record[Idx++]);
1210 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001211 if (D->isExpandedParameterPack()) {
1212 void **Data = reinterpret_cast<void **>(D + 1);
1213 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1214 Data[2*I] = Reader.GetType(Record[Idx++]).getAsOpaquePtr();
1215 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1216 }
1217 } else {
1218 // Rest of NonTypeTemplateParmDecl.
1219 D->ParameterPack = Record[Idx++];
1220 if (Record[Idx++]) {
1221 Expr *DefArg = Reader.ReadExpr(F);
1222 bool Inherited = Record[Idx++];
1223 D->setDefaultArgument(DefArg, Inherited);
1224 }
1225 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001226}
1227
Sebastian Redlb3298c32010-08-18 23:56:48 +00001228void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001229 VisitTemplateDecl(D);
1230 // TemplateParmPosition.
1231 D->setDepth(Record[Idx++]);
1232 D->setPosition(Record[Idx++]);
1233 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001234 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001235 bool IsInherited = Record[Idx++];
1236 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001237 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001238}
1239
Sebastian Redlb3298c32010-08-18 23:56:48 +00001240void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001241 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001242 D->AssertExpr = Reader.ReadExpr(F);
1243 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Chris Lattnerca025db2010-05-07 21:43:38 +00001244}
1245
Mike Stump11289f42009-09-09 15:08:12 +00001246std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001247ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001248 uint64_t LexicalOffset = Record[Idx++];
1249 uint64_t VisibleOffset = Record[Idx++];
1250 return std::make_pair(LexicalOffset, VisibleOffset);
1251}
1252
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001253template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001254void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001255 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1256 RedeclKind Kind = (RedeclKind)Record[Idx++];
1257 switch (Kind) {
1258 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +00001259 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001260 " reading");
1261 case NoRedeclaration:
1262 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001263 case PointsToPrevious: {
1264 DeclID PreviousDeclID = Record[Idx++];
1265 DeclID FirstDeclID = Record[Idx++];
1266 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1267 // We temporarily set the first (canonical) declaration as the previous one
1268 // which is the one that matters and mark the real previous DeclID to be
1269 // loaded & attached later on.
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001270 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001271 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1272 if (PreviousDeclID != FirstDeclID)
1273 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1274 PreviousDeclID));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001275 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001276 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001277 case PointsToLatest:
1278 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1279 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1280 break;
1281 }
1282
1283 assert(!(Kind == PointsToPrevious &&
1284 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1285 Reader.FirstLatestDeclIDs.end()) &&
1286 "This decl is not first, it should not be in the map");
1287 if (Kind == PointsToPrevious)
1288 return;
1289
1290 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001291 // the same AST file. However, if this actually needs to point to a
1292 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001293 // FirstLatestDeclIDs map which tracks this kind of decls.
1294 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1295 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001296 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001297 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1298 if (I != Reader.FirstLatestDeclIDs.end()) {
1299 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001300 D->RedeclLink
1301 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1302 }
1303}
1304
Chris Lattner487412d2009-04-27 05:27:42 +00001305//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001306// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001307//===----------------------------------------------------------------------===//
1308
Chris Lattner8f63ab52009-04-27 06:01:06 +00001309/// \brief Reads attributes from the current stream position.
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001310void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs,
1311 const RecordData &Record, unsigned &Idx) {
1312 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001313 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001314 attr::Kind Kind = (attr::Kind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001315 SourceLocation Loc = ReadSourceLocation(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001316
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001317#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001318
1319 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001320 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001321 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001322}
1323
1324//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001325// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001326//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001327
1328/// \brief Note that we have loaded the declaration with the given
1329/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001330///
Chris Lattner487412d2009-04-27 05:27:42 +00001331/// This routine notes that this declaration has already been loaded,
1332/// so that future GetDecl calls will return this declaration rather
1333/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001334inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001335 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1336 DeclsLoaded[Index] = D;
1337}
1338
1339
1340/// \brief Determine whether the consumer will be interested in seeing
1341/// this declaration (via HandleTopLevelDecl).
1342///
1343/// This routine should return true for anything that might affect
1344/// code generation, e.g., inline function definitions, Objective-C
1345/// declarations with metadata, etc.
1346static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001347 if (isa<FileScopeAsmDecl>(D))
1348 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001349 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001350 return Var->isFileVarDecl() &&
1351 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001352 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1353 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001354 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001355}
1356
Sebastian Redl34627792010-07-20 22:46:15 +00001357/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001358ASTReader::RecordLocation
Sebastian Redl539c5062010-08-18 23:57:32 +00001359ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001360 // See if there's an override.
1361 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1362 if (It != ReplacedDecls.end())
Sebastian Redl2c373b92010-10-05 15:59:54 +00001363 return RecordLocation(It->second.first, It->second.second);
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001364
Sebastian Redl34627792010-07-20 22:46:15 +00001365 PerFileData *F = 0;
1366 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1367 F = Chain[N - I - 1];
1368 if (Index < F->LocalNumDecls)
1369 break;
1370 Index -= F->LocalNumDecls;
1371 }
1372 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redl2c373b92010-10-05 15:59:54 +00001373 return RecordLocation(F, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001374}
1375
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001376void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1377 assert(D && previous);
1378 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1379 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1380 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1381 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1382 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1383 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1384 } else {
1385 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1386 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1387 }
1388}
1389
1390void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1391 Decl *previous = GetDecl(ID);
1392 ASTDeclReader::attachPreviousDecl(D, previous);
1393}
1394
Sebastian Redlb3298c32010-08-18 23:56:48 +00001395/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl539c5062010-08-18 23:57:32 +00001396Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001397 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001398 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001399 // Keep track of where we are in the stream, then jump back there
1400 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001401 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001402
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001403 ReadingKindTracker ReadingKind(Read_Decl, *this);
1404
Douglas Gregor1342e842009-07-06 18:54:52 +00001405 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001406 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001407
Sebastian Redl2c373b92010-10-05 15:59:54 +00001408 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001409 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001410 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001411 unsigned Idx = 0;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001412 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001413
Chris Lattner1de76db2009-04-27 05:58:23 +00001414 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001415 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001416 case DECL_CONTEXT_LEXICAL:
1417 case DECL_CONTEXT_VISIBLE:
Chris Lattner487412d2009-04-27 05:27:42 +00001418 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1419 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001420 case DECL_TRANSLATION_UNIT:
Chris Lattner487412d2009-04-27 05:27:42 +00001421 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001422 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001423 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001424 case DECL_TYPEDEF:
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001425 D = TypedefDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1426 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001427 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001428 case DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001429 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001430 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001431 case DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001432 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001433 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001434 case DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001435 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001436 0, llvm::APSInt());
1437 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001438 case DECL_FUNCTION:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001439 D = FunctionDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1440 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001441 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001442 case DECL_LINKAGE_SPEC:
Chris Lattnerca025db2010-05-07 21:43:38 +00001443 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1444 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001445 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001446 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001447 case DECL_LABEL:
1448 D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
1449 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001450 case DECL_NAMESPACE:
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001451 D = NamespaceDecl::Create(*Context, 0, SourceLocation(),
1452 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001453 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001454 case DECL_NAMESPACE_ALIAS:
Chris Lattnerca025db2010-05-07 21:43:38 +00001455 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001456 SourceLocation(), 0,
1457 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001458 SourceLocation(), 0);
1459 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001460 case DECL_USING:
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001461 D = UsingDecl::Create(*Context, 0, SourceLocation(),
1462 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1463 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001464 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001465 case DECL_USING_SHADOW:
Chris Lattnerca025db2010-05-07 21:43:38 +00001466 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1467 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001468 case DECL_USING_DIRECTIVE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001469 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001470 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001471 SourceLocation(), 0, 0);
1472 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001473 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001474 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001475 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001476 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001477 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001478 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattnerca025db2010-05-07 21:43:38 +00001479 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001480 SourceLocation(),
1481 NestedNameSpecifierLoc(),
1482 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001483 DeclarationName());
1484 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001485 case DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001486 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001487 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001488 case DECL_CXX_METHOD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001489 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(),
1490 DeclarationNameInfo(), QualType(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001491 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001492 case DECL_CXX_CONSTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001493 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1494 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001495 case DECL_CXX_DESTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001496 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1497 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001498 case DECL_CXX_CONVERSION:
Chris Lattnerca025db2010-05-07 21:43:38 +00001499 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1500 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001501 case DECL_ACCESS_SPEC:
Argyrios Kyrtzidis260b4a82010-09-08 21:32:35 +00001502 D = AccessSpecDecl::Create(*Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001503 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001504 case DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001505 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001506 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001507 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001508 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001509 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001510 case DECL_CLASS_TEMPLATE:
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001511 D = ClassTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001512 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001513 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001514 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001515 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001516 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001517 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001518 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001519 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001520 case DECL_FUNCTION_TEMPLATE:
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001521 D = FunctionTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001522 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001523 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001524 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001525 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001526 case DECL_NON_TYPE_TEMPLATE_PARM:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001527 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(),
1528 SourceLocation(), 0, 0, 0, QualType(),
1529 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001530 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001531 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001532 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(),
1533 SourceLocation(), 0, 0, 0, QualType(),
1534 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001535 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001536 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregorf5500772011-01-05 15:48:55 +00001537 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1538 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001539 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001540 case DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001541 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001542 break;
1543
Sebastian Redl539c5062010-08-18 23:57:32 +00001544 case DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001545 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001546 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001547 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001548 case DECL_OBJC_INTERFACE:
Douglas Gregor1c283312010-08-11 12:19:30 +00001549 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001550 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001551 case DECL_OBJC_IVAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001552 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1553 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001554 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001555 case DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001556 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001557 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001558 case DECL_OBJC_AT_DEFS_FIELD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001559 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(),
1560 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001561 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001562 case DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001563 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001564 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001565 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001566 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001567 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001568 case DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001569 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1570 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001571 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001572 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001573 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001574 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001575 case DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001576 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001577 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001578 case DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001579 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001580 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001581 case DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001582 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001583 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001584 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001585 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001586 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001587 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001588 ObjCPropertyImplDecl::Dynamic, 0,
1589 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001590 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001591 case DECL_FIELD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001592 D = FieldDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1593 QualType(), 0, 0, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001594 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001595 case DECL_INDIRECTFIELD:
1596 D = IndirectFieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
1597 0, 0);
1598 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001599 case DECL_VAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001600 D = VarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1601 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001602 break;
1603
Sebastian Redl539c5062010-08-18 23:57:32 +00001604 case DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001605 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001606 break;
1607
Sebastian Redl539c5062010-08-18 23:57:32 +00001608 case DECL_PARM_VAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001609 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1610 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001611 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001612 case DECL_FILE_SCOPE_ASM:
Abramo Bagnara348823a2011-03-03 14:20:18 +00001613 D = FileScopeAsmDecl::Create(*Context, 0, 0, SourceLocation(),
1614 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001615 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001616 case DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001617 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001618 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001619 case DECL_CXX_BASE_SPECIFIERS:
1620 Error("attempt to read a C++ base-specifier record as a declaration");
1621 return 0;
Chris Lattner487412d2009-04-27 05:27:42 +00001622 }
Chris Lattner487412d2009-04-27 05:27:42 +00001623
Sebastian Redlb3298c32010-08-18 23:56:48 +00001624 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001625 LoadedDecl(Index, D);
1626 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001627
1628 // If this declaration is also a declaration context, get the
1629 // offsets for its tables of lexical and visible declarations.
1630 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1631 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1632 if (Offsets.first || Offsets.second) {
1633 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1634 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001635 DeclContextInfo Info;
1636 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1637 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001638 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001639 // Reading the TU will happen after reading its lexical update blocks,
1640 // so we need to make sure we insert in front. For all other contexts,
1641 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001642 Infos.insert(Infos.begin(), Info);
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001643
1644 // Now add the pending visible updates for this decl context, if it has
1645 // any.
1646 DeclContextVisibleUpdatesPending::iterator I =
1647 PendingVisibleUpdates.find(ID);
1648 if (I != PendingVisibleUpdates.end()) {
1649 DeclContextVisibleUpdates &U = I->second;
1650 Info.LexicalDecls = 0;
1651 Info.NumLexicalDecls = 0;
1652 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1653 UI != UE; ++UI) {
1654 Info.NameLookupTableData = *UI;
1655 Infos.push_back(Info);
1656 }
1657 PendingVisibleUpdates.erase(I);
1658 }
Chris Lattner487412d2009-04-27 05:27:42 +00001659 }
1660 }
1661 assert(Idx == Record.size());
1662
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001663 // The declaration may have been modified by files later in the chain.
1664 // If this is the case, read the record containing the updates from each file
1665 // and pass it to ASTDeclReader to make the modifications.
1666 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1667 if (UpdI != DeclUpdateOffsets.end()) {
1668 FileOffsetsTy &UpdateOffsets = UpdI->second;
1669 for (FileOffsetsTy::iterator
1670 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
1671 PerFileData *F = I->first;
1672 uint64_t Offset = I->second;
1673 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1674 SavedStreamPosition SavedPosition(Cursor);
1675 Cursor.JumpToBit(Offset);
1676 RecordData Record;
1677 unsigned Code = Cursor.ReadCode();
1678 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1679 (void)RecCode;
1680 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
1681 Reader.UpdateDecl(D, Record);
1682 }
1683 }
1684
Chris Lattner487412d2009-04-27 05:27:42 +00001685 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001686 // AST consumer might need to know about, queue it.
1687 // We don't pass it to the consumer immediately because we may be in recursive
1688 // loading, and some declarations may still be initializing.
1689 if (isConsumerInterestedIn(D))
1690 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001691
1692 return D;
1693}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001694
1695void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001696 unsigned Idx = 0;
1697 while (Idx < Record.size()) {
1698 switch ((DeclUpdateKind)Record[Idx++]) {
1699 case UPD_CXX_SET_DEFINITIONDATA: {
1700 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
1701 CXXRecordDecl *
1702 DefinitionDecl = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
1703 assert(!RD->DefinitionData && "DefinitionData is already set!");
1704 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1705 break;
1706 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001707
1708 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
1709 cast<CXXRecordDecl>(D)->addedMember(Reader.GetDecl(Record[Idx++]));
1710 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00001711
1712 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1713 // It will be added to the template's specializations set when loaded.
1714 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001715 }
1716 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001717}