blob: 14dd2e927c41a11de9e47836004a24333df6010a [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++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000134 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000135 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000136 // FIXME: maybe read optional qualifier and its range.
137 TD->setTypedefForAnonDecl(
138 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000139}
140
141void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
142 VisitTagDecl(ED);
143 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000144 ED->setPromotionType(Reader.GetType(Record[Idx++]));
Douglas Gregor7a749382009-05-27 17:20:35 +0000145 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000146}
147
148void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
149 VisitTagDecl(RD);
150 RD->setHasFlexibleArrayMember(Record[Idx++]);
151 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000152 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000153}
154
155void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
156 VisitNamedDecl(VD);
157 VD->setType(Reader.GetType(Record[Idx++]));
158}
159
160void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
161 VisitValueDecl(ECD);
162 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000163 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000164 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
165}
166
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000167void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
168 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000169 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
170 if (TInfo)
171 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000172 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000173}
174
Chris Lattner487412d2009-04-27 05:27:42 +0000175void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000176 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000177 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000178 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000179 FD->setPreviousDeclaration(
180 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
181 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000182 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000183 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000184 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000185 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000186 FD->setHasInheritedPrototype(Record[Idx++]);
187 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000188 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000189 FD->setTrivial(Record[Idx++]);
190 FD->setCopyAssignment(Record[Idx++]);
191 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000192 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor24c332b2009-05-14 21:06:31 +0000193 // FIXME: C++ TemplateOrInstantiation
Chris Lattner487412d2009-04-27 05:27:42 +0000194 unsigned NumParams = Record[Idx++];
195 llvm::SmallVector<ParmVarDecl *, 16> Params;
196 Params.reserve(NumParams);
197 for (unsigned I = 0; I != NumParams; ++I)
198 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000199 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000200
201 // FIXME: order this properly w.r.t. friendness
202 // FIXME: this same thing needs to happen for function templates
203 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
204 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000205}
206
207void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
208 VisitNamedDecl(MD);
209 if (Record[Idx++]) {
210 // In practice, this won't be executed (since method definitions
211 // don't occur in header files).
Chris Lattner1de76db2009-04-27 05:58:23 +0000212 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000213 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
214 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
215 }
216 MD->setInstanceMethod(Record[Idx++]);
217 MD->setVariadic(Record[Idx++]);
218 MD->setSynthesized(Record[Idx++]);
219 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
220 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000221 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000222 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000223 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000224 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
225 unsigned NumParams = Record[Idx++];
226 llvm::SmallVector<ParmVarDecl *, 16> Params;
227 Params.reserve(NumParams);
228 for (unsigned I = 0; I != NumParams; ++I)
229 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000230 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
231 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000232}
233
234void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
235 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000236 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
237 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
238 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000239}
240
241void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
242 VisitObjCContainerDecl(ID);
243 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
244 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
245 (Reader.GetDecl(Record[Idx++])));
246 unsigned NumProtocols = Record[Idx++];
247 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
248 Protocols.reserve(NumProtocols);
249 for (unsigned I = 0; I != NumProtocols; ++I)
250 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000251 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
252 ProtoLocs.reserve(NumProtocols);
253 for (unsigned I = 0; I != NumProtocols; ++I)
254 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
255 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
256 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000257 unsigned NumIvars = Record[Idx++];
258 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
259 IVars.reserve(NumIvars);
260 for (unsigned I = 0; I != NumIvars; ++I)
261 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000262 ID->setCategoryList(
263 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
264 ID->setForwardDecl(Record[Idx++]);
265 ID->setImplicitInterfaceDecl(Record[Idx++]);
266 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
267 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000268 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000269}
270
271void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
272 VisitFieldDecl(IVD);
273 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
274}
275
276void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
277 VisitObjCContainerDecl(PD);
278 PD->setForwardDecl(Record[Idx++]);
279 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
280 unsigned NumProtoRefs = Record[Idx++];
281 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
282 ProtoRefs.reserve(NumProtoRefs);
283 for (unsigned I = 0; I != NumProtoRefs; ++I)
284 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000285 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
286 ProtoLocs.reserve(NumProtoRefs);
287 for (unsigned I = 0; I != NumProtoRefs; ++I)
288 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
289 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
290 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000291}
292
293void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
294 VisitFieldDecl(FD);
295}
296
297void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
298 VisitDecl(CD);
299 unsigned NumClassRefs = Record[Idx++];
300 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
301 ClassRefs.reserve(NumClassRefs);
302 for (unsigned I = 0; I != NumClassRefs; ++I)
303 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000304 llvm::SmallVector<SourceLocation, 16> SLocs;
305 SLocs.reserve(NumClassRefs);
306 for (unsigned I = 0; I != NumClassRefs; ++I)
307 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
308 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
309 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000310}
311
312void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
313 VisitDecl(FPD);
314 unsigned NumProtoRefs = Record[Idx++];
315 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
316 ProtoRefs.reserve(NumProtoRefs);
317 for (unsigned I = 0; I != NumProtoRefs; ++I)
318 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000319 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
320 ProtoLocs.reserve(NumProtoRefs);
321 for (unsigned I = 0; I != NumProtoRefs; ++I)
322 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
323 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
324 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000325}
326
327void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
328 VisitObjCContainerDecl(CD);
329 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
330 unsigned NumProtoRefs = Record[Idx++];
331 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
332 ProtoRefs.reserve(NumProtoRefs);
333 for (unsigned I = 0; I != NumProtoRefs; ++I)
334 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000335 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
336 ProtoLocs.reserve(NumProtoRefs);
337 for (unsigned I = 0; I != NumProtoRefs; ++I)
338 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
339 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
340 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000341 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000342 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
343 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000344}
345
346void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
347 VisitNamedDecl(CAD);
348 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
349}
350
351void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
352 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000353 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000354 D->setType(Reader.GetType(Record[Idx++]));
355 // FIXME: stable encoding
356 D->setPropertyAttributes(
357 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
358 // FIXME: stable encoding
359 D->setPropertyImplementation(
360 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
361 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
362 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
363 D->setGetterMethodDecl(
364 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
365 D->setSetterMethodDecl(
366 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
367 D->setPropertyIvarDecl(
368 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
369}
370
371void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000372 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000373 D->setClassInterface(
374 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000375}
376
377void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
378 VisitObjCImplDecl(D);
379 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
380}
381
382void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
383 VisitObjCImplDecl(D);
384 D->setSuperClass(
385 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000386 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000387}
388
389
390void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
391 VisitDecl(D);
392 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
393 D->setPropertyDecl(
394 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
395 D->setPropertyIvarDecl(
396 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
397}
398
399void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000400 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000401 FD->setMutable(Record[Idx++]);
402 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000403 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000404}
405
406void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000407 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000408 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000409 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000410 VD->setThreadSpecified(Record[Idx++]);
411 VD->setCXXDirectInitializer(Record[Idx++]);
412 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000413 VD->setExceptionVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000414 VD->setPreviousDeclaration(
415 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000416 if (Record[Idx++])
Douglas Gregord5058122010-02-11 01:19:42 +0000417 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000418}
419
420void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
421 VisitVarDecl(PD);
422}
423
424void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
425 VisitVarDecl(PD);
426 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000427 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000428}
429
Chris Lattner487412d2009-04-27 05:27:42 +0000430void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
431 VisitDecl(AD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000432 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000433}
434
435void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
436 VisitDecl(BD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000437 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner487412d2009-04-27 05:27:42 +0000438 unsigned NumParams = Record[Idx++];
439 llvm::SmallVector<ParmVarDecl *, 16> Params;
440 Params.reserve(NumParams);
441 for (unsigned I = 0; I != NumParams; ++I)
442 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000443 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000444}
445
Mike Stump11289f42009-09-09 15:08:12 +0000446std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000447PCHDeclReader::VisitDeclContext(DeclContext *DC) {
448 uint64_t LexicalOffset = Record[Idx++];
449 uint64_t VisibleOffset = Record[Idx++];
450 return std::make_pair(LexicalOffset, VisibleOffset);
451}
452
453//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000454// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000455//===----------------------------------------------------------------------===//
456
Chris Lattner8f63ab52009-04-27 06:01:06 +0000457/// \brief Reads attributes from the current stream position.
458Attr *PCHReader::ReadAttributes() {
459 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000460 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000461 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000462
Chris Lattner8f63ab52009-04-27 06:01:06 +0000463 RecordData Record;
464 unsigned Idx = 0;
465 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000466 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000467 (void)RecCode;
468
469#define SIMPLE_ATTR(Name) \
470 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000471 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000472 break
473
474#define STRING_ATTR(Name) \
475 case Attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000476 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000477 break
478
479#define UNSIGNED_ATTR(Name) \
480 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000481 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000482 break
483
484 Attr *Attrs = 0;
485 while (Idx < Record.size()) {
486 Attr *New = 0;
487 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
488 bool IsInherited = Record[Idx++];
489
490 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000491 default:
492 assert(0 && "Unknown attribute!");
493 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000494 STRING_ATTR(Alias);
495 UNSIGNED_ATTR(Aligned);
496 SIMPLE_ATTR(AlwaysInline);
497 SIMPLE_ATTR(AnalyzerNoReturn);
498 STRING_ATTR(Annotate);
499 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000500 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000501
Chris Lattner8f63ab52009-04-27 06:01:06 +0000502 case Attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000503 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000504 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
505 break;
Mike Stump11289f42009-09-09 15:08:12 +0000506
Eli Friedmane4310c82009-11-09 18:38:53 +0000507 SIMPLE_ATTR(CDecl);
508
Chris Lattner8f63ab52009-04-27 06:01:06 +0000509 case Attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000510 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000511 cast<FunctionDecl>(GetDecl(Record[Idx++])));
512 break;
513
514 SIMPLE_ATTR(Const);
515 UNSIGNED_ATTR(Constructor);
516 SIMPLE_ATTR(DLLExport);
517 SIMPLE_ATTR(DLLImport);
518 SIMPLE_ATTR(Deprecated);
519 UNSIGNED_ATTR(Destructor);
520 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000521 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000522
Chris Lattner8f63ab52009-04-27 06:01:06 +0000523 case Attr::Format: {
524 std::string Type = ReadString(Record, Idx);
525 unsigned FormatIdx = Record[Idx++];
526 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000527 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000528 break;
529 }
Mike Stump11289f42009-09-09 15:08:12 +0000530
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000531 case Attr::FormatArg: {
532 unsigned FormatIdx = Record[Idx++];
533 New = ::new (*Context) FormatArgAttr(FormatIdx);
534 break;
535 }
Mike Stump11289f42009-09-09 15:08:12 +0000536
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000537 case Attr::Sentinel: {
538 int sentinel = Record[Idx++];
539 int nullPos = Record[Idx++];
540 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
541 break;
542 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000543
544 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000545 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000546
Ted Kremenek06be9682010-02-17 02:37:45 +0000547 case Attr::IBActionKind:
548 New = ::new (*Context) IBActionAttr();
549 break;
550
Chris Lattner8f63ab52009-04-27 06:01:06 +0000551 case Attr::IBOutletKind:
Chris Lattner8575daa2009-04-27 21:45:14 +0000552 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000553 break;
554
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000555 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000556 SIMPLE_ATTR(NoDebug);
557 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000558 SIMPLE_ATTR(NoReturn);
559 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000560
Chris Lattner8f63ab52009-04-27 06:01:06 +0000561 case Attr::NonNull: {
562 unsigned Size = Record[Idx++];
563 llvm::SmallVector<unsigned, 16> ArgNums;
564 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
565 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000566 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000567 break;
568 }
Mike Stump11289f42009-09-09 15:08:12 +0000569
Nate Begemanf2758702009-06-26 06:32:41 +0000570 case Attr::ReqdWorkGroupSize: {
571 unsigned X = Record[Idx++];
572 unsigned Y = Record[Idx++];
573 unsigned Z = Record[Idx++];
574 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
575 break;
576 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000577
578 SIMPLE_ATTR(ObjCException);
579 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000580 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000581 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000582 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000583 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000584 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000585 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000586 SIMPLE_ATTR(Packed);
587 UNSIGNED_ATTR(PragmaPack);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000588 SIMPLE_ATTR(Pure);
589 UNSIGNED_ATTR(Regparm);
590 STRING_ATTR(Section);
591 SIMPLE_ATTR(StdCall);
592 SIMPLE_ATTR(TransparentUnion);
593 SIMPLE_ATTR(Unavailable);
594 SIMPLE_ATTR(Unused);
595 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000596
Chris Lattner8f63ab52009-04-27 06:01:06 +0000597 case Attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000598 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000599 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
600 break;
601
602 SIMPLE_ATTR(WarnUnusedResult);
603 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +0000604 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000605 SIMPLE_ATTR(WeakImport);
606 }
607
608 assert(New && "Unable to decode attribute?");
609 New->setInherited(IsInherited);
610 New->setNext(Attrs);
611 Attrs = New;
612 }
613#undef UNSIGNED_ATTR
614#undef STRING_ATTR
615#undef SIMPLE_ATTR
616
617 // The list of attributes was built backwards. Reverse the list
618 // before returning it.
619 Attr *PrevAttr = 0, *NextAttr = 0;
620 while (Attrs) {
621 NextAttr = Attrs->getNext();
622 Attrs->setNext(PrevAttr);
623 PrevAttr = Attrs;
624 Attrs = NextAttr;
625 }
626
627 return PrevAttr;
628}
629
630//===----------------------------------------------------------------------===//
631// PCHReader Implementation
632//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000633
634/// \brief Note that we have loaded the declaration with the given
635/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000636///
Chris Lattner487412d2009-04-27 05:27:42 +0000637/// This routine notes that this declaration has already been loaded,
638/// so that future GetDecl calls will return this declaration rather
639/// than trying to load a new declaration.
640inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
641 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
642 DeclsLoaded[Index] = D;
643}
644
645
646/// \brief Determine whether the consumer will be interested in seeing
647/// this declaration (via HandleTopLevelDecl).
648///
649/// This routine should return true for anything that might affect
650/// code generation, e.g., inline function definitions, Objective-C
651/// declarations with metadata, etc.
652static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000653 if (isa<FileScopeAsmDecl>(D))
654 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000655 if (VarDecl *Var = dyn_cast<VarDecl>(D))
656 return Var->isFileVarDecl() && Var->getInit();
657 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
658 return Func->isThisDeclarationADefinition();
659 return isa<ObjCProtocolDecl>(D);
660}
661
662/// \brief Read the declaration at the given offset from the PCH file.
663Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
664 // Keep track of where we are in the stream, then jump back there
665 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000666 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000667
Douglas Gregor1342e842009-07-06 18:54:52 +0000668 // Note that we are loading a declaration record.
669 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000670
Chris Lattner1de76db2009-04-27 05:58:23 +0000671 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000672 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000673 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000674 unsigned Idx = 0;
675 PCHDeclReader Reader(*this, Record, Idx);
676
Chris Lattner1de76db2009-04-27 05:58:23 +0000677 Decl *D = 0;
678 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000679 case pch::DECL_ATTR:
680 case pch::DECL_CONTEXT_LEXICAL:
681 case pch::DECL_CONTEXT_VISIBLE:
682 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
683 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000684 case pch::DECL_TRANSLATION_UNIT:
685 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +0000686 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +0000687 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000688 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +0000689 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000690 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000691 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000692 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000693 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000694 case pch::DECL_RECORD:
Chris Lattner8575daa2009-04-27 21:45:14 +0000695 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000696 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000697 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000698 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +0000699 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +0000700 0, llvm::APSInt());
701 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000702 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +0000703 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000704 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000705 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000706 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +0000707 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +0000708 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000709 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000710 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +0000711 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000712 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000713 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000714 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000715 ObjCIvarDecl::None);
716 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000717 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000718 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000719 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000720 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000721 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000722 QualType(), 0);
723 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000724 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000725 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000726 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000727 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000728 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000729 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000730 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +0000731 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
732 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000733 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000734 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000735 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000736 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000737 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +0000738 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000739 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000740 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000741 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000742 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000743 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000744 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
745 QualType());
Chris Lattner487412d2009-04-27 05:27:42 +0000746 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000747 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000748 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +0000749 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000750 ObjCPropertyImplDecl::Dynamic, 0);
751 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000752 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000753 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000754 false);
Chris Lattner487412d2009-04-27 05:27:42 +0000755 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000756 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000757 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +0000758 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +0000759 break;
760
761 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +0000762 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +0000763 break;
764
Chris Lattner8f63ab52009-04-27 06:01:06 +0000765 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +0000766 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +0000767 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000768 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000769 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +0000770 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000771 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000772 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +0000773 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000774 break;
Douglas Gregore31bbd92010-02-21 18:22:14 +0000775
776 case pch::DECL_NAMESPACE:
777 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
778 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000779 }
Chris Lattner487412d2009-04-27 05:27:42 +0000780
781 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000782 LoadedDecl(Index, D);
783 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000784
785 // If this declaration is also a declaration context, get the
786 // offsets for its tables of lexical and visible declarations.
787 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
788 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
789 if (Offsets.first || Offsets.second) {
790 DC->setHasExternalLexicalStorage(Offsets.first != 0);
791 DC->setHasExternalVisibleStorage(Offsets.second != 0);
792 DeclContextOffsets[DC] = Offsets;
793 }
794 }
795 assert(Idx == Record.size());
796
797 // If we have deserialized a declaration that has a definition the
798 // AST consumer might need to know about, notify the consumer
799 // about that definition now or queue it for later.
800 if (isConsumerInterestedIn(D)) {
801 if (Consumer) {
802 DeclGroupRef DG(D);
803 Consumer->HandleTopLevelDecl(DG);
804 } else {
805 InterestingDecls.push_back(D);
806 }
807 }
808
809 return D;
810}