blob: 8d32bde5fcadbce8e6acc89cd1849beca77aaefc [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 Bagnaraea947882011-03-08 16:41:52 +0000747 D->setExternLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000748 D->setRBraceLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000749}
750
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000751void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
752 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000753 D->setLocStart(ReadSourceLocation(Record, Idx));
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000754}
755
756
Sebastian Redlb3298c32010-08-18 23:56:48 +0000757void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000758 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000759 D->IsInline = Record[Idx++];
Abramo Bagnarab5545be2011-03-08 12:38:20 +0000760 D->LocStart = ReadSourceLocation(Record, Idx);
761 D->RBraceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor417e87c2010-10-27 19:49:05 +0000762 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000763
Chris Lattnerca025db2010-05-07 21:43:38 +0000764 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000765 D->OrigOrAnonNamespace.setInt(IsOriginal);
766 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000767 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
768}
769
Sebastian Redlb3298c32010-08-18 23:56:48 +0000770void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000771 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000772 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000773 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +0000774 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000775 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000776}
777
Sebastian Redlb3298c32010-08-18 23:56:48 +0000778void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000779 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000780 D->setUsingLocation(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000781 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000782 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000783 D->FirstUsingShadow = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000784 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000785 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
786 if (Pattern)
787 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000788}
789
Sebastian Redlb3298c32010-08-18 23:56:48 +0000790void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000791 VisitNamedDecl(D);
792 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000793 D->UsingOrNextShadow = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000794 UsingShadowDecl *Pattern
795 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
796 if (Pattern)
797 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000798}
799
Sebastian Redlb3298c32010-08-18 23:56:48 +0000800void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000801 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000802 D->UsingLoc = ReadSourceLocation(Record, Idx);
803 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
Douglas Gregor12441b32011-02-25 16:33:46 +0000804 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Douglas Gregor01a430132010-09-01 03:07:18 +0000805 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
806 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000807}
808
Sebastian Redlb3298c32010-08-18 23:56:48 +0000809void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000810 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000811 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000812 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000813 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000814}
815
Sebastian Redlb3298c32010-08-18 23:56:48 +0000816void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000817 UnresolvedUsingTypenameDecl *D) {
818 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000819 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9d87bc2011-02-25 00:36:19 +0000820 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000821}
822
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000823void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000824 struct CXXRecordDecl::DefinitionData &Data,
825 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000826 Data.UserDeclaredConstructor = Record[Idx++];
827 Data.UserDeclaredCopyConstructor = Record[Idx++];
828 Data.UserDeclaredCopyAssignment = Record[Idx++];
829 Data.UserDeclaredDestructor = Record[Idx++];
830 Data.Aggregate = Record[Idx++];
831 Data.PlainOldData = Record[Idx++];
832 Data.Empty = Record[Idx++];
833 Data.Polymorphic = Record[Idx++];
834 Data.Abstract = Record[Idx++];
835 Data.HasTrivialConstructor = Record[Idx++];
836 Data.HasTrivialCopyConstructor = Record[Idx++];
837 Data.HasTrivialCopyAssignment = Record[Idx++];
838 Data.HasTrivialDestructor = Record[Idx++];
839 Data.ComputedVisibleConversions = Record[Idx++];
840 Data.DeclaredDefaultConstructor = Record[Idx++];
841 Data.DeclaredCopyConstructor = Record[Idx++];
842 Data.DeclaredCopyAssignment = Record[Idx++];
843 Data.DeclaredDestructor = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000844
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000845 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000846 if (Data.NumBases)
847 Data.Bases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000848 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000849 if (Data.NumVBases)
850 Data.VBases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
851
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000852 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
853 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
854 assert(Data.Definition && "Data.Definition should be already set!");
855 Data.FirstFriend
856 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
857}
858
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000859void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
860 CXXRecordDecl *DefinitionDecl,
861 const RecordData &Record,
862 unsigned &Idx) {
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000863 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000864
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000865 if (D == DefinitionDecl) {
866 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000867 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000868 // We read the definition info. Check if there are pending forward
869 // references that need to point to this DefinitionData pointer.
870 ASTReader::PendingForwardRefsMap::iterator
871 FindI = Reader.PendingForwardRefs.find(D);
872 if (FindI != Reader.PendingForwardRefs.end()) {
873 ASTReader::ForwardRefs &Refs = FindI->second;
874 for (ASTReader::ForwardRefs::iterator
875 I = Refs.begin(), E = Refs.end(); I != E; ++I)
876 (*I)->DefinitionData = D->DefinitionData;
877#ifndef NDEBUG
878 // We later check whether PendingForwardRefs is empty to make sure all
879 // pending references were linked.
880 Reader.PendingForwardRefs.erase(D);
881#endif
882 }
883 } else if (DefinitionDecl) {
884 if (DefinitionDecl->DefinitionData) {
885 D->DefinitionData = DefinitionDecl->DefinitionData;
886 } else {
887 // The definition is still initializing.
888 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
889 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000890 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000891}
892
893void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
894 VisitRecordDecl(D);
895
896 CXXRecordDecl *DefinitionDecl
897 = cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
898 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
899
900 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000901
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000902 enum CXXRecKind {
903 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
904 };
905 switch ((CXXRecKind)Record[Idx++]) {
906 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000907 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000908 case CXXRecNotTemplate:
909 break;
910 case CXXRecTemplate:
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000911 D->TemplateOrInstantiation
912 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000913 break;
914 case CXXRecMemberSpecialization: {
915 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
916 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000917 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000918 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
919 MSI->setPointOfInstantiation(POI);
920 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000921 break;
922 }
923 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +0000924
925 // Load the key function to avoid deserializing every method so we can
926 // compute it.
927 if (D->IsDefinition) {
928 CXXMethodDecl *Key
929 = cast_or_null<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
930 if (Key)
931 C.KeyFunctions[D] = Key;
932 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000933}
934
Sebastian Redlb3298c32010-08-18 23:56:48 +0000935void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000936 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000937 unsigned NumOverridenMethods = Record[Idx++];
938 while (NumOverridenMethods--) {
939 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
940 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
941 // MD may be initializing.
942 Reader.getContext()->addOverriddenMethod(D, MD);
943 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000944}
945
Sebastian Redlb3298c32010-08-18 23:56:48 +0000946void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000947 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000948
949 D->IsExplicitSpecified = Record[Idx++];
950 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +0000951 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
952 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000953}
954
Sebastian Redlb3298c32010-08-18 23:56:48 +0000955void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000956 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000957
958 D->ImplicitlyDefined = Record[Idx++];
959 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000960}
961
Sebastian Redlb3298c32010-08-18 23:56:48 +0000962void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000963 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000964 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000965}
966
Sebastian Redlb3298c32010-08-18 23:56:48 +0000967void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +0000968 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000969 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +0000970}
971
Sebastian Redlb3298c32010-08-18 23:56:48 +0000972void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000973 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000974 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000975 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000976 else
977 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Douglas Gregore0fb32c2010-10-27 20:23:41 +0000978 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +0000979 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000980 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000981}
982
Sebastian Redlb3298c32010-08-18 23:56:48 +0000983void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000984 VisitDecl(D);
985 unsigned NumParams = Record[Idx++];
986 D->NumParams = NumParams;
987 D->Params = new TemplateParameterList*[NumParams];
988 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000989 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000990 if (Record[Idx++]) // HasFriendDecl
991 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
992 else
Sebastian Redl2c373b92010-10-05 15:59:54 +0000993 D->Friend = GetTypeSourceInfo(Record, Idx);
994 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000995}
996
Sebastian Redlb3298c32010-08-18 23:56:48 +0000997void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000998 VisitNamedDecl(D);
999
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001000 NamedDecl *TemplatedDecl
1001 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001002 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +00001003 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001004 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +00001005}
1006
Sebastian Redlb3298c32010-08-18 23:56:48 +00001007void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001008 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1009 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001010
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001011 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001012 DeclID PreviousDeclID = Record[Idx++];
1013 DeclID FirstDeclID = PreviousDeclID ? Record[Idx++] : 0;
1014 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1015 // We temporarily set the first (canonical) declaration as the previous one
1016 // which is the one that matters and mark the real previous DeclID to be
1017 // loaded & attached later on.
1018 RedeclarableTemplateDecl *FirstDecl =
1019 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1020 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1021 "FirstDecl kind mismatch");
1022 if (FirstDecl) {
1023 D->CommonOrPrev = FirstDecl;
1024 // Mark the real previous DeclID to be loaded & attached later on.
1025 if (PreviousDeclID != FirstDeclID)
1026 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1027 } else {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001028 D->CommonOrPrev = D->newCommon(*Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001029 if (RedeclarableTemplateDecl *RTD
1030 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
1031 assert(RTD->getKind() == D->getKind() &&
1032 "InstantiatedFromMemberTemplate kind mismatch");
1033 D->setInstantiatedFromMemberTemplateImpl(RTD);
1034 if (Record[Idx++])
1035 D->setMemberSpecialization();
1036 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001037
1038 RedeclarableTemplateDecl *LatestDecl =
1039 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001040
1041 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001042 // in the same AST file. However, if this actually needs to point to a
1043 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001044 // the FirstLatestDeclIDs map which tracks this kind of decls.
1045 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001046 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001047 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1048 if (I != Reader.FirstLatestDeclIDs.end()) {
1049 Decl *NewLatest = Reader.GetDecl(I->second);
1050 assert((LatestDecl->getLocation().isInvalid() ||
1051 NewLatest->getLocation().isInvalid() ||
Argyrios Kyrtzidis54b88e72010-10-20 23:48:40 +00001052 !Reader.SourceMgr.isBeforeInTranslationUnit(
1053 NewLatest->getLocation(),
1054 LatestDecl->getLocation())) &&
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001055 "The new latest is supposed to come after the previous latest");
1056 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
1057 }
1058
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001059 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1060 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001061 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001062
1063 VisitTemplateDecl(D);
1064 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001065}
1066
Sebastian Redlb3298c32010-08-18 23:56:48 +00001067void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001068 VisitRedeclarableTemplateDecl(D);
1069
1070 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001071 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1072 // the specializations.
1073 llvm::SmallVector<serialization::DeclID, 2> SpecIDs;
1074 SpecIDs.push_back(0);
1075
1076 // Specializations.
1077 unsigned Size = Record[Idx++];
1078 SpecIDs[0] += Size;
1079 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1080 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001081
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001082 // Partial specializations.
1083 Size = Record[Idx++];
1084 SpecIDs[0] += Size;
1085 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1086 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001087
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001088 if (SpecIDs[0]) {
1089 typedef serialization::DeclID DeclID;
1090
1091 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1092 CommonPtr->LazySpecializations
1093 = new (*Reader.getContext()) DeclID [SpecIDs.size()];
1094 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1095 SpecIDs.size() * sizeof(DeclID));
1096 }
1097
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001098 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001099 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001100}
1101
Sebastian Redlb3298c32010-08-18 23:56:48 +00001102void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001103 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001104 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001105
1106 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001107 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
1108 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001109 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001110 } else {
1111 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001112 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001113 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001114 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1115 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001116 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1117 = new (C) ClassTemplateSpecializationDecl::
1118 SpecializedPartialSpecialization();
1119 PS->PartialSpecialization
1120 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1121 PS->TemplateArgs = ArgList;
1122 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001123 }
1124 }
1125
1126 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001127 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001128 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1129 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1130 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001131 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1132 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001133 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001134 }
1135
1136 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001137 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001138 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1139 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001140 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001141 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001142
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001143 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001144 ClassTemplateDecl *CanonPattern
1145 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
1146 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001147 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1148 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001149 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001150 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001151 }
1152 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001153}
1154
Sebastian Redlb3298c32010-08-18 23:56:48 +00001155void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001156 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001157 VisitClassTemplateSpecializationDecl(D);
1158
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001159 ASTContext &C = *Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001160 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001161
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001162 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001163 if (NumArgs) {
1164 D->NumArgsAsWritten = NumArgs;
1165 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1166 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001167 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001168 }
1169
1170 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001171
1172 // These are read/set from/to the first declaration.
1173 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001174 D->InstantiatedFromMember.setPointer(
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001175 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1176 Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001177 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001178 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001179}
1180
Sebastian Redlb3298c32010-08-18 23:56:48 +00001181void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001182 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001183
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001184 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001185 // This FunctionTemplateDecl owns a CommonPtr; read it.
1186
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001187 // Read the function specialization declarations.
1188 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001189 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001190 unsigned NumSpecs = Record[Idx++];
1191 while (NumSpecs--)
1192 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001193 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001194}
1195
Sebastian Redlb3298c32010-08-18 23:56:48 +00001196void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001197 VisitTypeDecl(D);
1198
1199 D->setDeclaredWithTypename(Record[Idx++]);
1200 D->setParameterPack(Record[Idx++]);
1201
1202 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001203 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001204 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001205}
1206
Sebastian Redlb3298c32010-08-18 23:56:48 +00001207void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001208 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001209 // TemplateParmPosition.
1210 D->setDepth(Record[Idx++]);
1211 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001212 if (D->isExpandedParameterPack()) {
1213 void **Data = reinterpret_cast<void **>(D + 1);
1214 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1215 Data[2*I] = Reader.GetType(Record[Idx++]).getAsOpaquePtr();
1216 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1217 }
1218 } else {
1219 // Rest of NonTypeTemplateParmDecl.
1220 D->ParameterPack = Record[Idx++];
1221 if (Record[Idx++]) {
1222 Expr *DefArg = Reader.ReadExpr(F);
1223 bool Inherited = Record[Idx++];
1224 D->setDefaultArgument(DefArg, Inherited);
1225 }
1226 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001227}
1228
Sebastian Redlb3298c32010-08-18 23:56:48 +00001229void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001230 VisitTemplateDecl(D);
1231 // TemplateParmPosition.
1232 D->setDepth(Record[Idx++]);
1233 D->setPosition(Record[Idx++]);
1234 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001235 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001236 bool IsInherited = Record[Idx++];
1237 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001238 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001239}
1240
Sebastian Redlb3298c32010-08-18 23:56:48 +00001241void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001242 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001243 D->AssertExpr = Reader.ReadExpr(F);
1244 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Abramo Bagnaraea947882011-03-08 16:41:52 +00001245 D->RParenLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +00001246}
1247
Mike Stump11289f42009-09-09 15:08:12 +00001248std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001249ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001250 uint64_t LexicalOffset = Record[Idx++];
1251 uint64_t VisibleOffset = Record[Idx++];
1252 return std::make_pair(LexicalOffset, VisibleOffset);
1253}
1254
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001255template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001256void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001257 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1258 RedeclKind Kind = (RedeclKind)Record[Idx++];
1259 switch (Kind) {
1260 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +00001261 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001262 " reading");
1263 case NoRedeclaration:
1264 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001265 case PointsToPrevious: {
1266 DeclID PreviousDeclID = Record[Idx++];
1267 DeclID FirstDeclID = Record[Idx++];
1268 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1269 // We temporarily set the first (canonical) declaration as the previous one
1270 // which is the one that matters and mark the real previous DeclID to be
1271 // loaded & attached later on.
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001272 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001273 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1274 if (PreviousDeclID != FirstDeclID)
1275 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1276 PreviousDeclID));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001277 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001278 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001279 case PointsToLatest:
1280 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1281 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1282 break;
1283 }
1284
1285 assert(!(Kind == PointsToPrevious &&
1286 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1287 Reader.FirstLatestDeclIDs.end()) &&
1288 "This decl is not first, it should not be in the map");
1289 if (Kind == PointsToPrevious)
1290 return;
1291
1292 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001293 // the same AST file. However, if this actually needs to point to a
1294 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001295 // FirstLatestDeclIDs map which tracks this kind of decls.
1296 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1297 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001298 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001299 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1300 if (I != Reader.FirstLatestDeclIDs.end()) {
1301 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001302 D->RedeclLink
1303 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1304 }
1305}
1306
Chris Lattner487412d2009-04-27 05:27:42 +00001307//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001308// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001309//===----------------------------------------------------------------------===//
1310
Chris Lattner8f63ab52009-04-27 06:01:06 +00001311/// \brief Reads attributes from the current stream position.
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001312void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs,
1313 const RecordData &Record, unsigned &Idx) {
1314 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001315 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001316 attr::Kind Kind = (attr::Kind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001317 SourceLocation Loc = ReadSourceLocation(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001318
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001319#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001320
1321 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001322 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001323 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001324}
1325
1326//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001327// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001328//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001329
1330/// \brief Note that we have loaded the declaration with the given
1331/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001332///
Chris Lattner487412d2009-04-27 05:27:42 +00001333/// This routine notes that this declaration has already been loaded,
1334/// so that future GetDecl calls will return this declaration rather
1335/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001336inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001337 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1338 DeclsLoaded[Index] = D;
1339}
1340
1341
1342/// \brief Determine whether the consumer will be interested in seeing
1343/// this declaration (via HandleTopLevelDecl).
1344///
1345/// This routine should return true for anything that might affect
1346/// code generation, e.g., inline function definitions, Objective-C
1347/// declarations with metadata, etc.
1348static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001349 if (isa<FileScopeAsmDecl>(D))
1350 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001351 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001352 return Var->isFileVarDecl() &&
1353 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001354 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1355 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001356 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001357}
1358
Sebastian Redl34627792010-07-20 22:46:15 +00001359/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001360ASTReader::RecordLocation
Sebastian Redl539c5062010-08-18 23:57:32 +00001361ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001362 // See if there's an override.
1363 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1364 if (It != ReplacedDecls.end())
Sebastian Redl2c373b92010-10-05 15:59:54 +00001365 return RecordLocation(It->second.first, It->second.second);
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001366
Sebastian Redl34627792010-07-20 22:46:15 +00001367 PerFileData *F = 0;
1368 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1369 F = Chain[N - I - 1];
1370 if (Index < F->LocalNumDecls)
1371 break;
1372 Index -= F->LocalNumDecls;
1373 }
1374 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redl2c373b92010-10-05 15:59:54 +00001375 return RecordLocation(F, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001376}
1377
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001378void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1379 assert(D && previous);
1380 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1381 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1382 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1383 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1384 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1385 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1386 } else {
1387 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1388 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1389 }
1390}
1391
1392void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1393 Decl *previous = GetDecl(ID);
1394 ASTDeclReader::attachPreviousDecl(D, previous);
1395}
1396
Sebastian Redlb3298c32010-08-18 23:56:48 +00001397/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl539c5062010-08-18 23:57:32 +00001398Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001399 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001400 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001401 // Keep track of where we are in the stream, then jump back there
1402 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001403 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001404
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001405 ReadingKindTracker ReadingKind(Read_Decl, *this);
1406
Douglas Gregor1342e842009-07-06 18:54:52 +00001407 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001408 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Sebastian Redl2c373b92010-10-05 15:59:54 +00001410 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001411 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001412 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001413 unsigned Idx = 0;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001414 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001415
Chris Lattner1de76db2009-04-27 05:58:23 +00001416 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001417 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001418 case DECL_CONTEXT_LEXICAL:
1419 case DECL_CONTEXT_VISIBLE:
Chris Lattner487412d2009-04-27 05:27:42 +00001420 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1421 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001422 case DECL_TRANSLATION_UNIT:
Chris Lattner487412d2009-04-27 05:27:42 +00001423 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001424 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001425 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001426 case DECL_TYPEDEF:
Abramo Bagnarab3185b02011-03-06 15:48:19 +00001427 D = TypedefDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1428 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001429 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001430 case DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001431 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001432 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001433 case DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001434 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001435 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001436 case DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001437 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001438 0, llvm::APSInt());
1439 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001440 case DECL_FUNCTION:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001441 D = FunctionDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1442 DeclarationName(), QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001443 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001444 case DECL_LINKAGE_SPEC:
Abramo Bagnaraea947882011-03-08 16:41:52 +00001445 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001446 (LinkageSpecDecl::LanguageIDs)0,
Abramo Bagnara66a35d72011-03-03 16:52:29 +00001447 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001448 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001449 case DECL_LABEL:
1450 D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
1451 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001452 case DECL_NAMESPACE:
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001453 D = NamespaceDecl::Create(*Context, 0, SourceLocation(),
1454 SourceLocation(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001455 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001456 case DECL_NAMESPACE_ALIAS:
Chris Lattnerca025db2010-05-07 21:43:38 +00001457 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001458 SourceLocation(), 0,
1459 NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001460 SourceLocation(), 0);
1461 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001462 case DECL_USING:
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001463 D = UsingDecl::Create(*Context, 0, SourceLocation(),
1464 NestedNameSpecifierLoc(), DeclarationNameInfo(),
1465 false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001466 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001467 case DECL_USING_SHADOW:
Chris Lattnerca025db2010-05-07 21:43:38 +00001468 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1469 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001470 case DECL_USING_DIRECTIVE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001471 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregor12441b32011-02-25 16:33:46 +00001472 SourceLocation(), NestedNameSpecifierLoc(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001473 SourceLocation(), 0, 0);
1474 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001475 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001476 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001477 NestedNameSpecifierLoc(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001478 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001479 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001480 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattnerca025db2010-05-07 21:43:38 +00001481 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001482 SourceLocation(),
1483 NestedNameSpecifierLoc(),
1484 SourceLocation(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001485 DeclarationName());
1486 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001487 case DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001488 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001489 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001490 case DECL_CXX_METHOD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001491 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(),
1492 DeclarationNameInfo(), QualType(), 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001493 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001494 case DECL_CXX_CONSTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001495 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1496 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001497 case DECL_CXX_DESTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001498 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1499 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001500 case DECL_CXX_CONVERSION:
Chris Lattnerca025db2010-05-07 21:43:38 +00001501 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1502 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001503 case DECL_ACCESS_SPEC:
Argyrios Kyrtzidis260b4a82010-09-08 21:32:35 +00001504 D = AccessSpecDecl::Create(*Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001505 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001506 case DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001507 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001508 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001509 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001510 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001511 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001512 case DECL_CLASS_TEMPLATE:
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001513 D = ClassTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001514 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001515 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001516 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001517 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001518 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001519 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001520 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001521 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001522 case DECL_FUNCTION_TEMPLATE:
Douglas Gregorfd7c2252011-03-04 17:52:15 +00001523 D = FunctionTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001524 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001525 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001526 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001527 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001528 case DECL_NON_TYPE_TEMPLATE_PARM:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001529 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(),
1530 SourceLocation(), 0, 0, 0, QualType(),
1531 false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001532 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001533 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001534 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(),
1535 SourceLocation(), 0, 0, 0, QualType(),
1536 0, 0, Record[Idx++], 0);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001537 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001538 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregorf5500772011-01-05 15:48:55 +00001539 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1540 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001541 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001542 case DECL_STATIC_ASSERT:
Abramo Bagnaraea947882011-03-08 16:41:52 +00001543 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1544 SourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001545 break;
1546
Sebastian Redl539c5062010-08-18 23:57:32 +00001547 case DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001548 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001549 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001550 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001551 case DECL_OBJC_INTERFACE:
Douglas Gregor1c283312010-08-11 12:19:30 +00001552 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001553 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001554 case DECL_OBJC_IVAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001555 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
1556 0, QualType(), 0, ObjCIvarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001557 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001558 case DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001559 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001560 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001561 case DECL_OBJC_AT_DEFS_FIELD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001562 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(),
1563 SourceLocation(), 0, QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001564 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001565 case DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001566 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001567 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001568 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001569 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001570 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001571 case DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001572 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1573 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001574 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001575 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001576 D = ObjCCategoryImplDecl::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_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001579 D = ObjCImplementationDecl::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_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001582 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001583 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001584 case DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001585 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001586 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001587 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001588 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001589 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001590 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001591 ObjCPropertyImplDecl::Dynamic, 0,
1592 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001593 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001594 case DECL_FIELD:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001595 D = FieldDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1596 QualType(), 0, 0, false);
Chris Lattner487412d2009-04-27 05:27:42 +00001597 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001598 case DECL_INDIRECTFIELD:
1599 D = IndirectFieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
1600 0, 0);
1601 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001602 case DECL_VAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001603 D = VarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1604 QualType(), 0, SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001605 break;
1606
Sebastian Redl539c5062010-08-18 23:57:32 +00001607 case DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001608 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001609 break;
1610
Sebastian Redl539c5062010-08-18 23:57:32 +00001611 case DECL_PARM_VAR:
Abramo Bagnaradff19302011-03-08 08:55:46 +00001612 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), 0,
1613 QualType(), 0, SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001614 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001615 case DECL_FILE_SCOPE_ASM:
Abramo Bagnara348823a2011-03-03 14:20:18 +00001616 D = FileScopeAsmDecl::Create(*Context, 0, 0, SourceLocation(),
1617 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001618 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001619 case DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001620 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001621 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001622 case DECL_CXX_BASE_SPECIFIERS:
1623 Error("attempt to read a C++ base-specifier record as a declaration");
1624 return 0;
Chris Lattner487412d2009-04-27 05:27:42 +00001625 }
Chris Lattner487412d2009-04-27 05:27:42 +00001626
Sebastian Redlb3298c32010-08-18 23:56:48 +00001627 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001628 LoadedDecl(Index, D);
1629 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001630
1631 // If this declaration is also a declaration context, get the
1632 // offsets for its tables of lexical and visible declarations.
1633 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1634 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1635 if (Offsets.first || Offsets.second) {
1636 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1637 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001638 DeclContextInfo Info;
1639 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1640 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001641 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001642 // Reading the TU will happen after reading its lexical update blocks,
1643 // so we need to make sure we insert in front. For all other contexts,
1644 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001645 Infos.insert(Infos.begin(), Info);
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001646
1647 // Now add the pending visible updates for this decl context, if it has
1648 // any.
1649 DeclContextVisibleUpdatesPending::iterator I =
1650 PendingVisibleUpdates.find(ID);
1651 if (I != PendingVisibleUpdates.end()) {
1652 DeclContextVisibleUpdates &U = I->second;
1653 Info.LexicalDecls = 0;
1654 Info.NumLexicalDecls = 0;
1655 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1656 UI != UE; ++UI) {
1657 Info.NameLookupTableData = *UI;
1658 Infos.push_back(Info);
1659 }
1660 PendingVisibleUpdates.erase(I);
1661 }
Chris Lattner487412d2009-04-27 05:27:42 +00001662 }
1663 }
1664 assert(Idx == Record.size());
1665
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001666 // The declaration may have been modified by files later in the chain.
1667 // If this is the case, read the record containing the updates from each file
1668 // and pass it to ASTDeclReader to make the modifications.
1669 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1670 if (UpdI != DeclUpdateOffsets.end()) {
1671 FileOffsetsTy &UpdateOffsets = UpdI->second;
1672 for (FileOffsetsTy::iterator
1673 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
1674 PerFileData *F = I->first;
1675 uint64_t Offset = I->second;
1676 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1677 SavedStreamPosition SavedPosition(Cursor);
1678 Cursor.JumpToBit(Offset);
1679 RecordData Record;
1680 unsigned Code = Cursor.ReadCode();
1681 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1682 (void)RecCode;
1683 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
1684 Reader.UpdateDecl(D, Record);
1685 }
1686 }
1687
Chris Lattner487412d2009-04-27 05:27:42 +00001688 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001689 // AST consumer might need to know about, queue it.
1690 // We don't pass it to the consumer immediately because we may be in recursive
1691 // loading, and some declarations may still be initializing.
1692 if (isConsumerInterestedIn(D))
1693 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001694
1695 return D;
1696}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001697
1698void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001699 unsigned Idx = 0;
1700 while (Idx < Record.size()) {
1701 switch ((DeclUpdateKind)Record[Idx++]) {
1702 case UPD_CXX_SET_DEFINITIONDATA: {
1703 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
1704 CXXRecordDecl *
1705 DefinitionDecl = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
1706 assert(!RD->DefinitionData && "DefinitionData is already set!");
1707 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1708 break;
1709 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001710
1711 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
1712 cast<CXXRecordDecl>(D)->addedMember(Reader.GetDecl(Record[Idx++]));
1713 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00001714
1715 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1716 // It will be added to the template's specializations set when loaded.
1717 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001718 }
1719 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001720}