blob: f847becb15b878562082026c717026fd936061b5 [file] [log] [blame]
Chris Lattner698f9252009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
20#include "clang/AST/Expr.h"
21using namespace clang;
22
Chris Lattner698f9252009-04-27 05:27:42 +000023
24//===----------------------------------------------------------------------===//
25// Declaration deserialization
26//===----------------------------------------------------------------------===//
27
28namespace {
29 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
30 PCHReader &Reader;
31 const PCHReader::RecordData &Record;
32 unsigned &Idx;
33
34 public:
35 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
36 unsigned &Idx)
37 : Reader(Reader), Record(Record), Idx(Idx) { }
38
39 void VisitDecl(Decl *D);
40 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
41 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregor0cef4832010-02-21 18:22:14 +000042 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner698f9252009-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 Kyrtzidisd4a7e542009-08-19 01:28:35 +000050 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-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 Lattner698f9252009-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 Kyrtzidis40b598e2009-06-30 02:34:44 +000084 D->addAttr(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +000085 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +000086 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +000087 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +000088 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-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 Stump1eb44332009-09-09 15:08:12 +000097 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +000098}
99
Douglas Gregor0cef4832010-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 Lattner698f9252009-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 McCallba6a9bd2009-10-24 08:00:42 +0000122 uint64_t TypeData = Record[Idx++];
John McCalla93c9342009-12-07 02:54:59 +0000123 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCallba6a9bd2009-10-24 08:00:42 +0000124 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000125}
126
127void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
128 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000129 TD->setPreviousDeclaration(
130 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000131 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
132 TD->setDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000133 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000134 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000135 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallb6217662010-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 Lattner698f9252009-04-27 05:27:42 +0000139}
140
141void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
142 VisitTagDecl(ED);
143 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000144 ED->setPromotionType(Reader.GetType(Record[Idx++]));
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000145 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-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 Jahanian643b7df2009-07-08 16:37:44 +0000152 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-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 Lattnerda930612009-04-27 05:58:23 +0000163 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000164 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
165}
166
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000167void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
168 VisitValueDecl(DD);
John McCalla93c9342009-12-07 02:54:59 +0000169 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
170 if (TInfo)
171 DD->setTypeSourceInfo(TInfo);
John McCallb6217662010-03-15 10:12:16 +0000172 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000173}
174
Chris Lattner698f9252009-04-27 05:27:42 +0000175void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000176 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000177 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000178 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-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 Gregor0130f3c2009-10-27 21:01:01 +0000182 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000183 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000184 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000185 FD->setHasInheritedPrototype(Record[Idx++]);
186 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000187 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000188 FD->setTrivial(Record[Idx++]);
189 FD->setCopyAssignment(Record[Idx++]);
190 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000191 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000192 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000193 unsigned NumParams = Record[Idx++];
194 llvm::SmallVector<ParmVarDecl *, 16> Params;
195 Params.reserve(NumParams);
196 for (unsigned I = 0; I != NumParams; ++I)
197 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000198 FD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000199}
200
201void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
202 VisitNamedDecl(MD);
203 if (Record[Idx++]) {
204 // In practice, this won't be executed (since method definitions
205 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000206 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000207 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
208 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
209 }
210 MD->setInstanceMethod(Record[Idx++]);
211 MD->setVariadic(Record[Idx++]);
212 MD->setSynthesized(Record[Idx++]);
213 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
214 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
215 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000216 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000217 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
218 unsigned NumParams = Record[Idx++];
219 llvm::SmallVector<ParmVarDecl *, 16> Params;
220 Params.reserve(NumParams);
221 for (unsigned I = 0; I != NumParams; ++I)
222 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000223 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000224}
225
226void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
227 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000228 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
229 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
230 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000231}
232
233void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
234 VisitObjCContainerDecl(ID);
235 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
236 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
237 (Reader.GetDecl(Record[Idx++])));
238 unsigned NumProtocols = Record[Idx++];
239 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
240 Protocols.reserve(NumProtocols);
241 for (unsigned I = 0; I != NumProtocols; ++I)
242 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000243 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
244 ProtoLocs.reserve(NumProtocols);
245 for (unsigned I = 0; I != NumProtocols; ++I)
246 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
247 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
248 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000249 unsigned NumIvars = Record[Idx++];
250 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
251 IVars.reserve(NumIvars);
252 for (unsigned I = 0; I != NumIvars; ++I)
253 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000254 ID->setCategoryList(
255 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
256 ID->setForwardDecl(Record[Idx++]);
257 ID->setImplicitInterfaceDecl(Record[Idx++]);
258 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
259 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000260 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000261}
262
263void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
264 VisitFieldDecl(IVD);
265 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
266}
267
268void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
269 VisitObjCContainerDecl(PD);
270 PD->setForwardDecl(Record[Idx++]);
271 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
272 unsigned NumProtoRefs = Record[Idx++];
273 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
274 ProtoRefs.reserve(NumProtoRefs);
275 for (unsigned I = 0; I != NumProtoRefs; ++I)
276 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000277 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
278 ProtoLocs.reserve(NumProtoRefs);
279 for (unsigned I = 0; I != NumProtoRefs; ++I)
280 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
281 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
282 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000283}
284
285void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
286 VisitFieldDecl(FD);
287}
288
289void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
290 VisitDecl(CD);
291 unsigned NumClassRefs = Record[Idx++];
292 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
293 ClassRefs.reserve(NumClassRefs);
294 for (unsigned I = 0; I != NumClassRefs; ++I)
295 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000296 llvm::SmallVector<SourceLocation, 16> SLocs;
297 SLocs.reserve(NumClassRefs);
298 for (unsigned I = 0; I != NumClassRefs; ++I)
299 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
300 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
301 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000302}
303
304void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
305 VisitDecl(FPD);
306 unsigned NumProtoRefs = Record[Idx++];
307 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
308 ProtoRefs.reserve(NumProtoRefs);
309 for (unsigned I = 0; I != NumProtoRefs; ++I)
310 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000311 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
312 ProtoLocs.reserve(NumProtoRefs);
313 for (unsigned I = 0; I != NumProtoRefs; ++I)
314 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
315 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
316 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000317}
318
319void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
320 VisitObjCContainerDecl(CD);
321 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
322 unsigned NumProtoRefs = Record[Idx++];
323 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
324 ProtoRefs.reserve(NumProtoRefs);
325 for (unsigned I = 0; I != NumProtoRefs; ++I)
326 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000327 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
328 ProtoLocs.reserve(NumProtoRefs);
329 for (unsigned I = 0; I != NumProtoRefs; ++I)
330 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
331 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
332 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000333 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor3db211b2010-01-16 16:38:58 +0000334 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
335 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000336}
337
338void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
339 VisitNamedDecl(CAD);
340 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
341}
342
343void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
344 VisitNamedDecl(D);
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000345 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000346 D->setType(Reader.GetType(Record[Idx++]));
347 // FIXME: stable encoding
348 D->setPropertyAttributes(
349 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
350 // FIXME: stable encoding
351 D->setPropertyImplementation(
352 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
353 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
354 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
355 D->setGetterMethodDecl(
356 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
357 D->setSetterMethodDecl(
358 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
359 D->setPropertyIvarDecl(
360 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
361}
362
363void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000364 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000365 D->setClassInterface(
366 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000367}
368
369void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
370 VisitObjCImplDecl(D);
371 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
372}
373
374void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
375 VisitObjCImplDecl(D);
376 D->setSuperClass(
377 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
378}
379
380
381void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
382 VisitDecl(D);
383 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
384 D->setPropertyDecl(
385 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
386 D->setPropertyIvarDecl(
387 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
388}
389
390void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000391 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000392 FD->setMutable(Record[Idx++]);
393 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000394 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000395}
396
397void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000398 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000399 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
400 VD->setThreadSpecified(Record[Idx++]);
401 VD->setCXXDirectInitializer(Record[Idx++]);
402 VD->setDeclaredInCondition(Record[Idx++]);
403 VD->setPreviousDeclaration(
404 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000405 if (Record[Idx++])
Douglas Gregor838db382010-02-11 01:19:42 +0000406 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000407}
408
409void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
410 VisitVarDecl(PD);
411}
412
413void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
414 VisitVarDecl(PD);
415 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallbf73b352010-03-12 18:31:32 +0000416 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000417}
418
Chris Lattner698f9252009-04-27 05:27:42 +0000419void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
420 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000421 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000422}
423
424void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
425 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000426 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000427 unsigned NumParams = Record[Idx++];
428 llvm::SmallVector<ParmVarDecl *, 16> Params;
429 Params.reserve(NumParams);
430 for (unsigned I = 0; I != NumParams; ++I)
431 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000432 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000433}
434
Mike Stump1eb44332009-09-09 15:08:12 +0000435std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000436PCHDeclReader::VisitDeclContext(DeclContext *DC) {
437 uint64_t LexicalOffset = Record[Idx++];
438 uint64_t VisibleOffset = Record[Idx++];
439 return std::make_pair(LexicalOffset, VisibleOffset);
440}
441
442//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000443// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000444//===----------------------------------------------------------------------===//
445
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000446/// \brief Reads attributes from the current stream position.
447Attr *PCHReader::ReadAttributes() {
448 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000449 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000450 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000451
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000452 RecordData Record;
453 unsigned Idx = 0;
454 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000455 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000456 (void)RecCode;
457
458#define SIMPLE_ATTR(Name) \
459 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000460 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000461 break
462
463#define STRING_ATTR(Name) \
464 case Attr::Name: \
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000465 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000466 break
467
468#define UNSIGNED_ATTR(Name) \
469 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000470 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000471 break
472
473 Attr *Attrs = 0;
474 while (Idx < Record.size()) {
475 Attr *New = 0;
476 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
477 bool IsInherited = Record[Idx++];
478
479 switch (Kind) {
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000480 default:
481 assert(0 && "Unknown attribute!");
482 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000483 STRING_ATTR(Alias);
484 UNSIGNED_ATTR(Aligned);
485 SIMPLE_ATTR(AlwaysInline);
486 SIMPLE_ATTR(AnalyzerNoReturn);
487 STRING_ATTR(Annotate);
488 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +0000489 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +0000490
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000491 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000492 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000493 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
494 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000495
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000496 SIMPLE_ATTR(CDecl);
497
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000498 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000499 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000500 cast<FunctionDecl>(GetDecl(Record[Idx++])));
501 break;
502
503 SIMPLE_ATTR(Const);
504 UNSIGNED_ATTR(Constructor);
505 SIMPLE_ATTR(DLLExport);
506 SIMPLE_ATTR(DLLImport);
507 SIMPLE_ATTR(Deprecated);
508 UNSIGNED_ATTR(Destructor);
509 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +0000510 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000512 case Attr::Format: {
513 std::string Type = ReadString(Record, Idx);
514 unsigned FormatIdx = Record[Idx++];
515 unsigned FirstArg = Record[Idx++];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000516 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000517 break;
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000520 case Attr::FormatArg: {
521 unsigned FormatIdx = Record[Idx++];
522 New = ::new (*Context) FormatArgAttr(FormatIdx);
523 break;
524 }
Mike Stump1eb44332009-09-09 15:08:12 +0000525
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000526 case Attr::Sentinel: {
527 int sentinel = Record[Idx++];
528 int nullPos = Record[Idx++];
529 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
530 break;
531 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000532
533 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +0000534 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +0000535
Ted Kremenekefbddd22010-02-17 02:37:45 +0000536 case Attr::IBActionKind:
537 New = ::new (*Context) IBActionAttr();
538 break;
539
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000540 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000541 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000542 break;
543
Ryan Flynn76168e22009-08-09 20:07:29 +0000544 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000545 SIMPLE_ATTR(NoDebug);
546 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000547 SIMPLE_ATTR(NoReturn);
548 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000549
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000550 case Attr::NonNull: {
551 unsigned Size = Record[Idx++];
552 llvm::SmallVector<unsigned, 16> ArgNums;
553 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
554 Idx += Size;
Ted Kremenek59616112010-02-11 07:31:47 +0000555 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000556 break;
557 }
Mike Stump1eb44332009-09-09 15:08:12 +0000558
Nate Begeman6f3d8382009-06-26 06:32:41 +0000559 case Attr::ReqdWorkGroupSize: {
560 unsigned X = Record[Idx++];
561 unsigned Y = Record[Idx++];
562 unsigned Z = Record[Idx++];
563 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
564 break;
565 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000566
567 SIMPLE_ATTR(ObjCException);
568 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenek31c780d2010-02-18 00:05:45 +0000569 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000570 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenek31c780d2010-02-18 00:05:45 +0000571 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000572 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000573 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +0000574 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +0000575 SIMPLE_ATTR(Packed);
576 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000577 SIMPLE_ATTR(Pure);
578 UNSIGNED_ATTR(Regparm);
579 STRING_ATTR(Section);
580 SIMPLE_ATTR(StdCall);
581 SIMPLE_ATTR(TransparentUnion);
582 SIMPLE_ATTR(Unavailable);
583 SIMPLE_ATTR(Unused);
584 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000585
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000586 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000587 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000588 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
589 break;
590
591 SIMPLE_ATTR(WarnUnusedResult);
592 SIMPLE_ATTR(Weak);
Rafael Espindola11e8ce72010-02-23 22:00:30 +0000593 SIMPLE_ATTR(WeakRef);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000594 SIMPLE_ATTR(WeakImport);
595 }
596
597 assert(New && "Unable to decode attribute?");
598 New->setInherited(IsInherited);
599 New->setNext(Attrs);
600 Attrs = New;
601 }
602#undef UNSIGNED_ATTR
603#undef STRING_ATTR
604#undef SIMPLE_ATTR
605
606 // The list of attributes was built backwards. Reverse the list
607 // before returning it.
608 Attr *PrevAttr = 0, *NextAttr = 0;
609 while (Attrs) {
610 NextAttr = Attrs->getNext();
611 Attrs->setNext(PrevAttr);
612 PrevAttr = Attrs;
613 Attrs = NextAttr;
614 }
615
616 return PrevAttr;
617}
618
619//===----------------------------------------------------------------------===//
620// PCHReader Implementation
621//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000622
623/// \brief Note that we have loaded the declaration with the given
624/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000625///
Chris Lattner698f9252009-04-27 05:27:42 +0000626/// This routine notes that this declaration has already been loaded,
627/// so that future GetDecl calls will return this declaration rather
628/// than trying to load a new declaration.
629inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
630 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
631 DeclsLoaded[Index] = D;
632}
633
634
635/// \brief Determine whether the consumer will be interested in seeing
636/// this declaration (via HandleTopLevelDecl).
637///
638/// This routine should return true for anything that might affect
639/// code generation, e.g., inline function definitions, Objective-C
640/// declarations with metadata, etc.
641static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000642 if (isa<FileScopeAsmDecl>(D))
643 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000644 if (VarDecl *Var = dyn_cast<VarDecl>(D))
645 return Var->isFileVarDecl() && Var->getInit();
646 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
647 return Func->isThisDeclarationADefinition();
648 return isa<ObjCProtocolDecl>(D);
649}
650
651/// \brief Read the declaration at the given offset from the PCH file.
652Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
653 // Keep track of where we are in the stream, then jump back there
654 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000655 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000656
Douglas Gregord89275b2009-07-06 18:54:52 +0000657 // Note that we are loading a declaration record.
658 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000659
Chris Lattnerda930612009-04-27 05:58:23 +0000660 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000661 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000662 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000663 unsigned Idx = 0;
664 PCHDeclReader Reader(*this, Record, Idx);
665
Chris Lattnerda930612009-04-27 05:58:23 +0000666 Decl *D = 0;
667 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000668 case pch::DECL_ATTR:
669 case pch::DECL_CONTEXT_LEXICAL:
670 case pch::DECL_CONTEXT_VISIBLE:
671 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
672 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000673 case pch::DECL_TRANSLATION_UNIT:
674 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000675 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000676 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000677 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +0000678 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000679 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000680 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000681 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000682 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000683 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000684 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000685 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000686 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000687 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000688 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000689 0, llvm::APSInt());
690 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000691 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000692 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000693 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000694 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000695 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000696 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000697 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000698 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000699 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000700 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000701 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000702 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000703 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000704 ObjCIvarDecl::None);
705 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000706 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000707 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000708 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000709 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000710 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000711 QualType(), 0);
712 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000713 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000714 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000715 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000716 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000717 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000718 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000719 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +0000720 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
721 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000722 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000723 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000724 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000725 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000726 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000727 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000728 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000729 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000730 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000731 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000732 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000733 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
734 QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000735 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000736 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000737 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000738 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000739 ObjCPropertyImplDecl::Dynamic, 0);
740 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000741 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000742 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000743 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000744 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000745 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000746 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000747 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000748 break;
749
750 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000751 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000752 break;
753
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000754 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000755 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000756 VarDecl::None, 0);
757 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000758 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000759 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000760 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000761 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000762 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000763 break;
Douglas Gregor0cef4832010-02-21 18:22:14 +0000764
765 case pch::DECL_NAMESPACE:
766 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
767 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000768 }
Chris Lattner698f9252009-04-27 05:27:42 +0000769
770 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000771 LoadedDecl(Index, D);
772 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000773
774 // If this declaration is also a declaration context, get the
775 // offsets for its tables of lexical and visible declarations.
776 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
777 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
778 if (Offsets.first || Offsets.second) {
779 DC->setHasExternalLexicalStorage(Offsets.first != 0);
780 DC->setHasExternalVisibleStorage(Offsets.second != 0);
781 DeclContextOffsets[DC] = Offsets;
782 }
783 }
784 assert(Idx == Record.size());
785
786 // If we have deserialized a declaration that has a definition the
787 // AST consumer might need to know about, notify the consumer
788 // about that definition now or queue it for later.
789 if (isConsumerInterestedIn(D)) {
790 if (Consumer) {
791 DeclGroupRef DG(D);
792 Consumer->HandleTopLevelDecl(DG);
793 } else {
794 InterestingDecls.push_back(D);
795 }
796 }
797
798 return D;
799}