blob: d1cb461640b761033393787bc83f5855b0eba19d [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);
55 void VisitOriginalParmVarDecl(OriginalParmVarDecl *PD);
56 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
100void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
101 VisitNamedDecl(TD);
102 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
103}
104
105void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
106 // Note that we cannot use VisitTypeDecl here, because we need to
107 // set the underlying type of the typedef *before* we try to read
108 // the type associated with the TypedefDecl.
109 VisitNamedDecl(TD);
110 TD->setUnderlyingType(Reader.GetType(Record[Idx + 1]));
111 TD->setTypeForDecl(Reader.GetType(Record[Idx]).getTypePtr());
112 Idx += 2;
113}
114
115void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
116 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000117 TD->setPreviousDeclaration(
118 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000119 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
120 TD->setDefinition(Record[Idx++]);
121 TD->setTypedefForAnonDecl(
122 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000123 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000124 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000125}
126
127void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
128 VisitTagDecl(ED);
129 ED->setIntegerType(Reader.GetType(Record[Idx++]));
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000130 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-04-27 05:27:42 +0000131}
132
133void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
134 VisitTagDecl(RD);
135 RD->setHasFlexibleArrayMember(Record[Idx++]);
136 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000137 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000138}
139
140void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
141 VisitNamedDecl(VD);
142 VD->setType(Reader.GetType(Record[Idx++]));
143}
144
145void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
146 VisitValueDecl(ECD);
147 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000148 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000149 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
150}
151
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000152void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
153 VisitValueDecl(DD);
John McCalla1ee0c52009-10-16 21:56:05 +0000154 DeclaratorInfo *DInfo = Reader.GetDeclaratorInfo(Record, Idx);
155 if (DInfo)
156 DD->setDeclaratorInfo(DInfo);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000157}
158
Chris Lattner698f9252009-04-27 05:27:42 +0000159void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000160 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000161 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000162 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000163 FD->setPreviousDeclaration(
164 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
165 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
166 FD->setInline(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000167 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000168 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000169 FD->setHasInheritedPrototype(Record[Idx++]);
170 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000171 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000172 FD->setTrivial(Record[Idx++]);
173 FD->setCopyAssignment(Record[Idx++]);
174 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000175 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000176 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000177 unsigned NumParams = Record[Idx++];
178 llvm::SmallVector<ParmVarDecl *, 16> Params;
179 Params.reserve(NumParams);
180 for (unsigned I = 0; I != NumParams; ++I)
181 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000182 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000183}
184
185void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
186 VisitNamedDecl(MD);
187 if (Record[Idx++]) {
188 // In practice, this won't be executed (since method definitions
189 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000190 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000191 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
192 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
193 }
194 MD->setInstanceMethod(Record[Idx++]);
195 MD->setVariadic(Record[Idx++]);
196 MD->setSynthesized(Record[Idx++]);
197 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
198 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
199 MD->setResultType(Reader.GetType(Record[Idx++]));
200 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
201 unsigned NumParams = Record[Idx++];
202 llvm::SmallVector<ParmVarDecl *, 16> Params;
203 Params.reserve(NumParams);
204 for (unsigned I = 0; I != NumParams; ++I)
205 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000206 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000207}
208
209void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
210 VisitNamedDecl(CD);
211 CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
212}
213
214void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
215 VisitObjCContainerDecl(ID);
216 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
217 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
218 (Reader.GetDecl(Record[Idx++])));
219 unsigned NumProtocols = Record[Idx++];
220 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
221 Protocols.reserve(NumProtocols);
222 for (unsigned I = 0; I != NumProtocols; ++I)
223 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000224 ID->setProtocolList(Protocols.data(), NumProtocols, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000225 unsigned NumIvars = Record[Idx++];
226 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
227 IVars.reserve(NumIvars);
228 for (unsigned I = 0; I != NumIvars; ++I)
229 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000230 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000231 ID->setCategoryList(
232 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
233 ID->setForwardDecl(Record[Idx++]);
234 ID->setImplicitInterfaceDecl(Record[Idx++]);
235 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
236 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000237 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000238}
239
240void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
241 VisitFieldDecl(IVD);
242 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
243}
244
245void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
246 VisitObjCContainerDecl(PD);
247 PD->setForwardDecl(Record[Idx++]);
248 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
249 unsigned NumProtoRefs = Record[Idx++];
250 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
251 ProtoRefs.reserve(NumProtoRefs);
252 for (unsigned I = 0; I != NumProtoRefs; ++I)
253 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000254 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000255}
256
257void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
258 VisitFieldDecl(FD);
259}
260
261void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
262 VisitDecl(CD);
263 unsigned NumClassRefs = Record[Idx++];
264 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
265 ClassRefs.reserve(NumClassRefs);
266 for (unsigned I = 0; I != NumClassRefs; ++I)
267 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000268 CD->setClassList(*Reader.getContext(), ClassRefs.data(), NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000269}
270
271void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
272 VisitDecl(FPD);
273 unsigned NumProtoRefs = Record[Idx++];
274 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
275 ProtoRefs.reserve(NumProtoRefs);
276 for (unsigned I = 0; I != NumProtoRefs; ++I)
277 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000278 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000279}
280
281void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
282 VisitObjCContainerDecl(CD);
283 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
284 unsigned NumProtoRefs = Record[Idx++];
285 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
286 ProtoRefs.reserve(NumProtoRefs);
287 for (unsigned I = 0; I != NumProtoRefs; ++I)
288 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek66ef1112009-05-22 22:34:23 +0000289 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000290 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
291 CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
292}
293
294void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
295 VisitNamedDecl(CAD);
296 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
297}
298
299void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
300 VisitNamedDecl(D);
301 D->setType(Reader.GetType(Record[Idx++]));
302 // FIXME: stable encoding
303 D->setPropertyAttributes(
304 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
305 // FIXME: stable encoding
306 D->setPropertyImplementation(
307 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
308 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
309 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
310 D->setGetterMethodDecl(
311 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
312 D->setSetterMethodDecl(
313 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
314 D->setPropertyIvarDecl(
315 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
316}
317
318void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000319 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000320 D->setClassInterface(
321 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000322}
323
324void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
325 VisitObjCImplDecl(D);
326 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
327}
328
329void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
330 VisitObjCImplDecl(D);
331 D->setSuperClass(
332 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
333}
334
335
336void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
337 VisitDecl(D);
338 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
339 D->setPropertyDecl(
340 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
341 D->setPropertyIvarDecl(
342 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
343}
344
345void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000346 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000347 FD->setMutable(Record[Idx++]);
348 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000349 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000350}
351
352void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000353 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000354 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
355 VD->setThreadSpecified(Record[Idx++]);
356 VD->setCXXDirectInitializer(Record[Idx++]);
357 VD->setDeclaredInCondition(Record[Idx++]);
358 VD->setPreviousDeclaration(
359 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000360 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000361 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000362}
363
364void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
365 VisitVarDecl(PD);
366}
367
368void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
369 VisitVarDecl(PD);
370 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000371}
372
373void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
374 VisitParmVarDecl(PD);
375 PD->setOriginalType(Reader.GetType(Record[Idx++]));
376}
377
378void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
379 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000380 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000381}
382
383void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
384 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000385 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000386 unsigned NumParams = Record[Idx++];
387 llvm::SmallVector<ParmVarDecl *, 16> Params;
388 Params.reserve(NumParams);
389 for (unsigned I = 0; I != NumParams; ++I)
390 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Mike Stump1eb44332009-09-09 15:08:12 +0000391 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000392}
393
Mike Stump1eb44332009-09-09 15:08:12 +0000394std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000395PCHDeclReader::VisitDeclContext(DeclContext *DC) {
396 uint64_t LexicalOffset = Record[Idx++];
397 uint64_t VisibleOffset = Record[Idx++];
398 return std::make_pair(LexicalOffset, VisibleOffset);
399}
400
401//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000402// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000403//===----------------------------------------------------------------------===//
404
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000405/// \brief Reads attributes from the current stream position.
406Attr *PCHReader::ReadAttributes() {
407 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000408 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000409 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000410
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000411 RecordData Record;
412 unsigned Idx = 0;
413 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000414 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000415 (void)RecCode;
416
417#define SIMPLE_ATTR(Name) \
418 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000419 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000420 break
421
422#define STRING_ATTR(Name) \
423 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000424 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000425 break
426
427#define UNSIGNED_ATTR(Name) \
428 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000429 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000430 break
431
432 Attr *Attrs = 0;
433 while (Idx < Record.size()) {
434 Attr *New = 0;
435 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
436 bool IsInherited = Record[Idx++];
437
438 switch (Kind) {
439 STRING_ATTR(Alias);
440 UNSIGNED_ATTR(Aligned);
441 SIMPLE_ATTR(AlwaysInline);
442 SIMPLE_ATTR(AnalyzerNoReturn);
443 STRING_ATTR(Annotate);
444 STRING_ATTR(AsmLabel);
Mike Stump1eb44332009-09-09 15:08:12 +0000445
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000446 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000447 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000448 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
449 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000451 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000452 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000453 cast<FunctionDecl>(GetDecl(Record[Idx++])));
454 break;
455
456 SIMPLE_ATTR(Const);
457 UNSIGNED_ATTR(Constructor);
458 SIMPLE_ATTR(DLLExport);
459 SIMPLE_ATTR(DLLImport);
460 SIMPLE_ATTR(Deprecated);
461 UNSIGNED_ATTR(Destructor);
462 SIMPLE_ATTR(FastCall);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000464 case Attr::Format: {
465 std::string Type = ReadString(Record, Idx);
466 unsigned FormatIdx = Record[Idx++];
467 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000468 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000469 break;
470 }
Mike Stump1eb44332009-09-09 15:08:12 +0000471
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000472 case Attr::FormatArg: {
473 unsigned FormatIdx = Record[Idx++];
474 New = ::new (*Context) FormatArgAttr(FormatIdx);
475 break;
476 }
Mike Stump1eb44332009-09-09 15:08:12 +0000477
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000478 case Attr::Sentinel: {
479 int sentinel = Record[Idx++];
480 int nullPos = Record[Idx++];
481 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
482 break;
483 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000484
485 SIMPLE_ATTR(GNUInline);
Mike Stump1eb44332009-09-09 15:08:12 +0000486
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000487 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000488 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000489 break;
490
Ryan Flynn76168e22009-08-09 20:07:29 +0000491 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000492 SIMPLE_ATTR(NoDebug);
493 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000494 SIMPLE_ATTR(NoReturn);
495 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000496
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000497 case Attr::NonNull: {
498 unsigned Size = Record[Idx++];
499 llvm::SmallVector<unsigned, 16> ArgNums;
500 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
501 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000502 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000503 break;
504 }
Mike Stump1eb44332009-09-09 15:08:12 +0000505
Nate Begeman6f3d8382009-06-26 06:32:41 +0000506 case Attr::ReqdWorkGroupSize: {
507 unsigned X = Record[Idx++];
508 unsigned Y = Record[Idx++];
509 unsigned Z = Record[Idx++];
510 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
511 break;
512 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000513
514 SIMPLE_ATTR(ObjCException);
515 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000516 SIMPLE_ATTR(CFReturnsRetained);
517 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000518 SIMPLE_ATTR(Overloadable);
Anders Carlssona860e752009-08-08 18:23:56 +0000519 SIMPLE_ATTR(Packed);
520 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000521 SIMPLE_ATTR(Pure);
522 UNSIGNED_ATTR(Regparm);
523 STRING_ATTR(Section);
524 SIMPLE_ATTR(StdCall);
525 SIMPLE_ATTR(TransparentUnion);
526 SIMPLE_ATTR(Unavailable);
527 SIMPLE_ATTR(Unused);
528 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000529
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000530 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000531 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000532 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
533 break;
534
535 SIMPLE_ATTR(WarnUnusedResult);
536 SIMPLE_ATTR(Weak);
537 SIMPLE_ATTR(WeakImport);
538 }
539
540 assert(New && "Unable to decode attribute?");
541 New->setInherited(IsInherited);
542 New->setNext(Attrs);
543 Attrs = New;
544 }
545#undef UNSIGNED_ATTR
546#undef STRING_ATTR
547#undef SIMPLE_ATTR
548
549 // The list of attributes was built backwards. Reverse the list
550 // before returning it.
551 Attr *PrevAttr = 0, *NextAttr = 0;
552 while (Attrs) {
553 NextAttr = Attrs->getNext();
554 Attrs->setNext(PrevAttr);
555 PrevAttr = Attrs;
556 Attrs = NextAttr;
557 }
558
559 return PrevAttr;
560}
561
562//===----------------------------------------------------------------------===//
563// PCHReader Implementation
564//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000565
566/// \brief Note that we have loaded the declaration with the given
567/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000568///
Chris Lattner698f9252009-04-27 05:27:42 +0000569/// This routine notes that this declaration has already been loaded,
570/// so that future GetDecl calls will return this declaration rather
571/// than trying to load a new declaration.
572inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
573 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
574 DeclsLoaded[Index] = D;
575}
576
577
578/// \brief Determine whether the consumer will be interested in seeing
579/// this declaration (via HandleTopLevelDecl).
580///
581/// This routine should return true for anything that might affect
582/// code generation, e.g., inline function definitions, Objective-C
583/// declarations with metadata, etc.
584static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000585 if (isa<FileScopeAsmDecl>(D))
586 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000587 if (VarDecl *Var = dyn_cast<VarDecl>(D))
588 return Var->isFileVarDecl() && Var->getInit();
589 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
590 return Func->isThisDeclarationADefinition();
591 return isa<ObjCProtocolDecl>(D);
592}
593
594/// \brief Read the declaration at the given offset from the PCH file.
595Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
596 // Keep track of where we are in the stream, then jump back there
597 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000598 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000599
Douglas Gregord89275b2009-07-06 18:54:52 +0000600 // Note that we are loading a declaration record.
601 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000602
Chris Lattnerda930612009-04-27 05:58:23 +0000603 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000604 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000605 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000606 unsigned Idx = 0;
607 PCHDeclReader Reader(*this, Record, Idx);
608
Chris Lattnerda930612009-04-27 05:58:23 +0000609 Decl *D = 0;
610 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000611 case pch::DECL_ATTR:
612 case pch::DECL_CONTEXT_LEXICAL:
613 case pch::DECL_CONTEXT_VISIBLE:
614 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
615 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000616 case pch::DECL_TRANSLATION_UNIT:
617 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000618 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000619 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000620 case pch::DECL_TYPEDEF:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000621 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000622 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000623 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000624 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000625 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000626 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000627 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000628 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000629 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000630 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000631 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000632 0, llvm::APSInt());
633 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000634 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000635 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000636 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000637 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000638 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000639 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000640 Selector(), QualType(), 0);
641 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000642 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000643 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000644 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000645 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000646 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000647 ObjCIvarDecl::None);
648 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000649 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000650 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000651 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000652 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000653 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000654 QualType(), 0);
655 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000656 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000657 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000658 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000659 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000660 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000661 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000662 case pch::DECL_OBJC_CATEGORY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000663 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000664 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000665 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000666 D = ObjCCategoryImplDecl::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_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000669 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000670 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000671 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000672 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000673 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000674 case pch::DECL_OBJC_PROPERTY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000675 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000676 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000677 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000678 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000679 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000680 ObjCPropertyImplDecl::Dynamic, 0);
681 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000682 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000683 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000684 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000685 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000686 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000687 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000688 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000689 break;
690
691 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000692 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000693 break;
694
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000695 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000696 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000697 VarDecl::None, 0);
698 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000699 case pch::DECL_ORIGINAL_PARM_VAR:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000700 D = OriginalParmVarDecl::Create(*Context, 0, SourceLocation(), 0,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000701 QualType(),0, QualType(), VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000702 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000703 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000704 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000705 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000706 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000707 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000708 break;
709 }
Chris Lattner698f9252009-04-27 05:27:42 +0000710
711 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000712 LoadedDecl(Index, D);
713 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000714
715 // If this declaration is also a declaration context, get the
716 // offsets for its tables of lexical and visible declarations.
717 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
718 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
719 if (Offsets.first || Offsets.second) {
720 DC->setHasExternalLexicalStorage(Offsets.first != 0);
721 DC->setHasExternalVisibleStorage(Offsets.second != 0);
722 DeclContextOffsets[DC] = Offsets;
723 }
724 }
725 assert(Idx == Record.size());
726
727 // If we have deserialized a declaration that has a definition the
728 // AST consumer might need to know about, notify the consumer
729 // about that definition now or queue it for later.
730 if (isConsumerInterestedIn(D)) {
731 if (Consumer) {
732 DeclGroupRef DG(D);
733 Consumer->HandleTopLevelDecl(DG);
734 } else {
735 InterestingDecls.push_back(D);
736 }
737 }
738
739 return D;
740}