blob: ed6728233a96e86c6ac0d8a390836833d4e716f9 [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 Kyrtzidis0c411802009-09-29 21:27:32 +000021#include "clang/AST/TypeLocVisitor.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++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +000089 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +000090}
91
92void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
93 VisitDecl(TU);
94}
95
96void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
97 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +000098 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +000099}
100
101void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
102 VisitNamedDecl(TD);
103 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
104}
105
106void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
107 // Note that we cannot use VisitTypeDecl here, because we need to
108 // set the underlying type of the typedef *before* we try to read
109 // the type associated with the TypedefDecl.
110 VisitNamedDecl(TD);
111 TD->setUnderlyingType(Reader.GetType(Record[Idx + 1]));
112 TD->setTypeForDecl(Reader.GetType(Record[Idx]).getTypePtr());
113 Idx += 2;
114}
115
116void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
117 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000118 TD->setPreviousDeclaration(
119 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000120 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
121 TD->setDefinition(Record[Idx++]);
122 TD->setTypedefForAnonDecl(
123 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000124 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000125 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000126}
127
128void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
129 VisitTagDecl(ED);
130 ED->setIntegerType(Reader.GetType(Record[Idx++]));
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000131 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-04-27 05:27:42 +0000132}
133
134void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
135 VisitTagDecl(RD);
136 RD->setHasFlexibleArrayMember(Record[Idx++]);
137 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000138 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000139}
140
141void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
142 VisitNamedDecl(VD);
143 VD->setType(Reader.GetType(Record[Idx++]));
144}
145
146void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
147 VisitValueDecl(ECD);
148 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000149 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000150 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
151}
152
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000153namespace {
154
155class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
156 PCHReader &Reader;
157 const PCHReader::RecordData &Record;
158 unsigned &Idx;
159
160public:
161 TypeLocReader(PCHReader &Reader, const PCHReader::RecordData &Record,
162 unsigned &Idx)
163 : Reader(Reader), Record(Record), Idx(Idx) { }
164
165#define ABSTRACT_TYPELOC(CLASS)
John McCall34a04472009-10-15 03:50:32 +0000166#define TYPELOC(CLASS, PARENT) \
Mike Stump1eb44332009-09-09 15:08:12 +0000167 void Visit##CLASS(CLASS TyLoc);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000168#include "clang/AST/TypeLocNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000169
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000170 void VisitTypeLoc(TypeLoc TyLoc) {
171 assert(0 && "A type loc wrapper was not handled!");
172 }
173};
174
175}
176
John McCall34a04472009-10-15 03:50:32 +0000177void TypeLocReader::VisitQualifiedLoc(QualifiedLoc TyLoc) {
178 // nothing to do
179}
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000180void TypeLocReader::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) {
181 TyLoc.setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
182}
183void TypeLocReader::VisitTypedefLoc(TypedefLoc TyLoc) {
184 TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
185}
Argyrios Kyrtzidiseb667592009-09-29 19:45:22 +0000186void TypeLocReader::VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) {
187 TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
188}
Argyrios Kyrtzidisf352bdd2009-09-29 19:43:35 +0000189void TypeLocReader::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) {
190 TyLoc.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
191 TyLoc.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
192 for (unsigned i = 0, e = TyLoc.getNumProtocols(); i != e; ++i)
193 TyLoc.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++]));
194}
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000195void TypeLocReader::VisitPointerLoc(PointerLoc TyLoc) {
196 TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
197}
198void TypeLocReader::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
199 TyLoc.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
200}
201void TypeLocReader::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
202 TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
203}
204void TypeLocReader::VisitReferenceLoc(ReferenceLoc TyLoc) {
205 TyLoc.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
206}
207void TypeLocReader::VisitFunctionLoc(FunctionLoc TyLoc) {
208 TyLoc.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
209 TyLoc.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
210 for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
211 TyLoc.setArg(i, cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
212}
213void TypeLocReader::VisitArrayLoc(ArrayLoc TyLoc) {
214 TyLoc.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
215 TyLoc.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
216 if (Record[Idx++])
217 TyLoc.setSizeExpr(Reader.ReadDeclExpr());
218}
219
220void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
221 VisitValueDecl(DD);
222 QualType InfoTy = Reader.GetType(Record[Idx++]);
223 if (InfoTy.isNull())
224 return;
225
226 DeclaratorInfo *DInfo = Reader.getContext()->CreateDeclaratorInfo(InfoTy);
227 TypeLocReader TLR(Reader, Record, Idx);
228 for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
229 TLR.Visit(TL);
230 DD->setDeclaratorInfo(DInfo);
231}
232
Chris Lattner698f9252009-04-27 05:27:42 +0000233void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000234 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000235 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000236 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000237 FD->setPreviousDeclaration(
238 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
239 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
240 FD->setInline(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000241 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000242 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000243 FD->setHasInheritedPrototype(Record[Idx++]);
244 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000245 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000246 FD->setTrivial(Record[Idx++]);
247 FD->setCopyAssignment(Record[Idx++]);
248 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000249 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000250 // FIXME: C++ TemplateOrInstantiation
Chris Lattner698f9252009-04-27 05:27:42 +0000251 unsigned NumParams = Record[Idx++];
252 llvm::SmallVector<ParmVarDecl *, 16> Params;
253 Params.reserve(NumParams);
254 for (unsigned I = 0; I != NumParams; ++I)
255 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000256 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000257}
258
259void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
260 VisitNamedDecl(MD);
261 if (Record[Idx++]) {
262 // In practice, this won't be executed (since method definitions
263 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000264 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000265 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
266 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
267 }
268 MD->setInstanceMethod(Record[Idx++]);
269 MD->setVariadic(Record[Idx++]);
270 MD->setSynthesized(Record[Idx++]);
271 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
272 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
273 MD->setResultType(Reader.GetType(Record[Idx++]));
274 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
275 unsigned NumParams = Record[Idx++];
276 llvm::SmallVector<ParmVarDecl *, 16> Params;
277 Params.reserve(NumParams);
278 for (unsigned I = 0; I != NumParams; ++I)
279 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000280 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000281}
282
283void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
284 VisitNamedDecl(CD);
285 CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
286}
287
288void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
289 VisitObjCContainerDecl(ID);
290 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
291 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
292 (Reader.GetDecl(Record[Idx++])));
293 unsigned NumProtocols = Record[Idx++];
294 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
295 Protocols.reserve(NumProtocols);
296 for (unsigned I = 0; I != NumProtocols; ++I)
297 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000298 ID->setProtocolList(Protocols.data(), NumProtocols, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000299 unsigned NumIvars = Record[Idx++];
300 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
301 IVars.reserve(NumIvars);
302 for (unsigned I = 0; I != NumIvars; ++I)
303 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000304 ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000305 ID->setCategoryList(
306 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
307 ID->setForwardDecl(Record[Idx++]);
308 ID->setImplicitInterfaceDecl(Record[Idx++]);
309 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
310 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000311 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000312}
313
314void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
315 VisitFieldDecl(IVD);
316 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
317}
318
319void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
320 VisitObjCContainerDecl(PD);
321 PD->setForwardDecl(Record[Idx++]);
322 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
323 unsigned NumProtoRefs = Record[Idx++];
324 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
325 ProtoRefs.reserve(NumProtoRefs);
326 for (unsigned I = 0; I != NumProtoRefs; ++I)
327 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Jay Foadbeaaccd2009-05-21 09:52:38 +0000328 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000329}
330
331void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
332 VisitFieldDecl(FD);
333}
334
335void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
336 VisitDecl(CD);
337 unsigned NumClassRefs = Record[Idx++];
338 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
339 ClassRefs.reserve(NumClassRefs);
340 for (unsigned I = 0; I != NumClassRefs; ++I)
341 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000342 CD->setClassList(*Reader.getContext(), ClassRefs.data(), NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000343}
344
345void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
346 VisitDecl(FPD);
347 unsigned NumProtoRefs = Record[Idx++];
348 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
349 ProtoRefs.reserve(NumProtoRefs);
350 for (unsigned I = 0; I != NumProtoRefs; ++I)
351 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor75fdb232009-05-22 22:45:36 +0000352 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000353}
354
355void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
356 VisitObjCContainerDecl(CD);
357 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
358 unsigned NumProtoRefs = Record[Idx++];
359 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
360 ProtoRefs.reserve(NumProtoRefs);
361 for (unsigned I = 0; I != NumProtoRefs; ++I)
362 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek66ef1112009-05-22 22:34:23 +0000363 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000364 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
365 CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
366}
367
368void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
369 VisitNamedDecl(CAD);
370 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
371}
372
373void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
374 VisitNamedDecl(D);
375 D->setType(Reader.GetType(Record[Idx++]));
376 // FIXME: stable encoding
377 D->setPropertyAttributes(
378 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
379 // FIXME: stable encoding
380 D->setPropertyImplementation(
381 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
382 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
383 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
384 D->setGetterMethodDecl(
385 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
386 D->setSetterMethodDecl(
387 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
388 D->setPropertyIvarDecl(
389 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
390}
391
392void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000393 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000394 D->setClassInterface(
395 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000396}
397
398void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
399 VisitObjCImplDecl(D);
400 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
401}
402
403void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
404 VisitObjCImplDecl(D);
405 D->setSuperClass(
406 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
407}
408
409
410void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
411 VisitDecl(D);
412 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
413 D->setPropertyDecl(
414 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
415 D->setPropertyIvarDecl(
416 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
417}
418
419void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000420 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000421 FD->setMutable(Record[Idx++]);
422 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000423 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000424}
425
426void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000427 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000428 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
429 VD->setThreadSpecified(Record[Idx++]);
430 VD->setCXXDirectInitializer(Record[Idx++]);
431 VD->setDeclaredInCondition(Record[Idx++]);
432 VD->setPreviousDeclaration(
433 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000434 if (Record[Idx++])
Douglas Gregor78d15832009-05-26 18:54:04 +0000435 VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000436}
437
438void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
439 VisitVarDecl(PD);
440}
441
442void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
443 VisitVarDecl(PD);
444 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000445}
446
447void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) {
448 VisitParmVarDecl(PD);
449 PD->setOriginalType(Reader.GetType(Record[Idx++]));
450}
451
452void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
453 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000454 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000455}
456
457void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
458 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000459 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000460 unsigned NumParams = Record[Idx++];
461 llvm::SmallVector<ParmVarDecl *, 16> Params;
462 Params.reserve(NumParams);
463 for (unsigned I = 0; I != NumParams; ++I)
464 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Mike Stump1eb44332009-09-09 15:08:12 +0000465 BD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000466}
467
Mike Stump1eb44332009-09-09 15:08:12 +0000468std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000469PCHDeclReader::VisitDeclContext(DeclContext *DC) {
470 uint64_t LexicalOffset = Record[Idx++];
471 uint64_t VisibleOffset = Record[Idx++];
472 return std::make_pair(LexicalOffset, VisibleOffset);
473}
474
475//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000476// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000477//===----------------------------------------------------------------------===//
478
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000479/// \brief Reads attributes from the current stream position.
480Attr *PCHReader::ReadAttributes() {
481 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000482 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000483 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000484
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000485 RecordData Record;
486 unsigned Idx = 0;
487 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000488 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000489 (void)RecCode;
490
491#define SIMPLE_ATTR(Name) \
492 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000493 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000494 break
495
496#define STRING_ATTR(Name) \
497 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000498 New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000499 break
500
501#define UNSIGNED_ATTR(Name) \
502 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000503 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000504 break
505
506 Attr *Attrs = 0;
507 while (Idx < Record.size()) {
508 Attr *New = 0;
509 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
510 bool IsInherited = Record[Idx++];
511
512 switch (Kind) {
513 STRING_ATTR(Alias);
514 UNSIGNED_ATTR(Aligned);
515 SIMPLE_ATTR(AlwaysInline);
516 SIMPLE_ATTR(AnalyzerNoReturn);
517 STRING_ATTR(Annotate);
518 STRING_ATTR(AsmLabel);
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000520 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000521 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000522 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
523 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000524
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000525 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000526 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000527 cast<FunctionDecl>(GetDecl(Record[Idx++])));
528 break;
529
530 SIMPLE_ATTR(Const);
531 UNSIGNED_ATTR(Constructor);
532 SIMPLE_ATTR(DLLExport);
533 SIMPLE_ATTR(DLLImport);
534 SIMPLE_ATTR(Deprecated);
535 UNSIGNED_ATTR(Destructor);
536 SIMPLE_ATTR(FastCall);
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000538 case Attr::Format: {
539 std::string Type = ReadString(Record, Idx);
540 unsigned FormatIdx = Record[Idx++];
541 unsigned FirstArg = Record[Idx++];
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000542 New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000543 break;
544 }
Mike Stump1eb44332009-09-09 15:08:12 +0000545
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000546 case Attr::FormatArg: {
547 unsigned FormatIdx = Record[Idx++];
548 New = ::new (*Context) FormatArgAttr(FormatIdx);
549 break;
550 }
Mike Stump1eb44332009-09-09 15:08:12 +0000551
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000552 case Attr::Sentinel: {
553 int sentinel = Record[Idx++];
554 int nullPos = Record[Idx++];
555 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
556 break;
557 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000558
559 SIMPLE_ATTR(GNUInline);
Mike Stump1eb44332009-09-09 15:08:12 +0000560
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000561 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000562 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000563 break;
564
Ryan Flynn76168e22009-08-09 20:07:29 +0000565 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000566 SIMPLE_ATTR(NoDebug);
567 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000568 SIMPLE_ATTR(NoReturn);
569 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000571 case Attr::NonNull: {
572 unsigned Size = Record[Idx++];
573 llvm::SmallVector<unsigned, 16> ArgNums;
574 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
575 Idx += Size;
Douglas Gregor75fdb232009-05-22 22:45:36 +0000576 New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000577 break;
578 }
Mike Stump1eb44332009-09-09 15:08:12 +0000579
Nate Begeman6f3d8382009-06-26 06:32:41 +0000580 case Attr::ReqdWorkGroupSize: {
581 unsigned X = Record[Idx++];
582 unsigned Y = Record[Idx++];
583 unsigned Z = Record[Idx++];
584 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
585 break;
586 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000587
588 SIMPLE_ATTR(ObjCException);
589 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000590 SIMPLE_ATTR(CFReturnsRetained);
591 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000592 SIMPLE_ATTR(Overloadable);
Anders Carlssona860e752009-08-08 18:23:56 +0000593 SIMPLE_ATTR(Packed);
594 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000595 SIMPLE_ATTR(Pure);
596 UNSIGNED_ATTR(Regparm);
597 STRING_ATTR(Section);
598 SIMPLE_ATTR(StdCall);
599 SIMPLE_ATTR(TransparentUnion);
600 SIMPLE_ATTR(Unavailable);
601 SIMPLE_ATTR(Unused);
602 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000603
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000604 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000605 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000606 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
607 break;
608
609 SIMPLE_ATTR(WarnUnusedResult);
610 SIMPLE_ATTR(Weak);
611 SIMPLE_ATTR(WeakImport);
612 }
613
614 assert(New && "Unable to decode attribute?");
615 New->setInherited(IsInherited);
616 New->setNext(Attrs);
617 Attrs = New;
618 }
619#undef UNSIGNED_ATTR
620#undef STRING_ATTR
621#undef SIMPLE_ATTR
622
623 // The list of attributes was built backwards. Reverse the list
624 // before returning it.
625 Attr *PrevAttr = 0, *NextAttr = 0;
626 while (Attrs) {
627 NextAttr = Attrs->getNext();
628 Attrs->setNext(PrevAttr);
629 PrevAttr = Attrs;
630 Attrs = NextAttr;
631 }
632
633 return PrevAttr;
634}
635
636//===----------------------------------------------------------------------===//
637// PCHReader Implementation
638//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000639
640/// \brief Note that we have loaded the declaration with the given
641/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000642///
Chris Lattner698f9252009-04-27 05:27:42 +0000643/// This routine notes that this declaration has already been loaded,
644/// so that future GetDecl calls will return this declaration rather
645/// than trying to load a new declaration.
646inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
647 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
648 DeclsLoaded[Index] = D;
649}
650
651
652/// \brief Determine whether the consumer will be interested in seeing
653/// this declaration (via HandleTopLevelDecl).
654///
655/// This routine should return true for anything that might affect
656/// code generation, e.g., inline function definitions, Objective-C
657/// declarations with metadata, etc.
658static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000659 if (isa<FileScopeAsmDecl>(D))
660 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000661 if (VarDecl *Var = dyn_cast<VarDecl>(D))
662 return Var->isFileVarDecl() && Var->getInit();
663 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
664 return Func->isThisDeclarationADefinition();
665 return isa<ObjCProtocolDecl>(D);
666}
667
668/// \brief Read the declaration at the given offset from the PCH file.
669Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
670 // Keep track of where we are in the stream, then jump back there
671 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000672 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000673
Douglas Gregord89275b2009-07-06 18:54:52 +0000674 // Note that we are loading a declaration record.
675 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000676
Chris Lattnerda930612009-04-27 05:58:23 +0000677 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000678 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000679 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000680 unsigned Idx = 0;
681 PCHDeclReader Reader(*this, Record, Idx);
682
Chris Lattnerda930612009-04-27 05:58:23 +0000683 Decl *D = 0;
684 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000685 case pch::DECL_ATTR:
686 case pch::DECL_CONTEXT_LEXICAL:
687 case pch::DECL_CONTEXT_VISIBLE:
688 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
689 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000690 case pch::DECL_TRANSLATION_UNIT:
691 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000692 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000693 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000694 case pch::DECL_TYPEDEF:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000695 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000696 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000697 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000698 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000699 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000700 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000701 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000702 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000703 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000704 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000705 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000706 0, llvm::APSInt());
707 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000708 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000709 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000710 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000711 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000712 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000713 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Chris Lattner698f9252009-04-27 05:27:42 +0000714 Selector(), QualType(), 0);
715 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000716 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000717 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000718 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000719 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000720 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000721 ObjCIvarDecl::None);
722 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000723 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000724 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000725 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000726 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000727 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000728 QualType(), 0);
729 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000730 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000731 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000732 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000733 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000734 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000735 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000736 case pch::DECL_OBJC_CATEGORY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000737 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000738 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000739 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000740 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000741 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000742 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000743 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000744 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000745 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000746 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000747 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000748 case pch::DECL_OBJC_PROPERTY:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000749 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000750 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000751 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000752 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +0000753 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000754 ObjCPropertyImplDecl::Dynamic, 0);
755 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000756 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000757 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000758 false);
Chris Lattner698f9252009-04-27 05:27:42 +0000759 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000760 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000761 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +0000762 VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +0000763 break;
764
765 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000766 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +0000767 break;
768
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000769 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +0000770 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000771 VarDecl::None, 0);
772 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000773 case pch::DECL_ORIGINAL_PARM_VAR:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000774 D = OriginalParmVarDecl::Create(*Context, 0, SourceLocation(), 0,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000775 QualType(),0, QualType(), VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000776 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000777 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000778 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000779 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000780 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000781 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000782 break;
783 }
Chris Lattner698f9252009-04-27 05:27:42 +0000784
785 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000786 LoadedDecl(Index, D);
787 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000788
789 // If this declaration is also a declaration context, get the
790 // offsets for its tables of lexical and visible declarations.
791 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
792 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
793 if (Offsets.first || Offsets.second) {
794 DC->setHasExternalLexicalStorage(Offsets.first != 0);
795 DC->setHasExternalVisibleStorage(Offsets.second != 0);
796 DeclContextOffsets[DC] = Offsets;
797 }
798 }
799 assert(Idx == Record.size());
800
801 // If we have deserialized a declaration that has a definition the
802 // AST consumer might need to know about, notify the consumer
803 // about that definition now or queue it for later.
804 if (isConsumerInterestedIn(D)) {
805 if (Consumer) {
806 DeclGroupRef DG(D);
807 Consumer->HandleTopLevelDecl(DG);
808 } else {
809 InterestingDecls.push_back(D);
810 }
811 }
812
813 return D;
814}