blob: 27349ecbfe50ba13a5d026b40caf1bb14b805272 [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);
Douglas Gregore31bbd92010-02-21 18:22:14 +000042 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000043 void VisitTypeDecl(TypeDecl *TD);
44 void VisitTypedefDecl(TypedefDecl *TD);
45 void VisitTagDecl(TagDecl *TD);
46 void VisitEnumDecl(EnumDecl *ED);
47 void VisitRecordDecl(RecordDecl *RD);
48 void VisitValueDecl(ValueDecl *VD);
49 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000050 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000051 void VisitFunctionDecl(FunctionDecl *FD);
52 void VisitFieldDecl(FieldDecl *FD);
53 void VisitVarDecl(VarDecl *VD);
54 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
55 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner487412d2009-04-27 05:27:42 +000056 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
57 void VisitBlockDecl(BlockDecl *BD);
58 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
59 void VisitObjCMethodDecl(ObjCMethodDecl *D);
60 void VisitObjCContainerDecl(ObjCContainerDecl *D);
61 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
62 void VisitObjCIvarDecl(ObjCIvarDecl *D);
63 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
64 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
65 void VisitObjCClassDecl(ObjCClassDecl *D);
66 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
67 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
68 void VisitObjCImplDecl(ObjCImplDecl *D);
69 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
70 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
71 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
72 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
73 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
74 };
75}
76
77void PCHDeclReader::VisitDecl(Decl *D) {
78 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
79 D->setLexicalDeclContext(
80 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
81 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
82 D->setInvalidDecl(Record[Idx++]);
83 if (Record[Idx++])
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +000084 D->addAttr(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +000085 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +000086 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +000087 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +000088 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +000089}
90
91void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
92 VisitDecl(TU);
93}
94
95void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
96 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +000097 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +000098}
99
Douglas Gregore31bbd92010-02-21 18:22:14 +0000100void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
101 VisitNamedDecl(D);
102 D->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
103 D->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
104 D->setNextNamespace(
105 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
106 D->setOriginalNamespace(
107 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
108 D->setAnonymousNamespace(
109 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
110}
111
Chris Lattner487412d2009-04-27 05:27:42 +0000112void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
113 VisitNamedDecl(TD);
114 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
115}
116
117void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
118 // Note that we cannot use VisitTypeDecl here, because we need to
119 // set the underlying type of the typedef *before* we try to read
120 // the type associated with the TypedefDecl.
121 VisitNamedDecl(TD);
John McCall703a3f82009-10-24 08:00:42 +0000122 uint64_t TypeData = Record[Idx++];
John McCallbcd03502009-12-07 02:54:59 +0000123 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCall703a3f82009-10-24 08:00:42 +0000124 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000125}
126
127void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
128 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000129 TD->setPreviousDeclaration(
130 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000131 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
132 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000133 TD->setEmbeddedInDeclarator(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000134 TD->setTypedefForAnonDecl(
135 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000136 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000137 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000138}
139
140void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
141 VisitTagDecl(ED);
142 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000143 ED->setPromotionType(Reader.GetType(Record[Idx++]));
Douglas Gregor7a749382009-05-27 17:20:35 +0000144 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000145}
146
147void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
148 VisitTagDecl(RD);
149 RD->setHasFlexibleArrayMember(Record[Idx++]);
150 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000151 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000152}
153
154void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
155 VisitNamedDecl(VD);
156 VD->setType(Reader.GetType(Record[Idx++]));
157}
158
159void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
160 VisitValueDecl(ECD);
161 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000162 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000163 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
164}
165
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000166void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
167 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000168 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
169 if (TInfo)
170 DD->setTypeSourceInfo(TInfo);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000171}
172
Chris Lattner487412d2009-04-27 05:27:42 +0000173void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000174 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000175 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000176 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000177 FD->setPreviousDeclaration(
178 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
179 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000180 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000181 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000182 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000183 FD->setHasInheritedPrototype(Record[Idx++]);
184 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000185 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000186 FD->setTrivial(Record[Idx++]);
187 FD->setCopyAssignment(Record[Idx++]);
188 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000189 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor24c332b2009-05-14 21:06:31 +0000190 // FIXME: C++ TemplateOrInstantiation
Chris Lattner487412d2009-04-27 05:27:42 +0000191 unsigned NumParams = Record[Idx++];
192 llvm::SmallVector<ParmVarDecl *, 16> Params;
193 Params.reserve(NumParams);
194 for (unsigned I = 0; I != NumParams; ++I)
195 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000196 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000197}
198
199void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
200 VisitNamedDecl(MD);
201 if (Record[Idx++]) {
202 // In practice, this won't be executed (since method definitions
203 // don't occur in header files).
Chris Lattner1de76db2009-04-27 05:58:23 +0000204 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000205 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
206 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
207 }
208 MD->setInstanceMethod(Record[Idx++]);
209 MD->setVariadic(Record[Idx++]);
210 MD->setSynthesized(Record[Idx++]);
211 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
212 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
213 MD->setResultType(Reader.GetType(Record[Idx++]));
214 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
215 unsigned NumParams = Record[Idx++];
216 llvm::SmallVector<ParmVarDecl *, 16> Params;
217 Params.reserve(NumParams);
218 for (unsigned I = 0; I != NumParams; ++I)
219 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foad7d0479f2009-05-21 09:52:38 +0000220 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000221}
222
223void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
224 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000225 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
226 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
227 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000228}
229
230void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
231 VisitObjCContainerDecl(ID);
232 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
233 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
234 (Reader.GetDecl(Record[Idx++])));
235 unsigned NumProtocols = Record[Idx++];
236 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
237 Protocols.reserve(NumProtocols);
238 for (unsigned I = 0; I != NumProtocols; ++I)
239 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000240 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
241 ProtoLocs.reserve(NumProtocols);
242 for (unsigned I = 0; I != NumProtocols; ++I)
243 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
244 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
245 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000246 unsigned NumIvars = Record[Idx++];
247 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
248 IVars.reserve(NumIvars);
249 for (unsigned I = 0; I != NumIvars; ++I)
250 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000251 ID->setCategoryList(
252 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
253 ID->setForwardDecl(Record[Idx++]);
254 ID->setImplicitInterfaceDecl(Record[Idx++]);
255 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
256 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000257 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000258}
259
260void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
261 VisitFieldDecl(IVD);
262 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
263}
264
265void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
266 VisitObjCContainerDecl(PD);
267 PD->setForwardDecl(Record[Idx++]);
268 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
269 unsigned NumProtoRefs = Record[Idx++];
270 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
271 ProtoRefs.reserve(NumProtoRefs);
272 for (unsigned I = 0; I != NumProtoRefs; ++I)
273 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000274 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
275 ProtoLocs.reserve(NumProtoRefs);
276 for (unsigned I = 0; I != NumProtoRefs; ++I)
277 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
278 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
279 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000280}
281
282void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
283 VisitFieldDecl(FD);
284}
285
286void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
287 VisitDecl(CD);
288 unsigned NumClassRefs = Record[Idx++];
289 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
290 ClassRefs.reserve(NumClassRefs);
291 for (unsigned I = 0; I != NumClassRefs; ++I)
292 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000293 llvm::SmallVector<SourceLocation, 16> SLocs;
294 SLocs.reserve(NumClassRefs);
295 for (unsigned I = 0; I != NumClassRefs; ++I)
296 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
297 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
298 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000299}
300
301void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
302 VisitDecl(FPD);
303 unsigned NumProtoRefs = Record[Idx++];
304 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
305 ProtoRefs.reserve(NumProtoRefs);
306 for (unsigned I = 0; I != NumProtoRefs; ++I)
307 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000308 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
309 ProtoLocs.reserve(NumProtoRefs);
310 for (unsigned I = 0; I != NumProtoRefs; ++I)
311 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
312 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
313 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000314}
315
316void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
317 VisitObjCContainerDecl(CD);
318 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
319 unsigned NumProtoRefs = Record[Idx++];
320 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
321 ProtoRefs.reserve(NumProtoRefs);
322 for (unsigned I = 0; I != NumProtoRefs; ++I)
323 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000324 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
325 ProtoLocs.reserve(NumProtoRefs);
326 for (unsigned I = 0; I != NumProtoRefs; ++I)
327 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
328 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
329 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000330 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000331 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
332 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000333}
334
335void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
336 VisitNamedDecl(CAD);
337 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
338}
339
340void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
341 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000342 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000343 D->setType(Reader.GetType(Record[Idx++]));
344 // FIXME: stable encoding
345 D->setPropertyAttributes(
346 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
347 // FIXME: stable encoding
348 D->setPropertyImplementation(
349 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
350 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
351 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
352 D->setGetterMethodDecl(
353 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
354 D->setSetterMethodDecl(
355 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
356 D->setPropertyIvarDecl(
357 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
358}
359
360void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000361 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000362 D->setClassInterface(
363 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000364}
365
366void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
367 VisitObjCImplDecl(D);
368 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
369}
370
371void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
372 VisitObjCImplDecl(D);
373 D->setSuperClass(
374 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
375}
376
377
378void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
379 VisitDecl(D);
380 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
381 D->setPropertyDecl(
382 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
383 D->setPropertyIvarDecl(
384 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
385}
386
387void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000388 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000389 FD->setMutable(Record[Idx++]);
390 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000391 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000392}
393
394void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000395 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000396 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
397 VD->setThreadSpecified(Record[Idx++]);
398 VD->setCXXDirectInitializer(Record[Idx++]);
399 VD->setDeclaredInCondition(Record[Idx++]);
400 VD->setPreviousDeclaration(
401 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000402 if (Record[Idx++])
Douglas Gregord5058122010-02-11 01:19:42 +0000403 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000404}
405
406void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
407 VisitVarDecl(PD);
408}
409
410void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
411 VisitVarDecl(PD);
412 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000413}
414
Chris Lattner487412d2009-04-27 05:27:42 +0000415void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
416 VisitDecl(AD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000417 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000418}
419
420void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
421 VisitDecl(BD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000422 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner487412d2009-04-27 05:27:42 +0000423 unsigned NumParams = Record[Idx++];
424 llvm::SmallVector<ParmVarDecl *, 16> Params;
425 Params.reserve(NumParams);
426 for (unsigned I = 0; I != NumParams; ++I)
427 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000428 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000429}
430
Mike Stump11289f42009-09-09 15:08:12 +0000431std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000432PCHDeclReader::VisitDeclContext(DeclContext *DC) {
433 uint64_t LexicalOffset = Record[Idx++];
434 uint64_t VisibleOffset = Record[Idx++];
435 return std::make_pair(LexicalOffset, VisibleOffset);
436}
437
438//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000439// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000440//===----------------------------------------------------------------------===//
441
Chris Lattner8f63ab52009-04-27 06:01:06 +0000442/// \brief Reads attributes from the current stream position.
443Attr *PCHReader::ReadAttributes() {
444 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000445 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000446 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000447
Chris Lattner8f63ab52009-04-27 06:01:06 +0000448 RecordData Record;
449 unsigned Idx = 0;
450 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000451 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000452 (void)RecCode;
453
454#define SIMPLE_ATTR(Name) \
455 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000456 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000457 break
458
459#define STRING_ATTR(Name) \
460 case Attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000461 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000462 break
463
464#define UNSIGNED_ATTR(Name) \
465 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000466 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000467 break
468
469 Attr *Attrs = 0;
470 while (Idx < Record.size()) {
471 Attr *New = 0;
472 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
473 bool IsInherited = Record[Idx++];
474
475 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000476 default:
477 assert(0 && "Unknown attribute!");
478 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000479 STRING_ATTR(Alias);
480 UNSIGNED_ATTR(Aligned);
481 SIMPLE_ATTR(AlwaysInline);
482 SIMPLE_ATTR(AnalyzerNoReturn);
483 STRING_ATTR(Annotate);
484 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000485 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000486
Chris Lattner8f63ab52009-04-27 06:01:06 +0000487 case Attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000488 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000489 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
490 break;
Mike Stump11289f42009-09-09 15:08:12 +0000491
Eli Friedmane4310c82009-11-09 18:38:53 +0000492 SIMPLE_ATTR(CDecl);
493
Chris Lattner8f63ab52009-04-27 06:01:06 +0000494 case Attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000495 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000496 cast<FunctionDecl>(GetDecl(Record[Idx++])));
497 break;
498
499 SIMPLE_ATTR(Const);
500 UNSIGNED_ATTR(Constructor);
501 SIMPLE_ATTR(DLLExport);
502 SIMPLE_ATTR(DLLImport);
503 SIMPLE_ATTR(Deprecated);
504 UNSIGNED_ATTR(Destructor);
505 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000506 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000507
Chris Lattner8f63ab52009-04-27 06:01:06 +0000508 case Attr::Format: {
509 std::string Type = ReadString(Record, Idx);
510 unsigned FormatIdx = Record[Idx++];
511 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000512 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000513 break;
514 }
Mike Stump11289f42009-09-09 15:08:12 +0000515
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000516 case Attr::FormatArg: {
517 unsigned FormatIdx = Record[Idx++];
518 New = ::new (*Context) FormatArgAttr(FormatIdx);
519 break;
520 }
Mike Stump11289f42009-09-09 15:08:12 +0000521
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000522 case Attr::Sentinel: {
523 int sentinel = Record[Idx++];
524 int nullPos = Record[Idx++];
525 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
526 break;
527 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000528
529 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000530 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000531
Ted Kremenek06be9682010-02-17 02:37:45 +0000532 case Attr::IBActionKind:
533 New = ::new (*Context) IBActionAttr();
534 break;
535
Chris Lattner8f63ab52009-04-27 06:01:06 +0000536 case Attr::IBOutletKind:
Chris Lattner8575daa2009-04-27 21:45:14 +0000537 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000538 break;
539
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000540 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000541 SIMPLE_ATTR(NoDebug);
542 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000543 SIMPLE_ATTR(NoReturn);
544 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000545
Chris Lattner8f63ab52009-04-27 06:01:06 +0000546 case Attr::NonNull: {
547 unsigned Size = Record[Idx++];
548 llvm::SmallVector<unsigned, 16> ArgNums;
549 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
550 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000551 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000552 break;
553 }
Mike Stump11289f42009-09-09 15:08:12 +0000554
Nate Begemanf2758702009-06-26 06:32:41 +0000555 case Attr::ReqdWorkGroupSize: {
556 unsigned X = Record[Idx++];
557 unsigned Y = Record[Idx++];
558 unsigned Z = Record[Idx++];
559 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
560 break;
561 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000562
563 SIMPLE_ATTR(ObjCException);
564 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000565 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000566 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000567 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000568 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000569 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000570 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000571 SIMPLE_ATTR(Packed);
572 UNSIGNED_ATTR(PragmaPack);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000573 SIMPLE_ATTR(Pure);
574 UNSIGNED_ATTR(Regparm);
575 STRING_ATTR(Section);
576 SIMPLE_ATTR(StdCall);
577 SIMPLE_ATTR(TransparentUnion);
578 SIMPLE_ATTR(Unavailable);
579 SIMPLE_ATTR(Unused);
580 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000581
Chris Lattner8f63ab52009-04-27 06:01:06 +0000582 case Attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000583 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000584 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
585 break;
586
587 SIMPLE_ATTR(WarnUnusedResult);
588 SIMPLE_ATTR(Weak);
589 SIMPLE_ATTR(WeakImport);
590 }
591
592 assert(New && "Unable to decode attribute?");
593 New->setInherited(IsInherited);
594 New->setNext(Attrs);
595 Attrs = New;
596 }
597#undef UNSIGNED_ATTR
598#undef STRING_ATTR
599#undef SIMPLE_ATTR
600
601 // The list of attributes was built backwards. Reverse the list
602 // before returning it.
603 Attr *PrevAttr = 0, *NextAttr = 0;
604 while (Attrs) {
605 NextAttr = Attrs->getNext();
606 Attrs->setNext(PrevAttr);
607 PrevAttr = Attrs;
608 Attrs = NextAttr;
609 }
610
611 return PrevAttr;
612}
613
614//===----------------------------------------------------------------------===//
615// PCHReader Implementation
616//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000617
618/// \brief Note that we have loaded the declaration with the given
619/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000620///
Chris Lattner487412d2009-04-27 05:27:42 +0000621/// This routine notes that this declaration has already been loaded,
622/// so that future GetDecl calls will return this declaration rather
623/// than trying to load a new declaration.
624inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
625 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
626 DeclsLoaded[Index] = D;
627}
628
629
630/// \brief Determine whether the consumer will be interested in seeing
631/// this declaration (via HandleTopLevelDecl).
632///
633/// This routine should return true for anything that might affect
634/// code generation, e.g., inline function definitions, Objective-C
635/// declarations with metadata, etc.
636static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000637 if (isa<FileScopeAsmDecl>(D))
638 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000639 if (VarDecl *Var = dyn_cast<VarDecl>(D))
640 return Var->isFileVarDecl() && Var->getInit();
641 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
642 return Func->isThisDeclarationADefinition();
643 return isa<ObjCProtocolDecl>(D);
644}
645
646/// \brief Read the declaration at the given offset from the PCH file.
647Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
648 // Keep track of where we are in the stream, then jump back there
649 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000650 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000651
Douglas Gregor1342e842009-07-06 18:54:52 +0000652 // Note that we are loading a declaration record.
653 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000654
Chris Lattner1de76db2009-04-27 05:58:23 +0000655 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000656 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000657 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000658 unsigned Idx = 0;
659 PCHDeclReader Reader(*this, Record, Idx);
660
Chris Lattner1de76db2009-04-27 05:58:23 +0000661 Decl *D = 0;
662 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000663 case pch::DECL_ATTR:
664 case pch::DECL_CONTEXT_LEXICAL:
665 case pch::DECL_CONTEXT_VISIBLE:
666 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
667 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000668 case pch::DECL_TRANSLATION_UNIT:
669 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +0000670 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +0000671 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000672 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +0000673 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000674 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000675 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000676 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000677 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000678 case pch::DECL_RECORD:
Chris Lattner8575daa2009-04-27 21:45:14 +0000679 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000680 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000681 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000682 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +0000683 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +0000684 0, llvm::APSInt());
685 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000686 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +0000687 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000688 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000689 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000690 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +0000691 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner487412d2009-04-27 05:27:42 +0000692 Selector(), QualType(), 0);
693 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000694 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +0000695 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000696 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000697 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000698 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000699 ObjCIvarDecl::None);
700 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000701 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000702 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000703 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000704 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000705 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000706 QualType(), 0);
707 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000708 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000709 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000710 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000711 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000712 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000713 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000714 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +0000715 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
716 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000717 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000718 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000719 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000720 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000721 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +0000722 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000723 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000724 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000725 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000726 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000727 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000728 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
729 QualType());
Chris Lattner487412d2009-04-27 05:27:42 +0000730 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000731 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000732 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +0000733 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000734 ObjCPropertyImplDecl::Dynamic, 0);
735 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000736 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000737 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000738 false);
Chris Lattner487412d2009-04-27 05:27:42 +0000739 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000740 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000741 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000742 VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +0000743 break;
744
745 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +0000746 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +0000747 break;
748
Chris Lattner8f63ab52009-04-27 06:01:06 +0000749 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +0000750 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000751 VarDecl::None, 0);
752 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000753 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +0000754 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000755 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000756 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +0000757 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000758 break;
Douglas Gregore31bbd92010-02-21 18:22:14 +0000759
760 case pch::DECL_NAMESPACE:
761 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
762 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000763 }
Chris Lattner487412d2009-04-27 05:27:42 +0000764
765 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000766 LoadedDecl(Index, D);
767 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000768
769 // If this declaration is also a declaration context, get the
770 // offsets for its tables of lexical and visible declarations.
771 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
772 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
773 if (Offsets.first || Offsets.second) {
774 DC->setHasExternalLexicalStorage(Offsets.first != 0);
775 DC->setHasExternalVisibleStorage(Offsets.second != 0);
776 DeclContextOffsets[DC] = Offsets;
777 }
778 }
779 assert(Idx == Record.size());
780
781 // If we have deserialized a declaration that has a definition the
782 // AST consumer might need to know about, notify the consumer
783 // about that definition now or queue it for later.
784 if (isConsumerInterestedIn(D)) {
785 if (Consumer) {
786 DeclGroupRef DG(D);
787 Consumer->HandleTopLevelDecl(DG);
788 } else {
789 InterestingDecls.push_back(D);
790 }
791 }
792
793 return D;
794}