blob: 4dc1318a3ee8699d114361d53429fd80a71afb17 [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"
20#include "clang/AST/Expr.h"
21using namespace clang;
22
Chris Lattner698f9252009-04-27 05:27:42 +000023
24//===----------------------------------------------------------------------===//
25// Declaration deserialization
26//===----------------------------------------------------------------------===//
27
28namespace {
29 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
30 PCHReader &Reader;
31 const PCHReader::RecordData &Record;
32 unsigned &Idx;
33
34 public:
35 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
36 unsigned &Idx)
37 : Reader(Reader), Record(Record), Idx(Idx) { }
38
39 void VisitDecl(Decl *D);
40 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
41 void VisitNamedDecl(NamedDecl *ND);
42 void VisitTypeDecl(TypeDecl *TD);
43 void VisitTypedefDecl(TypedefDecl *TD);
44 void VisitTagDecl(TagDecl *TD);
45 void VisitEnumDecl(EnumDecl *ED);
46 void VisitRecordDecl(RecordDecl *RD);
47 void VisitValueDecl(ValueDecl *VD);
48 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000049 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000050 void VisitFunctionDecl(FunctionDecl *FD);
51 void VisitFieldDecl(FieldDecl *FD);
52 void VisitVarDecl(VarDecl *VD);
53 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
54 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner698f9252009-04-27 05:27:42 +000055 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
56 void VisitBlockDecl(BlockDecl *BD);
57 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
58 void VisitObjCMethodDecl(ObjCMethodDecl *D);
59 void VisitObjCContainerDecl(ObjCContainerDecl *D);
60 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
61 void VisitObjCIvarDecl(ObjCIvarDecl *D);
62 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
63 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
64 void VisitObjCClassDecl(ObjCClassDecl *D);
65 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
66 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
67 void VisitObjCImplDecl(ObjCImplDecl *D);
68 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
69 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
70 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
71 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
72 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
73 };
74}
75
76void PCHDeclReader::VisitDecl(Decl *D) {
77 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
78 D->setLexicalDeclContext(
79 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
80 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
81 D->setInvalidDecl(Record[Idx++]);
82 if (Record[Idx++])
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +000083 D->addAttr(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +000084 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +000085 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +000086 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +000087 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +000088}
89
90void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
91 VisitDecl(TU);
92}
93
94void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
95 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +000096 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +000097}
98
99void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
100 VisitNamedDecl(TD);
101 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
102}
103
104void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
105 // Note that we cannot use VisitTypeDecl here, because we need to
106 // set the underlying type of the typedef *before* we try to read
107 // the type associated with the TypedefDecl.
108 VisitNamedDecl(TD);
John McCallba6a9bd2009-10-24 08:00:42 +0000109 uint64_t TypeData = Record[Idx++];
John McCalla93c9342009-12-07 02:54:59 +0000110 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCallba6a9bd2009-10-24 08:00:42 +0000111 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000112}
113
114void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
115 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000116 TD->setPreviousDeclaration(
117 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000118 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
119 TD->setDefinition(Record[Idx++]);
120 TD->setTypedefForAnonDecl(
121 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000122 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000123 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000124}
125
126void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
127 VisitTagDecl(ED);
128 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000129 ED->setPromotionType(Reader.GetType(Record[Idx++]));
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000130 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-04-27 05:27:42 +0000131}
132
133void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
134 VisitTagDecl(RD);
135 RD->setHasFlexibleArrayMember(Record[Idx++]);
136 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000137 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000138}
139
140void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
141 VisitNamedDecl(VD);
142 VD->setType(Reader.GetType(Record[Idx++]));
143}
144
145void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
146 VisitValueDecl(ECD);
147 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000148 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000149 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
150}
151
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000152void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
153 VisitValueDecl(DD);
John McCalla93c9342009-12-07 02:54:59 +0000154 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
155 if (TInfo)
156 DD->setTypeSourceInfo(TInfo);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000157}
158
Chris Lattner698f9252009-04-27 05:27:42 +0000159void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000160 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000161 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000162 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000163 FD->setPreviousDeclaration(
164 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
165 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000166 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000167 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000168 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000169 FD->setHasInheritedPrototype(Record[Idx++]);
170 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000171 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000172 FD->setTrivial(Record[Idx++]);
173 FD->setCopyAssignment(Record[Idx++]);
174 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000175 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000176 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000177 unsigned NumParams = Record[Idx++];
178 llvm::SmallVector<ParmVarDecl *, 16> Params;
179 Params.reserve(NumParams);
180 for (unsigned I = 0; I != NumParams; ++I)
181 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000182 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000183}
184
185void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
186 VisitNamedDecl(MD);
187 if (Record[Idx++]) {
188 // In practice, this won't be executed (since method definitions
189 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000190 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000191 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
192 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
193 }
194 MD->setInstanceMethod(Record[Idx++]);
195 MD->setVariadic(Record[Idx++]);
196 MD->setSynthesized(Record[Idx++]);
197 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
198 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
199 MD->setResultType(Reader.GetType(Record[Idx++]));
200 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
201 unsigned NumParams = Record[Idx++];
202 llvm::SmallVector<ParmVarDecl *, 16> Params;
203 Params.reserve(NumParams);
204 for (unsigned I = 0; I != NumParams; ++I)
205 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000206 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000207}
208
209void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
210 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000211 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
212 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
213 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000214}
215
216void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
217 VisitObjCContainerDecl(ID);
218 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
219 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
220 (Reader.GetDecl(Record[Idx++])));
221 unsigned NumProtocols = Record[Idx++];
222 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
223 Protocols.reserve(NumProtocols);
224 for (unsigned I = 0; I != NumProtocols; ++I)
225 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000226 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
227 ProtoLocs.reserve(NumProtocols);
228 for (unsigned I = 0; I != NumProtocols; ++I)
229 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
230 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
231 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000232 unsigned NumIvars = Record[Idx++];
233 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
234 IVars.reserve(NumIvars);
235 for (unsigned I = 0; I != NumIvars; ++I)
236 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000237 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000238 ID->setCategoryList(
239 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
240 ID->setForwardDecl(Record[Idx++]);
241 ID->setImplicitInterfaceDecl(Record[Idx++]);
242 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
243 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000244 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000245}
246
247void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
248 VisitFieldDecl(IVD);
249 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
250}
251
252void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
253 VisitObjCContainerDecl(PD);
254 PD->setForwardDecl(Record[Idx++]);
255 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
256 unsigned NumProtoRefs = Record[Idx++];
257 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
258 ProtoRefs.reserve(NumProtoRefs);
259 for (unsigned I = 0; I != NumProtoRefs; ++I)
260 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000261 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
262 ProtoLocs.reserve(NumProtoRefs);
263 for (unsigned I = 0; I != NumProtoRefs; ++I)
264 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
265 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
266 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000267}
268
269void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
270 VisitFieldDecl(FD);
271}
272
273void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
274 VisitDecl(CD);
275 unsigned NumClassRefs = Record[Idx++];
276 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
277 ClassRefs.reserve(NumClassRefs);
278 for (unsigned I = 0; I != NumClassRefs; ++I)
279 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000280 llvm::SmallVector<SourceLocation, 16> SLocs;
281 SLocs.reserve(NumClassRefs);
282 for (unsigned I = 0; I != NumClassRefs; ++I)
283 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
284 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
285 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000286}
287
288void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
289 VisitDecl(FPD);
290 unsigned NumProtoRefs = Record[Idx++];
291 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
292 ProtoRefs.reserve(NumProtoRefs);
293 for (unsigned I = 0; I != NumProtoRefs; ++I)
294 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000295 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
296 ProtoLocs.reserve(NumProtoRefs);
297 for (unsigned I = 0; I != NumProtoRefs; ++I)
298 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
299 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
300 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000301}
302
303void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
304 VisitObjCContainerDecl(CD);
305 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
306 unsigned NumProtoRefs = Record[Idx++];
307 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
308 ProtoRefs.reserve(NumProtoRefs);
309 for (unsigned I = 0; I != NumProtoRefs; ++I)
310 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000311 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
312 ProtoLocs.reserve(NumProtoRefs);
313 for (unsigned I = 0; I != NumProtoRefs; ++I)
314 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
315 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
316 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000317 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor3db211b2010-01-16 16:38:58 +0000318 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
319 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000320}
321
322void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
323 VisitNamedDecl(CAD);
324 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
325}
326
327void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
328 VisitNamedDecl(D);
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000329 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000330 D->setType(Reader.GetType(Record[Idx++]));
331 // FIXME: stable encoding
332 D->setPropertyAttributes(
333 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
334 // FIXME: stable encoding
335 D->setPropertyImplementation(
336 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
337 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
338 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
339 D->setGetterMethodDecl(
340 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
341 D->setSetterMethodDecl(
342 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
343 D->setPropertyIvarDecl(
344 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
345}
346
347void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000348 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000349 D->setClassInterface(
350 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000351}
352
353void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
354 VisitObjCImplDecl(D);
355 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
356}
357
358void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
359 VisitObjCImplDecl(D);
360 D->setSuperClass(
361 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
362}
363
364
365void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
366 VisitDecl(D);
367 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
368 D->setPropertyDecl(
369 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
370 D->setPropertyIvarDecl(
371 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
372}
373
374void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000375 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000376 FD->setMutable(Record[Idx++]);
377 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000378 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000379}
380
381void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000382 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000383 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
384 VD->setThreadSpecified(Record[Idx++]);
385 VD->setCXXDirectInitializer(Record[Idx++]);
386 VD->setDeclaredInCondition(Record[Idx++]);
387 VD->setPreviousDeclaration(
388 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000389 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000390 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000391}
392
393void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
394 VisitVarDecl(PD);
395}
396
397void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
398 VisitVarDecl(PD);
399 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000400}
401
Chris Lattner698f9252009-04-27 05:27:42 +0000402void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
403 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000404 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000405}
406
407void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
408 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000409 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000410 unsigned NumParams = Record[Idx++];
411 llvm::SmallVector<ParmVarDecl *, 16> Params;
412 Params.reserve(NumParams);
413 for (unsigned I = 0; I != NumParams; ++I)
414 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Mike Stump1eb44332009-09-09 15:08:12 +0000415 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000416}
417
Mike Stump1eb44332009-09-09 15:08:12 +0000418std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000419PCHDeclReader::VisitDeclContext(DeclContext *DC) {
420 uint64_t LexicalOffset = Record[Idx++];
421 uint64_t VisibleOffset = Record[Idx++];
422 return std::make_pair(LexicalOffset, VisibleOffset);
423}
424
425//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000426// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000427//===----------------------------------------------------------------------===//
428
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000429/// \brief Reads attributes from the current stream position.
430Attr *PCHReader::ReadAttributes() {
431 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000432 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000433 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000434
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000435 RecordData Record;
436 unsigned Idx = 0;
437 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000438 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000439 (void)RecCode;
440
441#define SIMPLE_ATTR(Name) \
442 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000443 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000444 break
445
446#define STRING_ATTR(Name) \
447 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000448 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000449 break
450
451#define UNSIGNED_ATTR(Name) \
452 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000453 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000454 break
455
456 Attr *Attrs = 0;
457 while (Idx < Record.size()) {
458 Attr *New = 0;
459 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
460 bool IsInherited = Record[Idx++];
461
462 switch (Kind) {
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000463 default:
464 assert(0 && "Unknown attribute!");
465 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000466 STRING_ATTR(Alias);
467 UNSIGNED_ATTR(Aligned);
468 SIMPLE_ATTR(AlwaysInline);
469 SIMPLE_ATTR(AnalyzerNoReturn);
470 STRING_ATTR(Annotate);
471 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +0000472 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +0000473
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000474 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000475 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000476 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
477 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000478
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000479 SIMPLE_ATTR(CDecl);
480
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000481 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000482 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000483 cast<FunctionDecl>(GetDecl(Record[Idx++])));
484 break;
485
486 SIMPLE_ATTR(Const);
487 UNSIGNED_ATTR(Constructor);
488 SIMPLE_ATTR(DLLExport);
489 SIMPLE_ATTR(DLLImport);
490 SIMPLE_ATTR(Deprecated);
491 UNSIGNED_ATTR(Destructor);
492 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +0000493 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +0000494
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000495 case Attr::Format: {
496 std::string Type = ReadString(Record, Idx);
497 unsigned FormatIdx = Record[Idx++];
498 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000499 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000500 break;
501 }
Mike Stump1eb44332009-09-09 15:08:12 +0000502
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000503 case Attr::FormatArg: {
504 unsigned FormatIdx = Record[Idx++];
505 New = ::new (*Context) FormatArgAttr(FormatIdx);
506 break;
507 }
Mike Stump1eb44332009-09-09 15:08:12 +0000508
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000509 case Attr::Sentinel: {
510 int sentinel = Record[Idx++];
511 int nullPos = Record[Idx++];
512 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
513 break;
514 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000515
516 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +0000517 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +0000518
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000519 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000520 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000521 break;
522
Ryan Flynn76168e22009-08-09 20:07:29 +0000523 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000524 SIMPLE_ATTR(NoDebug);
525 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000526 SIMPLE_ATTR(NoReturn);
527 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000528
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000529 case Attr::NonNull: {
530 unsigned Size = Record[Idx++];
531 llvm::SmallVector<unsigned, 16> ArgNums;
532 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
533 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000534 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000535 break;
536 }
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Nate Begeman6f3d8382009-06-26 06:32:41 +0000538 case Attr::ReqdWorkGroupSize: {
539 unsigned X = Record[Idx++];
540 unsigned Y = Record[Idx++];
541 unsigned Z = Record[Idx++];
542 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
543 break;
544 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000545
546 SIMPLE_ATTR(ObjCException);
547 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000548 SIMPLE_ATTR(CFReturnsRetained);
549 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000550 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +0000551 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +0000552 SIMPLE_ATTR(Packed);
553 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000554 SIMPLE_ATTR(Pure);
555 UNSIGNED_ATTR(Regparm);
556 STRING_ATTR(Section);
557 SIMPLE_ATTR(StdCall);
558 SIMPLE_ATTR(TransparentUnion);
559 SIMPLE_ATTR(Unavailable);
560 SIMPLE_ATTR(Unused);
561 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000562
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000563 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000564 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000565 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
566 break;
567
568 SIMPLE_ATTR(WarnUnusedResult);
569 SIMPLE_ATTR(Weak);
570 SIMPLE_ATTR(WeakImport);
571 }
572
573 assert(New && "Unable to decode attribute?");
574 New->setInherited(IsInherited);
575 New->setNext(Attrs);
576 Attrs = New;
577 }
578#undef UNSIGNED_ATTR
579#undef STRING_ATTR
580#undef SIMPLE_ATTR
581
582 // The list of attributes was built backwards. Reverse the list
583 // before returning it.
584 Attr *PrevAttr = 0, *NextAttr = 0;
585 while (Attrs) {
586 NextAttr = Attrs->getNext();
587 Attrs->setNext(PrevAttr);
588 PrevAttr = Attrs;
589 Attrs = NextAttr;
590 }
591
592 return PrevAttr;
593}
594
595//===----------------------------------------------------------------------===//
596// PCHReader Implementation
597//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000598
599/// \brief Note that we have loaded the declaration with the given
600/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000601///
Chris Lattner698f9252009-04-27 05:27:42 +0000602/// This routine notes that this declaration has already been loaded,
603/// so that future GetDecl calls will return this declaration rather
604/// than trying to load a new declaration.
605inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
606 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
607 DeclsLoaded[Index] = D;
608}
609
610
611/// \brief Determine whether the consumer will be interested in seeing
612/// this declaration (via HandleTopLevelDecl).
613///
614/// This routine should return true for anything that might affect
615/// code generation, e.g., inline function definitions, Objective-C
616/// declarations with metadata, etc.
617static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000618 if (isa<FileScopeAsmDecl>(D))
619 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000620 if (VarDecl *Var = dyn_cast<VarDecl>(D))
621 return Var->isFileVarDecl() && Var->getInit();
622 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
623 return Func->isThisDeclarationADefinition();
624 return isa<ObjCProtocolDecl>(D);
625}
626
627/// \brief Read the declaration at the given offset from the PCH file.
628Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
629 // Keep track of where we are in the stream, then jump back there
630 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000631 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000632
Douglas Gregord89275b2009-07-06 18:54:52 +0000633 // Note that we are loading a declaration record.
634 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Chris Lattnerda930612009-04-27 05:58:23 +0000636 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000637 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000638 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000639 unsigned Idx = 0;
640 PCHDeclReader Reader(*this, Record, Idx);
641
Chris Lattnerda930612009-04-27 05:58:23 +0000642 Decl *D = 0;
643 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000644 case pch::DECL_ATTR:
645 case pch::DECL_CONTEXT_LEXICAL:
646 case pch::DECL_CONTEXT_VISIBLE:
647 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
648 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000649 case pch::DECL_TRANSLATION_UNIT:
650 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000651 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000652 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000653 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +0000654 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000655 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000656 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000657 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000658 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000659 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000660 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000661 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000662 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000663 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000664 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000665 0, llvm::APSInt());
666 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000667 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000668 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000669 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000670 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000671 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000672 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000673 Selector(), QualType(), 0);
674 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000675 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000676 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000677 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000678 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000679 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000680 ObjCIvarDecl::None);
681 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000682 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000683 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000684 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000685 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000686 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000687 QualType(), 0);
688 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000689 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000690 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000691 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000692 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000693 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000694 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000695 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +0000696 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
697 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000698 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000699 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000700 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000701 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000702 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000703 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000704 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000705 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000706 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000707 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000708 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000709 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
710 QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000711 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000712 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000713 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000714 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000715 ObjCPropertyImplDecl::Dynamic, 0);
716 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000717 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000718 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000719 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000720 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000721 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000722 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000723 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000724 break;
725
726 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000727 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000728 break;
729
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000730 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000731 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000732 VarDecl::None, 0);
733 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000734 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000735 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000736 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000737 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000738 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000739 break;
740 }
Chris Lattner698f9252009-04-27 05:27:42 +0000741
742 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000743 LoadedDecl(Index, D);
744 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000745
746 // If this declaration is also a declaration context, get the
747 // offsets for its tables of lexical and visible declarations.
748 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
749 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
750 if (Offsets.first || Offsets.second) {
751 DC->setHasExternalLexicalStorage(Offsets.first != 0);
752 DC->setHasExternalVisibleStorage(Offsets.second != 0);
753 DeclContextOffsets[DC] = Offsets;
754 }
755 }
756 assert(Idx == Record.size());
757
758 // If we have deserialized a declaration that has a definition the
759 // AST consumer might need to know about, notify the consumer
760 // about that definition now or queue it for later.
761 if (isConsumerInterestedIn(D)) {
762 if (Consumer) {
763 DeclGroupRef DG(D);
764 Consumer->HandleTopLevelDecl(DG);
765 } else {
766 InterestingDecls.push_back(D);
767 }
768 }
769
770 return D;
771}