blob: fe11ca76d3ebed04fc34db787e561906e8115b96 [file] [log] [blame]
Chris Lattner487412d2009-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"
Chris Lattnerca025db2010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner487412d2009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
30namespace {
31 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
32 PCHReader &Reader;
33 const PCHReader::RecordData &Record;
34 unsigned &Idx;
35
36 public:
37 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
38 unsigned &Idx)
39 : Reader(Reader), Record(Record), Idx(Idx) { }
40
John McCall1c70e992010-06-03 19:28:45 +000041 CXXBaseSpecifier *ReadCXXBaseSpecifier();
42
Chris Lattner487412d2009-04-27 05:27:42 +000043 void VisitDecl(Decl *D);
44 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
45 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000046 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000047 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
48 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000049 void VisitTypeDecl(TypeDecl *TD);
50 void VisitTypedefDecl(TypedefDecl *TD);
Chris Lattnerca025db2010-05-07 21:43:38 +000051 void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000052 void VisitTagDecl(TagDecl *TD);
53 void VisitEnumDecl(EnumDecl *ED);
54 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000055 void VisitCXXRecordDecl(CXXRecordDecl *D);
56 void VisitClassTemplateSpecializationDecl(
57 ClassTemplateSpecializationDecl *D);
58 void VisitClassTemplatePartialSpecializationDecl(
59 ClassTemplatePartialSpecializationDecl *D);
60 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000061 void VisitValueDecl(ValueDecl *VD);
62 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Chris Lattnerca025db2010-05-07 21:43:38 +000063 void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000064 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000065 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000066 void VisitCXXMethodDecl(CXXMethodDecl *D);
67 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
68 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
69 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000070 void VisitFieldDecl(FieldDecl *FD);
71 void VisitVarDecl(VarDecl *VD);
72 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
73 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000074 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
75 void VisitTemplateDecl(TemplateDecl *D);
76 void VisitClassTemplateDecl(ClassTemplateDecl *D);
77 void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
78 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
79 void VisitUsing(UsingDecl *D);
80 void VisitUsingShadow(UsingShadowDecl *D);
81 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000082 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000083 void VisitAccessSpecDecl(AccessSpecDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
85 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000086 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000087
Chris Lattner487412d2009-04-27 05:27:42 +000088 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000089
Alexis Hunted053252010-05-30 07:21:58 +000090 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000091 void VisitObjCMethodDecl(ObjCMethodDecl *D);
92 void VisitObjCContainerDecl(ObjCContainerDecl *D);
93 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
94 void VisitObjCIvarDecl(ObjCIvarDecl *D);
95 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
96 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
97 void VisitObjCClassDecl(ObjCClassDecl *D);
98 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
99 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
100 void VisitObjCImplDecl(ObjCImplDecl *D);
101 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
102 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
103 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
104 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
105 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
106 };
107}
108
109void PCHDeclReader::VisitDecl(Decl *D) {
110 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
111 D->setLexicalDeclContext(
112 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
113 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
114 D->setInvalidDecl(Record[Idx++]);
115 if (Record[Idx++])
Argyrios Kyrtzidis91167172010-06-11 23:09:25 +0000116 D->initAttrs(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000117 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000118 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000119 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000120 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000121}
122
123void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
124 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000125 TU->setAnonymousNamespace(
126 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000127}
128
129void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
130 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000131 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000132}
133
134void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
135 VisitNamedDecl(TD);
136 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
137}
138
139void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
140 // Note that we cannot use VisitTypeDecl here, because we need to
141 // set the underlying type of the typedef *before* we try to read
142 // the type associated with the TypedefDecl.
143 VisitNamedDecl(TD);
John McCall703a3f82009-10-24 08:00:42 +0000144 uint64_t TypeData = Record[Idx++];
John McCallbcd03502009-12-07 02:54:59 +0000145 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCall703a3f82009-10-24 08:00:42 +0000146 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000147}
148
149void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
150 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000151 TD->setPreviousDeclaration(
152 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000153 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
154 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000155 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000156 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000157 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000158 // FIXME: maybe read optional qualifier and its range.
159 TD->setTypedefForAnonDecl(
160 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000161}
162
163void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
164 VisitTagDecl(ED);
165 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000166 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000167 ED->setNumPositiveBits(Record[Idx++]);
168 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor7a749382009-05-27 17:20:35 +0000169 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000170}
171
172void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
173 VisitTagDecl(RD);
174 RD->setHasFlexibleArrayMember(Record[Idx++]);
175 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000176 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000177}
178
179void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
180 VisitNamedDecl(VD);
181 VD->setType(Reader.GetType(Record[Idx++]));
182}
183
184void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
185 VisitValueDecl(ECD);
186 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000187 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000188 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
189}
190
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000191void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
192 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000193 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
194 if (TInfo)
195 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000196 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000197}
198
Chris Lattner487412d2009-04-27 05:27:42 +0000199void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000200 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000201 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000202 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000203 FD->setPreviousDeclaration(
204 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
205 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000206 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000207 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000208 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000209 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000210 FD->setHasInheritedPrototype(Record[Idx++]);
211 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000212 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000213 FD->setTrivial(Record[Idx++]);
214 FD->setCopyAssignment(Record[Idx++]);
215 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000216 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor24c332b2009-05-14 21:06:31 +0000217 // FIXME: C++ TemplateOrInstantiation
Chris Lattnerca025db2010-05-07 21:43:38 +0000218
219 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000220 unsigned NumParams = Record[Idx++];
221 llvm::SmallVector<ParmVarDecl *, 16> Params;
222 Params.reserve(NumParams);
223 for (unsigned I = 0; I != NumParams; ++I)
224 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000225 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000226
227 // FIXME: order this properly w.r.t. friendness
228 // FIXME: this same thing needs to happen for function templates
229 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
230 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000231}
232
233void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
234 VisitNamedDecl(MD);
235 if (Record[Idx++]) {
236 // In practice, this won't be executed (since method definitions
237 // don't occur in header files).
Chris Lattner1de76db2009-04-27 05:58:23 +0000238 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000239 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
240 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
241 }
242 MD->setInstanceMethod(Record[Idx++]);
243 MD->setVariadic(Record[Idx++]);
244 MD->setSynthesized(Record[Idx++]);
245 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
246 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000247 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000248 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000249 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000250 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
251 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++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000256 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
257 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000258}
259
260void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
261 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000262 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
263 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
264 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000265}
266
267void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
268 VisitObjCContainerDecl(ID);
269 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
270 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
271 (Reader.GetDecl(Record[Idx++])));
272 unsigned NumProtocols = Record[Idx++];
273 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
274 Protocols.reserve(NumProtocols);
275 for (unsigned I = 0; I != NumProtocols; ++I)
276 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000277 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
278 ProtoLocs.reserve(NumProtocols);
279 for (unsigned I = 0; I != NumProtocols; ++I)
280 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
281 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
282 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000283 unsigned NumIvars = Record[Idx++];
284 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
285 IVars.reserve(NumIvars);
286 for (unsigned I = 0; I != NumIvars; ++I)
287 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000288 ID->setCategoryList(
289 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
290 ID->setForwardDecl(Record[Idx++]);
291 ID->setImplicitInterfaceDecl(Record[Idx++]);
292 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
293 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000294 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000295}
296
297void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
298 VisitFieldDecl(IVD);
299 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
300}
301
302void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
303 VisitObjCContainerDecl(PD);
304 PD->setForwardDecl(Record[Idx++]);
305 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
306 unsigned NumProtoRefs = Record[Idx++];
307 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
308 ProtoRefs.reserve(NumProtoRefs);
309 for (unsigned I = 0; I != NumProtoRefs; ++I)
310 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000311 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
312 ProtoLocs.reserve(NumProtoRefs);
313 for (unsigned I = 0; I != NumProtoRefs; ++I)
314 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
315 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
316 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000317}
318
319void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
320 VisitFieldDecl(FD);
321}
322
323void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
324 VisitDecl(CD);
325 unsigned NumClassRefs = Record[Idx++];
326 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
327 ClassRefs.reserve(NumClassRefs);
328 for (unsigned I = 0; I != NumClassRefs; ++I)
329 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000330 llvm::SmallVector<SourceLocation, 16> SLocs;
331 SLocs.reserve(NumClassRefs);
332 for (unsigned I = 0; I != NumClassRefs; ++I)
333 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
334 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
335 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000336}
337
338void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
339 VisitDecl(FPD);
340 unsigned NumProtoRefs = Record[Idx++];
341 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
342 ProtoRefs.reserve(NumProtoRefs);
343 for (unsigned I = 0; I != NumProtoRefs; ++I)
344 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000345 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
346 ProtoLocs.reserve(NumProtoRefs);
347 for (unsigned I = 0; I != NumProtoRefs; ++I)
348 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
349 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
350 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000351}
352
353void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
354 VisitObjCContainerDecl(CD);
355 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
356 unsigned NumProtoRefs = Record[Idx++];
357 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
358 ProtoRefs.reserve(NumProtoRefs);
359 for (unsigned I = 0; I != NumProtoRefs; ++I)
360 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000361 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
362 ProtoLocs.reserve(NumProtoRefs);
363 for (unsigned I = 0; I != NumProtoRefs; ++I)
364 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
365 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
366 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000367 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000368 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
369 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000370}
371
372void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
373 VisitNamedDecl(CAD);
374 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
375}
376
377void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
378 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000379 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000380 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000381 // FIXME: stable encoding
382 D->setPropertyAttributes(
383 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
384 // FIXME: stable encoding
385 D->setPropertyImplementation(
386 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
387 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
388 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
389 D->setGetterMethodDecl(
390 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
391 D->setSetterMethodDecl(
392 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
393 D->setPropertyIvarDecl(
394 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
395}
396
397void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000398 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000399 D->setClassInterface(
400 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000401}
402
403void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
404 VisitObjCImplDecl(D);
405 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
406}
407
408void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
409 VisitObjCImplDecl(D);
410 D->setSuperClass(
411 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000412 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000413}
414
415
416void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
417 VisitDecl(D);
418 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
419 D->setPropertyDecl(
420 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
421 D->setPropertyIvarDecl(
422 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000423 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000424}
425
426void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000427 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000428 FD->setMutable(Record[Idx++]);
429 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000430 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000431}
432
433void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000434 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000435 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000436 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000437 VD->setThreadSpecified(Record[Idx++]);
438 VD->setCXXDirectInitializer(Record[Idx++]);
439 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000440 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000441 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000442 VD->setPreviousDeclaration(
443 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000444 if (Record[Idx++])
Douglas Gregord5058122010-02-11 01:19:42 +0000445 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000446}
447
448void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
449 VisitVarDecl(PD);
450}
451
452void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
453 VisitVarDecl(PD);
454 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000455 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000456}
457
Chris Lattner487412d2009-04-27 05:27:42 +0000458void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
459 VisitDecl(AD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000460 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000461}
462
463void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
464 VisitDecl(BD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000465 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000466 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000467 unsigned NumParams = Record[Idx++];
468 llvm::SmallVector<ParmVarDecl *, 16> Params;
469 Params.reserve(NumParams);
470 for (unsigned I = 0; I != NumParams; ++I)
471 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000472 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000473}
474
Chris Lattnerca025db2010-05-07 21:43:38 +0000475void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
476 VisitDecl(D);
477 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
478 D->setHasBraces(Record[Idx++]);
479}
480
481void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
482 VisitNamedDecl(D);
483 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
484 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
485 D->setNextNamespace(
486 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
487
488 // Only read one reference--the original or anonymous namespace.
489 bool IsOriginal = Record[Idx++];
490 if (IsOriginal)
491 D->setAnonymousNamespace(
492 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
493 else
494 D->setOriginalNamespace(
495 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
496}
497
498void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
499 VisitNamedDecl(D);
500
501 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
502 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
503 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
504 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
505 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
506}
507
508void PCHDeclReader::VisitUsing(UsingDecl *D) {
509 VisitNamedDecl(D);
510 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
511 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
512 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
513
514 // FIXME: It would probably be more efficient to read these into a vector
515 // and then re-cosntruct the shadow decl set over that vector since it
516 // would avoid existence checks.
517 unsigned NumShadows = Record[Idx++];
518 for(unsigned I = 0; I != NumShadows; ++I) {
519 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
520 }
521 D->setTypeName(Record[Idx++]);
522}
523
524void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) {
525 VisitNamedDecl(D);
526 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
527 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
528}
529
530void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
531 VisitNamedDecl(D);
532 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
533 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
534 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
535 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
536 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
537 D->setCommonAncestor(cast_or_null<DeclContext>(
538 Reader.GetDecl(Record[Idx++])));
539}
540
541void PCHDeclReader::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) {
542 VisitValueDecl(D);
543 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
544 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
545 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
546}
547
548void PCHDeclReader::VisitUnresolvedUsingTypename(
549 UnresolvedUsingTypenameDecl *D) {
550 VisitTypeDecl(D);
551 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
552 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
553 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
554 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
555}
556
John McCall1c70e992010-06-03 19:28:45 +0000557CXXBaseSpecifier *PCHDeclReader::ReadCXXBaseSpecifier() {
558 bool isVirtual = static_cast<bool>(Record[Idx++]);
559 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
560 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
561 QualType T = Reader.GetType(Record[Idx++]);
562 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
563 return new (*Reader.getContext())
564 CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
565}
566
Chris Lattnerca025db2010-05-07 21:43:38 +0000567void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
568 // assert(false && "cannot read CXXRecordDecl");
569 VisitRecordDecl(D);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000570
571 enum CXXRecKind {
572 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
573 };
574 switch ((CXXRecKind)Record[Idx++]) {
575 default:
576 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
577 case CXXRecNotTemplate:
578 break;
579 case CXXRecTemplate:
580 D->setDescribedClassTemplate(
581 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
582 break;
583 case CXXRecMemberSpecialization: {
584 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
585 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
586 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
587 D->setInstantiationOfMemberClass(RD, TSK);
588 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
589 break;
590 }
591 }
John McCall1c70e992010-06-03 19:28:45 +0000592
593 // FIXME: this is far from complete
594
595 if (D->isDefinition()) {
596 D->setDefinition(false); // make peace with an assertion
597 D->startDefinition();
598
599 unsigned NumBases = Record[Idx++];
600
601 llvm::SmallVector<CXXBaseSpecifier*, 4> Bases;
602 Bases.reserve(NumBases);
603 for (unsigned I = 0; I != NumBases; ++I)
604 Bases.push_back(ReadCXXBaseSpecifier());
605 D->setBases(Bases.begin(), NumBases);
606
607 // FIXME: there's a lot of stuff we do here that's kindof sketchy
608 // if we're leaving the context incomplete.
609 D->completeDefinition();
610 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000611}
612
613void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
614 // assert(false && "cannot read CXXMethodDecl");
615 VisitFunctionDecl(D);
616}
617
618void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
619 // assert(false && "cannot read CXXConstructorDecl");
620 VisitCXXMethodDecl(D);
621}
622
623void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
624 // assert(false && "cannot read CXXDestructorDecl");
625 VisitCXXMethodDecl(D);
626}
627
628void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
629 // assert(false && "cannot read CXXConversionDecl");
630 VisitCXXMethodDecl(D);
631}
632
Abramo Bagnarad7340582010-06-05 05:09:32 +0000633void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
634 VisitDecl(D);
635 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
636}
637
Chris Lattnerca025db2010-05-07 21:43:38 +0000638void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
639 assert(false && "cannot read FriendTemplateDecl");
640}
641
642void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000643 VisitNamedDecl(D);
644
645 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
646
647 // TemplateParams.
648 SourceLocation TemplateLoc = Reader.ReadSourceLocation(Record, Idx);
649 SourceLocation LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
650 SourceLocation RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
651
652 unsigned NumParams = Record[Idx++];
653 assert(NumParams && "No template params!");
654 llvm::SmallVector<NamedDecl *, 16> Params;
655 Params.reserve(NumParams);
656 while (NumParams--)
657 Params.push_back(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
658
659 TemplateParameterList* TemplateParams =
660 TemplateParameterList::Create(*Reader.getContext(), TemplateLoc, LAngleLoc,
661 Params.data(), Params.size(), RAngleLoc);
662
663 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000664}
665
666void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000667 VisitTemplateDecl(D);
668
669 ClassTemplateDecl *PrevDecl =
670 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
671 D->initPreviousDeclaration(*Reader.getContext(), PrevDecl);
672 if (PrevDecl == 0) {
673 // This ClassTemplateDecl owns a CommonPtr; read it.
674
675 unsigned size = Record[Idx++];
676 while (size--) {
677 ClassTemplateSpecializationDecl *CTSD
678 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
679 llvm::FoldingSetNodeID ID;
680 void *InsertPos = 0;
681 ClassTemplateSpecializationDecl::Profile(ID,
682 CTSD->getTemplateArgs().getFlatArgumentList(),
683 CTSD->getTemplateArgs().flat_size(),
684 *Reader.getContext());
685 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
686 D->getSpecializations().InsertNode(CTSD, InsertPos);
687 }
688
689 size = Record[Idx++];
690 while (size--) {
691 ClassTemplatePartialSpecializationDecl *CTSD
692 = cast<ClassTemplatePartialSpecializationDecl>(
693 Reader.GetDecl(Record[Idx++]));
694 llvm::FoldingSetNodeID ID;
695 void *InsertPos = 0;
696 ClassTemplatePartialSpecializationDecl::Profile(ID,
697 CTSD->getTemplateArgs().getFlatArgumentList(),
698 CTSD->getTemplateArgs().flat_size(),
699 *Reader.getContext());
700 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
701 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
702 }
703
704 // InjectedClassNameType is computed.
705
706 if (ClassTemplateDecl *CTD
707 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
708 D->setInstantiatedFromMemberTemplate(CTD);
709 if (Record[Idx++])
710 D->setMemberSpecialization();
711 }
712 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000713}
714
715void PCHDeclReader::VisitClassTemplateSpecializationDecl(
716 ClassTemplateSpecializationDecl *D) {
717 assert(false && "cannot read ClassTemplateSpecializationDecl");
718}
719
720void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
721 ClassTemplatePartialSpecializationDecl *D) {
722 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
723}
724
725void PCHDeclReader::visitFunctionTemplateDecl(FunctionTemplateDecl *D) {
726 assert(false && "cannot read FunctionTemplateDecl");
727}
728
729void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000730 VisitTypeDecl(D);
731
732 D->setDeclaredWithTypename(Record[Idx++]);
733 D->setParameterPack(Record[Idx++]);
734
735 bool Inherited = Record[Idx++];
736 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
737 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +0000738}
739
740void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
741 assert(false && "cannot read NonTypeTemplateParmDecl");
742}
743
744void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
745 assert(false && "cannot read TemplateTemplateParmDecl");
746}
747
748void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
749 assert(false && "cannot read StaticAssertDecl");
750}
751
Mike Stump11289f42009-09-09 15:08:12 +0000752std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000753PCHDeclReader::VisitDeclContext(DeclContext *DC) {
754 uint64_t LexicalOffset = Record[Idx++];
755 uint64_t VisibleOffset = Record[Idx++];
756 return std::make_pair(LexicalOffset, VisibleOffset);
757}
758
759//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000760// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000761//===----------------------------------------------------------------------===//
762
Chris Lattner8f63ab52009-04-27 06:01:06 +0000763/// \brief Reads attributes from the current stream position.
764Attr *PCHReader::ReadAttributes() {
765 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000766 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000767 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000768
Chris Lattner8f63ab52009-04-27 06:01:06 +0000769 RecordData Record;
770 unsigned Idx = 0;
771 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000772 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000773 (void)RecCode;
774
775#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000776 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000777 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000778 break
779
780#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000781 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000782 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000783 break
784
785#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000786 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000787 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000788 break
789
790 Attr *Attrs = 0;
791 while (Idx < Record.size()) {
792 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +0000793 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +0000794 bool IsInherited = Record[Idx++];
795
796 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000797 default:
798 assert(0 && "Unknown attribute!");
799 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000800 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +0000801 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000802 UNSIGNED_ATTR(Aligned);
803 SIMPLE_ATTR(AlwaysInline);
804 SIMPLE_ATTR(AnalyzerNoReturn);
805 STRING_ATTR(Annotate);
806 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000807 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000808
Alexis Hunt344393e2010-06-16 23:43:53 +0000809 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000810 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000811 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
812 break;
Mike Stump11289f42009-09-09 15:08:12 +0000813
Eli Friedmane4310c82009-11-09 18:38:53 +0000814 SIMPLE_ATTR(CDecl);
815
Alexis Hunt344393e2010-06-16 23:43:53 +0000816 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000817 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000818 cast<FunctionDecl>(GetDecl(Record[Idx++])));
819 break;
820
821 SIMPLE_ATTR(Const);
822 UNSIGNED_ATTR(Constructor);
823 SIMPLE_ATTR(DLLExport);
824 SIMPLE_ATTR(DLLImport);
825 SIMPLE_ATTR(Deprecated);
826 UNSIGNED_ATTR(Destructor);
827 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000828 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000829
Alexis Hunt344393e2010-06-16 23:43:53 +0000830 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +0000831 std::string Type = ReadString(Record, Idx);
832 unsigned FormatIdx = Record[Idx++];
833 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000834 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000835 break;
836 }
Mike Stump11289f42009-09-09 15:08:12 +0000837
Alexis Hunt344393e2010-06-16 23:43:53 +0000838 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000839 unsigned FormatIdx = Record[Idx++];
840 New = ::new (*Context) FormatArgAttr(FormatIdx);
841 break;
842 }
Mike Stump11289f42009-09-09 15:08:12 +0000843
Alexis Hunt344393e2010-06-16 23:43:53 +0000844 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000845 int sentinel = Record[Idx++];
846 int nullPos = Record[Idx++];
847 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
848 break;
849 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000850
851 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000852 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000853
Alexis Hunt344393e2010-06-16 23:43:53 +0000854 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +0000855 New = ::new (*Context) IBActionAttr();
856 break;
857
Alexis Hunt344393e2010-06-16 23:43:53 +0000858 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +0000859 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000860 break;
861
Alexis Hunt344393e2010-06-16 23:43:53 +0000862 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +0000863 ObjCInterfaceDecl *D =
864 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
865 New = ::new (*Context) IBOutletCollectionAttr(D);
866 break;
867 }
868
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000869 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000870 SIMPLE_ATTR(NoDebug);
871 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000872 SIMPLE_ATTR(NoReturn);
873 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000874
Alexis Hunt344393e2010-06-16 23:43:53 +0000875 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +0000876 unsigned Size = Record[Idx++];
877 llvm::SmallVector<unsigned, 16> ArgNums;
878 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
879 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000880 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000881 break;
882 }
Mike Stump11289f42009-09-09 15:08:12 +0000883
Alexis Hunt344393e2010-06-16 23:43:53 +0000884 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +0000885 unsigned X = Record[Idx++];
886 unsigned Y = Record[Idx++];
887 unsigned Z = Record[Idx++];
888 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
889 break;
890 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000891
892 SIMPLE_ATTR(ObjCException);
893 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000894 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000895 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000896 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000897 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000898 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000899 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000900 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +0000901 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000902 SIMPLE_ATTR(Pure);
903 UNSIGNED_ATTR(Regparm);
904 STRING_ATTR(Section);
905 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +0000906 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000907 SIMPLE_ATTR(TransparentUnion);
908 SIMPLE_ATTR(Unavailable);
909 SIMPLE_ATTR(Unused);
910 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000911
Alexis Hunt344393e2010-06-16 23:43:53 +0000912 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000913 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000914 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
915 break;
916
917 SIMPLE_ATTR(WarnUnusedResult);
918 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +0000919 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000920 SIMPLE_ATTR(WeakImport);
921 }
922
923 assert(New && "Unable to decode attribute?");
924 New->setInherited(IsInherited);
925 New->setNext(Attrs);
926 Attrs = New;
927 }
928#undef UNSIGNED_ATTR
929#undef STRING_ATTR
930#undef SIMPLE_ATTR
931
932 // The list of attributes was built backwards. Reverse the list
933 // before returning it.
934 Attr *PrevAttr = 0, *NextAttr = 0;
935 while (Attrs) {
936 NextAttr = Attrs->getNext();
937 Attrs->setNext(PrevAttr);
938 PrevAttr = Attrs;
939 Attrs = NextAttr;
940 }
941
942 return PrevAttr;
943}
944
945//===----------------------------------------------------------------------===//
946// PCHReader Implementation
947//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000948
949/// \brief Note that we have loaded the declaration with the given
950/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000951///
Chris Lattner487412d2009-04-27 05:27:42 +0000952/// This routine notes that this declaration has already been loaded,
953/// so that future GetDecl calls will return this declaration rather
954/// than trying to load a new declaration.
955inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
956 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
957 DeclsLoaded[Index] = D;
958}
959
960
961/// \brief Determine whether the consumer will be interested in seeing
962/// this declaration (via HandleTopLevelDecl).
963///
964/// This routine should return true for anything that might affect
965/// code generation, e.g., inline function definitions, Objective-C
966/// declarations with metadata, etc.
967static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000968 if (isa<FileScopeAsmDecl>(D))
969 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000970 if (VarDecl *Var = dyn_cast<VarDecl>(D))
971 return Var->isFileVarDecl() && Var->getInit();
972 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
973 return Func->isThisDeclarationADefinition();
974 return isa<ObjCProtocolDecl>(D);
975}
976
977/// \brief Read the declaration at the given offset from the PCH file.
978Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
979 // Keep track of where we are in the stream, then jump back there
980 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000981 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000982
Douglas Gregor1342e842009-07-06 18:54:52 +0000983 // Note that we are loading a declaration record.
984 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000985
Chris Lattner1de76db2009-04-27 05:58:23 +0000986 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000987 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000988 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000989 unsigned Idx = 0;
990 PCHDeclReader Reader(*this, Record, Idx);
991
Chris Lattner1de76db2009-04-27 05:58:23 +0000992 Decl *D = 0;
993 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000994 case pch::DECL_ATTR:
995 case pch::DECL_CONTEXT_LEXICAL:
996 case pch::DECL_CONTEXT_VISIBLE:
997 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
998 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000999 case pch::DECL_TRANSLATION_UNIT:
1000 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001001 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001002 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001003 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001004 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001005 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001006 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +00001007 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001008 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001009 case pch::DECL_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +00001010 D = RecordDecl::Create(*Context, TTK_Struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +00001011 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001012 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001013 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001014 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001015 0, llvm::APSInt());
1016 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001017 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001018 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001019 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001020 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001021 case pch::DECL_LINKAGE_SPEC:
1022 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1023 (LinkageSpecDecl::LanguageIDs)0,
1024 false);
1025 break;
1026 case pch::DECL_NAMESPACE:
1027 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1028 break;
1029 case pch::DECL_NAMESPACE_ALIAS:
1030 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1031 SourceLocation(), 0, SourceRange(), 0,
1032 SourceLocation(), 0);
1033 break;
1034 case pch::DECL_USING:
1035 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1036 SourceLocation(), 0, DeclarationName(), false);
1037 break;
1038 case pch::DECL_USING_SHADOW:
1039 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1040 break;
1041 case pch::DECL_USING_DIRECTIVE:
1042 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1043 SourceLocation(), SourceRange(), 0,
1044 SourceLocation(), 0, 0);
1045 break;
1046 case pch::DECL_UNRESOLVED_USING_VALUE:
1047 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1048 SourceRange(), 0, SourceLocation(),
1049 DeclarationName());
1050 break;
1051 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1052 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1053 SourceLocation(), SourceRange(),
1054 0, SourceLocation(),
1055 DeclarationName());
1056 break;
1057 case pch::DECL_CXX_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +00001058 D = CXXRecordDecl::Create(*Context, TTK_Struct, 0,
Chris Lattnerca025db2010-05-07 21:43:38 +00001059 SourceLocation(), 0, SourceLocation(), 0);
1060 break;
1061 case pch::DECL_CXX_METHOD:
1062 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1063 QualType(), 0);
1064 break;
1065 case pch::DECL_CXX_CONSTRUCTOR:
1066 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1067 break;
1068 case pch::DECL_CXX_DESTRUCTOR:
1069 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1070 break;
1071 case pch::DECL_CXX_CONVERSION:
1072 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1073 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001074 case pch::DECL_ACCESS_SPEC:
1075 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1076 SourceLocation());
1077 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001078 case pch::DECL_FRIEND:
1079 assert(false && "cannot read FriendDecl");
1080 break;
1081 case pch::DECL_FRIEND_TEMPLATE:
1082 assert(false && "cannot read FriendTemplateDecl");
1083 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001084 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001085 D = ClassTemplateDecl::CreateEmpty(*Context);
Chris Lattnerca025db2010-05-07 21:43:38 +00001086 break;
1087 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
1088 assert(false && "cannot read ClasstemplateSpecializationDecl");
1089 break;
1090 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
1091 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
1092 break;
1093 case pch::DECL_FUNCTION_TEMPLATE:
1094 assert(false && "cannot read FunctionTemplateDecl");
1095 break;
1096 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001097 D = TemplateTypeParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001098 break;
1099 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
1100 assert(false && "cannot read NonTypeTemplateParmDecl");
1101 break;
1102 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1103 assert(false && "cannot read TemplateTemplateParmDecl");
1104 break;
1105 case pch::DECL_STATIC_ASSERT:
1106 assert(false && "cannot read StaticAssertDecl");
1107 break;
1108
Chris Lattner8f63ab52009-04-27 06:01:06 +00001109 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001110 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001111 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001112 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001113 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001114 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001115 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001116 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001117 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001118 ObjCIvarDecl::None);
1119 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001120 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001121 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001122 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001123 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001124 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001125 QualType(), 0);
1126 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001127 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001128 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001129 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001130 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001131 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001132 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001133 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001134 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1135 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001136 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001137 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001138 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001139 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001140 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001141 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001142 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001143 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001144 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001145 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001146 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001147 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001148 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001149 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001150 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001151 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001152 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001153 ObjCPropertyImplDecl::Dynamic, 0);
1154 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001155 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001156 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001157 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001158 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001159 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001160 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001161 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001162 break;
1163
1164 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001165 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001166 break;
1167
Chris Lattner8f63ab52009-04-27 06:01:06 +00001168 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001169 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001170 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001171 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001172 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001173 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001174 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001175 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001176 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001177 break;
1178 }
Chris Lattner487412d2009-04-27 05:27:42 +00001179
1180 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001181 LoadedDecl(Index, D);
1182 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001183
1184 // If this declaration is also a declaration context, get the
1185 // offsets for its tables of lexical and visible declarations.
1186 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1187 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1188 if (Offsets.first || Offsets.second) {
1189 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1190 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1191 DeclContextOffsets[DC] = Offsets;
1192 }
1193 }
1194 assert(Idx == Record.size());
1195
1196 // If we have deserialized a declaration that has a definition the
1197 // AST consumer might need to know about, notify the consumer
1198 // about that definition now or queue it for later.
1199 if (isConsumerInterestedIn(D)) {
1200 if (Consumer) {
1201 DeclGroupRef DG(D);
1202 Consumer->HandleTopLevelDecl(DG);
1203 } else {
1204 InterestingDecls.push_back(D);
1205 }
1206 }
1207
1208 return D;
1209}