blob: cadc5427658abc8252787a17658f70fb4d3da1f5 [file] [log] [blame]
Chris Lattner487412d2009-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 Lattner487412d2009-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 Kyrtzidis560ac972009-08-19 01:28:35 +000049 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-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 Lattner487412d2009-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 Kyrtzidisb4b64ca2009-06-30 02:34:44 +000083 D->addAttr(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +000084 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +000085 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +000086 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +000087 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-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 Stump11289f42009-09-09 15:08:12 +000096 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-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 McCall703a3f82009-10-24 08:00:42 +0000109 uint64_t TypeData = Record[Idx++];
John McCallbcd03502009-12-07 02:54:59 +0000110 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCall703a3f82009-10-24 08:00:42 +0000111 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000112}
113
114void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
115 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000116 TD->setPreviousDeclaration(
117 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000118 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
119 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000120 TD->setEmbeddedInDeclarator(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000121 TD->setTypedefForAnonDecl(
122 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000123 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000124 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000125}
126
127void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
128 VisitTagDecl(ED);
129 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000130 ED->setPromotionType(Reader.GetType(Record[Idx++]));
Douglas Gregor7a749382009-05-27 17:20:35 +0000131 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000132}
133
134void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
135 VisitTagDecl(RD);
136 RD->setHasFlexibleArrayMember(Record[Idx++]);
137 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000138 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000139}
140
141void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
142 VisitNamedDecl(VD);
143 VD->setType(Reader.GetType(Record[Idx++]));
144}
145
146void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
147 VisitValueDecl(ECD);
148 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000149 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000150 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
151}
152
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000153void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
154 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000155 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
156 if (TInfo)
157 DD->setTypeSourceInfo(TInfo);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000158}
159
Chris Lattner487412d2009-04-27 05:27:42 +0000160void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000161 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000162 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000163 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000164 FD->setPreviousDeclaration(
165 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
166 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000167 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000168 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000169 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000170 FD->setHasInheritedPrototype(Record[Idx++]);
171 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000172 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000173 FD->setTrivial(Record[Idx++]);
174 FD->setCopyAssignment(Record[Idx++]);
175 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000176 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor24c332b2009-05-14 21:06:31 +0000177 // FIXME: C++ TemplateOrInstantiation
Chris Lattner487412d2009-04-27 05:27:42 +0000178 unsigned NumParams = Record[Idx++];
179 llvm::SmallVector<ParmVarDecl *, 16> Params;
180 Params.reserve(NumParams);
181 for (unsigned I = 0; I != NumParams; ++I)
182 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000183 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000184}
185
186void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
187 VisitNamedDecl(MD);
188 if (Record[Idx++]) {
189 // In practice, this won't be executed (since method definitions
190 // don't occur in header files).
Chris Lattner1de76db2009-04-27 05:58:23 +0000191 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000192 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
193 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
194 }
195 MD->setInstanceMethod(Record[Idx++]);
196 MD->setVariadic(Record[Idx++]);
197 MD->setSynthesized(Record[Idx++]);
198 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
199 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
200 MD->setResultType(Reader.GetType(Record[Idx++]));
201 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
202 unsigned NumParams = Record[Idx++];
203 llvm::SmallVector<ParmVarDecl *, 16> Params;
204 Params.reserve(NumParams);
205 for (unsigned I = 0; I != NumParams; ++I)
206 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foad7d0479f2009-05-21 09:52:38 +0000207 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000208}
209
210void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
211 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000212 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
213 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
214 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000215}
216
217void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
218 VisitObjCContainerDecl(ID);
219 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
220 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
221 (Reader.GetDecl(Record[Idx++])));
222 unsigned NumProtocols = Record[Idx++];
223 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
224 Protocols.reserve(NumProtocols);
225 for (unsigned I = 0; I != NumProtocols; ++I)
226 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000227 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
228 ProtoLocs.reserve(NumProtocols);
229 for (unsigned I = 0; I != NumProtocols; ++I)
230 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
231 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
232 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000233 unsigned NumIvars = Record[Idx++];
234 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
235 IVars.reserve(NumIvars);
236 for (unsigned I = 0; I != NumIvars; ++I)
237 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foad7d0479f2009-05-21 09:52:38 +0000238 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000239 ID->setCategoryList(
240 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
241 ID->setForwardDecl(Record[Idx++]);
242 ID->setImplicitInterfaceDecl(Record[Idx++]);
243 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
244 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000245 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000246}
247
248void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
249 VisitFieldDecl(IVD);
250 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
251}
252
253void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
254 VisitObjCContainerDecl(PD);
255 PD->setForwardDecl(Record[Idx++]);
256 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
257 unsigned NumProtoRefs = Record[Idx++];
258 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
259 ProtoRefs.reserve(NumProtoRefs);
260 for (unsigned I = 0; I != NumProtoRefs; ++I)
261 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000262 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
263 ProtoLocs.reserve(NumProtoRefs);
264 for (unsigned I = 0; I != NumProtoRefs; ++I)
265 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
266 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
267 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000268}
269
270void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
271 VisitFieldDecl(FD);
272}
273
274void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
275 VisitDecl(CD);
276 unsigned NumClassRefs = Record[Idx++];
277 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
278 ClassRefs.reserve(NumClassRefs);
279 for (unsigned I = 0; I != NumClassRefs; ++I)
280 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000281 llvm::SmallVector<SourceLocation, 16> SLocs;
282 SLocs.reserve(NumClassRefs);
283 for (unsigned I = 0; I != NumClassRefs; ++I)
284 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
285 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
286 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000287}
288
289void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
290 VisitDecl(FPD);
291 unsigned NumProtoRefs = Record[Idx++];
292 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
293 ProtoRefs.reserve(NumProtoRefs);
294 for (unsigned I = 0; I != NumProtoRefs; ++I)
295 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000296 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
297 ProtoLocs.reserve(NumProtoRefs);
298 for (unsigned I = 0; I != NumProtoRefs; ++I)
299 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
300 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
301 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000302}
303
304void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
305 VisitObjCContainerDecl(CD);
306 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
307 unsigned NumProtoRefs = Record[Idx++];
308 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
309 ProtoRefs.reserve(NumProtoRefs);
310 for (unsigned I = 0; I != NumProtoRefs; ++I)
311 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000312 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
313 ProtoLocs.reserve(NumProtoRefs);
314 for (unsigned I = 0; I != NumProtoRefs; ++I)
315 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
316 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
317 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000318 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000319 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
320 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000321}
322
323void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
324 VisitNamedDecl(CAD);
325 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
326}
327
328void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
329 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000330 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000331 D->setType(Reader.GetType(Record[Idx++]));
332 // FIXME: stable encoding
333 D->setPropertyAttributes(
334 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
335 // FIXME: stable encoding
336 D->setPropertyImplementation(
337 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
338 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
339 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
340 D->setGetterMethodDecl(
341 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
342 D->setSetterMethodDecl(
343 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
344 D->setPropertyIvarDecl(
345 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
346}
347
348void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000349 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000350 D->setClassInterface(
351 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000352}
353
354void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
355 VisitObjCImplDecl(D);
356 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
357}
358
359void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
360 VisitObjCImplDecl(D);
361 D->setSuperClass(
362 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
363}
364
365
366void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
367 VisitDecl(D);
368 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
369 D->setPropertyDecl(
370 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
371 D->setPropertyIvarDecl(
372 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
373}
374
375void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000376 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000377 FD->setMutable(Record[Idx++]);
378 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000379 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000380}
381
382void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000383 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000384 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
385 VD->setThreadSpecified(Record[Idx++]);
386 VD->setCXXDirectInitializer(Record[Idx++]);
387 VD->setDeclaredInCondition(Record[Idx++]);
388 VD->setPreviousDeclaration(
389 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000390 if (Record[Idx++])
Douglas Gregord5058122010-02-11 01:19:42 +0000391 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000392}
393
394void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
395 VisitVarDecl(PD);
396}
397
398void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
399 VisitVarDecl(PD);
400 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000401}
402
Chris Lattner487412d2009-04-27 05:27:42 +0000403void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
404 VisitDecl(AD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000405 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000406}
407
408void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
409 VisitDecl(BD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000410 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner487412d2009-04-27 05:27:42 +0000411 unsigned NumParams = Record[Idx++];
412 llvm::SmallVector<ParmVarDecl *, 16> Params;
413 Params.reserve(NumParams);
414 for (unsigned I = 0; I != NumParams; ++I)
415 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000416 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000417}
418
Mike Stump11289f42009-09-09 15:08:12 +0000419std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000420PCHDeclReader::VisitDeclContext(DeclContext *DC) {
421 uint64_t LexicalOffset = Record[Idx++];
422 uint64_t VisibleOffset = Record[Idx++];
423 return std::make_pair(LexicalOffset, VisibleOffset);
424}
425
426//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000427// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000428//===----------------------------------------------------------------------===//
429
Chris Lattner8f63ab52009-04-27 06:01:06 +0000430/// \brief Reads attributes from the current stream position.
431Attr *PCHReader::ReadAttributes() {
432 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000433 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000434 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000435
Chris Lattner8f63ab52009-04-27 06:01:06 +0000436 RecordData Record;
437 unsigned Idx = 0;
438 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000439 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000440 (void)RecCode;
441
442#define SIMPLE_ATTR(Name) \
443 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000444 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000445 break
446
447#define STRING_ATTR(Name) \
448 case Attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000449 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000450 break
451
452#define UNSIGNED_ATTR(Name) \
453 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000454 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000455 break
456
457 Attr *Attrs = 0;
458 while (Idx < Record.size()) {
459 Attr *New = 0;
460 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
461 bool IsInherited = Record[Idx++];
462
463 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000464 default:
465 assert(0 && "Unknown attribute!");
466 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000467 STRING_ATTR(Alias);
468 UNSIGNED_ATTR(Aligned);
469 SIMPLE_ATTR(AlwaysInline);
470 SIMPLE_ATTR(AnalyzerNoReturn);
471 STRING_ATTR(Annotate);
472 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000473 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000474
Chris Lattner8f63ab52009-04-27 06:01:06 +0000475 case Attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000476 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000477 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
478 break;
Mike Stump11289f42009-09-09 15:08:12 +0000479
Eli Friedmane4310c82009-11-09 18:38:53 +0000480 SIMPLE_ATTR(CDecl);
481
Chris Lattner8f63ab52009-04-27 06:01:06 +0000482 case Attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000483 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000484 cast<FunctionDecl>(GetDecl(Record[Idx++])));
485 break;
486
487 SIMPLE_ATTR(Const);
488 UNSIGNED_ATTR(Constructor);
489 SIMPLE_ATTR(DLLExport);
490 SIMPLE_ATTR(DLLImport);
491 SIMPLE_ATTR(Deprecated);
492 UNSIGNED_ATTR(Destructor);
493 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000494 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000495
Chris Lattner8f63ab52009-04-27 06:01:06 +0000496 case Attr::Format: {
497 std::string Type = ReadString(Record, Idx);
498 unsigned FormatIdx = Record[Idx++];
499 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000500 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000501 break;
502 }
Mike Stump11289f42009-09-09 15:08:12 +0000503
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000504 case Attr::FormatArg: {
505 unsigned FormatIdx = Record[Idx++];
506 New = ::new (*Context) FormatArgAttr(FormatIdx);
507 break;
508 }
Mike Stump11289f42009-09-09 15:08:12 +0000509
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000510 case Attr::Sentinel: {
511 int sentinel = Record[Idx++];
512 int nullPos = Record[Idx++];
513 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
514 break;
515 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000516
517 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000518 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Ted Kremenek06be9682010-02-17 02:37:45 +0000520 case Attr::IBActionKind:
521 New = ::new (*Context) IBActionAttr();
522 break;
523
Chris Lattner8f63ab52009-04-27 06:01:06 +0000524 case Attr::IBOutletKind:
Chris Lattner8575daa2009-04-27 21:45:14 +0000525 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000526 break;
527
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000528 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000529 SIMPLE_ATTR(NoDebug);
530 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000531 SIMPLE_ATTR(NoReturn);
532 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000533
Chris Lattner8f63ab52009-04-27 06:01:06 +0000534 case Attr::NonNull: {
535 unsigned Size = Record[Idx++];
536 llvm::SmallVector<unsigned, 16> ArgNums;
537 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
538 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000539 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000540 break;
541 }
Mike Stump11289f42009-09-09 15:08:12 +0000542
Nate Begemanf2758702009-06-26 06:32:41 +0000543 case Attr::ReqdWorkGroupSize: {
544 unsigned X = Record[Idx++];
545 unsigned Y = Record[Idx++];
546 unsigned Z = Record[Idx++];
547 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
548 break;
549 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000550
551 SIMPLE_ATTR(ObjCException);
552 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000553 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000554 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000555 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000556 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000557 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000558 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000559 SIMPLE_ATTR(Packed);
560 UNSIGNED_ATTR(PragmaPack);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000561 SIMPLE_ATTR(Pure);
562 UNSIGNED_ATTR(Regparm);
563 STRING_ATTR(Section);
564 SIMPLE_ATTR(StdCall);
565 SIMPLE_ATTR(TransparentUnion);
566 SIMPLE_ATTR(Unavailable);
567 SIMPLE_ATTR(Unused);
568 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000569
Chris Lattner8f63ab52009-04-27 06:01:06 +0000570 case Attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000571 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000572 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
573 break;
574
575 SIMPLE_ATTR(WarnUnusedResult);
576 SIMPLE_ATTR(Weak);
577 SIMPLE_ATTR(WeakImport);
578 }
579
580 assert(New && "Unable to decode attribute?");
581 New->setInherited(IsInherited);
582 New->setNext(Attrs);
583 Attrs = New;
584 }
585#undef UNSIGNED_ATTR
586#undef STRING_ATTR
587#undef SIMPLE_ATTR
588
589 // The list of attributes was built backwards. Reverse the list
590 // before returning it.
591 Attr *PrevAttr = 0, *NextAttr = 0;
592 while (Attrs) {
593 NextAttr = Attrs->getNext();
594 Attrs->setNext(PrevAttr);
595 PrevAttr = Attrs;
596 Attrs = NextAttr;
597 }
598
599 return PrevAttr;
600}
601
602//===----------------------------------------------------------------------===//
603// PCHReader Implementation
604//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000605
606/// \brief Note that we have loaded the declaration with the given
607/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000608///
Chris Lattner487412d2009-04-27 05:27:42 +0000609/// This routine notes that this declaration has already been loaded,
610/// so that future GetDecl calls will return this declaration rather
611/// than trying to load a new declaration.
612inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
613 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
614 DeclsLoaded[Index] = D;
615}
616
617
618/// \brief Determine whether the consumer will be interested in seeing
619/// this declaration (via HandleTopLevelDecl).
620///
621/// This routine should return true for anything that might affect
622/// code generation, e.g., inline function definitions, Objective-C
623/// declarations with metadata, etc.
624static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000625 if (isa<FileScopeAsmDecl>(D))
626 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000627 if (VarDecl *Var = dyn_cast<VarDecl>(D))
628 return Var->isFileVarDecl() && Var->getInit();
629 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
630 return Func->isThisDeclarationADefinition();
631 return isa<ObjCProtocolDecl>(D);
632}
633
634/// \brief Read the declaration at the given offset from the PCH file.
635Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
636 // Keep track of where we are in the stream, then jump back there
637 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000638 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000639
Douglas Gregor1342e842009-07-06 18:54:52 +0000640 // Note that we are loading a declaration record.
641 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000642
Chris Lattner1de76db2009-04-27 05:58:23 +0000643 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000644 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000645 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000646 unsigned Idx = 0;
647 PCHDeclReader Reader(*this, Record, Idx);
648
Chris Lattner1de76db2009-04-27 05:58:23 +0000649 Decl *D = 0;
650 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000651 case pch::DECL_ATTR:
652 case pch::DECL_CONTEXT_LEXICAL:
653 case pch::DECL_CONTEXT_VISIBLE:
654 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
655 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000656 case pch::DECL_TRANSLATION_UNIT:
657 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +0000658 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +0000659 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000660 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +0000661 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000662 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000663 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000664 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000665 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000666 case pch::DECL_RECORD:
Chris Lattner8575daa2009-04-27 21:45:14 +0000667 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000668 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000669 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000670 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +0000671 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +0000672 0, llvm::APSInt());
673 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000674 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +0000675 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000676 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000677 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000678 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +0000679 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner487412d2009-04-27 05:27:42 +0000680 Selector(), QualType(), 0);
681 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000682 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +0000683 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000684 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000685 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000686 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000687 ObjCIvarDecl::None);
688 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000689 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000690 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000691 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000692 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000693 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000694 QualType(), 0);
695 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000696 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000697 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000698 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000699 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000700 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000701 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000702 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +0000703 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
704 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000705 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000706 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000707 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000708 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000709 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +0000710 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000711 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000712 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000713 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000714 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000715 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000716 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
717 QualType());
Chris Lattner487412d2009-04-27 05:27:42 +0000718 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000719 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000720 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +0000721 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000722 ObjCPropertyImplDecl::Dynamic, 0);
723 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000724 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000725 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000726 false);
Chris Lattner487412d2009-04-27 05:27:42 +0000727 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000728 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000729 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000730 VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +0000731 break;
732
733 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +0000734 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +0000735 break;
736
Chris Lattner8f63ab52009-04-27 06:01:06 +0000737 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +0000738 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000739 VarDecl::None, 0);
740 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000741 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +0000742 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000743 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000744 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +0000745 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000746 break;
747 }
Chris Lattner487412d2009-04-27 05:27:42 +0000748
749 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000750 LoadedDecl(Index, D);
751 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000752
753 // If this declaration is also a declaration context, get the
754 // offsets for its tables of lexical and visible declarations.
755 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
756 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
757 if (Offsets.first || Offsets.second) {
758 DC->setHasExternalLexicalStorage(Offsets.first != 0);
759 DC->setHasExternalVisibleStorage(Offsets.second != 0);
760 DeclContextOffsets[DC] = Offsets;
761 }
762 }
763 assert(Idx == Record.size());
764
765 // If we have deserialized a declaration that has a definition the
766 // AST consumer might need to know about, notify the consumer
767 // about that definition now or queue it for later.
768 if (isConsumerInterestedIn(D)) {
769 if (Consumer) {
770 DeclGroupRef DG(D);
771 Consumer->HandleTopLevelDecl(DG);
772 } else {
773 InterestingDecls.push_back(D);
774 }
775 }
776
777 return D;
778}