blob: 49010bf0d6dd171853fd0295a716e4f80834ed6b [file] [log] [blame]
Chris Lattner698f9252009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
Chris Lattner6ad9ac02010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner698f9252009-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 Gregor0cef4832010-02-21 18:22:14 +000044 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000045 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
46 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000047 void VisitTypeDecl(TypeDecl *TD);
48 void VisitTypedefDecl(TypedefDecl *TD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000049 void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000050 void VisitTagDecl(TagDecl *TD);
51 void VisitEnumDecl(EnumDecl *ED);
52 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-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 Lattner698f9252009-04-27 05:27:42 +000059 void VisitValueDecl(ValueDecl *VD);
60 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000061 void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000062 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000063 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-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 Lattner698f9252009-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 Lattner6ad9ac02010-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 Lattner698f9252009-04-27 05:27:42 +000080 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000081 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
82 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000083 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000084
Chris Lattner698f9252009-04-27 05:27:42 +000085 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000086
87 // FIXME: Reorder according to DeclNodes.def?
Chris Lattner698f9252009-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 Kyrtzidis40b598e2009-06-30 02:34:44 +0000113 D->addAttr(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +0000114 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000115 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000116 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000117 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +0000118}
119
120void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
121 VisitDecl(TU);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000122 TU->setAnonymousNamespace(
123 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000124}
125
126void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
127 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +0000128 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-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 McCallba6a9bd2009-10-24 08:00:42 +0000141 uint64_t TypeData = Record[Idx++];
John McCalla93c9342009-12-07 02:54:59 +0000142 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCallba6a9bd2009-10-24 08:00:42 +0000143 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000144}
145
146void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
147 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000148 TD->setPreviousDeclaration(
149 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000150 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
151 TD->setDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000152 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000153 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000154 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallb6217662010-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 Lattner698f9252009-04-27 05:27:42 +0000158}
159
160void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
161 VisitTagDecl(ED);
162 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000163 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall1b5a6182010-05-06 08:49:23 +0000164 ED->setNumPositiveBits(Record[Idx++]);
165 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000166 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-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 Jahanian643b7df2009-07-08 16:37:44 +0000173 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-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 Lattnerda930612009-04-27 05:58:23 +0000184 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000185 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
186}
187
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000188void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
189 VisitValueDecl(DD);
John McCalla93c9342009-12-07 02:54:59 +0000190 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
191 if (TInfo)
192 DD->setTypeSourceInfo(TInfo);
John McCallb6217662010-03-15 10:12:16 +0000193 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000194}
195
Chris Lattner698f9252009-04-27 05:27:42 +0000196void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000197 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000198 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000199 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-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 Gregor16573fa2010-04-19 22:54:31 +0000203 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000204 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000205 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000206 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000207 FD->setHasInheritedPrototype(Record[Idx++]);
208 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000209 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000210 FD->setTrivial(Record[Idx++]);
211 FD->setCopyAssignment(Record[Idx++]);
212 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000213 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000214 // FIXME: C++ TemplateOrInstantiation
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000215
216 // Read in the parameters.
Chris Lattner698f9252009-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 Gregor838db382010-02-11 01:19:42 +0000222 FD->setParams(Params.data(), NumParams);
John McCall76d32642010-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 Lattner698f9252009-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 Lattnerda930612009-04-27 05:58:23 +0000235 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-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 Jahanian7732cc92010-04-08 21:29:11 +0000244 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000245 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000246 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-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 Jahanian4ecb25f2010-04-09 15:40:42 +0000253 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
254 NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000255}
256
257void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
258 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-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 Lattner698f9252009-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 Gregor18df52b2010-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 Lattner698f9252009-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 Lattner698f9252009-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 Kyrtzidisc999f1f2009-07-18 00:33:23 +0000291 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-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 Gregor18df52b2010-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 Lattner698f9252009-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 Kremenek321c22f2009-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 Lattner698f9252009-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 Gregor18df52b2010-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 Lattner698f9252009-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 Gregor18df52b2010-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 Lattner698f9252009-04-27 05:27:42 +0000364 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor3db211b2010-01-16 16:38:58 +0000365 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
366 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-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 Jahaniand0502402010-01-21 17:36:00 +0000376 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-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 Kyrtzidisaecae622009-07-27 19:04:32 +0000395 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000396 D->setClassInterface(
397 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-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 Jahaniane4498c62010-04-28 16:11:27 +0000409 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner698f9252009-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 Jahanian17cb3262010-05-05 21:52:17 +0000420 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner698f9252009-04-27 05:27:42 +0000421}
422
423void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000424 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000425 FD->setMutable(Record[Idx++]);
426 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000427 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000428}
429
430void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000431 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000432 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregor16573fa2010-04-19 22:54:31 +0000433 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000434 VD->setThreadSpecified(Record[Idx++]);
435 VD->setCXXDirectInitializer(Record[Idx++]);
436 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor324b54d2010-05-03 18:51:14 +0000437 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor5077c382010-05-15 06:01:05 +0000438 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000439 VD->setPreviousDeclaration(
440 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000441 if (Record[Idx++])
Douglas Gregor838db382010-02-11 01:19:42 +0000442 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner698f9252009-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 McCallbf73b352010-03-12 18:31:32 +0000452 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000453}
454
Chris Lattner698f9252009-04-27 05:27:42 +0000455void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
456 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000457 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000458}
459
460void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
461 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000462 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-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 Gregor838db382010-02-11 01:19:42 +0000468 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000469}
470
Chris Lattner6ad9ac02010-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 Stump1eb44332009-09-09 15:08:12 +0000620std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-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 Lattner4e3fcc82009-04-27 06:01:06 +0000628// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000629//===----------------------------------------------------------------------===//
630
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000631/// \brief Reads attributes from the current stream position.
632Attr *PCHReader::ReadAttributes() {
633 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000634 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000635 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000636
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000637 RecordData Record;
638 unsigned Idx = 0;
639 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000640 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000641 (void)RecCode;
642
643#define SIMPLE_ATTR(Name) \
644 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000645 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000646 break
647
648#define STRING_ATTR(Name) \
649 case Attr::Name: \
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000650 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000651 break
652
653#define UNSIGNED_ATTR(Name) \
654 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000655 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-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 Korobeynikov82d0a412010-01-10 12:58:08 +0000665 default:
666 assert(0 && "Unknown attribute!");
667 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000668 STRING_ATTR(Alias);
669 UNSIGNED_ATTR(Aligned);
670 SIMPLE_ATTR(AlwaysInline);
671 SIMPLE_ATTR(AnalyzerNoReturn);
672 STRING_ATTR(Annotate);
673 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +0000674 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000676 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000677 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000678 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
679 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000681 SIMPLE_ATTR(CDecl);
682
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000683 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000684 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000685 cast<FunctionDecl>(GetDecl(Record[Idx++])));
686 break;
687
688 SIMPLE_ATTR(Const);
689 UNSIGNED_ATTR(Constructor);
690 SIMPLE_ATTR(DLLExport);
691 SIMPLE_ATTR(DLLImport);
692 SIMPLE_ATTR(Deprecated);
693 UNSIGNED_ATTR(Destructor);
694 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +0000695 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +0000696
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000697 case Attr::Format: {
698 std::string Type = ReadString(Record, Idx);
699 unsigned FormatIdx = Record[Idx++];
700 unsigned FirstArg = Record[Idx++];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000701 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000702 break;
703 }
Mike Stump1eb44332009-09-09 15:08:12 +0000704
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000705 case Attr::FormatArg: {
706 unsigned FormatIdx = Record[Idx++];
707 New = ::new (*Context) FormatArgAttr(FormatIdx);
708 break;
709 }
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000711 case Attr::Sentinel: {
712 int sentinel = Record[Idx++];
713 int nullPos = Record[Idx++];
714 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
715 break;
716 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000717
718 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +0000719 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +0000720
Ted Kremenekefbddd22010-02-17 02:37:45 +0000721 case Attr::IBActionKind:
722 New = ::new (*Context) IBActionAttr();
723 break;
724
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000725 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000726 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000727 break;
728
Ryan Flynn76168e22009-08-09 20:07:29 +0000729 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000730 SIMPLE_ATTR(NoDebug);
731 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000732 SIMPLE_ATTR(NoReturn);
733 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000735 case Attr::NonNull: {
736 unsigned Size = Record[Idx++];
737 llvm::SmallVector<unsigned, 16> ArgNums;
738 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
739 Idx += Size;
Ted Kremenek59616112010-02-11 07:31:47 +0000740 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000741 break;
742 }
Mike Stump1eb44332009-09-09 15:08:12 +0000743
Nate Begeman6f3d8382009-06-26 06:32:41 +0000744 case Attr::ReqdWorkGroupSize: {
745 unsigned X = Record[Idx++];
746 unsigned Y = Record[Idx++];
747 unsigned Z = Record[Idx++];
748 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
749 break;
750 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000751
752 SIMPLE_ATTR(ObjCException);
753 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenek31c780d2010-02-18 00:05:45 +0000754 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000755 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenek31c780d2010-02-18 00:05:45 +0000756 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000757 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000758 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +0000759 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +0000760 SIMPLE_ATTR(Packed);
761 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000762 SIMPLE_ATTR(Pure);
763 UNSIGNED_ATTR(Regparm);
764 STRING_ATTR(Section);
765 SIMPLE_ATTR(StdCall);
766 SIMPLE_ATTR(TransparentUnion);
767 SIMPLE_ATTR(Unavailable);
768 SIMPLE_ATTR(Unused);
769 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000770
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000771 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000772 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000773 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
774 break;
775
776 SIMPLE_ATTR(WarnUnusedResult);
777 SIMPLE_ATTR(Weak);
Rafael Espindola11e8ce72010-02-23 22:00:30 +0000778 SIMPLE_ATTR(WeakRef);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000779 SIMPLE_ATTR(WeakImport);
780 }
781
782 assert(New && "Unable to decode attribute?");
783 New->setInherited(IsInherited);
784 New->setNext(Attrs);
785 Attrs = New;
786 }
787#undef UNSIGNED_ATTR
788#undef STRING_ATTR
789#undef SIMPLE_ATTR
790
791 // The list of attributes was built backwards. Reverse the list
792 // before returning it.
793 Attr *PrevAttr = 0, *NextAttr = 0;
794 while (Attrs) {
795 NextAttr = Attrs->getNext();
796 Attrs->setNext(PrevAttr);
797 PrevAttr = Attrs;
798 Attrs = NextAttr;
799 }
800
801 return PrevAttr;
802}
803
804//===----------------------------------------------------------------------===//
805// PCHReader Implementation
806//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000807
808/// \brief Note that we have loaded the declaration with the given
809/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000810///
Chris Lattner698f9252009-04-27 05:27:42 +0000811/// This routine notes that this declaration has already been loaded,
812/// so that future GetDecl calls will return this declaration rather
813/// than trying to load a new declaration.
814inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
815 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
816 DeclsLoaded[Index] = D;
817}
818
819
820/// \brief Determine whether the consumer will be interested in seeing
821/// this declaration (via HandleTopLevelDecl).
822///
823/// This routine should return true for anything that might affect
824/// code generation, e.g., inline function definitions, Objective-C
825/// declarations with metadata, etc.
826static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000827 if (isa<FileScopeAsmDecl>(D))
828 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000829 if (VarDecl *Var = dyn_cast<VarDecl>(D))
830 return Var->isFileVarDecl() && Var->getInit();
831 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
832 return Func->isThisDeclarationADefinition();
833 return isa<ObjCProtocolDecl>(D);
834}
835
836/// \brief Read the declaration at the given offset from the PCH file.
837Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
838 // Keep track of where we are in the stream, then jump back there
839 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000840 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000841
Douglas Gregord89275b2009-07-06 18:54:52 +0000842 // Note that we are loading a declaration record.
843 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000844
Chris Lattnerda930612009-04-27 05:58:23 +0000845 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000846 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000847 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000848 unsigned Idx = 0;
849 PCHDeclReader Reader(*this, Record, Idx);
850
Chris Lattnerda930612009-04-27 05:58:23 +0000851 Decl *D = 0;
852 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000853 case pch::DECL_ATTR:
854 case pch::DECL_CONTEXT_LEXICAL:
855 case pch::DECL_CONTEXT_VISIBLE:
856 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
857 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000858 case pch::DECL_TRANSLATION_UNIT:
859 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000860 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000861 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000862 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +0000863 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000864 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000865 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000866 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000867 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000868 case pch::DECL_RECORD:
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000869 D = RecordDecl::Create(*Context, TTK_Struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000870 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000871 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000872 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000873 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000874 0, llvm::APSInt());
875 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000876 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000877 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000878 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000879 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000880 case pch::DECL_LINKAGE_SPEC:
881 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
882 (LinkageSpecDecl::LanguageIDs)0,
883 false);
884 break;
885 case pch::DECL_NAMESPACE:
886 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
887 break;
888 case pch::DECL_NAMESPACE_ALIAS:
889 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
890 SourceLocation(), 0, SourceRange(), 0,
891 SourceLocation(), 0);
892 break;
893 case pch::DECL_USING:
894 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
895 SourceLocation(), 0, DeclarationName(), false);
896 break;
897 case pch::DECL_USING_SHADOW:
898 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
899 break;
900 case pch::DECL_USING_DIRECTIVE:
901 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
902 SourceLocation(), SourceRange(), 0,
903 SourceLocation(), 0, 0);
904 break;
905 case pch::DECL_UNRESOLVED_USING_VALUE:
906 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
907 SourceRange(), 0, SourceLocation(),
908 DeclarationName());
909 break;
910 case pch::DECL_UNRESOLVED_USING_TYPENAME:
911 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
912 SourceLocation(), SourceRange(),
913 0, SourceLocation(),
914 DeclarationName());
915 break;
916 case pch::DECL_CXX_RECORD:
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000917 D = CXXRecordDecl::Create(*Context, TTK_Struct, 0,
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000918 SourceLocation(), 0, SourceLocation(), 0);
919 break;
920 case pch::DECL_CXX_METHOD:
921 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
922 QualType(), 0);
923 break;
924 case pch::DECL_CXX_CONSTRUCTOR:
925 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
926 break;
927 case pch::DECL_CXX_DESTRUCTOR:
928 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
929 break;
930 case pch::DECL_CXX_CONVERSION:
931 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
932 break;
933 case pch::DECL_FRIEND:
934 assert(false && "cannot read FriendDecl");
935 break;
936 case pch::DECL_FRIEND_TEMPLATE:
937 assert(false && "cannot read FriendTemplateDecl");
938 break;
939 case pch::DECL_TEMPLATE:
940 // FIXME: Should TemplateDecl be ABSTRACT_DECL???
941 assert(false && "TemplateDecl should be abstract!");
942 break;
943 case pch::DECL_CLASS_TEMPLATE:
944 assert(false && "cannot read ClassTemplateDecl");
945 break;
946 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
947 assert(false && "cannot read ClasstemplateSpecializationDecl");
948 break;
949 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
950 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
951 break;
952 case pch::DECL_FUNCTION_TEMPLATE:
953 assert(false && "cannot read FunctionTemplateDecl");
954 break;
955 case pch::DECL_TEMPLATE_TYPE_PARM:
956 assert(false && "cannot read TemplateTypeParmDecl");
957 break;
958 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
959 assert(false && "cannot read NonTypeTemplateParmDecl");
960 break;
961 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
962 assert(false && "cannot read TemplateTemplateParmDecl");
963 break;
964 case pch::DECL_STATIC_ASSERT:
965 assert(false && "cannot read StaticAssertDecl");
966 break;
967
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000968 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000969 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000970 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000971 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000972 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000973 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000974 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000975 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000976 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000977 ObjCIvarDecl::None);
978 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000979 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000980 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000981 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000982 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000983 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000984 QualType(), 0);
985 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000986 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000987 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000988 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000989 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000990 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000991 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000992 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +0000993 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
994 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000995 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000996 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000997 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000998 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000999 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001000 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001001 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001002 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001003 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001004 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001005 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001006 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
1007 QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001008 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001009 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001010 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001011 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001012 ObjCPropertyImplDecl::Dynamic, 0);
1013 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001014 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001015 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +00001016 false);
Chris Lattner698f9252009-04-27 05:27:42 +00001017 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001018 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001019 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001020 VarDecl::None, VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001021 break;
1022
1023 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001024 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001025 break;
1026
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001027 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +00001028 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001029 VarDecl::None, VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001030 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001031 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001032 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001033 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001034 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001035 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001036 break;
1037 }
Chris Lattner698f9252009-04-27 05:27:42 +00001038
1039 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001040 LoadedDecl(Index, D);
1041 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001042
1043 // If this declaration is also a declaration context, get the
1044 // offsets for its tables of lexical and visible declarations.
1045 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1046 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1047 if (Offsets.first || Offsets.second) {
1048 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1049 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1050 DeclContextOffsets[DC] = Offsets;
1051 }
1052 }
1053 assert(Idx == Record.size());
1054
1055 // If we have deserialized a declaration that has a definition the
1056 // AST consumer might need to know about, notify the consumer
1057 // about that definition now or queue it for later.
1058 if (isConsumerInterestedIn(D)) {
1059 if (Consumer) {
1060 DeclGroupRef DG(D);
1061 Consumer->HandleTopLevelDecl(DG);
1062 } else {
1063 InterestingDecls.push_back(D);
1064 }
1065 }
1066
1067 return D;
1068}