blob: 5925dc6d7146687dcfa362b6dbe53a64b7c27a36 [file] [log] [blame]
Chris Lattner698f9252009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
20#include "clang/AST/Expr.h"
21using namespace clang;
22
Chris Lattner698f9252009-04-27 05:27:42 +000023
24//===----------------------------------------------------------------------===//
25// Declaration deserialization
26//===----------------------------------------------------------------------===//
27
28namespace {
29 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
30 PCHReader &Reader;
31 const PCHReader::RecordData &Record;
32 unsigned &Idx;
33
34 public:
35 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
36 unsigned &Idx)
37 : Reader(Reader), Record(Record), Idx(Idx) { }
38
39 void VisitDecl(Decl *D);
40 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
41 void VisitNamedDecl(NamedDecl *ND);
42 void VisitTypeDecl(TypeDecl *TD);
43 void VisitTypedefDecl(TypedefDecl *TD);
44 void VisitTagDecl(TagDecl *TD);
45 void VisitEnumDecl(EnumDecl *ED);
46 void VisitRecordDecl(RecordDecl *RD);
47 void VisitValueDecl(ValueDecl *VD);
48 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000049 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000050 void VisitFunctionDecl(FunctionDecl *FD);
51 void VisitFieldDecl(FieldDecl *FD);
52 void VisitVarDecl(VarDecl *VD);
53 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
54 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner698f9252009-04-27 05:27:42 +000055 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
56 void VisitBlockDecl(BlockDecl *BD);
57 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
58 void VisitObjCMethodDecl(ObjCMethodDecl *D);
59 void VisitObjCContainerDecl(ObjCContainerDecl *D);
60 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
61 void VisitObjCIvarDecl(ObjCIvarDecl *D);
62 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
63 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
64 void VisitObjCClassDecl(ObjCClassDecl *D);
65 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
66 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
67 void VisitObjCImplDecl(ObjCImplDecl *D);
68 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
69 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
70 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
71 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
72 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
73 };
74}
75
76void PCHDeclReader::VisitDecl(Decl *D) {
77 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
78 D->setLexicalDeclContext(
79 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
80 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
81 D->setInvalidDecl(Record[Idx++]);
82 if (Record[Idx++])
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +000083 D->addAttr(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +000084 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +000085 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +000086 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +000087 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +000088}
89
90void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
91 VisitDecl(TU);
92}
93
94void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
95 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +000096 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +000097}
98
99void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
100 VisitNamedDecl(TD);
101 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
102}
103
104void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
105 // Note that we cannot use VisitTypeDecl here, because we need to
106 // set the underlying type of the typedef *before* we try to read
107 // the type associated with the TypedefDecl.
108 VisitNamedDecl(TD);
109 TD->setUnderlyingType(Reader.GetType(Record[Idx + 1]));
110 TD->setTypeForDecl(Reader.GetType(Record[Idx]).getTypePtr());
111 Idx += 2;
112}
113
114void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
115 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000116 TD->setPreviousDeclaration(
117 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000118 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
119 TD->setDefinition(Record[Idx++]);
120 TD->setTypedefForAnonDecl(
121 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000122 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000123 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000124}
125
126void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
127 VisitTagDecl(ED);
128 ED->setIntegerType(Reader.GetType(Record[Idx++]));
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000129 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-04-27 05:27:42 +0000130}
131
132void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
133 VisitTagDecl(RD);
134 RD->setHasFlexibleArrayMember(Record[Idx++]);
135 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000136 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000137}
138
139void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
140 VisitNamedDecl(VD);
141 VD->setType(Reader.GetType(Record[Idx++]));
142}
143
144void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
145 VisitValueDecl(ECD);
146 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000147 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000148 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
149}
150
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000151void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
152 VisitValueDecl(DD);
John McCalla1ee0c52009-10-16 21:56:05 +0000153 DeclaratorInfo *DInfo = Reader.GetDeclaratorInfo(Record, Idx);
154 if (DInfo)
155 DD->setDeclaratorInfo(DInfo);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000156}
157
Chris Lattner698f9252009-04-27 05:27:42 +0000158void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000159 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000160 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000161 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000162 FD->setPreviousDeclaration(
163 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
164 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
165 FD->setInline(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000166 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000167 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000168 FD->setHasInheritedPrototype(Record[Idx++]);
169 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000170 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000171 FD->setTrivial(Record[Idx++]);
172 FD->setCopyAssignment(Record[Idx++]);
173 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000174 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000175 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000176 unsigned NumParams = Record[Idx++];
177 llvm::SmallVector<ParmVarDecl *, 16> Params;
178 Params.reserve(NumParams);
179 for (unsigned I = 0; I != NumParams; ++I)
180 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000181 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000182}
183
184void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
185 VisitNamedDecl(MD);
186 if (Record[Idx++]) {
187 // In practice, this won't be executed (since method definitions
188 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000189 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000190 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
191 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
192 }
193 MD->setInstanceMethod(Record[Idx++]);
194 MD->setVariadic(Record[Idx++]);
195 MD->setSynthesized(Record[Idx++]);
196 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
197 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
198 MD->setResultType(Reader.GetType(Record[Idx++]));
199 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
200 unsigned NumParams = Record[Idx++];
201 llvm::SmallVector<ParmVarDecl *, 16> Params;
202 Params.reserve(NumParams);
203 for (unsigned I = 0; I != NumParams; ++I)
204 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000205 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000206}
207
208void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
209 VisitNamedDecl(CD);
210 CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
211}
212
213void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
214 VisitObjCContainerDecl(ID);
215 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
216 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
217 (Reader.GetDecl(Record[Idx++])));
218 unsigned NumProtocols = Record[Idx++];
219 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
220 Protocols.reserve(NumProtocols);
221 for (unsigned I = 0; I != NumProtocols; ++I)
222 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000223 ID->setProtocolList(Protocols.data(), NumProtocols, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000224 unsigned NumIvars = Record[Idx++];
225 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
226 IVars.reserve(NumIvars);
227 for (unsigned I = 0; I != NumIvars; ++I)
228 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000229 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000230 ID->setCategoryList(
231 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
232 ID->setForwardDecl(Record[Idx++]);
233 ID->setImplicitInterfaceDecl(Record[Idx++]);
234 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
235 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000236 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000237}
238
239void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
240 VisitFieldDecl(IVD);
241 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
242}
243
244void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
245 VisitObjCContainerDecl(PD);
246 PD->setForwardDecl(Record[Idx++]);
247 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
248 unsigned NumProtoRefs = Record[Idx++];
249 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
250 ProtoRefs.reserve(NumProtoRefs);
251 for (unsigned I = 0; I != NumProtoRefs; ++I)
252 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000253 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000254}
255
256void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
257 VisitFieldDecl(FD);
258}
259
260void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
261 VisitDecl(CD);
262 unsigned NumClassRefs = Record[Idx++];
263 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
264 ClassRefs.reserve(NumClassRefs);
265 for (unsigned I = 0; I != NumClassRefs; ++I)
266 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000267 CD->setClassList(*Reader.getContext(), ClassRefs.data(), NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000268}
269
270void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
271 VisitDecl(FPD);
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 Gregor75fdb232009-05-22 22:45:36 +0000277 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000278}
279
280void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
281 VisitObjCContainerDecl(CD);
282 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
283 unsigned NumProtoRefs = Record[Idx++];
284 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
285 ProtoRefs.reserve(NumProtoRefs);
286 for (unsigned I = 0; I != NumProtoRefs; ++I)
287 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek66ef1112009-05-22 22:34:23 +0000288 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000289 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
290 CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
291}
292
293void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
294 VisitNamedDecl(CAD);
295 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
296}
297
298void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
299 VisitNamedDecl(D);
300 D->setType(Reader.GetType(Record[Idx++]));
301 // FIXME: stable encoding
302 D->setPropertyAttributes(
303 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
304 // FIXME: stable encoding
305 D->setPropertyImplementation(
306 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
307 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
308 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
309 D->setGetterMethodDecl(
310 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
311 D->setSetterMethodDecl(
312 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
313 D->setPropertyIvarDecl(
314 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
315}
316
317void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000318 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000319 D->setClassInterface(
320 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000321}
322
323void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
324 VisitObjCImplDecl(D);
325 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
326}
327
328void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
329 VisitObjCImplDecl(D);
330 D->setSuperClass(
331 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
332}
333
334
335void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
336 VisitDecl(D);
337 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
338 D->setPropertyDecl(
339 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
340 D->setPropertyIvarDecl(
341 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
342}
343
344void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000345 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000346 FD->setMutable(Record[Idx++]);
347 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000348 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000349}
350
351void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000352 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000353 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
354 VD->setThreadSpecified(Record[Idx++]);
355 VD->setCXXDirectInitializer(Record[Idx++]);
356 VD->setDeclaredInCondition(Record[Idx++]);
357 VD->setPreviousDeclaration(
358 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000359 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000360 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000361}
362
363void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
364 VisitVarDecl(PD);
365}
366
367void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
368 VisitVarDecl(PD);
369 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000370}
371
Chris Lattner698f9252009-04-27 05:27:42 +0000372void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
373 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000374 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000375}
376
377void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
378 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000379 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000380 unsigned NumParams = Record[Idx++];
381 llvm::SmallVector<ParmVarDecl *, 16> Params;
382 Params.reserve(NumParams);
383 for (unsigned I = 0; I != NumParams; ++I)
384 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Mike Stump1eb44332009-09-09 15:08:12 +0000385 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000386}
387
Mike Stump1eb44332009-09-09 15:08:12 +0000388std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000389PCHDeclReader::VisitDeclContext(DeclContext *DC) {
390 uint64_t LexicalOffset = Record[Idx++];
391 uint64_t VisibleOffset = Record[Idx++];
392 return std::make_pair(LexicalOffset, VisibleOffset);
393}
394
395//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000396// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000397//===----------------------------------------------------------------------===//
398
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000399/// \brief Reads attributes from the current stream position.
400Attr *PCHReader::ReadAttributes() {
401 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000402 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000403 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000404
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000405 RecordData Record;
406 unsigned Idx = 0;
407 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000408 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000409 (void)RecCode;
410
411#define SIMPLE_ATTR(Name) \
412 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000413 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000414 break
415
416#define STRING_ATTR(Name) \
417 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000418 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000419 break
420
421#define UNSIGNED_ATTR(Name) \
422 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000423 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000424 break
425
426 Attr *Attrs = 0;
427 while (Idx < Record.size()) {
428 Attr *New = 0;
429 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
430 bool IsInherited = Record[Idx++];
431
432 switch (Kind) {
433 STRING_ATTR(Alias);
434 UNSIGNED_ATTR(Aligned);
435 SIMPLE_ATTR(AlwaysInline);
436 SIMPLE_ATTR(AnalyzerNoReturn);
437 STRING_ATTR(Annotate);
438 STRING_ATTR(AsmLabel);
Mike Stump1eb44332009-09-09 15:08:12 +0000439
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000440 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000441 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000442 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
443 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000444
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000445 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000446 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000447 cast<FunctionDecl>(GetDecl(Record[Idx++])));
448 break;
449
450 SIMPLE_ATTR(Const);
451 UNSIGNED_ATTR(Constructor);
452 SIMPLE_ATTR(DLLExport);
453 SIMPLE_ATTR(DLLImport);
454 SIMPLE_ATTR(Deprecated);
455 UNSIGNED_ATTR(Destructor);
456 SIMPLE_ATTR(FastCall);
Mike Stump1eb44332009-09-09 15:08:12 +0000457
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000458 case Attr::Format: {
459 std::string Type = ReadString(Record, Idx);
460 unsigned FormatIdx = Record[Idx++];
461 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000462 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000463 break;
464 }
Mike Stump1eb44332009-09-09 15:08:12 +0000465
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000466 case Attr::FormatArg: {
467 unsigned FormatIdx = Record[Idx++];
468 New = ::new (*Context) FormatArgAttr(FormatIdx);
469 break;
470 }
Mike Stump1eb44332009-09-09 15:08:12 +0000471
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000472 case Attr::Sentinel: {
473 int sentinel = Record[Idx++];
474 int nullPos = Record[Idx++];
475 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
476 break;
477 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000478
479 SIMPLE_ATTR(GNUInline);
Mike Stump1eb44332009-09-09 15:08:12 +0000480
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000481 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000482 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000483 break;
484
Ryan Flynn76168e22009-08-09 20:07:29 +0000485 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000486 SIMPLE_ATTR(NoDebug);
487 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000488 SIMPLE_ATTR(NoReturn);
489 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000490
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000491 case Attr::NonNull: {
492 unsigned Size = Record[Idx++];
493 llvm::SmallVector<unsigned, 16> ArgNums;
494 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
495 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000496 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000497 break;
498 }
Mike Stump1eb44332009-09-09 15:08:12 +0000499
Nate Begeman6f3d8382009-06-26 06:32:41 +0000500 case Attr::ReqdWorkGroupSize: {
501 unsigned X = Record[Idx++];
502 unsigned Y = Record[Idx++];
503 unsigned Z = Record[Idx++];
504 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
505 break;
506 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000507
508 SIMPLE_ATTR(ObjCException);
509 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000510 SIMPLE_ATTR(CFReturnsRetained);
511 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000512 SIMPLE_ATTR(Overloadable);
Anders Carlssona860e752009-08-08 18:23:56 +0000513 SIMPLE_ATTR(Packed);
514 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000515 SIMPLE_ATTR(Pure);
516 UNSIGNED_ATTR(Regparm);
517 STRING_ATTR(Section);
518 SIMPLE_ATTR(StdCall);
519 SIMPLE_ATTR(TransparentUnion);
520 SIMPLE_ATTR(Unavailable);
521 SIMPLE_ATTR(Unused);
522 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000523
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000524 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000525 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000526 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
527 break;
528
529 SIMPLE_ATTR(WarnUnusedResult);
530 SIMPLE_ATTR(Weak);
531 SIMPLE_ATTR(WeakImport);
532 }
533
534 assert(New && "Unable to decode attribute?");
535 New->setInherited(IsInherited);
536 New->setNext(Attrs);
537 Attrs = New;
538 }
539#undef UNSIGNED_ATTR
540#undef STRING_ATTR
541#undef SIMPLE_ATTR
542
543 // The list of attributes was built backwards. Reverse the list
544 // before returning it.
545 Attr *PrevAttr = 0, *NextAttr = 0;
546 while (Attrs) {
547 NextAttr = Attrs->getNext();
548 Attrs->setNext(PrevAttr);
549 PrevAttr = Attrs;
550 Attrs = NextAttr;
551 }
552
553 return PrevAttr;
554}
555
556//===----------------------------------------------------------------------===//
557// PCHReader Implementation
558//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000559
560/// \brief Note that we have loaded the declaration with the given
561/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000562///
Chris Lattner698f9252009-04-27 05:27:42 +0000563/// This routine notes that this declaration has already been loaded,
564/// so that future GetDecl calls will return this declaration rather
565/// than trying to load a new declaration.
566inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
567 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
568 DeclsLoaded[Index] = D;
569}
570
571
572/// \brief Determine whether the consumer will be interested in seeing
573/// this declaration (via HandleTopLevelDecl).
574///
575/// This routine should return true for anything that might affect
576/// code generation, e.g., inline function definitions, Objective-C
577/// declarations with metadata, etc.
578static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000579 if (isa<FileScopeAsmDecl>(D))
580 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000581 if (VarDecl *Var = dyn_cast<VarDecl>(D))
582 return Var->isFileVarDecl() && Var->getInit();
583 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
584 return Func->isThisDeclarationADefinition();
585 return isa<ObjCProtocolDecl>(D);
586}
587
588/// \brief Read the declaration at the given offset from the PCH file.
589Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
590 // Keep track of where we are in the stream, then jump back there
591 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000592 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000593
Douglas Gregord89275b2009-07-06 18:54:52 +0000594 // Note that we are loading a declaration record.
595 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Chris Lattnerda930612009-04-27 05:58:23 +0000597 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000598 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000599 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000600 unsigned Idx = 0;
601 PCHDeclReader Reader(*this, Record, Idx);
602
Chris Lattnerda930612009-04-27 05:58:23 +0000603 Decl *D = 0;
604 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000605 case pch::DECL_ATTR:
606 case pch::DECL_CONTEXT_LEXICAL:
607 case pch::DECL_CONTEXT_VISIBLE:
608 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
609 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000610 case pch::DECL_TRANSLATION_UNIT:
611 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000612 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000613 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000614 case pch::DECL_TYPEDEF:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000615 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000616 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000617 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000618 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000619 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000620 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000621 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000622 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000623 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000624 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000625 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000626 0, llvm::APSInt());
627 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000628 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000629 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000630 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000631 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000632 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000633 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000634 Selector(), QualType(), 0);
635 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000636 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000637 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000638 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000639 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000640 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000641 ObjCIvarDecl::None);
642 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000643 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000644 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000645 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000646 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000647 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000648 QualType(), 0);
649 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000650 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000651 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000652 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000653 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000654 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000655 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000656 case pch::DECL_OBJC_CATEGORY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000657 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000658 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000659 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000660 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000661 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000662 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000663 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000664 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000665 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000666 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000667 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000668 case pch::DECL_OBJC_PROPERTY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000669 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000670 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000671 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000672 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000673 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000674 ObjCPropertyImplDecl::Dynamic, 0);
675 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000676 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000677 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000678 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000679 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000680 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000681 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000682 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000683 break;
684
685 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000686 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000687 break;
688
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000689 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000690 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000691 VarDecl::None, 0);
692 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000693 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000694 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000695 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000696 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000697 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000698 break;
699 }
Chris Lattner698f9252009-04-27 05:27:42 +0000700
701 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000702 LoadedDecl(Index, D);
703 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000704
705 // If this declaration is also a declaration context, get the
706 // offsets for its tables of lexical and visible declarations.
707 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
708 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
709 if (Offsets.first || Offsets.second) {
710 DC->setHasExternalLexicalStorage(Offsets.first != 0);
711 DC->setHasExternalVisibleStorage(Offsets.second != 0);
712 DeclContextOffsets[DC] = Offsets;
713 }
714 }
715 assert(Idx == Record.size());
716
717 // If we have deserialized a declaration that has a definition the
718 // AST consumer might need to know about, notify the consumer
719 // about that definition now or queue it for later.
720 if (isConsumerInterestedIn(D)) {
721 if (Consumer) {
722 DeclGroupRef DG(D);
723 Consumer->HandleTopLevelDecl(DG);
724 } else {
725 InterestingDecls.push_back(D);
726 }
727 }
728
729 return D;
730}