blob: 1ef0441ebf60842f29fcaa6d76acc0d816b88f78 [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
41 void VisitDecl(Decl *D);
42 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
43 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000044 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000045 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
46 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000047 void VisitTypeDecl(TypeDecl *TD);
48 void VisitTypedefDecl(TypedefDecl *TD);
Chris Lattnerca025db2010-05-07 21:43:38 +000049 void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000050 void VisitTagDecl(TagDecl *TD);
51 void VisitEnumDecl(EnumDecl *ED);
52 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000053 void VisitCXXRecordDecl(CXXRecordDecl *D);
54 void VisitClassTemplateSpecializationDecl(
55 ClassTemplateSpecializationDecl *D);
56 void VisitClassTemplatePartialSpecializationDecl(
57 ClassTemplatePartialSpecializationDecl *D);
58 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000059 void VisitValueDecl(ValueDecl *VD);
60 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Chris Lattnerca025db2010-05-07 21:43:38 +000061 void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000062 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000063 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000064 void VisitCXXMethodDecl(CXXMethodDecl *D);
65 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
66 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
67 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000068 void VisitFieldDecl(FieldDecl *FD);
69 void VisitVarDecl(VarDecl *VD);
70 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
71 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000072 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
73 void VisitTemplateDecl(TemplateDecl *D);
74 void VisitClassTemplateDecl(ClassTemplateDecl *D);
75 void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
76 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
77 void VisitUsing(UsingDecl *D);
78 void VisitUsingShadow(UsingShadowDecl *D);
79 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000080 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Chris Lattnerca025db2010-05-07 21:43:38 +000081 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
82 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000083 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000084
Chris Lattner487412d2009-04-27 05:27:42 +000085 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000086
87 // FIXME: Reorder according to DeclNodes.def?
Chris Lattner487412d2009-04-27 05:27:42 +000088 void VisitObjCMethodDecl(ObjCMethodDecl *D);
89 void VisitObjCContainerDecl(ObjCContainerDecl *D);
90 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
91 void VisitObjCIvarDecl(ObjCIvarDecl *D);
92 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
93 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
94 void VisitObjCClassDecl(ObjCClassDecl *D);
95 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
96 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
97 void VisitObjCImplDecl(ObjCImplDecl *D);
98 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
99 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
100 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
101 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
102 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
103 };
104}
105
106void PCHDeclReader::VisitDecl(Decl *D) {
107 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
108 D->setLexicalDeclContext(
109 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
110 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
111 D->setInvalidDecl(Record[Idx++]);
112 if (Record[Idx++])
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +0000113 D->addAttr(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000114 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000115 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000116 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000117 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000118}
119
120void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
121 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000122 TU->setAnonymousNamespace(
123 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000124}
125
126void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
127 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000128 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000129}
130
131void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
132 VisitNamedDecl(TD);
133 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
134}
135
136void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
137 // Note that we cannot use VisitTypeDecl here, because we need to
138 // set the underlying type of the typedef *before* we try to read
139 // the type associated with the TypedefDecl.
140 VisitNamedDecl(TD);
John McCall703a3f82009-10-24 08:00:42 +0000141 uint64_t TypeData = Record[Idx++];
John McCallbcd03502009-12-07 02:54:59 +0000142 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCall703a3f82009-10-24 08:00:42 +0000143 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000144}
145
146void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
147 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000148 TD->setPreviousDeclaration(
149 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000150 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
151 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000152 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000153 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000154 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000155 // FIXME: maybe read optional qualifier and its range.
156 TD->setTypedefForAnonDecl(
157 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000158}
159
160void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
161 VisitTagDecl(ED);
162 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000163 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000164 ED->setNumPositiveBits(Record[Idx++]);
165 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor7a749382009-05-27 17:20:35 +0000166 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000167}
168
169void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
170 VisitTagDecl(RD);
171 RD->setHasFlexibleArrayMember(Record[Idx++]);
172 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000173 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000174}
175
176void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
177 VisitNamedDecl(VD);
178 VD->setType(Reader.GetType(Record[Idx++]));
179}
180
181void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
182 VisitValueDecl(ECD);
183 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000184 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000185 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
186}
187
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000188void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
189 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000190 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
191 if (TInfo)
192 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000193 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000194}
195
Chris Lattner487412d2009-04-27 05:27:42 +0000196void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000197 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000198 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000199 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000200 FD->setPreviousDeclaration(
201 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
202 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000203 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000204 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000205 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000206 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000207 FD->setHasInheritedPrototype(Record[Idx++]);
208 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000209 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000210 FD->setTrivial(Record[Idx++]);
211 FD->setCopyAssignment(Record[Idx++]);
212 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000213 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor24c332b2009-05-14 21:06:31 +0000214 // FIXME: C++ TemplateOrInstantiation
Chris Lattnerca025db2010-05-07 21:43:38 +0000215
216 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000217 unsigned NumParams = Record[Idx++];
218 llvm::SmallVector<ParmVarDecl *, 16> Params;
219 Params.reserve(NumParams);
220 for (unsigned I = 0; I != NumParams; ++I)
221 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000222 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000223
224 // FIXME: order this properly w.r.t. friendness
225 // FIXME: this same thing needs to happen for function templates
226 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
227 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000228}
229
230void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
231 VisitNamedDecl(MD);
232 if (Record[Idx++]) {
233 // In practice, this won't be executed (since method definitions
234 // don't occur in header files).
Chris Lattner1de76db2009-04-27 05:58:23 +0000235 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000236 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
237 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
238 }
239 MD->setInstanceMethod(Record[Idx++]);
240 MD->setVariadic(Record[Idx++]);
241 MD->setSynthesized(Record[Idx++]);
242 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
243 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000244 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000245 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000246 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000247 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
248 unsigned NumParams = Record[Idx++];
249 llvm::SmallVector<ParmVarDecl *, 16> Params;
250 Params.reserve(NumParams);
251 for (unsigned I = 0; I != NumParams; ++I)
252 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000253 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
254 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000255}
256
257void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
258 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000259 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
260 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
261 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000262}
263
264void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
265 VisitObjCContainerDecl(ID);
266 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
267 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
268 (Reader.GetDecl(Record[Idx++])));
269 unsigned NumProtocols = Record[Idx++];
270 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
271 Protocols.reserve(NumProtocols);
272 for (unsigned I = 0; I != NumProtocols; ++I)
273 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000274 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
275 ProtoLocs.reserve(NumProtocols);
276 for (unsigned I = 0; I != NumProtocols; ++I)
277 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
278 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
279 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000280 unsigned NumIvars = Record[Idx++];
281 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
282 IVars.reserve(NumIvars);
283 for (unsigned I = 0; I != NumIvars; ++I)
284 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000285 ID->setCategoryList(
286 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
287 ID->setForwardDecl(Record[Idx++]);
288 ID->setImplicitInterfaceDecl(Record[Idx++]);
289 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
290 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000291 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000292}
293
294void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
295 VisitFieldDecl(IVD);
296 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
297}
298
299void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
300 VisitObjCContainerDecl(PD);
301 PD->setForwardDecl(Record[Idx++]);
302 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
303 unsigned NumProtoRefs = Record[Idx++];
304 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
305 ProtoRefs.reserve(NumProtoRefs);
306 for (unsigned I = 0; I != NumProtoRefs; ++I)
307 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000308 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
309 ProtoLocs.reserve(NumProtoRefs);
310 for (unsigned I = 0; I != NumProtoRefs; ++I)
311 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
312 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
313 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000314}
315
316void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
317 VisitFieldDecl(FD);
318}
319
320void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
321 VisitDecl(CD);
322 unsigned NumClassRefs = Record[Idx++];
323 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
324 ClassRefs.reserve(NumClassRefs);
325 for (unsigned I = 0; I != NumClassRefs; ++I)
326 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000327 llvm::SmallVector<SourceLocation, 16> SLocs;
328 SLocs.reserve(NumClassRefs);
329 for (unsigned I = 0; I != NumClassRefs; ++I)
330 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
331 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
332 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000333}
334
335void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
336 VisitDecl(FPD);
337 unsigned NumProtoRefs = Record[Idx++];
338 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
339 ProtoRefs.reserve(NumProtoRefs);
340 for (unsigned I = 0; I != NumProtoRefs; ++I)
341 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000342 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
343 ProtoLocs.reserve(NumProtoRefs);
344 for (unsigned I = 0; I != NumProtoRefs; ++I)
345 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
346 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
347 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000348}
349
350void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
351 VisitObjCContainerDecl(CD);
352 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
353 unsigned NumProtoRefs = Record[Idx++];
354 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
355 ProtoRefs.reserve(NumProtoRefs);
356 for (unsigned I = 0; I != NumProtoRefs; ++I)
357 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000358 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
359 ProtoLocs.reserve(NumProtoRefs);
360 for (unsigned I = 0; I != NumProtoRefs; ++I)
361 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
362 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
363 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000364 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000365 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
366 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000367}
368
369void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
370 VisitNamedDecl(CAD);
371 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
372}
373
374void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
375 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000376 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000377 D->setType(Reader.GetType(Record[Idx++]));
378 // FIXME: stable encoding
379 D->setPropertyAttributes(
380 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
381 // FIXME: stable encoding
382 D->setPropertyImplementation(
383 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
384 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
385 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
386 D->setGetterMethodDecl(
387 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
388 D->setSetterMethodDecl(
389 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
390 D->setPropertyIvarDecl(
391 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
392}
393
394void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000395 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000396 D->setClassInterface(
397 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000398}
399
400void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
401 VisitObjCImplDecl(D);
402 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
403}
404
405void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
406 VisitObjCImplDecl(D);
407 D->setSuperClass(
408 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000409 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000410}
411
412
413void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
414 VisitDecl(D);
415 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
416 D->setPropertyDecl(
417 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
418 D->setPropertyIvarDecl(
419 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000420 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000421}
422
423void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000424 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000425 FD->setMutable(Record[Idx++]);
426 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000427 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000428}
429
430void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000431 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000432 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000433 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000434 VD->setThreadSpecified(Record[Idx++]);
435 VD->setCXXDirectInitializer(Record[Idx++]);
436 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000437 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000438 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000439 VD->setPreviousDeclaration(
440 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000441 if (Record[Idx++])
Douglas Gregord5058122010-02-11 01:19:42 +0000442 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000443}
444
445void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
446 VisitVarDecl(PD);
447}
448
449void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
450 VisitVarDecl(PD);
451 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000452 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000453}
454
Chris Lattner487412d2009-04-27 05:27:42 +0000455void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
456 VisitDecl(AD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000457 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000458}
459
460void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
461 VisitDecl(BD);
Chris Lattner1de76db2009-04-27 05:58:23 +0000462 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner487412d2009-04-27 05:27:42 +0000463 unsigned NumParams = Record[Idx++];
464 llvm::SmallVector<ParmVarDecl *, 16> Params;
465 Params.reserve(NumParams);
466 for (unsigned I = 0; I != NumParams; ++I)
467 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000468 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000469}
470
Chris Lattnerca025db2010-05-07 21:43:38 +0000471void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
472 VisitDecl(D);
473 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
474 D->setHasBraces(Record[Idx++]);
475}
476
477void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
478 VisitNamedDecl(D);
479 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
480 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
481 D->setNextNamespace(
482 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
483
484 // Only read one reference--the original or anonymous namespace.
485 bool IsOriginal = Record[Idx++];
486 if (IsOriginal)
487 D->setAnonymousNamespace(
488 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
489 else
490 D->setOriginalNamespace(
491 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
492}
493
494void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
495 VisitNamedDecl(D);
496
497 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
498 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
499 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
500 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
501 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
502}
503
504void PCHDeclReader::VisitUsing(UsingDecl *D) {
505 VisitNamedDecl(D);
506 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
507 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
508 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
509
510 // FIXME: It would probably be more efficient to read these into a vector
511 // and then re-cosntruct the shadow decl set over that vector since it
512 // would avoid existence checks.
513 unsigned NumShadows = Record[Idx++];
514 for(unsigned I = 0; I != NumShadows; ++I) {
515 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
516 }
517 D->setTypeName(Record[Idx++]);
518}
519
520void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) {
521 VisitNamedDecl(D);
522 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
523 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
524}
525
526void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
527 VisitNamedDecl(D);
528 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
529 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
530 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
531 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
532 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
533 D->setCommonAncestor(cast_or_null<DeclContext>(
534 Reader.GetDecl(Record[Idx++])));
535}
536
537void PCHDeclReader::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) {
538 VisitValueDecl(D);
539 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
540 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
541 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
542}
543
544void PCHDeclReader::VisitUnresolvedUsingTypename(
545 UnresolvedUsingTypenameDecl *D) {
546 VisitTypeDecl(D);
547 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
548 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
549 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
550 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
551}
552
553void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
554 // assert(false && "cannot read CXXRecordDecl");
555 VisitRecordDecl(D);
556}
557
558void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
559 // assert(false && "cannot read CXXMethodDecl");
560 VisitFunctionDecl(D);
561}
562
563void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
564 // assert(false && "cannot read CXXConstructorDecl");
565 VisitCXXMethodDecl(D);
566}
567
568void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
569 // assert(false && "cannot read CXXDestructorDecl");
570 VisitCXXMethodDecl(D);
571}
572
573void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
574 // assert(false && "cannot read CXXConversionDecl");
575 VisitCXXMethodDecl(D);
576}
577
578void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
579 assert(false && "cannot read FriendTemplateDecl");
580}
581
582void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
583 assert(false && "cannot read TemplateDecl");
584}
585
586void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
587 assert(false && "cannot read ClassTemplateDecl");
588}
589
590void PCHDeclReader::VisitClassTemplateSpecializationDecl(
591 ClassTemplateSpecializationDecl *D) {
592 assert(false && "cannot read ClassTemplateSpecializationDecl");
593}
594
595void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
596 ClassTemplatePartialSpecializationDecl *D) {
597 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
598}
599
600void PCHDeclReader::visitFunctionTemplateDecl(FunctionTemplateDecl *D) {
601 assert(false && "cannot read FunctionTemplateDecl");
602}
603
604void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
605 assert(false && "cannot read TemplateTypeParmDecl");
606}
607
608void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
609 assert(false && "cannot read NonTypeTemplateParmDecl");
610}
611
612void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
613 assert(false && "cannot read TemplateTemplateParmDecl");
614}
615
616void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
617 assert(false && "cannot read StaticAssertDecl");
618}
619
Mike Stump11289f42009-09-09 15:08:12 +0000620std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000621PCHDeclReader::VisitDeclContext(DeclContext *DC) {
622 uint64_t LexicalOffset = Record[Idx++];
623 uint64_t VisibleOffset = Record[Idx++];
624 return std::make_pair(LexicalOffset, VisibleOffset);
625}
626
627//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000628// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000629//===----------------------------------------------------------------------===//
630
Chris Lattner8f63ab52009-04-27 06:01:06 +0000631/// \brief Reads attributes from the current stream position.
632Attr *PCHReader::ReadAttributes() {
633 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000634 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000635 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000636
Chris Lattner8f63ab52009-04-27 06:01:06 +0000637 RecordData Record;
638 unsigned Idx = 0;
639 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000640 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000641 (void)RecCode;
642
643#define SIMPLE_ATTR(Name) \
644 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000645 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000646 break
647
648#define STRING_ATTR(Name) \
649 case Attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000650 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000651 break
652
653#define UNSIGNED_ATTR(Name) \
654 case Attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000655 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000656 break
657
658 Attr *Attrs = 0;
659 while (Idx < Record.size()) {
660 Attr *New = 0;
661 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
662 bool IsInherited = Record[Idx++];
663
664 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000665 default:
666 assert(0 && "Unknown attribute!");
667 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000668 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +0000669 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000670 UNSIGNED_ATTR(Aligned);
671 SIMPLE_ATTR(AlwaysInline);
672 SIMPLE_ATTR(AnalyzerNoReturn);
673 STRING_ATTR(Annotate);
674 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000675 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000676
Chris Lattner8f63ab52009-04-27 06:01:06 +0000677 case Attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000678 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000679 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
680 break;
Mike Stump11289f42009-09-09 15:08:12 +0000681
Eli Friedmane4310c82009-11-09 18:38:53 +0000682 SIMPLE_ATTR(CDecl);
683
Chris Lattner8f63ab52009-04-27 06:01:06 +0000684 case Attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000685 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000686 cast<FunctionDecl>(GetDecl(Record[Idx++])));
687 break;
688
689 SIMPLE_ATTR(Const);
690 UNSIGNED_ATTR(Constructor);
691 SIMPLE_ATTR(DLLExport);
692 SIMPLE_ATTR(DLLImport);
693 SIMPLE_ATTR(Deprecated);
694 UNSIGNED_ATTR(Destructor);
695 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000696 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000697
Chris Lattner8f63ab52009-04-27 06:01:06 +0000698 case Attr::Format: {
699 std::string Type = ReadString(Record, Idx);
700 unsigned FormatIdx = Record[Idx++];
701 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000702 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000703 break;
704 }
Mike Stump11289f42009-09-09 15:08:12 +0000705
Fariborz Jahanianf1c25022009-05-20 17:41:43 +0000706 case Attr::FormatArg: {
707 unsigned FormatIdx = Record[Idx++];
708 New = ::new (*Context) FormatArgAttr(FormatIdx);
709 break;
710 }
Mike Stump11289f42009-09-09 15:08:12 +0000711
Fariborz Jahanian027b8862009-05-13 18:09:35 +0000712 case Attr::Sentinel: {
713 int sentinel = Record[Idx++];
714 int nullPos = Record[Idx++];
715 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
716 break;
717 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000718
719 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +0000720 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +0000721
Ted Kremenek06be9682010-02-17 02:37:45 +0000722 case Attr::IBActionKind:
723 New = ::new (*Context) IBActionAttr();
724 break;
725
Chris Lattner8f63ab52009-04-27 06:01:06 +0000726 case Attr::IBOutletKind:
Chris Lattner8575daa2009-04-27 21:45:14 +0000727 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +0000728 break;
729
Ted Kremenek26bde772010-05-19 17:38:06 +0000730 case Attr::IBOutletCollectionKind: {
731 ObjCInterfaceDecl *D =
732 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
733 New = ::new (*Context) IBOutletCollectionAttr(D);
734 break;
735 }
736
Ryan Flynn1f1fdc02009-08-09 20:07:29 +0000737 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +0000738 SIMPLE_ATTR(NoDebug);
739 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000740 SIMPLE_ATTR(NoReturn);
741 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +0000742
Chris Lattner8f63ab52009-04-27 06:01:06 +0000743 case Attr::NonNull: {
744 unsigned Size = Record[Idx++];
745 llvm::SmallVector<unsigned, 16> ArgNums;
746 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
747 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +0000748 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000749 break;
750 }
Mike Stump11289f42009-09-09 15:08:12 +0000751
Nate Begemanf2758702009-06-26 06:32:41 +0000752 case Attr::ReqdWorkGroupSize: {
753 unsigned X = Record[Idx++];
754 unsigned Y = Record[Idx++];
755 unsigned Z = Record[Idx++];
756 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
757 break;
758 }
Chris Lattner8f63ab52009-04-27 06:01:06 +0000759
760 SIMPLE_ATTR(ObjCException);
761 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000762 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000763 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +0000764 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +0000765 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000766 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +0000767 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +0000768 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +0000769 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000770 SIMPLE_ATTR(Pure);
771 UNSIGNED_ATTR(Regparm);
772 STRING_ATTR(Section);
773 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +0000774 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000775 SIMPLE_ATTR(TransparentUnion);
776 SIMPLE_ATTR(Unavailable);
777 SIMPLE_ATTR(Unused);
778 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +0000779
Chris Lattner8f63ab52009-04-27 06:01:06 +0000780 case Attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +0000781 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000782 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
783 break;
784
785 SIMPLE_ATTR(WarnUnusedResult);
786 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +0000787 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000788 SIMPLE_ATTR(WeakImport);
789 }
790
791 assert(New && "Unable to decode attribute?");
792 New->setInherited(IsInherited);
793 New->setNext(Attrs);
794 Attrs = New;
795 }
796#undef UNSIGNED_ATTR
797#undef STRING_ATTR
798#undef SIMPLE_ATTR
799
800 // The list of attributes was built backwards. Reverse the list
801 // before returning it.
802 Attr *PrevAttr = 0, *NextAttr = 0;
803 while (Attrs) {
804 NextAttr = Attrs->getNext();
805 Attrs->setNext(PrevAttr);
806 PrevAttr = Attrs;
807 Attrs = NextAttr;
808 }
809
810 return PrevAttr;
811}
812
813//===----------------------------------------------------------------------===//
814// PCHReader Implementation
815//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +0000816
817/// \brief Note that we have loaded the declaration with the given
818/// Index.
Mike Stump11289f42009-09-09 15:08:12 +0000819///
Chris Lattner487412d2009-04-27 05:27:42 +0000820/// This routine notes that this declaration has already been loaded,
821/// so that future GetDecl calls will return this declaration rather
822/// than trying to load a new declaration.
823inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
824 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
825 DeclsLoaded[Index] = D;
826}
827
828
829/// \brief Determine whether the consumer will be interested in seeing
830/// this declaration (via HandleTopLevelDecl).
831///
832/// This routine should return true for anything that might affect
833/// code generation, e.g., inline function definitions, Objective-C
834/// declarations with metadata, etc.
835static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +0000836 if (isa<FileScopeAsmDecl>(D))
837 return true;
Chris Lattner487412d2009-04-27 05:27:42 +0000838 if (VarDecl *Var = dyn_cast<VarDecl>(D))
839 return Var->isFileVarDecl() && Var->getInit();
840 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
841 return Func->isThisDeclarationADefinition();
842 return isa<ObjCProtocolDecl>(D);
843}
844
845/// \brief Read the declaration at the given offset from the PCH file.
846Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
847 // Keep track of where we are in the stream, then jump back there
848 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +0000849 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +0000850
Douglas Gregor1342e842009-07-06 18:54:52 +0000851 // Note that we are loading a declaration record.
852 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000853
Chris Lattner1de76db2009-04-27 05:58:23 +0000854 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +0000855 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +0000856 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +0000857 unsigned Idx = 0;
858 PCHDeclReader Reader(*this, Record, Idx);
859
Chris Lattner1de76db2009-04-27 05:58:23 +0000860 Decl *D = 0;
861 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +0000862 case pch::DECL_ATTR:
863 case pch::DECL_CONTEXT_LEXICAL:
864 case pch::DECL_CONTEXT_VISIBLE:
865 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
866 break;
Chris Lattner487412d2009-04-27 05:27:42 +0000867 case pch::DECL_TRANSLATION_UNIT:
868 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +0000869 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +0000870 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000871 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +0000872 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000873 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000874 case pch::DECL_ENUM:
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000875 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000876 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000877 case pch::DECL_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 D = RecordDecl::Create(*Context, TTK_Struct, 0, SourceLocation(),
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000879 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000880 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000881 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +0000882 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +0000883 0, llvm::APSInt());
884 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000885 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +0000886 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000887 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000888 break;
Chris Lattnerca025db2010-05-07 21:43:38 +0000889 case pch::DECL_LINKAGE_SPEC:
890 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
891 (LinkageSpecDecl::LanguageIDs)0,
892 false);
893 break;
894 case pch::DECL_NAMESPACE:
895 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
896 break;
897 case pch::DECL_NAMESPACE_ALIAS:
898 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
899 SourceLocation(), 0, SourceRange(), 0,
900 SourceLocation(), 0);
901 break;
902 case pch::DECL_USING:
903 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
904 SourceLocation(), 0, DeclarationName(), false);
905 break;
906 case pch::DECL_USING_SHADOW:
907 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
908 break;
909 case pch::DECL_USING_DIRECTIVE:
910 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
911 SourceLocation(), SourceRange(), 0,
912 SourceLocation(), 0, 0);
913 break;
914 case pch::DECL_UNRESOLVED_USING_VALUE:
915 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
916 SourceRange(), 0, SourceLocation(),
917 DeclarationName());
918 break;
919 case pch::DECL_UNRESOLVED_USING_TYPENAME:
920 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
921 SourceLocation(), SourceRange(),
922 0, SourceLocation(),
923 DeclarationName());
924 break;
925 case pch::DECL_CXX_RECORD:
Abramo Bagnara6150c882010-05-11 21:36:43 +0000926 D = CXXRecordDecl::Create(*Context, TTK_Struct, 0,
Chris Lattnerca025db2010-05-07 21:43:38 +0000927 SourceLocation(), 0, SourceLocation(), 0);
928 break;
929 case pch::DECL_CXX_METHOD:
930 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
931 QualType(), 0);
932 break;
933 case pch::DECL_CXX_CONSTRUCTOR:
934 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
935 break;
936 case pch::DECL_CXX_DESTRUCTOR:
937 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
938 break;
939 case pch::DECL_CXX_CONVERSION:
940 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
941 break;
942 case pch::DECL_FRIEND:
943 assert(false && "cannot read FriendDecl");
944 break;
945 case pch::DECL_FRIEND_TEMPLATE:
946 assert(false && "cannot read FriendTemplateDecl");
947 break;
948 case pch::DECL_TEMPLATE:
949 // FIXME: Should TemplateDecl be ABSTRACT_DECL???
950 assert(false && "TemplateDecl should be abstract!");
951 break;
952 case pch::DECL_CLASS_TEMPLATE:
953 assert(false && "cannot read ClassTemplateDecl");
954 break;
955 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
956 assert(false && "cannot read ClasstemplateSpecializationDecl");
957 break;
958 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
959 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
960 break;
961 case pch::DECL_FUNCTION_TEMPLATE:
962 assert(false && "cannot read FunctionTemplateDecl");
963 break;
964 case pch::DECL_TEMPLATE_TYPE_PARM:
965 assert(false && "cannot read TemplateTypeParmDecl");
966 break;
967 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
968 assert(false && "cannot read NonTypeTemplateParmDecl");
969 break;
970 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
971 assert(false && "cannot read TemplateTemplateParmDecl");
972 break;
973 case pch::DECL_STATIC_ASSERT:
974 assert(false && "cannot read StaticAssertDecl");
975 break;
976
Chris Lattner8f63ab52009-04-27 06:01:06 +0000977 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +0000978 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +0000979 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000980 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000981 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +0000982 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000983 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000984 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000985 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000986 ObjCIvarDecl::None);
987 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000988 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000989 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +0000990 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000991 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +0000992 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +0000993 QualType(), 0);
994 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000995 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +0000996 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +0000997 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000998 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +0000999 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001000 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001001 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001002 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1003 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001004 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001005 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001006 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001007 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001008 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001009 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001010 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001011 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001012 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001013 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001014 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001015 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
1016 QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001017 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001018 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001019 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001020 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001021 ObjCPropertyImplDecl::Dynamic, 0);
1022 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001023 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001024 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001025 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001026 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001027 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001028 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001029 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001030 break;
1031
1032 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001033 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001034 break;
1035
Chris Lattner8f63ab52009-04-27 06:01:06 +00001036 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001037 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001038 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001039 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001040 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001041 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001042 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001043 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001044 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001045 break;
1046 }
Chris Lattner487412d2009-04-27 05:27:42 +00001047
1048 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001049 LoadedDecl(Index, D);
1050 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001051
1052 // If this declaration is also a declaration context, get the
1053 // offsets for its tables of lexical and visible declarations.
1054 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1055 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1056 if (Offsets.first || Offsets.second) {
1057 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1058 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1059 DeclContextOffsets[DC] = Offsets;
1060 }
1061 }
1062 assert(Idx == Record.size());
1063
1064 // If we have deserialized a declaration that has a definition the
1065 // AST consumer might need to know about, notify the consumer
1066 // about that definition now or queue it for later.
1067 if (isConsumerInterestedIn(D)) {
1068 if (Consumer) {
1069 DeclGroupRef DG(D);
1070 Consumer->HandleTopLevelDecl(DG);
1071 } else {
1072 InterestingDecls.push_back(D);
1073 }
1074 }
1075
1076 return D;
1077}