blob: 6a92a2db51a8705d0ec937e6c72d6ca38e3aaa9d [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);
John McCallba6a9bd2009-10-24 08:00:42 +0000109 uint64_t TypeData = Record[Idx++];
110 TD->setTypeDeclaratorInfo(Reader.GetDeclaratorInfo(Record, Idx));
111 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000112}
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++]);
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000165 FD->setInlineSpecified(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++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000267 llvm::SmallVector<SourceLocation, 16> SLocs;
268 SLocs.reserve(NumClassRefs);
269 for (unsigned I = 0; I != NumClassRefs; ++I)
270 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
271 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
272 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000273}
274
275void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
276 VisitDecl(FPD);
277 unsigned NumProtoRefs = Record[Idx++];
278 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
279 ProtoRefs.reserve(NumProtoRefs);
280 for (unsigned I = 0; I != NumProtoRefs; ++I)
281 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000282 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000283}
284
285void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
286 VisitObjCContainerDecl(CD);
287 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
288 unsigned NumProtoRefs = Record[Idx++];
289 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
290 ProtoRefs.reserve(NumProtoRefs);
291 for (unsigned I = 0; I != NumProtoRefs; ++I)
292 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek66ef1112009-05-22 22:34:23 +0000293 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000294 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
295 CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
296}
297
298void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
299 VisitNamedDecl(CAD);
300 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
301}
302
303void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
304 VisitNamedDecl(D);
305 D->setType(Reader.GetType(Record[Idx++]));
306 // FIXME: stable encoding
307 D->setPropertyAttributes(
308 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
309 // FIXME: stable encoding
310 D->setPropertyImplementation(
311 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
312 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
313 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
314 D->setGetterMethodDecl(
315 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
316 D->setSetterMethodDecl(
317 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
318 D->setPropertyIvarDecl(
319 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
320}
321
322void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000323 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000324 D->setClassInterface(
325 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000326}
327
328void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
329 VisitObjCImplDecl(D);
330 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
331}
332
333void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
334 VisitObjCImplDecl(D);
335 D->setSuperClass(
336 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
337}
338
339
340void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
341 VisitDecl(D);
342 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
343 D->setPropertyDecl(
344 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
345 D->setPropertyIvarDecl(
346 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
347}
348
349void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000350 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000351 FD->setMutable(Record[Idx++]);
352 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000353 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000354}
355
356void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000357 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000358 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
359 VD->setThreadSpecified(Record[Idx++]);
360 VD->setCXXDirectInitializer(Record[Idx++]);
361 VD->setDeclaredInCondition(Record[Idx++]);
362 VD->setPreviousDeclaration(
363 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000364 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000365 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000366}
367
368void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
369 VisitVarDecl(PD);
370}
371
372void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
373 VisitVarDecl(PD);
374 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000375}
376
Chris Lattner698f9252009-04-27 05:27:42 +0000377void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
378 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000379 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000380}
381
382void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
383 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000384 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000385 unsigned NumParams = Record[Idx++];
386 llvm::SmallVector<ParmVarDecl *, 16> Params;
387 Params.reserve(NumParams);
388 for (unsigned I = 0; I != NumParams; ++I)
389 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Mike Stump1eb44332009-09-09 15:08:12 +0000390 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000391}
392
Mike Stump1eb44332009-09-09 15:08:12 +0000393std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000394PCHDeclReader::VisitDeclContext(DeclContext *DC) {
395 uint64_t LexicalOffset = Record[Idx++];
396 uint64_t VisibleOffset = Record[Idx++];
397 return std::make_pair(LexicalOffset, VisibleOffset);
398}
399
400//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000401// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000402//===----------------------------------------------------------------------===//
403
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000404/// \brief Reads attributes from the current stream position.
405Attr *PCHReader::ReadAttributes() {
406 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000407 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000408 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000409
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000410 RecordData Record;
411 unsigned Idx = 0;
412 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000413 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000414 (void)RecCode;
415
416#define SIMPLE_ATTR(Name) \
417 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000418 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000419 break
420
421#define STRING_ATTR(Name) \
422 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000423 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000424 break
425
426#define UNSIGNED_ATTR(Name) \
427 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000428 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000429 break
430
431 Attr *Attrs = 0;
432 while (Idx < Record.size()) {
433 Attr *New = 0;
434 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
435 bool IsInherited = Record[Idx++];
436
437 switch (Kind) {
438 STRING_ATTR(Alias);
439 UNSIGNED_ATTR(Aligned);
440 SIMPLE_ATTR(AlwaysInline);
441 SIMPLE_ATTR(AnalyzerNoReturn);
442 STRING_ATTR(Annotate);
443 STRING_ATTR(AsmLabel);
Mike Stump1eb44332009-09-09 15:08:12 +0000444
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000445 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000446 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000447 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
448 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000449
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000450 SIMPLE_ATTR(CDecl);
451
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000452 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000453 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000454 cast<FunctionDecl>(GetDecl(Record[Idx++])));
455 break;
456
457 SIMPLE_ATTR(Const);
458 UNSIGNED_ATTR(Constructor);
459 SIMPLE_ATTR(DLLExport);
460 SIMPLE_ATTR(DLLImport);
461 SIMPLE_ATTR(Deprecated);
462 UNSIGNED_ATTR(Destructor);
463 SIMPLE_ATTR(FastCall);
Mike Stump1eb44332009-09-09 15:08:12 +0000464
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000465 case Attr::Format: {
466 std::string Type = ReadString(Record, Idx);
467 unsigned FormatIdx = Record[Idx++];
468 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000469 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000470 break;
471 }
Mike Stump1eb44332009-09-09 15:08:12 +0000472
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000473 case Attr::FormatArg: {
474 unsigned FormatIdx = Record[Idx++];
475 New = ::new (*Context) FormatArgAttr(FormatIdx);
476 break;
477 }
Mike Stump1eb44332009-09-09 15:08:12 +0000478
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000479 case Attr::Sentinel: {
480 int sentinel = Record[Idx++];
481 int nullPos = Record[Idx++];
482 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
483 break;
484 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000485
486 SIMPLE_ATTR(GNUInline);
Mike Stump1eb44332009-09-09 15:08:12 +0000487
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000488 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000489 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000490 break;
491
Ryan Flynn76168e22009-08-09 20:07:29 +0000492 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000493 SIMPLE_ATTR(NoDebug);
494 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000495 SIMPLE_ATTR(NoReturn);
496 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000497
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000498 case Attr::NonNull: {
499 unsigned Size = Record[Idx++];
500 llvm::SmallVector<unsigned, 16> ArgNums;
501 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
502 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000503 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000504 break;
505 }
Mike Stump1eb44332009-09-09 15:08:12 +0000506
Nate Begeman6f3d8382009-06-26 06:32:41 +0000507 case Attr::ReqdWorkGroupSize: {
508 unsigned X = Record[Idx++];
509 unsigned Y = Record[Idx++];
510 unsigned Z = Record[Idx++];
511 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
512 break;
513 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000514
515 SIMPLE_ATTR(ObjCException);
516 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000517 SIMPLE_ATTR(CFReturnsRetained);
518 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000519 SIMPLE_ATTR(Overloadable);
Anders Carlssona860e752009-08-08 18:23:56 +0000520 SIMPLE_ATTR(Packed);
521 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000522 SIMPLE_ATTR(Pure);
523 UNSIGNED_ATTR(Regparm);
524 STRING_ATTR(Section);
525 SIMPLE_ATTR(StdCall);
526 SIMPLE_ATTR(TransparentUnion);
527 SIMPLE_ATTR(Unavailable);
528 SIMPLE_ATTR(Unused);
529 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000531 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000532 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000533 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
534 break;
535
536 SIMPLE_ATTR(WarnUnusedResult);
537 SIMPLE_ATTR(Weak);
538 SIMPLE_ATTR(WeakImport);
539 }
540
541 assert(New && "Unable to decode attribute?");
542 New->setInherited(IsInherited);
543 New->setNext(Attrs);
544 Attrs = New;
545 }
546#undef UNSIGNED_ATTR
547#undef STRING_ATTR
548#undef SIMPLE_ATTR
549
550 // The list of attributes was built backwards. Reverse the list
551 // before returning it.
552 Attr *PrevAttr = 0, *NextAttr = 0;
553 while (Attrs) {
554 NextAttr = Attrs->getNext();
555 Attrs->setNext(PrevAttr);
556 PrevAttr = Attrs;
557 Attrs = NextAttr;
558 }
559
560 return PrevAttr;
561}
562
563//===----------------------------------------------------------------------===//
564// PCHReader Implementation
565//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000566
567/// \brief Note that we have loaded the declaration with the given
568/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000569///
Chris Lattner698f9252009-04-27 05:27:42 +0000570/// This routine notes that this declaration has already been loaded,
571/// so that future GetDecl calls will return this declaration rather
572/// than trying to load a new declaration.
573inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
574 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
575 DeclsLoaded[Index] = D;
576}
577
578
579/// \brief Determine whether the consumer will be interested in seeing
580/// this declaration (via HandleTopLevelDecl).
581///
582/// This routine should return true for anything that might affect
583/// code generation, e.g., inline function definitions, Objective-C
584/// declarations with metadata, etc.
585static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000586 if (isa<FileScopeAsmDecl>(D))
587 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000588 if (VarDecl *Var = dyn_cast<VarDecl>(D))
589 return Var->isFileVarDecl() && Var->getInit();
590 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
591 return Func->isThisDeclarationADefinition();
592 return isa<ObjCProtocolDecl>(D);
593}
594
595/// \brief Read the declaration at the given offset from the PCH file.
596Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
597 // Keep track of where we are in the stream, then jump back there
598 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000599 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000600
Douglas Gregord89275b2009-07-06 18:54:52 +0000601 // Note that we are loading a declaration record.
602 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000603
Chris Lattnerda930612009-04-27 05:58:23 +0000604 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000605 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000606 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000607 unsigned Idx = 0;
608 PCHDeclReader Reader(*this, Record, Idx);
609
Chris Lattnerda930612009-04-27 05:58:23 +0000610 Decl *D = 0;
611 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000612 case pch::DECL_ATTR:
613 case pch::DECL_CONTEXT_LEXICAL:
614 case pch::DECL_CONTEXT_VISIBLE:
615 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
616 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000617 case pch::DECL_TRANSLATION_UNIT:
618 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000619 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000620 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000621 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +0000622 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000623 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000624 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000625 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000626 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000627 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000628 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000629 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000630 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000631 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000632 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000633 0, llvm::APSInt());
634 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000635 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000636 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000637 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000638 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000639 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000640 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000641 Selector(), QualType(), 0);
642 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000643 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000644 D = ObjCInterfaceDecl::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_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000647 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000648 ObjCIvarDecl::None);
649 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000650 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000651 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000652 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000653 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000654 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000655 QualType(), 0);
656 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000657 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000658 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000659 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000660 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000661 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000662 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000663 case pch::DECL_OBJC_CATEGORY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000664 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000665 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000666 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000667 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000668 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000669 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000670 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000671 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000672 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000673 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000674 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000675 case pch::DECL_OBJC_PROPERTY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000676 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000677 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000678 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000679 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000680 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000681 ObjCPropertyImplDecl::Dynamic, 0);
682 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000683 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000684 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000685 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000686 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000687 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000688 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000689 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000690 break;
691
692 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000693 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000694 break;
695
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000696 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000697 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000698 VarDecl::None, 0);
699 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000700 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000701 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000702 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000703 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000704 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000705 break;
706 }
Chris Lattner698f9252009-04-27 05:27:42 +0000707
708 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000709 LoadedDecl(Index, D);
710 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000711
712 // If this declaration is also a declaration context, get the
713 // offsets for its tables of lexical and visible declarations.
714 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
715 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
716 if (Offsets.first || Offsets.second) {
717 DC->setHasExternalLexicalStorage(Offsets.first != 0);
718 DC->setHasExternalVisibleStorage(Offsets.second != 0);
719 DeclContextOffsets[DC] = Offsets;
720 }
721 }
722 assert(Idx == Record.size());
723
724 // If we have deserialized a declaration that has a definition the
725 // AST consumer might need to know about, notify the consumer
726 // about that definition now or queue it for later.
727 if (isConsumerInterestedIn(D)) {
728 if (Consumer) {
729 DeclGroupRef DG(D);
730 Consumer->HandleTopLevelDecl(DG);
731 } else {
732 InterestingDecls.push_back(D);
733 }
734 }
735
736 return D;
737}