blob: 78ae5f01b7d3d39f7735513743db777a3ec1b9df [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);
John McCall1c70e992010-06-03 19:28:45 +0000570
571 // FIXME: this is far from complete
572
573 if (D->isDefinition()) {
574 D->setDefinition(false); // make peace with an assertion
575 D->startDefinition();
576
577 unsigned NumBases = Record[Idx++];
578
579 llvm::SmallVector<CXXBaseSpecifier*, 4> Bases;
580 Bases.reserve(NumBases);
581 for (unsigned I = 0; I != NumBases; ++I)
582 Bases.push_back(ReadCXXBaseSpecifier());
583 D->setBases(Bases.begin(), NumBases);
584
585 // FIXME: there's a lot of stuff we do here that's kindof sketchy
586 // if we're leaving the context incomplete.
587 D->completeDefinition();
588 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000589}
590
591void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
592 // assert(false && "cannot read CXXMethodDecl");
593 VisitFunctionDecl(D);
594}
595
596void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
597 // assert(false && "cannot read CXXConstructorDecl");
598 VisitCXXMethodDecl(D);
599}
600
601void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
602 // assert(false && "cannot read CXXDestructorDecl");
603 VisitCXXMethodDecl(D);
604}
605
606void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
607 // assert(false && "cannot read CXXConversionDecl");
608 VisitCXXMethodDecl(D);
609}
610
Abramo Bagnarad7340582010-06-05 05:09:32 +0000611void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
612 VisitDecl(D);
613 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
614}
615
Chris Lattnerca025db2010-05-07 21:43:38 +0000616void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
617 assert(false && "cannot read FriendTemplateDecl");
618}
619
620void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
621 assert(false && "cannot read TemplateDecl");
622}
623
624void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
625 assert(false && "cannot read ClassTemplateDecl");
626}
627
628void PCHDeclReader::VisitClassTemplateSpecializationDecl(
629 ClassTemplateSpecializationDecl *D) {
630 assert(false && "cannot read ClassTemplateSpecializationDecl");
631}
632
633void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
634 ClassTemplatePartialSpecializationDecl *D) {
635 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
636}
637
638void PCHDeclReader::visitFunctionTemplateDecl(FunctionTemplateDecl *D) {
639 assert(false && "cannot read FunctionTemplateDecl");
640}
641
642void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
643 assert(false && "cannot read TemplateTypeParmDecl");
644}
645
646void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
647 assert(false && "cannot read NonTypeTemplateParmDecl");
648}
649
650void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
651 assert(false && "cannot read TemplateTemplateParmDecl");
652}
653
654void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
655 assert(false && "cannot read StaticAssertDecl");
656}
657
Mike Stump11289f42009-09-09 15:08:12 +0000658std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000659PCHDeclReader::VisitDeclContext(DeclContext *DC) {
660 uint64_t LexicalOffset = Record[Idx++];
661 uint64_t VisibleOffset = Record[Idx++];
662 return std::make_pair(LexicalOffset, VisibleOffset);
663}
664
665//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000666// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000667//===----------------------------------------------------------------------===//
668
Chris Lattner8f63ab52009-04-27 06:01:06 +0000669/// \brief Reads attributes from the current stream position.
670Attr *PCHReader::ReadAttributes() {
671 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000672 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000673 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000674
Chris Lattner8f63ab52009-04-27 06:01:06 +0000675 RecordData Record;
676 unsigned Idx = 0;
677 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000678 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000679 (void)RecCode;
680
681#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000682 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000683 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000684 break
685
686#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000687 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000688 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000689 break
690
691#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000692 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000693 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000694 break
695
696 Attr *Attrs = 0;
697 while (Idx < Record.size()) {
698 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +0000699 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +0000700 bool IsInherited = Record[Idx++];
701
702 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000703 default:
704 assert(0 && "Unknown attribute!");
705 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000706 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +0000707 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000708 UNSIGNED_ATTR(Aligned);
709 SIMPLE_ATTR(AlwaysInline);
710 SIMPLE_ATTR(AnalyzerNoReturn);
711 STRING_ATTR(Annotate);
712 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000713 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000714
Alexis Hunt344393e2010-06-16 23:43:53 +0000715 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000716 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000717 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
718 break;
Mike Stump11289f42009-09-09 15:08:12 +0000719
Eli Friedmane4310c82009-11-09 18:38:53 +0000720 SIMPLE_ATTR(CDecl);
721
Alexis Hunt344393e2010-06-16 23:43:53 +0000722 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000723 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000724 cast<FunctionDecl>(GetDecl(Record[Idx++])));
725 break;
726
727 SIMPLE_ATTR(Const);
728 UNSIGNED_ATTR(Constructor);
729 SIMPLE_ATTR(DLLExport);
730 SIMPLE_ATTR(DLLImport);
731 SIMPLE_ATTR(Deprecated);
732 UNSIGNED_ATTR(Destructor);
733 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000734 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000735
Alexis Hunt344393e2010-06-16 23:43:53 +0000736 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +0000737 std::string Type = ReadString(Record, Idx);
738 unsigned FormatIdx = Record[Idx++];
739 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000740 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000741 break;
742 }
Mike Stump11289f42009-09-09 15:08:12 +0000743
Alexis Hunt344393e2010-06-16 23:43:53 +0000744 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000745 unsigned FormatIdx = Record[Idx++];
746 New = ::new (*Context) FormatArgAttr(FormatIdx);
747 break;
748 }
Mike Stump11289f42009-09-09 15:08:12 +0000749
Alexis Hunt344393e2010-06-16 23:43:53 +0000750 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000751 int sentinel = Record[Idx++];
752 int nullPos = Record[Idx++];
753 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
754 break;
755 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000756
757 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000758 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000759
Alexis Hunt344393e2010-06-16 23:43:53 +0000760 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +0000761 New = ::new (*Context) IBActionAttr();
762 break;
763
Alexis Hunt344393e2010-06-16 23:43:53 +0000764 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +0000765 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000766 break;
767
Alexis Hunt344393e2010-06-16 23:43:53 +0000768 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +0000769 ObjCInterfaceDecl *D =
770 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
771 New = ::new (*Context) IBOutletCollectionAttr(D);
772 break;
773 }
774
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000775 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000776 SIMPLE_ATTR(NoDebug);
777 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000778 SIMPLE_ATTR(NoReturn);
779 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000780
Alexis Hunt344393e2010-06-16 23:43:53 +0000781 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +0000782 unsigned Size = Record[Idx++];
783 llvm::SmallVector<unsigned, 16> ArgNums;
784 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
785 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000786 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000787 break;
788 }
Mike Stump11289f42009-09-09 15:08:12 +0000789
Alexis Hunt344393e2010-06-16 23:43:53 +0000790 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +0000791 unsigned X = Record[Idx++];
792 unsigned Y = Record[Idx++];
793 unsigned Z = Record[Idx++];
794 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
795 break;
796 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000797
798 SIMPLE_ATTR(ObjCException);
799 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000800 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000801 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000802 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000803 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000804 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000805 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000806 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +0000807 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000808 SIMPLE_ATTR(Pure);
809 UNSIGNED_ATTR(Regparm);
810 STRING_ATTR(Section);
811 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +0000812 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000813 SIMPLE_ATTR(TransparentUnion);
814 SIMPLE_ATTR(Unavailable);
815 SIMPLE_ATTR(Unused);
816 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000817
Alexis Hunt344393e2010-06-16 23:43:53 +0000818 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000819 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000820 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
821 break;
822
823 SIMPLE_ATTR(WarnUnusedResult);
824 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +0000825 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000826 SIMPLE_ATTR(WeakImport);
827 }
828
829 assert(New && "Unable to decode attribute?");
830 New->setInherited(IsInherited);
831 New->setNext(Attrs);
832 Attrs = New;
833 }
834#undef UNSIGNED_ATTR
835#undef STRING_ATTR
836#undef SIMPLE_ATTR
837
838 // The list of attributes was built backwards. Reverse the list
839 // before returning it.
840 Attr *PrevAttr = 0, *NextAttr = 0;
841 while (Attrs) {
842 NextAttr = Attrs->getNext();
843 Attrs->setNext(PrevAttr);
844 PrevAttr = Attrs;
845 Attrs = NextAttr;
846 }
847
848 return PrevAttr;
849}
850
851//===----------------------------------------------------------------------===//
852// PCHReader Implementation
853//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000854
855/// \brief Note that we have loaded the declaration with the given
856/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000857///
Chris Lattner487412d2009-04-27 05:27:42 +0000858/// This routine notes that this declaration has already been loaded,
859/// so that future GetDecl calls will return this declaration rather
860/// than trying to load a new declaration.
861inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
862 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
863 DeclsLoaded[Index] = D;
864}
865
866
867/// \brief Determine whether the consumer will be interested in seeing
868/// this declaration (via HandleTopLevelDecl).
869///
870/// This routine should return true for anything that might affect
871/// code generation, e.g., inline function definitions, Objective-C
872/// declarations with metadata, etc.
873static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000874 if (isa<FileScopeAsmDecl>(D))
875 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000876 if (VarDecl *Var = dyn_cast<VarDecl>(D))
877 return Var->isFileVarDecl() && Var->getInit();
878 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
879 return Func->isThisDeclarationADefinition();
880 return isa<ObjCProtocolDecl>(D);
881}
882
883/// \brief Read the declaration at the given offset from the PCH file.
884Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
885 // Keep track of where we are in the stream, then jump back there
886 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000887 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000888
Douglas Gregor1342e842009-07-06 18:54:52 +0000889 // Note that we are loading a declaration record.
890 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000891
Chris Lattner1de76db2009-04-27 05:58:23 +0000892 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000893 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000894 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000895 unsigned Idx = 0;
896 PCHDeclReader Reader(*this, Record, Idx);
897
Chris Lattner1de76db2009-04-27 05:58:23 +0000898 Decl *D = 0;
899 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000900 case pch::DECL_ATTR:
901 case pch::DECL_CONTEXT_LEXICAL:
902 case pch::DECL_CONTEXT_VISIBLE:
903 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
904 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000905 case pch::DECL_TRANSLATION_UNIT:
906 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +0000907 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +0000908 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000909 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +0000910 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000911 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000912 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000913 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000914 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000915 case pch::DECL_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +0000916 D = RecordDecl::Create(*Context, TTK_Struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000917 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000918 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000919 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +0000920 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +0000921 0, llvm::APSInt());
922 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000923 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +0000924 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000925 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000926 break;
Chris Lattnerca025db2010-05-07 21:43:38 +0000927 case pch::DECL_LINKAGE_SPEC:
928 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
929 (LinkageSpecDecl::LanguageIDs)0,
930 false);
931 break;
932 case pch::DECL_NAMESPACE:
933 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
934 break;
935 case pch::DECL_NAMESPACE_ALIAS:
936 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
937 SourceLocation(), 0, SourceRange(), 0,
938 SourceLocation(), 0);
939 break;
940 case pch::DECL_USING:
941 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
942 SourceLocation(), 0, DeclarationName(), false);
943 break;
944 case pch::DECL_USING_SHADOW:
945 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
946 break;
947 case pch::DECL_USING_DIRECTIVE:
948 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
949 SourceLocation(), SourceRange(), 0,
950 SourceLocation(), 0, 0);
951 break;
952 case pch::DECL_UNRESOLVED_USING_VALUE:
953 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
954 SourceRange(), 0, SourceLocation(),
955 DeclarationName());
956 break;
957 case pch::DECL_UNRESOLVED_USING_TYPENAME:
958 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
959 SourceLocation(), SourceRange(),
960 0, SourceLocation(),
961 DeclarationName());
962 break;
963 case pch::DECL_CXX_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +0000964 D = CXXRecordDecl::Create(*Context, TTK_Struct, 0,
Chris Lattnerca025db2010-05-07 21:43:38 +0000965 SourceLocation(), 0, SourceLocation(), 0);
966 break;
967 case pch::DECL_CXX_METHOD:
968 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
969 QualType(), 0);
970 break;
971 case pch::DECL_CXX_CONSTRUCTOR:
972 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
973 break;
974 case pch::DECL_CXX_DESTRUCTOR:
975 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
976 break;
977 case pch::DECL_CXX_CONVERSION:
978 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
979 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +0000980 case pch::DECL_ACCESS_SPEC:
981 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
982 SourceLocation());
983 break;
Chris Lattnerca025db2010-05-07 21:43:38 +0000984 case pch::DECL_FRIEND:
985 assert(false && "cannot read FriendDecl");
986 break;
987 case pch::DECL_FRIEND_TEMPLATE:
988 assert(false && "cannot read FriendTemplateDecl");
989 break;
990 case pch::DECL_TEMPLATE:
991 // FIXME: Should TemplateDecl be ABSTRACT_DECL???
992 assert(false && "TemplateDecl should be abstract!");
993 break;
994 case pch::DECL_CLASS_TEMPLATE:
995 assert(false && "cannot read ClassTemplateDecl");
996 break;
997 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
998 assert(false && "cannot read ClasstemplateSpecializationDecl");
999 break;
1000 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
1001 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
1002 break;
1003 case pch::DECL_FUNCTION_TEMPLATE:
1004 assert(false && "cannot read FunctionTemplateDecl");
1005 break;
1006 case pch::DECL_TEMPLATE_TYPE_PARM:
1007 assert(false && "cannot read TemplateTypeParmDecl");
1008 break;
1009 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
1010 assert(false && "cannot read NonTypeTemplateParmDecl");
1011 break;
1012 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1013 assert(false && "cannot read TemplateTemplateParmDecl");
1014 break;
1015 case pch::DECL_STATIC_ASSERT:
1016 assert(false && "cannot read StaticAssertDecl");
1017 break;
1018
Chris Lattner8f63ab52009-04-27 06:01:06 +00001019 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001020 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001021 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001022 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001023 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001024 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001025 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001026 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001027 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001028 ObjCIvarDecl::None);
1029 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001030 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001031 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001032 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001033 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001034 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001035 QualType(), 0);
1036 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001037 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001038 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001039 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001040 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001041 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001042 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001043 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001044 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1045 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001046 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001047 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001048 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001049 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001050 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001051 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001052 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001053 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001054 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001055 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001056 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001057 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001058 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001059 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001060 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001061 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001062 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001063 ObjCPropertyImplDecl::Dynamic, 0);
1064 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001065 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001066 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001067 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001068 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001069 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001070 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001071 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001072 break;
1073
1074 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001075 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001076 break;
1077
Chris Lattner8f63ab52009-04-27 06:01:06 +00001078 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001079 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001080 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001081 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001082 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001083 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001084 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001085 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001086 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001087 break;
1088 }
Chris Lattner487412d2009-04-27 05:27:42 +00001089
1090 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001091 LoadedDecl(Index, D);
1092 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001093
1094 // If this declaration is also a declaration context, get the
1095 // offsets for its tables of lexical and visible declarations.
1096 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1097 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1098 if (Offsets.first || Offsets.second) {
1099 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1100 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1101 DeclContextOffsets[DC] = Offsets;
1102 }
1103 }
1104 assert(Idx == Record.size());
1105
1106 // If we have deserialized a declaration that has a definition the
1107 // AST consumer might need to know about, notify the consumer
1108 // about that definition now or queue it for later.
1109 if (isConsumerInterestedIn(D)) {
1110 if (Consumer) {
1111 DeclGroupRef DG(D);
1112 Consumer->HandleTopLevelDecl(DG);
1113 } else {
1114 InterestingDecls.push_back(D);
1115 }
1116 }
1117
1118 return D;
1119}