blob: c4f9622db8dba71a04b9887cdb0b786def59b326 [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++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000438 VD->setPreviousDeclaration(
439 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000440 if (Record[Idx++])
Douglas Gregor838db382010-02-11 01:19:42 +0000441 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000442}
443
444void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
445 VisitVarDecl(PD);
446}
447
448void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
449 VisitVarDecl(PD);
450 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallbf73b352010-03-12 18:31:32 +0000451 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000452}
453
Chris Lattner698f9252009-04-27 05:27:42 +0000454void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
455 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000456 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000457}
458
459void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
460 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000461 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
Chris Lattner698f9252009-04-27 05:27:42 +0000462 unsigned NumParams = Record[Idx++];
463 llvm::SmallVector<ParmVarDecl *, 16> Params;
464 Params.reserve(NumParams);
465 for (unsigned I = 0; I != NumParams; ++I)
466 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000467 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000468}
469
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000470void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
471 VisitDecl(D);
472 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
473 D->setHasBraces(Record[Idx++]);
474}
475
476void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
477 VisitNamedDecl(D);
478 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
479 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
480 D->setNextNamespace(
481 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
482
483 // Only read one reference--the original or anonymous namespace.
484 bool IsOriginal = Record[Idx++];
485 if (IsOriginal)
486 D->setAnonymousNamespace(
487 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
488 else
489 D->setOriginalNamespace(
490 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
491}
492
493void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
494 VisitNamedDecl(D);
495
496 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
497 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
498 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
499 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
500 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
501}
502
503void PCHDeclReader::VisitUsing(UsingDecl *D) {
504 VisitNamedDecl(D);
505 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
506 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
507 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
508
509 // FIXME: It would probably be more efficient to read these into a vector
510 // and then re-cosntruct the shadow decl set over that vector since it
511 // would avoid existence checks.
512 unsigned NumShadows = Record[Idx++];
513 for(unsigned I = 0; I != NumShadows; ++I) {
514 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
515 }
516 D->setTypeName(Record[Idx++]);
517}
518
519void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) {
520 VisitNamedDecl(D);
521 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
522 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
523}
524
525void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
526 VisitNamedDecl(D);
527 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
528 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
529 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
530 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
531 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
532 D->setCommonAncestor(cast_or_null<DeclContext>(
533 Reader.GetDecl(Record[Idx++])));
534}
535
536void PCHDeclReader::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) {
537 VisitValueDecl(D);
538 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
539 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
540 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
541}
542
543void PCHDeclReader::VisitUnresolvedUsingTypename(
544 UnresolvedUsingTypenameDecl *D) {
545 VisitTypeDecl(D);
546 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
547 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
548 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
549 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
550}
551
552void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
553 // assert(false && "cannot read CXXRecordDecl");
554 VisitRecordDecl(D);
555}
556
557void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
558 // assert(false && "cannot read CXXMethodDecl");
559 VisitFunctionDecl(D);
560}
561
562void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
563 // assert(false && "cannot read CXXConstructorDecl");
564 VisitCXXMethodDecl(D);
565}
566
567void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
568 // assert(false && "cannot read CXXDestructorDecl");
569 VisitCXXMethodDecl(D);
570}
571
572void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
573 // assert(false && "cannot read CXXConversionDecl");
574 VisitCXXMethodDecl(D);
575}
576
577void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
578 assert(false && "cannot read FriendTemplateDecl");
579}
580
581void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
582 assert(false && "cannot read TemplateDecl");
583}
584
585void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
586 assert(false && "cannot read ClassTemplateDecl");
587}
588
589void PCHDeclReader::VisitClassTemplateSpecializationDecl(
590 ClassTemplateSpecializationDecl *D) {
591 assert(false && "cannot read ClassTemplateSpecializationDecl");
592}
593
594void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
595 ClassTemplatePartialSpecializationDecl *D) {
596 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
597}
598
599void PCHDeclReader::visitFunctionTemplateDecl(FunctionTemplateDecl *D) {
600 assert(false && "cannot read FunctionTemplateDecl");
601}
602
603void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
604 assert(false && "cannot read TemplateTypeParmDecl");
605}
606
607void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
608 assert(false && "cannot read NonTypeTemplateParmDecl");
609}
610
611void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
612 assert(false && "cannot read TemplateTemplateParmDecl");
613}
614
615void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
616 assert(false && "cannot read StaticAssertDecl");
617}
618
Mike Stump1eb44332009-09-09 15:08:12 +0000619std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000620PCHDeclReader::VisitDeclContext(DeclContext *DC) {
621 uint64_t LexicalOffset = Record[Idx++];
622 uint64_t VisibleOffset = Record[Idx++];
623 return std::make_pair(LexicalOffset, VisibleOffset);
624}
625
626//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000627// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000628//===----------------------------------------------------------------------===//
629
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000630/// \brief Reads attributes from the current stream position.
631Attr *PCHReader::ReadAttributes() {
632 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000633 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000634 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000636 RecordData Record;
637 unsigned Idx = 0;
638 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000639 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000640 (void)RecCode;
641
642#define SIMPLE_ATTR(Name) \
643 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000644 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000645 break
646
647#define STRING_ATTR(Name) \
648 case Attr::Name: \
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000649 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000650 break
651
652#define UNSIGNED_ATTR(Name) \
653 case Attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000654 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000655 break
656
657 Attr *Attrs = 0;
658 while (Idx < Record.size()) {
659 Attr *New = 0;
660 Attr::Kind Kind = (Attr::Kind)Record[Idx++];
661 bool IsInherited = Record[Idx++];
662
663 switch (Kind) {
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000664 default:
665 assert(0 && "Unknown attribute!");
666 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000667 STRING_ATTR(Alias);
668 UNSIGNED_ATTR(Aligned);
669 SIMPLE_ATTR(AlwaysInline);
670 SIMPLE_ATTR(AnalyzerNoReturn);
671 STRING_ATTR(Annotate);
672 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +0000673 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +0000674
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000675 case Attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000676 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000677 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
678 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000679
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000680 SIMPLE_ATTR(CDecl);
681
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000682 case Attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000683 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000684 cast<FunctionDecl>(GetDecl(Record[Idx++])));
685 break;
686
687 SIMPLE_ATTR(Const);
688 UNSIGNED_ATTR(Constructor);
689 SIMPLE_ATTR(DLLExport);
690 SIMPLE_ATTR(DLLImport);
691 SIMPLE_ATTR(Deprecated);
692 UNSIGNED_ATTR(Destructor);
693 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +0000694 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000696 case Attr::Format: {
697 std::string Type = ReadString(Record, Idx);
698 unsigned FormatIdx = Record[Idx++];
699 unsigned FirstArg = Record[Idx++];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000700 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000701 break;
702 }
Mike Stump1eb44332009-09-09 15:08:12 +0000703
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000704 case Attr::FormatArg: {
705 unsigned FormatIdx = Record[Idx++];
706 New = ::new (*Context) FormatArgAttr(FormatIdx);
707 break;
708 }
Mike Stump1eb44332009-09-09 15:08:12 +0000709
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000710 case Attr::Sentinel: {
711 int sentinel = Record[Idx++];
712 int nullPos = Record[Idx++];
713 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
714 break;
715 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000716
717 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +0000718 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +0000719
Ted Kremenekefbddd22010-02-17 02:37:45 +0000720 case Attr::IBActionKind:
721 New = ::new (*Context) IBActionAttr();
722 break;
723
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000724 case Attr::IBOutletKind:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000725 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000726 break;
727
Ryan Flynn76168e22009-08-09 20:07:29 +0000728 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000729 SIMPLE_ATTR(NoDebug);
730 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000731 SIMPLE_ATTR(NoReturn);
732 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000733
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000734 case Attr::NonNull: {
735 unsigned Size = Record[Idx++];
736 llvm::SmallVector<unsigned, 16> ArgNums;
737 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
738 Idx += Size;
Ted Kremenek59616112010-02-11 07:31:47 +0000739 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000740 break;
741 }
Mike Stump1eb44332009-09-09 15:08:12 +0000742
Nate Begeman6f3d8382009-06-26 06:32:41 +0000743 case Attr::ReqdWorkGroupSize: {
744 unsigned X = Record[Idx++];
745 unsigned Y = Record[Idx++];
746 unsigned Z = Record[Idx++];
747 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
748 break;
749 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000750
751 SIMPLE_ATTR(ObjCException);
752 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenek31c780d2010-02-18 00:05:45 +0000753 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000754 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenek31c780d2010-02-18 00:05:45 +0000755 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +0000756 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000757 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +0000758 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +0000759 SIMPLE_ATTR(Packed);
760 UNSIGNED_ATTR(PragmaPack);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000761 SIMPLE_ATTR(Pure);
762 UNSIGNED_ATTR(Regparm);
763 STRING_ATTR(Section);
764 SIMPLE_ATTR(StdCall);
765 SIMPLE_ATTR(TransparentUnion);
766 SIMPLE_ATTR(Unavailable);
767 SIMPLE_ATTR(Unused);
768 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000770 case Attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000771 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000772 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
773 break;
774
775 SIMPLE_ATTR(WarnUnusedResult);
776 SIMPLE_ATTR(Weak);
Rafael Espindola11e8ce72010-02-23 22:00:30 +0000777 SIMPLE_ATTR(WeakRef);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000778 SIMPLE_ATTR(WeakImport);
779 }
780
781 assert(New && "Unable to decode attribute?");
782 New->setInherited(IsInherited);
783 New->setNext(Attrs);
784 Attrs = New;
785 }
786#undef UNSIGNED_ATTR
787#undef STRING_ATTR
788#undef SIMPLE_ATTR
789
790 // The list of attributes was built backwards. Reverse the list
791 // before returning it.
792 Attr *PrevAttr = 0, *NextAttr = 0;
793 while (Attrs) {
794 NextAttr = Attrs->getNext();
795 Attrs->setNext(PrevAttr);
796 PrevAttr = Attrs;
797 Attrs = NextAttr;
798 }
799
800 return PrevAttr;
801}
802
803//===----------------------------------------------------------------------===//
804// PCHReader Implementation
805//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +0000806
807/// \brief Note that we have loaded the declaration with the given
808/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +0000809///
Chris Lattner698f9252009-04-27 05:27:42 +0000810/// This routine notes that this declaration has already been loaded,
811/// so that future GetDecl calls will return this declaration rather
812/// than trying to load a new declaration.
813inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
814 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
815 DeclsLoaded[Index] = D;
816}
817
818
819/// \brief Determine whether the consumer will be interested in seeing
820/// this declaration (via HandleTopLevelDecl).
821///
822/// This routine should return true for anything that might affect
823/// code generation, e.g., inline function definitions, Objective-C
824/// declarations with metadata, etc.
825static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +0000826 if (isa<FileScopeAsmDecl>(D))
827 return true;
Chris Lattner698f9252009-04-27 05:27:42 +0000828 if (VarDecl *Var = dyn_cast<VarDecl>(D))
829 return Var->isFileVarDecl() && Var->getInit();
830 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
831 return Func->isThisDeclarationADefinition();
832 return isa<ObjCProtocolDecl>(D);
833}
834
835/// \brief Read the declaration at the given offset from the PCH file.
836Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
837 // Keep track of where we are in the stream, then jump back there
838 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +0000839 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +0000840
Douglas Gregord89275b2009-07-06 18:54:52 +0000841 // Note that we are loading a declaration record.
842 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000843
Chris Lattnerda930612009-04-27 05:58:23 +0000844 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +0000845 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +0000846 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +0000847 unsigned Idx = 0;
848 PCHDeclReader Reader(*this, Record, Idx);
849
Chris Lattnerda930612009-04-27 05:58:23 +0000850 Decl *D = 0;
851 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +0000852 case pch::DECL_ATTR:
853 case pch::DECL_CONTEXT_LEXICAL:
854 case pch::DECL_CONTEXT_VISIBLE:
855 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
856 break;
Chris Lattner698f9252009-04-27 05:27:42 +0000857 case pch::DECL_TRANSLATION_UNIT:
858 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000859 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +0000860 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000861 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +0000862 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000863 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000864 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000865 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000866 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000867 case pch::DECL_RECORD:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000868 D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000869 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000870 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000871 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000872 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +0000873 0, llvm::APSInt());
874 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000875 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +0000876 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000877 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000878 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000879 case pch::DECL_LINKAGE_SPEC:
880 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
881 (LinkageSpecDecl::LanguageIDs)0,
882 false);
883 break;
884 case pch::DECL_NAMESPACE:
885 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
886 break;
887 case pch::DECL_NAMESPACE_ALIAS:
888 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
889 SourceLocation(), 0, SourceRange(), 0,
890 SourceLocation(), 0);
891 break;
892 case pch::DECL_USING:
893 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
894 SourceLocation(), 0, DeclarationName(), false);
895 break;
896 case pch::DECL_USING_SHADOW:
897 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
898 break;
899 case pch::DECL_USING_DIRECTIVE:
900 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
901 SourceLocation(), SourceRange(), 0,
902 SourceLocation(), 0, 0);
903 break;
904 case pch::DECL_UNRESOLVED_USING_VALUE:
905 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
906 SourceRange(), 0, SourceLocation(),
907 DeclarationName());
908 break;
909 case pch::DECL_UNRESOLVED_USING_TYPENAME:
910 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
911 SourceLocation(), SourceRange(),
912 0, SourceLocation(),
913 DeclarationName());
914 break;
915 case pch::DECL_CXX_RECORD:
916 D = CXXRecordDecl::Create(*Context, TagDecl::TK_struct, 0,
917 SourceLocation(), 0, SourceLocation(), 0);
918 break;
919 case pch::DECL_CXX_METHOD:
920 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
921 QualType(), 0);
922 break;
923 case pch::DECL_CXX_CONSTRUCTOR:
924 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
925 break;
926 case pch::DECL_CXX_DESTRUCTOR:
927 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
928 break;
929 case pch::DECL_CXX_CONVERSION:
930 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
931 break;
932 case pch::DECL_FRIEND:
933 assert(false && "cannot read FriendDecl");
934 break;
935 case pch::DECL_FRIEND_TEMPLATE:
936 assert(false && "cannot read FriendTemplateDecl");
937 break;
938 case pch::DECL_TEMPLATE:
939 // FIXME: Should TemplateDecl be ABSTRACT_DECL???
940 assert(false && "TemplateDecl should be abstract!");
941 break;
942 case pch::DECL_CLASS_TEMPLATE:
943 assert(false && "cannot read ClassTemplateDecl");
944 break;
945 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
946 assert(false && "cannot read ClasstemplateSpecializationDecl");
947 break;
948 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
949 assert(false && "cannot read ClassTemplatePartialSpecializationDecl");
950 break;
951 case pch::DECL_FUNCTION_TEMPLATE:
952 assert(false && "cannot read FunctionTemplateDecl");
953 break;
954 case pch::DECL_TEMPLATE_TYPE_PARM:
955 assert(false && "cannot read TemplateTypeParmDecl");
956 break;
957 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
958 assert(false && "cannot read NonTypeTemplateParmDecl");
959 break;
960 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
961 assert(false && "cannot read TemplateTemplateParmDecl");
962 break;
963 case pch::DECL_STATIC_ASSERT:
964 assert(false && "cannot read StaticAssertDecl");
965 break;
966
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000967 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +0000968 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000969 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000970 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000971 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000972 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000973 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000974 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000975 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000976 ObjCIvarDecl::None);
977 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000978 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000979 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000980 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000981 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +0000982 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +0000983 QualType(), 0);
984 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000985 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000986 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000987 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000988 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000989 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +0000990 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000991 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +0000992 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
993 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000994 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000995 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000996 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +0000997 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000998 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000999 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001000 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001001 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001002 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001003 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001004 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001005 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
1006 QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001007 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001008 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001009 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001010 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001011 ObjCPropertyImplDecl::Dynamic, 0);
1012 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001013 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001014 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +00001015 false);
Chris Lattner698f9252009-04-27 05:27:42 +00001016 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001017 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001018 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001019 VarDecl::None, VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001020 break;
1021
1022 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001023 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001024 break;
1025
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001026 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +00001027 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001028 VarDecl::None, VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001029 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001030 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001031 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001032 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001033 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001034 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001035 break;
1036 }
Chris Lattner698f9252009-04-27 05:27:42 +00001037
1038 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001039 LoadedDecl(Index, D);
1040 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001041
1042 // If this declaration is also a declaration context, get the
1043 // offsets for its tables of lexical and visible declarations.
1044 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1045 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1046 if (Offsets.first || Offsets.second) {
1047 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1048 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1049 DeclContextOffsets[DC] = Offsets;
1050 }
1051 }
1052 assert(Idx == Record.size());
1053
1054 // If we have deserialized a declaration that has a definition the
1055 // AST consumer might need to know about, notify the consumer
1056 // about that definition now or queue it for later.
1057 if (isConsumerInterestedIn(D)) {
1058 if (Consumer) {
1059 DeclGroupRef DG(D);
1060 Consumer->HandleTopLevelDecl(DG);
1061 } else {
1062 InterestingDecls.push_back(D);
1063 }
1064 }
1065
1066 return D;
1067}