blob: 5056f93377c79bcb1e913f7b4866e04458d16a35 [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);
Chris Lattnerca025db2010-05-07 21:43:38 +000083 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
84 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000085 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000086
Chris Lattner487412d2009-04-27 05:27:42 +000087 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000088
Alexis Hunted053252010-05-30 07:21:58 +000089 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000090 void VisitObjCMethodDecl(ObjCMethodDecl *D);
91 void VisitObjCContainerDecl(ObjCContainerDecl *D);
92 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
93 void VisitObjCIvarDecl(ObjCIvarDecl *D);
94 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
95 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
96 void VisitObjCClassDecl(ObjCClassDecl *D);
97 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
98 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
99 void VisitObjCImplDecl(ObjCImplDecl *D);
100 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
101 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
102 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
103 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
104 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
105 };
106}
107
108void PCHDeclReader::VisitDecl(Decl *D) {
109 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
110 D->setLexicalDeclContext(
111 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
112 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
113 D->setInvalidDecl(Record[Idx++]);
114 if (Record[Idx++])
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +0000115 D->addAttr(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000116 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000117 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000118 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000119 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000120}
121
122void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
123 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000124 TU->setAnonymousNamespace(
125 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000126}
127
128void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
129 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000130 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000131}
132
133void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
134 VisitNamedDecl(TD);
135 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
136}
137
138void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
139 // Note that we cannot use VisitTypeDecl here, because we need to
140 // set the underlying type of the typedef *before* we try to read
141 // the type associated with the TypedefDecl.
142 VisitNamedDecl(TD);
John McCall703a3f82009-10-24 08:00:42 +0000143 uint64_t TypeData = Record[Idx++];
John McCallbcd03502009-12-07 02:54:59 +0000144 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCall703a3f82009-10-24 08:00:42 +0000145 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000146}
147
148void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
149 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000150 TD->setPreviousDeclaration(
151 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000152 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
153 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000154 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000155 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000156 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000157 // FIXME: maybe read optional qualifier and its range.
158 TD->setTypedefForAnonDecl(
159 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000160}
161
162void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
163 VisitTagDecl(ED);
164 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000165 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000166 ED->setNumPositiveBits(Record[Idx++]);
167 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor7a749382009-05-27 17:20:35 +0000168 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000169}
170
171void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
172 VisitTagDecl(RD);
173 RD->setHasFlexibleArrayMember(Record[Idx++]);
174 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000175 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000176}
177
178void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
179 VisitNamedDecl(VD);
180 VD->setType(Reader.GetType(Record[Idx++]));
181}
182
183void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
184 VisitValueDecl(ECD);
185 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000186 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000187 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
188}
189
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000190void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
191 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000192 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
193 if (TInfo)
194 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000195 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000196}
197
Chris Lattner487412d2009-04-27 05:27:42 +0000198void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000199 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000200 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000201 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000202 FD->setPreviousDeclaration(
203 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
204 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000205 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000206 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000207 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000208 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000209 FD->setHasInheritedPrototype(Record[Idx++]);
210 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000211 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000212 FD->setTrivial(Record[Idx++]);
213 FD->setCopyAssignment(Record[Idx++]);
214 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000215 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor24c332b2009-05-14 21:06:31 +0000216 // FIXME: C++ TemplateOrInstantiation
Chris Lattnerca025db2010-05-07 21:43:38 +0000217
218 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000219 unsigned NumParams = Record[Idx++];
220 llvm::SmallVector<ParmVarDecl *, 16> Params;
221 Params.reserve(NumParams);
222 for (unsigned I = 0; I != NumParams; ++I)
223 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000224 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000225
226 // FIXME: order this properly w.r.t. friendness
227 // FIXME: this same thing needs to happen for function templates
228 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
229 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000230}
231
232void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
233 VisitNamedDecl(MD);
234 if (Record[Idx++]) {
235 // In practice, this won't be executed (since method definitions
236 // don't occur in header files).
Chris Lattner1de76db2009-04-27 05:58:23 +0000237 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000238 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
239 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
240 }
241 MD->setInstanceMethod(Record[Idx++]);
242 MD->setVariadic(Record[Idx++]);
243 MD->setSynthesized(Record[Idx++]);
244 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
245 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000246 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000247 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000248 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000249 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
250 unsigned NumParams = Record[Idx++];
251 llvm::SmallVector<ParmVarDecl *, 16> Params;
252 Params.reserve(NumParams);
253 for (unsigned I = 0; I != NumParams; ++I)
254 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000255 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
256 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000257}
258
259void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
260 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000261 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
262 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
263 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000264}
265
266void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
267 VisitObjCContainerDecl(ID);
268 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
269 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
270 (Reader.GetDecl(Record[Idx++])));
271 unsigned NumProtocols = Record[Idx++];
272 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
273 Protocols.reserve(NumProtocols);
274 for (unsigned I = 0; I != NumProtocols; ++I)
275 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000276 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
277 ProtoLocs.reserve(NumProtocols);
278 for (unsigned I = 0; I != NumProtocols; ++I)
279 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
280 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
281 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000282 unsigned NumIvars = Record[Idx++];
283 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
284 IVars.reserve(NumIvars);
285 for (unsigned I = 0; I != NumIvars; ++I)
286 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000287 ID->setCategoryList(
288 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
289 ID->setForwardDecl(Record[Idx++]);
290 ID->setImplicitInterfaceDecl(Record[Idx++]);
291 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
292 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000293 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000294}
295
296void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
297 VisitFieldDecl(IVD);
298 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
299}
300
301void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
302 VisitObjCContainerDecl(PD);
303 PD->setForwardDecl(Record[Idx++]);
304 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
305 unsigned NumProtoRefs = Record[Idx++];
306 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
307 ProtoRefs.reserve(NumProtoRefs);
308 for (unsigned I = 0; I != NumProtoRefs; ++I)
309 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000310 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
311 ProtoLocs.reserve(NumProtoRefs);
312 for (unsigned I = 0; I != NumProtoRefs; ++I)
313 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
314 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
315 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000316}
317
318void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
319 VisitFieldDecl(FD);
320}
321
322void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
323 VisitDecl(CD);
324 unsigned NumClassRefs = Record[Idx++];
325 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
326 ClassRefs.reserve(NumClassRefs);
327 for (unsigned I = 0; I != NumClassRefs; ++I)
328 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000329 llvm::SmallVector<SourceLocation, 16> SLocs;
330 SLocs.reserve(NumClassRefs);
331 for (unsigned I = 0; I != NumClassRefs; ++I)
332 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
333 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
334 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000335}
336
337void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
338 VisitDecl(FPD);
339 unsigned NumProtoRefs = Record[Idx++];
340 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
341 ProtoRefs.reserve(NumProtoRefs);
342 for (unsigned I = 0; I != NumProtoRefs; ++I)
343 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000344 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
345 ProtoLocs.reserve(NumProtoRefs);
346 for (unsigned I = 0; I != NumProtoRefs; ++I)
347 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
348 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
349 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000350}
351
352void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
353 VisitObjCContainerDecl(CD);
354 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
355 unsigned NumProtoRefs = Record[Idx++];
356 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
357 ProtoRefs.reserve(NumProtoRefs);
358 for (unsigned I = 0; I != NumProtoRefs; ++I)
359 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000360 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
361 ProtoLocs.reserve(NumProtoRefs);
362 for (unsigned I = 0; I != NumProtoRefs; ++I)
363 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
364 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
365 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000366 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000367 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
368 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000369}
370
371void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
372 VisitNamedDecl(CAD);
373 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
374}
375
376void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
377 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000378 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000379 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000380 // FIXME: stable encoding
381 D->setPropertyAttributes(
382 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
383 // FIXME: stable encoding
384 D->setPropertyImplementation(
385 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
386 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
387 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
388 D->setGetterMethodDecl(
389 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
390 D->setSetterMethodDecl(
391 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
392 D->setPropertyIvarDecl(
393 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
394}
395
396void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000397 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000398 D->setClassInterface(
399 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000400}
401
402void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
403 VisitObjCImplDecl(D);
404 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
405}
406
407void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
408 VisitObjCImplDecl(D);
409 D->setSuperClass(
410 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000411 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000412}
413
414
415void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
416 VisitDecl(D);
417 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
418 D->setPropertyDecl(
419 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
420 D->setPropertyIvarDecl(
421 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000422 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000423}
424
425void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000426 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000427 FD->setMutable(Record[Idx++]);
428 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000429 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000430}
431
432void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000433 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000434 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000435 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000436 VD->setThreadSpecified(Record[Idx++]);
437 VD->setCXXDirectInitializer(Record[Idx++]);
438 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000439 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000440 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000441 VD->setPreviousDeclaration(
442 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000443 if (Record[Idx++])
Douglas Gregord5058122010-02-11 01:19:42 +0000444 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000445}
446
447void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
448 VisitVarDecl(PD);
449}
450
451void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
452 VisitVarDecl(PD);
453 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000454 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000455}
456
Chris Lattner487412d2009-04-27 05:27:42 +0000457void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
458 VisitDecl(AD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000459 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000460}
461
462void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
463 VisitDecl(BD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000464 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000465 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000466 unsigned NumParams = Record[Idx++];
467 llvm::SmallVector<ParmVarDecl *, 16> Params;
468 Params.reserve(NumParams);
469 for (unsigned I = 0; I != NumParams; ++I)
470 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000471 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000472}
473
Chris Lattnerca025db2010-05-07 21:43:38 +0000474void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
475 VisitDecl(D);
476 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
477 D->setHasBraces(Record[Idx++]);
478}
479
480void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
481 VisitNamedDecl(D);
482 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
483 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
484 D->setNextNamespace(
485 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
486
487 // Only read one reference--the original or anonymous namespace.
488 bool IsOriginal = Record[Idx++];
489 if (IsOriginal)
490 D->setAnonymousNamespace(
491 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
492 else
493 D->setOriginalNamespace(
494 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
495}
496
497void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
498 VisitNamedDecl(D);
499
500 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
501 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
502 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
503 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
504 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
505}
506
507void PCHDeclReader::VisitUsing(UsingDecl *D) {
508 VisitNamedDecl(D);
509 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
510 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
511 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
512
513 // FIXME: It would probably be more efficient to read these into a vector
514 // and then re-cosntruct the shadow decl set over that vector since it
515 // would avoid existence checks.
516 unsigned NumShadows = Record[Idx++];
517 for(unsigned I = 0; I != NumShadows; ++I) {
518 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
519 }
520 D->setTypeName(Record[Idx++]);
521}
522
523void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) {
524 VisitNamedDecl(D);
525 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
526 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
527}
528
529void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
530 VisitNamedDecl(D);
531 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
532 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
533 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
534 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
535 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
536 D->setCommonAncestor(cast_or_null<DeclContext>(
537 Reader.GetDecl(Record[Idx++])));
538}
539
540void PCHDeclReader::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) {
541 VisitValueDecl(D);
542 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
543 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
544 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
545}
546
547void PCHDeclReader::VisitUnresolvedUsingTypename(
548 UnresolvedUsingTypenameDecl *D) {
549 VisitTypeDecl(D);
550 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
551 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
552 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
553 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
554}
555
John McCall1c70e992010-06-03 19:28:45 +0000556CXXBaseSpecifier *PCHDeclReader::ReadCXXBaseSpecifier() {
557 bool isVirtual = static_cast<bool>(Record[Idx++]);
558 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
559 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
560 QualType T = Reader.GetType(Record[Idx++]);
561 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
562 return new (*Reader.getContext())
563 CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
564}
565
Chris Lattnerca025db2010-05-07 21:43:38 +0000566void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
567 // assert(false && "cannot read CXXRecordDecl");
568 VisitRecordDecl(D);
John McCall1c70e992010-06-03 19:28:45 +0000569
570 // FIXME: this is far from complete
571
572 if (D->isDefinition()) {
573 D->setDefinition(false); // make peace with an assertion
574 D->startDefinition();
575
576 unsigned NumBases = Record[Idx++];
577
578 llvm::SmallVector<CXXBaseSpecifier*, 4> Bases;
579 Bases.reserve(NumBases);
580 for (unsigned I = 0; I != NumBases; ++I)
581 Bases.push_back(ReadCXXBaseSpecifier());
582 D->setBases(Bases.begin(), NumBases);
583
584 // FIXME: there's a lot of stuff we do here that's kindof sketchy
585 // if we're leaving the context incomplete.
586 D->completeDefinition();
587 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000588}
589
590void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
591 // assert(false && "cannot read CXXMethodDecl");
592 VisitFunctionDecl(D);
593}
594
595void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
596 // assert(false && "cannot read CXXConstructorDecl");
597 VisitCXXMethodDecl(D);
598}
599
600void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
601 // assert(false && "cannot read CXXDestructorDecl");
602 VisitCXXMethodDecl(D);
603}
604
605void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
606 // assert(false && "cannot read CXXConversionDecl");
607 VisitCXXMethodDecl(D);
608}
609
610void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
611 assert(false && "cannot read FriendTemplateDecl");
612}
613
614void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
615 assert(false && "cannot read TemplateDecl");
616}
617
618void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
619 assert(false && "cannot read ClassTemplateDecl");
620}
621
622void PCHDeclReader::VisitClassTemplateSpecializationDecl(
623 ClassTemplateSpecializationDecl *D) {
624 assert(false && "cannot read ClassTemplateSpecializationDecl");
625}
626
627void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
628 ClassTemplatePartialSpecializationDecl *D) {
629 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
630}
631
632void PCHDeclReader::visitFunctionTemplateDecl(FunctionTemplateDecl *D) {
633 assert(false && "cannot read FunctionTemplateDecl");
634}
635
636void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
637 assert(false && "cannot read TemplateTypeParmDecl");
638}
639
640void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
641 assert(false && "cannot read NonTypeTemplateParmDecl");
642}
643
644void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
645 assert(false && "cannot read TemplateTemplateParmDecl");
646}
647
648void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
649 assert(false && "cannot read StaticAssertDecl");
650}
651
Mike Stump11289f42009-09-09 15:08:12 +0000652std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000653PCHDeclReader::VisitDeclContext(DeclContext *DC) {
654 uint64_t LexicalOffset = Record[Idx++];
655 uint64_t VisibleOffset = Record[Idx++];
656 return std::make_pair(LexicalOffset, VisibleOffset);
657}
658
659//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000660// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000661//===----------------------------------------------------------------------===//
662
Chris Lattner8f63ab52009-04-27 06:01:06 +0000663/// \brief Reads attributes from the current stream position.
664Attr *PCHReader::ReadAttributes() {
665 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000666 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000667 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000668
Chris Lattner8f63ab52009-04-27 06:01:06 +0000669 RecordData Record;
670 unsigned Idx = 0;
671 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000672 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000673 (void)RecCode;
674
675#define SIMPLE_ATTR(Name) \
676 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000677 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000678 break
679
680#define STRING_ATTR(Name) \
681 case Attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000682 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000683 break
684
685#define UNSIGNED_ATTR(Name) \
686 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000687 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000688 break
689
690 Attr *Attrs = 0;
691 while (Idx < Record.size()) {
692 Attr *New = 0;
693 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
694 bool IsInherited = Record[Idx++];
695
696 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000697 default:
698 assert(0 && "Unknown attribute!");
699 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000700 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +0000701 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000702 UNSIGNED_ATTR(Aligned);
703 SIMPLE_ATTR(AlwaysInline);
704 SIMPLE_ATTR(AnalyzerNoReturn);
705 STRING_ATTR(Annotate);
706 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000707 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000708
Chris Lattner8f63ab52009-04-27 06:01:06 +0000709 case Attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000710 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000711 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
712 break;
Mike Stump11289f42009-09-09 15:08:12 +0000713
Eli Friedmane4310c82009-11-09 18:38:53 +0000714 SIMPLE_ATTR(CDecl);
715
Chris Lattner8f63ab52009-04-27 06:01:06 +0000716 case Attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000717 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000718 cast<FunctionDecl>(GetDecl(Record[Idx++])));
719 break;
720
721 SIMPLE_ATTR(Const);
722 UNSIGNED_ATTR(Constructor);
723 SIMPLE_ATTR(DLLExport);
724 SIMPLE_ATTR(DLLImport);
725 SIMPLE_ATTR(Deprecated);
726 UNSIGNED_ATTR(Destructor);
727 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000728 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000729
Chris Lattner8f63ab52009-04-27 06:01:06 +0000730 case Attr::Format: {
731 std::string Type = ReadString(Record, Idx);
732 unsigned FormatIdx = Record[Idx++];
733 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000734 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000735 break;
736 }
Mike Stump11289f42009-09-09 15:08:12 +0000737
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000738 case Attr::FormatArg: {
739 unsigned FormatIdx = Record[Idx++];
740 New = ::new (*Context) FormatArgAttr(FormatIdx);
741 break;
742 }
Mike Stump11289f42009-09-09 15:08:12 +0000743
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000744 case Attr::Sentinel: {
745 int sentinel = Record[Idx++];
746 int nullPos = Record[Idx++];
747 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
748 break;
749 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000750
751 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000752 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000753
Ted Kremenek06be9682010-02-17 02:37:45 +0000754 case Attr::IBActionKind:
755 New = ::new (*Context) IBActionAttr();
756 break;
757
Chris Lattner8f63ab52009-04-27 06:01:06 +0000758 case Attr::IBOutletKind:
Chris Lattner8575daa2009-04-27 21:45:14 +0000759 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000760 break;
761
Ted Kremenek26bde772010-05-19 17:38:06 +0000762 case Attr::IBOutletCollectionKind: {
763 ObjCInterfaceDecl *D =
764 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
765 New = ::new (*Context) IBOutletCollectionAttr(D);
766 break;
767 }
768
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000769 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000770 SIMPLE_ATTR(NoDebug);
771 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000772 SIMPLE_ATTR(NoReturn);
773 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000774
Chris Lattner8f63ab52009-04-27 06:01:06 +0000775 case Attr::NonNull: {
776 unsigned Size = Record[Idx++];
777 llvm::SmallVector<unsigned, 16> ArgNums;
778 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
779 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000780 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000781 break;
782 }
Mike Stump11289f42009-09-09 15:08:12 +0000783
Nate Begemanf2758702009-06-26 06:32:41 +0000784 case Attr::ReqdWorkGroupSize: {
785 unsigned X = Record[Idx++];
786 unsigned Y = Record[Idx++];
787 unsigned Z = Record[Idx++];
788 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
789 break;
790 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000791
792 SIMPLE_ATTR(ObjCException);
793 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000794 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000795 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000796 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000797 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000798 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000799 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000800 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +0000801 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000802 SIMPLE_ATTR(Pure);
803 UNSIGNED_ATTR(Regparm);
804 STRING_ATTR(Section);
805 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +0000806 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000807 SIMPLE_ATTR(TransparentUnion);
808 SIMPLE_ATTR(Unavailable);
809 SIMPLE_ATTR(Unused);
810 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000811
Chris Lattner8f63ab52009-04-27 06:01:06 +0000812 case Attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000813 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000814 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
815 break;
816
817 SIMPLE_ATTR(WarnUnusedResult);
818 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +0000819 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000820 SIMPLE_ATTR(WeakImport);
821 }
822
823 assert(New && "Unable to decode attribute?");
824 New->setInherited(IsInherited);
825 New->setNext(Attrs);
826 Attrs = New;
827 }
828#undef UNSIGNED_ATTR
829#undef STRING_ATTR
830#undef SIMPLE_ATTR
831
832 // The list of attributes was built backwards. Reverse the list
833 // before returning it.
834 Attr *PrevAttr = 0, *NextAttr = 0;
835 while (Attrs) {
836 NextAttr = Attrs->getNext();
837 Attrs->setNext(PrevAttr);
838 PrevAttr = Attrs;
839 Attrs = NextAttr;
840 }
841
842 return PrevAttr;
843}
844
845//===----------------------------------------------------------------------===//
846// PCHReader Implementation
847//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000848
849/// \brief Note that we have loaded the declaration with the given
850/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000851///
Chris Lattner487412d2009-04-27 05:27:42 +0000852/// This routine notes that this declaration has already been loaded,
853/// so that future GetDecl calls will return this declaration rather
854/// than trying to load a new declaration.
855inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
856 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
857 DeclsLoaded[Index] = D;
858}
859
860
861/// \brief Determine whether the consumer will be interested in seeing
862/// this declaration (via HandleTopLevelDecl).
863///
864/// This routine should return true for anything that might affect
865/// code generation, e.g., inline function definitions, Objective-C
866/// declarations with metadata, etc.
867static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000868 if (isa<FileScopeAsmDecl>(D))
869 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000870 if (VarDecl *Var = dyn_cast<VarDecl>(D))
871 return Var->isFileVarDecl() && Var->getInit();
872 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
873 return Func->isThisDeclarationADefinition();
874 return isa<ObjCProtocolDecl>(D);
875}
876
877/// \brief Read the declaration at the given offset from the PCH file.
878Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
879 // Keep track of where we are in the stream, then jump back there
880 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000881 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000882
Douglas Gregor1342e842009-07-06 18:54:52 +0000883 // Note that we are loading a declaration record.
884 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000885
Chris Lattner1de76db2009-04-27 05:58:23 +0000886 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000887 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000888 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000889 unsigned Idx = 0;
890 PCHDeclReader Reader(*this, Record, Idx);
891
Chris Lattner1de76db2009-04-27 05:58:23 +0000892 Decl *D = 0;
893 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000894 case pch::DECL_ATTR:
895 case pch::DECL_CONTEXT_LEXICAL:
896 case pch::DECL_CONTEXT_VISIBLE:
897 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
898 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000899 case pch::DECL_TRANSLATION_UNIT:
900 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +0000901 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +0000902 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000903 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +0000904 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000905 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000906 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000907 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000908 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000909 case pch::DECL_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +0000910 D = RecordDecl::Create(*Context, TTK_Struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000911 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000912 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000913 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +0000914 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +0000915 0, llvm::APSInt());
916 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000917 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +0000918 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000919 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000920 break;
Chris Lattnerca025db2010-05-07 21:43:38 +0000921 case pch::DECL_LINKAGE_SPEC:
922 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
923 (LinkageSpecDecl::LanguageIDs)0,
924 false);
925 break;
926 case pch::DECL_NAMESPACE:
927 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
928 break;
929 case pch::DECL_NAMESPACE_ALIAS:
930 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
931 SourceLocation(), 0, SourceRange(), 0,
932 SourceLocation(), 0);
933 break;
934 case pch::DECL_USING:
935 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
936 SourceLocation(), 0, DeclarationName(), false);
937 break;
938 case pch::DECL_USING_SHADOW:
939 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
940 break;
941 case pch::DECL_USING_DIRECTIVE:
942 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
943 SourceLocation(), SourceRange(), 0,
944 SourceLocation(), 0, 0);
945 break;
946 case pch::DECL_UNRESOLVED_USING_VALUE:
947 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
948 SourceRange(), 0, SourceLocation(),
949 DeclarationName());
950 break;
951 case pch::DECL_UNRESOLVED_USING_TYPENAME:
952 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
953 SourceLocation(), SourceRange(),
954 0, SourceLocation(),
955 DeclarationName());
956 break;
957 case pch::DECL_CXX_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +0000958 D = CXXRecordDecl::Create(*Context, TTK_Struct, 0,
Chris Lattnerca025db2010-05-07 21:43:38 +0000959 SourceLocation(), 0, SourceLocation(), 0);
960 break;
961 case pch::DECL_CXX_METHOD:
962 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
963 QualType(), 0);
964 break;
965 case pch::DECL_CXX_CONSTRUCTOR:
966 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
967 break;
968 case pch::DECL_CXX_DESTRUCTOR:
969 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
970 break;
971 case pch::DECL_CXX_CONVERSION:
972 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
973 break;
974 case pch::DECL_FRIEND:
975 assert(false && "cannot read FriendDecl");
976 break;
977 case pch::DECL_FRIEND_TEMPLATE:
978 assert(false && "cannot read FriendTemplateDecl");
979 break;
980 case pch::DECL_TEMPLATE:
981 // FIXME: Should TemplateDecl be ABSTRACT_DECL???
982 assert(false && "TemplateDecl should be abstract!");
983 break;
984 case pch::DECL_CLASS_TEMPLATE:
985 assert(false && "cannot read ClassTemplateDecl");
986 break;
987 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
988 assert(false && "cannot read ClasstemplateSpecializationDecl");
989 break;
990 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
991 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
992 break;
993 case pch::DECL_FUNCTION_TEMPLATE:
994 assert(false && "cannot read FunctionTemplateDecl");
995 break;
996 case pch::DECL_TEMPLATE_TYPE_PARM:
997 assert(false && "cannot read TemplateTypeParmDecl");
998 break;
999 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
1000 assert(false && "cannot read NonTypeTemplateParmDecl");
1001 break;
1002 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1003 assert(false && "cannot read TemplateTemplateParmDecl");
1004 break;
1005 case pch::DECL_STATIC_ASSERT:
1006 assert(false && "cannot read StaticAssertDecl");
1007 break;
1008
Chris Lattner8f63ab52009-04-27 06:01:06 +00001009 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001010 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001011 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001012 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001013 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001014 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001015 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001016 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001017 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001018 ObjCIvarDecl::None);
1019 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001020 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001021 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001022 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001023 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001024 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001025 QualType(), 0);
1026 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001027 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001028 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001029 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001030 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001031 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001032 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001033 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001034 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1035 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001036 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001037 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001038 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001039 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001040 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001041 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001042 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001043 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001044 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001045 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001046 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001047 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001048 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001049 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001050 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001051 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001052 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001053 ObjCPropertyImplDecl::Dynamic, 0);
1054 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001055 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001056 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001057 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001058 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001059 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001060 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001061 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001062 break;
1063
1064 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001065 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001066 break;
1067
Chris Lattner8f63ab52009-04-27 06:01:06 +00001068 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001069 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001070 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001071 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001072 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001073 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001074 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001075 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001076 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001077 break;
1078 }
Chris Lattner487412d2009-04-27 05:27:42 +00001079
1080 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001081 LoadedDecl(Index, D);
1082 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001083
1084 // If this declaration is also a declaration context, get the
1085 // offsets for its tables of lexical and visible declarations.
1086 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1087 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1088 if (Offsets.first || Offsets.second) {
1089 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1090 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1091 DeclContextOffsets[DC] = Offsets;
1092 }
1093 }
1094 assert(Idx == Record.size());
1095
1096 // If we have deserialized a declaration that has a definition the
1097 // AST consumer might need to know about, notify the consumer
1098 // about that definition now or queue it for later.
1099 if (isConsumerInterestedIn(D)) {
1100 if (Consumer) {
1101 DeclGroupRef DG(D);
1102 Consumer->HandleTopLevelDecl(DG);
1103 } else {
1104 InterestingDecls.push_back(D);
1105 }
1106 }
1107
1108 return D;
1109}