blob: cc8712acd0920a73a718dc031b7ad5f0faddd48e [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"
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000021#include "clang/AST/TypeLoc.h"
Chris Lattner698f9252009-04-27 05:27:42 +000022using namespace clang;
23
Chris Lattner698f9252009-04-27 05:27:42 +000024
25//===----------------------------------------------------------------------===//
26// Declaration deserialization
27//===----------------------------------------------------------------------===//
28
29namespace {
30 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
31 PCHReader &Reader;
32 const PCHReader::RecordData &Record;
33 unsigned &Idx;
34
35 public:
36 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
37 unsigned &Idx)
38 : Reader(Reader), Record(Record), Idx(Idx) { }
39
40 void VisitDecl(Decl *D);
41 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
42 void VisitNamedDecl(NamedDecl *ND);
43 void VisitTypeDecl(TypeDecl *TD);
44 void VisitTypedefDecl(TypedefDecl *TD);
45 void VisitTagDecl(TagDecl *TD);
46 void VisitEnumDecl(EnumDecl *ED);
47 void VisitRecordDecl(RecordDecl *RD);
48 void VisitValueDecl(ValueDecl *VD);
49 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000050 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000051 void VisitFunctionDecl(FunctionDecl *FD);
52 void VisitFieldDecl(FieldDecl *FD);
53 void VisitVarDecl(VarDecl *VD);
54 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
55 void VisitParmVarDecl(ParmVarDecl *PD);
56 void VisitOriginalParmVarDecl(OriginalParmVarDecl *PD);
57 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
58 void VisitBlockDecl(BlockDecl *BD);
59 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
60 void VisitObjCMethodDecl(ObjCMethodDecl *D);
61 void VisitObjCContainerDecl(ObjCContainerDecl *D);
62 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
63 void VisitObjCIvarDecl(ObjCIvarDecl *D);
64 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
65 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
66 void VisitObjCClassDecl(ObjCClassDecl *D);
67 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
68 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
69 void VisitObjCImplDecl(ObjCImplDecl *D);
70 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
71 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
72 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
73 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
74 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
75 };
76}
77
78void PCHDeclReader::VisitDecl(Decl *D) {
79 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
80 D->setLexicalDeclContext(
81 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
82 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
83 D->setInvalidDecl(Record[Idx++]);
84 if (Record[Idx++])
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +000085 D->addAttr(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +000086 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +000087 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +000088 D->setAccess((AccessSpecifier)Record[Idx++]);
89}
90
91void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
92 VisitDecl(TU);
93}
94
95void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
96 VisitDecl(ND);
97 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
98}
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 +0000152namespace {
153
154class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
155 PCHReader &Reader;
156 const PCHReader::RecordData &Record;
157 unsigned &Idx;
158
159public:
160 TypeLocReader(PCHReader &Reader, const PCHReader::RecordData &Record,
161 unsigned &Idx)
162 : Reader(Reader), Record(Record), Idx(Idx) { }
163
164#define ABSTRACT_TYPELOC(CLASS)
165#define TYPELOC(CLASS, PARENT, TYPE) \
166 void Visit##CLASS(CLASS TyLoc);
167#include "clang/AST/TypeLocNodes.def"
168
169 void VisitTypeLoc(TypeLoc TyLoc) {
170 assert(0 && "A type loc wrapper was not handled!");
171 }
172};
173
174}
175
176void TypeLocReader::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) {
177 TyLoc.setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
178}
179void TypeLocReader::VisitTypedefLoc(TypedefLoc TyLoc) {
180 TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
181}
182void TypeLocReader::VisitPointerLoc(PointerLoc TyLoc) {
183 TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
184}
185void TypeLocReader::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
186 TyLoc.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
187}
188void TypeLocReader::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
189 TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
190}
191void TypeLocReader::VisitReferenceLoc(ReferenceLoc TyLoc) {
192 TyLoc.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
193}
194void TypeLocReader::VisitFunctionLoc(FunctionLoc TyLoc) {
195 TyLoc.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
196 TyLoc.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
197 for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
198 TyLoc.setArg(i, cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
199}
200void TypeLocReader::VisitArrayLoc(ArrayLoc TyLoc) {
201 TyLoc.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
202 TyLoc.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
203 if (Record[Idx++])
204 TyLoc.setSizeExpr(Reader.ReadDeclExpr());
205}
206
207void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
208 VisitValueDecl(DD);
209 QualType InfoTy = Reader.GetType(Record[Idx++]);
210 if (InfoTy.isNull())
211 return;
212
213 DeclaratorInfo *DInfo = Reader.getContext()->CreateDeclaratorInfo(InfoTy);
214 TypeLocReader TLR(Reader, Record, Idx);
215 for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
216 TLR.Visit(TL);
217 DD->setDeclaratorInfo(DInfo);
218}
219
Chris Lattner698f9252009-04-27 05:27:42 +0000220void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000221 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000222 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000223 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000224 FD->setPreviousDeclaration(
225 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
226 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
227 FD->setInline(Record[Idx++]);
228 FD->setC99InlineDefinition(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000229 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000230 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000231 FD->setHasInheritedPrototype(Record[Idx++]);
232 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000233 FD->setDeleted(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000234 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000235 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000236 unsigned NumParams = Record[Idx++];
237 llvm::SmallVector<ParmVarDecl *, 16> Params;
238 Params.reserve(NumParams);
239 for (unsigned I = 0; I != NumParams; ++I)
240 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000241 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000242}
243
244void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
245 VisitNamedDecl(MD);
246 if (Record[Idx++]) {
247 // In practice, this won't be executed (since method definitions
248 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000249 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000250 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
251 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
252 }
253 MD->setInstanceMethod(Record[Idx++]);
254 MD->setVariadic(Record[Idx++]);
255 MD->setSynthesized(Record[Idx++]);
256 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
257 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
258 MD->setResultType(Reader.GetType(Record[Idx++]));
259 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
260 unsigned NumParams = Record[Idx++];
261 llvm::SmallVector<ParmVarDecl *, 16> Params;
262 Params.reserve(NumParams);
263 for (unsigned I = 0; I != NumParams; ++I)
264 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000265 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000266}
267
268void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
269 VisitNamedDecl(CD);
270 CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
271}
272
273void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
274 VisitObjCContainerDecl(ID);
275 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
276 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
277 (Reader.GetDecl(Record[Idx++])));
278 unsigned NumProtocols = Record[Idx++];
279 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
280 Protocols.reserve(NumProtocols);
281 for (unsigned I = 0; I != NumProtocols; ++I)
282 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000283 ID->setProtocolList(Protocols.data(), NumProtocols, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000284 unsigned NumIvars = Record[Idx++];
285 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
286 IVars.reserve(NumIvars);
287 for (unsigned I = 0; I != NumIvars; ++I)
288 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000289 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000290 ID->setCategoryList(
291 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
292 ID->setForwardDecl(Record[Idx++]);
293 ID->setImplicitInterfaceDecl(Record[Idx++]);
294 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
295 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000296 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000297}
298
299void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
300 VisitFieldDecl(IVD);
301 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
302}
303
304void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
305 VisitObjCContainerDecl(PD);
306 PD->setForwardDecl(Record[Idx++]);
307 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
308 unsigned NumProtoRefs = Record[Idx++];
309 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
310 ProtoRefs.reserve(NumProtoRefs);
311 for (unsigned I = 0; I != NumProtoRefs; ++I)
312 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000313 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000314}
315
316void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
317 VisitFieldDecl(FD);
318}
319
320void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
321 VisitDecl(CD);
322 unsigned NumClassRefs = Record[Idx++];
323 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
324 ClassRefs.reserve(NumClassRefs);
325 for (unsigned I = 0; I != NumClassRefs; ++I)
326 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000327 CD->setClassList(*Reader.getContext(), ClassRefs.data(), NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000328}
329
330void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
331 VisitDecl(FPD);
332 unsigned NumProtoRefs = Record[Idx++];
333 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
334 ProtoRefs.reserve(NumProtoRefs);
335 for (unsigned I = 0; I != NumProtoRefs; ++I)
336 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000337 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000338}
339
340void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
341 VisitObjCContainerDecl(CD);
342 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
343 unsigned NumProtoRefs = Record[Idx++];
344 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
345 ProtoRefs.reserve(NumProtoRefs);
346 for (unsigned I = 0; I != NumProtoRefs; ++I)
347 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek66ef1112009-05-22 22:34:23 +0000348 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000349 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
350 CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
351}
352
353void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
354 VisitNamedDecl(CAD);
355 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
356}
357
358void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
359 VisitNamedDecl(D);
360 D->setType(Reader.GetType(Record[Idx++]));
361 // FIXME: stable encoding
362 D->setPropertyAttributes(
363 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
364 // FIXME: stable encoding
365 D->setPropertyImplementation(
366 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
367 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
368 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
369 D->setGetterMethodDecl(
370 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
371 D->setSetterMethodDecl(
372 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
373 D->setPropertyIvarDecl(
374 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
375}
376
377void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000378 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000379 D->setClassInterface(
380 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000381}
382
383void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
384 VisitObjCImplDecl(D);
385 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
386}
387
388void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
389 VisitObjCImplDecl(D);
390 D->setSuperClass(
391 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
392}
393
394
395void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
396 VisitDecl(D);
397 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
398 D->setPropertyDecl(
399 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
400 D->setPropertyIvarDecl(
401 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
402}
403
404void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000405 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000406 FD->setMutable(Record[Idx++]);
407 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000408 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000409}
410
411void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000412 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000413 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
414 VD->setThreadSpecified(Record[Idx++]);
415 VD->setCXXDirectInitializer(Record[Idx++]);
416 VD->setDeclaredInCondition(Record[Idx++]);
417 VD->setPreviousDeclaration(
418 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000419 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000420 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000421}
422
423void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
424 VisitVarDecl(PD);
425}
426
427void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
428 VisitVarDecl(PD);
429 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000430}
431
432void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
433 VisitParmVarDecl(PD);
434 PD->setOriginalType(Reader.GetType(Record[Idx++]));
435}
436
437void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
438 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000439 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000440}
441
442void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
443 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000444 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000445 unsigned NumParams = Record[Idx++];
446 llvm::SmallVector<ParmVarDecl *, 16> Params;
447 Params.reserve(NumParams);
448 for (unsigned I = 0; I != NumParams; ++I)
449 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000450 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000451}
452
453std::pair<uint64_t, uint64_t>
454PCHDeclReader::VisitDeclContext(DeclContext *DC) {
455 uint64_t LexicalOffset = Record[Idx++];
456 uint64_t VisibleOffset = Record[Idx++];
457 return std::make_pair(LexicalOffset, VisibleOffset);
458}
459
460//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000461// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000462//===----------------------------------------------------------------------===//
463
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000464/// \brief Reads attributes from the current stream position.
465Attr *PCHReader::ReadAttributes() {
466 unsigned Code = DeclsCursor.ReadCode();
467 assert(Code == llvm::bitc::UNABBREV_RECORD &&
468 "Expected unabbreviated record"); (void)Code;
469
470 RecordData Record;
471 unsigned Idx = 0;
472 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
473 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
474 (void)RecCode;
475
476#define SIMPLE_ATTR(Name) \
477 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000478 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000479 break
480
481#define STRING_ATTR(Name) \
482 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000483 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000484 break
485
486#define UNSIGNED_ATTR(Name) \
487 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000488 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000489 break
490
491 Attr *Attrs = 0;
492 while (Idx < Record.size()) {
493 Attr *New = 0;
494 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
495 bool IsInherited = Record[Idx++];
496
497 switch (Kind) {
498 STRING_ATTR(Alias);
499 UNSIGNED_ATTR(Aligned);
500 SIMPLE_ATTR(AlwaysInline);
501 SIMPLE_ATTR(AnalyzerNoReturn);
502 STRING_ATTR(Annotate);
503 STRING_ATTR(AsmLabel);
504
505 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000506 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000507 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
508 break;
509
510 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000511 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000512 cast<FunctionDecl>(GetDecl(Record[Idx++])));
513 break;
514
515 SIMPLE_ATTR(Const);
516 UNSIGNED_ATTR(Constructor);
517 SIMPLE_ATTR(DLLExport);
518 SIMPLE_ATTR(DLLImport);
519 SIMPLE_ATTR(Deprecated);
520 UNSIGNED_ATTR(Destructor);
521 SIMPLE_ATTR(FastCall);
522
523 case Attr::Format: {
524 std::string Type = ReadString(Record, Idx);
525 unsigned FormatIdx = Record[Idx++];
526 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000527 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000528 break;
529 }
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000530
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000531 case Attr::FormatArg: {
532 unsigned FormatIdx = Record[Idx++];
533 New = ::new (*Context) FormatArgAttr(FormatIdx);
534 break;
535 }
536
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000537 case Attr::Sentinel: {
538 int sentinel = Record[Idx++];
539 int nullPos = Record[Idx++];
540 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
541 break;
542 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000543
544 SIMPLE_ATTR(GNUInline);
545
546 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000547 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000548 break;
549
Ryan Flynn76168e22009-08-09 20:07:29 +0000550 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000551 SIMPLE_ATTR(NoDebug);
552 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000553 SIMPLE_ATTR(NoReturn);
554 SIMPLE_ATTR(NoThrow);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000555
556 case Attr::NonNull: {
557 unsigned Size = Record[Idx++];
558 llvm::SmallVector<unsigned, 16> ArgNums;
559 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
560 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000561 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000562 break;
563 }
Nate Begeman6f3d8382009-06-26 06:32:41 +0000564
565 case Attr::ReqdWorkGroupSize: {
566 unsigned X = Record[Idx++];
567 unsigned Y = Record[Idx++];
568 unsigned Z = Record[Idx++];
569 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
570 break;
571 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000572
573 SIMPLE_ATTR(ObjCException);
574 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000575 SIMPLE_ATTR(CFReturnsRetained);
576 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000577 SIMPLE_ATTR(Overloadable);
Anders Carlssona860e752009-08-08 18:23:56 +0000578 SIMPLE_ATTR(Packed);
579 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000580 SIMPLE_ATTR(Pure);
581 UNSIGNED_ATTR(Regparm);
582 STRING_ATTR(Section);
583 SIMPLE_ATTR(StdCall);
584 SIMPLE_ATTR(TransparentUnion);
585 SIMPLE_ATTR(Unavailable);
586 SIMPLE_ATTR(Unused);
587 SIMPLE_ATTR(Used);
588
589 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000590 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000591 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
592 break;
593
594 SIMPLE_ATTR(WarnUnusedResult);
595 SIMPLE_ATTR(Weak);
596 SIMPLE_ATTR(WeakImport);
597 }
598
599 assert(New && "Unable to decode attribute?");
600 New->setInherited(IsInherited);
601 New->setNext(Attrs);
602 Attrs = New;
603 }
604#undef UNSIGNED_ATTR
605#undef STRING_ATTR
606#undef SIMPLE_ATTR
607
608 // The list of attributes was built backwards. Reverse the list
609 // before returning it.
610 Attr *PrevAttr = 0, *NextAttr = 0;
611 while (Attrs) {
612 NextAttr = Attrs->getNext();
613 Attrs->setNext(PrevAttr);
614 PrevAttr = Attrs;
615 Attrs = NextAttr;
616 }
617
618 return PrevAttr;
619}
620
621//===----------------------------------------------------------------------===//
622// PCHReader Implementation
623//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000624
625/// \brief Note that we have loaded the declaration with the given
626/// Index.
627///
628/// This routine notes that this declaration has already been loaded,
629/// so that future GetDecl calls will return this declaration rather
630/// than trying to load a new declaration.
631inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
632 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
633 DeclsLoaded[Index] = D;
634}
635
636
637/// \brief Determine whether the consumer will be interested in seeing
638/// this declaration (via HandleTopLevelDecl).
639///
640/// This routine should return true for anything that might affect
641/// code generation, e.g., inline function definitions, Objective-C
642/// declarations with metadata, etc.
643static bool isConsumerInterestedIn(Decl *D) {
644 if (VarDecl *Var = dyn_cast<VarDecl>(D))
645 return Var->isFileVarDecl() && Var->getInit();
646 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
647 return Func->isThisDeclarationADefinition();
648 return isa<ObjCProtocolDecl>(D);
649}
650
651/// \brief Read the declaration at the given offset from the PCH file.
652Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
653 // Keep track of where we are in the stream, then jump back there
654 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000655 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000656
Douglas Gregord89275b2009-07-06 18:54:52 +0000657 // Note that we are loading a declaration record.
658 LoadingTypeOrDecl Loading(*this);
659
Chris Lattnerda930612009-04-27 05:58:23 +0000660 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000661 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000662 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000663 unsigned Idx = 0;
664 PCHDeclReader Reader(*this, Record, Idx);
665
Chris Lattnerda930612009-04-27 05:58:23 +0000666 Decl *D = 0;
667 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000668 case pch::DECL_ATTR:
669 case pch::DECL_CONTEXT_LEXICAL:
670 case pch::DECL_CONTEXT_VISIBLE:
671 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
672 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000673 case pch::DECL_TRANSLATION_UNIT:
674 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000675 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000676 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000677 case pch::DECL_TYPEDEF:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000678 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000679 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000680 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000681 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000682 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000683 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000684 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000685 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000686 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000687 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000688 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000689 0, llvm::APSInt());
690 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000691 case pch::DECL_FUNCTION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000692 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000693 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000694 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000695 case pch::DECL_OBJC_METHOD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000696 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000697 Selector(), QualType(), 0);
698 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000699 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000700 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000701 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000702 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000703 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000704 ObjCIvarDecl::None);
705 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000706 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000707 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000708 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000709 case pch::DECL_OBJC_AT_DEFS_FIELD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000710 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000711 QualType(), 0);
712 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000713 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000714 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000715 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000716 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000717 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000718 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000719 case pch::DECL_OBJC_CATEGORY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000720 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000721 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000722 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000723 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000724 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000725 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000726 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000727 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000728 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000729 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000730 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000731 case pch::DECL_OBJC_PROPERTY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000732 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000733 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000734 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000735 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000736 SourceLocation(), 0,
737 ObjCPropertyImplDecl::Dynamic, 0);
738 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000739 case pch::DECL_FIELD:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000740 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000741 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000742 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000743 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000744 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000745 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000746 break;
747
748 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000749 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000750 break;
751
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000752 case pch::DECL_PARM_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000753 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000754 VarDecl::None, 0);
755 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000756 case pch::DECL_ORIGINAL_PARM_VAR:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000757 D = OriginalParmVarDecl::Create(*Context, 0, SourceLocation(), 0,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000758 QualType(),0, QualType(), VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000759 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000760 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000761 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000762 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000763 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000764 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000765 break;
766 }
Chris Lattner698f9252009-04-27 05:27:42 +0000767
768 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000769 LoadedDecl(Index, D);
770 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000771
772 // If this declaration is also a declaration context, get the
773 // offsets for its tables of lexical and visible declarations.
774 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
775 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
776 if (Offsets.first || Offsets.second) {
777 DC->setHasExternalLexicalStorage(Offsets.first != 0);
778 DC->setHasExternalVisibleStorage(Offsets.second != 0);
779 DeclContextOffsets[DC] = Offsets;
780 }
781 }
782 assert(Idx == Record.size());
783
784 // If we have deserialized a declaration that has a definition the
785 // AST consumer might need to know about, notify the consumer
786 // about that definition now or queue it for later.
787 if (isConsumerInterestedIn(D)) {
788 if (Consumer) {
789 DeclGroupRef DG(D);
790 Consumer->HandleTopLevelDecl(DG);
791 } else {
792 InterestingDecls.push_back(D);
793 }
794 }
795
796 return D;
797}
798