blob: 9b28e8bac79c1142fea1d1e012edf4d6172d8d47 [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);
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 +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) \
Mike Stump1eb44332009-09-09 15:08:12 +0000166 void Visit##CLASS(CLASS TyLoc);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000167#include "clang/AST/TypeLocNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000169 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}
Argyrios Kyrtzidiseb667592009-09-29 19:45:22 +0000182void TypeLocReader::VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) {
183 TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
184}
Argyrios Kyrtzidisf352bdd2009-09-29 19:43:35 +0000185void TypeLocReader::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) {
186 TyLoc.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
187 TyLoc.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
188 for (unsigned i = 0, e = TyLoc.getNumProtocols(); i != e; ++i)
189 TyLoc.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++]));
190}
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000191void TypeLocReader::VisitPointerLoc(PointerLoc TyLoc) {
192 TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
193}
194void TypeLocReader::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
195 TyLoc.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
196}
197void TypeLocReader::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
198 TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
199}
200void TypeLocReader::VisitReferenceLoc(ReferenceLoc TyLoc) {
201 TyLoc.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
202}
203void TypeLocReader::VisitFunctionLoc(FunctionLoc TyLoc) {
204 TyLoc.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
205 TyLoc.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
206 for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
207 TyLoc.setArg(i, cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
208}
209void TypeLocReader::VisitArrayLoc(ArrayLoc TyLoc) {
210 TyLoc.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
211 TyLoc.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
212 if (Record[Idx++])
213 TyLoc.setSizeExpr(Reader.ReadDeclExpr());
214}
215
216void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
217 VisitValueDecl(DD);
218 QualType InfoTy = Reader.GetType(Record[Idx++]);
219 if (InfoTy.isNull())
220 return;
221
222 DeclaratorInfo *DInfo = Reader.getContext()->CreateDeclaratorInfo(InfoTy);
223 TypeLocReader TLR(Reader, Record, Idx);
224 for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
225 TLR.Visit(TL);
226 DD->setDeclaratorInfo(DInfo);
227}
228
Chris Lattner698f9252009-04-27 05:27:42 +0000229void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000230 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000231 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000232 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000233 FD->setPreviousDeclaration(
234 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
235 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
236 FD->setInline(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000237 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000238 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000239 FD->setHasInheritedPrototype(Record[Idx++]);
240 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000241 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000242 FD->setTrivial(Record[Idx++]);
243 FD->setCopyAssignment(Record[Idx++]);
244 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000245 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000246 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000247 unsigned NumParams = Record[Idx++];
248 llvm::SmallVector<ParmVarDecl *, 16> Params;
249 Params.reserve(NumParams);
250 for (unsigned I = 0; I != NumParams; ++I)
251 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000252 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000253}
254
255void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
256 VisitNamedDecl(MD);
257 if (Record[Idx++]) {
258 // In practice, this won't be executed (since method definitions
259 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000260 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000261 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
262 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
263 }
264 MD->setInstanceMethod(Record[Idx++]);
265 MD->setVariadic(Record[Idx++]);
266 MD->setSynthesized(Record[Idx++]);
267 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
268 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
269 MD->setResultType(Reader.GetType(Record[Idx++]));
270 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
271 unsigned NumParams = Record[Idx++];
272 llvm::SmallVector<ParmVarDecl *, 16> Params;
273 Params.reserve(NumParams);
274 for (unsigned I = 0; I != NumParams; ++I)
275 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000276 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000277}
278
279void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
280 VisitNamedDecl(CD);
281 CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
282}
283
284void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
285 VisitObjCContainerDecl(ID);
286 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
287 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
288 (Reader.GetDecl(Record[Idx++])));
289 unsigned NumProtocols = Record[Idx++];
290 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
291 Protocols.reserve(NumProtocols);
292 for (unsigned I = 0; I != NumProtocols; ++I)
293 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000294 ID->setProtocolList(Protocols.data(), NumProtocols, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000295 unsigned NumIvars = Record[Idx++];
296 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
297 IVars.reserve(NumIvars);
298 for (unsigned I = 0; I != NumIvars; ++I)
299 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000300 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000301 ID->setCategoryList(
302 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
303 ID->setForwardDecl(Record[Idx++]);
304 ID->setImplicitInterfaceDecl(Record[Idx++]);
305 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
306 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000307 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000308}
309
310void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
311 VisitFieldDecl(IVD);
312 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
313}
314
315void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
316 VisitObjCContainerDecl(PD);
317 PD->setForwardDecl(Record[Idx++]);
318 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
319 unsigned NumProtoRefs = Record[Idx++];
320 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
321 ProtoRefs.reserve(NumProtoRefs);
322 for (unsigned I = 0; I != NumProtoRefs; ++I)
323 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000324 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000325}
326
327void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
328 VisitFieldDecl(FD);
329}
330
331void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
332 VisitDecl(CD);
333 unsigned NumClassRefs = Record[Idx++];
334 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
335 ClassRefs.reserve(NumClassRefs);
336 for (unsigned I = 0; I != NumClassRefs; ++I)
337 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000338 CD->setClassList(*Reader.getContext(), ClassRefs.data(), NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000339}
340
341void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
342 VisitDecl(FPD);
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++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000348 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000349}
350
351void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
352 VisitObjCContainerDecl(CD);
353 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
354 unsigned NumProtoRefs = Record[Idx++];
355 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
356 ProtoRefs.reserve(NumProtoRefs);
357 for (unsigned I = 0; I != NumProtoRefs; ++I)
358 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek66ef1112009-05-22 22:34:23 +0000359 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000360 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
361 CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
362}
363
364void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
365 VisitNamedDecl(CAD);
366 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
367}
368
369void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
370 VisitNamedDecl(D);
371 D->setType(Reader.GetType(Record[Idx++]));
372 // FIXME: stable encoding
373 D->setPropertyAttributes(
374 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
375 // FIXME: stable encoding
376 D->setPropertyImplementation(
377 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
378 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
379 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
380 D->setGetterMethodDecl(
381 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
382 D->setSetterMethodDecl(
383 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
384 D->setPropertyIvarDecl(
385 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
386}
387
388void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000389 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000390 D->setClassInterface(
391 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000392}
393
394void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
395 VisitObjCImplDecl(D);
396 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
397}
398
399void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
400 VisitObjCImplDecl(D);
401 D->setSuperClass(
402 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
403}
404
405
406void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
407 VisitDecl(D);
408 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
409 D->setPropertyDecl(
410 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
411 D->setPropertyIvarDecl(
412 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
413}
414
415void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000416 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000417 FD->setMutable(Record[Idx++]);
418 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000419 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000420}
421
422void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000423 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000424 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
425 VD->setThreadSpecified(Record[Idx++]);
426 VD->setCXXDirectInitializer(Record[Idx++]);
427 VD->setDeclaredInCondition(Record[Idx++]);
428 VD->setPreviousDeclaration(
429 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000430 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000431 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000432}
433
434void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
435 VisitVarDecl(PD);
436}
437
438void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
439 VisitVarDecl(PD);
440 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000441}
442
443void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
444 VisitParmVarDecl(PD);
445 PD->setOriginalType(Reader.GetType(Record[Idx++]));
446}
447
448void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
449 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000450 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000451}
452
453void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
454 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000455 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000456 unsigned NumParams = Record[Idx++];
457 llvm::SmallVector<ParmVarDecl *, 16> Params;
458 Params.reserve(NumParams);
459 for (unsigned I = 0; I != NumParams; ++I)
460 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Mike Stump1eb44332009-09-09 15:08:12 +0000461 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000462}
463
Mike Stump1eb44332009-09-09 15:08:12 +0000464std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000465PCHDeclReader::VisitDeclContext(DeclContext *DC) {
466 uint64_t LexicalOffset = Record[Idx++];
467 uint64_t VisibleOffset = Record[Idx++];
468 return std::make_pair(LexicalOffset, VisibleOffset);
469}
470
471//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000472// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000473//===----------------------------------------------------------------------===//
474
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000475/// \brief Reads attributes from the current stream position.
476Attr *PCHReader::ReadAttributes() {
477 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000478 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000479 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000480
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000481 RecordData Record;
482 unsigned Idx = 0;
483 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000484 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000485 (void)RecCode;
486
487#define SIMPLE_ATTR(Name) \
488 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000489 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000490 break
491
492#define STRING_ATTR(Name) \
493 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000494 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000495 break
496
497#define UNSIGNED_ATTR(Name) \
498 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000499 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000500 break
501
502 Attr *Attrs = 0;
503 while (Idx < Record.size()) {
504 Attr *New = 0;
505 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
506 bool IsInherited = Record[Idx++];
507
508 switch (Kind) {
509 STRING_ATTR(Alias);
510 UNSIGNED_ATTR(Aligned);
511 SIMPLE_ATTR(AlwaysInline);
512 SIMPLE_ATTR(AnalyzerNoReturn);
513 STRING_ATTR(Annotate);
514 STRING_ATTR(AsmLabel);
Mike Stump1eb44332009-09-09 15:08:12 +0000515
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000516 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000517 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000518 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
519 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000520
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000521 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000522 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000523 cast<FunctionDecl>(GetDecl(Record[Idx++])));
524 break;
525
526 SIMPLE_ATTR(Const);
527 UNSIGNED_ATTR(Constructor);
528 SIMPLE_ATTR(DLLExport);
529 SIMPLE_ATTR(DLLImport);
530 SIMPLE_ATTR(Deprecated);
531 UNSIGNED_ATTR(Destructor);
532 SIMPLE_ATTR(FastCall);
Mike Stump1eb44332009-09-09 15:08:12 +0000533
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000534 case Attr::Format: {
535 std::string Type = ReadString(Record, Idx);
536 unsigned FormatIdx = Record[Idx++];
537 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000538 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000539 break;
540 }
Mike Stump1eb44332009-09-09 15:08:12 +0000541
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000542 case Attr::FormatArg: {
543 unsigned FormatIdx = Record[Idx++];
544 New = ::new (*Context) FormatArgAttr(FormatIdx);
545 break;
546 }
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000548 case Attr::Sentinel: {
549 int sentinel = Record[Idx++];
550 int nullPos = Record[Idx++];
551 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
552 break;
553 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000554
555 SIMPLE_ATTR(GNUInline);
Mike Stump1eb44332009-09-09 15:08:12 +0000556
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000557 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000558 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000559 break;
560
Ryan Flynn76168e22009-08-09 20:07:29 +0000561 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000562 SIMPLE_ATTR(NoDebug);
563 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000564 SIMPLE_ATTR(NoReturn);
565 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000566
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000567 case Attr::NonNull: {
568 unsigned Size = Record[Idx++];
569 llvm::SmallVector<unsigned, 16> ArgNums;
570 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
571 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000572 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000573 break;
574 }
Mike Stump1eb44332009-09-09 15:08:12 +0000575
Nate Begeman6f3d8382009-06-26 06:32:41 +0000576 case Attr::ReqdWorkGroupSize: {
577 unsigned X = Record[Idx++];
578 unsigned Y = Record[Idx++];
579 unsigned Z = Record[Idx++];
580 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
581 break;
582 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000583
584 SIMPLE_ATTR(ObjCException);
585 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000586 SIMPLE_ATTR(CFReturnsRetained);
587 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000588 SIMPLE_ATTR(Overloadable);
Anders Carlssona860e752009-08-08 18:23:56 +0000589 SIMPLE_ATTR(Packed);
590 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000591 SIMPLE_ATTR(Pure);
592 UNSIGNED_ATTR(Regparm);
593 STRING_ATTR(Section);
594 SIMPLE_ATTR(StdCall);
595 SIMPLE_ATTR(TransparentUnion);
596 SIMPLE_ATTR(Unavailable);
597 SIMPLE_ATTR(Unused);
598 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000599
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000600 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000601 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000602 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
603 break;
604
605 SIMPLE_ATTR(WarnUnusedResult);
606 SIMPLE_ATTR(Weak);
607 SIMPLE_ATTR(WeakImport);
608 }
609
610 assert(New && "Unable to decode attribute?");
611 New->setInherited(IsInherited);
612 New->setNext(Attrs);
613 Attrs = New;
614 }
615#undef UNSIGNED_ATTR
616#undef STRING_ATTR
617#undef SIMPLE_ATTR
618
619 // The list of attributes was built backwards. Reverse the list
620 // before returning it.
621 Attr *PrevAttr = 0, *NextAttr = 0;
622 while (Attrs) {
623 NextAttr = Attrs->getNext();
624 Attrs->setNext(PrevAttr);
625 PrevAttr = Attrs;
626 Attrs = NextAttr;
627 }
628
629 return PrevAttr;
630}
631
632//===----------------------------------------------------------------------===//
633// PCHReader Implementation
634//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000635
636/// \brief Note that we have loaded the declaration with the given
637/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000638///
Chris Lattner698f9252009-04-27 05:27:42 +0000639/// This routine notes that this declaration has already been loaded,
640/// so that future GetDecl calls will return this declaration rather
641/// than trying to load a new declaration.
642inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
643 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
644 DeclsLoaded[Index] = D;
645}
646
647
648/// \brief Determine whether the consumer will be interested in seeing
649/// this declaration (via HandleTopLevelDecl).
650///
651/// This routine should return true for anything that might affect
652/// code generation, e.g., inline function definitions, Objective-C
653/// declarations with metadata, etc.
654static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000655 if (isa<FileScopeAsmDecl>(D))
656 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000657 if (VarDecl *Var = dyn_cast<VarDecl>(D))
658 return Var->isFileVarDecl() && Var->getInit();
659 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
660 return Func->isThisDeclarationADefinition();
661 return isa<ObjCProtocolDecl>(D);
662}
663
664/// \brief Read the declaration at the given offset from the PCH file.
665Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
666 // Keep track of where we are in the stream, then jump back there
667 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000668 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000669
Douglas Gregord89275b2009-07-06 18:54:52 +0000670 // Note that we are loading a declaration record.
671 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000672
Chris Lattnerda930612009-04-27 05:58:23 +0000673 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000674 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000675 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000676 unsigned Idx = 0;
677 PCHDeclReader Reader(*this, Record, Idx);
678
Chris Lattnerda930612009-04-27 05:58:23 +0000679 Decl *D = 0;
680 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000681 case pch::DECL_ATTR:
682 case pch::DECL_CONTEXT_LEXICAL:
683 case pch::DECL_CONTEXT_VISIBLE:
684 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
685 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000686 case pch::DECL_TRANSLATION_UNIT:
687 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000688 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000689 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000690 case pch::DECL_TYPEDEF:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000691 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000692 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000693 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000694 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000695 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000696 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000697 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000698 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000699 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000700 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000701 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000702 0, llvm::APSInt());
703 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000704 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000705 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000706 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000707 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000708 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000709 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000710 Selector(), QualType(), 0);
711 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000712 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000713 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000714 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000715 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000716 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000717 ObjCIvarDecl::None);
718 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000719 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000720 D = ObjCProtocolDecl::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_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000723 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000724 QualType(), 0);
725 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000726 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000727 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000728 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000729 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000730 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000731 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000732 case pch::DECL_OBJC_CATEGORY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000733 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000734 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000735 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000736 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000737 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000738 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000739 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000740 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000741 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000742 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000743 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000744 case pch::DECL_OBJC_PROPERTY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000745 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000746 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000747 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000748 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000749 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000750 ObjCPropertyImplDecl::Dynamic, 0);
751 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000752 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000753 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000754 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000755 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000756 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000757 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000758 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000759 break;
760
761 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000762 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000763 break;
764
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000765 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000766 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000767 VarDecl::None, 0);
768 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000769 case pch::DECL_ORIGINAL_PARM_VAR:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000770 D = OriginalParmVarDecl::Create(*Context, 0, SourceLocation(), 0,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000771 QualType(),0, QualType(), VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000772 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000773 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000774 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000775 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000776 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000777 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000778 break;
779 }
Chris Lattner698f9252009-04-27 05:27:42 +0000780
781 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000782 LoadedDecl(Index, D);
783 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000784
785 // If this declaration is also a declaration context, get the
786 // offsets for its tables of lexical and visible declarations.
787 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
788 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
789 if (Offsets.first || Offsets.second) {
790 DC->setHasExternalLexicalStorage(Offsets.first != 0);
791 DC->setHasExternalVisibleStorage(Offsets.second != 0);
792 DeclContextOffsets[DC] = Offsets;
793 }
794 }
795 assert(Idx == Record.size());
796
797 // If we have deserialized a declaration that has a definition the
798 // AST consumer might need to know about, notify the consumer
799 // about that definition now or queue it for later.
800 if (isConsumerInterestedIn(D)) {
801 if (Consumer) {
802 DeclGroupRef DG(D);
803 Consumer->HandleTopLevelDecl(DG);
804 } else {
805 InterestingDecls.push_back(D);
806 }
807 }
808
809 return D;
810}