blob: 27e771804c91570297d3e632eefffbdbe8c4f843 [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;
Chris Lattner487412d2009-04-27 05:27:42 +000041
Sebastian Redlc67764e2010-07-22 22:43:28 +000042 uint64_t GetCurrentCursorOffset();
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000043 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000044 return Reader.ReadSourceLocation(F, R, I);
45 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000046 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000047 return Reader.ReadSourceRange(F, R, I);
48 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000049 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
Sebastian Redl2c373b92010-10-05 15:59:54 +000050 return Reader.GetTypeSourceInfo(F, R, I);
51 }
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000052 void ReadQualifierInfo(QualifierInfo &Info,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000053 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000054 Reader.ReadQualifierInfo(F, Info, R, I);
55 }
56 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000057 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000058 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
59 }
60 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000061 const RecordData &R, unsigned &I) {
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +000062 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
63 }
Sebastian Redlc67764e2010-07-22 22:43:28 +000064
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +000065 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
66 const RecordData &R, unsigned &I);
67
68 void InitializeCXXDefinitionData(CXXRecordDecl *D,
69 CXXRecordDecl *DefinitionDecl,
70 const RecordData &Record, unsigned &Idx);
Chris Lattner487412d2009-04-27 05:27:42 +000071 public:
Sebastian Redl2c373b92010-10-05 15:59:54 +000072 ASTDeclReader(ASTReader &Reader, ASTReader::PerFileData &F,
73 llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000074 const RecordData &Record, unsigned &Idx)
Sebastian Redl2c373b92010-10-05 15:59:54 +000075 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
76 Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000077
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +000078 static void attachPreviousDecl(Decl *D, Decl *previous);
79
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000080 void Visit(Decl *D);
81
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000082 void UpdateDecl(Decl *D, const RecordData &Record);
83
Chris Lattner487412d2009-04-27 05:27:42 +000084 void VisitDecl(Decl *D);
85 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
86 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000087 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000088 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000089 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
90 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000091 void VisitTypeDecl(TypeDecl *TD);
92 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000093 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000094 void VisitTagDecl(TagDecl *TD);
95 void VisitEnumDecl(EnumDecl *ED);
96 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000097 void VisitCXXRecordDecl(CXXRecordDecl *D);
98 void VisitClassTemplateSpecializationDecl(
99 ClassTemplateSpecializationDecl *D);
100 void VisitClassTemplatePartialSpecializationDecl(
101 ClassTemplatePartialSpecializationDecl *D);
102 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000103 void VisitValueDecl(ValueDecl *VD);
104 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000105 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000106 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000107 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000108 void VisitCXXMethodDecl(CXXMethodDecl *D);
109 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
110 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
111 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000112 void VisitFieldDecl(FieldDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000113 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000114 void VisitVarDecl(VarDecl *VD);
115 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
116 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000117 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
118 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000119 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000120 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000121 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000122 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000123 void VisitUsingDecl(UsingDecl *D);
124 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000125 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000126 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000127 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000128 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000129 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
130 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000131 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000132
Chris Lattner487412d2009-04-27 05:27:42 +0000133 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000134 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000135
Alexis Hunted053252010-05-30 07:21:58 +0000136 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000137 void VisitObjCMethodDecl(ObjCMethodDecl *D);
138 void VisitObjCContainerDecl(ObjCContainerDecl *D);
139 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
140 void VisitObjCIvarDecl(ObjCIvarDecl *D);
141 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
142 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
143 void VisitObjCClassDecl(ObjCClassDecl *D);
144 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
145 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
146 void VisitObjCImplDecl(ObjCImplDecl *D);
147 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
148 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
149 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
150 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
151 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
152 };
153}
154
Sebastian Redlb3298c32010-08-18 23:56:48 +0000155uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Sebastian Redlc67764e2010-07-22 22:43:28 +0000156 uint64_t Off = 0;
157 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
Sebastian Redl2c499f62010-08-18 23:56:43 +0000158 ASTReader::PerFileData &F = *Reader.Chain[N - I - 1];
Sebastian Redlc67764e2010-07-22 22:43:28 +0000159 if (&Cursor == &F.DeclsCursor) {
160 Off += F.DeclsCursor.GetCurrentBitNo();
161 break;
162 }
163 Off += F.SizeInBits;
164 }
165 return Off;
166}
167
Sebastian Redlb3298c32010-08-18 23:56:48 +0000168void ASTDeclReader::Visit(Decl *D) {
169 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000170
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000171 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000172 // if we have a fully initialized TypeDecl, we can safely read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000173 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000174 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
175 // FunctionDecl's body was written last after all other Stmts/Exprs.
176 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000177 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000178 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000179}
180
Sebastian Redlb3298c32010-08-18 23:56:48 +0000181void ASTDeclReader::VisitDecl(Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000182 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
183 D->setLexicalDeclContext(
184 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000185 D->setLocation(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000186 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000187 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000188 AttrVec Attrs;
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000189 Reader.ReadAttributes(F, Attrs, Record, Idx);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000190 D->setAttrs(Attrs);
191 }
Chris Lattner487412d2009-04-27 05:27:42 +0000192 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000193 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000194 D->setAccess((AccessSpecifier)Record[Idx++]);
Sebastian Redl009e7f22010-10-05 16:15:19 +0000195 D->setPCHLevel(Record[Idx++] + (F.Type <= ASTReader::PCH));
Chris Lattner487412d2009-04-27 05:27:42 +0000196}
197
Sebastian Redlb3298c32010-08-18 23:56:48 +0000198void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Chris Lattner487412d2009-04-27 05:27:42 +0000199 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000200 TU->setAnonymousNamespace(
201 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000202}
203
Sebastian Redlb3298c32010-08-18 23:56:48 +0000204void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000205 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000206 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000207}
208
Sebastian Redlb3298c32010-08-18 23:56:48 +0000209void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000210 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000211 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor1c283312010-08-11 12:19:30 +0000212 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000213}
214
Sebastian Redlb3298c32010-08-18 23:56:48 +0000215void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000216 VisitTypeDecl(TD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000217 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000218}
219
Sebastian Redlb3298c32010-08-18 23:56:48 +0000220void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000221 VisitTypeDecl(TD);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000222 VisitRedeclarable(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000223 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000224 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
225 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000226 TD->setEmbeddedInDeclarator(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000227 TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
228 TD->setTagKeywordLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000229 if (Record[Idx++]) { // hasExtInfo
230 TagDecl::ExtInfo *Info = new (*Reader.getContext()) TagDecl::ExtInfo();
231 ReadQualifierInfo(*Info, Record, Idx);
232 TD->TypedefDeclOrQualifier = Info;
233 } else
234 TD->setTypedefForAnonDecl(
235 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000236}
237
Sebastian Redlb3298c32010-08-18 23:56:48 +0000238void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000239 VisitTagDecl(ED);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000240 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
241 ED->setIntegerTypeSourceInfo(TI);
242 else
243 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000244 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000245 ED->setNumPositiveBits(Record[Idx++]);
246 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000247 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000248 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000249 ED->IsFixed = Record[Idx++];
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000250 ED->setInstantiationOfMemberEnum(
251 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000252}
253
Sebastian Redlb3298c32010-08-18 23:56:48 +0000254void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000255 VisitTagDecl(RD);
256 RD->setHasFlexibleArrayMember(Record[Idx++]);
257 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000258 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000259}
260
Sebastian Redlb3298c32010-08-18 23:56:48 +0000261void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000262 VisitNamedDecl(VD);
263 VD->setType(Reader.GetType(Record[Idx++]));
264}
265
Sebastian Redlb3298c32010-08-18 23:56:48 +0000266void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000267 VisitValueDecl(ECD);
268 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000269 ECD->setInitExpr(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000270 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
271}
272
Sebastian Redlb3298c32010-08-18 23:56:48 +0000273void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000274 VisitValueDecl(DD);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000275 if (Record[Idx++]) { // hasExtInfo
276 DeclaratorDecl::ExtInfo *Info
277 = new (*Reader.getContext()) DeclaratorDecl::ExtInfo();
278 ReadQualifierInfo(*Info, Record, Idx);
279 Info->TInfo = GetTypeSourceInfo(Record, Idx);
280 DD->DeclInfo = Info;
281 } else
282 DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000283}
284
Sebastian Redlb3298c32010-08-18 23:56:48 +0000285void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000286 VisitDeclaratorDecl(FD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000287 VisitRedeclarable(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000288
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000289 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000290 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000291 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000292 default: assert(false && "Unhandled TemplatedKind!");
293 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000294 case FunctionDecl::TK_NonTemplate:
295 break;
296 case FunctionDecl::TK_FunctionTemplate:
297 FD->setDescribedFunctionTemplate(
298 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
299 break;
300 case FunctionDecl::TK_MemberSpecialization: {
301 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
302 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000303 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000304 FD->setInstantiationOfMemberFunction(*Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000305 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
306 break;
307 }
308 case FunctionDecl::TK_FunctionTemplateSpecialization: {
309 FunctionTemplateDecl *Template
310 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
311 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
312
313 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000314 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +0000315 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000316
317 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000318 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000319 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000320 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
321 unsigned NumTemplateArgLocs = Record[Idx++];
322 TemplArgLocs.reserve(NumTemplateArgLocs);
323 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000324 TemplArgLocs.push_back(
Sebastian Redl2c373b92010-10-05 15:59:54 +0000325 Reader.ReadTemplateArgumentLoc(F, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000326
Sebastian Redl2c373b92010-10-05 15:59:54 +0000327 LAngleLoc = ReadSourceLocation(Record, Idx);
328 RAngleLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000329 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000330
Sebastian Redl2c373b92010-10-05 15:59:54 +0000331 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000332
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000333 ASTContext &C = *Reader.getContext();
334 TemplateArgumentList *TemplArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +0000335 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000336 TemplateArgumentListInfo *TemplArgsInfo
337 = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
338 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
339 TemplArgsInfo->addArgument(TemplArgLocs[i]);
340 FunctionTemplateSpecializationInfo *FTInfo
341 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
342 TemplArgList,
343 TemplArgsInfo, POI);
344 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000345
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000346 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000347 // The template that contains the specializations set. It's not safe to
348 // use getCanonicalDecl on Template since it may still be initializing.
349 FunctionTemplateDecl *CanonTemplate
350 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000351 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
352 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
353 // FunctionTemplateSpecializationInfo's Profile().
354 // We avoid getASTContext because a decl in the parent hierarchy may
355 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000356 llvm::FoldingSetNodeID ID;
357 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
358 TemplArgs.size(), C);
359 void *InsertPos = 0;
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000360 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000361 assert(InsertPos && "Another specialization already inserted!");
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000362 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000363 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000364 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000365 }
366 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
367 // Templates.
368 UnresolvedSet<8> TemplDecls;
369 unsigned NumTemplates = Record[Idx++];
370 while (NumTemplates--)
371 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
372
373 // Templates args.
374 TemplateArgumentListInfo TemplArgs;
375 unsigned NumArgs = Record[Idx++];
376 while (NumArgs--)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000377 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
378 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
379 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000380
381 FD->setDependentTemplateSpecialization(*Reader.getContext(),
382 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000383 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000384 }
385 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000386
Sebastian Redlb3298c32010-08-18 23:56:48 +0000387 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000388 // after everything else is read.
389
Douglas Gregorbf62d642010-12-06 18:36:25 +0000390 FD->SClass = (StorageClass)Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000391 FD->SClassAsWritten = (StorageClass)Record[Idx++];
Douglas Gregorff76cb92010-12-09 16:59:22 +0000392 FD->IsInline = Record[Idx++];
393 FD->IsInlineSpecified = Record[Idx++];
Argyrios Kyrtzidis7cd69242011-01-03 17:57:40 +0000394 FD->IsVirtualAsWritten = Record[Idx++];
395 FD->IsPure = Record[Idx++];
396 FD->HasInheritedPrototype = Record[Idx++];
397 FD->HasWrittenPrototype = Record[Idx++];
398 FD->IsDeleted = Record[Idx++];
399 FD->IsTrivial = Record[Idx++];
400 FD->HasImplicitReturnZero = Record[Idx++];
401 FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000402
Chris Lattnerca025db2010-05-07 21:43:38 +0000403 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000404 unsigned NumParams = Record[Idx++];
405 llvm::SmallVector<ParmVarDecl *, 16> Params;
406 Params.reserve(NumParams);
407 for (unsigned I = 0; I != NumParams; ++I)
408 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000409 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000410}
411
Sebastian Redlb3298c32010-08-18 23:56:48 +0000412void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000413 VisitNamedDecl(MD);
414 if (Record[Idx++]) {
415 // In practice, this won't be executed (since method definitions
416 // don't occur in header files).
Sebastian Redl2c373b92010-10-05 15:59:54 +0000417 MD->setBody(Reader.ReadStmt(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000418 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
419 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
420 }
421 MD->setInstanceMethod(Record[Idx++]);
422 MD->setVariadic(Record[Idx++]);
423 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000424 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000425 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
426 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000427 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000428 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000429 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
430 MD->setEndLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000431 unsigned NumParams = Record[Idx++];
432 llvm::SmallVector<ParmVarDecl *, 16> Params;
433 Params.reserve(NumParams);
434 for (unsigned I = 0; I != NumParams; ++I)
435 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000436 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
437 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000438}
439
Sebastian Redlb3298c32010-08-18 23:56:48 +0000440void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000441 VisitNamedDecl(CD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000442 SourceLocation A = ReadSourceLocation(Record, Idx);
443 SourceLocation B = ReadSourceLocation(Record, Idx);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000444 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000445}
446
Sebastian Redlb3298c32010-08-18 23:56:48 +0000447void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000448 VisitObjCContainerDecl(ID);
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000449 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtrOrNull());
Chris Lattner487412d2009-04-27 05:27:42 +0000450 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
451 (Reader.GetDecl(Record[Idx++])));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000452
453 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000454 unsigned NumProtocols = Record[Idx++];
455 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
456 Protocols.reserve(NumProtocols);
457 for (unsigned I = 0; I != NumProtocols; ++I)
458 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000459 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
460 ProtoLocs.reserve(NumProtocols);
461 for (unsigned I = 0; I != NumProtocols; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000462 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000463 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
464 *Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000465
466 // Read the transitive closure of protocols referenced by this class.
467 NumProtocols = Record[Idx++];
468 Protocols.clear();
469 Protocols.reserve(NumProtocols);
470 for (unsigned I = 0; I != NumProtocols; ++I)
471 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
472 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
473 *Reader.getContext());
474
475 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000476 unsigned NumIvars = Record[Idx++];
477 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
478 IVars.reserve(NumIvars);
479 for (unsigned I = 0; I != NumIvars; ++I)
480 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000481 ID->setCategoryList(
482 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000483 // We will rebuild this list lazily.
484 ID->setIvarList(0);
Douglas Gregor1c283312010-08-11 12:19:30 +0000485 ID->setForwardDecl(Record[Idx++]);
486 ID->setImplicitInterfaceDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000487 ID->setClassLoc(ReadSourceLocation(Record, Idx));
488 ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
489 ID->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000490}
491
Sebastian Redlb3298c32010-08-18 23:56:48 +0000492void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000493 VisitFieldDecl(IVD);
494 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000495 // This field will be built lazily.
496 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000497 bool synth = Record[Idx++];
498 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000499}
500
Sebastian Redlb3298c32010-08-18 23:56:48 +0000501void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000502 VisitObjCContainerDecl(PD);
503 PD->setForwardDecl(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000504 PD->setLocEnd(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000505 unsigned NumProtoRefs = Record[Idx++];
506 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
507 ProtoRefs.reserve(NumProtoRefs);
508 for (unsigned I = 0; I != NumProtoRefs; ++I)
509 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000510 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
511 ProtoLocs.reserve(NumProtoRefs);
512 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000513 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000514 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
515 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000516}
517
Sebastian Redlb3298c32010-08-18 23:56:48 +0000518void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000519 VisitFieldDecl(FD);
520}
521
Sebastian Redlb3298c32010-08-18 23:56:48 +0000522void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000523 VisitDecl(CD);
524 unsigned NumClassRefs = Record[Idx++];
525 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
526 ClassRefs.reserve(NumClassRefs);
527 for (unsigned I = 0; I != NumClassRefs; ++I)
528 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000529 llvm::SmallVector<SourceLocation, 16> SLocs;
530 SLocs.reserve(NumClassRefs);
531 for (unsigned I = 0; I != NumClassRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000532 SLocs.push_back(ReadSourceLocation(Record, Idx));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000533 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
534 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000535}
536
Sebastian Redlb3298c32010-08-18 23:56:48 +0000537void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000538 VisitDecl(FPD);
539 unsigned NumProtoRefs = Record[Idx++];
540 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
541 ProtoRefs.reserve(NumProtoRefs);
542 for (unsigned I = 0; I != NumProtoRefs; ++I)
543 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000544 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
545 ProtoLocs.reserve(NumProtoRefs);
546 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000547 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000548 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
549 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000550}
551
Sebastian Redlb3298c32010-08-18 23:56:48 +0000552void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000553 VisitObjCContainerDecl(CD);
554 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
555 unsigned NumProtoRefs = Record[Idx++];
556 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
557 ProtoRefs.reserve(NumProtoRefs);
558 for (unsigned I = 0; I != NumProtoRefs; ++I)
559 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000560 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
561 ProtoLocs.reserve(NumProtoRefs);
562 for (unsigned I = 0; I != NumProtoRefs; ++I)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000563 ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
Douglas Gregor002b6712010-01-16 15:02:53 +0000564 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
565 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000566 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000567 CD->setHasSynthBitfield(Record[Idx++]);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000568 CD->setAtLoc(ReadSourceLocation(Record, Idx));
569 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000570}
571
Sebastian Redlb3298c32010-08-18 23:56:48 +0000572void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000573 VisitNamedDecl(CAD);
574 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
575}
576
Sebastian Redlb3298c32010-08-18 23:56:48 +0000577void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000578 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000579 D->setAtLoc(ReadSourceLocation(Record, Idx));
580 D->setType(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000581 // FIXME: stable encoding
582 D->setPropertyAttributes(
583 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000584 D->setPropertyAttributesAsWritten(
585 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000586 // FIXME: stable encoding
587 D->setPropertyImplementation(
588 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
589 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
590 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
591 D->setGetterMethodDecl(
592 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
593 D->setSetterMethodDecl(
594 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
595 D->setPropertyIvarDecl(
596 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
597}
598
Sebastian Redlb3298c32010-08-18 23:56:48 +0000599void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000600 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000601 D->setClassInterface(
602 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000603}
604
Sebastian Redlb3298c32010-08-18 23:56:48 +0000605void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000606 VisitObjCImplDecl(D);
607 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
608}
609
Sebastian Redlb3298c32010-08-18 23:56:48 +0000610void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000611 VisitObjCImplDecl(D);
612 D->setSuperClass(
613 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000614 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
Alexis Hunt1d792652011-01-08 20:30:50 +0000615 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000616 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000617}
618
619
Sebastian Redlb3298c32010-08-18 23:56:48 +0000620void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000621 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000622 D->setAtLoc(ReadSourceLocation(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000623 D->setPropertyDecl(
624 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000625 D->PropertyIvarDecl =
626 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]));
627 D->IvarLoc = ReadSourceLocation(Record, Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000628 D->setGetterCXXConstructor(Reader.ReadExpr(F));
629 D->setSetterCXXAssignment(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000630}
631
Sebastian Redlb3298c32010-08-18 23:56:48 +0000632void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000633 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000634 FD->setMutable(Record[Idx++]);
635 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000636 FD->setBitWidth(Reader.ReadExpr(F));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000637 if (!FD->getDeclName()) {
638 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
639 if (Tmpl)
640 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
641 }
Chris Lattner487412d2009-04-27 05:27:42 +0000642}
643
Francois Pichet783dd6e2010-11-21 06:08:52 +0000644void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
645 VisitValueDecl(FD);
646
647 FD->ChainingSize = Record[Idx++];
648 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
649 FD->Chaining = new (*Reader.getContext())NamedDecl*[FD->ChainingSize];
650
651 for (unsigned I = 0; I != FD->ChainingSize; ++I)
652 FD->Chaining[I] = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
653}
654
Sebastian Redlb3298c32010-08-18 23:56:48 +0000655void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000656 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000657 VisitRedeclarable(VD);
Douglas Gregorbf62d642010-12-06 18:36:25 +0000658 VD->SClass = (StorageClass)Record[Idx++];
John McCall8e7d6562010-08-26 03:08:43 +0000659 VD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000660 VD->setThreadSpecified(Record[Idx++]);
661 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000662 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000663 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000664 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000665 VD->setInit(Reader.ReadExpr(F));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000666
667 if (Record[Idx++]) { // HasMemberSpecializationInfo.
668 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
669 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000670 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000671 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
672 }
Chris Lattner487412d2009-04-27 05:27:42 +0000673}
674
Sebastian Redlb3298c32010-08-18 23:56:48 +0000675void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000676 VisitVarDecl(PD);
677}
678
Sebastian Redlb3298c32010-08-18 23:56:48 +0000679void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000680 VisitVarDecl(PD);
681 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000682 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000683 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl2c373b92010-10-05 15:59:54 +0000684 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
Chris Lattner487412d2009-04-27 05:27:42 +0000685}
686
Sebastian Redlb3298c32010-08-18 23:56:48 +0000687void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000688 VisitDecl(AD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000689 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
Chris Lattner487412d2009-04-27 05:27:42 +0000690}
691
Sebastian Redlb3298c32010-08-18 23:56:48 +0000692void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000693 VisitDecl(BD);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000694 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
695 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000696 unsigned NumParams = Record[Idx++];
697 llvm::SmallVector<ParmVarDecl *, 16> Params;
698 Params.reserve(NumParams);
699 for (unsigned I = 0; I != NumParams; ++I)
700 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000701 BD->setParams(Params.data(), NumParams);
John McCallc63de662011-02-02 13:00:07 +0000702
703 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +0000704 unsigned numCaptures = Record[Idx++];
705 llvm::SmallVector<BlockDecl::Capture, 16> captures;
706 captures.reserve(numCaptures);
707 for (unsigned i = 0; i != numCaptures; ++i) {
708 VarDecl *decl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
709 unsigned flags = Record[Idx++];
710 bool byRef = (flags & 1);
711 bool nested = (flags & 2);
712 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
713
714 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
715 }
716 BD->setCaptures(*Reader.getContext(), captures.begin(),
717 captures.end(), capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +0000718}
719
Sebastian Redlb3298c32010-08-18 23:56:48 +0000720void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000721 VisitDecl(D);
722 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
723 D->setHasBraces(Record[Idx++]);
724}
725
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000726void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
727 VisitNamedDecl(D);
728 if (Record[Idx++]) D->setHasUnusedAttribute();
729}
730
731
Sebastian Redlb3298c32010-08-18 23:56:48 +0000732void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000733 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +0000734 D->IsInline = Record[Idx++];
Douglas Gregor417e87c2010-10-27 19:49:05 +0000735 D->LBracLoc = ReadSourceLocation(Record, Idx);
736 D->RBracLoc = ReadSourceLocation(Record, Idx);
737 D->NextNamespace = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000738
Chris Lattnerca025db2010-05-07 21:43:38 +0000739 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000740 D->OrigOrAnonNamespace.setInt(IsOriginal);
741 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000742 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
743}
744
Sebastian Redlb3298c32010-08-18 23:56:48 +0000745void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000746 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000747 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
748 D->setQualifierRange(ReadSourceRange(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000749 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Sebastian Redl2c373b92010-10-05 15:59:54 +0000750 D->IdentLoc = ReadSourceLocation(Record, Idx);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000751 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000752}
753
Sebastian Redlb3298c32010-08-18 23:56:48 +0000754void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000755 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000756 D->setUsingLocation(ReadSourceLocation(Record, Idx));
757 D->setNestedNameRange(ReadSourceRange(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000758 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000759 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000760 D->FirstUsingShadow = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000761 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000762 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
763 if (Pattern)
764 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000765}
766
Sebastian Redlb3298c32010-08-18 23:56:48 +0000767void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000768 VisitNamedDecl(D);
769 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +0000770 D->UsingOrNextShadow = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000771 UsingShadowDecl *Pattern
772 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
773 if (Pattern)
774 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000775}
776
Sebastian Redlb3298c32010-08-18 23:56:48 +0000777void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000778 VisitNamedDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000779 D->UsingLoc = ReadSourceLocation(Record, Idx);
780 D->NamespaceLoc = ReadSourceLocation(Record, Idx);
781 D->QualifierRange = ReadSourceRange(Record, Idx);
Douglas Gregor01a430132010-09-01 03:07:18 +0000782 D->Qualifier = Reader.ReadNestedNameSpecifier(Record, Idx);
783 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
784 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000785}
786
Sebastian Redlb3298c32010-08-18 23:56:48 +0000787void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000788 VisitValueDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000789 D->setTargetNestedNameRange(ReadSourceRange(Record, Idx));
790 D->setUsingLoc(ReadSourceLocation(Record, Idx));
Chris Lattnerca025db2010-05-07 21:43:38 +0000791 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000792 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000793}
794
Sebastian Redlb3298c32010-08-18 23:56:48 +0000795void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000796 UnresolvedUsingTypenameDecl *D) {
797 VisitTypeDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000798 D->TargetNestedNameRange = ReadSourceRange(Record, Idx);
799 D->UsingLocation = ReadSourceLocation(Record, Idx);
800 D->TypenameLocation = ReadSourceLocation(Record, Idx);
Douglas Gregora9aa29c2010-09-01 19:52:22 +0000801 D->TargetNestedNameSpecifier = Reader.ReadNestedNameSpecifier(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000802}
803
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000804void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000805 struct CXXRecordDecl::DefinitionData &Data,
806 const RecordData &Record, unsigned &Idx) {
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000807 Data.UserDeclaredConstructor = Record[Idx++];
808 Data.UserDeclaredCopyConstructor = Record[Idx++];
809 Data.UserDeclaredCopyAssignment = Record[Idx++];
810 Data.UserDeclaredDestructor = Record[Idx++];
811 Data.Aggregate = Record[Idx++];
812 Data.PlainOldData = Record[Idx++];
813 Data.Empty = Record[Idx++];
814 Data.Polymorphic = Record[Idx++];
815 Data.Abstract = Record[Idx++];
816 Data.HasTrivialConstructor = Record[Idx++];
817 Data.HasTrivialCopyConstructor = Record[Idx++];
818 Data.HasTrivialCopyAssignment = Record[Idx++];
819 Data.HasTrivialDestructor = Record[Idx++];
820 Data.ComputedVisibleConversions = Record[Idx++];
821 Data.DeclaredDefaultConstructor = Record[Idx++];
822 Data.DeclaredCopyConstructor = Record[Idx++];
823 Data.DeclaredCopyAssignment = Record[Idx++];
824 Data.DeclaredDestructor = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +0000825
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000826 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000827 if (Data.NumBases)
828 Data.Bases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000829 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000830 if (Data.NumVBases)
831 Data.VBases = Reader.GetCXXBaseSpecifiersOffset(Record[Idx++]);
832
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +0000833 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
834 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
835 assert(Data.Definition && "Data.Definition should be already set!");
836 Data.FirstFriend
837 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
838}
839
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000840void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
841 CXXRecordDecl *DefinitionDecl,
842 const RecordData &Record,
843 unsigned &Idx) {
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000844 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000845
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000846 if (D == DefinitionDecl) {
847 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000848 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
Argyrios Kyrtzidisad5f95c2010-10-24 17:26:31 +0000849 // We read the definition info. Check if there are pending forward
850 // references that need to point to this DefinitionData pointer.
851 ASTReader::PendingForwardRefsMap::iterator
852 FindI = Reader.PendingForwardRefs.find(D);
853 if (FindI != Reader.PendingForwardRefs.end()) {
854 ASTReader::ForwardRefs &Refs = FindI->second;
855 for (ASTReader::ForwardRefs::iterator
856 I = Refs.begin(), E = Refs.end(); I != E; ++I)
857 (*I)->DefinitionData = D->DefinitionData;
858#ifndef NDEBUG
859 // We later check whether PendingForwardRefs is empty to make sure all
860 // pending references were linked.
861 Reader.PendingForwardRefs.erase(D);
862#endif
863 }
864 } else if (DefinitionDecl) {
865 if (DefinitionDecl->DefinitionData) {
866 D->DefinitionData = DefinitionDecl->DefinitionData;
867 } else {
868 // The definition is still initializing.
869 Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
870 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000871 }
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000872}
873
874void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
875 VisitRecordDecl(D);
876
877 CXXRecordDecl *DefinitionDecl
878 = cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
879 InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
880
881 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000882
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000883 enum CXXRecKind {
884 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
885 };
886 switch ((CXXRecKind)Record[Idx++]) {
887 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000888 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000889 case CXXRecNotTemplate:
890 break;
891 case CXXRecTemplate:
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000892 D->TemplateOrInstantiation
893 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000894 break;
895 case CXXRecMemberSpecialization: {
896 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
897 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +0000898 SourceLocation POI = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000899 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
900 MSI->setPointOfInstantiation(POI);
901 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000902 break;
903 }
904 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +0000905
906 // Load the key function to avoid deserializing every method so we can
907 // compute it.
908 if (D->IsDefinition) {
909 CXXMethodDecl *Key
910 = cast_or_null<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
911 if (Key)
912 C.KeyFunctions[D] = Key;
913 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000914}
915
Sebastian Redlb3298c32010-08-18 23:56:48 +0000916void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000917 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000918 unsigned NumOverridenMethods = Record[Idx++];
919 while (NumOverridenMethods--) {
920 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
921 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
922 // MD may be initializing.
923 Reader.getContext()->addOverriddenMethod(D, MD);
924 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000925}
926
Sebastian Redlb3298c32010-08-18 23:56:48 +0000927void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000928 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000929
930 D->IsExplicitSpecified = Record[Idx++];
931 D->ImplicitlyDefined = Record[Idx++];
Alexis Hunt1d792652011-01-08 20:30:50 +0000932 llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
933 = Reader.ReadCXXCtorInitializers(F, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000934}
935
Sebastian Redlb3298c32010-08-18 23:56:48 +0000936void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000937 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000938
939 D->ImplicitlyDefined = Record[Idx++];
940 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000941}
942
Sebastian Redlb3298c32010-08-18 23:56:48 +0000943void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000944 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000945 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000946}
947
Sebastian Redlb3298c32010-08-18 23:56:48 +0000948void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +0000949 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000950 D->setColonLoc(ReadSourceLocation(Record, Idx));
Abramo Bagnarad7340582010-06-05 05:09:32 +0000951}
952
Sebastian Redlb3298c32010-08-18 23:56:48 +0000953void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000954 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000955 if (Record[Idx++])
Sebastian Redl2c373b92010-10-05 15:59:54 +0000956 D->Friend = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000957 else
958 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Douglas Gregore0fb32c2010-10-27 20:23:41 +0000959 D->NextFriend = Record[Idx++];
John McCall2c2eb122010-10-16 06:59:13 +0000960 D->UnsupportedFriend = (Record[Idx++] != 0);
Sebastian Redl2c373b92010-10-05 15:59:54 +0000961 D->FriendLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000962}
963
Sebastian Redlb3298c32010-08-18 23:56:48 +0000964void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000965 VisitDecl(D);
966 unsigned NumParams = Record[Idx++];
967 D->NumParams = NumParams;
968 D->Params = new TemplateParameterList*[NumParams];
969 for (unsigned i = 0; i != NumParams; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +0000970 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000971 if (Record[Idx++]) // HasFriendDecl
972 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
973 else
Sebastian Redl2c373b92010-10-05 15:59:54 +0000974 D->Friend = GetTypeSourceInfo(Record, Idx);
975 D->FriendLoc = ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000976}
977
Sebastian Redlb3298c32010-08-18 23:56:48 +0000978void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000979 VisitNamedDecl(D);
980
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000981 NamedDecl *TemplatedDecl
982 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000983 TemplateParameterList* TemplateParams
Sebastian Redl2c373b92010-10-05 15:59:54 +0000984 = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000985 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000986}
987
Sebastian Redlb3298c32010-08-18 23:56:48 +0000988void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000989 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
990 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000991
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000992 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000993 DeclID PreviousDeclID = Record[Idx++];
994 DeclID FirstDeclID = PreviousDeclID ? Record[Idx++] : 0;
995 // We delay loading of the redeclaration chain to avoid deeply nested calls.
996 // We temporarily set the first (canonical) declaration as the previous one
997 // which is the one that matters and mark the real previous DeclID to be
998 // loaded & attached later on.
999 RedeclarableTemplateDecl *FirstDecl =
1000 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1001 assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1002 "FirstDecl kind mismatch");
1003 if (FirstDecl) {
1004 D->CommonOrPrev = FirstDecl;
1005 // Mark the real previous DeclID to be loaded & attached later on.
1006 if (PreviousDeclID != FirstDeclID)
1007 Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1008 } else {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001009 D->CommonOrPrev = D->newCommon(*Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001010 if (RedeclarableTemplateDecl *RTD
1011 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
1012 assert(RTD->getKind() == D->getKind() &&
1013 "InstantiatedFromMemberTemplate kind mismatch");
1014 D->setInstantiatedFromMemberTemplateImpl(RTD);
1015 if (Record[Idx++])
1016 D->setMemberSpecialization();
1017 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001018
1019 RedeclarableTemplateDecl *LatestDecl =
1020 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001021
1022 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001023 // in the same AST file. However, if this actually needs to point to a
1024 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001025 // the FirstLatestDeclIDs map which tracks this kind of decls.
1026 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001027 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001028 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1029 if (I != Reader.FirstLatestDeclIDs.end()) {
1030 Decl *NewLatest = Reader.GetDecl(I->second);
1031 assert((LatestDecl->getLocation().isInvalid() ||
1032 NewLatest->getLocation().isInvalid() ||
Argyrios Kyrtzidis54b88e72010-10-20 23:48:40 +00001033 !Reader.SourceMgr.isBeforeInTranslationUnit(
1034 NewLatest->getLocation(),
1035 LatestDecl->getLocation())) &&
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001036 "The new latest is supposed to come after the previous latest");
1037 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
1038 }
1039
Peter Collingbourne2bf3d242010-07-29 16:12:01 +00001040 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1041 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001042 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001043
1044 VisitTemplateDecl(D);
1045 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001046}
1047
Sebastian Redlb3298c32010-08-18 23:56:48 +00001048void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001049 VisitRedeclarableTemplateDecl(D);
1050
1051 if (D->getPreviousDeclaration() == 0) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001052 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1053 // the specializations.
1054 llvm::SmallVector<serialization::DeclID, 2> SpecIDs;
1055 SpecIDs.push_back(0);
1056
1057 // Specializations.
1058 unsigned Size = Record[Idx++];
1059 SpecIDs[0] += Size;
1060 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1061 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001062
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001063 // Partial specializations.
1064 Size = Record[Idx++];
1065 SpecIDs[0] += Size;
1066 SpecIDs.append(Record.begin() + Idx, Record.begin() + Idx + Size);
1067 Idx += Size;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001068
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001069 if (SpecIDs[0]) {
1070 typedef serialization::DeclID DeclID;
1071
1072 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1073 CommonPtr->LazySpecializations
1074 = new (*Reader.getContext()) DeclID [SpecIDs.size()];
1075 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1076 SpecIDs.size() * sizeof(DeclID));
1077 }
1078
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001079 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001080 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001081}
1082
Sebastian Redlb3298c32010-08-18 23:56:48 +00001083void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001084 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001085 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001086
1087 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001088 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
1089 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001090 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001091 } else {
1092 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001093 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001094 TemplateArgumentList *ArgList
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001095 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1096 TemplArgs.size());
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001097 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1098 = new (C) ClassTemplateSpecializationDecl::
1099 SpecializedPartialSpecialization();
1100 PS->PartialSpecialization
1101 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1102 PS->TemplateArgs = ArgList;
1103 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001104 }
1105 }
1106
1107 // Explicit info.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001108 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001109 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1110 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1111 ExplicitInfo->TypeAsWritten = TyInfo;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001112 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1113 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001114 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001115 }
1116
1117 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001118 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
Douglas Gregor1ccc8412010-11-07 23:05:16 +00001119 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1120 TemplArgs.size());
Sebastian Redl2c373b92010-10-05 15:59:54 +00001121 D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001122 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001123
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001124 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001125 ClassTemplateDecl *CanonPattern
1126 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
1127 if (ClassTemplatePartialSpecializationDecl *Partial
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001128 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1129 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001130 } else {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001131 CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001132 }
1133 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001134}
1135
Sebastian Redlb3298c32010-08-18 23:56:48 +00001136void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001137 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001138 VisitClassTemplateSpecializationDecl(D);
1139
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001140 ASTContext &C = *Reader.getContext();
Sebastian Redl2c373b92010-10-05 15:59:54 +00001141 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001142
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001143 unsigned NumArgs = Record[Idx++];
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001144 if (NumArgs) {
1145 D->NumArgsAsWritten = NumArgs;
1146 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1147 for (unsigned i=0; i != NumArgs; ++i)
Sebastian Redl2c373b92010-10-05 15:59:54 +00001148 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001149 }
1150
1151 D->SequenceNumber = Record[Idx++];
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001152
1153 // These are read/set from/to the first declaration.
1154 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001155 D->InstantiatedFromMember.setPointer(
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001156 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1157 Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00001158 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001159 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001160}
1161
Sebastian Redlb3298c32010-08-18 23:56:48 +00001162void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001163 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001164
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001165 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001166 // This FunctionTemplateDecl owns a CommonPtr; read it.
1167
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001168 // Read the function specialization declarations.
1169 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +00001170 // when reading the specialized FunctionDecl.
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001171 unsigned NumSpecs = Record[Idx++];
1172 while (NumSpecs--)
1173 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001174 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001175}
1176
Sebastian Redlb3298c32010-08-18 23:56:48 +00001177void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001178 VisitTypeDecl(D);
1179
1180 D->setDeclaredWithTypename(Record[Idx++]);
1181 D->setParameterPack(Record[Idx++]);
1182
1183 bool Inherited = Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001184 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001185 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001186}
1187
Sebastian Redlb3298c32010-08-18 23:56:48 +00001188void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00001189 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001190 // TemplateParmPosition.
1191 D->setDepth(Record[Idx++]);
1192 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001193 if (D->isExpandedParameterPack()) {
1194 void **Data = reinterpret_cast<void **>(D + 1);
1195 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1196 Data[2*I] = Reader.GetType(Record[Idx++]).getAsOpaquePtr();
1197 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1198 }
1199 } else {
1200 // Rest of NonTypeTemplateParmDecl.
1201 D->ParameterPack = Record[Idx++];
1202 if (Record[Idx++]) {
1203 Expr *DefArg = Reader.ReadExpr(F);
1204 bool Inherited = Record[Idx++];
1205 D->setDefaultArgument(DefArg, Inherited);
1206 }
1207 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001208}
1209
Sebastian Redlb3298c32010-08-18 23:56:48 +00001210void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001211 VisitTemplateDecl(D);
1212 // TemplateParmPosition.
1213 D->setDepth(Record[Idx++]);
1214 D->setPosition(Record[Idx++]);
1215 // Rest of TemplateTemplateParmDecl.
Sebastian Redl2c373b92010-10-05 15:59:54 +00001216 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001217 bool IsInherited = Record[Idx++];
1218 D->setDefaultArgument(Arg, IsInherited);
Douglas Gregorf5500772011-01-05 15:48:55 +00001219 D->ParameterPack = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001220}
1221
Sebastian Redlb3298c32010-08-18 23:56:48 +00001222void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001223 VisitDecl(D);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001224 D->AssertExpr = Reader.ReadExpr(F);
1225 D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
Chris Lattnerca025db2010-05-07 21:43:38 +00001226}
1227
Mike Stump11289f42009-09-09 15:08:12 +00001228std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001229ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001230 uint64_t LexicalOffset = Record[Idx++];
1231 uint64_t VisibleOffset = Record[Idx++];
1232 return std::make_pair(LexicalOffset, VisibleOffset);
1233}
1234
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001235template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001236void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001237 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1238 RedeclKind Kind = (RedeclKind)Record[Idx++];
1239 switch (Kind) {
1240 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +00001241 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001242 " reading");
1243 case NoRedeclaration:
1244 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001245 case PointsToPrevious: {
1246 DeclID PreviousDeclID = Record[Idx++];
1247 DeclID FirstDeclID = Record[Idx++];
1248 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1249 // We temporarily set the first (canonical) declaration as the previous one
1250 // which is the one that matters and mark the real previous DeclID to be
1251 // loaded & attached later on.
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001252 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001253 cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1254 if (PreviousDeclID != FirstDeclID)
1255 Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1256 PreviousDeclID));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001257 break;
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001258 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001259 case PointsToLatest:
1260 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1261 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1262 break;
1263 }
1264
1265 assert(!(Kind == PointsToPrevious &&
1266 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1267 Reader.FirstLatestDeclIDs.end()) &&
1268 "This decl is not first, it should not be in the map");
1269 if (Kind == PointsToPrevious)
1270 return;
1271
1272 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001273 // the same AST file. However, if this actually needs to point to a
1274 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001275 // FirstLatestDeclIDs map which tracks this kind of decls.
1276 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1277 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001278 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001279 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1280 if (I != Reader.FirstLatestDeclIDs.end()) {
1281 Decl *NewLatest = Reader.GetDecl(I->second);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001282 D->RedeclLink
1283 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1284 }
1285}
1286
Chris Lattner487412d2009-04-27 05:27:42 +00001287//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001288// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001289//===----------------------------------------------------------------------===//
1290
Chris Lattner8f63ab52009-04-27 06:01:06 +00001291/// \brief Reads attributes from the current stream position.
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00001292void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs,
1293 const RecordData &Record, unsigned &Idx) {
1294 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001295 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001296 attr::Kind Kind = (attr::Kind)Record[Idx++];
Sebastian Redl2c373b92010-10-05 15:59:54 +00001297 SourceLocation Loc = ReadSourceLocation(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001298
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001299#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001300
1301 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001302 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001303 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001304}
1305
1306//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001307// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001308//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001309
1310/// \brief Note that we have loaded the declaration with the given
1311/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001312///
Chris Lattner487412d2009-04-27 05:27:42 +00001313/// This routine notes that this declaration has already been loaded,
1314/// so that future GetDecl calls will return this declaration rather
1315/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001316inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001317 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1318 DeclsLoaded[Index] = D;
1319}
1320
1321
1322/// \brief Determine whether the consumer will be interested in seeing
1323/// this declaration (via HandleTopLevelDecl).
1324///
1325/// This routine should return true for anything that might affect
1326/// code generation, e.g., inline function definitions, Objective-C
1327/// declarations with metadata, etc.
1328static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001329 if (isa<FileScopeAsmDecl>(D))
1330 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001331 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001332 return Var->isFileVarDecl() &&
1333 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001334 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1335 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001336 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001337}
1338
Sebastian Redl34627792010-07-20 22:46:15 +00001339/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001340ASTReader::RecordLocation
Sebastian Redl539c5062010-08-18 23:57:32 +00001341ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001342 // See if there's an override.
1343 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1344 if (It != ReplacedDecls.end())
Sebastian Redl2c373b92010-10-05 15:59:54 +00001345 return RecordLocation(It->second.first, It->second.second);
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001346
Sebastian Redl34627792010-07-20 22:46:15 +00001347 PerFileData *F = 0;
1348 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1349 F = Chain[N - I - 1];
1350 if (Index < F->LocalNumDecls)
1351 break;
1352 Index -= F->LocalNumDecls;
1353 }
1354 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redl2c373b92010-10-05 15:59:54 +00001355 return RecordLocation(F, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001356}
1357
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00001358void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1359 assert(D && previous);
1360 if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1361 TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1362 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1363 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1364 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1365 VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1366 } else {
1367 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1368 TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1369 }
1370}
1371
1372void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1373 Decl *previous = GetDecl(ID);
1374 ASTDeclReader::attachPreviousDecl(D, previous);
1375}
1376
Sebastian Redlb3298c32010-08-18 23:56:48 +00001377/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl539c5062010-08-18 23:57:32 +00001378Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001379 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redl2c373b92010-10-05 15:59:54 +00001380 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00001381 // Keep track of where we are in the stream, then jump back there
1382 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001383 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001384
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001385 ReadingKindTracker ReadingKind(Read_Decl, *this);
1386
Douglas Gregor1342e842009-07-06 18:54:52 +00001387 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001388 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001389
Sebastian Redl2c373b92010-10-05 15:59:54 +00001390 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001391 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001392 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001393 unsigned Idx = 0;
Sebastian Redl2c373b92010-10-05 15:59:54 +00001394 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001395
Chris Lattner1de76db2009-04-27 05:58:23 +00001396 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001397 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00001398 case DECL_CONTEXT_LEXICAL:
1399 case DECL_CONTEXT_VISIBLE:
Chris Lattner487412d2009-04-27 05:27:42 +00001400 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1401 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001402 case DECL_TRANSLATION_UNIT:
Chris Lattner487412d2009-04-27 05:27:42 +00001403 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001404 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001405 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001406 case DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001407 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001408 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001409 case DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001410 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001411 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001412 case DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001413 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001414 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001415 case DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001416 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001417 0, llvm::APSInt());
1418 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001419 case DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001420 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001421 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001422 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001423 case DECL_LINKAGE_SPEC:
Chris Lattnerca025db2010-05-07 21:43:38 +00001424 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1425 (LinkageSpecDecl::LanguageIDs)0,
1426 false);
1427 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001428 case DECL_LABEL:
1429 D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
1430 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001431 case DECL_NAMESPACE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001432 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1433 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001434 case DECL_NAMESPACE_ALIAS:
Chris Lattnerca025db2010-05-07 21:43:38 +00001435 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1436 SourceLocation(), 0, SourceRange(), 0,
1437 SourceLocation(), 0);
1438 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001439 case DECL_USING:
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001440 D = UsingDecl::Create(*Context, 0, SourceRange(), SourceLocation(),
1441 0, DeclarationNameInfo(), false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001442 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001443 case DECL_USING_SHADOW:
Chris Lattnerca025db2010-05-07 21:43:38 +00001444 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1445 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001446 case DECL_USING_DIRECTIVE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001447 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1448 SourceLocation(), SourceRange(), 0,
1449 SourceLocation(), 0, 0);
1450 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001451 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001452 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001453 SourceRange(), 0,
1454 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001455 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001456 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattnerca025db2010-05-07 21:43:38 +00001457 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1458 SourceLocation(), SourceRange(),
1459 0, SourceLocation(),
1460 DeclarationName());
1461 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001462 case DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001463 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001464 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001465 case DECL_CXX_METHOD:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001466 D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001467 QualType(), 0);
1468 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001469 case DECL_CXX_CONSTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001470 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1471 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001472 case DECL_CXX_DESTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001473 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1474 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001475 case DECL_CXX_CONVERSION:
Chris Lattnerca025db2010-05-07 21:43:38 +00001476 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1477 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001478 case DECL_ACCESS_SPEC:
Argyrios Kyrtzidis260b4a82010-09-08 21:32:35 +00001479 D = AccessSpecDecl::Create(*Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001480 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001481 case DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001482 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001483 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001484 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001485 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001486 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001487 case DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001488 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1489 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001490 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001491 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001492 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001493 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001494 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001495 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1496 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001497 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001498 case DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001499 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1500 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001501 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001502 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001503 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001504 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001505 case DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001506 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
Douglas Gregorda3cc0d2010-12-23 23:51:58 +00001507 QualType(), false, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001508 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001509 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
1510 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1511 0, QualType(), 0, 0, Record[Idx++],
1512 0);
1513 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001514 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregorf5500772011-01-05 15:48:55 +00001515 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0, 0,
1516 false, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001517 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001518 case DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001519 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001520 break;
1521
Sebastian Redl539c5062010-08-18 23:57:32 +00001522 case DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001523 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001524 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001525 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001526 case DECL_OBJC_INTERFACE:
Douglas Gregor1c283312010-08-11 12:19:30 +00001527 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001528 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001529 case DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001530 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001531 ObjCIvarDecl::None);
1532 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001533 case DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001534 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001535 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001536 case DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001537 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001538 QualType(), 0);
1539 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001540 case DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001541 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001542 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001543 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001544 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001545 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001546 case DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001547 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1548 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001549 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001550 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001551 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001552 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001553 case DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001554 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001555 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001556 case DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001557 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001558 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001559 case DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001560 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001561 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001562 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001563 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001564 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001565 SourceLocation(), 0,
Douglas Gregorb1b71e52010-11-17 01:03:52 +00001566 ObjCPropertyImplDecl::Dynamic, 0,
1567 SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001568 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001569 case DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001570 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001571 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001572 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00001573 case DECL_INDIRECTFIELD:
1574 D = IndirectFieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
1575 0, 0);
1576 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001577 case DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001578 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCall8e7d6562010-08-26 03:08:43 +00001579 SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001580 break;
1581
Sebastian Redl539c5062010-08-18 23:57:32 +00001582 case DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001583 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001584 break;
1585
Sebastian Redl539c5062010-08-18 23:57:32 +00001586 case DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001587 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCall8e7d6562010-08-26 03:08:43 +00001588 SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001589 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001590 case DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001591 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001592 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001593 case DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001594 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001595 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001596 case DECL_CXX_BASE_SPECIFIERS:
1597 Error("attempt to read a C++ base-specifier record as a declaration");
1598 return 0;
Chris Lattner487412d2009-04-27 05:27:42 +00001599 }
Chris Lattner487412d2009-04-27 05:27:42 +00001600
Sebastian Redlb3298c32010-08-18 23:56:48 +00001601 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001602 LoadedDecl(Index, D);
1603 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001604
1605 // If this declaration is also a declaration context, get the
1606 // offsets for its tables of lexical and visible declarations.
1607 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1608 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1609 if (Offsets.first || Offsets.second) {
1610 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1611 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001612 DeclContextInfo Info;
1613 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1614 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001615 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001616 // Reading the TU will happen after reading its lexical update blocks,
1617 // so we need to make sure we insert in front. For all other contexts,
1618 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001619 Infos.insert(Infos.begin(), Info);
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001620
1621 // Now add the pending visible updates for this decl context, if it has
1622 // any.
1623 DeclContextVisibleUpdatesPending::iterator I =
1624 PendingVisibleUpdates.find(ID);
1625 if (I != PendingVisibleUpdates.end()) {
1626 DeclContextVisibleUpdates &U = I->second;
1627 Info.LexicalDecls = 0;
1628 Info.NumLexicalDecls = 0;
1629 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1630 UI != UE; ++UI) {
1631 Info.NameLookupTableData = *UI;
1632 Infos.push_back(Info);
1633 }
1634 PendingVisibleUpdates.erase(I);
1635 }
Chris Lattner487412d2009-04-27 05:27:42 +00001636 }
1637 }
1638 assert(Idx == Record.size());
1639
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001640 // The declaration may have been modified by files later in the chain.
1641 // If this is the case, read the record containing the updates from each file
1642 // and pass it to ASTDeclReader to make the modifications.
1643 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1644 if (UpdI != DeclUpdateOffsets.end()) {
1645 FileOffsetsTy &UpdateOffsets = UpdI->second;
1646 for (FileOffsetsTy::iterator
1647 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
1648 PerFileData *F = I->first;
1649 uint64_t Offset = I->second;
1650 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1651 SavedStreamPosition SavedPosition(Cursor);
1652 Cursor.JumpToBit(Offset);
1653 RecordData Record;
1654 unsigned Code = Cursor.ReadCode();
1655 unsigned RecCode = Cursor.ReadRecord(Code, Record);
1656 (void)RecCode;
1657 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
1658 Reader.UpdateDecl(D, Record);
1659 }
1660 }
1661
Chris Lattner487412d2009-04-27 05:27:42 +00001662 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001663 // AST consumer might need to know about, queue it.
1664 // We don't pass it to the consumer immediately because we may be in recursive
1665 // loading, and some declarations may still be initializing.
1666 if (isConsumerInterestedIn(D))
1667 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001668
1669 return D;
1670}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001671
1672void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001673 unsigned Idx = 0;
1674 while (Idx < Record.size()) {
1675 switch ((DeclUpdateKind)Record[Idx++]) {
1676 case UPD_CXX_SET_DEFINITIONDATA: {
1677 CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
1678 CXXRecordDecl *
1679 DefinitionDecl = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
1680 assert(!RD->DefinitionData && "DefinitionData is already set!");
1681 InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1682 break;
1683 }
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00001684
1685 case UPD_CXX_ADDED_IMPLICIT_MEMBER:
1686 cast<CXXRecordDecl>(D)->addedMember(Reader.GetDecl(Record[Idx++]));
1687 break;
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00001688
1689 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1690 // It will be added to the template's specializations set when loaded.
1691 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00001692 }
1693 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00001694}