blob: cb18108cad17fc445b48411658afe55f99384a73 [file] [log] [blame]
Chris Lattner698f9252009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
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//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
Chris Lattner6ad9ac02010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner698f9252009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000030namespace clang {
Chris Lattner698f9252009-04-27 05:27:42 +000031 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
32 PCHReader &Reader;
Sebastian Redl577d4792010-07-22 22:43:28 +000033 llvm::BitstreamCursor &Cursor;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000034 const pch::DeclID ThisDeclID;
Chris Lattner698f9252009-04-27 05:27:42 +000035 const PCHReader::RecordData &Record;
36 unsigned &Idx;
Douglas Gregordeacbdc2010-08-11 12:19:30 +000037 pch::TypeID TypeIDForTypeDecl;
Chris Lattner698f9252009-04-27 05:27:42 +000038
Sebastian Redl577d4792010-07-22 22:43:28 +000039 uint64_t GetCurrentCursorOffset();
40
Chris Lattner698f9252009-04-27 05:27:42 +000041 public:
Sebastian Redl577d4792010-07-22 22:43:28 +000042 PCHDeclReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor,
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000043 pch::DeclID thisDeclID, const PCHReader::RecordData &Record,
44 unsigned &Idx)
45 : Reader(Reader), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record),
Douglas Gregordeacbdc2010-08-11 12:19:30 +000046 Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner698f9252009-04-27 05:27:42 +000047
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +000048 void Visit(Decl *D);
49
Chris Lattner698f9252009-04-27 05:27:42 +000050 void VisitDecl(Decl *D);
51 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
52 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregor0cef4832010-02-21 18:22:14 +000053 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000054 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
55 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000056 void VisitTypeDecl(TypeDecl *TD);
57 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +000058 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000059 void VisitTagDecl(TagDecl *TD);
60 void VisitEnumDecl(EnumDecl *ED);
61 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000062 void VisitCXXRecordDecl(CXXRecordDecl *D);
63 void VisitClassTemplateSpecializationDecl(
64 ClassTemplateSpecializationDecl *D);
65 void VisitClassTemplatePartialSpecializationDecl(
66 ClassTemplatePartialSpecializationDecl *D);
67 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000068 void VisitValueDecl(ValueDecl *VD);
69 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +000070 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000071 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000072 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000073 void VisitCXXMethodDecl(CXXMethodDecl *D);
74 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
75 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
76 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000077 void VisitFieldDecl(FieldDecl *FD);
78 void VisitVarDecl(VarDecl *VD);
79 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
80 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000081 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
82 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +000083 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000084 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +000085 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000086 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +000087 void VisitUsingDecl(UsingDecl *D);
88 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000089 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000090 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnara6206d532010-06-05 05:09:32 +000091 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000092 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000093 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
94 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000095 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000096
Chris Lattner698f9252009-04-27 05:27:42 +000097 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000098 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000099
Sean Hunt9a555912010-05-30 07:21:58 +0000100 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-04-27 05:27:42 +0000101 void VisitObjCMethodDecl(ObjCMethodDecl *D);
102 void VisitObjCContainerDecl(ObjCContainerDecl *D);
103 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
104 void VisitObjCIvarDecl(ObjCIvarDecl *D);
105 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
106 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
107 void VisitObjCClassDecl(ObjCClassDecl *D);
108 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
109 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
110 void VisitObjCImplDecl(ObjCImplDecl *D);
111 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
112 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
113 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
114 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
115 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
116 };
117}
118
Sebastian Redl577d4792010-07-22 22:43:28 +0000119uint64_t PCHDeclReader::GetCurrentCursorOffset() {
120 uint64_t Off = 0;
121 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
122 PCHReader::PerFileData &F = *Reader.Chain[N - I - 1];
123 if (&Cursor == &F.DeclsCursor) {
124 Off += F.DeclsCursor.GetCurrentBitNo();
125 break;
126 }
127 Off += F.SizeInBits;
128 }
129 return Off;
130}
131
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000132void PCHDeclReader::Visit(Decl *D) {
133 DeclVisitor<PCHDeclReader, void>::Visit(D);
134
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000135 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000136 // if we have a fully initialized TypeDecl, we can safely read its type now.
137 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000138 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
139 // FunctionDecl's body was written last after all other Stmts/Exprs.
140 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000141 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000142 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000143}
144
Chris Lattner698f9252009-04-27 05:27:42 +0000145void PCHDeclReader::VisitDecl(Decl *D) {
146 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
147 D->setLexicalDeclContext(
148 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
149 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
150 D->setInvalidDecl(Record[Idx++]);
151 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000152 D->initAttrs(Reader.ReadAttributes(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000153 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000154 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000155 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000156 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +0000157}
158
159void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
160 VisitDecl(TU);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000161 TU->setAnonymousNamespace(
162 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000163}
164
165void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
166 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +0000167 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000168}
169
170void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
171 VisitNamedDecl(TD);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000172 // Delay type reading until after we have fully initialized the decl.
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000173 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000174}
175
176void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000177 VisitTypeDecl(TD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000178 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000179}
180
181void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
182 VisitTypeDecl(TD);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000183 TD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000184 VisitRedeclarable(TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000185 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
186 TD->setDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000187 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000188 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000189 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallb6217662010-03-15 10:12:16 +0000190 // FIXME: maybe read optional qualifier and its range.
191 TD->setTypedefForAnonDecl(
192 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000193}
194
195void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
196 VisitTagDecl(ED);
197 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000198 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall1b5a6182010-05-06 08:49:23 +0000199 ED->setNumPositiveBits(Record[Idx++]);
200 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis74228272010-07-06 15:36:48 +0000201 ED->setInstantiationOfMemberEnum(
202 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000203}
204
205void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
206 VisitTagDecl(RD);
207 RD->setHasFlexibleArrayMember(Record[Idx++]);
208 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000209 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000210}
211
212void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
213 VisitNamedDecl(VD);
214 VD->setType(Reader.GetType(Record[Idx++]));
215}
216
217void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
218 VisitValueDecl(ECD);
219 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000220 ECD->setInitExpr(Reader.ReadExpr(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000221 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
222}
223
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000224void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
225 VisitValueDecl(DD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000226 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
John McCalla93c9342009-12-07 02:54:59 +0000227 if (TInfo)
228 DD->setTypeSourceInfo(TInfo);
John McCallb6217662010-03-15 10:12:16 +0000229 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000230}
231
Chris Lattner698f9252009-04-27 05:27:42 +0000232void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000233 VisitDeclaratorDecl(FD);
Abramo Bagnara25777432010-08-11 22:01:17 +0000234 // FIXME: read DeclarationNameLoc.
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000235
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000236 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000237 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000238 default: assert(false && "Unhandled TemplatedKind!");
239 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000240 case FunctionDecl::TK_NonTemplate:
241 break;
242 case FunctionDecl::TK_FunctionTemplate:
243 FD->setDescribedFunctionTemplate(
244 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
245 break;
246 case FunctionDecl::TK_MemberSpecialization: {
247 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
248 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
249 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
250 FD->setInstantiationOfMemberFunction(InstFD, TSK);
251 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
252 break;
253 }
254 case FunctionDecl::TK_FunctionTemplateSpecialization: {
255 FunctionTemplateDecl *Template
256 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
257 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
258
259 // Template arguments.
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000260 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl577d4792010-07-22 22:43:28 +0000261 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000262
263 // Template args as written.
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000264 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000265 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000266 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
267 unsigned NumTemplateArgLocs = Record[Idx++];
268 TemplArgLocs.reserve(NumTemplateArgLocs);
269 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000270 TemplArgLocs.push_back(
271 Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000272
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000273 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
274 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
275 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000276
277 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000278
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000279 if (FD->isCanonicalDecl()) // if canonical add to template's set.
280 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
281 TemplArgs.data(), TSK,
282 TemplArgLocs.size(),
283 TemplArgLocs.data(),
284 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000285 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000286 }
287 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
288 // Templates.
289 UnresolvedSet<8> TemplDecls;
290 unsigned NumTemplates = Record[Idx++];
291 while (NumTemplates--)
292 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
293
294 // Templates args.
295 TemplateArgumentListInfo TemplArgs;
296 unsigned NumArgs = Record[Idx++];
297 while (NumArgs--)
Sebastian Redl577d4792010-07-22 22:43:28 +0000298 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000299 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
300 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000301
302 FD->setDependentTemplateSpecialization(*Reader.getContext(),
303 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000304 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000305 }
306 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000307
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000308 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
309 // after everything else is read.
310
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000311 VisitRedeclarable(FD);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000312 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
313 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
314 FD->setInlineSpecified(Record[Idx++]);
315 FD->setVirtualAsWritten(Record[Idx++]);
316 FD->setPure(Record[Idx++]);
317 FD->setHasInheritedPrototype(Record[Idx++]);
318 FD->setHasWrittenPrototype(Record[Idx++]);
319 FD->setDeleted(Record[Idx++]);
320 FD->setTrivial(Record[Idx++]);
321 FD->setCopyAssignment(Record[Idx++]);
322 FD->setHasImplicitReturnZero(Record[Idx++]);
323 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
324
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000325 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000326 unsigned NumParams = Record[Idx++];
327 llvm::SmallVector<ParmVarDecl *, 16> Params;
328 Params.reserve(NumParams);
329 for (unsigned I = 0; I != NumParams; ++I)
330 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000331 FD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000332}
333
334void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
335 VisitNamedDecl(MD);
336 if (Record[Idx++]) {
337 // In practice, this won't be executed (since method definitions
338 // don't occur in header files).
Sebastian Redl577d4792010-07-22 22:43:28 +0000339 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000340 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
341 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
342 }
343 MD->setInstanceMethod(Record[Idx++]);
344 MD->setVariadic(Record[Idx++]);
345 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000346 MD->setDefined(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000347 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
348 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000349 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000350 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redl577d4792010-07-22 22:43:28 +0000351 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000352 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
353 unsigned NumParams = Record[Idx++];
354 llvm::SmallVector<ParmVarDecl *, 16> Params;
355 Params.reserve(NumParams);
356 for (unsigned I = 0; I != NumParams; ++I)
357 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian4ecb25f2010-04-09 15:40:42 +0000358 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
359 NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000360}
361
362void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
363 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000364 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
365 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
366 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000367}
368
369void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
370 VisitObjCContainerDecl(ID);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000371 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000372 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
373 (Reader.GetDecl(Record[Idx++])));
374 unsigned NumProtocols = Record[Idx++];
375 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
376 Protocols.reserve(NumProtocols);
377 for (unsigned I = 0; I != NumProtocols; ++I)
378 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000379 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
380 ProtoLocs.reserve(NumProtocols);
381 for (unsigned I = 0; I != NumProtocols; ++I)
382 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
383 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
384 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000385 unsigned NumIvars = Record[Idx++];
386 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
387 IVars.reserve(NumIvars);
388 for (unsigned I = 0; I != NumIvars; ++I)
389 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000390 ID->setCategoryList(
391 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000392 ID->setForwardDecl(Record[Idx++]);
393 ID->setImplicitInterfaceDecl(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000394 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
395 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000396 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000397}
398
399void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
400 VisitFieldDecl(IVD);
401 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000402 bool synth = Record[Idx++];
403 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000404}
405
406void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
407 VisitObjCContainerDecl(PD);
408 PD->setForwardDecl(Record[Idx++]);
409 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
410 unsigned NumProtoRefs = Record[Idx++];
411 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
412 ProtoRefs.reserve(NumProtoRefs);
413 for (unsigned I = 0; I != NumProtoRefs; ++I)
414 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000415 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
416 ProtoLocs.reserve(NumProtoRefs);
417 for (unsigned I = 0; I != NumProtoRefs; ++I)
418 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
419 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
420 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000421}
422
423void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
424 VisitFieldDecl(FD);
425}
426
427void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
428 VisitDecl(CD);
429 unsigned NumClassRefs = Record[Idx++];
430 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
431 ClassRefs.reserve(NumClassRefs);
432 for (unsigned I = 0; I != NumClassRefs; ++I)
433 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000434 llvm::SmallVector<SourceLocation, 16> SLocs;
435 SLocs.reserve(NumClassRefs);
436 for (unsigned I = 0; I != NumClassRefs; ++I)
437 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
438 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
439 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000440}
441
442void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
443 VisitDecl(FPD);
444 unsigned NumProtoRefs = Record[Idx++];
445 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
446 ProtoRefs.reserve(NumProtoRefs);
447 for (unsigned I = 0; I != NumProtoRefs; ++I)
448 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000449 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
450 ProtoLocs.reserve(NumProtoRefs);
451 for (unsigned I = 0; I != NumProtoRefs; ++I)
452 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
453 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
454 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000455}
456
457void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
458 VisitObjCContainerDecl(CD);
459 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
460 unsigned NumProtoRefs = Record[Idx++];
461 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
462 ProtoRefs.reserve(NumProtoRefs);
463 for (unsigned I = 0; I != NumProtoRefs; ++I)
464 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000465 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
466 ProtoLocs.reserve(NumProtoRefs);
467 for (unsigned I = 0; I != NumProtoRefs; ++I)
468 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
469 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
470 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000471 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor3db211b2010-01-16 16:38:58 +0000472 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
473 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000474}
475
476void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
477 VisitNamedDecl(CAD);
478 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
479}
480
481void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
482 VisitNamedDecl(D);
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000483 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redl577d4792010-07-22 22:43:28 +0000484 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000485 // FIXME: stable encoding
486 D->setPropertyAttributes(
487 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000488 D->setPropertyAttributesAsWritten(
489 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000490 // FIXME: stable encoding
491 D->setPropertyImplementation(
492 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
493 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
494 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
495 D->setGetterMethodDecl(
496 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
497 D->setSetterMethodDecl(
498 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
499 D->setPropertyIvarDecl(
500 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
501}
502
503void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000504 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000505 D->setClassInterface(
506 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000507}
508
509void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
510 VisitObjCImplDecl(D);
511 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
512}
513
514void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
515 VisitObjCImplDecl(D);
516 D->setSuperClass(
517 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000518 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
519 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +0000520}
521
522
523void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
524 VisitDecl(D);
525 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
526 D->setPropertyDecl(
527 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
528 D->setPropertyIvarDecl(
529 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis2f922302010-08-09 10:54:37 +0000530 D->setGetterCXXConstructor(Reader.ReadExpr(Cursor));
531 D->setSetterCXXAssignment(Reader.ReadExpr(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000532}
533
534void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000535 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000536 FD->setMutable(Record[Idx++]);
537 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000538 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000539 if (!FD->getDeclName()) {
540 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
541 if (Tmpl)
542 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
543 }
Chris Lattner698f9252009-04-27 05:27:42 +0000544}
545
546void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000547 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000548 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregor16573fa2010-04-19 22:54:31 +0000549 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000550 VD->setThreadSpecified(Record[Idx++]);
551 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor324b54d2010-05-03 18:51:14 +0000552 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor5077c382010-05-15 06:01:05 +0000553 VD->setNRVOVariable(Record[Idx++]);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000554 VisitRedeclarable(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000555 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000556 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000557
558 if (Record[Idx++]) { // HasMemberSpecializationInfo.
559 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
560 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
561 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
562 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
563 }
Chris Lattner698f9252009-04-27 05:27:42 +0000564}
565
566void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
567 VisitVarDecl(PD);
568}
569
570void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
571 VisitVarDecl(PD);
572 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallbf73b352010-03-12 18:31:32 +0000573 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000574 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl577d4792010-07-22 22:43:28 +0000575 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000576}
577
Chris Lattner698f9252009-04-27 05:27:42 +0000578void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
579 VisitDecl(AD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000580 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner698f9252009-04-27 05:27:42 +0000581}
582
583void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
584 VisitDecl(BD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000585 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
586 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000587 unsigned NumParams = Record[Idx++];
588 llvm::SmallVector<ParmVarDecl *, 16> Params;
589 Params.reserve(NumParams);
590 for (unsigned I = 0; I != NumParams; ++I)
591 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000592 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000593}
594
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000595void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
596 VisitDecl(D);
597 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
598 D->setHasBraces(Record[Idx++]);
599}
600
601void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
602 VisitNamedDecl(D);
603 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
604 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
605 D->setNextNamespace(
606 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
607
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000608 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000609 D->OrigOrAnonNamespace.setInt(IsOriginal);
610 D->OrigOrAnonNamespace.setPointer(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000611 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
612}
613
614void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
615 VisitNamedDecl(D);
616
617 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
618 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
619 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
620 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
621 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
622}
623
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000624void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000625 VisitNamedDecl(D);
626 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
627 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
628 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
629
630 // FIXME: It would probably be more efficient to read these into a vector
631 // and then re-cosntruct the shadow decl set over that vector since it
632 // would avoid existence checks.
633 unsigned NumShadows = Record[Idx++];
634 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis82f8e792010-07-08 13:09:41 +0000635 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
636 // be initializing.
637 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000638 }
639 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000640 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
641 if (Pattern)
642 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000643}
644
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000645void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000646 VisitNamedDecl(D);
647 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
648 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000649 UsingShadowDecl *Pattern
650 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
651 if (Pattern)
652 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000653}
654
655void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
656 VisitNamedDecl(D);
657 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
658 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
659 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
660 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
661 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
662 D->setCommonAncestor(cast_or_null<DeclContext>(
663 Reader.GetDecl(Record[Idx++])));
664}
665
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000666void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000667 VisitValueDecl(D);
668 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
669 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
670 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
671}
672
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000673void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000674 UnresolvedUsingTypenameDecl *D) {
675 VisitTypeDecl(D);
676 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
677 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
678 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
679 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
680}
681
682void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000683 ASTContext &C = *Reader.getContext();
684
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000685 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
686 // so that the other CXXRecordDecls can get a pointer even when the owner
687 // is still initializing.
688 bool OwnsDefinitionData = false;
689 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
690 switch ((DataOwnership)Record[Idx++]) {
691 default:
692 assert(0 && "Out of sync with PCHDeclWriter or messed up reading");
693 case Data_NoDefData:
694 break;
695 case Data_Owner:
696 OwnsDefinitionData = true;
697 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
698 break;
699 case Data_NotOwner:
700 D->DefinitionData
701 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
702 break;
703 }
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000704
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000705 VisitRecordDecl(D);
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000706
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000707 if (OwnsDefinitionData) {
708 assert(D->DefinitionData);
709 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000710
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000711 Data.UserDeclaredConstructor = Record[Idx++];
712 Data.UserDeclaredCopyConstructor = Record[Idx++];
713 Data.UserDeclaredCopyAssignment = Record[Idx++];
714 Data.UserDeclaredDestructor = Record[Idx++];
715 Data.Aggregate = Record[Idx++];
716 Data.PlainOldData = Record[Idx++];
717 Data.Empty = Record[Idx++];
718 Data.Polymorphic = Record[Idx++];
719 Data.Abstract = Record[Idx++];
720 Data.HasTrivialConstructor = Record[Idx++];
721 Data.HasTrivialCopyConstructor = Record[Idx++];
722 Data.HasTrivialCopyAssignment = Record[Idx++];
723 Data.HasTrivialDestructor = Record[Idx++];
724 Data.ComputedVisibleConversions = Record[Idx++];
725 Data.DeclaredDefaultConstructor = Record[Idx++];
726 Data.DeclaredCopyConstructor = Record[Idx++];
727 Data.DeclaredCopyAssignment = Record[Idx++];
728 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000729
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000730 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky56062202010-07-26 16:56:01 +0000731 // uninitialized base.
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000732 Data.NumBases = Record[Idx++];
733 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
734 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky56062202010-07-26 16:56:01 +0000735 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000736
737 // FIXME: Make VBases lazily computed when needed to avoid storing them.
738 Data.NumVBases = Record[Idx++];
739 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
740 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky56062202010-07-26 16:56:01 +0000741 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000742
743 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
744 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
745 assert(Data.Definition && "Data.Definition should be already set!");
746 Data.FirstFriend
747 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000748 }
749
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000750 enum CXXRecKind {
751 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
752 };
753 switch ((CXXRecKind)Record[Idx++]) {
754 default:
755 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
756 case CXXRecNotTemplate:
757 break;
758 case CXXRecTemplate:
759 D->setDescribedClassTemplate(
760 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
761 break;
762 case CXXRecMemberSpecialization: {
763 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
764 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
765 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
766 D->setInstantiationOfMemberClass(RD, TSK);
767 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
768 break;
769 }
770 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000771}
772
773void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000774 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000775 unsigned NumOverridenMethods = Record[Idx++];
776 while (NumOverridenMethods--) {
777 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
778 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
779 // MD may be initializing.
780 Reader.getContext()->addOverriddenMethod(D, MD);
781 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000782}
783
784void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000785 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000786
787 D->IsExplicitSpecified = Record[Idx++];
788 D->ImplicitlyDefined = Record[Idx++];
Argyrios Kyrtzidis8e706f42010-08-09 10:54:12 +0000789 llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers)
790 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000791}
792
793void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000794 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000795
796 D->ImplicitlyDefined = Record[Idx++];
797 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000798}
799
800void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000801 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000802 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000803}
804
Abramo Bagnara6206d532010-06-05 05:09:32 +0000805void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
806 VisitDecl(D);
807 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
808}
809
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000810void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000811 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000812 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000813 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000814 else
815 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
816 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
817 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
818}
819
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000820void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000821 VisitDecl(D);
822 unsigned NumParams = Record[Idx++];
823 D->NumParams = NumParams;
824 D->Params = new TemplateParameterList*[NumParams];
825 for (unsigned i = 0; i != NumParams; ++i)
826 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
827 if (Record[Idx++]) // HasFriendDecl
828 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
829 else
Sebastian Redl577d4792010-07-22 22:43:28 +0000830 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000831 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000832}
833
834void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000835 VisitNamedDecl(D);
836
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +0000837 NamedDecl *TemplatedDecl
838 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000839 TemplateParameterList* TemplateParams
840 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000841 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000842}
843
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000844void PCHDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000845 VisitTemplateDecl(D);
846
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000847 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000848 RedeclarableTemplateDecl *PrevDecl =
849 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
850 assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) &&
851 "PrevDecl kind mismatch");
852 if (PrevDecl)
853 D->CommonOrPrev = PrevDecl;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000854 if (PrevDecl == 0) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000855 if (RedeclarableTemplateDecl *RTD
856 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
857 assert(RTD->getKind() == D->getKind() &&
858 "InstantiatedFromMemberTemplate kind mismatch");
859 D->setInstantiatedFromMemberTemplateImpl(RTD);
860 if (Record[Idx++])
861 D->setMemberSpecialization();
862 }
Peter Collingbourne8a798a72010-07-29 16:12:01 +0000863
864 RedeclarableTemplateDecl *LatestDecl =
865 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000866
867 // This decl is a first one and the latest declaration that it points to is
868 // in the same PCH. However, if this actually needs to point to a
869 // redeclaration in another chained PCH, we need to update it by checking
870 // the FirstLatestDeclIDs map which tracks this kind of decls.
871 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
872 PCHReader::FirstLatestDeclIDMap::iterator I
873 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
874 if (I != Reader.FirstLatestDeclIDs.end()) {
875 Decl *NewLatest = Reader.GetDecl(I->second);
876 assert((LatestDecl->getLocation().isInvalid() ||
877 NewLatest->getLocation().isInvalid() ||
878 Reader.SourceMgr.isBeforeInTranslationUnit(
879 LatestDecl->getLocation(),
880 NewLatest->getLocation())) &&
881 "The new latest is supposed to come after the previous latest");
882 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
883 }
884
Peter Collingbourne8a798a72010-07-29 16:12:01 +0000885 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
886 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000887 }
888}
889
890void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
891 VisitRedeclarableTemplateDecl(D);
892
893 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000894 // This ClassTemplateDecl owns a CommonPtr; read it.
895
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000896 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000897 unsigned size = Record[Idx++];
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000898 while (size--)
899 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000900
901 size = Record[Idx++];
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000902 while (size--)
903 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000904 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000905
906 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000907 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000908}
909
910void PCHDeclReader::VisitClassTemplateSpecializationDecl(
911 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000912 VisitCXXRecordDecl(D);
913
914 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
915 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
916 D->setInstantiationOf(CTD);
917 } else {
918 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl577d4792010-07-22 22:43:28 +0000919 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000920 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
921 TemplArgs.data(), TemplArgs.size());
922 }
923 }
924
925 // Explicit info.
Sebastian Redl577d4792010-07-22 22:43:28 +0000926 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000927 D->setTypeAsWritten(TyInfo);
928 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
929 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
930 }
931
932 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl577d4792010-07-22 22:43:28 +0000933 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000934 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
935 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
936 if (POI.isValid())
937 D->setPointOfInstantiation(POI);
938 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000939
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +0000940 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000941 ClassTemplateDecl *CanonPattern
942 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
943 if (ClassTemplatePartialSpecializationDecl *Partial
944 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidis0a67edd2010-07-12 21:41:31 +0000945 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000946 } else {
Argyrios Kyrtzidis0a67edd2010-07-12 21:41:31 +0000947 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000948 }
949 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000950}
951
952void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
953 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000954 VisitClassTemplateSpecializationDecl(D);
955
956 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
957
958 TemplateArgumentListInfo ArgInfos;
959 unsigned NumArgs = Record[Idx++];
960 while (NumArgs--)
Sebastian Redl577d4792010-07-22 22:43:28 +0000961 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000962 D->initTemplateArgsAsWritten(ArgInfos);
963
964 D->setSequenceNumber(Record[Idx++]);
965
966 // These are read/set from/to the first declaration.
967 if (D->getPreviousDeclaration() == 0) {
968 D->setInstantiatedFromMember(
969 cast_or_null<ClassTemplatePartialSpecializationDecl>(
970 Reader.GetDecl(Record[Idx++])));
971 if (Record[Idx++])
Argyrios Kyrtzidis64a5e2c2010-07-09 21:11:35 +0000972 D->setMemberSpecialization();
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000973 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000974}
975
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000976void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000977 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000978
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000979 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000980 // This FunctionTemplateDecl owns a CommonPtr; read it.
981
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +0000982 // Read the function specialization declarations.
983 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
984 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
985 unsigned NumSpecs = Record[Idx++];
986 while (NumSpecs--)
987 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000988 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000989}
990
991void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000992 VisitTypeDecl(D);
993
994 D->setDeclaredWithTypename(Record[Idx++]);
995 D->setParameterPack(Record[Idx++]);
996
997 bool Inherited = Record[Idx++];
Sebastian Redl577d4792010-07-22 22:43:28 +0000998 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000999 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001000}
1001
1002void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001003 VisitVarDecl(D);
1004 // TemplateParmPosition.
1005 D->setDepth(Record[Idx++]);
1006 D->setPosition(Record[Idx++]);
1007 // Rest of NonTypeTemplateParmDecl.
1008 if (Record[Idx++]) {
Sebastian Redl577d4792010-07-22 22:43:28 +00001009 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001010 bool Inherited = Record[Idx++];
1011 D->setDefaultArgument(DefArg, Inherited);
1012 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001013}
1014
1015void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001016 VisitTemplateDecl(D);
1017 // TemplateParmPosition.
1018 D->setDepth(Record[Idx++]);
1019 D->setPosition(Record[Idx++]);
1020 // Rest of TemplateTemplateParmDecl.
Sebastian Redl577d4792010-07-22 22:43:28 +00001021 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001022 bool IsInherited = Record[Idx++];
1023 D->setDefaultArgument(Arg, IsInherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001024}
1025
1026void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001027 VisitDecl(D);
Sebastian Redl577d4792010-07-22 22:43:28 +00001028 D->AssertExpr = Reader.ReadExpr(Cursor);
1029 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001030}
1031
Mike Stump1eb44332009-09-09 15:08:12 +00001032std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +00001033PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1034 uint64_t LexicalOffset = Record[Idx++];
1035 uint64_t VisibleOffset = Record[Idx++];
1036 return std::make_pair(LexicalOffset, VisibleOffset);
1037}
1038
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001039template <typename T>
1040void PCHDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
1041 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1042 RedeclKind Kind = (RedeclKind)Record[Idx++];
1043 switch (Kind) {
1044 default:
1045 assert(0 && "Out of sync with PCHDeclWriter::VisitRedeclarable or messed up"
1046 " reading");
1047 case NoRedeclaration:
1048 break;
1049 case PointsToPrevious:
1050 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
1051 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1052 break;
1053 case PointsToLatest:
1054 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1055 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1056 break;
1057 }
1058
1059 assert(!(Kind == PointsToPrevious &&
1060 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1061 Reader.FirstLatestDeclIDs.end()) &&
1062 "This decl is not first, it should not be in the map");
1063 if (Kind == PointsToPrevious)
1064 return;
1065
1066 // This decl is a first one and the latest declaration that it points to is in
1067 // the same PCH. However, if this actually needs to point to a redeclaration
1068 // in another chained PCH, we need to update it by checking the
1069 // FirstLatestDeclIDs map which tracks this kind of decls.
1070 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1071 "Invalid ThisDeclID ?");
1072 PCHReader::FirstLatestDeclIDMap::iterator I
1073 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1074 if (I != Reader.FirstLatestDeclIDs.end()) {
1075 Decl *NewLatest = Reader.GetDecl(I->second);
1076 assert((D->getMostRecentDeclaration()->getLocation().isInvalid() ||
1077 NewLatest->getLocation().isInvalid() ||
1078 Reader.SourceMgr.isBeforeInTranslationUnit(
1079 D->getMostRecentDeclaration()->getLocation(),
1080 NewLatest->getLocation())) &&
1081 "The new latest is supposed to come after the previous latest");
1082 D->RedeclLink
1083 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1084 }
1085}
1086
Chris Lattner698f9252009-04-27 05:27:42 +00001087//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001088// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001089//===----------------------------------------------------------------------===//
1090
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001091/// \brief Reads attributes from the current stream position.
Sebastian Redl577d4792010-07-22 22:43:28 +00001092Attr *PCHReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001093 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +00001094 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001095 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001097 RecordData Record;
1098 unsigned Idx = 0;
1099 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +00001100 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001101 (void)RecCode;
1102
1103#define SIMPLE_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +00001104 case attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001105 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001106 break
1107
1108#define STRING_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +00001109 case attr::Name: \
Ted Kremenek3d2c43e2010-02-11 05:28:37 +00001110 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001111 break
1112
1113#define UNSIGNED_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +00001114 case attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001115 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001116 break
1117
1118 Attr *Attrs = 0;
1119 while (Idx < Record.size()) {
1120 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001121 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001122 bool IsInherited = Record[Idx++];
1123
1124 switch (Kind) {
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001125 default:
1126 assert(0 && "Unknown attribute!");
1127 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001128 STRING_ATTR(Alias);
Daniel Dunbar4e9255f2010-05-27 02:25:39 +00001129 SIMPLE_ATTR(AlignMac68k);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001130 UNSIGNED_ATTR(Aligned);
1131 SIMPLE_ATTR(AlwaysInline);
1132 SIMPLE_ATTR(AnalyzerNoReturn);
1133 STRING_ATTR(Annotate);
1134 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +00001135 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +00001136
Sean Hunt387475d2010-06-16 23:43:53 +00001137 case attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001138 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001139 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1140 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Eli Friedman8f4c59e2009-11-09 18:38:53 +00001142 SIMPLE_ATTR(CDecl);
1143
Sean Hunt387475d2010-06-16 23:43:53 +00001144 case attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001145 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001146 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1147 break;
1148
1149 SIMPLE_ATTR(Const);
1150 UNSIGNED_ATTR(Constructor);
1151 SIMPLE_ATTR(DLLExport);
1152 SIMPLE_ATTR(DLLImport);
1153 SIMPLE_ATTR(Deprecated);
1154 UNSIGNED_ATTR(Destructor);
1155 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +00001156 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +00001157
Sean Hunt387475d2010-06-16 23:43:53 +00001158 case attr::Format: {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001159 std::string Type = ReadString(Record, Idx);
1160 unsigned FormatIdx = Record[Idx++];
1161 unsigned FirstArg = Record[Idx++];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +00001162 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001163 break;
1164 }
Mike Stump1eb44332009-09-09 15:08:12 +00001165
Sean Hunt387475d2010-06-16 23:43:53 +00001166 case attr::FormatArg: {
Fariborz Jahanian5b160922009-05-20 17:41:43 +00001167 unsigned FormatIdx = Record[Idx++];
1168 New = ::new (*Context) FormatArgAttr(FormatIdx);
1169 break;
1170 }
Mike Stump1eb44332009-09-09 15:08:12 +00001171
Sean Hunt387475d2010-06-16 23:43:53 +00001172 case attr::Sentinel: {
Fariborz Jahanian5b530052009-05-13 18:09:35 +00001173 int sentinel = Record[Idx++];
1174 int nullPos = Record[Idx++];
1175 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1176 break;
1177 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001178
1179 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +00001180 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Sean Hunt387475d2010-06-16 23:43:53 +00001182 case attr::IBAction:
Ted Kremenekefbddd22010-02-17 02:37:45 +00001183 New = ::new (*Context) IBActionAttr();
1184 break;
1185
Sean Hunt387475d2010-06-16 23:43:53 +00001186 case attr::IBOutlet:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001187 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001188 break;
1189
Sean Hunt387475d2010-06-16 23:43:53 +00001190 case attr::IBOutletCollection: {
Ted Kremenek857e9182010-05-19 17:38:06 +00001191 ObjCInterfaceDecl *D =
1192 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1193 New = ::new (*Context) IBOutletCollectionAttr(D);
1194 break;
1195 }
1196
Ryan Flynn76168e22009-08-09 20:07:29 +00001197 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +00001198 SIMPLE_ATTR(NoDebug);
1199 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001200 SIMPLE_ATTR(NoReturn);
1201 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +00001202
Sean Hunt387475d2010-06-16 23:43:53 +00001203 case attr::NonNull: {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001204 unsigned Size = Record[Idx++];
1205 llvm::SmallVector<unsigned, 16> ArgNums;
1206 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1207 Idx += Size;
Ted Kremenek59616112010-02-11 07:31:47 +00001208 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001209 break;
1210 }
Mike Stump1eb44332009-09-09 15:08:12 +00001211
Sean Hunt387475d2010-06-16 23:43:53 +00001212 case attr::ReqdWorkGroupSize: {
Nate Begeman6f3d8382009-06-26 06:32:41 +00001213 unsigned X = Record[Idx++];
1214 unsigned Y = Record[Idx++];
1215 unsigned Z = Record[Idx++];
1216 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1217 break;
1218 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001219
1220 SIMPLE_ATTR(ObjCException);
1221 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenek31c780d2010-02-18 00:05:45 +00001222 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +00001223 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenek31c780d2010-02-18 00:05:45 +00001224 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +00001225 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001226 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +00001227 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +00001228 SIMPLE_ATTR(Packed);
Daniel Dunbar8a2c92c2010-05-27 01:12:46 +00001229 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001230 SIMPLE_ATTR(Pure);
1231 UNSIGNED_ATTR(Regparm);
1232 STRING_ATTR(Section);
1233 SIMPLE_ATTR(StdCall);
Douglas Gregorf813a2c2010-05-18 16:57:00 +00001234 SIMPLE_ATTR(ThisCall);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001235 SIMPLE_ATTR(TransparentUnion);
1236 SIMPLE_ATTR(Unavailable);
1237 SIMPLE_ATTR(Unused);
1238 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +00001239
Sean Hunt387475d2010-06-16 23:43:53 +00001240 case attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001241 New = ::new (*Context) VisibilityAttr(
Eli Friedmanaa8b0d12010-08-05 06:57:20 +00001242 (VisibilityAttr::VisibilityTypes)Record[Idx++],
1243 (bool)Record[Idx++]);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001244 break;
1245
1246 SIMPLE_ATTR(WarnUnusedResult);
1247 SIMPLE_ATTR(Weak);
Rafael Espindola11e8ce72010-02-23 22:00:30 +00001248 SIMPLE_ATTR(WeakRef);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001249 SIMPLE_ATTR(WeakImport);
1250 }
1251
1252 assert(New && "Unable to decode attribute?");
1253 New->setInherited(IsInherited);
1254 New->setNext(Attrs);
1255 Attrs = New;
1256 }
1257#undef UNSIGNED_ATTR
1258#undef STRING_ATTR
1259#undef SIMPLE_ATTR
1260
1261 // The list of attributes was built backwards. Reverse the list
1262 // before returning it.
1263 Attr *PrevAttr = 0, *NextAttr = 0;
1264 while (Attrs) {
1265 NextAttr = Attrs->getNext();
1266 Attrs->setNext(PrevAttr);
1267 PrevAttr = Attrs;
1268 Attrs = NextAttr;
1269 }
1270
1271 return PrevAttr;
1272}
1273
1274//===----------------------------------------------------------------------===//
1275// PCHReader Implementation
1276//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001277
1278/// \brief Note that we have loaded the declaration with the given
1279/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001280///
Chris Lattner698f9252009-04-27 05:27:42 +00001281/// This routine notes that this declaration has already been loaded,
1282/// so that future GetDecl calls will return this declaration rather
1283/// than trying to load a new declaration.
1284inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1285 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1286 DeclsLoaded[Index] = D;
1287}
1288
1289
1290/// \brief Determine whether the consumer will be interested in seeing
1291/// this declaration (via HandleTopLevelDecl).
1292///
1293/// This routine should return true for anything that might affect
1294/// code generation, e.g., inline function definitions, Objective-C
1295/// declarations with metadata, etc.
1296static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001297 if (isa<FileScopeAsmDecl>(D))
1298 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001299 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001300 return Var->isFileVarDecl() &&
1301 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001302 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1303 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +00001304 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001305}
1306
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001307/// \brief Get the correct cursor and offset for loading a type.
1308PCHReader::RecordLocation PCHReader::DeclCursorForIndex(unsigned Index) {
1309 PerFileData *F = 0;
1310 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1311 F = Chain[N - I - 1];
1312 if (Index < F->LocalNumDecls)
1313 break;
1314 Index -= F->LocalNumDecls;
1315 }
1316 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redl971dd442010-07-20 22:55:31 +00001317 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001318}
1319
Chris Lattner698f9252009-04-27 05:27:42 +00001320/// \brief Read the declaration at the given offset from the PCH file.
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001321Decl *PCHReader::ReadDeclRecord(unsigned Index, pch::DeclID ID) {
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001322 RecordLocation Loc = DeclCursorForIndex(Index);
Sebastian Redl971dd442010-07-20 22:55:31 +00001323 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner698f9252009-04-27 05:27:42 +00001324 // Keep track of where we are in the stream, then jump back there
1325 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001326 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001327
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001328 ReadingKindTracker ReadingKind(Read_Decl, *this);
1329
Douglas Gregord89275b2009-07-06 18:54:52 +00001330 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001331 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001332
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001333 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner698f9252009-04-27 05:27:42 +00001334 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001335 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001336 unsigned Idx = 0;
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001337 PCHDeclReader Reader(*this, DeclsCursor, ID, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001338
Chris Lattnerda930612009-04-27 05:58:23 +00001339 Decl *D = 0;
1340 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +00001341 case pch::DECL_ATTR:
1342 case pch::DECL_CONTEXT_LEXICAL:
1343 case pch::DECL_CONTEXT_VISIBLE:
1344 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1345 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001346 case pch::DECL_TRANSLATION_UNIT:
1347 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001348 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +00001349 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001350 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +00001351 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001352 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001353 case pch::DECL_ENUM:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001354 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001355 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001356 case pch::DECL_RECORD:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001357 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001358 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001359 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001360 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001361 0, llvm::APSInt());
1362 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001363 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +00001364 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001365 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001366 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001367 case pch::DECL_LINKAGE_SPEC:
1368 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1369 (LinkageSpecDecl::LanguageIDs)0,
1370 false);
1371 break;
1372 case pch::DECL_NAMESPACE:
1373 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1374 break;
1375 case pch::DECL_NAMESPACE_ALIAS:
1376 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1377 SourceLocation(), 0, SourceRange(), 0,
1378 SourceLocation(), 0);
1379 break;
1380 case pch::DECL_USING:
1381 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1382 SourceLocation(), 0, DeclarationName(), false);
1383 break;
1384 case pch::DECL_USING_SHADOW:
1385 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1386 break;
1387 case pch::DECL_USING_DIRECTIVE:
1388 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1389 SourceLocation(), SourceRange(), 0,
1390 SourceLocation(), 0, 0);
1391 break;
1392 case pch::DECL_UNRESOLVED_USING_VALUE:
1393 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1394 SourceRange(), 0, SourceLocation(),
1395 DeclarationName());
1396 break;
1397 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1398 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1399 SourceLocation(), SourceRange(),
1400 0, SourceLocation(),
1401 DeclarationName());
1402 break;
1403 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001404 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001405 break;
1406 case pch::DECL_CXX_METHOD:
Abramo Bagnara25777432010-08-11 22:01:17 +00001407 D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001408 QualType(), 0);
1409 break;
1410 case pch::DECL_CXX_CONSTRUCTOR:
1411 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1412 break;
1413 case pch::DECL_CXX_DESTRUCTOR:
1414 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1415 break;
1416 case pch::DECL_CXX_CONVERSION:
1417 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1418 break;
Abramo Bagnara6206d532010-06-05 05:09:32 +00001419 case pch::DECL_ACCESS_SPEC:
1420 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1421 SourceLocation());
1422 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001423 case pch::DECL_FRIEND:
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001424 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001425 break;
1426 case pch::DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001427 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001428 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001429 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +00001430 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1431 DeclarationName(), 0, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001432 break;
1433 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001434 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001435 break;
1436 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001437 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1438 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001439 break;
1440 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001441 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1442 DeclarationName(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001443 break;
1444 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001445 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001446 break;
1447 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001448 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1449 QualType(),0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001450 break;
1451 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001452 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001453 break;
1454 case pch::DECL_STATIC_ASSERT:
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001455 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001456 break;
1457
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001458 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +00001459 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001460 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001461 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001462 case pch::DECL_OBJC_INTERFACE:
Douglas Gregordeacbdc2010-08-11 12:19:30 +00001463 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001464 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001465 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001466 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001467 ObjCIvarDecl::None);
1468 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001469 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001470 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001471 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001472 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001473 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001474 QualType(), 0);
1475 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001476 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001477 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001478 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001479 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001480 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001481 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001482 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +00001483 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1484 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001485 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001486 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001487 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001488 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001489 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001490 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001491 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001492 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001493 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001494 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001495 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001496 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001497 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001498 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001499 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001500 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001501 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001502 ObjCPropertyImplDecl::Dynamic, 0);
1503 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001504 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001505 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +00001506 false);
Chris Lattner698f9252009-04-27 05:27:42 +00001507 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001508 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001509 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001510 VarDecl::None, VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001511 break;
1512
1513 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001514 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001515 break;
1516
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001517 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +00001518 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001519 VarDecl::None, VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001520 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001521 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001522 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001523 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001524 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001525 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001526 break;
1527 }
Chris Lattner698f9252009-04-27 05:27:42 +00001528
1529 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001530 LoadedDecl(Index, D);
1531 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001532
1533 // If this declaration is also a declaration context, get the
1534 // offsets for its tables of lexical and visible declarations.
1535 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1536 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1537 if (Offsets.first || Offsets.second) {
1538 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1539 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl681d7232010-07-27 00:17:23 +00001540 DeclContextInfo Info;
1541 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1542 return 0;
Sebastian Redld692af72010-07-27 18:24:41 +00001543 DeclContextInfos &Infos = DeclContextOffsets[DC];
1544 // Reading the TU will happen after reading its update blocks, so we need
1545 // to make sure we insert in front. For all other contexts, the vector
1546 // is empty here anyway, so there's no loss in efficiency.
1547 Infos.insert(Infos.begin(), Info);
Chris Lattner698f9252009-04-27 05:27:42 +00001548 }
1549 }
1550 assert(Idx == Record.size());
1551
1552 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidisbb80a8e2010-07-07 15:46:26 +00001553 // AST consumer might need to know about, queue it.
1554 // We don't pass it to the consumer immediately because we may be in recursive
1555 // loading, and some declarations may still be initializing.
1556 if (isConsumerInterestedIn(D))
1557 InterestingDecls.push_back(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001558
1559 return D;
1560}
Sebastian Redl681d7232010-07-27 00:17:23 +00001561
1562bool PCHReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
1563 const std::pair<uint64_t, uint64_t> &Offsets,
1564 DeclContextInfo &Info) {
1565 SavedStreamPosition SavedPosition(Cursor);
1566 // First the lexical decls.
1567 if (Offsets.first != 0) {
1568 Cursor.JumpToBit(Offsets.first);
1569
1570 RecordData Record;
1571 const char *Blob;
1572 unsigned BlobLen;
1573 unsigned Code = Cursor.ReadCode();
1574 unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen);
1575 if (RecCode != pch::DECL_CONTEXT_LEXICAL) {
1576 Error("Expected lexical block");
1577 return true;
1578 }
1579
1580 Info.LexicalDecls = reinterpret_cast<const pch::DeclID*>(Blob);
1581 Info.NumLexicalDecls = BlobLen / sizeof(pch::DeclID);
1582 } else {
1583 Info.LexicalDecls = 0;
1584 Info.NumLexicalDecls = 0;
1585 }
1586
1587 // Now the visible decls.
1588 Info.Stream = &Cursor;
1589 Info.OffsetToVisibleDecls = Offsets.second;
1590
1591 return false;
1592}